Skip to content

Commit 8ed0239

Browse files
Taylor Starktyhicks
authored andcommitted
virtio-pmem: Set DRIVER_OK status prior to creating pmem region
Update virtio-pmem to call virtio_device_ready prior to creating the pmem region. Otherwise, the guest may try to access the pmem region prior to the DRIVER_OK status being set. In the case of Hyper-V, the backing pmem file isn't mapped to the guest until the DRIVER_OK status is set. Therefore, attempts to access the pmem region can cause the guest to crash. Hyper-V could map the file earlier, for example at VM creation, but we didn't want to pay the mapping cost if the device is never used. Additionally, it felt weird to allow the guest to access the region prior to the device fully coming online. Signed-off-by: Taylor Stark <[email protected]> Reviewed-by: Pankaj Gupta <[email protected]> Link: https://lore.kernel.org/r/20210715223638.GA29649@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net Signed-off-by: Tyler Hicks <[email protected]>
1 parent 171d82c commit 8ed0239

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/nvdimm/virtio_pmem.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
9191

9292
dev_set_drvdata(&vdev->dev, vpmem->nvdimm_bus);
9393

94+
/* Online the device prior to creating a pmem region, to ensure that
95+
* the region is never touched while the device is offline.
96+
*/
97+
virtio_device_ready(vdev);
98+
9499
ndr_desc.res = &res;
95100
ndr_desc.numa_node = nid;
96101
ndr_desc.flush = async_pmem_flush;
@@ -105,6 +110,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
105110
nd_region->provider_data = dev_to_virtio(nd_region->dev.parent->parent);
106111
return 0;
107112
out_nd:
113+
vdev->config->reset(vdev);
108114
nvdimm_bus_unregister(vpmem->nvdimm_bus);
109115
out_vq:
110116
vdev->config->del_vqs(vdev);

0 commit comments

Comments
 (0)