From: Muchun Song <songmuchun@bytedance.com>
To: qiang.zhang@windriver.com
Cc: mgorman@techsingularity.net,
Andrew Morton <akpm@linux-foundation.org>,
alobakin@pm.me, wangqing@vivo.com,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [External] [PATCH] mm/page_alloc: Fix sleeping function called in case of irqsdisable.
Date: Tue, 6 Jul 2021 14:50:04 +0800 [thread overview]
Message-ID: <CAMZfGtVB-UQV0i4_mrRrt59iWFZbchm1FtT_TFhaE6Bmp43Hfw@mail.gmail.com> (raw)
In-Reply-To: <20210706032907.1276-1-qiang.zhang@windriver.com>
On Tue, Jul 6, 2021 at 11:29 AM <qiang.zhang@windriver.com> wrote:
>
> From: Zqiang <qiang.zhang@windriver.com>
>
> BUG: sleeping function called from invalid context at mm/page_alloc.c:5179
> in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 1, name: swapper/0
> .....
> __dump_stack lib/dump_stack.c:79 [inline]
> dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:96
> ___might_sleep.cold+0x1f1/0x237 kernel/sched/core.c:9153
> prepare_alloc_pages+0x3da/0x580 mm/page_alloc.c:5179
> __alloc_pages+0x12f/0x500 mm/page_alloc.c:5375
> alloc_page_interleave+0x1e/0x200 mm/mempolicy.c:2147
> alloc_pages+0x238/0x2a0 mm/mempolicy.c:2270
> stack_depot_save+0x39d/0x4e0 lib/stackdepot.c:303
> save_stack+0x15e/0x1e0 mm/page_owner.c:120
> __set_page_owner+0x50/0x290 mm/page_owner.c:181
> prep_new_page mm/page_alloc.c:2445 [inline]
> __alloc_pages_bulk+0x8b9/0x1870 mm/page_alloc.c:5313
> alloc_pages_bulk_array_node include/linux/gfp.h:557 [inline]
> vm_area_alloc_pages mm/vmalloc.c:2775 [inline]
> __vmalloc_area_node mm/vmalloc.c:2845 [inline]
> __vmalloc_node_range+0x39d/0x960 mm/vmalloc.c:2947
> __vmalloc_node mm/vmalloc.c:2996 [inline]
> vzalloc+0x67/0x80 mm/vmalloc.c:3066
>
> If the PAGE_OWNER is enabled, in __set_page_owner(), the pages will be
> allocated to save calltrace info, due to the allocated action is executed
> under irq disable(pagesets.lock be held), if the gfp variable contains
> the flag that causes sleep, will trigger above information. the
> prep_new_page() is not need to disable irq for protection, fix it through
> enable irq before call prep_new_page().
>
> Fixes: 0f87d9d30f21 ("mm/page_alloc: add an array-based interface to the bulk page allocator")
> Reported-by: syzbot+0123a2b8f9e623d5b443@syzkaller.appspotmail.com
> Signed-off-by: Zqiang <qiang.zhang@windriver.com>
> ---
> mm/page_alloc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index d6e94cc8066c..8d7f0f5ce891 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5309,12 +5309,14 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
> }
> nr_account++;
>
> + local_unlock_irqrestore(&pagesets.lock, flags);
> prep_new_page(page, 0, gfp, 0);
> if (page_list)
> list_add(&page->lru, page_list);
> else
> page_array[nr_populated] = page;
> nr_populated++;
> + local_lock_irqsave(&pagesets.lock, flags);
Because pagesets.lock is relocked here, the current
thread can be scheduled to another CPU. The @pcp
and @pcp_list need to be reloaded. Otherwise, it is
broken in the next loop.
Thanks.
> }
>
> local_unlock_irqrestore(&pagesets.lock, flags);
> --
> 2.17.1
>
next prev parent reply other threads:[~2021-07-06 6:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-06 3:29 qiang.zhang
2021-07-06 6:50 ` Muchun Song [this message]
2021-07-06 7:16 ` [External] " Zhang, Qiang
2021-07-06 8:19 ` Mel Gorman
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=CAMZfGtVB-UQV0i4_mrRrt59iWFZbchm1FtT_TFhaE6Bmp43Hfw@mail.gmail.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=alobakin@pm.me \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=qiang.zhang@windriver.com \
--cc=wangqing@vivo.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