virtio_console: allocate the port_buffer with the caller's gfp
Subsystems (3)
PATCH 1/1 virtio_console: allocate the port_buffer with the caller's gfp
put_chars() runs from the hvc console write path with preemption disabled, so it asks alloc_buf() for GFP_ATOMIC. Only the data buffer gets it: the struct port_buffer itself keeps the GFP_KERNEL default, so the allocation can enter direct reclaim and sleep. A write to /dev/kmsg on a CONFIG_DEBUG_ATOMIC_SLEEP kernel splats:
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>
Pass gfp on to that allocation too.
--- drivers/char/virtio_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/virtio_console.c +1 -1
@@ -426,7 +426,7 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size* Allocate buffer and the sg list. The sg list array is allocated * directly after the port_buffer struct. */ - buf =kmalloc_flex (*buf, sg, pages); + buf =kmalloc_flex (*buf, sg, pages, gfp);if (!buf) goto fail;
---
base-commit: 6b8c8af514d739d0335f5579b585e02babe8a727
change-id: 20260810-serial-d9b259ec9100
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Quoted 28 lines · Breno Leitao
put_chars()runs from the hvc console write path with preemption disabled, so it asksalloc_buf()forGFP_ATOMIC. Only the data buffer gets it: the structport_bufferitself keeps theGFP_KERNELdefault, so the allocation can enter direct reclaim and sleep. A write to/dev/kmsgon aCONFIG_DEBUG_ATOMIC_SLEEPkernel splats:BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>
Quoted 4 lines
Pass gfp on to that allocation too.
Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership")Signed-off-by Breno Leitao <[email protected]>
Ping?
I am sorry for the late reply.
I fully agree with your patch.
It was my mistake. I should have to allocate the buffer with gfp flags. Thank you for the corrections.
On 2026년 8월 18일 오후 6시 6분 37초 GMT+09:00, Breno Leitao <[email protected]> 작성함:
Quoted 36 lines · Breno Leitao
Quoted 28 lines
put_chars()runs from the hvc console write path with preemption disabled, so it asksalloc_buf()forGFP_ATOMIC. Only the data buffer gets it: the structport_bufferitself keeps theGFP_KERNELdefault, so the allocation can enter direct reclaim and sleep. A write to/dev/kmsgon aCONFIG_DEBUG_ATOMIC_SLEEPkernel splats:BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>Quoted 4 lines
Pass gfp on to that allocation too.
Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership")Signed-off-by Breno Leitao <[email protected]>Ping?
Hello Sungho,
Quoted 4 lines · Sungho Bae
I am sorry for the late reply.
I fully agree with your patch.
It was my mistake. I should have to allocate the buffer with gfp flags. Thank you for the corrections.
Thanks, would you mind adding your reviewed-by or acked-by tag, please?
--breno
Hi Breno,
(Sorry, sending this again as I forgot to use reply-all in my previous email.)
Quoted 29 lines · Breno Leitao
put_chars()runs from the hvc console write path with preemption disabled, so it asksalloc_buf()forGFP_ATOMIC. Only the data buffer gets it: the structport_bufferitself keeps theGFP_KERNELdefault, so the allocation can enter direct reclaim and sleep. A write to/dev/kmsgon aCONFIG_DEBUG_ATOMIC_SLEEPkernel splats:BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>
Quoted 4 lines
Pass gfp on to that allocation too.
Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership")Signed-off-by Breno Leitao <[email protected]>
Looks good to me.
Thanks for fixing the part I missed.
--
Thanks,
Sungho
Quoted 29 lines · Sungho Bae
Quoted 29 lines
put_chars()runs from the hvc console write path with preemption disabled, so it asksalloc_buf()forGFP_ATOMIC. Only the data buffer gets it: the structport_bufferitself keeps theGFP_KERNELdefault, so the allocation can enter direct reclaim and sleep. A write to/dev/kmsgon aCONFIG_DEBUG_ATOMIC_SLEEPkernel splats:BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>
Quoted 6 lines
Quoted 4 lines
Pass gfp on to that allocation too.
Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership")Signed-off-by Breno Leitao <[email protected]>Acked-by Sungho Bae <[email protected]>
Greg, are you the one that should pick this up?
The regression fixed here is now on Linus' tree.
Thanks
--breno
Greg KH
maintainerQuoted 32 lines · Breno Leitao
Quoted 31 lines · Sungho Bae
Quoted 31 lines
put_chars()runs from the hvc console write path with preemption disabled, so it asksalloc_buf()forGFP_ATOMIC. Only the data buffer gets it: the structport_bufferitself keeps theGFP_KERNELdefault, so the allocation can enter direct reclaim and sleep. A write to/dev/kmsgon aCONFIG_DEBUG_ATOMIC_SLEEPkernel splats:BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:320 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1, name: virtme-ng-init preempt_count: 1, expected: 0 Preemption disabled at: [<ffffffff813fd90d>] vprintk_emit+0x17d/0x510 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 __might_resched+0x37a/0x4d0 __kmalloc_cache_noprof+0x94/0x5f0 put_chars+0x209/0x3e0 hvc_console_print+0x234/0x640 console_flush_all+0x4fc/0x950 console_unlock+0xbf/0x1b0 vprintk_emit+0x312/0x510 devkmsg_emit+0xba/0x110 devkmsg_write+0x21b/0x2e0 vfs_write+0x4dc/0x9d0 ksys_write+0x108/0x1e0 do_syscall_64+0xfa/0x460 </TASK>Pass gfp on to that allocation too.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership")Signed-off-by Breno Leitao <[email protected]>Acked-by Sungho Bae <[email protected]>Greg, are you the one that should pick this up?
The regression fixed here is now on Linus' tree.
I can, after -rc1 is out, sorry.
greg k-h