Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1051184ybe; Thu, 19 Sep 2019 07:58:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0dUHSuqft1RgeTbt0Go6fZKeowdiEaKtME6ZZbFRye+vQ9CSm8WOXt65ntqsiNLxX2Di8 X-Received: by 2002:a50:b0c5:: with SMTP id j63mr2866073edd.90.1568905105634; Thu, 19 Sep 2019 07:58:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568905105; cv=none; d=google.com; s=arc-20160816; b=Ujr3VfFqEOFIZ7nvbo/6FNY1sjn8bKAO0pnAIaZNZZK6wQYRRK8hbaibjtqFoCNjKr ZVR+L0aRUFy8GbjRJfSJXLJiXzB7KBjfInTxzVoth/h1zl5I9ZmHaqhKoPo9ikJliZRe NP5NM6tc0+O9sL7YgZoLRrDviPv4PcJ8gXiMRBs4grIwte9yNfREzZrr+SetK5lXQ/05 Ce/FO4sPA20WGypTsTcKIiaSt4+Uyusl3JdHn7i1PYxbJClOoqM3MuwEL0WyRDLA4MUZ euWbEme0mLJ0eoGokwpMVBLtByVpVrxmlvIZJhVmIVaiqhLDHmLfy5YYm/9x9A3UQFAD W39w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ml6pvbBnWX+tVbs/3qAUrpicdkDWNyG6qZLKZKGdsPg=; b=Uw55Zf/qDRGORTtUL2fQE/qC65yGxkq5+DvaViGfuQvfqVZsgOeX1O0EsbgZ7+a70b UKnxgXQUnN+srVYCBcBmPk8kYKnLFUOxBq5kRtuaK2cpW8EmVP4zww9wh1veBUVDHCRE J21rC+m3Dwbi3oI16LXihlPEGXKSDOmbJHrYFu3HLx5OmTn/hq6AT7lzOl0AvDxUiQTm y7WlKVR+vWehhOKqwyV4z6jvMrWQBtWUAEXzn/RNCGpuKlIGUZtsZsg4K8Vsjz+bsW2G 8eT2VCUiYFD5yAq5bceEmQVkSfJnrGfawnRk9YdPDN8CPdKD/qWWcV4NYi2cVEB6cnG1 KpbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si4892043ejq.44.2019.09.19.07.58.00; Thu, 19 Sep 2019 07:58:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389123AbfISKXm (ORCPT + 99 others); Thu, 19 Sep 2019 06:23:42 -0400 Received: from mx1.emlix.com ([188.40.240.192]:57554 "EHLO mx1.emlix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389098AbfISKXl (ORCPT ); Thu, 19 Sep 2019 06:23:41 -0400 Received: from mailer.emlix.com (unknown [81.20.119.6]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id C61E56038C; Thu, 19 Sep 2019 12:23:39 +0200 (CEST) From: Philipp Puschmann To: linux-kernel@vger.kernel.org Cc: yibin.gong@nxp.com, fugang.duan@nxp.com, l.stach@pengutronix.de, dan.j.williams@intel.com, vkoul@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, dmaengine@vger.kernel.or, linux-arm-kernel@lists.infradead.org, Philipp Puschmann Subject: [PATCH v2 1/3] dmaengine: imx-sdma: fix buffer ownership Date: Thu, 19 Sep 2019 12:23:17 +0200 Message-Id: <20190919102319.23368-2-philipp.puschmann@emlix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919102319.23368-1-philipp.puschmann@emlix.com> References: <20190911144943.21554-1-philipp.puschmann@emlix.com> <20190919102319.23368-1-philipp.puschmann@emlix.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BD_DONE flag marks ownership of the buffer. When 1 SDMA owns the buffer, when 0 ARM owns it. When processing the buffers in sdma_update_channel_loop the ownership of the currently processed buffer was set to SDMA again before running the callback function of the buffer and while the sdma script may be running in parallel. So there was the possibility to get the buffer overwritten by SDMA before it has been processed by kernel leading to kind of random errors in the upper layers, e.g. bluetooth. Signed-off-by: Philipp Puschmann --- Changelog v2: - add dma_wb() drivers/dma/imx-sdma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 9ba74ab7e912..e029a2443cfc 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -802,7 +802,6 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac) */ desc->chn_real_count = bd->mode.count; - bd->mode.status |= BD_DONE; bd->mode.count = desc->period_len; desc->buf_ptail = desc->buf_tail; desc->buf_tail = (desc->buf_tail + 1) % desc->num_bd; @@ -817,6 +816,9 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac) dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL); spin_lock(&sdmac->vc.lock); + dma_wb(); + bd->mode.status |= BD_DONE; + if (error) sdmac->status = old_status; } -- 2.23.0