Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1237548rdb; Wed, 20 Sep 2023 03:49:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxKPiMb0YFXmoNNDAbIIpITX5aSsjb5S8VAwsjKnwBDWbaeVqRpmVm4jCu4I7eRosM9mxX X-Received: by 2002:a05:6358:9913:b0:143:3845:e6fb with SMTP id w19-20020a056358991300b001433845e6fbmr2748136rwa.27.1695206995282; Wed, 20 Sep 2023 03:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695206995; cv=none; d=google.com; s=arc-20160816; b=uWD5xnwvoU32N3LrbR3P7N71b6AAR8KlqjemdK8nbO3W10vLDmKe15Bgzw3Df46+Vq Rc5cJr/ztrC/dnNeK/WD4hVbQS9Lq3dWeRSJBu3UFwEph00FC4gwhOglcTSAP9TVbpjo DabFfamwohCcZEwH2sFYbcEQdqyXmp3tH5aEPqmB4pPXpClzU0QI8GD6QQ9meR6NJk0A s9kSxkLCFk+XQkRMywabeECo0JZ0N8nWSvZxfq0BRa/V6IHyQSXKLb3n2vtDdGUAzH8L DBO89NUl6kAQpzEVhPeCieOT6zK3RAXkPgq82ym1VRMS5c42MdqsLhORkhLQE7XpzgjT C5Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wh8p6sU/xrwX5Uzxw8YXWXg8fjaVMxC0qRKFN8RkOcs=; fh=G+5L1fACim1Tf0rbpuPbTku1YB/Lxo4mDPElvS1kQDE=; b=ZWj0Wjhyp3smUqcur2vlMCrwj6QIiBoQz1OF07FrvxQfz91DmCiGFiNahmV8ospVJ6 u27cAYMRj/ThWB0Er3sEy6dtUfI2t2dR2eqKGrv/SPn98yCTJoAVKbFYlshq6CKmaIDb n416SSZ+n1Qytj+pnMiMBuo5svQJb26jBlj9dPKbbgVmYbd/c1owdDqIpFlbS3D2DopU Yq7H/Roqbgzu/HvK32j6tXfYINroBeNASHnlbcH6FrviNkCDD62SFOGfR328XD8uwiRY otXE0KKipUafP+qg2vctAQCbsb51SlcE2DxI3bYuE2UU4qANK6liP24XNGyBKkq+PyUA nPVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t186-20020a6381c3000000b00578a2438d6asi3740881pgd.209.2023.09.20.03.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 03:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E03FD806E5E7; Wed, 20 Sep 2023 03:46:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234381AbjITKpt (ORCPT + 99 others); Wed, 20 Sep 2023 06:45:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234307AbjITKpY (ORCPT ); Wed, 20 Sep 2023 06:45:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DDE0197; Wed, 20 Sep 2023 03:45:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3628BC433CB; Wed, 20 Sep 2023 10:45:01 +0000 (UTC) Date: Wed, 20 Sep 2023 11:44:58 +0100 From: Catalin Marinas To: Jan Bottorff Cc: Yann Sionneau , Wolfram Sang , Serge Semin , Yann Sionneau , Will Deacon , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jan Dabros , Andi Shyti , Philipp Zabel , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] i2c: designware: Fix corrupted memory seen in the ISR Message-ID: References: <37e10c3d-b5ab-75ec-3c96-76e15eb9bef8@sionneau.net> <9de89e14-35bd-415d-97f1-4b6db1258997@os.amperecomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 20 Sep 2023 03:46:10 -0700 (PDT) On Tue, Sep 19, 2023 at 11:54:10AM -0700, Jan Bottorff wrote: > On 9/19/2023 7:51 AM, Catalin Marinas wrote: > > While smp_* is ok, it really depends on what the regmap_write() does. Is > > it a write to a shared peripheral (if not, you may need a DSB)? Does the > > regmap_write() caller know this? That's why I think having the barrier > > in dw_reg_write() is better. > > > > If you do want to stick to a fix in i2c_dw_xfer_init(), you could go for > > dma_wmb(). While this is not strictly DMA, it's sharing data with > > another coherent agent (a different CPU in this instance). The smp_wmb() > > is more about communication via memory not involving I/O. But this still > > assumes that the caller knows regmap_write() ends up with an I/O > > write*() (potentially relaxed). > > If we wanted maximum correctness wouldn't we need something like > writel_triggers_interrupt/regmap_write_triggers_interrupt or maybe > preinterrupt_wmb? Well, if you want to have an API for all things that can be triggered (interrupts, device DMA), you can try but I think it would make things more confusing and driver writers won't bother (if, say, they only test on x86 and never see a problem). The other way around - barriers by default and only relax if you see a performance issue - seems more sensible. But I don't maintain these drivers, so it's up to you guys. > The ARM docs do have a specific example case where the device write triggers > an interrupt, and that example specifically says a DSB barrier is needed. Yeah, the Arm ARM is not very precise here on what the mailbox is, whether it's a local or shared peripheral and they went for the stronger DMB. Will added a good explanation on why a DMB is sufficient in commit 22ec71615d82 ("arm64: io: Relax implicit barriers in default I/O accessors"). It talks about DMA but it applies equally to another CPU accessing the memory. It's pretty subtle though. > If I look at the ARM GIC IPI send function gic_ipi_send_mask in > https://elixir.bootlin.com/linux/v6.6-rc2/source/drivers/irqchip/irq-gic-v3.c#L1354 > is says: > > /* > * Ensure that stores to Normal memory are visible to the > * other CPUs before issuing the IPI. > */ > dsb(ishst); > > I would think the IPI send code is very carefully tuned for performance, and > would not use a barrier any stronger than required. That's why I mentioned in my previous reply that it really depends on what the regmap_write() does, where the I/O go shared peripheral or some local CPU interface). In the GIC example above, there's not even an I/O access but a system register write (MSR, see gic_write_sgi1r()), hence the DSB. If you look at gic_ipi_send_mask() in irq-gic.c (GICv2), there is a dmb(ishst) since the interrupt is sent with an I/O write to the GIC distributor (shared peripheral). > I believe dma_wmb maps to DMB on ARM64. Yes, it does. -- Catalin