Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1004596ybe; Wed, 11 Sep 2019 08:00:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwS7uzfZeoLknurxWNgOxqWr52/DIxRG4umyi9PwgmZ8I5zaFLypmuVA2E192xSBMHHDvVC X-Received: by 2002:aa7:d5cb:: with SMTP id d11mr37492969eds.250.1568214043557; Wed, 11 Sep 2019 08:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568214043; cv=none; d=google.com; s=arc-20160816; b=TLWGKng30F/lGhAF9LBtZG82Cpw1NjsAKMZ/8pl3iVTwbWpQom0nY+IZhvkiyFKgbU sM1h7803IUiG8e1vBo5al/vNMDPhe9GCdcKcgLB8/bQ5Vh4P2nWI4BmQ70bNlOR99EPb mh0jCDMOkrGDSQY7h7J3gZ7M/rNU2WLWUKIf+uQIDjOW0Jx3mt29BY1lOpALK0VvzlLZ +ZVYjcCQEBnRv27GdNofXXliYtMdVt0iEVCUFtHxs/pEcyZ8SWm7EDHzWWlth4fmdNzs A1VV5PwdqfHGe3qwE270Rr/UKuqXJXuWKuXhFiF/z4k7I1qRZdXaCdTYe6bAv3EF+BR9 L7ZQ== 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=w1furLj8DwM2cpgGJBV80Gsuoz7jzzScQBXiVwsZLIc=; b=BCw1evL5j7EZE6sIegG8RSYWCEiqVi74P9NrW4soobWEG8ph9loZjiTT7WVM3yc3+H j7Gs4YMVr6sDtxy2lcl6J2MG7ZQjhiqp0AJJtNBZlMN8RdpAEbodnP4Q1gmhbMzjFG+e UpfHBGgqXPfAOhe7DYWagGeBX85fBGWFM53KYWdjo+M+wkBw1AFMAgX16ESoQQgpQip1 /vg5KARE5nRF7MyodtZgbUDPzXoEQ4YjNkvc7Ep3NhJbtgVg4a4tOKFz9Qt0d6xAO5JO e0U/c6c1GJt/coU9bC+5UUEOoEJmp209r/yfcmSOQxrRgX8jGnQJu5knwdHn4upcLH+u 2ItA== 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 c9si12209459eda.229.2019.09.11.08.00.19; Wed, 11 Sep 2019 08:00:43 -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 S1728306AbfIKOzk (ORCPT + 99 others); Wed, 11 Sep 2019 10:55:40 -0400 Received: from mx1.emlix.com ([188.40.240.192]:37216 "EHLO mx1.emlix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728198AbfIKOzk (ORCPT ); Wed, 11 Sep 2019 10:55:40 -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 BC6E95FC57; Wed, 11 Sep 2019 16:50:00 +0200 (CEST) From: Philipp Puschmann To: linux-kernel@vger.kernel.org Cc: vkoul@kernel.org, dan.j.williams@intel.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, gregkh@linuxfoundation.org, jslaby@suse.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, Philipp Puschmann Subject: [PATCH 1/4] dmaengine: imx-sdma: fix buffer ownership Date: Wed, 11 Sep 2019 16:49:40 +0200 Message-Id: <20190911144943.21554-2-philipp.puschmann@emlix.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190911144943.21554-1-philipp.puschmann@emlix.com> References: <20190911144943.21554-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 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. It may be further a good idea to make the status struct member volatile or access it using writel or similar to rule out that the compiler sets the BD_DONE flag before the callback routine has finished. Signed-off-by: Philipp Puschmann --- drivers/dma/imx-sdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index a01f4b5d793c..1abb14ff394d 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,8 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac) dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL); spin_lock(&sdmac->vc.lock); + bd->mode.status |= BD_DONE; + if (error) sdmac->status = old_status; } -- 2.23.0