From 16ca3d0f59bfcbf0d702db24e6a84b228bab22e7 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Mon, 8 Jun 2020 21:49:42 +0000 Subject: [PATCH] virtio_mmio: Negotiate the upper half of the feature bits too The feature bits are exposed as a 32-bit register with 2 banks, so we should negotiate both halves. Notably, VIRTIO_F_VERSION_1 is in the upper half, and will be used in an upcoming commit. The PCI bus driver also has this bug, but the legacy BAR layout did not include selector registers and is rather different from the modern layout, so it remains solely as legacy. Reviewed by: br, brooks (mentor), jhb (mentor) Approved by: br, brooks (mentor), jhb (mentor) Differential Revision: https://reviews.freebsd.org/D25131 --- sys/dev/virtio/mmio/virtio_mmio.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/dev/virtio/mmio/virtio_mmio.c b/sys/dev/virtio/mmio/virtio_mmio.c index 133eb5dbcea..0414706fb99 100644 --- a/sys/dev/virtio/mmio/virtio_mmio.c +++ b/sys/dev/virtio/mmio/virtio_mmio.c @@ -390,7 +390,13 @@ vtmmio_negotiate_features(device_t dev, uint64_t child_features) sc = device_get_softc(dev); + vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 1); host_features = vtmmio_read_config_4(sc, VIRTIO_MMIO_HOST_FEATURES); + host_features <<= 32; + + vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 0); + host_features |= vtmmio_read_config_4(sc, VIRTIO_MMIO_HOST_FEATURES); + vtmmio_describe_features(sc, "host", host_features); /* @@ -402,6 +408,11 @@ vtmmio_negotiate_features(device_t dev, uint64_t child_features) sc->vtmmio_features = features; vtmmio_describe_features(sc, "negotiated", features); + + vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 1); + vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES, features >> 32); + + vtmmio_write_config_4(sc, VIRTIO_MMIO_HOST_FEATURES_SEL, 0); vtmmio_write_config_4(sc, VIRTIO_MMIO_GUEST_FEATURES, features); return (features);