Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7652310rwl; Tue, 10 Jan 2023 03:45:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXuNWvV0OMdGO6M6Hh6YYe+K0Bw/TYPdqo6R79hWS/YI4fMtU45V5hBbH5u/T+FClWweJsGn X-Received: by 2002:a17:907:8e93:b0:7ae:bfec:74c7 with SMTP id tx19-20020a1709078e9300b007aebfec74c7mr62264516ejc.72.1673351157919; Tue, 10 Jan 2023 03:45:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673351157; cv=none; d=google.com; s=arc-20160816; b=k7RaOvIGKsFvAv3tSk9vXlewB4vvSj4WNcLW+ZpFs5H+Yr2hlfIqF1fRpV8Fshj99O liCewYVFMLUt0j16WSZwdiQwR28KydcFx4z/dsDBGAe56nqGmohjvBY1CgMeKUSTaJ7z iHjtO+MJ0zIzk09oYkyj+wie8VMG0jGDwNiPwp0o6vlsaXKORewzAHKPx4prihibZqBu TwKJWIAAtJbG9G4iXX3KChUUtq/3eeIlIKiERpu5XbJEmA3J+h4QbriPeElUqsSeuOuk ylJPJ5Y0EHN9h9UP6GVpHtta1lnFlVWfCvkUV8jM5aAZwprFbrDSrSFrwG8MZ4oc5Dp2 IAwQ== 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=sL6J5Ywlc2KrfJCARO65wFjokXCwDNaUu1iFhyIVwlg=; b=jRTOBUy4ppa9bjDV85f2dHdpTm49S6y4LG2T61HCR57TpVyXKgtJOG9PS05HwtndJL HyGHLIninuaO3oajc4TiVXEq0v026w3fQJGfGWW22y+Ub0Qz+nSMe5wPJKLTB6ft+ktf V7UcX1b9RKBQG8vejM/enxshlkOBnkJex2CxBB4Nvdg8/XPZjosgvpw9KEeSkRl4fe6/ Q9hmtuL9JS32j2bgV5Ujmg/h8iWJiXumDDDONy9CEPZg2AkXcZ0jAeeW5W8Dw6TTKeN2 BGH5ci89m5ithaDiQbJXJQP78DrbKVQMu5TnYKoSpRnaEEFO3he7QHT9rJcO4UukrKwt wsKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw33-20020a1709066a2100b007bdf57f885esi12682490ejc.37.2023.01.10.03.45.28; Tue, 10 Jan 2023 03:45:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231544AbjAJL1k (ORCPT + 99 others); Tue, 10 Jan 2023 06:27:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjAJL1i (ORCPT ); Tue, 10 Jan 2023 06:27:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 57464482B9; Tue, 10 Jan 2023 03:27:37 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 064784B3; Tue, 10 Jan 2023 03:28:19 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.46.95]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE6AE3F587; Tue, 10 Jan 2023 03:27:30 -0800 (PST) Date: Tue, 10 Jan 2023 11:27:28 +0000 From: Mark Rutland To: Peter Zijlstra Cc: Heiko Carstens , Thomas Richter , torvalds@linux-foundation.org, corbet@lwn.net, will@kernel.org, boqun.feng@gmail.com, catalin.marinas@arm.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, Herbert Xu , davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, joro@8bytes.org, suravee.suthikulpanit@amd.com, robin.murphy@arm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, Arnd Bergmann , penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, Andrew Morton , vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org Subject: Re: [RFC][PATCH 08/12] s390: Replace cmpxchg_double() with cmpxchg128() Message-ID: References: <20221219153525.632521981@infradead.org> <20221219154119.352918965@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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-crypto@vger.kernel.org On Tue, Jan 10, 2023 at 09:32:55AM +0100, Peter Zijlstra wrote: > On Tue, Jan 10, 2023 at 08:23:05AM +0100, Heiko Carstens wrote: > > > So, Alexander Gordeev reported that this code was already prior to your > > changes potentially broken with respect to missing READ_ONCE() within the > > cmpxchg_double() loops. > > Unless there's an early exit, that shouldn't matter. If you managed to > read garbage the cmpxchg itself will simply fail and the loop retries. I don't think that's true; without READ_ONCE() the compiler could (but is very unlikely to) read multiple times, and that could cause problems. For example: | prev = *ptr; | | do { | new = some_function_of(prev); | old = cmpxchg(ptr, prev, new); | } while (old != prev); Could effectively become: | prev1 = *ptr; | prev2 = *ptr; | | do { | new = some_function_of(prev1) | old = cmpxchg(ptr, prev2, new); | } while (old != prev2); ... which would effectively udpate from a stale value, throwing away prev2. That and the two generated reads could be in either order. So I do think it's warranted to use READ_ONCE() for the prev value feeding into a cmpxchg operation, even if that's only for the "once" part rather than lack of tearing. Thanks, Mark.