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: <874ju5s35i.fsf@yhuang6-desk2.ccr.corp.intel.com>
Date:   Fri, 09 Dec 2022 10:48:41 +0800
From:   "Huang, Ying" <ying.huang@...el.com>
To:     Kairui Song <ryncsn@...il.com>
Cc:     linux-mm@...ck.org, Kairui Song <kasong@...cent.com>,
        linux-kernel@...r.kernel.org,
        Andrew Morton <akpm@...ux-foundation.org>,
        Miaohe Lin <linmiaohe@...wei.com>,
        David Hildenbrand <david@...hat.com>,
        Hugh Dickins <hughd@...gle.com>
Subject: Re: [PATCH 1/5] swapfile: get rid of volatile and avoid redundant read

Kairui Song <ryncsn@...il.com> writes:

> From: Kairui Song <kasong@...cent.com>
>
> Convert a volatile variable to more readable READ_ONCE. And this
> actually avoids the code from reading the variable twice redundantly
> when it races.
>
> Signed-off-by: Kairui Song <kasong@...cent.com>

LGTM, Thanks!

Reviewed-by: "Huang, Ying" <ying.huang@...el.com>

> ---
>  mm/swapfile.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 72e481aacd5d..ff4f3cb85232 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1836,13 +1836,13 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  	pte_t *pte;
>  	struct swap_info_struct *si;
>  	int ret = 0;
> -	volatile unsigned char *swap_map;
>  
>  	si = swap_info[type];
>  	pte = pte_offset_map(pmd, addr);
>  	do {
>  		struct folio *folio;
>  		unsigned long offset;
> +		unsigned char swp_count;
>  
>  		if (!is_swap_pte(*pte))
>  			continue;
> @@ -1853,7 +1853,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  
>  		offset = swp_offset(entry);
>  		pte_unmap(pte);
> -		swap_map = &si->swap_map[offset];
>  		folio = swap_cache_get_folio(entry, vma, addr);
>  		if (!folio) {
>  			struct page *page;
> @@ -1870,8 +1869,10 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  				folio = page_folio(page);
>  		}
>  		if (!folio) {
> -			if (*swap_map == 0 || *swap_map == SWAP_MAP_BAD)
> +			swp_count = READ_ONCE(si->swap_map[offset]);
> +			if (swp_count == 0 || swp_count == SWAP_MAP_BAD)
>  				goto try_next;
> +
>  			return -ENOMEM;
>  		}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ