mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 11:26:02 +09:00
mm/swapfile: do not sleep with a spin lock held
commitb11a76b37aupstream. We can't call kvfree() with a spin lock held, so defer it. Fixes a might_sleep() runtime warning. Fixes:873d7bcfd0("mm/swapfile.c: use kvzalloc for swap_info_struct allocation") Signed-off-by: Qian Cai <qcai@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Hugh Dickins <hughd@google.com> Cc: <stable@vger.kernel.org> Link: https://lkml.kernel.org/r/20201202151549.10350-1-qcai@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
7517a38342
commit
2498ae2460
@@ -2825,6 +2825,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;
|
||||
int size = sizeof(*p) + nr_node_ids * sizeof(struct plist_node);
|
||||
@@ -2854,7 +2855,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()
|
||||
@@ -2867,6 +2868,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user