lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aKXj_zTwvk0SwUpV@yury>
Date: Wed, 20 Aug 2025 11:04:31 -0400
From: Yury Norov <yury.norov@...il.com>
To: Vivian Wang <wangruikang@...as.ac.cn>
Cc: Paul Walmsley <paul.walmsley@...ive.com>,
	Palmer Dabbelt <palmer@...belt.com>,
	Albert Ou <aou@...s.berkeley.edu>, Alexandre Ghiti <alex@...ti.fr>,
	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Vivian Wang <uwu@...m.page>, linux-riscv@...ts.infradead.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 5/6] riscv: bitops: Convert to use_alternative_likely

On Wed, Aug 20, 2025 at 09:44:49PM +0800, Vivian Wang wrote:
> Use use_alternative_likely() to check for RISCV_ISA_EXT_ZBB, replacing
> the use of asm goto with ALTERNATIVE.
> 
> The "likely" variant is used to match the behavior of the original
> implementation using ALTERNATIVE("j %l[legacy]", "nop", ...).
> 
> Signed-off-by: Vivian Wang <wangruikang@...as.ac.cn>
> ---
>  arch/riscv/include/asm/bitops.h | 112 ++++++++++++++++++----------------------
>  1 file changed, 50 insertions(+), 62 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h
> index d59310f74c2ba70caeb7b9b0e9221882117583f5..0257d547a96293909d90b017c8a48b508d0fd642 100644
> --- a/arch/riscv/include/asm/bitops.h
> +++ b/arch/riscv/include/asm/bitops.h
> @@ -47,20 +47,17 @@
>  
>  static __always_inline unsigned long variable__ffs(unsigned long word)
>  {
> -	asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
> -				      RISCV_ISA_EXT_ZBB, 1)
> -			  : : : : legacy);
> -
> -	asm volatile (".option push\n"
> -		      ".option arch,+zbb\n"
> -		      "ctz %0, %1\n"
> -		      ".option pop\n"
> -		      : "=r" (word) : "r" (word) :);
> -
> -	return word;
> -
> -legacy:
> -	return generic___ffs(word);
> +	if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) {

I don't think that 'likely' is used properly here. The likely/unlikely
wording has a meaning of a hint to the compiler:

        if (unlikely(WARN_ON(cond))
                goto err;

In your case, it's just meaningless, because whatever is 'likely' for
one CPU, will be always 'unlikely' for another. 


> +		asm volatile (".option push\n"
> +			      ".option arch,+zbb\n"
> +			      "ctz %0, %1\n"
> +			      ".option pop\n"
> +			      : "=r" (word) : "r" (word) :);
> +
> +		return word;
> +	} else {
> +		return generic___ffs(word);
> +	}
>  }

This tabs wipe most of the history. Can you reorganize your patch
such that it preserves as much history as you can?

        if (use_alternative_unlikely(...))
                return generic___ffs();

        asm volatile (".option push\n"
                      ".option arch,+zbb\n"
                      "ctz %0, %1\n"
                      ".option pop\n"
                      : "=r" (word) : "r" (word) :);

        return word;

And so on.

Thanks,
Yury

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ