From: Matthew Wilcox <willy@infradead.org>
To: Rongwei Wang <rongwei.wang@linux.alibaba.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, linux-stable@vger.kernel.org
Subject: Re: [PATCH] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages()
Date: Mon, 3 Apr 2023 05:10:28 +0100 [thread overview]
Message-ID: <ZCpRtASqL5z5QphY@casper.infradead.org> (raw)
In-Reply-To: <20230401221920.57986-1-rongwei.wang@linux.alibaba.com>
On Sun, Apr 02, 2023 at 06:19:20AM +0800, Rongwei Wang wrote:
> Without this modification, a core will wait (mostly)
> 'swap_info_struct->lock' when completing
> 'del_from_avail_list(p)'. Immediately, other cores
> soon calling 'add_to_avail_list()' to add the same
> object again when acquiring the lock that released
> by former. It's not the desired result but exists
> indeed. This case can be described as below:
This feels like a very verbose way of saying
"The si->lock must be held when deleting the si from the
available list. Otherwise, another thread can re-add the
si to the available list, which can lead to memory corruption.
The only place we have found where this happens is in the
swapoff path."
> +++ b/mm/swapfile.c
> @@ -2610,8 +2610,12 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> spin_unlock(&swap_lock);
> goto out_dput;
> }
> - del_from_avail_list(p);
> + /*
> + * Here lock is used to protect deleting and SWP_WRITEOK clearing
> + * can be seen concurrently.
> + */
This comment isn't necessary. But I would add a lockdep assert inside
__del_from_avail_list() that p->lock is held.
> spin_lock(&p->lock);
> + del_from_avail_list(p);
> if (p->prio < 0) {
> struct swap_info_struct *si = p;
> int nid;
> --
> 2.27.0
>
>
next prev parent reply other threads:[~2023-04-03 4:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-01 22:19 Rongwei Wang
2023-04-02 13:37 ` Bagas Sanjaya
2023-04-02 14:56 ` Rongwei Wang
2023-04-03 4:10 ` Matthew Wilcox [this message]
2023-04-03 8:02 ` Rongwei Wang
2023-04-04 15:47 ` [PATCH v2] " Rongwei Wang
2023-04-04 16:08 ` Rongwei Wang
2023-04-06 12:12 ` Aaron Lu
2023-04-06 12:55 ` Rongwei Wang
2023-04-04 19:26 ` Andrew Morton
2023-04-05 6:49 ` Rongwei Wang
2023-04-06 6:58 ` Aaron Lu
2023-04-06 12:20 ` Rongwei Wang
2023-04-06 14:04 ` Aaron Lu
2023-04-06 14:57 ` Aaron Lu
2023-04-07 2:20 ` Rongwei Wang
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=ZCpRtASqL5z5QphY@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-stable@vger.kernel.org \
--cc=rongwei.wang@linux.alibaba.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