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 152CDCE79D7 for ; Wed, 20 Sep 2023 14:22:31 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6JMdrjX/U0kb4w32Cjd0Z+gLELC+YXTYtxWfuWr7U48=; b=bD08PWFrVWBZ/v LguGodoOuoH2nAZjYmnKn9WPZ3osY8gd7ohezviVAoVtYGwRAszzOXieWX9Rkw/WJfI1BRlm+aKUq XmUDvsCatAZjDnGQGgdAz7lb+ZJPbNYP0Ot6fHilNURbqpZs4xfU+62s+p9FIa+GlqaE7dhWgcRO7 M6ux6qpJQROiXnYUTTsPu6t+OY7r2R5ZvnSJF6UNIQIH0Ncj7243AAuSsjVuWBcb3iAjscqKeAcmr K9+zSFESVOuRC9z44GiMlHzYLX2TW4Vqv2wZBD0XjFJ1Nyfe6hW05j6QADkcdE1ed307qOl56c2Ex MXyAgTBjEMlL3XCq44XQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiy5g-003J9w-25; Wed, 20 Sep 2023 14:22:08 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiy5d-003J8n-1n for linux-arm-kernel@lists.infradead.org; Wed, 20 Sep 2023 14:22:07 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id AF619CE1B76; Wed, 20 Sep 2023 14:22:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5FF5C433C7; Wed, 20 Sep 2023 14:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695219721; bh=LqtqpHzwRDH0oWFyoYM+97XwIaM8ozMTSXhPn4/77c8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PUBcifAXieesYeb9maaaTS68yS0r2bj9paBIg4jeIUAuxAN3aa9wOqdS82iXcoEGN CexkaU3/X9lFp5se8Zi6ZBWce7wLw8E5e5sL1gpnYInOw8KG9XL1aOsTy6L4Pj481S v+xQYwBJjE/5H/PRq8gnK4XKZpY3KO/2xWdxQdIdh+hNUrm6JkacOVELEo9wL42qJr zoI61/yTlB6wNO01fUAg1KnMdlZ9Sh6EHYhNo39GJGtxdPGxLJUHGbuMjQjwMHCNAV jvrOCBAHfEeZmt4ZSwpXCzcMV0LO3s6xsJCGizXwosg8QA8viuRO8LGd5zie9iYPWi sM2TYm9y24z7Q== Date: Wed, 20 Sep 2023 07:22:01 -0700 From: "Darrick J. Wong" To: Baokun Li Cc: Mark Rutland , linux-kernel@vger.kernel.org, Peter Zijlstra , boqun.feng@gmail.com, david@fromorbit.com, kent.overstreet@linux.dev, linux-arm-kernel@lists.infradead.org, ming.lei@redhat.com, will@kernel.org, yi.zhang@redhat.com, yangerkun Subject: Re: [PATCH] locking/atomic: scripts: fix fallback ifdeffery Message-ID: <20230920142201.GG348037@frogsfrogsfrogs> References: <20230919171430.2697727-1-mark.rutland@arm.com> <8cef9531-e44d-04de-f789-cb77c63ecf4f@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8cef9531-e44d-04de-f789-cb77c63ecf4f@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230920_072205_990370_E41C278F X-CRM114-Status: GOOD ( 36.99 ) 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 20, 2023 at 10:08:02AM +0800, Baokun Li wrote: > On 2023/9/20 1:14, Mark Rutland wrote: > > Since commit: > > = > > 9257959a6e5b4fca ("locking/atomic: scripts: restructure fallback ifd= effery") > > = > > The ordering fallbacks for atomic*_read_acquire() and > > atomic*_set_release() erroneously fall back to the implictly relaxed > > atomic*_read() and atomic*_set() variants respectively, without any > > additional barriers. This loses the ACQUIRE and RELEASE ordering > > semantics, which can result in a wide variety of problems, even on > > strongly-ordered architectures where the implementation of > > atomic*_read() and/or atomic*_set() allows the compiler to reorder those > > relative to other accesses. > > = > > In practice this has been observed to break bit spinlocks on arm64, > > resulting in dentry cache corruption. > > = > > The fallback logic was intended to allow ACQUIRE/RELEASE/RELAXED ops to > > be defined in terms of FULL ops, but where an op had RELAXED ordering by > > default, this unintentionally permitted the ACQUIRE/RELEASE ops to be > > defined in terms of the implicitly RELAXED default. > > = > > This patch corrects the logic to avoid falling back to implicitly > > RELAXED ops, resulting in the same behaviour as prior to commit > > 9257959a6e5b4fca. > > = > > I've verified the resulting assembly on arm64 by generating outlined > > wrappers of the atomics. Prior to this patch the compiler generates > > sequences using relaxed load (LDR) and store (STR) instructions, e.g. > > = > > | : > > | ldr x0, [x0] > > | ret > > | > > | : > > | str x1, [x0] > > | ret > > = > > With this patch applied the compiler generates sequences using the > > intended load-acquire (LDAR) and store-release (STLR) instructions, e.g. > > = > > | : > > | ldar x0, [x0] > > | ret > > | > > | : > > | stlr x1, [x0] > > | ret > > = > > To make sure that there were no other victims of the ifdeffery rewrite, > > I generated outlined copies of all of the {atomic,atomic64,atomic_long} > > atomic operations before and after commit 9257959a6e5b4fca. A diff of > > the generated assembly on arm64 shows that only the read_acquire() and > > set_release() operations were changed, and only lost their intended > > ordering: > > = > > | [mark@lakrids:~/src/linux]% diff -u \ > > | <(aarch64-linux-gnu-objdump -d before-9257959a6e5b4fca.o) > > | <(aarch64-linux-gnu-objdump -d after-9257959a6e5b4fca.o) > > | --- /proc/self/fd/11 2023-09-19 16:51:51.114779415 +0100 > > | +++ /proc/self/fd/16 2023-09-19 16:51:51.114779415 +0100 > > | @@ -1,5 +1,5 @@ > > | > > | -before-9257959a6e5b4fca.o: file format elf64-littleaarch64 > > | +after-9257959a6e5b4fca.o: file format elf64-littleaarch64 > > | > > | > > | Disassembly of section .text: > > | @@ -9,7 +9,7 @@ > > | 4: d65f03c0 ret > > | > > | 0000000000000008 : > > | - 8: 88dffc00 ldar w0, [x0] > > | + 8: b9400000 ldr w0, [x0] > > | c: d65f03c0 ret > > | > > | 0000000000000010 : > > | @@ -17,7 +17,7 @@ > > | 14: d65f03c0 ret > > | > > | 0000000000000018 : > > | - 18: 889ffc01 stlr w1, [x0] > > | + 18: b9000001 str w1, [x0] > > | 1c: d65f03c0 ret > > | > > | 0000000000000020 : > > | @@ -1230,7 +1230,7 @@ > > | 1070: d65f03c0 ret > > | > > | 0000000000001074 : > > | - 1074: c8dffc00 ldar x0, [x0] > > | + 1074: f9400000 ldr x0, [x0] > > | 1078: d65f03c0 ret > > | > > | 000000000000107c : > > | @@ -1238,7 +1238,7 @@ > > | 1080: d65f03c0 ret > > | > > | 0000000000001084 : > > | - 1084: c89ffc01 stlr x1, [x0] > > | + 1084: f9000001 str x1, [x0] > > | 1088: d65f03c0 ret > > | > > | 000000000000108c : > > | @@ -2427,7 +2427,7 @@ > > | 207c: d65f03c0 ret > > | > > | 0000000000002080 : > > | - 2080: c8dffc00 ldar x0, [x0] > > | + 2080: f9400000 ldr x0, [x0] > > | 2084: d65f03c0 ret > > | > > | 0000000000002088 : > > | @@ -2435,7 +2435,7 @@ > > | 208c: d65f03c0 ret > > | > > | 0000000000002090 : > > | - 2090: c89ffc01 stlr x1, [x0] > > | + 2090: f9000001 str x1, [x0] > > | 2094: d65f03c0 ret > > | > > | 0000000000002098 : > > = > > I've build tested this with a variety of configs for alpha, arm, arm64, > > csky, i386, m68k, microblaze, mips, nios2, openrisc, powerpc, riscv, > > s390, sh, sparc, x86_64, and xtensa, for which I've seen no issues. I > > was unable to build test for ia64 and parisc due to existing build > > breakage in v6.6-rc2. > > = > > Fixes: 9257959a6e5b4fca ("locking/atomic: scripts: restructure fallback= ifdeffery") > > Reported-by: Ming Lei > > Link: https://lore.kernel.org/all/ZOWFtqA2om0w5Vmz@fedora/ > > Reported-by: Darrick J. Wong The dentry crashes on fstests on arm64 have gone away, so I feel confident in saying: Tested-by: Darrick J. Wong --D > > Link: https://lore.kernel.org/linux-fsdevel/20230912173026.GA3389127@fr= ogsfrogsfrogs/ > > Signed-off-by: Mark Rutland > = > Thank you=A0 for the patch that fixes this issue! > = > I tested the patch and confirmed that hlist_bl_lock now provides the > guarantees it should. > = > Tested-by: Baokun Li > = > = > Cheers! > Baokun Li > > Cc: Baokun Li > > Cc: Boqun Feng > > Cc: Darrick J. Wong > > Cc: Dave Chinner > > Cc: Kent Overstreet > > Cc: Ming Lei > > Cc: Peter Zijlstra > > Cc: Will Deacon > > Cc: Yi Zhang > > Cc: linux-arm-kernel@lists.infradead.org > > --- > > include/linux/atomic/atomic-arch-fallback.h | 10 +--------- > > scripts/atomic/gen-atomic-fallback.sh | 2 +- > > 2 files changed, 2 insertions(+), 10 deletions(-) > > = > > Peter, are you happy to queue this in the tip tree? It's a pretty nasty > > regresssion in v6.5, and I'd like to get this in as a fix for v6.6 ASAP. > > = > > Thanks, > > Mark. > > = > > diff --git a/include/linux/atomic/atomic-arch-fallback.h b/include/linu= x/atomic/atomic-arch-fallback.h > > index 18f5744dfb5d8..b83ef19da13de 100644 > > --- a/include/linux/atomic/atomic-arch-fallback.h > > +++ b/include/linux/atomic/atomic-arch-fallback.h > > @@ -459,8 +459,6 @@ raw_atomic_read_acquire(const atomic_t *v) > > { > > #if defined(arch_atomic_read_acquire) > > return arch_atomic_read_acquire(v); > > -#elif defined(arch_atomic_read) > > - return arch_atomic_read(v); > > #else > > int ret; > > @@ -508,8 +506,6 @@ raw_atomic_set_release(atomic_t *v, int i) > > { > > #if defined(arch_atomic_set_release) > > arch_atomic_set_release(v, i); > > -#elif defined(arch_atomic_set) > > - arch_atomic_set(v, i); > > #else > > if (__native_word(atomic_t)) { > > smp_store_release(&(v)->counter, i); > > @@ -2575,8 +2571,6 @@ raw_atomic64_read_acquire(const atomic64_t *v) > > { > > #if defined(arch_atomic64_read_acquire) > > return arch_atomic64_read_acquire(v); > > -#elif defined(arch_atomic64_read) > > - return arch_atomic64_read(v); > > #else > > s64 ret; > > @@ -2624,8 +2618,6 @@ raw_atomic64_set_release(atomic64_t *v, s64 i) > > { > > #if defined(arch_atomic64_set_release) > > arch_atomic64_set_release(v, i); > > -#elif defined(arch_atomic64_set) > > - arch_atomic64_set(v, i); > > #else > > if (__native_word(atomic64_t)) { > > smp_store_release(&(v)->counter, i); > > @@ -4657,4 +4649,4 @@ raw_atomic64_dec_if_positive(atomic64_t *v) > > } > > #endif /* _LINUX_ATOMIC_FALLBACK_H */ > > -// 202b45c7db600ce36198eb1f1fc2c2d5268ace2d > > +// 2fdd6702823fa842f9cea57a002e6e4476ae780c > > diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen= -atomic-fallback.sh > > index c0c8a85d7c81b..a45154cefa487 100755 > > --- a/scripts/atomic/gen-atomic-fallback.sh > > +++ b/scripts/atomic/gen-atomic-fallback.sh > > @@ -102,7 +102,7 @@ gen_proto_order_variant() > > fi > > # Allow ACQUIRE/RELEASE/RELAXED ops to be defined in terms of FULL o= ps > > - if [ ! -z "${order}" ]; then > > + if [ ! -z "${order}" ] && ! meta_is_implicitly_relaxed "${meta}"; then > > printf "#elif defined(arch_${basename})\n" > > printf "\t${retstmt}arch_${basename}(${args});\n" > > fi > = > = _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel