linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Miaohe Lin <linmiaohe@huawei.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages
Date: Tue, 31 May 2022 15:02:24 +0200	[thread overview]
Message-ID: <768fbb44-90c3-1f88-73a0-8765b2233226@redhat.com> (raw)
In-Reply-To: <20220527092626.31883-4-linmiaohe@huawei.com>

On 27.05.22 11:26, Miaohe Lin wrote:
> si->inuse_pages could still be accessed concurrently now. The plain reads
> outside si->lock critical section, i.e. swap_show and si_swapinfo, which
> results in data races. But these should be ok because they're just used
> for showing swap info.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/swapfile.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index e033a53a99df..29d7ca9eaa3c 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2649,7 +2649,7 @@ static int swap_show(struct seq_file *swap, void *v)
>  	}
>  
>  	bytes = si->pages << (PAGE_SHIFT - 10);
> -	inuse = si->inuse_pages << (PAGE_SHIFT - 10);
> +	inuse = READ_ONCE(si->inuse_pages) << (PAGE_SHIFT - 10);
>  
>  	file = si->swap_file;
>  	len = seq_file_path(swap, file, " \t\n\\");
> @@ -3268,7 +3268,7 @@ void si_swapinfo(struct sysinfo *val)
>  		struct swap_info_struct *si = swap_info[type];
>  
>  		if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK))
> -			nr_to_be_unused += si->inuse_pages;
> +			nr_to_be_unused += READ_ONCE(si->inuse_pages);
>  	}
>  	val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
>  	val->totalswap = total_swap_pages + nr_to_be_unused;


AFAIKT, this makes sense

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

-- 
Thanks,

David / dhildenb



      reply	other threads:[~2022-05-31 13:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27  9:26 [PATCH 0/3] A few fixup patches for swap Miaohe Lin
2022-05-27  9:26 ` [PATCH 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
2022-05-30 23:02   ` Andrew Morton
2022-05-31  2:40     ` Miaohe Lin
2022-05-27  9:26 ` [PATCH 2/3] mm/swapfile: avoid confusing swap cache statistics Miaohe Lin
2022-05-30 23:04   ` Andrew Morton
2022-05-31  2:55     ` Miaohe Lin
2022-05-31 12:58       ` David Hildenbrand
2022-06-01  2:11         ` Miaohe Lin
2022-06-01  7:53           ` David Hildenbrand
2022-06-02  7:29             ` Miaohe Lin
2022-06-02  8:41               ` David Hildenbrand
2022-06-06  3:14                 ` Miaohe Lin
2022-05-27  9:26 ` [PATCH 3/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
2022-05-31 13:02   ` David Hildenbrand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=768fbb44-90c3-1f88-73a0-8765b2233226@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox