linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/swapfile: Do not sleep with a spin lock held
@ 2020-12-02 15:15 Qian Cai
  2020-12-02 23:15 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Qian Cai @ 2020-12-02 15:15 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Qian Cai

We can't call kvfree() with a spin lock held, so defer it.

Signed-off-by: Qian Cai <qcai@redhat.com>
---
 mm/swapfile.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index c4a613688a17..d58361109066 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2867,6 +2867,7 @@ late_initcall(max_swapfiles_check);
 static struct swap_info_struct *alloc_swap_info(void)
 {
 	struct swap_info_struct *p;
+	struct swap_info_struct *defer = NULL;
 	unsigned int type;
 	int i;
 
@@ -2895,7 +2896,7 @@ static struct swap_info_struct *alloc_swap_info(void)
 		smp_wmb();
 		WRITE_ONCE(nr_swapfiles, nr_swapfiles + 1);
 	} else {
-		kvfree(p);
+		defer = p;
 		p = swap_info[type];
 		/*
 		 * Do not memset this entry: a racing procfs swap_next()
@@ -2908,6 +2909,7 @@ static struct swap_info_struct *alloc_swap_info(void)
 		plist_node_init(&p->avail_lists[i], 0);
 	p->flags = SWP_USED;
 	spin_unlock(&swap_lock);
+	kvfree(defer);
 	spin_lock_init(&p->lock);
 	spin_lock_init(&p->cont_lock);
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/swapfile: Do not sleep with a spin lock held
  2020-12-02 15:15 [PATCH] mm/swapfile: Do not sleep with a spin lock held Qian Cai
@ 2020-12-02 23:15 ` Andrew Morton
  2020-12-02 23:39   ` Qian Cai
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2020-12-02 23:15 UTC (permalink / raw)
  To: Qian Cai; +Cc: linux-mm, linux-kernel

On Wed,  2 Dec 2020 10:15:49 -0500 Qian Cai <qcai@redhat.com> wrote:

> We can't call kvfree() with a spin lock held, so defer it.
> 

Fixes: 873d7bcfd066 ("mm/swapfile.c: use kvzalloc for swap_info_struct allocatio
n")

Do you think it's worth a cc:stable?  IOW, is this known to ever
produce a warning?

(If not, why did we need 873d7bcfd066??)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/swapfile: Do not sleep with a spin lock held
  2020-12-02 23:15 ` Andrew Morton
@ 2020-12-02 23:39   ` Qian Cai
  0 siblings, 0 replies; 3+ messages in thread
From: Qian Cai @ 2020-12-02 23:39 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel

On Wed, 2020-12-02 at 15:15 -0800, Andrew Morton wrote:
> On Wed,  2 Dec 2020 10:15:49 -0500 Qian Cai <qcai@redhat.com> wrote:
> 
> > We can't call kvfree() with a spin lock held, so defer it.
> > 
> 
> Fixes: 873d7bcfd066 ("mm/swapfile.c: use kvzalloc for swap_info_struct
> allocatio
> n")
> 
> Do you think it's worth a cc:stable?  IOW, is this known to ever
> produce a warning?

Yes, it did trigger a might_sleep() warning.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-02 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 15:15 [PATCH] mm/swapfile: Do not sleep with a spin lock held Qian Cai
2020-12-02 23:15 ` Andrew Morton
2020-12-02 23:39   ` Qian Cai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).