Skip to contentSkip to conversation

virtio_console: Fix alloc_buf(.gfp) usage

PATCH In review Peter Zijlstra 2 participants 3 messages Aug 28 – Sep 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_console: Fix alloc_buf(.gfp) usage

Commit fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership") added a .gfp argument to alloc_buf(), but forgot to convert all allocation calls.

The result is that any GFP_ATOMIC calls, such as those from:

hvc_console_print()
put_chars()
alloc_buf(.gfp = GFP_ATOMIC)

will trip the might_sleep_if() check when used from an atomic context.

Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer

---

drivers/char/virtio_console.c +1 -1
index 62eecfa61646..7f6cbe851d1e 100644
@@ -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;
 
#1 lore raw
Quoted 22 lines · Peter Zijlstra

Commit fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership") added a .gfp argument to alloc_buf(), but forgot to convert all allocation calls.

The result is that any GFP_ATOMIC calls, such as those from:

hvc_console_print()
put_chars()
alloc_buf(.gfp = GFP_ATOMIC)

will trip the might_sleep_if() check when used from an atomic context.

Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer

---

drivers/char/virtio_console.c +0 -0
index 62eecfa61646..7f6cbe851d1e 100644

drivers/char/virtio_console.c static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size · line 432

Quoted 8 lines
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;
 

Sorry about that, will grab it after -rc1 is out.

thanks,

greg k-h

#2 lore raw
In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra

Commit fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer ownership") added a .gfp argument to alloc_buf(), but forgot to convert all allocation calls.

The result is that any GFP_ATOMIC calls, such as those from:

hvc_console_print()
put_chars()
alloc_buf(.gfp = GFP_ATOMIC)

Quoted 6 lines

will trip the might_sleep_if() check when used from an atomic context.

Fixes fc220d6be3c7 ("virtio_console: refactor __send_to_port() buffer

---

Sorry for the delay, I took this earlier patch instead:

	https://lore.kernel.org/r/[email protected]