Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3738926rwb; Tue, 16 Aug 2022 08:03:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR57mZznwPnUa4nmbL8JesInlGCb2B08xL69ZdkEOWupj+j0IgMkIGFdJaDon07/KnDI6oXa X-Received: by 2002:a05:6402:190b:b0:43d:d001:2cce with SMTP id e11-20020a056402190b00b0043dd0012ccemr19005944edz.326.1660662235022; Tue, 16 Aug 2022 08:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660662235; cv=none; d=google.com; s=arc-20160816; b=HOf7Em63hU99wqmnpaNvsvf8FYMFT4YliR6mgz7h90n4u6mCCsTdarnTq1kJnafP06 R5wAc8tUv2J4lYBZws1ZlrUVW404KIEBcVGWKAJWNYlCGRbrbusSfR9Ezt8SAc0JVpkH ugEcLXluwO/5SUtDeHz/0fONuJ7Tk+/gDuz+3lWcNk1wqEIOaXogcKqD/9oY4Fy3E/6v DyXGnUkH0wL8DwQywgyS2Qm1sknkaWxd7yDtqN7NIztpdnCxeiBfGeoyHxdfwSbAFiuw oBtQhqFc1J6c+mDmJP13orUtwyLEJguwr8NJ7mtSasBFEk1dEuXFBV/CsNu02dV8DqCg 976Q== 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=dDB7PePIn7jWuuK/C5w4BS2LcV1K9JjRffMFK+Gok2A=; b=eM7cnDi/V9GC8Rbxnw3GLELSMorC6cpEgBLSm5MGvPQOw+mseCuyHMKrjL5E7XHVxe bIlId1v4Vpg3MUN7jdjGSvnf66NrqyH8u/ki/5XuZV+aG/L/B8x+N/hVAM9bIFjjZZmz vAw9iJMfZ6y/STXB58/QJ/GIeEZLIiI8I6gynZ6d5tDxn63sKKZ6vdHIt7Jo37HusAY9 g1NU7rIwYizbr5MFTdxq8WshLAS6jCBqsUYP2oLN7CpyTBfe2VMM/RsMoCx5TajFozgo H2FoVpX9B28USldFnlSBCaaGEdjuvEzQP/OYHZ2lWbG/Y+GIbp85RNGQw8shgOv087th 6sfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kfw1O86y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di3-20020a170906730300b0072af8809a85si10774170ejc.332.2022.08.16.08.03.23; Tue, 16 Aug 2022 08:03:55 -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=@kernel.org header.s=k20201202 header.b=kfw1O86y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235904AbiHPOGx (ORCPT + 99 others); Tue, 16 Aug 2022 10:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232853AbiHPOGw (ORCPT ); Tue, 16 Aug 2022 10:06:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7F59580B3; Tue, 16 Aug 2022 07:06:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 753FE60FBE; Tue, 16 Aug 2022 14:06:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA9B7C433D7; Tue, 16 Aug 2022 14:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660658809; bh=Or6NyDZrBzLzCXiIiquybOJRFR8o21mNOuu9wwm7Nss=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kfw1O86y2BXK91mGj0emsKUZkIdWk32UmBAWTwQjudeEvHAasXBTJndVb1TuUneDD rVYTtbvFMo+QhYNl2UJK1HMfxu4hKojAVWqZgsyNUoFb+rzPxq+zFxDKs66QJCCtm1 2txEOXrlVzP3vE7EMu24gEtSP6dRv/3DcWqeW7duIlMCeqnVBXuK8jgabfBzlCc7/l fZUv+oaFllnBBMxHS/Q+r5R49NpjKKAEXV5lQOrXfgAPGq2AdzcdlZM1kUydwTcJBV JTanTDke6p8gRxBvtYYFcMNyInC9y26AtCwzencBxBL6osJm5XT9OcY9JsudLnfkc7 XbYfPc765w6cA== Date: Tue, 16 Aug 2022 15:06:41 +0100 From: Will Deacon To: Arnd Bergmann Cc: 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: <20220816140640.GD11202@willie-the-truck> References: <20220816070311.89186-1-marcan@marcan.st> 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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 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. Will