mm/swapfile: fix possible data races of inuse_pages
authorMiaohe Lin <linmiaohe@huawei.com>
Wed, 8 Jun 2022 14:40:30 +0000 (22:40 +0800)
committerakpm <akpm@linux-foundation.org>
Mon, 4 Jul 2022 01:08:42 +0000 (18:08 -0700)
commitc8945306976f497802b208cf8f2cad4543868bc6
tree52be9312a6af5bfc3e1688252c5247060ac89abe
parent5e21f2d577cf174ced5fe9bdff67dcb70190d9f8
mm/swapfile: fix possible data races of inuse_pages

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.  READ_ONCE and WRITE_ONCE is used to fix such data
races.  Note these data races should be ok because they're just used for
showing swap info.

[linmiaohe@huawei.com: use WRITE_ONCE to pair with READ_ONCE]
Link: https://lkml.kernel.org/r/20220625093346.48894-2-linmiaohe@huawei.com
Link: https://lkml.kernel.org/r/20220608144031.829-3-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c