Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp532391rdb; Tue, 19 Sep 2023 02:58:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE//vajb+LT6yv3dRvhCgXsUihOCQf8ydJZtHuvqG9DvgevMndP98OsBJQWqSbc5uZ4IRhv X-Received: by 2002:a17:90a:4610:b0:26b:280b:d24c with SMTP id w16-20020a17090a461000b0026b280bd24cmr10456902pjg.42.1695117498116; Tue, 19 Sep 2023 02:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695117498; cv=none; d=google.com; s=arc-20160816; b=tmhs0zg01ib0tz4wpySBJIw54Lmy+AmqMLDegAqybFWKbd4sUPuZeElQORXJAIgQ/v riVjdcKdNU/U6RPX2gjEIRntiTMzPSzZx7deCet5VJWlJLTGQXjVJQ0UYKV9+m0BYMsp LN/MTEsXSrocCcYpdunC5jMFrMpxtmAED05Ayd4Qw2JFdcIglTzEiF8OfySYXNj27dYR fYwlV/L4L/oxwAEnEMmhfmrBpsEx4CxHVFwNK4T0u8XtrfbzTdXttk72TOV7Dwy07yNT rmidHRPQivnoscGA+kRrhNUqkoKuXbQp2GAnOtgVPl2N7f92gvkgo2AyAFxSTwih3uzx jnhQ== 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=BWoUBveiSFqQzhxCjNm1GElTgZIIXhfPb18+qgeU6BA=; fh=2lAgkii+Pm2y38awX2YcoINp4XCeosiiqR7dYThf+i8=; b=Intd70KYrpWk/1MpsFe6iocw+EmwG1I/3UYLPdwdkP/p14g4r11+Z0c8/P7hsFAbil ex1uOXV7Vb9pA7bGU3mBFcbb7x7/sP9EKjsiVVl83KB6HO86zSgiwGwto2Eo54xxQqZP jB0oSVetZSr1GlK8PIwDXkJ19AoM50+xWMS1t5r733kVB7ElsO5ET1RIjYxWgWYPz1z5 aYwqCXF3DySoB0+WVnrqJnOQgS5aaCeR7TJdCPZo5mGEh1tQEI66jOMp2tDHQK4i9fHn yGqJ1n/kwOkCRzASBphlBscBoymdeT6ecRDT3wZH1wGOP7dtpOi7sVgqFtc2mL0Lqbf5 UJqw== 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:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id qe13-20020a17090b4f8d00b00273dfe0741csi12066414pjb.90.2023.09.19.02.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 4923A80DE61A; Tue, 19 Sep 2023 02:57:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231808AbjISJ46 (ORCPT + 99 others); Tue, 19 Sep 2023 05:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjISJ4r (ORCPT ); Tue, 19 Sep 2023 05:56:47 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A393F1990; Tue, 19 Sep 2023 02:55:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BCBEC433C8; Tue, 19 Sep 2023 09:55:26 +0000 (UTC) Date: Tue, 19 Sep 2023 10:55:23 +0100 From: Catalin Marinas To: Jan Bottorff Cc: 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, Yann Sionneau Subject: Re: [PATCH v2] i2c: designware: Fix corrupted memory seen in the ISR Message-ID: References: <20230913232938.420423-1-janb@os.amperecomputing.com> <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: <9de89e14-35bd-415d-97f1-4b6db1258997@os.amperecomputing.com> 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:57:01 -0700 (PDT) On Mon, Sep 18, 2023 at 08:45:42PM -0700, Jan Bottorff wrote: > > > > > > > diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c > > > > > > > index ca1035e010c7..1694ac6bb592 100644 > > > > > > > --- a/drivers/i2c/busses/i2c-designware-master.c > > > > > > > +++ b/drivers/i2c/busses/i2c-designware-master.c > > > > > > > @@ -248,6 +248,14 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev) > > > > > > > /* Dummy read to avoid the register getting stuck on Bay Trail */ > > > > > > > regmap_read(dev->map, DW_IC_ENABLE_STATUS, &dummy); > > > > > > > > > > > > > > + /* > > > > > > > + * To guarantee data written by the current core is visible to > > > > > > > + * all cores, a write barrier is required. This needs to be > > > > > > > + * before an interrupt causes execution on another core. > > > > > > > + * For ARM processors, this needs to be a DSB barrier. > > > > > > > + */ > > > > > > > + wmb(); [...] > I did find the below text in the Arm Architectural Reference Manual (DDI > 0487I.a) section K13.4 "Using a mailbox to send an interrupt". It was nearly > the same wording as the ARM barrier document I previously referenced at > https://developer.arm.com/documentation/genc007826/latest/ This too says a > DSB barrier is required for memory updates to be observable in the ISR. > > " > K13.4 Using a mailbox to send an interrupt > In some message passing systems, it is common for one observer to update > memory and then notify a second observer of the update by sending an > interrupt, using a mailbox. Although a memory access might be made to > initiate the sending of the mailbox interrupt, a DSB instruction is > required to ensure the completion of previous memory accesses. > > Therefore, the following sequence is required to ensure that P2 observes the > updated value: > > AArch32 > P1 > STR R5, [R1] ; message stored to shared memory location > DSB ST > STR R0, [R4] ; R4 contains the address of a mailbox > P2 > ; interrupt service routine > LDR R5, [R1] > > AArch64 > P1 > STR W5, [X1] ; message stored to shared memory location > DSB ST > STR W0, [X4] ; R4 contains the address of a mailbox > P2 > ; interrupt service routine > LDR W5, [X1] > " Will convinced me in the past that a DMB is sufficient here unless the peripheral is CPU-local. The Arm ARM is not entirely clear here. > I hear your concern about how this barrier in platform portable code may > impact platforms other than the one I'm trying to fix. It almost seems like > there is some missing type of barrier macro that on ARM64 does what is > required for cases like this and on other platforms does whatever is > appropriate for that platform, often nothing. I also agree that a wmb() in the i2c driver is not the more elegant fix. For similar reasons, we hid barriers in the write*() macros, drivers need to stay architecture-agnostic as much as possible. Where does the regmap_write() end up? I think the barrier should be somewhere down this path. -- Catalin