From nobody Tue Apr 7 14:56:03 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF1B7ECAAA3 for ; Fri, 26 Aug 2022 20:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344976AbiHZUoF (ORCPT ); Fri, 26 Aug 2022 16:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231680AbiHZUn7 (ORCPT ); Fri, 26 Aug 2022 16:43:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5253DC0B4 for ; Fri, 26 Aug 2022 13:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661546638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Nam1cAfsFD5oHCEiyBVoFhT08lyzL12/kSxOf4iyFlo=; b=KBPVvgQK5cX/kGEBhdCMfxw+55XrgVke+RQerlnMg3LoSe/LWivL90PZXvzxdVgcj7S9mK h49Tb/Motl6VZNeBgUgEIOi4n8J0nstJfceqYlvVvClGnmRrvrNd3azLe3/I96lYhwQjNf DDdXKm2GqUHud3rA5nWlHyBheFeCBDk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-567-t2YgIOmwO7ugWLUU88GpeQ-1; Fri, 26 Aug 2022 16:43:52 -0400 X-MC-Unique: t2YgIOmwO7ugWLUU88GpeQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE35E3C0F398; Fri, 26 Aug 2022 20:43:51 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DAD7945D2; Fri, 26 Aug 2022 20:43:51 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 27QKhpZP024898; Fri, 26 Aug 2022 16:43:51 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 27QKhpRT024894; Fri, 26 Aug 2022 16:43:51 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Fri, 26 Aug 2022 16:43:51 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Linus Torvalds , Brian Cain , linux-hexagon@vger.kernel.org cc: Geert Uytterhoeven , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Linux Kernel Mailing List , Linux-Arch Subject: [PATCH] provide arch_test_bit_acquire for architectures that define test_bit In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: TEXT/PLAIN; charset="utf-8" On Fri, 26 Aug 2022, Linus Torvalds wrote: > On Fri, Aug 26, 2022 at 12:23 PM Geert Uytterhoeven > wrote: > > > > include/asm-generic/bitops/non-instrumented-non-atomic.h:15:33: > > error: implicit declaration of function 'arch_test_bit_acquire'; did > > you mean '_test_bit_acquire'? [-Werror=3Dimplicit-function-declaration] > > >=20 > Ahh. m68k isn't using any of the generic bitops headers. >=20 > *Most* architectures have that >=20 > #include >=20 > and get it that way, but while it's common, it's most definitely not univ= ersal: >=20 > [torvalds@ryzen linux]$ git grep -L bitops/non-atomic.h > arch/*/include/asm/bitops.h > arch/alpha/include/asm/bitops.h > arch/hexagon/include/asm/bitops.h > arch/ia64/include/asm/bitops.h > arch/m68k/include/asm/bitops.h > arch/s390/include/asm/bitops.h > arch/sparc/include/asm/bitops.h > arch/x86/include/asm/bitops.h >=20 > and of that list only x86 has the new arch_test_bit_acquire(). >=20 > So I assume it's not just m68k, but also alpha, hexagon, ia64, s390 > and sparc that have this issue (unless they maybe have some other path > that includes the gerneric ones, I didn't check). For sparc, there is arch/sparc/include/asm/bitops_32.h and=20 arch/sparc/include/asm/bitops_64.h that include=20 asm-generic/bitops/non-atomic.h For the others, the generic version is not included. I'm wondering why do the architectures redefine test_bit, if their=20 definition is equivalent to the generic one? We could just delete=20 arch_test_bit and use "#define arch_test_bit generic_test_bit" as well. > This was actually why my original suggested patch used the > 'generic-non-atomic.h' header for it, because that is actually > included regardless of any architecture headers directly from > . >=20 > And it never triggered for me that Mikulas' updated patch then had > this arch_test_bit_acquire() issue. >=20 > Something like the attached patch *MAY* fix it, but I really haven't > thought about it a lot, and it's pretty ugly. Maybe it would be better > to just add the >=20 > #define arch_test_bit_acquire generic_test_bit_acquire >=20 > to the affected files instead, and then let those > architectures decide on their own that maybe they want to use their > own test_bit() function because it is _already_ an acquire one. >=20 > Mikulas? >=20 > Geert - any opinions on that "maybe the arch should just do that > #define itself"? I don't think it actually matters for m68k, you end > up with pretty much the same thing anyway, because > "smp_load_acquire()" is just a load anyway.. >=20 > Linus Another untested patch ... tomorrow, I'll try to compile it, at least for=20 architectures where Debian provides cross-compiling gcc. From: Mikulas Patocka Some architectures define their own arch_test_bit and they also need arch_test_bit_acquire, otherwise they won't compile. We also clean up the code by using the generic test_bit if that is equivalent to the arch-specific version. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Fixes: 8238b4579866 ("wait_on_bit: add an acquire memory barrier") --- arch/alpha/include/asm/bitops.h | 7 ++----- arch/hexagon/include/asm/bitops.h | 15 +++++++++++++++ arch/ia64/include/asm/bitops.h | 7 ++----- arch/m68k/include/asm/bitops.h | 7 ++----- arch/s390/include/asm/bitops.h | 10 ++-------- arch/sh/include/asm/bitops-op32.h | 12 ++---------- 6 files changed, 25 insertions(+), 33 deletions(-) Index: linux-2.6/arch/alpha/include/asm/bitops.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/alpha/include/asm/bitops.h +++ linux-2.6/arch/alpha/include/asm/bitops.h @@ -283,11 +283,8 @@ arch___test_and_change_bit(unsigned long return (old & mask) !=3D 0; } =20 -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) !=3D 0UL; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire =20 /* * ffz =3D Find First Zero in word. Undefined if no zero exists, Index: linux-2.6/arch/hexagon/include/asm/bitops.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/hexagon/include/asm/bitops.h +++ linux-2.6/arch/hexagon/include/asm/bitops.h @@ -179,6 +179,21 @@ arch_test_bit(unsigned long nr, const vo return retval; } =20 +static __always_inline bool +arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr) +{ + int retval; + + asm volatile( + "{P0 =3D tstbit(%1,%2); if (P0.new) %0 =3D #1; if (!P0.new) %0 =3D #0;}\n" + : "=3D&r" (retval) + : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG) + : "p0", "memory" + ); + + return retval; +} + /* * ffz - find first zero in word. * @word: The word to search Index: linux-2.6/arch/ia64/include/asm/bitops.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/ia64/include/asm/bitops.h +++ linux-2.6/arch/ia64/include/asm/bitops.h @@ -331,11 +331,8 @@ arch___test_and_change_bit(unsigned long return (old & bit) !=3D 0; } =20 -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return 1 & (((const volatile __u32 *) addr)[nr >> 5] >> (nr & 31)); -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire =20 /** * ffz - find the first zero bit in a long word Index: linux-2.6/arch/s390/include/asm/bitops.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/s390/include/asm/bitops.h +++ linux-2.6/arch/s390/include/asm/bitops.h @@ -176,14 +176,8 @@ arch___test_and_change_bit(unsigned long return old & mask; } =20 -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - const volatile unsigned long *p =3D __bitops_word(nr, addr); - unsigned long mask =3D __bitops_mask(nr); - - return *p & mask; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire =20 static inline bool arch_test_and_set_bit_lock(unsigned long nr, volatile unsigned long *ptr) Index: linux-2.6/arch/m68k/include/asm/bitops.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/m68k/include/asm/bitops.h +++ linux-2.6/arch/m68k/include/asm/bitops.h @@ -157,11 +157,8 @@ arch___change_bit(unsigned long nr, vola change_bit(nr, addr); } =20 -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return (addr[nr >> 5] & (1UL << (nr & 31))) !=3D 0; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire =20 static inline int bset_reg_test_and_set_bit(int nr, volatile unsigned long *vaddr) Index: linux-2.6/arch/sh/include/asm/bitops-op32.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.orig/arch/sh/include/asm/bitops-op32.h +++ linux-2.6/arch/sh/include/asm/bitops-op32.h @@ -135,16 +135,8 @@ arch___test_and_change_bit(unsigned long return (old & mask) !=3D 0; } =20 -/** - * arch_test_bit - Determine whether a bit is set - * @nr: bit number to test - * @addr: Address to start counting from - */ -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire =20 #include