From: Rongwei Wang <rongwei.wang@linux.alibaba.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: bagasdotme@gmail.com, willy@infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Aaron Lu <aaron.lu@intel.com>
Subject: Re: [PATCH v2] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages()
Date: Wed, 5 Apr 2023 14:49:48 +0800 [thread overview]
Message-ID: <527978d9-3f6f-b507-5f0f-b24311ff78e4@linux.alibaba.com> (raw)
In-Reply-To: <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org>
Hi Andrew
On 4/5/23 3:26 AM, Andrew Morton wrote:
> On Tue, 4 Apr 2023 23:47:16 +0800 Rongwei Wang <rongwei.wang@linux.alibaba.com> wrote:
>
>> The si->lock must be held when deleting the si from
>> the available list.
>>
>> ...
>>
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -679,6 +679,7 @@ static void __del_from_avail_list(struct swap_info_struct *p)
>> {
>> int nid;
>>
>> + assert_spin_locked(&p->lock);
>> for_each_node(nid)
>> plist_del(&p->avail_lists[nid], &swap_avail_heads[nid]);
>> }
>> @@ -2434,8 +2435,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
>> spin_unlock(&swap_lock);
>> goto out_dput;
>> }
>> - del_from_avail_list(p);
>> spin_lock(&p->lock);
>> + del_from_avail_list(p);
>> if (p->prio < 0) {
>> struct swap_info_struct *si = p;
>> int nid;
> So we have
>
> swap_avail_lock
> swap_info_struct.lock
> swap_cluster_info.lock
>
> Is the ranking of these three clearly documented somewhere?
It seems have
swap_lock
swap_info_struct.lock
swap_avail_lock
I just summary the ranking of these three locks by reading code, not
find any documents (maybe have).
>
>
> Did you test this with lockdep fully enabled?
>
>
> I'm thinking that Aaron's a2468cc9bfdff ("swap: choose swap device
> according to numa node") is the appropriate Fixes: target - do you
> agree?
Yes, I'm sure my latest test version has included Aaron's a2468cc9bfdff,
and my test .config has enabled CONFIG
as below:
CONFIG_LOCK_DEBUGGING_SUPPORT=y CONFIG_PROVE_LOCKING=y
CONFIG_DEBUG_SPINLOCK=y CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_LOCKDEP=y
CONFIG_DEBUG_LOCKDEP=y CONFIG_DEBUG_ATOMIC_SLEEP=y
>
>
> These functions use identifier `p' for the swap_info_struct*, whereas
> most other code uses the much more sensible `si'. That's just rude.
> But we shouldn't change that within this fix.
Indeed, It's confusing more or less to use both 'si' and 'p'. I can
ready for another patch to replace 'p' with 'si'.
Thanks.
next prev parent reply other threads:[~2023-04-05 6:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-01 22:19 [PATCH] " Rongwei Wang
2023-04-02 13:37 ` Bagas Sanjaya
2023-04-02 14:56 ` Rongwei Wang
2023-04-03 4:10 ` Matthew Wilcox
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 [this message]
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=527978d9-3f6f-b507-5f0f-b24311ff78e4@linux.alibaba.com \
--to=rongwei.wang@linux.alibaba.com \
--cc=aaron.lu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=bagasdotme@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.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