mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
misc: nsm: mark device ready before registering the hwrng and misc device
nsm_device_probe() registers an hwrng provider and /dev/nsm. hwrng_register() can make this the current RNG, and the hwrng fill kthread finds it through the RCU-protected get_current_rng() rather than under the rng_mutex that hwrng_register() holds, so it can be in nsm_rng_read() offering buffers and kicking the queue before probe has returned. The driver never calls virtio_device_ready(), so DRIVER_OK is set on its behalf by virtio_dev_probe(), only once probe has returned. The virtio spec is explicit about that ordering in 3.1 Device Initialization: | The driver MUST NOT send any buffer available notifications to the | device before setting DRIVER_OK. A device that waits for DRIVER_OK before servicing the queue therefore leaves that read unanswered. Set DRIVER_OK once the virtqueue exists and before either interface is registered, so that the queue is usable by the time anything that can reach it is published; commitf5866db64f("virtio_console: enable VQs early") and commit1d774589f9("i2c: virtio: mark device ready before registering the adapter") do the same for the same reason. The err_hwrng and err_misc paths then unwind a device that is live, so reset it before deleting the virtqueue - the core only adds VIRTIO_CONFIG_S_FAILED to the status when probe fails, it does not reset. Fixes:b9873755a6("misc: Add Nitro Secure Module driver") Signed-off-by: Jasper Wise <jaspwise@amazon.co.uk> Link: https://patch.msgid.link/20260813083752.581981-1-jaspwise@amazon.co.uk Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0f3b12bab7
commit
e15596e84c
|
|
@ -439,6 +439,8 @@ static int nsm_device_probe(struct virtio_device *vdev)
|
|||
|
||||
mutex_init(&nsm->lock);
|
||||
|
||||
virtio_device_ready(vdev);
|
||||
|
||||
/* Register as hwrng provider */
|
||||
nsm->hwrng = (struct hwrng) {
|
||||
.read = nsm_rng_read,
|
||||
|
|
@ -471,6 +473,7 @@ static int nsm_device_probe(struct virtio_device *vdev)
|
|||
err_misc:
|
||||
hwrng_unregister(&nsm->hwrng);
|
||||
err_hwrng:
|
||||
virtio_reset_device(vdev);
|
||||
vdev->config->del_vqs(vdev);
|
||||
err_init_vq:
|
||||
return rc;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user