Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1756459rwd; Fri, 9 Jun 2023 01:27:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58DEBrtyddvoRhK3+lDS+xevryoZAGf9f0f76jszGII/8nHiHl5PGSETsw6SYXl3QLyVYp X-Received: by 2002:a05:6808:907:b0:399:dd46:d561 with SMTP id w7-20020a056808090700b00399dd46d561mr997827oih.48.1686299267606; Fri, 09 Jun 2023 01:27:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686299267; cv=none; d=google.com; s=arc-20160816; b=zbLTihbk53Pc02o+EAhqerg6SM9QUUKM0gq93GKg+R3dTFi+qlV7OnAbrhhEB8YjLQ OABxgIDuqYXIc/uJfzBCY7E4kK3gv3gYB9Q+8t76WMxHA9Mb7kSRE7sN6ZFzsSMvC5f1 qdYdHi7SdP1NmX+NgWshfjXFe/PiBwh9F7BY4qq+LP09ktaouswzEnUZ+awYqBbP8I0I 0PNI+Js5Hh6u/9uyEb2ngdr60bfLx8bz7AW4KKvkkfYcIwCrb8qwE8QGiOqbCZpB6WIw aXhGMPgddx+8gNfLag3cZwA+3SPhkuOSAM69EnommRMdg0by2Cq+knLIIN0Z26Wz006I py/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oCPB9Nf3YZqvG1rzu67yQSLPi8ZPt/80c1MDnzGqrYE=; b=EpvXezyyifM6QkEqVKOA5iLkHYr77EnlRopb6B5dPJq3rweXCjznWSPBMykR9wpeZz 0oSsXgMrBUaCHyesRnMsBMw+QVbyPWDMke98765xLCRphUrSurOwfHs2wIZAiTyZXLHG pAtcRj+3/OxOhNqvqgAQpa9aQfe7xdp25TZ7usny0jzMDwROtO0n2Cnm0OqqBSj2iFun cvM6tVGL89lTZpjE5nk9JSpCtUsv0t+Y6YwhuMlqSzeUVIEWV3pTR6c9uJdpK+fkNi1+ Fwmfxg7QfKmW/8BGTdp6mlkmJ3zY80AHltLvtru+tfaDPMCy9Hak7XTQipDpz//KfrjT PqKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=d+AW7Tcb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a625305000000b0066215192dd4si2110847pfb.295.2023.06.09.01.27.34; Fri, 09 Jun 2023 01:27:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=d+AW7Tcb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240196AbjFIISH (ORCPT + 99 others); Fri, 9 Jun 2023 04:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240207AbjFIIRk (ORCPT ); Fri, 9 Jun 2023 04:17:40 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10EDD2D7B; Fri, 9 Jun 2023 01:17:06 -0700 (PDT) X-GND-Sasl: kory.maincent@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686298623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oCPB9Nf3YZqvG1rzu67yQSLPi8ZPt/80c1MDnzGqrYE=; b=d+AW7TcbsOXUczeTbAj0+f1hTV3cgIhoVMCMFoZUmd4pq1hiPoV7nM3TWzrjrDqXxJGIBH WCZWVzTHH9uIxpnW0agbTU70MjQKdEYkKJ7vevRIvaRfuuQTAlh3+AjAuDTXNqoRf/Ziza eN7Wrz+IPBv6JEfNn2zGCeCXpUmJ2U/Gz1N8NZRZLCTIlfidyUzxTmRk6N/v4VZSBzDLVV YQ4nYhGhNZ/Bcis2Jav4orHvVEQbrbBBMLhx3HI39x/F0zCUpGZ99YnFbF/PquYBo7Zmvl c476gy+A60kmmPotp6HPPLqNwdZkIBglcWZEx62DbPGosO0elJnd8DGVeg1lSw== X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com X-GND-Sasl: kory.maincent@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 47970C0010; Fri, 9 Jun 2023 08:17:02 +0000 (UTC) From: =?UTF-8?q?K=C3=B6ry=20Maincent?= To: Cai Huoqing , Manivannan Sadhasivam , Serge Semin , Vinod Koul , Gustavo Pimentel , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Thomas Petazzoni , Gustavo Pimentel , Herve Codina , Kory Maincent Subject: [PATCH 6/9] dmaengine: dw-edma: HDMA: Fix possible race condition in local setup Date: Fri, 9 Jun 2023 10:16:51 +0200 Message-Id: <20230609081654.330857-7-kory.maincent@bootlin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230609081654.330857-1-kory.maincent@bootlin.com> References: <20230609081654.330857-1-kory.maincent@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Spam-Score: 300 X-GND-Status: SPAM X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kory Maincent When writing the linked list elements and pointer the control need to be written at the end. If the control is written and the SAR and DAR not stored we could face a race condition. Added a memory barrier to make sure the memory has been written. Fixes: e74c39573d35 ("dmaengine: dw-edma: Add support for native HDMA") Signed-off-by: Kory Maincent --- This patch has not been tested since I don't have board with HDMA in local setup. This patch is fixing a commit which is only in dmaengine tree and not merged mainline. --- drivers/dma/dw-edma/dw-hdma-v0-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dw-edma/dw-hdma-v0-core.c b/drivers/dma/dw-edma/dw-hdma-v0-core.c index f28e1671a753..d3c70500496c 100644 --- a/drivers/dma/dw-edma/dw-hdma-v0-core.c +++ b/drivers/dma/dw-edma/dw-hdma-v0-core.c @@ -155,10 +155,13 @@ static void dw_hdma_v0_write_ll_data(struct dw_edma_chunk *chunk, int i, if (chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL) { struct dw_hdma_v0_lli *lli = chunk->ll_region.vaddr.mem + ofs; - lli->control = control; lli->transfer_size = size; lli->sar.reg = sar; lli->dar.reg = dar; + + /* Make sure sar and dar is written before writing control */ + dma_wmb(); + lli->control = control; } else { struct dw_hdma_v0_lli __iomem *lli = chunk->ll_region.vaddr.io + ofs; @@ -177,8 +180,11 @@ static void dw_hdma_v0_write_ll_link(struct dw_edma_chunk *chunk, if (chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL) { struct dw_hdma_v0_llp *llp = chunk->ll_region.vaddr.mem + ofs; - llp->control = control; llp->llp.reg = pointer; + + /* Make sure sar and dar is written before writing control */ + dma_wmb(); + llp->control = control; } else { struct dw_hdma_v0_llp __iomem *llp = chunk->ll_region.vaddr.io + ofs; -- 2.25.1