From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 636B5110C for ; Tue, 16 Aug 2022 13:06:32 +0000 (UTC) Received: by mail-io1-f45.google.com with SMTP id h78so2973600iof.13 for ; Tue, 16 Aug 2022 06:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solid-run-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=jYFy/Ap+uf26Gcpe/I0MSisZFVmPhCJtSmEvqbaImns=; b=TPm7sp/EC7y75Bb9Hebx9wUeTQofUP3E8N5rnoRewYyUMY2eWw6qAfh2vaf06LqTso YjKjRjDFQEcsxNlFOM1iFupmE5nz6Q3XbtcBGZh25VL1dE4iLkyEx+d2OdQkCDQV4F1I Q3Gws5+w1yGxQXqr1/i3xdwfJnmv+szNLKS5kWYlfZBsfM5RmI/eB+NWZWPry33NMS3K 7KUwALiD/FTal89vHgf+W/bQjMhZ1WW4azMae9jdTw2nbZknuM1sk1Pi3+wD/VsqnjMN lZ7NcixEG9dmbkdfKcDkCLc/FtxPozmizq5rTPPr/72lRhKJj6KYyso7a0aS6JqLGCVp xn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=jYFy/Ap+uf26Gcpe/I0MSisZFVmPhCJtSmEvqbaImns=; b=imP+HKTMj5R3x3BuEW/1ZFfKWraSOWcaAkM3hFn3KkYR3gok3PU1i2qqlBYKkWCRke BPtbOLUflukRecm7FN/nvVC6QuLSmgSKcJUpEZwXt0AJeIM4de1u5TG8FHsbTItlYf3f MrUyI1EcXb1f82kTHv2HGsuiDLGztWQDpUmkp/1ZujdXxtwrxUpWSUduVQ3N1tEWfLHX rucmP6GJTc/l4gEiiB2k+Dh/bUVlOAsaNNchJkntGM0XvmNg4hf/za8kUaOADAwYN/rR klvvwYRuO8hMBpKjyYOdAqDqz0eLcwajwFzEmIV0balaHfljnKZXbbyH8aCIy9FG5e5D z9qw== X-Gm-Message-State: ACgBeo2bd8b5EuRU8hDG9/QMXoTpCKq5ckQMzHgNLXL8NrMK95Du3ZVr 1ZxTTHB7m4sGQ7DFoqQj3kVC8FhpjTe3wp7eBKUwqQ== X-Google-Smtp-Source: AA6agR4LYPGyytQ7zXtN6CVNQG0RmLGJHMQuUxL8SF2Np6jEPA1mTRDJD83cAn/zEamlnjrEgjfTpWUAWi1BuGTNAGw= X-Received: by 2002:a05:6638:d45:b0:343:2ae6:e39a with SMTP id d5-20020a0566380d4500b003432ae6e39amr9740158jak.139.1660655191422; Tue, 16 Aug 2022 06:06:31 -0700 (PDT) Precedence: bulk X-Mailing-List: asahi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20220816070311.89186-1-marcan@marcan.st> <20220816130048.GA11202@willie-the-truck> In-Reply-To: <20220816130048.GA11202@willie-the-truck> From: Jon Nettleton Date: Tue, 16 Aug 2022 15:05:54 +0200 Message-ID: Subject: Re: [PATCH] locking/atomic: Make test_and_*_bit() ordered on failure 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 Content-Type: text/plain; charset="UTF-8" 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 -Jon From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6E84C25B0E for ; Tue, 16 Aug 2022 13:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n0m9EOWWozFy8aw5kVzkKJ1hmBC09SQ6Too2jpqHOj0=; b=0hIKfCE1cP8iJn tXpQiB8/BgAjlfzBzepKNJbukA1vYi52OKZCbZTBiYSRAb1SyWdTO468UJj4//51DcI3pzEgpnCqI atGUuv98ofhmwZDRa3GisllWHRXSdDJC7o7uJKF2q+4+rg45qojYwzapnyyXyZY0j+qOl6GlAhVqq RGUmdK5WHfAoFFvM0xEfusWQ1L7X/f8L4Q6s9uJuLrEVnAp+LrZ+jo7GwmmufuaxgZHWG39PyynNc idT2igfeCa3x4JjKeBqPOoQeAE4tDb/sIL2O1M+QiR0NA45qIForFiftaGw4qkJdkX6Szz6Xh4gOs a4rhUXODu0dyCmuCtrxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNwHO-002dvp-7c; Tue, 16 Aug 2022 13:06:46 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNwHC-002dn3-K5 for linux-arm-kernel@lists.infradead.org; Tue, 16 Aug 2022 13:06:37 +0000 Received: by mail-io1-xd32.google.com with SMTP id v185so8108278ioe.11 for ; Tue, 16 Aug 2022 06:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solid-run-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=jYFy/Ap+uf26Gcpe/I0MSisZFVmPhCJtSmEvqbaImns=; b=TPm7sp/EC7y75Bb9Hebx9wUeTQofUP3E8N5rnoRewYyUMY2eWw6qAfh2vaf06LqTso YjKjRjDFQEcsxNlFOM1iFupmE5nz6Q3XbtcBGZh25VL1dE4iLkyEx+d2OdQkCDQV4F1I Q3Gws5+w1yGxQXqr1/i3xdwfJnmv+szNLKS5kWYlfZBsfM5RmI/eB+NWZWPry33NMS3K 7KUwALiD/FTal89vHgf+W/bQjMhZ1WW4azMae9jdTw2nbZknuM1sk1Pi3+wD/VsqnjMN lZ7NcixEG9dmbkdfKcDkCLc/FtxPozmizq5rTPPr/72lRhKJj6KYyso7a0aS6JqLGCVp xn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=jYFy/Ap+uf26Gcpe/I0MSisZFVmPhCJtSmEvqbaImns=; b=EHbltZWvjkXP82DKC552wrUBR+EDF2nDE+YrZ6Kyh9HfprD2bFiltSOe9UnHOmnksl +lSkm4HTWe83+5jr4isMeHDs6h3fuizaJOLtCKwMOPQIXKWrVVXmUBMzH/dPQet9pgoj IMylcm2lQqcGHuAj8+PDTLLEc5MNjB2M8toNF2McQ+Ws8EB0I01tCsP30MXM5dxDMxEg iAIH6lTy/pXF5ujAX59vWeERx4CxcC+j13MpdjxwWGm7LSD2PcbTxPeZorZ2RCJEwFM/ i2PeWxUGoPsptOSKAh84u1cPJp1v/FQ6oyXtSEkBu6T1RjOo4yEeBWNW+EEFNh2yuaJp aIrw== X-Gm-Message-State: ACgBeo2pDeKSGLYupJIsTpAbBpmSLf6HGJ5Pr18dkPlOSgLyfTOL3EJd FtTJwAxkqPxJc8CknKmqZAHOGQU6TBZVO1KsuU+mqw== X-Google-Smtp-Source: AA6agR4LYPGyytQ7zXtN6CVNQG0RmLGJHMQuUxL8SF2Np6jEPA1mTRDJD83cAn/zEamlnjrEgjfTpWUAWi1BuGTNAGw= X-Received: by 2002:a05:6638:d45:b0:343:2ae6:e39a with SMTP id d5-20020a0566380d4500b003432ae6e39amr9740158jak.139.1660655191422; Tue, 16 Aug 2022 06:06:31 -0700 (PDT) MIME-Version: 1.0 References: <20220816070311.89186-1-marcan@marcan.st> <20220816130048.GA11202@willie-the-truck> In-Reply-To: <20220816130048.GA11202@willie-the-truck> From: Jon Nettleton Date: Tue, 16 Aug 2022 15:05:54 +0200 Message-ID: Subject: Re: [PATCH] locking/atomic: Make test_and_*_bit() ordered on failure 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220816_060634_714445_BBE333F4 X-CRM114-Status: GOOD ( 34.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 -Jon _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel