From: Qian Cai <quic_qiancai@quicinc.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: Muchun Song <songmuchun@bytedance.com>,
"Huang, Ying" <ying.huang@intel.com>, <akpm@linux-foundation.org>,
<david@redhat.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] mm/swapfile: fix possible data races of inuse_pages
Date: Mon, 20 Jun 2022 09:46:47 -0400 [thread overview]
Message-ID: <YrB6R5uHQaz1adhK@qian> (raw)
In-Reply-To: <b61771ad-9daa-741e-27e4-fdb50a7c5e38@huawei.com>
On Mon, Jun 20, 2022 at 08:32:27PM +0800, Miaohe Lin wrote:
> >>>>> --- a/mm/swapfile.c
> >>>>> +++ b/mm/swapfile.c
> >>>>> @@ -2646,7 +2646,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\\");
> >>>>> @@ -3265,7 +3265,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;
> >>>>
> >>>> READ_ONCE() should be paired with WRITE_ONCE(). So, change the writer
> >>>> side too?
> >>>
> >>> READ_ONCE() is used to fix the complaint of concurrent accessing to si->inuse_pages from KCSAN here.
> >>> The similar commit is 218209487c3d ("mm/swapfile: fix data races in try_to_unuse()"). IMHO, it's fine
> >>
> >> I think the fix 218209487c3d is incomplete. The write side in swap_range_free() should
> >> also be fixed. Otherwise, IIUC, it cannot stop KCSAN complaining.
> >
> > I tend to agree with you. READ_ONCE() should be paired with WRITE_ONCE() theoretically. But WRITTE_ONCE()
> > is ignored while the commit is introduced. Add Qian Cai for helping verify it. It's very kind of @Qian Cai
> > if he could tell us whether WRITTE_ONCE() is ignored deliberately.
The write side should be protected by the lock swap_info_struct::lock. Is
that not the case here?
next prev parent reply other threads:[~2022-06-20 13:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 14:40 [PATCH v2 0/3] A few cleanup and fixup patches for swap Miaohe Lin
2022-06-08 14:40 ` [PATCH v2 1/3] mm/swapfile: make security_vm_enough_memory_mm() work as expected Miaohe Lin
2022-06-17 7:33 ` David Hildenbrand
2022-06-18 2:43 ` Miaohe Lin
2022-06-18 7:10 ` David Hildenbrand
2022-06-18 7:31 ` Miaohe Lin
2022-06-20 7:31 ` Huang, Ying
2022-06-20 12:12 ` Miaohe Lin
2022-06-21 1:35 ` Huang, Ying
2022-06-21 7:37 ` Miaohe Lin
2022-06-21 7:42 ` Huang, Ying
2022-06-21 8:20 ` Miaohe Lin
2022-06-08 14:40 ` [PATCH v2 2/3] mm/swapfile: fix possible data races of inuse_pages Miaohe Lin
2022-06-20 7:54 ` Huang, Ying
2022-06-20 9:04 ` Miaohe Lin
2022-06-20 9:23 ` Muchun Song
2022-06-20 12:23 ` Miaohe Lin
2022-06-20 12:32 ` Miaohe Lin
2022-06-20 13:46 ` Qian Cai [this message]
2022-06-20 14:20 ` Muchun Song
2022-06-20 21:36 ` Qian Cai
2022-06-21 1:14 ` Huang, Ying
2022-06-21 3:39 ` Muchun Song
2022-06-21 6:40 ` Miaohe Lin
2022-06-08 14:40 ` [PATCH v2 3/3] mm/swap: remove swap_cache_info statistics Miaohe Lin
2022-06-08 15:16 ` David Hildenbrand
2022-06-20 8:08 ` Huang, Ying
2022-06-20 9:05 ` Miaohe Lin
2022-06-20 9:30 ` Muchun Song
2022-06-17 2:37 ` [PATCH v2 0/3] A few cleanup and fixup patches for swap Andrew Morton
2022-06-17 3:00 ` Miaohe Lin
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=YrB6R5uHQaz1adhK@qian \
--to=quic_qiancai@quicinc.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=songmuchun@bytedance.com \
--cc=ying.huang@intel.com \
/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