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] [day] [month] [year] [list]
Message-ID: <kh7s7k4hipfppnthiq463svhzfqr7m2ovl3zehofmqyxps3d4s@jlklhf5mtrdx>
Date: Fri, 22 Aug 2025 16:20:07 +0200
From: Jan Kara <jack@...e.cz>
To: Uros Bizjak <ubizjak@...il.com>
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Alexander Viro <viro@...iv.linux.org.uk>, Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>
Subject: Re: [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq()

On Mon 11-08-25 15:23:03, Uros Bizjak wrote:
> Use !try_cmpxchg() instead of cmpxchg(*ptr, old, new) != old.
> 
> The x86 CMPXCHG instruction returns success in the ZF flag,
> so this change saves a compare after CMPXCHG.
> 
> No functional change intended.
> 
> Signed-off-by: Uros Bizjak <ubizjak@...il.com>
> Cc: Alexander Viro <viro@...iv.linux.org.uk>
> Cc: Christian Brauner <brauner@...nel.org>
> Cc: Jan Kara <jack@...e.cz>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@...e.cz>

								Honza

> ---
>  fs/super.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 7f876f32343a..e91718017701 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -2318,13 +2318,15 @@ int sb_init_dio_done_wq(struct super_block *sb)
>  						      sb->s_id);
>  	if (!wq)
>  		return -ENOMEM;
> +
> +	old = NULL;
>  	/*
>  	 * This has to be atomic as more DIOs can race to create the workqueue
>  	 */
> -	old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
> -	/* Someone created workqueue before us? Free ours... */
> -	if (old)
> +	if (!try_cmpxchg(&sb->s_dio_done_wq, &old, wq)) {
> +		/* Someone created workqueue before us? Free ours... */
>  		destroy_workqueue(wq);
> +	}
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(sb_init_dio_done_wq);
> -- 
> 2.50.1
> 
-- 
Jan Kara <jack@...e.com>
SUSE Labs, CR

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ