Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1018630ybe; Thu, 19 Sep 2019 07:27:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh98BkJ52EXiXVWmCvBKQYJkLxvH4qSlVgM/d9M1dzOulfLfTMo4QqXAqgKJqX2pK2N3a+ X-Received: by 2002:a05:6402:16d5:: with SMTP id r21mr16181764edx.71.1568903273292; Thu, 19 Sep 2019 07:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568903273; cv=none; d=google.com; s=arc-20160816; b=Jvw9pSpbma2ppssJhv7x0FwsUNDbBv2WR7zA7nqJzlA7yqGt2d5HoxZs+gzZfObuG6 7tOax3t5TdNwW/zo4pmfJlskhJjydI617o/KNcZNk4kU+XIhmar3jgpxuXwUTBV48skM I0R5/Zuh8+jPWMAYYe63MBKiwm316Hq1FNnAyQLKCZ0F4iVpZPKVKstW4jUT41VJJimB YGM4gWHL4+lXodVa2z0m8UxnFWlB56JEBJG7gI0l1wodUsHhGBgMFpBU1ggw5swqusdy 59h2M3pgvtUsU9+RkGAttdrYjv7efM/9sE544XNroJOqUA1dWWjvhcpyurK8SOHrDSBz 3o3Q== 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=XsDy0Vb/NDE2r0fywV0lPNOxYSyjvsjvG6zB5e9vwb4=; b=KW2kuGWeDu8DLxGOJAYoWIFDoIwpJ9u3sLdpXLPIK5N1CBvVyOe6Mi1208ztO3CwlC MqoMlF7ZuoTFBGvGDm0P9wpE7RJ2yYcyjzZkmMojxZNeY2RXP0PZunjXHYB8fARtu2Ep QDgBMC+edn5OCWJVdZ5DgbQvXxOtLKd/AaoKxT+7QSmkDGObLouueEVIF+GYgXOgyuLt nwuStGglsvfZDmWJzGUJ9ja/sYN7NFa5iZmsBNPMxnG7Dp4q9Q00BKATQTYdUfTf8kNg Ugj0bSvzBKNBZafrYJwme5VUQSDwl4CJ9C2ZjbxCMr93mb61wkdfuYnRm23spDFCsM4t zZDA== 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 w12si5226679edx.223.2019.09.19.07.27.29; Thu, 19 Sep 2019 07:27:53 -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 S2389097AbfISKpc (ORCPT + 99 others); Thu, 19 Sep 2019 06:45:32 -0400 Received: from mx1.emlix.com ([188.40.240.192]:57714 "EHLO mx1.emlix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388122AbfISKpc (ORCPT ); Thu, 19 Sep 2019 06:45:32 -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 73100603DE; Thu, 19 Sep 2019 12:45:30 +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 v3 1/3] dmaengine: imx-sdma: fix buffer ownership Date: Thu, 19 Sep 2019 12:45:24 +0200 Message-Id: <20190919104526.29851-2-philipp.puschmann@emlix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190919104526.29851-1-philipp.puschmann@emlix.com> References: <20190919102319.23368-1-philipp.puschmann@emlix.com> <20190919104526.29851-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. Fixes: broken since start Signed-off-by: Philipp Puschmann --- Changelog v3: - use correct dma_wmb() instead of dma_wb() - add fixes tag 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_wmb(); + bd->mode.status |= BD_DONE; + if (error) sdmac->status = old_status; } -- 2.23.0