public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Rongwei Wang <rongwei.wang@linux.alibaba.com>
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: Tue, 4 Apr 2023 12:26:00 -0700	[thread overview]
Message-ID: <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org> (raw)
In-Reply-To: <20230404154716.23058-1-rongwei.wang@linux.alibaba.com>

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?


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?


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.


  parent reply	other threads:[~2023-04-04 19:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-01 22:19 [PATCH] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() 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 [this message]
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=20230404122600.88257a623c7f72e078dcf705@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=aaron.lu@intel.com \
    --cc=bagasdotme@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rongwei.wang@linux.alibaba.com \
    --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