git: b3563d1d49e8 - stable/14 - virtio_random: defer first enqueue until after DRIVER_OK
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 09 Nov 2026 03:14:25 UTC
The branch stable/14 has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=b3563d1d49e89ed8486b2e9a73c573ecf281821d
commit b3563d1d49e89ed8486b2e9a73c573ecf281821d
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-11-05 21:53:30 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-11-09 03:14:13 +0000
virtio_random: defer first enqueue until after DRIVER_OK
According to the virtio spec:
> The driver MUST NOT send any buffer available notifications to the
> device before setting DRIVER_OK.
DRIVER_OK isn't set until after attach completes, so defer the first
enqueue. We haven't found any problems as a result of this to the best
of my knowledge: q35 and other devices that we *have* been used with
will apparently check when we go DRIVER_OK.
Tested with q35 virtio-random, which still works.
Reported by: llm-postcr
Reviewed by: kfv, markj
Fixes: f1c5a2e3a62505 ("virtio_random: Pipeline fetching the data")
Sponsored by: Stormshield
Sponsored by: Klara, Inc.
(cherry picked from commit 12f90bbd3029fedea93e9bb0b1f02c3afafe237b)
---
sys/dev/virtio/random/virtio_random.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/sys/dev/virtio/random/virtio_random.c b/sys/dev/virtio/random/virtio_random.c
index 0cffcc3962e6..51b671852b7c 100644
--- a/sys/dev/virtio/random/virtio_random.c
+++ b/sys/dev/virtio/random/virtio_random.c
@@ -48,6 +48,8 @@
#include <dev/virtio/virtio.h>
#include <dev/virtio/virtqueue.h>
+#include "virtio_if.h"
+
struct vtrnd_softc {
device_t vtrnd_dev;
uint64_t vtrnd_features;
@@ -70,6 +72,7 @@ static int vtrnd_setup_features(struct vtrnd_softc *);
static int vtrnd_alloc_virtqueue(struct vtrnd_softc *);
static int vtrnd_harvest(struct vtrnd_softc *, void *, size_t *);
static void vtrnd_enqueue(struct vtrnd_softc *sc);
+static int vtrnd_attach_completed(device_t);
static unsigned vtrnd_read(void *, unsigned);
#define VTRND_FEATURES 0
@@ -94,6 +97,9 @@ static device_method_t vtrnd_methods[] = {
DEVMETHOD(device_detach, vtrnd_detach),
DEVMETHOD(device_shutdown, vtrnd_shutdown),
+ /* Virtio methods. */
+ DEVMETHOD(virtio_attach_completed, vtrnd_attach_completed),
+
DEVMETHOD_END
};
@@ -182,8 +188,6 @@ vtrnd_attach(device_t dev)
sc->inactive = false;
random_source_register(&random_vtrnd);
- vtrnd_enqueue(sc);
-
fail:
if (error != 0) {
/* Parent will free the virtqueue. */
@@ -341,3 +345,13 @@ vtrnd_read(void *buf, unsigned usz)
return (sz);
}
+
+static int
+vtrnd_attach_completed(device_t dev)
+{
+ struct vtrnd_softc *sc;
+
+ sc = device_get_softc(dev);
+ vtrnd_enqueue(sc);
+ return (0);
+}