Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1756421rwd; Fri, 9 Jun 2023 01:27:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xDsM1EV90c4SvpCOi7zukbgJPHlPV9L/xsX3CG7vfHSzeWSDmi7MjTHN6Jv/0w7nxpUos X-Received: by 2002:a17:90b:4b91:b0:255:2dde:17cc with SMTP id lr17-20020a17090b4b9100b002552dde17ccmr592734pjb.47.1686299264898; Fri, 09 Jun 2023 01:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686299264; cv=none; d=google.com; s=arc-20160816; b=oxzUkhMf+I8ihjwpEVAm7Adk+OWkSkjFfG0yqjL93blPf3he6B18Zc9psl8IuBOePV wKpCmfEKCp8ZJnaNQmKK/vtJ0zRbB0RKwRcHPy5sk2zj5/U+Zu6blV8xiAeYW3iyNs+5 Cg6wYkmX/GUFwgUo8CvgT2cUSr0FpLdAHFKGcLfZ1qCU6cEvcCPUDTzXvuG+0TAw6zeH ZG9emHohn+1S6V+yCm9iG4FU4O6LmXjdKbO6GkrZTtctr8Oehld4UmxJQFO5DxRpl1QT de6SlO0TY7GzxTxfHuMWVSAYZcYgpvFruQ4tmCi+H1n8YwzoXncLK0AFxdY6DBiE0rHm TtYA== 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=GiInZFwv5UYo7clt/bdC/mTWPa4mwyqkZum6ygvm/Fw=; b=P2cq2bfYG/A1l7h3GkqRy/lQ26y89EkE/DZ9X8UhDux9jKu0DKDmPWw7sMQV3t7Kb1 mr4LsjMMvK6drceKsfRZPRX+mnD4kVGPAtusSGkzsuXnTgK/myZCmLDbt9eRbtJ7tfmm AcrS0qzqlg4b3YVIcWiEZ8fchkRH7xJ8Msu68ScVg6Zy2qrbo6FmsZEycCI2pWebXqDM JdgTDcdpGuWNkwvU9CxyOYn880msFSjwuSC1TLLtGJA+ft0Ir2YhQiTcYrtRpcXAq1Xq UpSsDjhIJfJxS9XTuXq70hPqoYlGs33ci4uWaqkUfjjnQIPgmVh1Ip9uLi+Dc2yplmMW WZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AyqcItky; 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 j4-20020a170903028400b001b1a240b107si2384601plr.221.2023.06.09.01.27.31; Fri, 09 Jun 2023 01:27:44 -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=AyqcItky; 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 S240062AbjFIISL (ORCPT + 99 others); Fri, 9 Jun 2023 04:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240248AbjFIIRm (ORCPT ); Fri, 9 Jun 2023 04:17:42 -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 E052D30ED; Fri, 9 Jun 2023 01:17:10 -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=1686298626; 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=GiInZFwv5UYo7clt/bdC/mTWPa4mwyqkZum6ygvm/Fw=; b=AyqcItkyGQ0Nf2EBvxSv7WugPbRmP9c+lYLP5DnylOOr8hMKkR04j+iZovz+F6Wp8BgN4K ET+m7VZ0WgduGkgYOcPMuMqDxIVP+PNQrSlLNi4t0J1I+/AytTqLR2bQFKNO209gvp0Htg 9WMvMBFy4d8MOHdOxVGKE6vXYLXDZcmazPW/t9fcwyhtvw8FuhVmImdrZIM40u8dC6Ucdp CZGdkSsHQRfsfGUbqqUqYjvyTDiG14dPadFX4RcVyQKcKhWwoqYZigiB/5mKNXQ9ecNTyY Dy67EsthO1953HjstPMYiuPVjHBQR7CDYyvMiHlnDfEpdnxQQVLZQLoxUrY7lg== 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 BD163C0014; Fri, 9 Jun 2023 08:17:05 +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 9/9] dmaengine: dw-edma: eDMA: Fix possible race condition in local setup Date: Fri, 9 Jun 2023 10:16:54 +0200 Message-Id: <20230609081654.330857-10-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: 7e4b8a4fbe2c ("dmaengine: Add Synopsys eDMA IP version 0 support") Signed-off-by: Kory Maincent --- This patch has not been tested since I don't have board with eDMA in local setup. --- drivers/dma/dw-edma/dw-edma-v0-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-v0-core.c b/drivers/dma/dw-edma/dw-edma-v0-core.c index a5d921ef54ec..612c8c49668f 100644 --- a/drivers/dma/dw-edma/dw-edma-v0-core.c +++ b/drivers/dma/dw-edma/dw-edma-v0-core.c @@ -284,10 +284,13 @@ static void dw_edma_v0_write_ll_data(struct dw_edma_chunk *chunk, int i, if (chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL) { struct dw_edma_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_edma_v0_lli __iomem *lli = chunk->ll_region.vaddr.io + ofs; @@ -306,8 +309,11 @@ static void dw_edma_v0_write_ll_link(struct dw_edma_chunk *chunk, if (chunk->chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL) { struct dw_edma_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_edma_v0_llp __iomem *llp = chunk->ll_region.vaddr.io + ofs; -- 2.25.1