From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Geliang Tang <geliang@kernel.org>
Cc: Amit Shah <amit@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Kees Cook <kees@kernel.org>,
Geliang Tang <tanggeliang@kylinos.cn>,
virtualization@lists.linux.dev
Subject: Re: [PATCH] virtio_console: pass gfp flag through in alloc_buf()
Date: Sat, 5 Sep 2026 19:32:09 +0200 [thread overview]
Message-ID: <2026090559-wavy-chase-7b71@gregkh> (raw)
In-Reply-To: <e084d7ed4c03020da3de5cbe1eb3a0c2055cbbd6.1787966331.git.tanggeliang@kylinos.cn>
On Sat, Aug 29, 2026 at 09:20:39AM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The `gfp` parameter of alloc_buf() has been dead code since the
> function was introduced. The underlying allocation was always
> hardcoded to GFP_KERNEL - first via kmalloc(..., GFP_KERNEL), then
> via kmalloc_flex(*buf, sg, pages, GFP_KERNEL), and most recently
> via kmalloc_flex(*buf, sg, pages) which defaults to GFP_KERNEL.
>
> This causes a "sleeping function called from invalid context" BUG
> when the hvc console flush path calls put_chars() with IRQs
> disabled:
>
> BUG: sleeping function called from invalid context at \
> include/linux/sched/mm.h:322
> in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 416, \
> name: test_progs
> ...
> Call Trace:
> __kmalloc_noprof+0x468/0x7c0
> alloc_buf.isra.0+0x42/0x260
> put_chars+0x1e5/0x2f0
> hvc_console_print+0x29d/0x6e0
> console_emit_next_record+0x21d/0x480
> console_flush_one_record+0x431/0x6a0
> console_unlock+0xda/0x1c0
> vprintk_emit+0x300/0x350
>
> put_chars() correctly passes GFP_ATOMIC, but alloc_buf() silently
> discards it and allocates with GFP_KERNEL, which may sleep.
>
> Pass the caller-supplied gfp flag through to kmalloc_flex() so
> that atomic callers get atomic allocations.
>
> Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Sorry for the delay, I took this earlier patch instead:
https://lore.kernel.org/r/20260810-serial-v1-1-abbe51602c13@debian.org
prev parent reply other threads:[~2026-09-05 17:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-29 1:20 [PATCH] virtio_console: pass gfp flag through in alloc_buf() Geliang Tang
2026-09-05 1:14 ` Florian Westphal
2026-09-05 11:37 ` Greg Kroah-Hartman
2026-09-05 17:32 ` Greg Kroah-Hartman [this message]
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=2026090559-wavy-chase-7b71@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=amit@kernel.org \
--cc=arnd@arndb.de \
--cc=geliang@kernel.org \
--cc=kees@kernel.org \
--cc=tanggeliang@kylinos.cn \
--cc=virtualization@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.