From patchwork Wed Dec 18 19:09:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 182027 Delivered-To: patches@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp1285145och; Wed, 18 Dec 2019 11:09:10 -0800 (PST) X-Received: by 2002:a17:902:7484:: with SMTP id h4mr4453202pll.74.1576696150226; Wed, 18 Dec 2019 11:09:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576696150; cv=none; d=google.com; s=arc-20160816; b=g/t98ZQxwEyDnpDk+YZtWpHTa4Qup1ZmUbGXThS6+57jSuF+pP13sayAbnWa2dqn+Q wIDfykRaT8VBXbpAycGrfuRxzCgEYK5qsZhgvczcZeW2QJHlgwq6ORDvSOcrxZ0bjGU6 uUd6QPi3UYpyPZa0ETG0hYJi75lwDMlXDOSfL5c/0S8eGmhRmnU1mZoqfqWrMOV24BFb Cjtx3+0yvbXwQPXrmPKcYbkgHKZC4j3iVL/IAN0L/vvi54inS7Vj5sxBiEpF3Bfl4CPB QAgoGnragOf2AeCWiEqu6mNduXE2LQfcGHz8ho1LlvAf18dxFzi2SiPZ3J2ALabG0xWu GlMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=j0zBkq0VgJoL6PSpb9mhqIxD+Izq0jA3YTPBw0iDOVI=; b=g+hT0c5xGxXihK78mvjaBEk3JiX8TVUHdinuFiFCgZR6E0iW2Fhflu79bSKP8UhiqV H8cJduHgogITBR7BRMZUYY3Z66mH/CITCb94wgnPf4QGsrulSjoES+eK3Stl1yG5UXhX KwUgdEl7SpkbsuVDhQVXzqE47XtUX7a9ntuqpnEYmwfux/TXWvREujDGYcN9hoKWFydz w4TLv58zhEVAkQonoTUy2hmrGX7DVVIELHe9xSYgB7AH2vqZQwU1K9oXJCpuyOf3PqrO n0clSOa++jBEju+0dU0p/4JoUoYsHiFOsJaPBSLqo9NnOd/1oWTOJacM3VnIApo08Mwd ouDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cpQOKq46; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t24sor3742019pfh.19.2019.12.18.11.09.10 for (Google Transport Security); Wed, 18 Dec 2019 11:09:10 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cpQOKq46; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=j0zBkq0VgJoL6PSpb9mhqIxD+Izq0jA3YTPBw0iDOVI=; b=cpQOKq46F3NoaI609tjoxOTU4bqZ6/gguyChGCfNtNNp+G9VmpWSMl3ctH9P3EEHOt SUDVzO2PqPC+yeJFDiQSXPvK1akjj7zKG55VVCamYt+/1mymm5EY8Bsg/+tyRSnk717B bb/DOkEwp52gHt5Xx8ueGKentiKKJkzpKsnjs4xxo/bZynRzSehP+skC+Y9HYTMxGwDj eqLFU9QXeHAU3MaMuWqvVt7nMCi3+kQYStuaPygHgwsgQD2td4jjVS/zvexgb6ElB1/9 Jsf4OukzbhjBfubeQCH038G2vSBZ1odepyBe02+V0UBagJQdzpwoX5iXNUDn2nFFaQIM QfVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=j0zBkq0VgJoL6PSpb9mhqIxD+Izq0jA3YTPBw0iDOVI=; b=ozNcKA21uWfr0PpY5M+vqfaoIPfV/K1Hpq0gYpwjcDusZKx+oodj4ZSx04XsEadEnG jcLCcC4CeSlHYl5PY1FFSy0hKGFxFSiQeCGZSJnrfSF6DiGnMpn6rhEbbgPGoCXg1Pm4 l1r/8wVP/IyhGU95vKdsW3SSjw9DCNsBn2lMw8UeeLr8YoTfAtlAuEfPd78ltojNaQPr TDhHnzfSdPW1l4Z2M3M5nqIHGWZrIkHhcdF4F3HDF9kTylXf6pkhOSafRODqOevuNzR/ m0XEnfuUZqb1a/nov59Od2dYENorwznP85oiuE+AsZPIRH62/vt0uhsFYM/3tHAy6Wth aCtA== X-Gm-Message-State: APjAAAUDPNvt2qQvuJ5EGey7SsSQYREytQmIZzFwbQ8VU1KgPmD497QV TWzDnCUy/3HpKqjiq4zYuJirKKTP X-Google-Smtp-Source: APXvYqxHKPx9oJncAqOZSvlZDU+b6hC8CJR05VxvwFjY+yLFMVdyoo1P4k1hS1WOwawqq6M7cbqOFQ== X-Received: by 2002:aa7:8299:: with SMTP id s25mr4610914pfm.261.1576696149859; Wed, 18 Dec 2019 11:09:09 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id r6sm4376396pfh.91.2019.12.18.11.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2019 11:09:09 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Vinod Koul , Dan Williams , ryan@edited.us, aserbinski@gmail.com, dmaengine@vger.kernel.org Subject: [PATCH] k3dma: Avoid null pointer traversal Date: Wed, 18 Dec 2019 19:09:06 +0000 Message-Id: <20191218190906.6641-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In some cases we seem to submit two transactions in a row, which causes us to lose track of the first. If we then cancel the request, we may still get an interrupt, which traverses a null ds_run value. So try to avoid starting a new transaction if the ds_run value is set. While this patch avoids the null pointer crash, I've had some reports of the k3dma driver still getting confused, which suggests the ds_run/ds_done value handling still isn't quite right. However, I've not run into an issue recently with it so I think this patch is worth pushing upstream to avoid the crash. Cc: Vinod Koul Cc: Dan Williams Cc: ryan@edited.us Cc: aserbinski@gmail.com Cc: dmaengine@vger.kernel.org Signed-off-by: John Stultz --- drivers/dma/k3dma.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c index adecea51814f..c5c1aa0dcaed 100644 --- a/drivers/dma/k3dma.c +++ b/drivers/dma/k3dma.c @@ -229,9 +229,11 @@ static irqreturn_t k3_dma_int_handler(int irq, void *dev_id) c = p->vchan; if (c && (tc1 & BIT(i))) { spin_lock_irqsave(&c->vc.lock, flags); - vchan_cookie_complete(&p->ds_run->vd); - p->ds_done = p->ds_run; - p->ds_run = NULL; + if (p->ds_run != NULL) { + 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))) { @@ -271,6 +273,10 @@ static int k3_dma_start_txd(struct k3_dma_chan *c) if (BIT(c->phy->idx) & k3_dma_get_chan_stat(d)) return -EAGAIN; + /* Avoid losing track of ds_run if a transaction is in flight */ + if (c->phy->ds_run) + return -EAGAIN; + if (vd) { struct k3_dma_desc_sw *ds = container_of(vd, struct k3_dma_desc_sw, vd);