virtio-mem: only mark the device ready in kdump mode with vmcore support
Subsystems (2)
PATCH v2 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. The device is left with DRIVER_OK set and a queue that points at freed memory. Nothing has been queued at that point, so the device has nothing to process, but the driver should not leave a device it is giving up on marked ready.
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.
---
v2:
- Drop Cc: stable, as no practical kdump kernel disables PROC_VMCORE (David).
- Say in the changelog that nothing is queued on this path.
- Rebased on v7.4-rc1.
v1: https://lore.kernel.org/r/[email protected]
Compile-tested with W=1, with and without CONFIG_PROC_VMCORE.
drivers/virtio/virtio_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 13 lines
virtio_mem_init_kdump()marks the deviceDRIVER_OKbefore it checks forCONFIG_PROC_VMCORE. Without vmcore support it then fails with-EBUSY, andvirtio_mem_probe()deletes the virtqueue on that error path without resetting the device first. The device is left withDRIVER_OKset and a queue that points at freed memory. Nothing has been queued at that point, so the device has nothing to process, but the driver should not leave a device it is giving up on marked ready.Before commit
a9403425b3cf("virtio-mem: mark device ready before registering callbacks in kdump mode"),virtio_mem_probe()calledvirtio_device_ready()only aftervirtio_mem_init()had succeeded, so this path never exposed a ready device.
Quoted 6 lines
Move
virtio_device_ready()into theCONFIG_PROC_VMCOREbranch, right before the vmcore callbacks that need it are registered, so the-EBUSYpath never setsDRIVER_OK.Fixes a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode")Signed-off-by Yuho Choi <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 13 lines · Yuho Choi
virtio_mem_init_kdump()marks the deviceDRIVER_OKbefore it checks forCONFIG_PROC_VMCORE. Without vmcore support it then fails with-EBUSY, andvirtio_mem_probe()deletes the virtqueue on that error path without resetting the device first. The device is left withDRIVER_OKset and a queue that points at freed memory. Nothing has been queued at that point, so the device has nothing to process, but the driver should not leave a device it is giving up on marked ready.Before commit
a9403425b3cf("virtio-mem: mark device ready before registering callbacks in kdump mode"),virtio_mem_probe()calledvirtio_device_ready()only aftervirtio_mem_init()had succeeded, so this path never exposed a ready device.
Quoted 7 lines
Move
virtio_device_ready()into theCONFIG_PROC_VMCOREbranch, right before the vmcore callbacks that need it are registered, so the-EBUSYpath never setsDRIVER_OK.Fixes a9403425b3cf ("virtio-mem: mark device ready before registering callbacks in kdump mode")Signed-off-by Yuho Choi <[email protected]>---
Signature · 3 lines
Cheers, David