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]
Date: Mon, 11 Mar 2024 15:37:22 +0100
From: David Hildenbrand <david@...hat.com>
To: Barry Song <21cnbao@...il.com>, akpm@...ux-foundation.org,
 linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org, Barry Song <v-songbaohua@...o.com>
Subject: Re: [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant
 WRITE_ONCE on swap_map for err cases

On 21.02.24 22:08, Barry Song wrote:
> From: Barry Song <v-songbaohua@...o.com>
> 
> The code is quite hard to read, we are still writing swap_map after
> errors happen. Though the written value is as before,
> 
>   has_cache = count & SWAP_HAS_CACHE;
>   count &= ~SWAP_HAS_CACHE;
>   [snipped]
>   WRITE_ONCE(p->swap_map[offset], count | has_cache);
> 
> It would be better to entirely drop the WRITE_ONCE for both
> performance and readability.
> 
> Signed-off-by: Barry Song <v-songbaohua@...o.com>
> ---
>   -v2: drop goto according to Andrew, Thanks!
> 
>   mm/swapfile.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 556ff7347d5f..7cb6d9a2d51d 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3320,7 +3320,8 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)
>   	} else
>   		err = -ENOENT;			/* unused swap entry */
>   
> -	WRITE_ONCE(p->swap_map[offset], count | has_cache);
> +	if (!err)
> +		WRITE_ONCE(p->swap_map[offset], count | has_cache);
>   
>   unlock_out:
>   	unlock_cluster_or_swap_info(p, ci);

Maybe too late, but LGTM

Reviewed-by: David Hildenbrand <david@...hat.com>

-- 
Cheers,

David / dhildenb


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ