From patchwork Thu Jul 21 03:53:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 72522 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp218260qga; Wed, 20 Jul 2016 20:53:33 -0700 (PDT) X-Received: by 10.98.60.20 with SMTP id j20mr69895894pfa.114.1469073207850; Wed, 20 Jul 2016 20:53:27 -0700 (PDT) Return-Path: Received: from mail-pa0-x22d.google.com (mail-pa0-x22d.google.com. [2607:f8b0:400e:c03::22d]) by mx.google.com with ESMTPS id cj15si7080613pac.175.2016.07.20.20.53.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2016 20:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c03::22d as permitted sender) client-ip=2607:f8b0:400e:c03::22d; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c03::22d as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pa0-x22d.google.com with SMTP id iw10so24497764pac.2 for ; Wed, 20 Jul 2016 20:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uy9J/Le9ur7lWMBZTRjZO3Q/bXjP9S8L2q8QpCYiOgE=; b=Q3un1noGo81utaMVkqVDxR567SFNvbzdP0LwtZrnkiDwbmXB3hB2DPzg1rkaQcYzcC EC/wdJx13i4qRKtLqkmxPelP1IRDX6vju93Wm6vMg7Kqj/1w5CwWJ7A8yFsiet+wbdC8 e0xI80nAyLAIk6MVqz0sORM8w4FTpWFvrDCJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uy9J/Le9ur7lWMBZTRjZO3Q/bXjP9S8L2q8QpCYiOgE=; b=gPKa+3baXeOpq4YnuF764cXQ9hyIWBOz1XdAJ+Kc2bshP8UpALrPwkBC0dC3lBJstk d3WyfSwrBYC+lC+brJk7vzv0DjzYzklaoqH7XCSQ3WIxD33O4cl0ZMFSaO3Ehervk8yx klcpMNx9ZsyjUW6z4wed9tQoHnniS7YK4cVh0nrjJycT7xtwsGL74bb9wtYKZjKIC/V4 VJxqiNI054Yrx2auoJ5F6DxLau+Aq473OaVNjXWeqp7hwecLukve3Pmgf1IaJIY6Th+Z nS3E9T3HhoK/lK/dQubAUkkyBGoI5kMbVIyeC9ScGcTdHy0NVXadTtsAu7qu7mbGvkIU T9Rw== X-Gm-Message-State: ALyK8tKvk08Ve3STA0Gfsg/H2yasUNIAd3651Ratozt1F1wRyCBNdI0QY+mu6ypMUHCMaOLQ1Q4= X-Received: by 10.66.135.40 with SMTP id pp8mr80786776pab.113.1469073207526; Wed, 20 Jul 2016 20:53:27 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id 84sm7773612pfp.59.2016.07.20.20.53.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Jul 2016 20:53:27 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Zhangfei Gao , Jingoo Han , Krzysztof Kozlowski , Maxime Ripard , Vinod Koul , Dan Williams , Mark Brown , Andy Green Subject: [PATCH 5/7] k3dma: Fix memory handling with cyclic mode Date: Wed, 20 Jul 2016 20:53:07 -0700 Message-Id: <1469073189-9167-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469073189-9167-1-git-send-email-john.stultz@linaro.org> References: <1469073189-9167-1-git-send-email-john.stultz@linaro.org> With cyclic mode, the shared virt-dma logic doesn't actually manage the descriptor state, nor the calling of the descriptor free callback. This results in leaking a desc structure every time we start an audio transfer. Thus we must manage it ourselves. The k3dma driver already keeps track of the active and finished descriptors via ds_run and ds_done pointers, so when we tear down everything in terminate_all, call free_desc on the ds_run and ds_done pointers if they are not null. NOTE: HiKey doesn't use the non-cyclic dma modes, so I'm not been able to test those modes. But with this patch we no longer leak the desc structures. Cc: Zhangfei Gao Cc: Jingoo Han Cc: Krzysztof Kozlowski Cc: Maxime Ripard Cc: Vinod Koul Cc: Dan Williams Cc: Mark Brown Cc: Andy Green Signed-off-by: John Stultz --- drivers/dma/k3dma.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) -- 1.9.1 diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c index 8e4c845..950ed36 100644 --- a/drivers/dma/k3dma.c +++ b/drivers/dma/k3dma.c @@ -219,6 +219,7 @@ static irqreturn_t k3_dma_int_handler(int irq, void *dev_id) spin_lock_irqsave(&c->vc.lock, flags); vchan_cookie_complete(&p->ds_run->vd); p->ds_done = p->ds_run; + p->ds_run = NULL; spin_unlock_irqrestore(&c->vc.lock, flags); } if (c && (tc2 & BIT(i))) { @@ -266,14 +267,14 @@ static int k3_dma_start_txd(struct k3_dma_chan *c) * so vc->desc_issued only contains desc pending */ list_del(&ds->vd.node); + + WARN_ON_ONCE(c->phy->ds_run); + WARN_ON_ONCE(c->phy->ds_done); c->phy->ds_run = ds; - c->phy->ds_done = NULL; /* start dma */ k3_dma_set_desc(c->phy, &ds->desc_hw[0]); return 0; } - c->phy->ds_done = NULL; - c->phy->ds_run = NULL; return -EAGAIN; } @@ -659,6 +660,15 @@ static int k3_dma_config(struct dma_chan *chan, return 0; } +static void k3_dma_free_desc(struct virt_dma_desc *vd) +{ + struct k3_dma_desc_sw *ds = + container_of(vd, struct k3_dma_desc_sw, vd); + + kfree(ds); +} + + static int k3_dma_terminate_all(struct dma_chan *chan) { struct k3_dma_chan *c = to_k3_chan(chan); @@ -682,7 +692,15 @@ static int k3_dma_terminate_all(struct dma_chan *chan) k3_dma_terminate_chan(p, d); c->phy = NULL; p->vchan = NULL; - p->ds_run = p->ds_done = NULL; + if (p->ds_run) { + k3_dma_free_desc(&p->ds_run->vd); + p->ds_run = NULL; + } + if (p->ds_done) { + k3_dma_free_desc(&p->ds_done->vd); + p->ds_done = NULL; + } + } spin_unlock_irqrestore(&c->vc.lock, flags); vchan_dma_desc_free_list(&c->vc, &head); @@ -735,14 +753,6 @@ static int k3_dma_transfer_resume(struct dma_chan *chan) return 0; } -static void k3_dma_free_desc(struct virt_dma_desc *vd) -{ - struct k3_dma_desc_sw *ds = - container_of(vd, struct k3_dma_desc_sw, vd); - - kfree(ds); -} - static const struct of_device_id k3_pdma_dt_ids[] = { { .compatible = "hisilicon,k3-dma-1.0", }, {}