Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3949051rwb; Tue, 16 Aug 2022 11:28:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR5YTJHPFAjPbpSRmsovFBCnwez3ThrhYT0A5JYot/keysCUBgfP54NgL8WORfdHVUQYIUL7 X-Received: by 2002:a17:906:58c6:b0:731:39e0:3eb8 with SMTP id e6-20020a17090658c600b0073139e03eb8mr14879447ejs.205.1660674514944; Tue, 16 Aug 2022 11:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660674514; cv=none; d=google.com; s=arc-20160816; b=BfNsZQ+4oRNGGk+qZNQ8OlWK5aJ0RWcmAeLxPafq1poZh82QdshQA/t6L0H7Mts2+s 0oD6frH6pb5sJufXEoG+ndyPYDUHO7dBvq/dVhGgSKOwUtfO0/mNBrd9xR55W5U/bVx0 CkCs9pF6xW15akltUkH5EGFM5A+hEVkXb2g6WrFpqbuK9fx8c89CI4rXq7Xvlpd4wS+F Edr6IChpUy9m1kMScb+uDnKWCpi8l2TqPyqPSRYzufbBkE97zxhR5T6n/zt0O9WnMvHI B5YtwA60ZsfoT0s3cboYsVtTq/zcj2HToEE7XipwBoSWShcGUXSDoTHT0IURcPXyHed7 KLuQ== 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:dkim-signature; bh=MySzvGXqRSaBBJhmsw3ulDhggVAysoOKEMJnaszkKsU=; b=QqnoL/Mg83YTeSSOP+dS1znzACohk5dJFxphfY+NQjIUAZlZFgB01+jaw2SvYEvTw0 SKbkfNoIE5IZ3xWei052xVZrCMkxgTwBSoPDKfBoCpR2ryplLjZR3e+3/nsnhRRColFv tCXcExI6O+Jw7RyZWX3y6vWa3LGJfUHO03OQVsfRI57fvYdVIqbTpNzlsNJ+LmJZ1Tt0 Kgogh07JwXTzdRbrdL5FlXZLwxtJkc+At6bU4UTazh42xRTEqnwn3Se3fXL8lFaKGzzX mY9qfoUMy7RtfqduhnHOKV8DsPLQmgP85AvUrJZrms0UeS4HCCTBjggE5LtQ9NAWMx/2 O7kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=YPrEDcLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg9-20020a170907a40900b0072f97d98a50si11295531ejc.945.2022.08.16.11.28.08; Tue, 16 Aug 2022 11:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=YPrEDcLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233897AbiHPSOu (ORCPT + 99 others); Tue, 16 Aug 2022 14:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233076AbiHPSOp (ORCPT ); Tue, 16 Aug 2022 14:14:45 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC0AD7AC02; Tue, 16 Aug 2022 11:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MySzvGXqRSaBBJhmsw3ulDhggVAysoOKEMJnaszkKsU=; b=YPrEDcLvKjIb0xNBG+Jk/CGOJ6 kW006eJ0NtmQgEuIfrtpv18W/AT3E6P4tU5tApVpU7iXAmUuqgW37qBLQwW2Knu5FTIuqME+NNPyp YadFUKbPi+Tq8trcm0xs6iZy0i2DBc3igLK50MYONBYKHxtUkGtlV31WJyX2fPAFh1cO7W3lL6vBo rNXj8n/uobl/HADOp+sc3StKPN9OlbxVN+x6YSldP1qDn+vr9g7EePepooP8GXvGf41FpHgOg9w5Q eUbNbWIvPg7EMgqcJ9XQFTfQntotK8qMPpjXTNgqVHkWILVngJ8OwCDNX5OV/DmArUSafNpj+lANo lPG7MazQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oO153-007DVO-MT; Tue, 16 Aug 2022 18:14:21 +0000 Date: Tue, 16 Aug 2022 19:14:21 +0100 From: Matthew Wilcox To: Will Deacon Cc: Arnd Bergmann , Hector Martin , Peter Zijlstra , Ingo Molnar , Alan Stern , Andrea Parri , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Mark Rutland , Jonathan Corbet , Tejun Heo , jirislaby@kernel.org, Marc Zyngier , Catalin Marinas , Oliver Neukum , Linus Torvalds , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Asahi Linux , stable@vger.kernel.org Subject: Re: [PATCH] locking/atomic: Make test_and_*_bit() ordered on failure Message-ID: References: <20220816070311.89186-1-marcan@marcan.st> <20220816140640.GD11202@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220816140640.GD11202@willie-the-truck> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org On Tue, Aug 16, 2022 at 03:06:41PM +0100, Will Deacon wrote: > On Tue, Aug 16, 2022 at 10:16:04AM +0200, Arnd Bergmann wrote: > > On Tue, Aug 16, 2022 at 9:03 AM Hector Martin wrote: > > > > > > These operations are documented as always ordered in > > > include/asm-generic/bitops/instrumented-atomic.h, and producer-consumer > > > type use cases where one side needs to ensure a flag is left pending > > > after some shared data was updated rely on this ordering, even in the > > > failure case. > > > > > > This is the case with the workqueue code, which currently suffers from a > > > reproducible ordering violation on Apple M1 platforms (which are > > > notoriously out-of-order) that ends up causing the TTY layer to fail to > > > deliver data to userspace properly under the right conditions. This > > > change fixes that bug. > > > > > > Change the documentation to restrict the "no order on failure" story to > > > the _lock() variant (for which it makes sense), and remove the > > > early-exit from the generic implementation, which is what causes the > > > missing barrier semantics in that case. Without this, the remaining > > > atomic op is fully ordered (including on ARM64 LSE, as of recent > > > versions of the architecture spec). > > > > > > Suggested-by: Linus Torvalds > > > Cc: stable@vger.kernel.org > > > Fixes: e986a0d6cb36 ("locking/atomics, asm-generic/bitops/atomic.h: Rewrite using atomic_*() APIs") > > > Fixes: 61e02392d3c7 ("locking/atomic/bitops: Document and clarify ordering semantics for failed test_and_{}_bit()") > > > Signed-off-by: Hector Martin > > > --- > > > Documentation/atomic_bitops.txt | 2 +- > > > include/asm-generic/bitops/atomic.h | 6 ------ > > > > I double-checked all the architecture specific implementations to ensure > > that the asm-generic one is the only one that needs the fix. > > I couldn't figure out parisc -- do you know what ordering their spinlocks > provide? They have a comment talking about a release, but I don't know what > the ordering guarantees of an "ldcw" are. "The semaphore operation is strongly ordered" (that's from the description of the LDCW instruction)