Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp703967rdb; Tue, 19 Sep 2023 07:54:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlkSBUj2+MwpBjZ0qxtgswALOrLyuDH8iSpOxQoXcx8jWPkaYUcUPfPC/7Bm91rR+INtWO X-Received: by 2002:a17:902:e884:b0:1bb:2020:be0d with SMTP id w4-20020a170902e88400b001bb2020be0dmr15396106plg.14.1695135296499; Tue, 19 Sep 2023 07:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695135296; cv=none; d=google.com; s=arc-20160816; b=VGTvIio0vPaLcVUu2X89DSaZOGwPadpzYc0YkWSoxQbd7ft8nlbQeyzniFaLkyYAr8 i1kWPKHbUlCWN3vG6wQjbmq7IJi6CWwQ9cT8hcvR0gyUJ0h8nWTM/euHihmUK1EiCiGS B3aoxrYRhTaDDQ0VRtUChgBxDCwyI/iPXPHDuS5mWHhM8FQZQeBnGbuQ+mwCDggjCVYo rdTUpEPxmMQ7RPHuMXyc2Wr1RAaZgej2VNwnYVLFQ6TMQIs5ONwi1T/yotKdN+G8fQo/ UQx67oBmiNhqeCjcHQEsGyU0VRZgIRmVI4P9sNhOHRXcg5BZ/0sXpYkEyO5v5k5u3LT0 SXLQ== 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=Ht/QabxnJ0LwTKh+fCW1GjVzlLb2vxUfPfmukLXNhVw=; fh=LAM8GIcZ5nhGQ72Wt1n6J8kYTzHko5L2LSvwUjKMGOk=; b=Q0az5+SSKtaodUz6vKkMW23bQ6Y2twWYbh/0iV1zuTJ9r6S0l/th0TK2mT/Vxd+5nX vaTux34fHKKbhuU16VcKvS22pIQh03uTbpfco2pwAVUufDDPJ/X+UcqadH0OswvR9abd V66asMBGhl+QdwDq56fUppooz2kIaqiXAnuCUnfPsejfhM6hTwFpLhUMAdFvCscqeBMl Fvl1ayvPBMO/irdYCgDCObpreaK3PHo5Vj7cAzx76/IkT5VD2zaGpcVkvJ9+/2JZqBmL Wv+RshdQqWY1+0o7acx/ffJpydiufO59nSiaIey15GIJ8QaJxvaIzso+TUGrSFmTYzCe 5kvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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. [23.128.96.32]) by mx.google.com with ESMTPS id o18-20020a170902e01200b001b9d2010c39si9774963plo.192.2023.09.19.07.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 07:54:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 D519180560D7; Tue, 19 Sep 2023 07:51:20 -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 S232913AbjISOvN (ORCPT + 99 others); Tue, 19 Sep 2023 10:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231208AbjISOvL (ORCPT ); Tue, 19 Sep 2023 10:51:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 708A5BC; Tue, 19 Sep 2023 07:51:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79D57C433C7; Tue, 19 Sep 2023 14:51:02 +0000 (UTC) Date: Tue, 19 Sep 2023 15:51:00 +0100 From: Catalin Marinas To: Yann Sionneau Cc: Wolfram Sang , Jan Bottorff , 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: <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: 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 07:51:21 -0700 (PDT) On Tue, Sep 19, 2023 at 02:38:22PM +0200, Yann Sionneau wrote: > Hi, > > On 9/19/23 12:19, Wolfram Sang wrote: > > > 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. > > Exactly my thinking. I wanted to read this patch discussion later this > > week. But from glimpsing at it so far, I already wondered why there > > isn't a memory barrier in the final accessor to the register. > > The regmap accessors used by the designware driver end up calling > writel_relaxed() and readl_relaxed() : https://elixir.bootlin.com/linux/v6.6-rc2/source/drivers/i2c/busses/i2c-designware-common.c#L71 OK, since it ends up with the *_relaxed() accessors, there are no barriers here. I wonder whether the regmap API should have both standard and relaxed variants. If a regmap driver does not populate the .reg_write_relaxed etc. members, a regmap_write_relaxed() would just fall back to regmap_write(). We went through similar discussions many years ago around the I/O accessors and decided to add the barriers to readl/writel() even if they become more expensive, correctness should be first. The relaxed variants were added as optimisations if specific memory ordering was not required. I think the regmap API should follow the same semantics, go for correctness first as you can't tell what the side-effect of a regmap_write() is (e.g. kicking off DMA or causing an interrupt on another CPU). > In those cases I would say the smp_* barriers are what we are supposed to > use, isn't it? 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). -- Catalin