Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp765387rwe; Fri, 26 Aug 2022 14:08:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR5S12rD0uFzJstoMdXudjPpBQFb1ek+E/KkrbdKvKx5T7A5YH/iOJlIuFA0oR7euDOg2MI4 X-Received: by 2002:a17:90a:e586:b0:1fa:d28b:ab9b with SMTP id g6-20020a17090ae58600b001fad28bab9bmr6287303pjz.47.1661548107454; Fri, 26 Aug 2022 14:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661548107; cv=none; d=google.com; s=arc-20160816; b=mQ7M4hwIoovAZ9yrafGzfwCpZ/FvifxvxXvA/MNolUAzj7mtxWiMIjazja+XOe8eWn jo2j2T6X/JquH4GhMEjqNYvJAjn7kCjUvVLxnp1nIY9HFu6ZP/K5WL75knyv5zxZitwP jRHzwq4DFFzomiCv+BR4QSPIfNAoeQT+6wFsezYzuf7Pv7mxxzrcGQrS0uQqBC8gir1f PkxEc5E8liMbE7k9tgT3yncFxxAUKE7DPnPPRKE3tZj2H8Yti7xIcHP8HRMp8PhPnRbt u80og8FO/IhMrJeACMrbmD0qShxXoX+zg+VamF/lRjdoTbY/R/HUgH/c/em475sXhaPN JUBA== 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:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=Nam1cAfsFD5oHCEiyBVoFhT08lyzL12/kSxOf4iyFlo=; b=kWRWS+2AknNve8/x9Exwo5D8ZRXu8scepkMfHoEdreKku/Sm+V6EtVz8TaOnwbFXiW nFqltK55+Nk8MIiBsmj6PpOM/30SZ28KI4U+sHuju1xOwEzW65B5Cq/7IZ5tlcMicZGY n3JxeeHDkkb4ENTWhSWjULMhx9QDeG+fb+YRIDcHP2jjiIt073gMEnu3aSySP8RYqQ/u G5TgLvbhW0P5vkmPdTS87KPp3YK4l4iIEgv5B44JGbn710q9PbNvMwfEZPmGPl2fUVU5 jYR9bTJiHEa3T/O6Ri0+sl67ml+oMx884v6QA+i7DT2QHBFSvUUINB6TAL/+C8zGfnNR yaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KBPVvgQK; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j190-20020a6380c7000000b0041d7e887487si2472595pgd.695.2022.08.26.14.08.09; Fri, 26 Aug 2022 14:08:27 -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=@redhat.com header.s=mimecast20190719 header.b=KBPVvgQK; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344686AbiHZUoE (ORCPT + 99 others); Fri, 26 Aug 2022 16:44:04 -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 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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=implicit-function-declaration] > > > > Ahh. m68k isn't using any of the generic bitops headers. > > *Most* architectures have that > > #include > > and get it that way, but while it's common, it's most definitely not universal: > > [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 > > and of that list only x86 has the new arch_test_bit_acquire(). > > 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 arch/sparc/include/asm/bitops_64.h that include 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 definition is equivalent to the generic one? We could just delete 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 > . > > And it never triggered for me that Mikulas' updated patch then had > this arch_test_bit_acquire() issue. > > 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 > > #define arch_test_bit_acquire generic_test_bit_acquire > > 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. > > Mikulas? > > 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.. > > Linus Another untested patch ... tomorrow, I'll try to compile it, at least for 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 =================================================================== --- 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) != 0; } -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return (1UL & (((const int *) addr)[nr >> 5] >> (nr & 31))) != 0UL; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire /* * ffz = Find First Zero in word. Undefined if no zero exists, Index: linux-2.6/arch/hexagon/include/asm/bitops.h =================================================================== --- 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; } +static __always_inline bool +arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr) +{ + int retval; + + asm volatile( + "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n" + : "=&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 =================================================================== --- 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) != 0; } -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 /** * ffz - find the first zero bit in a long word Index: linux-2.6/arch/s390/include/asm/bitops.h =================================================================== --- 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; } -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - const volatile unsigned long *p = __bitops_word(nr, addr); - unsigned long mask = __bitops_mask(nr); - - return *p & mask; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire 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 =================================================================== --- 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); } -static __always_inline bool -arch_test_bit(unsigned long nr, const volatile unsigned long *addr) -{ - return (addr[nr >> 5] & (1UL << (nr & 31))) != 0; -} +#define arch_test_bit generic_test_bit +#define arch_test_bit_acquire generic_test_bit_acquire 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 =================================================================== --- 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) != 0; } -/** - * 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 #include