Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2282942rdb; Mon, 20 Nov 2023 07:06:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHezGWEOofWOuxMu02jxTb7gBTTsTcGCOrBlgKRcYQrs/tfAekHQ7viSBB/mKAKQ6qGm05i X-Received: by 2002:a17:902:f68e:b0:1ce:5b21:5c34 with SMTP id l14-20020a170902f68e00b001ce5b215c34mr6634646plg.5.1700492803218; Mon, 20 Nov 2023 07:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700492803; cv=none; d=google.com; s=arc-20160816; b=ip8Z+AHnnuTbu0YozB1DEIU1TR3r7G+qNSfKzE1gC8MUfSRqT9CR4BiP4gvseJn4m2 HxeRqOhykAvkngaljH/HyfYQyElNInk72nGNlWgbCLSlAv7je7+bHMVq17bhy3BhsOf9 JbiDpPps0E5o38vlFvU6mL0B/5ssB6dqGm+tTqLVtX2P5niuto3kaClfSGS/dUTJ73CM ZvXmSOaUBTYyUGfjHKNAeARmeFfPw4pTDu2edchOGXjLz44DY6m4cIcW4SEzQN0YOZdN CWKOPpH8rh/EnlnQhwD9mywOWMQhrHHNk1WQUBPWkSV+7jZKqDPzLBan05JupNzAw+4F MziA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ZO0BFFZr3A/0KwkkxXzil8v/B1dDpRp0jmqcjI+YJMw=; fh=jAjW8oGrsqCmDJWJzb1bqDlbwFouZeqoKYcnPJEQroY=; b=PFDi5vvpassQvofL//2fIKcIFpxyHniHr9Bcm8Q6CzB8hVubqj8fKldUQ3Wy2iuvvh Vm7lpgwe/PcQLXs74zZ4EsZhb5NRodLHreZlwYVTFJS7U/wo54RbmUe4sRaPOmSuN0u7 VaqwMmAl5J9/Wf1kTA1pgGmJ5WnJeLb7CVs7xMNXOKQBMLb830g/DjLMxk/eE3mVBxw3 bWwHoYSZLg0ZU0P/6OW8gG8ly9DV0Z1F29JE1HLV1dbuY/tKgGDZSf4RHD6JWrHDqX5R sduY7MyMMeRiRhv6RmgdetaLn3oazpNIZH8lBEILXpPctARCjfKDcgZ4fNfdc6BbVhWp fnWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nf37+MGo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id c9-20020a170902c1c900b001c9ff461649si7988223plc.581.2023.11.20.07.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 07:06:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nf37+MGo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 39FAE80A64DB; Mon, 20 Nov 2023 07:05:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233875AbjKTPF0 (ORCPT + 99 others); Mon, 20 Nov 2023 10:05:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233564AbjKTPFZ (ORCPT ); Mon, 20 Nov 2023 10:05:25 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA05F93 for ; Mon, 20 Nov 2023 07:05:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA398C433C8; Mon, 20 Nov 2023 15:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700492721; bh=wkDFkqWY1q+7TNnh5FBjMJrCHmKUB6aLYQbdLpZqwSE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nf37+MGouG1zQ31cVpFoLYz4Q3JdOGJ2KdrauMtMigOEAKXQY9aNLsyOo+rGpUjsf aLsPbrR8LlQv6etrojYjeLvn+nkaDC4vNLCxVbwc5nU9tumi4+cqHnujmWpoRGkziE 7YgUZnmGWKlnSHTuar2CA44JXgd88+kqru1oHVOcUudm4Y5S1k/P2XxKJbEMqJOXWu KQ/LWrQrsZdXOEF/DyqUIxGBNgJxA1H9fkI3ZPFGdZNwhSLrCb7AcFefSTzAzd9HBC 06Me0sJT+1oVQYAjL08izkU7iQ2QKtcGqrMNjLL/uvq9zybglyCWiF1rLJ0vhotWc1 Kr14ETS5/dloQ== Date: Mon, 20 Nov 2023 15:05:16 +0000 From: Will Deacon To: Linus Torvalds Cc: Wolfram Sang , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Rosin , Bartosz Golaszewski , Andi Shyti , Catalin Marinas Subject: Re: [PULL REQUEST] i2c-for-6.7-rc2 Message-ID: <20231120150515.GA32570@willie-the-truck> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 07:05:48 -0800 (PST) On Sat, Nov 18, 2023 at 09:56:59AM -0800, Linus Torvalds wrote: > On Fri, 17 Nov 2023 at 16:05, Wolfram Sang wrote: > > > > Jan Bottorff (1): > > i2c: designware: Fix corrupted memory seen in the ISR > > I have pulled this, but honestly, looking at the patch, I really get > the feeling that there's some deeper problem going on. > > Either the designware driver doesn't do the right locking, or the > relaxed IO accesses improperly are escaping the locks that do exist. > > Either way, just changing "writel_relaxed()" to "writel()" seems to be wrong. > > Of course, it is entirely possible that those accesses should never > have been relaxed in the first place, and that the actual access > ordering between two accesses in the same thread matters. For example, > the code did > > *val = readw_relaxed(dev->base + reg) | > (readw_relaxed(dev->base + reg + 2) << 16); > > and if the order of those two readw's mattered, then the "relaxed" was > always entirely wrong. > > But the commit message seems to very much imply a multi-thread issue, > and for *that* issue, doing "writel_relaxed" -> "writel" is very much > wrong. The only thing fixing threading issues is proper locks (or > _working_ locks). > > Removing the "relaxed" may *hide* the issue, but doesn't really fix it. > > For the arm64 people I brought in: this is now commit f726eaa787e9 > ("i2c: designware: Fix corrupted memory seen in the ISR") upstream. > I've done the pull, because even if this is purely a "hide the > problem" fix, it's better than what the code did. I'm just asking that > people look at this a bit more. Thanks for putting me on CC. The original issue was discussed quite a bit over at: https://lore.kernel.org/all/20230913232938.420423-1-janb@os.amperecomputing.com/ and I think the high-level problem was something like: 1. CPU x writes some stuff to memory (I think one example was i2c_dw_xfer() setting 'dev->msg_read_idx' to 0) 2. CPU x writes to an I/O register on this I2C controller which generates an IRQ (end of i2c_dw_xfer_init()) 3. CPU y takes the IRQ 4. CPU y reads 'dev->msg_read_idx' and doesn't see the write from (1) (i2c folks: please chime in if I got this wrong) the issue being that the writes in (1) are not ordered before the I/O access in (2) if the relaxed accessor is used. Rather than upgrade only the register writes which can trigger an interrupt, the more conservative approach of upgrading everything to non-relaxed I/O accesses was taken (which is probably necessary to deal with spurious IRQs properly anyway because otherwise 'dev->msg_read_idx' could be read early in step (4)). Your point about locking is interesting. I don't see any obvious locks being taken in i2c_dw_isr(), so I don't think the issue is because relaxed accesses are escaping existing locks. An alternative would be putting steps (1) and (2) in a critical section and then taking the lock again in the interrupt handler. Or did you have something else in mind? Will