Skip to contentSkip to conversation

virtio-mem: only mark the device ready in kdump mode with vmcore support

PATCH Superseded Yuho Choi 4 participants 5 messages Oct 16 – Nov 2

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 virtio-mem: only mark the device ready in kdump mode with vmcore support

virtio_mem_init_kdump() marks the device DRIVER_OK before it checks for CONFIG_PROC_VMCORE. Without vmcore support it then fails with -EBUSY, and virtio_mem_probe() deletes the virtqueue on that error path without resetting the device first, so the device is left believing the driver is ready while its queue points at memory that has been freed.

Before commit a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode"), virtio_mem_probe() called virtio_device_ready() only after virtio_mem_init() had succeeded, so this path never exposed a ready device.

Move virtio_device_ready() into the CONFIG_PROC_VMCORE branch, right before the vmcore callbacks that need it are registered, so the -EBUSY path never sets DRIVER_OK.

Fixes a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode")
---
 drivers/virtio/virtio_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_mem.c +1 -1
index e18dd736f2ec..b28d2da7d5b6 100644
@@ -2817,9 +2817,9 @@ static int virtio_mem_vmcore_get_device_ram(struct vmcore_cb *cb,
 
 static int virtio_mem_init_kdump(struct virtio_mem *vm)
 {
+#ifdef CONFIG_PROC_VMCORE
 	/* We must be prepared to receive a callback immediately. */
 	virtio_device_ready(vm->vdev);
-#ifdef CONFIG_PROC_VMCORE
 	dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n");
 	vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram;
 #ifdef CONFIG_PROC_VMCORE_DEVICE_RAM
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

virtio_mem_init_kdump() marks the device DRIVER_OK before it checks for CONFIG_PROC_VMCORE. Without vmcore support it then fails with -EBUSY, and virtio_mem_probe() deletes the virtqueue on that error path without resetting the device first, so the device is left believing the driver is ready while its queue points at memory that has been freed.

Before commit a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode"), virtio_mem_probe() called virtio_device_ready() only after virtio_mem_init() had succeeded, so this path never exposed a ready device.

Quoted 7 lines

Move virtio_device_ready() into the CONFIG_PROC_VMCORE branch, right before the vmcore callbacks that need it are registered, so the -EBUSY path never sets DRIVER_OK.

Fixes a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Yuho Choi
Quoted 11 lines · Yuho Choi

virtio_mem_init_kdump() marks the device DRIVER_OK before it checks for CONFIG_PROC_VMCORE. Without vmcore support it then fails with -EBUSY, and virtio_mem_probe() deletes the virtqueue on that error path without resetting the device first, so the device is left believing the driver is ready while its queue points at memory that has been freed.

Before commit a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode"), virtio_mem_probe() called virtio_device_ready() only after virtio_mem_init() had succeeded, so this path never exposed a ready device.

Quoted 6 lines

Move virtio_device_ready() into the CONFIG_PROC_VMCORE branch, right before the vmcore callbacks that need it are registered, so the -EBUSY path never sets DRIVER_OK.

Fixes a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode")

Which kdump kernel exists that does not enable CONFIG_PROC_VMCORE?

IOW, why should this be stable material?

Quoted 10 lines
---
 drivers/virtio/virtio_mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_mem.c +0 -0
index e18dd736f2ec..b28d2da7d5b6 100644

drivers/virtio/virtio_mem.c static int virtio_mem_vmcore_get_device_ram(struct vmcore_cb *cb, · line 2825

Quoted 10 lines
drivers/virtio/virtio_mem.c +1 -1
@@ -2817,9 +2817,9 @@ static int virtio_mem_vmcore_get_device_ram(struct vmcore_cb *cb,
 
 static int virtio_mem_init_kdump(struct virtio_mem *vm)
 {
+#ifdef CONFIG_PROC_VMCORE
 	/* We must be prepared to receive a callback immediately. */
 	virtio_device_ready(vm->vdev);
-#ifdef CONFIG_PROC_VMCORE
 	dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n");
 	vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram;
 #ifdef CONFIG_PROC_VMCORE_DEVICE_RAM

LGTM, but I am pretty sure it does not make any difference in practice?

Signature · 3 lines
Cheers,

David
author
#3 lore raw
Quoted 4 lines · David Hildenbrand (Arm)

Which kdump kernel exists that does not enable CONFIG_PROC_VMCORE?

IOW, why should this be stable material?

I tagged it because a9403425b3cf has been in releases since v6.14 and PROC_VMCORE can still be turned off with CRASH_DUMP enabled, so the -EBUSY path is reachable in a valid configuration. But as no practical kdump kernel disables it, I'll drop the Cc: stable in v2.

Quoted 1 line

LGTM, but I am pretty sure it does not make any difference in practice?

Right, nothing is queued on that path, so the device has nothing to access.

#4 lore raw
Quoted 10 lines · Yuho Choi
Quoted 4 lines · David Hildenbrand (Arm)

Which kdump kernel exists that does not enable CONFIG_PROC_VMCORE?

IOW, why should this be stable material?

I tagged it because a9403425b3cf has been in releases since v6.14 and PROC_VMCORE can still be turned off with CRASH_DUMP enabled, so the -EBUSY path is reachable in a valid configuration. But as no practical kdump kernel disables it, I'll drop the Cc: stable in v2.

still did not get v2.

Quoted 4 lines
Quoted 1 line

LGTM, but I am pretty sure it does not make any difference in practice?

Right, nothing is queued on that path, so the device has nothing to access.