+ git diff upstream/releng/15.1 HEAD sys/dev/virtio diff --git a/sys/dev/virtio/gpu/virtio_gpu.c b/sys/dev/virtio/gpu/virtio_gpu.c index b95bae9fe286..2cbfc472909c 100644 --- a/sys/dev/virtio/gpu/virtio_gpu.c +++ b/sys/dev/virtio/gpu/virtio_gpu.c @@ -61,6 +61,12 @@ /* The guest can allocate resource IDs, we only need one */ #define VTGPU_RESOURCE_ID 1 +#if _BYTE_ORDER == _BIG_ENDIAN +#define VTGPU_FORMAT VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM +#else +#define VTGPU_FORMAT VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM +#endif + struct vtgpu_softc { /* Must be first so we can cast from info -> softc */ struct fb_info vtgpu_fb_info; @@ -556,7 +562,7 @@ vtgpu_create_2d(struct vtgpu_softc *sc) atomic_fetchadd_64(&sc->vtgpu_next_fence, 1)); s.req.resource_id = htole32(VTGPU_RESOURCE_ID); - s.req.format = htole32(VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM); + s.req.format = htole32(VTGPU_FORMAT); s.req.width = htole32(sc->vtgpu_fb_info.fb_width); s.req.height = htole32(sc->vtgpu_fb_info.fb_height); diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c index 19775416f8d4..112edde34b03 100644 --- a/sys/dev/virtio/network/if_vtnet.c +++ b/sys/dev/virtio/network/if_vtnet.c @@ -641,7 +641,7 @@ vtnet_negotiate_features(struct vtnet_softc *sc) { device_t dev; uint64_t features, negotiated_features; - int no_csum; + int error, no_csum; dev = sc->vtnet_dev; features = virtio_bus_is_modern(dev) ? VTNET_MODERN_FEATURES : @@ -719,7 +719,19 @@ vtnet_negotiate_features(struct vtnet_softc *sc) sc->vtnet_features = negotiated_features; sc->vtnet_negotiated_features = negotiated_features; - return (virtio_finalize_features(dev)); + error = virtio_finalize_features(dev); + if (error != 0 && (features & VTNET_OFFLOAD_FEATURES) != 0) { + device_printf(dev, + "retrying feature negotiation without offloads\n"); + features &= ~VTNET_OFFLOAD_FEATURES; + negotiated_features &= ~VTNET_OFFLOAD_FEATURES; + sc->vtnet_flags &= ~VTNET_FLAG_LRO_NOMRG; + sc->vtnet_features = negotiated_features; + sc->vtnet_negotiated_features = negotiated_features; + error = virtio_reinit(dev, features); + } + + return (error); } static int @@ -2059,8 +2071,16 @@ vtnet_rxq_input(struct vtnet_rxq *rxq, struct mbuf *m, } } - m->m_pkthdr.flowid = rxq->vtnrx_id; - M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + if (sc->vtnet_act_vq_pairs == 1) { + /* + * When RSS is not needed (one active rx queue), let the upper + * layer know and react. + */ + M_HASHTYPE_CLEAR(m); + } else { + m->m_pkthdr.flowid = rxq->vtnrx_id; + M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + } if (hdr->flags & (VIRTIO_NET_HDR_F_NEEDS_CSUM | VIRTIO_NET_HDR_F_DATA_VALID)) { diff --git a/sys/dev/virtio/network/if_vtnetvar.h b/sys/dev/virtio/network/if_vtnetvar.h index eb5e6784b07f..5b377323f970 100644 --- a/sys/dev/virtio/network/if_vtnetvar.h +++ b/sys/dev/virtio/network/if_vtnetvar.h @@ -320,6 +320,7 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE); VIRTIO_NET_F_MTU | \ VIRTIO_NET_F_CTRL_VQ | \ VIRTIO_NET_F_CTRL_RX | \ + VIRTIO_NET_F_CTRL_RX_EXTRA | \ VIRTIO_NET_F_CTRL_MAC_ADDR | \ VIRTIO_NET_F_CTRL_VLAN | \ VIRTIO_NET_F_CSUM | \ @@ -353,6 +354,22 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE); #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \ VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN) +/* + * Union of the offload-related features offered by the driver. As per spec, + * a device is permitted to reject an otherwise valid subset of its offered + * features by failing FEATURES_OK (v1.3 ยง2.2.2). Offloads are where this + * happens in practice, so feature negotiation retries without this entire + * group when the device rejects the first feature set. + * + * Must cover every offload-related bit in VTNET_COMMON_FEATURES. + */ +#define VTNET_OFFLOAD_FEATURES \ + (VIRTIO_NET_F_CSUM | \ + VIRTIO_NET_F_GUEST_CSUM | \ + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS | \ + VTNET_TSO_FEATURES | \ + VTNET_LRO_FEATURES) + #define VTNET_MIN_MTU 68 #define VTNET_MAX_MTU 65536 #define VTNET_MAX_RX_SIZE 65550 diff --git a/sys/dev/virtio/p9fs/virtio_p9fs.c b/sys/dev/virtio/p9fs/virtio_p9fs.c index 2b276a60aa9a..7586c5f03cf7 100644 --- a/sys/dev/virtio/p9fs/virtio_p9fs.c +++ b/sys/dev/virtio/p9fs/virtio_p9fs.c @@ -76,7 +76,7 @@ struct vt9p_softc { /* Global channel list, Each channel will correspond to a mount point */ static STAILQ_HEAD( ,vt9p_softc) global_chan_list = STAILQ_HEAD_INITIALIZER(global_chan_list); -struct mtx global_chan_list_mtx; +static struct mtx global_chan_list_mtx; MTX_SYSINIT(global_chan_list_mtx, &global_chan_list_mtx, "9pglobal", MTX_DEF); static struct virtio_feature_desc virtio_9p_feature_desc[] = { @@ -86,13 +86,6 @@ static struct virtio_feature_desc virtio_9p_feature_desc[] = { VIRTIO_SIMPLE_PNPINFO(virtio_p9fs, VIRTIO_ID_9P, "VirtIO 9P Transport"); -/* We don't currently allow canceling of virtio requests */ -static int -vt9p_cancel(void *handle, struct p9_req_t *req) -{ - return (1); -} - SYSCTL_NODE(_vfs, OID_AUTO, 9p, CTLFLAG_RW, 0, "9P File System Protocol"); /* @@ -278,6 +271,10 @@ vt9p_detach(device_t dev) struct vt9p_softc *sc; sc = device_get_softc(dev); + + if (sc->busy) + return (EBUSY); + VT9P_LOCK(sc); vt9p_stop(sc); VT9P_UNLOCK(sc); @@ -443,7 +440,6 @@ static struct p9_trans_module vt9p_trans = { .create = vt9p_create, .close = vt9p_close, .request = vt9p_request, - .cancel = vt9p_cancel, }; static device_method_t vt9p_mthds[] = { diff --git a/sys/dev/virtio/pci/virtio_pci_modern.c b/sys/dev/virtio/pci/virtio_pci_modern.c index 108fd2b5f8e9..685b113d11c4 100644 --- a/sys/dev/virtio/pci/virtio_pci_modern.c +++ b/sys/dev/virtio/pci/virtio_pci_modern.c @@ -665,16 +665,13 @@ vtpci_modern_read_dev_config(device_t dev, bus_size_t offset, void *dst, *(uint8_t *) dst = vtpci_modern_read_device_1(sc, offset); break; case 2: - *(uint16_t *) dst = virtio_htog16(true, - vtpci_modern_read_device_2(sc, offset)); + *(uint16_t *) dst = vtpci_modern_read_device_2(sc, offset); break; case 4: - *(uint32_t *) dst = virtio_htog32(true, - vtpci_modern_read_device_4(sc, offset)); + *(uint32_t *) dst = vtpci_modern_read_device_4(sc, offset); break; case 8: - *(uint64_t *) dst = virtio_htog64(true, - vtpci_modern_read_device_8(sc, offset)); + *(uint64_t *) dst = vtpci_modern_read_device_8(sc, offset); break; default: panic("%s: device %s invalid device read length %d offset %d", @@ -700,17 +697,17 @@ vtpci_modern_write_dev_config(device_t dev, bus_size_t offset, const void *src, vtpci_modern_write_device_1(sc, offset, *(const uint8_t *) src); break; case 2: { - uint16_t val = virtio_gtoh16(true, *(const uint16_t *) src); + uint16_t val = *(const uint16_t *) src; vtpci_modern_write_device_2(sc, offset, val); break; } case 4: { - uint32_t val = virtio_gtoh32(true, *(const uint32_t *) src); + uint32_t val = *(const uint32_t *) src; vtpci_modern_write_device_4(sc, offset, val); break; } case 8: { - uint64_t val = virtio_gtoh64(true, *(const uint64_t *) src); + uint64_t val = *(const uint64_t *) src; vtpci_modern_write_device_8(sc, offset, val); break; } @@ -1148,6 +1145,13 @@ vtpci_modern_probe_and_attach_child(struct vtpci_modern_softc *sc) /* Reset state for later attempt. */ vtpci_modern_child_detached(dev, child); } else { + /* + * It may be the case that the device will only be polled and + * an interrupt never configured, so enable our virtqueues here + * if they hadn't been already. + */ + vtpci_modern_enable_virtqueues(sc); + vtpci_modern_set_status(sc, VIRTIO_CONFIG_STATUS_DRIVER_OK); VIRTIO_ATTACH_COMPLETED(child); } @@ -1299,6 +1303,9 @@ vtpci_modern_enable_virtqueues(struct vtpci_modern_softc *sc) for (idx = 0; idx < sc->vtpci_common.vtpci_nvqs; idx++) { vtpci_modern_select_virtqueue(sc, idx); + if (vtpci_modern_read_common_2(sc, + VIRTIO_PCI_COMMON_Q_ENABLE) != 0) + continue; vtpci_modern_write_common_2(sc, VIRTIO_PCI_COMMON_Q_ENABLE, 1); } } @@ -1312,15 +1319,13 @@ vtpci_modern_read_common_1(struct vtpci_modern_softc *sc, bus_size_t off) static uint16_t vtpci_modern_read_common_2(struct vtpci_modern_softc *sc, bus_size_t off) { - return virtio_htog16(true, - bus_read_2(&sc->vtpci_common_res_map.vtrm_map, off)); + return bus_read_2(&sc->vtpci_common_res_map.vtrm_map, off); } static uint32_t vtpci_modern_read_common_4(struct vtpci_modern_softc *sc, bus_size_t off) { - return virtio_htog32(true, - bus_read_4(&sc->vtpci_common_res_map.vtrm_map, off)); + return bus_read_4(&sc->vtpci_common_res_map.vtrm_map, off); } static void @@ -1334,16 +1339,14 @@ static void vtpci_modern_write_common_2(struct vtpci_modern_softc *sc, bus_size_t off, uint16_t val) { - bus_write_2(&sc->vtpci_common_res_map.vtrm_map, - off, virtio_gtoh16(true, val)); + bus_write_2(&sc->vtpci_common_res_map.vtrm_map, off, val); } static void vtpci_modern_write_common_4(struct vtpci_modern_softc *sc, bus_size_t off, uint32_t val) { - bus_write_4(&sc->vtpci_common_res_map.vtrm_map, - off, virtio_gtoh32(true, val)); + bus_write_4(&sc->vtpci_common_res_map.vtrm_map, off, val); } static void diff --git a/sys/dev/virtio/random/virtio_random.c b/sys/dev/virtio/random/virtio_random.c index 3f30c8b68f4c..128e9c3937f0 100644 --- a/sys/dev/virtio/random/virtio_random.c +++ b/sys/dev/virtio/random/virtio_random.c @@ -47,6 +47,8 @@ #include #include +#include "virtio_if.h" + struct vtrnd_softc { device_t vtrnd_dev; uint64_t vtrnd_features; @@ -69,6 +71,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 @@ -93,6 +96,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 }; @@ -181,8 +187,6 @@ vtrnd_attach(device_t dev) sc->inactive = false; random_source_register(&random_vtrnd); - vtrnd_enqueue(sc); - fail: if (error) vtrnd_detach(dev); @@ -327,3 +331,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); +} diff --git a/sys/dev/virtio/virtio.h b/sys/dev/virtio/virtio.h index 855dafd63033..6266dc29b94c 100644 --- a/sys/dev/virtio/virtio.h +++ b/sys/dev/virtio/virtio.h @@ -53,13 +53,15 @@ struct vq_alloc_info; /* * VirtIO instance variables indices. */ -#define VIRTIO_IVAR_DEVTYPE 1 -#define VIRTIO_IVAR_FEATURE_DESC 2 -#define VIRTIO_IVAR_VENDOR 3 -#define VIRTIO_IVAR_DEVICE 4 -#define VIRTIO_IVAR_SUBVENDOR 5 -#define VIRTIO_IVAR_SUBDEVICE 6 -#define VIRTIO_IVAR_MODERN 7 +enum { + VIRTIO_IVAR_DEVTYPE = BUS_IVARS_PRIVATE + 1, + VIRTIO_IVAR_FEATURE_DESC, + VIRTIO_IVAR_VENDOR, + VIRTIO_IVAR_DEVICE, + VIRTIO_IVAR_SUBVENDOR, + VIRTIO_IVAR_SUBDEVICE, + VIRTIO_IVAR_MODERN +}; struct virtio_feature_desc { uint64_t vfd_val;