Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3633962rwb; Tue, 16 Aug 2022 06:30:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Kt63tt9C/qnZ3TFr7yeYQGAP4Yd2jn/xz7DLgBN3ampitVxLArbGTzYy8I+287aZhO4HA X-Received: by 2002:a17:907:d1f:b0:730:95c0:6cbc with SMTP id gn31-20020a1709070d1f00b0073095c06cbcmr13601548ejc.395.1660656629639; Tue, 16 Aug 2022 06:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660656629; cv=none; d=google.com; s=arc-20160816; b=bhWloQ4Suw3YK49DmdNAJdATvY2ykkUH2qKUeB0aL5GD/GgscqoZvtewlnMGc+4f4Q 40gjtyJSw6VUsHWcFYvQUVPew5jhRPumM0t3rWWG1Gj2CbaM8DVbh+SCOSGmSIp0eVvs G4aV135IWYzS8SZ1s9ujGdj6ktJyRcUnpN2sm1nP9cNdbKbNiFy/so1ybJ7N+LQTOi5P zTLxbKSbeAxQOQa/35W0YiM1ksLBsE/Hj/CVWOeVE8Bp/xhVFiAEaA33SCcI6Kv1rMUm AtTvUi9aumVzIB1m9vuK2PLvcs8AvxOVsQ3MuPX9lvNNzfsrGo5pKAdAsON6y+SwhNup fOjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=PAPcRMgu3fvr9tmN1eSbf2A3lAuvRFsR7QRsfb50iV8=; b=brpICchofCMQohvfEPxBriPVXP/Nogx5WFu+YKQ7SS+aA2xQHEuf1rWy7t5B4lCth9 LBarfPs/bnluM7Wt2lcuLws25YY/4CdazCj6zdO3BXyPIi3PzAFYaLF2WMuxfea7dCiw 5ercIk+C7GEprcFGBe/fWec+N6IMURS2y3wrmoF6hLzvUi/YrJDasJL0hw2kMN37+hqT Za4UKCXGRtczFnYZmDL+UZey4I6Oe4uiaBLL3Nu75h1dRpqmgH1vetzDX6LiP2bGcvYg lv4FTkzdaPE8k4GHZJA0E9fMeKP4cOWL9pfDWo7OE6NLHDUQS0qQGELuF5x5VtFJpNpE 6ysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Efap14+p; 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 z12-20020a05640240cc00b0044066d82f6dsi11921513edb.21.2022.08.16.06.30.04; Tue, 16 Aug 2022 06:30:29 -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=Efap14+p; 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 S233603AbiHPNXP (ORCPT + 99 others); Tue, 16 Aug 2022 09:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbiHPNXO (ORCPT ); Tue, 16 Aug 2022 09:23:14 -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 6B3E212098; Tue, 16 Aug 2022 06:23:11 -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 C401461387; Tue, 16 Aug 2022 13:23:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22AEEC433C1; Tue, 16 Aug 2022 13:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660656190; bh=JumyuZeI/tr0PhD+GYJH6A/O4IFXRoWVZzgl4XKHznE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Efap14+pMVDok7IK+6QRPjif/aQmWMGBSjZrJPWz+qZTnKjt8fW1Uc7L2WkYF4kjQ G6oi1jK2jk9sr7bRVb8z/1ifDCA45tbY2evJ2Cv8Qy/CrKCwj+EdM8LkRHnpaFig8W /PVLfsIPt7ZR8HIO7bggfapXP8NUhtcz+GyAN6bXg4B6/1QSx+S953tIR9Wej0oX+M Bka5mKS63I0ZXllJpWzq4/bz5ORlrZFTFcrUBDL61B1lZKiUUWkcxzp+GFaXoghOkW 9LYpbnYWT+GOLKoWgF2yG8bp0zpGngSI1CwUMYjzy6AH24tTdVVCnwx5xoD1rx6hKh b6AH3B1Y5XJSQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oNwXD-003Umf-M3; Tue, 16 Aug 2022 14:23:07 +0100 Date: Tue, 16 Aug 2022 14:23:02 +0100 Message-ID: <87v8qswceh.wl-maz@kernel.org> From: Marc Zyngier To: Jon Nettleton Cc: Will Deacon , 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, 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 In-Reply-To: References: <20220816070311.89186-1-marcan@marcan.st> <20220816130048.GA11202@willie-the-truck> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jon@solid-run.com, will@kernel.org, arnd@arndb.de, marcan@marcan.st, peterz@infradead.org, mingo@kernel.org, stern@rowland.harvard.edu, parri.andrea@gmail.com, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, paulmck@kernel.org, akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org, mark.rutland@arm.com, corbet@lwn.net, tj@kernel.org, jirislaby@kernel.org, catalin.marinas@arm.com, oneukum@suse.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, asahi@lists.linux.dev, stable@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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, 16 Aug 2022 14:05:54 +0100, Jon Nettleton wrote: > > On Tue, Aug 16, 2022 at 3:01 PM Will Deacon wrote: > > > > On Tue, Aug 16, 2022 at 02:29:49PM +0200, Jon Nettleton wrote: > > > On Tue, Aug 16, 2022 at 10:17 AM 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 assume this gets merged through the locking tree or that Linus picks it up > > > > directly, not through my asm-generic tree. > > > > > > > > Reviewed-by: Arnd Bergmann > > > > > > > > _______________________________________________ > > > > linux-arm-kernel mailing list > > > > linux-arm-kernel@lists.infradead.org > > > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > > > > > Testing this patch on pre Armv8.1 specifically Cortex-A72 and > > > Cortex-A53 cores I am seeing > > > a huge performance drop with this patch applied. Perf is showing > > > lock_is_held_type() as the worst offender > > > > Hmm, that should only exist if LOCKDEP is enabled and performance tends to > > go out of the window if you have that on. Can you reproduce the same > > regression with lockdep disabled? > > > > Will > > Yep I am working on it. We should note that > > config LOCKDEP_SUPPORT > def_bool y > > is the default for arm64 Yes, as the architecture supports LOCKDEP. However, you probably have something like CONFIG_PROVE_LOCKING to see such a performance hit (and that's definitely not on by default). M. -- Without deviation from the norm, progress is not possible.