virtio 1.0 patch series rebased
cover virtio 1.0 patch series rebased
Hi,
Here comes the virtio 1.0 patch series, rebased to latest master. Patches 1-23 are based on the old branch by cornelia & mst. Patches 24-30 are virtio-pci bits on top of that. Patches 31-33 add virtio-pci support for the virtio-input devices.
Light testing only so far, posting early nevertheless to parallelize testing efforts and speedup things a bit.
cheers,
Gerd
Cornelia Huck (10):
virtio: endianness checks for virtio 1.0 devices
virtio: allow virtio-1 queue layout
dataplane: allow virtio-1 devices
virtio: disallow late feature changes for virtio-1
virtio: allow to fail setting status
virtio-net: no writeable mac for virtio-1
virtio-net: support longer header
virtio-net: enable virtio 1.0
vhost: 64 bit features
virtio-balloon: switch to virtio_add_feature
Gerd Hoffmann (15):
virtio: 64bit features fixups.
virtio-pci: add flags to enable/disable legacy/modern
virtio-pci: make QEMU_VIRTIO_PCI_QUEUE_MEM_MULT smaller
virtio-pci: change & document virtio pci bar layout.
virtio-pci: make modern bar 64bit + prefetchable
virtio-pci: add struct VirtIOPCIRegion for virtio-1 regions
virtio-pci: add virtio_pci_modern_regions_init()
virtio-pci: add virtio_pci_modern_region_map()
virtio-pci: move virtio_pci_add_mem_cap call to
virtio_pci_modern_region_map
virtio-pci: move cap type to VirtIOPCIRegion
virtio-pci: drop identical virtio_pci_cap
virtio-pci: fill VirtIOPCIRegions early.
pci: add PCI_CLASS_INPUT_*
virtio-input: core code & base class [pci]
virtio-input: emulated devices [pci]
Jason Wang (1):
virtio-pci: correctly set host notifiers for modern bar
Michael S. Tsirkin (7):
vhost_net: add version_1 feature
linux-headers: add virtio_pci
virtio-pci: initial virtio 1.0 support
virtio: generation counter support
virtio: add modern config accessors
virtio-pci: switch to modern accessors for 1.0
virtio_balloon: header update
hw/net/vhost_net.c | 14 +- hw/net/virtio-net.c | 25 +- hw/s390x/virtio-ccw.c | 20 +- hw/virtio/dataplane/vring.c | 47 +-- hw/virtio/vhost.c | 14 +- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-mmio.c | 3 + hw/virtio/virtio-pci.c | 612 +++++++++++++++++++++++++++++++++++-- hw/virtio/virtio-pci.h | 59 ++++ hw/virtio/virtio.c | 198 ++++++++++-- include/hw/pci/pci_ids.h | 7 + include/hw/virtio/vhost.h | 6 +- include/hw/virtio/virtio-access.h | 4 + include/hw/virtio/virtio-balloon.h | 6 + include/hw/virtio/virtio.h | 34 ++- include/net/vhost_net.h | 4 +- linux-headers/linux/virtio_pci.h | 192 ++++++++++++ 17 files changed, 1140 insertions(+), 107 deletions(-) create mode 100644 linux-headers/linux/virtio_pci.h
Signature · 1 line
1.8.3.1
PATCH 1/33 virtio: 64bit features fixups.
Commit "019a3ed virtio: make features 64bit wide" missed a few changes, as I've noticed while trying to rebase the virtio-1 branch to latest master. This patch adds them.
--- hw/net/virtio-net.c | 2 +- hw/virtio/virtio.c | 2 +- include/hw/virtio/virtio.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
hw/net/virtio-net.c +1 -1
@@ -511,7 +511,7 @@ static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)return virtio_net_guest_offloads_by_features (vdev->guest_features); } -static void virtio_net_set_features (VirtIODevice *vdev,uint32_t features) +static void virtio_net_set_features (VirtIODevice *vdev,uint64_t features) {VirtIONet *n =VIRTIO_NET (vdev);int i;
hw/virtio/virtio.c +1 -1
@@ -1003,7 +1003,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev,NULL ); } -int virtio_set_features (VirtIODevice *vdev,uint32_t val) +int virtio_set_features (VirtIODevice *vdev,uint64_t val) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);bool bad = (val & ~(vdev->host_features)) !=0 ;
include/hw/virtio/virtio.h +5 -5
@@ -98,7 +98,7 @@ typedef struct VirtioDeviceClass {DeviceUnrealize unrealize;uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features);uint64_t (*bad_features)(VirtIODevice *vdev); -void (*set_features)(VirtIODevice *vdev,uint32_t val); +void (*set_features)(VirtIODevice *vdev,uint64_t val);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);void (*reset)(VirtIODevice *vdev);
@@ -184,7 +184,7 @@ void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);void virtio_set_status (VirtIODevice *vdev,uint8_t val);void virtio_reset (void *opaque);void virtio_update_irq (VirtIODevice *vdev); -int virtio_set_features (VirtIODevice *vdev,uint32_t val); +int virtio_set_features (VirtIODevice *vdev,uint64_t val);/* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf ;
@@ -230,19 +230,19 @@ VirtQueue *virtio_vector_next_queue(VirtQueue *vq);static inline void virtio_add_feature (uint64_t *features,unsigned int fbit) {assert (fbit <64 ); - *features |= (1 << fbit); + *features |= (1ULL << fbit); }static inline void virtio_clear_feature (uint64_t *features,unsigned int fbit) {assert (fbit <64 ); - *features &= ~(1 << fbit); + *features &= ~(1ULL << fbit); }static inline bool __virtio_has_feature (uint64_t features,unsigned int fbit) {assert (fbit <64 ); -return !!(features & (1 << fbit)); +return !!(features & (1ULL << fbit)); }static inline bool virtio_has_feature (VirtIODevice *vdev,unsigned int fbit)
Signature · 1 line
1.8.3.1
PATCH 2/33 virtio: endianness checks for virtio 1.0 devices
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
Add code that checks for the VERSION_1 feature bit in order to make decisions about the device's endianness. This allows us to support transitional devices.
--- hw/virtio/virtio.c | 6 +++++- include/hw/virtio/virtio-access.h | 4 ++++ include/hw/virtio/virtio.h | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +5 -1
@@ -903,7 +903,11 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian !=virtio_default_endian (); +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +return vdev->device_endian !=virtio_default_endian (); + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_LITTLE ; }static bool virtio_64bit_features_needed (void *opaque)
include/hw/virtio/virtio-access.h +4 -0
@@ -19,6 +19,10 @@static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; + }#if defined(TARGET_IS_BIENDIAN )return virtio_is_big_endian (vdev);#elif defined(TARGET_WORDS_BIGENDIAN )
include/hw/virtio/virtio.h +6 -2
@@ -252,7 +252,11 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit)static inline bool virtio_is_big_endian (VirtIODevice *vdev) { -assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; +if (!virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); +return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; + } +/* Devices conforming to VIRTIO 1.0 or later are always LE. */ +return false; }#endif
Signature · 1 line
1.8.3.1
PATCH 3/33 virtio: allow virtio-1 queue layout
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
For virtio-1 devices, we allow a more complex queue layout that doesn't require descriptor table and rings on a physically-contigous memory area:
add virtio_queue_set_rings() to allow transports to set this up.
--- hw/virtio/virtio-mmio.c | 3 +++ hw/virtio/virtio.c | 53 +++++++++++++++++++++++++++++----------------- include/hw/virtio/virtio.h | 3 +++ 3 files changed, 40 insertions(+), 19 deletions(-)
hw/virtio/virtio-mmio.c +3 -0
@@ -333,8 +333,11 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,case VIRTIO_MMIO_QUEUENUM :DPRINTF ("mmio_queue write %d max %d\n" , (int )value,VIRTQUEUE_MAX_SIZE );virtio_queue_set_num (vdev, vdev->queue_sel, value); +/* Note: only call this function for legacy devices */ +virtio_queue_update_rings (vdev, vdev->queue_sel);break ;case VIRTIO_MMIO_QUEUEALIGN : +/* Note: this is only valid for legacy devices */ virtio_queue_set_align (vdev, vdev->queue_sel, value);break ;case VIRTIO_MMIO_QUEUEPFN :
hw/virtio/virtio.c +34 -19
123 lines not on this page · raw message
include/hw/virtio/virtio.h +3 -0
@@ -177,6 +177,9 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);void virtio_queue_set_num (VirtIODevice *vdev,int n,int num);int virtio_queue_get_num (VirtIODevice *vdev,int n);int virtio_get_num_queues (VirtIODevice *vdev); +void virtio_queue_set_rings (VirtIODevice *vdev,int n,hwaddr desc, +hwaddr avail,hwaddr used); +void virtio_queue_update_rings (VirtIODevice *vdev,int n);void virtio_queue_set_align (VirtIODevice *vdev,int n,int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);
Signature · 1 line
1.8.3.1
PATCH 4/33 dataplane: allow virtio-1 devices
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
Handle endianness conversion for virtio-1 virtqueues correctly.
Note that dataplane now needs to be built per-target.
--- hw/virtio/dataplane/vring.c | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
hw/virtio/dataplane/vring.c +26 -21
@@ -157,15 +157,18 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring) } -static int get_desc (Vring *vring,VirtQueueElement *elem, +static int get_desc (VirtIODevice *vdev,Vring *vring,VirtQueueElement *elem,struct vring_desc *desc) {unsigned *num;struct iovec *iov;hwaddr *addr;MemoryRegion *mr; +int is_write =virtio_tswap16 (vdev, desc->flags) &VRING_DESC_F_WRITE ; +uint32_t len =virtio_tswap32 (vdev, desc->len); +uint64_t desc_addr =virtio_tswap64 (vdev, desc->addr); -if (desc->flags &VRING_DESC_F_WRITE ) { +if (is_write) { num = &elem->in_num; iov = &elem->in_sg[*num]; addr = &elem->in_addr[*num];
@@ -189,18 +192,17 @@ static int get_desc(Vring *vring, VirtQueueElement *elem, }/* TODO handle non-contiguous memory across region boundaries */ - iov->iov_base =vring_map (&mr, desc->addr, desc->len, - desc->flags &VRING_DESC_F_WRITE ); + iov->iov_base =vring_map (&mr, desc_addr, len, is_write);if (!iov->iov_base) {error_report ("Failed to map descriptor addr %#" PRIx64" len %u" , - (uint64_t )desc->addr, desc->len); + (uint64_t )desc_addr, len);return -EFAULT ; }/* The MemoryRegion is looked up again and unref'ed later, leave the * ref in place. */ - iov->iov_len = desc->len; - *addr = desc->addr; + iov->iov_len = len; + *addr = desc_addr; *num +=1 ;return 0 ; }
@@ -222,21 +224,23 @@ static int get_indirect(VirtIODevice *vdev, Vring *vring,struct vring_desc desc;unsigned int i =0 , count, found =0 ;int ret; +uint32_t len =virtio_tswap32 (vdev, indirect->len); +uint64_t addr =virtio_tswap64 (vdev, indirect->addr);/* Sanity check */ -if (unlikely (indirect->len %sizeof (desc))) { +if (unlikely (len %sizeof (desc))) {error_report ("Invalid length in indirect descriptor: " "len %#x not multiple of %#zx" , - indirect->len,sizeof (desc)); + len,sizeof (desc)); vring->broken = true;return -EFAULT ; } - count = indirect->len /sizeof (desc); + count = len /sizeof (desc);/* Buffers are chained via a 16 bit next field, so * we can have at most 2^16 of these. */ if (unlikely (count >USHRT_MAX +1 )) { -error_report ("Indirect buffer length too big: %d" , indirect->len); +error_report ("Indirect buffer length too big: %d" , len); vring->broken = true;return -EFAULT ; }
@@ -247,12 +251,12 @@ static int get_indirect(VirtIODevice *vdev, Vring *vring,/* Translate indirect descriptor */ desc_ptr =vring_map (&mr, - indirect->addr + found *sizeof (desc), + addr + found *sizeof (desc),sizeof (desc), false);if (!desc_ptr) {error_report ("Failed to map indirect descriptor " "addr %#" PRIx64" len %zu" , - (uint64_t )indirect->addr + found *sizeof (desc), + (uint64_t )addr + found *sizeof (desc),sizeof (desc)); vring->broken = true;return -EFAULT ;
@@ -270,19 +274,20 @@ static int get_indirect(VirtIODevice *vdev, Vring *vring,return -EFAULT ; } -if (unlikely (desc.flags &VRING_DESC_F_INDIRECT )) { +if (unlikely (virtio_tswap16 (vdev, desc.flags) + &VRING_DESC_F_INDIRECT )) {error_report ("Nested indirect descriptor" ); vring->broken = true;return -EFAULT ; } - ret =get_desc (vring, elem, &desc); + ret =get_desc (vdev, vring, elem, &desc);if (ret <0 ) { vring->broken |= (ret == -EFAULT );return ret; } - i = desc.next; - }while (desc.flags &VRING_DESC_F_NEXT ); + i =virtio_tswap16 (vdev, desc.next); + }while (virtio_tswap16 (vdev, desc.flags) &VRING_DESC_F_NEXT );return 0 ; }
@@ -383,7 +388,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,/* Ensure descriptor is loaded before accessing fields */ barrier (); -if (desc.flags &VRING_DESC_F_INDIRECT ) { +if (virtio_tswap16 (vdev, desc.flags) &VRING_DESC_F_INDIRECT ) { ret =get_indirect (vdev, vring, elem, &desc);if (ret <0 ) { goto out;
@@ -391,13 +396,13 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,continue ; } - ret =get_desc (vring, elem, &desc); + ret =get_desc (vdev, vring, elem, &desc);if (ret <0 ) { goto out; } - i = desc.next; - }while (desc.flags &VRING_DESC_F_NEXT ); + i =virtio_tswap16 (vdev, desc.next); + }while (virtio_tswap16 (vdev, desc.flags) &VRING_DESC_F_NEXT );/* On success, increment avail index. */ vring->last_avail_idx++;
Signature · 1 line
1.8.3.1
PATCH 5/33 virtio: disallow late feature changes for virtio-1
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
For virtio-1 devices, the driver must not attempt to set feature bits after it set FEATURES_OK in the device status. Simply reject it in that case.
--- hw/virtio/virtio.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +15 -3
@@ -1021,7 +1021,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)vmstate_save_state (f, &vmstate_virtio, vdev,NULL ); } -int virtio_set_features (VirtIODevice *vdev,uint64_t val) +static int virtio_set_features_nocheck (VirtIODevice *vdev,uint64_t val) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);bool bad = (val & ~(vdev->host_features)) !=0 ;
@@ -1034,6 +1034,18 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return bad ?-1 :0 ; } +int virtio_set_features (VirtIODevice *vdev,uint64_t val) +{ +/* +* The driver must not attempt to set features after feature negotiation +* has finished. +*/ +if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) { +return -EINVAL ; + } +return virtio_set_features_nocheck (vdev, val); +} +int virtio_load (VirtIODevice *vdev,QEMUFile *f,int version_id) {int i, ret;
@@ -1137,14 +1149,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)* host_features. */ uint64_t features64 = vdev->guest_features; -if (virtio_set_features (vdev, features64) <0 ) { +if (virtio_set_features_nocheck (vdev, features64) <0 ) {error_report ("Features 0x%" PRIx64" unsupported. " "Allowed features: 0x%" PRIx64, features64, vdev->host_features);return -1 ; } }else { -if (virtio_set_features (vdev, features) <0 ) { +if (virtio_set_features_nocheck (vdev, features) <0 ) {error_report ("Features 0x%x unsupported. " "Allowed features: 0x%" PRIx64, features, vdev->host_features);
Signature · 1 line
1.8.3.1
PATCH 6/33 virtio: allow to fail setting status
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
virtio-1 allow setting of the FEATURES_OK status bit to fail if the negotiated feature bits are inconsistent: let's fail virtio_set_status() in that case and update virtio-ccw to post an error to the guest.
--- hw/s390x/virtio-ccw.c | 20 ++++++++++++-------- hw/virtio/virtio.c | 24 +++++++++++++++++++++++- include/hw/virtio/virtio.h | 3 ++- 3 files changed, 37 insertions(+), 10 deletions(-)
hw/s390x/virtio-ccw.c +12 -8
@@ -497,15 +497,19 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (!(status &VIRTIO_CONFIG_S_DRIVER_OK )) {virtio_ccw_stop_ioeventfd (dev); } -virtio_set_status (vdev, status); -if (vdev->status ==0 ) { -virtio_reset (vdev); +if (virtio_set_status (vdev, status) ==0 ) { +if (vdev->status ==0 ) { +virtio_reset (vdev); + } +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +virtio_ccw_start_ioeventfd (dev); + } + sch->curr_status.scsw.count = ccw.count -sizeof (status); + ret =0 ; + }else { +/* Trigger a command reject. */ + ret = -ENOSYS ; } -if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { -virtio_ccw_start_ioeventfd (dev); - } - sch->curr_status.scsw.count = ccw.count -sizeof (status); - ret =0 ; }break ;case CCW_CMD_SET_IND :
hw/virtio/virtio.c +23 -1
@@ -544,15 +544,37 @@ void virtio_update_irq(VirtIODevice *vdev)virtio_notify_vector (vdev,VIRTIO_NO_VECTOR ); } -void virtio_set_status (VirtIODevice *vdev,uint8_t val) +static int virtio_validate_features (VirtIODevice *vdev) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); + +if (k->validate_features) { +return k->validate_features (vdev); + }else { +return 0 ; + } +} + +int virtio_set_status (VirtIODevice *vdev,uint8_t val) {VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev);trace_virtio_set_status (vdev, val); +if (virtio_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (!(vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) && + val &VIRTIO_CONFIG_S_FEATURES_OK ) { +int ret =virtio_validate_features (vdev); + +if (ret) { +return ret; + } + } + }if (k->set_status) { k->set_status (vdev, val); } vdev->status = val; +return 0 ; }bool target_words_bigendian (void );
include/hw/virtio/virtio.h +2 -1
@@ -99,6 +99,7 @@ typedef struct VirtioDeviceClass {uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features);uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint64_t val); +int (*validate_features)(VirtIODevice *vdev);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);void (*reset)(VirtIODevice *vdev);
@@ -184,7 +185,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);void virtio_queue_notify (VirtIODevice *vdev,int n);uint16_t virtio_queue_vector (VirtIODevice *vdev,int n);void virtio_queue_set_vector (VirtIODevice *vdev,int n,uint16_t vector); -void virtio_set_status (VirtIODevice *vdev,uint8_t val); +int virtio_set_status (VirtIODevice *vdev,uint8_t val);void virtio_reset (void *opaque);void virtio_update_irq (VirtIODevice *vdev);int virtio_set_features (VirtIODevice *vdev,uint64_t val);
Signature · 1 line
1.8.3.1
PATCH 7/33 virtio-net: no writeable mac for virtio-1
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
Devices operating as virtio 1.0 may not allow writes to the mac address in config space.
--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
@@ -87,6 +87,7 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)memcpy (&netcfg, config, n->config_size);if (!virtio_has_feature (vdev,VIRTIO_NET_F_CTRL_MAC_ADDR ) && + !virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ) &&memcmp (netcfg.mac, n->mac,ETH_ALEN )) {memcpy (n->mac, netcfg.mac,ETH_ALEN );qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac);
Signature · 1 line
1.8.3.1
PATCH 8/33 virtio-net: support longer header
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
virtio-1 devices always use num_buffers in the header, even if mergeable rx buffers have not been negotiated.
--- hw/net/virtio-net.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
hw/net/virtio-net.c +15 -6
@@ -367,15 +367,21 @@ static int peer_has_ufo(VirtIONet *n)return n->has_ufo; } -static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs) +static void virtio_net_set_mrg_rx_bufs (VirtIONet *n,int mergeable_rx_bufs, +int version_1) {int i;NetClientState *nc; n->mergeable_rx_bufs = mergeable_rx_bufs; - n->guest_hdr_len = n->mergeable_rx_bufs ? -sizeof (struct virtio_net_hdr_mrg_rxbuf ) :sizeof (struct virtio_net_hdr ); +if (version_1) { + n->guest_hdr_len =sizeof (struct virtio_net_hdr_mrg_rxbuf ); + }else { + n->guest_hdr_len = n->mergeable_rx_bufs ? +sizeof (struct virtio_net_hdr_mrg_rxbuf ) : +sizeof (struct virtio_net_hdr ); + }for (i =0 ; i < n->max_queues; i++) { nc =qemu_get_subqueue (n->nic, i);
@@ -522,7 +528,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)virtio_net_set_mrg_rx_bufs (n,__virtio_has_feature (features, -VIRTIO_NET_F_MRG_RXBUF )); +VIRTIO_NET_F_MRG_RXBUF ), +__virtio_has_feature (features, +VIRTIO_F_VERSION_1 ));if (n->has_vnet_hdr) { n->curr_guest_offloads =
@@ -1375,7 +1383,8 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,qemu_get_buffer (f, n->mac,ETH_ALEN ); n->vqs[0 ].tx_waiting =qemu_get_be32 (f); -virtio_net_set_mrg_rx_bufs (n,qemu_get_be32 (f)); +virtio_net_set_mrg_rx_bufs (n,qemu_get_be32 (f), +virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ));if (version_id >=3 ) n->status =qemu_get_be16 (f);
@@ -1627,7 +1636,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->vqs[0 ].tx_waiting =0 ; n->tx_burst = n->net_conf.txburst; -virtio_net_set_mrg_rx_bufs (n,0 ); +virtio_net_set_mrg_rx_bufs (n,0 ,0 ); n->promisc =1 ;/* for compatibility */ n->mac_table.macs =g_malloc0 (MAC_TABLE_ENTRIES *ETH_ALEN );
Signature · 1 line
1.8.3.1
PATCH 9/33 virtio-net: enable virtio 1.0
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
virtio-net (non-vhost) now should have everything in place to support virtio 1.0: let's enable the feature bit for it.
Note that VIRTIO_F_VERSION_1 is technically a transport feature; once every device is ready for virtio 1.0, we can move setting this feature bit out of the individual devices.
--- hw/net/virtio-net.c | 1 + 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
@@ -470,6 +470,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features) }if (!get_vhost_net (nc->peer)) { +virtio_add_feature (&features,VIRTIO_F_VERSION_1 );return features; }return vhost_net_get_features (get_vhost_net (nc->peer), features);
Signature · 1 line
1.8.3.1
PATCH 10/33 vhost_net: add version_1 feature
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
Add VERSION_1 to list of features that we should
test at the backend.
--- hw/net/vhost_net.c | 2 ++ 1 file changed, 2 insertions(+)
hw/net/vhost_net.c +2 -0
@@ -52,6 +52,7 @@ static const int kernel_feature_bits[] = {VIRTIO_RING_F_INDIRECT_DESC ,VIRTIO_RING_F_EVENT_IDX ,VIRTIO_NET_F_MRG_RXBUF , +VIRTIO_F_VERSION_1 , VHOST_INVALID_FEATURE_BIT };
@@ -62,6 +63,7 @@ static const int user_feature_bits[] = {VIRTIO_RING_F_EVENT_IDX ,VIRTIO_F_ANY_LAYOUT , +VIRTIO_F_VERSION_1 ,VIRTIO_NET_F_CSUM ,VIRTIO_NET_F_GUEST_CSUM , VIRTIO_NET_F_GSO,
Signature · 1 line
1.8.3.1
PATCH 11/33 vhost: 64 bit features
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
Make sure that all vhost interfaces use 64 bit features, as the virtio core does, and make sure to use ULL everywhere possible to be on the safe side.
--- hw/net/vhost_net.c | 12 ++++++------ hw/virtio/vhost.c | 14 +++++++------- include/hw/virtio/vhost.h | 6 +++--- include/net/vhost_net.h | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-)
hw/net/vhost_net.c +6 -6
@@ -109,13 +109,13 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)return feature_bits; } -unsigned vhost_net_get_features (struct vhost_net *net,unsigned features) +uint64_t vhost_net_get_features (struct vhost_net *net,uint64_t features) {return vhost_get_features (&net->dev,vhost_net_get_feature_bits (net), features); } -void vhost_net_ack_features (struct vhost_net *net,unsigned features) +void vhost_net_ack_features (struct vhost_net *net,uint64_t features) { net->dev.acked_features = net->dev.backend_features;vhost_ack_features (&net->dev,vhost_net_get_feature_bits (net), features);
@@ -149,7 +149,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) goto fail; } net->dev.backend_features =qemu_has_vnet_hdr (options->net_backend) - ?0 : (1 <<VHOST_NET_F_VIRTIO_NET_HDR ); + ?0 : (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ); net->backend = r; }else { net->dev.backend_features =0 ;
@@ -169,7 +169,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)if (backend_kernel) {if (!qemu_has_vnet_hdr_len (options->net_backend,sizeof (struct virtio_net_hdr_mrg_rxbuf ))) { - net->dev.features &= ~(1 <<VIRTIO_NET_F_MRG_RXBUF ); + net->dev.features &= ~(1ULL <<VIRTIO_NET_F_MRG_RXBUF ); }if (~net->dev.features & net->dev.backend_features) { fprintf(stderr, "vhost lacks feature mask %" PRIu64
@@ -433,11 +433,11 @@ void vhost_net_cleanup(struct vhost_net *net) { } -unsigned vhost_net_get_features (struct vhost_net *net,unsigned features) +uint64_t vhost_net_get_features (struct vhost_net *net,uint64_t features) {return features; } -void vhost_net_ack_features (struct vhost_net *net,unsigned features) +void vhost_net_ack_features (struct vhost_net *net,uint64_t features) { }
hw/virtio/vhost.c +7 -7
@@ -551,7 +551,7 @@ static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log)uint64_t features = dev->acked_features;int r;if (enable_log) { - features |=0x1 <<VHOST_F_LOG_ALL ; + features |=0x1ULL <<VHOST_F_LOG_ALL ; } r = dev->vhost_ops->vhost_call (dev,VHOST_SET_FEATURES , &features);return r <0 ? -errno :0 ;
@@ -860,7 +860,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, .priority = 10 }; hdev->migration_blocker =NULL ; -if (!(hdev->features & (0x1 <<VHOST_F_LOG_ALL ))) { +if (!(hdev->features & (0x1ULL <<VHOST_F_LOG_ALL ))) {error_setg (&hdev->migration_blocker,"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature." );migrate_add_blocker (hdev->migration_blocker);
@@ -1003,12 +1003,12 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,assert (r >=0 ); } -unsigned vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features) +uint64_t vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, +uint64_t features) {const int *bit = feature_bits;while (*bit !=VHOST_INVALID_FEATURE_BIT ) { -unsigned bit_mask = (1 << *bit); +uint64_t bit_mask = (1ULL << *bit);if (!(hdev->features & bit_mask)) { features &= ~bit_mask; }
@@ -1018,11 +1018,11 @@ unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, }void vhost_ack_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features) +uint64_t features) {const int *bit = feature_bits;while (*bit !=VHOST_INVALID_FEATURE_BIT ) { -unsigned bit_mask = (1 << *bit); +uint64_t bit_mask = (1ULL << *bit);if (features & bit_mask) { hdev->acked_features |= bit_mask; }
include/hw/virtio/vhost.h +3 -3
@@ -72,8 +72,8 @@ bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n);*/ void vhost_virtqueue_mask (struct vhost_dev *hdev,VirtIODevice *vdev,int n,bool mask); -unsigned vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features); +uint64_t vhost_get_features (struct vhost_dev *hdev,const int *feature_bits, +uint64_t features);void vhost_ack_features (struct vhost_dev *hdev,const int *feature_bits, -unsigned features); +uint64_t features);#endif
include/net/vhost_net.h +2 -2
@@ -22,8 +22,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queues);void vhost_net_cleanup (VHostNetState *net); -unsigned vhost_net_get_features (VHostNetState *net,unsigned features); -void vhost_net_ack_features (VHostNetState *net,unsigned features); +uint64_t vhost_net_get_features (VHostNetState *net,uint64_t features); +void vhost_net_ack_features (VHostNetState *net,uint64_t features);bool vhost_net_virtqueue_pending (VHostNetState *net,int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
Signature · 1 line
1.8.3.1
PATCH 12/33 linux-headers: add virtio_pci
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
Easier than duplicating code.
--- hw/virtio/virtio-pci.c | 2 + linux-headers/linux/virtio_pci.h | 192 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 linux-headers/linux/virtio_pci.h
hw/virtio/virtio-pci.c +2 -0
@@ -38,6 +38,8 @@#define VIRTIO_PCI_REGION_SIZE (dev) VIRTIO_PCI_CONFIG_OFF(msix_present(dev)) +#undef VIRTIO_PCI_CONFIG +/* The remaining space is defined by each driver as the per-driver * configuration space */ #define VIRTIO_PCI_CONFIG_SIZE (dev) VIRTIO_PCI_CONFIG_OFF(msix_enabled(dev))
linux-headers/linux/virtio_pci.h new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 13/33 virtio-pci: initial virtio 1.0 support
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
This is somewhat functional. With this, and linux driver from my tree, I was able to use virtio net as virtio 1.0 device for light browsing.
At the moment, dataplane and vhost code is
still missing.
Based on Cornelia's virtio 1.0 patchset:
Date: Thu, 11 Dec 2014 14:25:02 +0100
From: Cornelia Huck <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected], Cornelia Huck <[email protected]>
Subject: [PATCH RFC v6 00/20] qemu: towards virtio-1 host support
Message-Id: <[email protected]>
which is itself still missing some core bits.
--- hw/virtio/virtio-pci.c | 379 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 16 +++ 2 files changed, 395 insertions(+)
hw/virtio/virtio-pci.c +379 -0
@@ -913,6 +913,278 @@ static int virtio_pci_query_nvectors(DeviceState *d)return proxy->nvectors; } +static void virtio_pci_add_mem_cap (VirtIOPCIProxy *proxy, +struct virtio_pci_cap *cap) +{ +PCIDevice *dev = &proxy->pci_dev; +int offset; + + cap->bar =2 ; + + offset =pci_add_capability (dev,PCI_CAP_ID_VNDR ,0 , cap->cap_len); +assert (offset >0 ); + +assert (cap->cap_len >=sizeof *cap); +memcpy (dev->config + offset +PCI_CAP_FLAGS , &cap->cap_len, + cap->cap_len -PCI_CAP_FLAGS ); +} + +#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x10000 + +static uint64_t virtio_pci_common_read (void *opaque,hwaddr addr, +unsigned size) +{ +VirtIOPCIProxy *proxy = opaque; +VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); +uint32_t val =0 ; +int i; + +switch (addr) { +case VIRTIO_PCI_COMMON_DFSELECT : + val = proxy->dfselect; +break ; +case VIRTIO_PCI_COMMON_DF : +if (proxy->dfselect <=1 ) { + val = vdev->host_features >> (32 * proxy->dfselect); + } +break ; +case VIRTIO_PCI_COMMON_GFSELECT : + val = proxy->gfselect; +break ; +case VIRTIO_PCI_COMMON_GF : +if (proxy->gfselect <=ARRAY_SIZE (proxy->guest_features)) { + val = proxy->guest_features[proxy->gfselect]; + } +break ; +case VIRTIO_PCI_COMMON_MSIX : + val = vdev->config_vector; +break ; +case VIRTIO_PCI_COMMON_NUMQ : +for (i =0 ; i <VIRTIO_QUEUE_MAX ; ++i) { +if (virtio_queue_get_num (vdev, i)) { + val = i +1 ; + } + } +break ; +case VIRTIO_PCI_COMMON_STATUS : + val = vdev->status; +break ; +case VIRTIO_PCI_COMMON_CFGGENERATION : + val =0 ;/* TODO */ +break ; +case VIRTIO_PCI_COMMON_Q_SELECT : + val = vdev->queue_sel; +break ; +case VIRTIO_PCI_COMMON_Q_SIZE : + val =virtio_queue_get_num (vdev, vdev->queue_sel); +break ; +case VIRTIO_PCI_COMMON_Q_MSIX : + val =virtio_queue_vector (vdev, vdev->queue_sel); +break ; +case VIRTIO_PCI_COMMON_Q_ENABLE : + val = proxy->vqs[vdev->queue_sel].enabled; +break ; +case VIRTIO_PCI_COMMON_Q_NOFF : +/* Simply map queues in order */ + val = vdev->queue_sel; +break ; +case VIRTIO_PCI_COMMON_Q_DESCLO : + val = proxy->vqs[vdev->queue_sel].desc[0 ]; +break ; +case VIRTIO_PCI_COMMON_Q_DESCHI : + val = proxy->vqs[vdev->queue_sel].desc[1 ]; +break ; +case VIRTIO_PCI_COMMON_Q_AVAILLO : + val = proxy->vqs[vdev->queue_sel].avail[0 ]; +break ; +case VIRTIO_PCI_COMMON_Q_AVAILHI : + val = proxy->vqs[vdev->queue_sel].avail[1 ]; +break ; +case VIRTIO_PCI_COMMON_Q_USEDLO : + val = proxy->vqs[vdev->queue_sel].used[0 ]; +break ; +case VIRTIO_PCI_COMMON_Q_USEDHI : + val = proxy->vqs[vdev->queue_sel].used[1 ]; +break ; +default : + val =0 ; + } + +return val; +} + +static void virtio_pci_common_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +VirtIOPCIProxy *proxy = opaque; +VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); + +switch (addr) { +case VIRTIO_PCI_COMMON_DFSELECT : + proxy->dfselect = val; +break ; +case VIRTIO_PCI_COMMON_GFSELECT : + proxy->gfselect = val; +break ; +case VIRTIO_PCI_COMMON_GF : +if (proxy->gfselect <=ARRAY_SIZE (proxy->guest_features)) { + proxy->guest_features[proxy->gfselect] = val; +virtio_set_features (vdev, + (((uint64_t )proxy->guest_features[1 ]) <<32 ) | + proxy->guest_features[0 ]); + } +break ; +case VIRTIO_PCI_COMMON_MSIX : +msix_vector_unuse (&proxy->pci_dev, vdev->config_vector); +/* Make it possible for guest to discover an error took place. */ +if (msix_vector_use (&proxy->pci_dev, val) <0 ) { + val =VIRTIO_NO_VECTOR ; + } + vdev->config_vector = val; +break ; +case VIRTIO_PCI_COMMON_STATUS : +if (!(val &VIRTIO_CONFIG_S_DRIVER_OK )) { +virtio_pci_stop_ioeventfd (proxy); + } + +virtio_set_status (vdev, val &0xFF ); + +if (val &VIRTIO_CONFIG_S_DRIVER_OK ) { +virtio_pci_start_ioeventfd (proxy); + } + +if (vdev->status ==0 ) { +virtio_reset (vdev); +msix_unuse_all_vectors (&proxy->pci_dev); + } + +break ; +case VIRTIO_PCI_COMMON_Q_SELECT : +if (val <VIRTIO_QUEUE_MAX ) { + vdev->queue_sel = val; + } +break ; +case VIRTIO_PCI_COMMON_Q_SIZE : + proxy->vqs[vdev->queue_sel].num = val; +break ; +case VIRTIO_PCI_COMMON_Q_MSIX : +msix_vector_unuse (&proxy->pci_dev, +virtio_queue_vector (vdev, vdev->queue_sel)); +/* Make it possible for guest to discover an error took place. */ +if (msix_vector_use (&proxy->pci_dev, val) <0 ) { + val =VIRTIO_NO_VECTOR ; + } +virtio_queue_set_vector (vdev, vdev->queue_sel, val); +break ; +case VIRTIO_PCI_COMMON_Q_ENABLE : +/* TODO: need a way to put num back on reset. */ +virtio_queue_set_num (vdev, vdev->queue_sel, + proxy->vqs[vdev->queue_sel].num); +virtio_queue_set_rings (vdev, vdev->queue_sel, + ((uint64_t )proxy->vqs[vdev->queue_sel].desc[1 ]) <<32 | + proxy->vqs[vdev->queue_sel].desc[0 ], + ((uint64_t )proxy->vqs[vdev->queue_sel].avail[1 ]) <<32 | + proxy->vqs[vdev->queue_sel].avail[0 ], + ((uint64_t )proxy->vqs[vdev->queue_sel].used[1 ]) <<32 | + proxy->vqs[vdev->queue_sel].used[0 ]); +break ; +case VIRTIO_PCI_COMMON_Q_DESCLO : + proxy->vqs[vdev->queue_sel].desc[0 ] = val; +break ; +case VIRTIO_PCI_COMMON_Q_DESCHI : + proxy->vqs[vdev->queue_sel].desc[1 ] = val; +break ; +case VIRTIO_PCI_COMMON_Q_AVAILLO : + proxy->vqs[vdev->queue_sel].avail[0 ] = val; +break ; +case VIRTIO_PCI_COMMON_Q_AVAILHI : + proxy->vqs[vdev->queue_sel].avail[1 ] = val; +break ; +case VIRTIO_PCI_COMMON_Q_USEDLO : + proxy->vqs[vdev->queue_sel].used[0 ] = val; +break ; +case VIRTIO_PCI_COMMON_Q_USEDHI : + proxy->vqs[vdev->queue_sel].used[1 ] = val; +break ; +default : +break ; + } +} + + +static uint64_t virtio_pci_notify_read (void *opaque,hwaddr addr, +unsigned size) +{ +return 0 ; +} + +static void virtio_pci_notify_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +VirtIODevice *vdev = opaque; +unsigned queue = addr /QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ; + +if (queue <VIRTIO_QUEUE_MAX ) { +virtio_queue_notify (vdev, queue); + } +} + +static uint64_t virtio_pci_isr_read (void *opaque,hwaddr addr, +unsigned size) +{ +VirtIOPCIProxy *proxy = opaque; +VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); +uint64_t val = vdev->isr; + + vdev->isr =0 ; +pci_irq_deassert (&proxy->pci_dev); + +return val; +} + +static void virtio_pci_isr_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +} + +static uint64_t virtio_pci_device_read (void *opaque,hwaddr addr, +unsigned size) +{ +VirtIODevice *vdev = opaque; +uint64_t val =0 ; + +switch (size) { +case 1 : + val =virtio_config_readb (vdev, addr); +break ; +case 2 : + val =virtio_config_readw (vdev, addr); +break ; +case 4 : + val =virtio_config_readl (vdev, addr); +break ; + } +return val; +} + +static void virtio_pci_device_write (void *opaque,hwaddr addr, +uint64_t val,unsigned size) +{ +VirtIODevice *vdev = opaque; +switch (size) { +case 1 : +virtio_config_writeb (vdev, addr, val); +break ; +case 2 : +virtio_config_writew (vdev, addr, val); +break ; +case 4 : +virtio_config_writel (vdev, addr, val); +break ; + } +} + +/* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged (DeviceState *d,Error **errp) {
@@ -931,6 +1203,112 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); config[PCI_INTERRUPT_PIN ] =1 ; + +if (1 ) {/* TODO: Make this optional, dependent on virtio 1.0 */ +struct virtio_pci_cap common = { + .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , + .cap_len =sizeof common, + .offset =cpu_to_le32 (0x0 ), + .length =cpu_to_le32 (0x1000 ), + }; +struct virtio_pci_cap isr = { + .cfg_type =VIRTIO_PCI_CAP_ISR_CFG , + .cap_len =sizeof isr, + .offset =cpu_to_le32 (0x1000 ), + .length =cpu_to_le32 (0x1000 ), + }; +struct virtio_pci_cap device = { + .cfg_type =VIRTIO_PCI_CAP_DEVICE_CFG , + .cap_len =sizeof device, + .offset =cpu_to_le32 (0x2000 ), + .length =cpu_to_le32 (0x1000 ), + }; +struct virtio_pci_notify_cap notify = { + .cap.cfg_type =VIRTIO_PCI_CAP_NOTIFY_CFG , + .cap.cap_len =sizeof notify, + .cap.offset =cpu_to_le32 (0x3000 ), + .cap.length =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_QUEUE_MAX ), + .notify_off_multiplier = +cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ), + }; + +static const MemoryRegionOps common_ops = { + .read = virtio_pci_common_read, + .write = virtio_pci_common_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +static const MemoryRegionOps isr_ops = { + .read = virtio_pci_isr_read, + .write = virtio_pci_isr_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +static const MemoryRegionOps device_ops = { + .read = virtio_pci_device_read, + .write = virtio_pci_device_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +static const MemoryRegionOps notify_ops = { + .read = virtio_pci_notify_read, + .write = virtio_pci_notify_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +/* TODO: add io access for speed */ +virtio_pci_add_mem_cap (proxy, &common); +virtio_pci_add_mem_cap (proxy, &isr); +virtio_pci_add_mem_cap (proxy, &device); +virtio_pci_add_mem_cap (proxy, ¬ify.cap); + +virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 ); +memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" , +2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_QUEUE_MAX ); +memory_region_init_io (&proxy->common,OBJECT (proxy), + &common_ops, + proxy, +"virtio-pci-common" ,0x1000 ); +memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common); +memory_region_init_io (&proxy->isr,OBJECT (proxy), + &isr_ops, + proxy, +"virtio-pci-isr" ,0x1000 ); +memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr); +memory_region_init_io (&proxy->device,OBJECT (proxy), + &device_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-device" ,0x1000 ); +memory_region_add_subregion (&proxy->modern_bar,0x2000 , &proxy->device); +memory_region_init_io (&proxy->notify,OBJECT (proxy), + ¬ify_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-notify" , +QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_QUEUE_MAX ); +memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify); +pci_register_bar (&proxy->pci_dev,2 ,PCI_BASE_ADDRESS_SPACE_MEMORY , + &proxy->modern_bar); + } +if (proxy->nvectors &&msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors,1 )) { error_report("unable to init msix vectors to %" PRIu32,
@@ -948,6 +1326,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)memory_region_init_io (&proxy->bar,OBJECT (proxy), &virtio_pci_config_ops, proxy,"virtio-pci" , size); +pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , &proxy->bar);
hw/virtio/virtio-pci.h +16 -0
@@ -88,9 +88,25 @@ typedef struct VirtioPCIClass {struct VirtIOPCIProxy {PCIDevice pci_dev;MemoryRegion bar; +MemoryRegion common; +MemoryRegion isr; +MemoryRegion device; +MemoryRegion notify; +MemoryRegion modern_bar;uint32_t flags;uint32_t class_code;uint32_t nvectors; +uint32_t dfselect; +uint32_t gfselect; +uint32_t guest_features[2 ]; +struct { +uint16_t num; +bool enabled; +uint32_t desc[2 ]; +uint32_t avail[2 ]; +uint32_t used[2 ]; + } vqs[VIRTIO_QUEUE_MAX ]; +bool ioeventfd_disabled;bool ioeventfd_started;VirtIOIRQFD *vector_irqfd;
Signature · 1 line
1.8.3.1
PATCH 14/33 virtio: generation counter support
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
--- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 1 + include/hw/virtio/virtio.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
@@ -970,7 +970,7 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, val = vdev->status;break ;case VIRTIO_PCI_COMMON_CFGGENERATION : - val =0 ;/* TODO */ + val = vdev->generation;break ;case VIRTIO_PCI_COMMON_Q_SELECT : val = vdev->queue_sel;
hw/virtio/virtio.c +1 -0
@@ -930,6 +930,7 @@ void virtio_notify_config(VirtIODevice *vdev)return ; vdev->isr |=0x03 ; + vdev->generation++;virtio_notify_vector (vdev, vdev->config_vector); }
include/hw/virtio/virtio.h +1 -0
@@ -78,6 +78,7 @@ struct VirtIODevicesize_t config_len;void *config;uint16_t config_vector; +uint32_t generation;int nvectors;VirtQueue *vq;uint16_t device_id;
Signature · 1 line
1.8.3.1
PATCH 15/33 virtio: add modern config accessors
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
virtio 1.0 defines config space as LE,
as opposed to pre-1.0 which was native endian.
Add API for transports to execute word/dword accesses in little endian format - will be useful for mmio and pci (byte access is also wrapped, for completeness).
For simplicity, we still keep config in host native endian format, byteswap to LE on guest access.
--- hw/virtio/virtio.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 9 +++++ 2 files changed, 105 insertions(+)
hw/virtio/virtio.c +96 -0
@@ -729,6 +729,102 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data) } } +uint32_t virtio_config_modern_readb (VirtIODevice *vdev,uint32_t addr) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint8_t val; + +if (addr +sizeof (val) > vdev->config_len) { +return (uint32_t )-1 ; + } + + k->get_config (vdev, vdev->config); + + val =ldub_p (vdev->config + addr); +return val; +} + +uint32_t virtio_config_modern_readw (VirtIODevice *vdev,uint32_t addr) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint16_t val; + +if (addr +sizeof (val) > vdev->config_len) { +return (uint32_t )-1 ; + } + + k->get_config (vdev, vdev->config); + + val =lduw_le_p (vdev->config + addr); +return val; +} + +uint32_t virtio_config_modern_readl (VirtIODevice *vdev,uint32_t addr) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint32_t val; + +if (addr +sizeof (val) > vdev->config_len) { +return (uint32_t )-1 ; + } + + k->get_config (vdev, vdev->config); + + val =ldl_le_p (vdev->config + addr); +return val; +} + +void virtio_config_modern_writeb (VirtIODevice *vdev, +uint32_t addr,uint32_t data) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint8_t val = data; + +if (addr +sizeof (val) > vdev->config_len) { +return ; + } + +stb_p (vdev->config + addr, val); + +if (k->set_config) { + k->set_config (vdev, vdev->config); + } +} + +void virtio_config_modern_writew (VirtIODevice *vdev, +uint32_t addr,uint32_t data) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint16_t val = data; + +if (addr +sizeof (val) > vdev->config_len) { +return ; + } + +stw_le_p (vdev->config + addr, val); + +if (k->set_config) { + k->set_config (vdev, vdev->config); + } +} + +void virtio_config_modern_writel (VirtIODevice *vdev, +uint32_t addr,uint32_t data) +{ +VirtioDeviceClass *k =VIRTIO_DEVICE_GET_CLASS (vdev); +uint32_t val = data; + +if (addr +sizeof (val) > vdev->config_len) { +return ; + } + +stl_le_p (vdev->config + addr, val); + +if (k->set_config) { + k->set_config (vdev, vdev->config); + } +} +void virtio_queue_set_addr (VirtIODevice *vdev,int n,hwaddr addr) { vdev->vq[n].vring.desc = addr;
include/hw/virtio/virtio.h +9 -0
@@ -174,6 +174,15 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr);void virtio_config_writeb (VirtIODevice *vdev,uint32_t addr,uint32_t data);void virtio_config_writew (VirtIODevice *vdev,uint32_t addr,uint32_t data);void virtio_config_writel (VirtIODevice *vdev,uint32_t addr,uint32_t data); +uint32_t virtio_config_modern_readb (VirtIODevice *vdev,uint32_t addr); +uint32_t virtio_config_modern_readw (VirtIODevice *vdev,uint32_t addr); +uint32_t virtio_config_modern_readl (VirtIODevice *vdev,uint32_t addr); +void virtio_config_modern_writeb (VirtIODevice *vdev, +uint32_t addr,uint32_t data); +void virtio_config_modern_writew (VirtIODevice *vdev, +uint32_t addr,uint32_t data); +void virtio_config_modern_writel (VirtIODevice *vdev, +uint32_t addr,uint32_t data);void virtio_queue_set_addr (VirtIODevice *vdev,int n,hwaddr addr);hwaddr virtio_queue_get_addr (VirtIODevice *vdev,int n);void virtio_queue_set_num (VirtIODevice *vdev,int n,int num);
Signature · 1 line
1.8.3.1
PATCH 16/33 virtio-pci: switch to modern accessors for 1.0
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
virtio 1.0 config space is in LE format for all devices, use modern wrappers when accessed through the 1.0 BAR.
--- hw/virtio/virtio-pci.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +6 -6
@@ -1155,13 +1155,13 @@ static uint64_t virtio_pci_device_read(void *opaque, hwaddr addr,switch (size) {case 1 : - val =virtio_config_readb (vdev, addr); + val =virtio_config_modern_readb (vdev, addr);break ;case 2 : - val =virtio_config_readw (vdev, addr); + val =virtio_config_modern_readw (vdev, addr);break ;case 4 : - val =virtio_config_readl (vdev, addr); + val =virtio_config_modern_readl (vdev, addr);break ; }return val;
@@ -1173,13 +1173,13 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr,VirtIODevice *vdev = opaque;switch (size) {case 1 : -virtio_config_writeb (vdev, addr, val); +virtio_config_modern_writeb (vdev, addr, val);break ;case 2 : -virtio_config_writew (vdev, addr, val); +virtio_config_modern_writew (vdev, addr, val);break ;case 4 : -virtio_config_writel (vdev, addr, val); +virtio_config_modern_writel (vdev, addr, val);break ; } }
Signature · 1 line
1.8.3.1
PATCH 17/33 virtio-pci: add flags to enable/disable legacy/modern
In reply to Gerd HoffmannAdd VIRTIO_PCI_FLAG_DISABLE_LEGACY and VIRTIO_PCI_FLAG_DISABLE_MODERN for VirtIOPCIProxy->flags. Also add properties for them. They can be used to disable modern (virtio 1.0) or legacy (virtio 0.9) modes.
By default only legacy is advertized, modern will be turned on by default once all remaining spec compilance issues are addressed.
--- hw/virtio/virtio-pci.c | 48 ++++++++++++++++++++++++++++++++++-------------- hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 40 insertions(+), 14 deletions(-)
hw/virtio/virtio-pci.c +34 -14
@@ -1190,6 +1190,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (d);VirtioBusState *bus = &proxy->bus; +bool legacy = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_LEGACY ); +bool modern = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN );uint8_t *config;uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus);
@@ -1198,13 +1200,24 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (proxy->class_code) {pci_config_set_class (config, proxy->class_code); } -pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , -pci_get_word (config +PCI_VENDOR_ID )); -pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + +if (legacy) { +/* legacy and transitional */ +pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , +pci_get_word (config +PCI_VENDOR_ID )); +pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + }else { +/* pure virtio-1.0 */ +pci_set_word (config +PCI_VENDOR_ID , +PCI_VENDOR_ID_REDHAT_QUMRANET ); +pci_set_word (config +PCI_DEVICE_ID , +0x1040 +virtio_bus_get_vdev_id (bus)); +pci_config_set_revision (config,1 ); + } config[PCI_INTERRUPT_PIN ] =1 ; -if (1 ) {/* TODO: Make this optional, dependent on virtio 1.0 */ +if (modern) {struct virtio_pci_cap common = { .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , .cap_len =sizeof common,
@@ -1318,18 +1331,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) proxy->pci_dev.config_write = virtio_write_config; - size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) - +virtio_bus_get_vdev_config_len (bus); -if (size & (size -1 )) { - size =1 <<qemu_fls (size); +if (legacy) { + size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) + +virtio_bus_get_vdev_config_len (bus); +if (size & (size -1 )) { + size =1 <<qemu_fls (size); + } + +memory_region_init_io (&proxy->bar,OBJECT (proxy), + &virtio_pci_config_ops, + proxy,"virtio-pci" , size); + +pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , + &proxy->bar); } -memory_region_init_io (&proxy->bar,OBJECT (proxy), &virtio_pci_config_ops, - proxy,"virtio-pci" , size); - -pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , - &proxy->bar); -if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ; }
@@ -1372,6 +1388,10 @@ static void virtio_pci_reset(DeviceState *qdev)static Property virtio_pci_properties[] = {DEFINE_PROP_BIT ("virtio-pci-bus-master-bug-migration" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT , false), +DEFINE_PROP_BIT ("disable-legacy" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT , false), +DEFINE_PROP_BIT ("disable-modern" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT , true),DEFINE_PROP_END_OF_LIST (), };
hw/virtio/virtio-pci.h +6 -0
@@ -63,6 +63,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT) +/* virtio version flags */ +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT 2 +#define VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT 3 +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT) +#define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT) + typedef struct { MSIMessage msg; int virq;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 17/33] virtio-pci: add flags to enable/disable legacy/modern
Quoted 6 lines · Gerd Hoffmann
Add
VIRTIO_PCI_FLAG_DISABLE_LEGACYandVIRTIO_PCI_FLAG_DISABLE_MODERNforVirtIOPCIProxy->flags. Also add properties for them. They can be used to disable modern (virtio 1.0) or legacy (virtio 0.9) modes.By default only legacy is advertized, modern will be turned on by default once all remaining spec compilance issues are addressed.
What is the reason for adding these flags? From the pov of management app integration I think we'd really want the front/back to be automatically negotiating the right compatible featureset. Having mgmt need to set these legacy/modern flags based on guest OS needs seems rather painful. As such I'd be really loathe to support these in libvirt
Quoted 115 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio-pci.c | 48 ++++++++++++++++++++++++++++++++++-------------- hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 40 insertions(+), 14 deletions(-)hw/virtio/virtio-pci.c +34
-14@@ -1190,6 +1190,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (d);VirtioBusState *bus = &proxy->bus; +bool legacy = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_LEGACY ); +bool modern = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN );uint8_t *config;uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus);@@ -1198,13 +1200,24 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (proxy->class_code) {pci_config_set_class (config, proxy->class_code); } -pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , -pci_get_word (config +PCI_VENDOR_ID )); -pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + +if (legacy) { +/* legacy and transitional */ +pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , +pci_get_word (config +PCI_VENDOR_ID )); +pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + }else { +/* pure virtio-1.0 */ +pci_set_word (config +PCI_VENDOR_ID , +PCI_VENDOR_ID_REDHAT_QUMRANET ); +pci_set_word (config +PCI_DEVICE_ID , +0x1040 +virtio_bus_get_vdev_id (bus)); +pci_config_set_revision (config,1 ); + } config[PCI_INTERRUPT_PIN ] =1 ; -if (1 ) {/* TODO: Make this optional, dependent on virtio 1.0 */ +if (modern) {struct virtio_pci_cap common = { .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , .cap_len =sizeof common,@@ -1318,18 +1331,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) proxy->pci_dev.config_write = virtio_write_config; - size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) - +virtio_bus_get_vdev_config_len (bus); -if (size & (size -1 )) { - size =1 <<qemu_fls (size); +if (legacy) { + size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) + +virtio_bus_get_vdev_config_len (bus); +if (size & (size -1 )) { + size =1 <<qemu_fls (size); + } + +memory_region_init_io (&proxy->bar,OBJECT (proxy), + &virtio_pci_config_ops, + proxy,"virtio-pci" , size); + +pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , + &proxy->bar); } -memory_region_init_io (&proxy->bar,OBJECT (proxy), &virtio_pci_config_ops, - proxy,"virtio-pci" , size); - -pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , - &proxy->bar); -if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ; }@@ -1372,6 +1388,10 @@ static void virtio_pci_reset(DeviceState *qdev)static Property virtio_pci_properties[] = {DEFINE_PROP_BIT ("virtio-pci-bus-master-bug-migration" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT , false), +DEFINE_PROP_BIT ("disable-legacy" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT , false), +DEFINE_PROP_BIT ("disable-modern" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT , true),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-0@@ -63,6 +63,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT) +/* virtio version flags */ +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT 2 +#define VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT 3 +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT) +#define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT) + typedef struct { MSIMessage msg; int virq;Signature · 1 line
1.8.3.1
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 17/33] virtio-pci: add flags to enable/disable legacy/modern
Quoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Gerd Hoffmann
Add
VIRTIO_PCI_FLAG_DISABLE_LEGACYandVIRTIO_PCI_FLAG_DISABLE_MODERNforVirtIOPCIProxy->flags. Also add properties for them. They can be used to disable modern (virtio 1.0) or legacy (virtio 0.9) modes.
Quoted 8 lines
Quoted 2 lines
By default only legacy is advertized, modern will be turned on by default once all remaining spec compilance issues are addressed.
What is the reason for adding these flags? From the pov of management app integration I think we'd really want the front/back to be automatically negotiating the right compatible featureset. Having mgmt need to set these legacy/modern flags based on guest OS needs seems rather painful. As such I'd be really loathe to support these in libvirt
Normally people want a transitional device which has both interfaces, so most people don't set any flags, and we negotiate the best compatible configuration.
Ability to suppress the modern interface from libvirt seems useful as a safety latch: makes guest use legacy code.
Ability to suppress the legacy interface from libvirt might serve to reduce the attack surface slightly.
It also frees up IO resources (which are allocated at boot whether the interface is used or not) so it useful if people have a huge # of devices.
To summarise, mgmt never needs to set these automatically, but it is useful to expose them to users.
Quoted 123 lines
Quoted 115 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/virtio/virtio-pci.c | 48 ++++++++++++++++++++++++++++++++++-------------- hw/virtio/virtio-pci.h | 6 ++++++ 2 files changed, 40 insertions(+), 14 deletions(-)hw/virtio/virtio-pci.c +34
-14@@ -1190,6 +1190,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (d);VirtioBusState *bus = &proxy->bus; +bool legacy = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_LEGACY ); +bool modern = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN );uint8_t *config;uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus);@@ -1198,13 +1200,24 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (proxy->class_code) {pci_config_set_class (config, proxy->class_code); } -pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , -pci_get_word (config +PCI_VENDOR_ID )); -pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + +if (legacy) { +/* legacy and transitional */ +pci_set_word (config +PCI_SUBSYSTEM_VENDOR_ID , +pci_get_word (config +PCI_VENDOR_ID )); +pci_set_word (config +PCI_SUBSYSTEM_ID ,virtio_bus_get_vdev_id (bus)); + }else { +/* pure virtio-1.0 */ +pci_set_word (config +PCI_VENDOR_ID , +PCI_VENDOR_ID_REDHAT_QUMRANET ); +pci_set_word (config +PCI_DEVICE_ID , +0x1040 +virtio_bus_get_vdev_id (bus)); +pci_config_set_revision (config,1 ); + } config[PCI_INTERRUPT_PIN ] =1 ; -if (1 ) {/* TODO: Make this optional, dependent on virtio 1.0 */ +if (modern) {struct virtio_pci_cap common = { .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , .cap_len =sizeof common,@@ -1318,18 +1331,21 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) proxy->pci_dev.config_write = virtio_write_config; - size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) - +virtio_bus_get_vdev_config_len (bus); -if (size & (size -1 )) { - size =1 <<qemu_fls (size); +if (legacy) { + size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) + +virtio_bus_get_vdev_config_len (bus); +if (size & (size -1 )) { + size =1 <<qemu_fls (size); + } + +memory_region_init_io (&proxy->bar,OBJECT (proxy), + &virtio_pci_config_ops, + proxy,"virtio-pci" , size); + +pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , + &proxy->bar); } -memory_region_init_io (&proxy->bar,OBJECT (proxy), &virtio_pci_config_ops, - proxy,"virtio-pci" , size); - -pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , - &proxy->bar); -if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ; }@@ -1372,6 +1388,10 @@ static void virtio_pci_reset(DeviceState *qdev)static Property virtio_pci_properties[] = {DEFINE_PROP_BIT ("virtio-pci-bus-master-bug-migration" , VirtIOPCIProxy, flags,VIRTIO_PCI_FLAG_BUS_MASTER_BUG_MIGRATION_BIT , false), +DEFINE_PROP_BIT ("disable-legacy" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT , false), +DEFINE_PROP_BIT ("disable-modern" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT , true),DEFINE_PROP_END_OF_LIST (), };hw/virtio/virtio-pci.h +6
-0@@ -63,6 +63,12 @@ typedef struct VirtioBusClass VirtioPCIBusClass;#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1#define VIRTIO_PCI_FLAG_USE_IOEVENTFD (1 << VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT) +/* virtio version flags */ +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT 2 +#define VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT 3 +#define VIRTIO_PCI_FLAG_DISABLE_LEGACY (1 << VIRTIO_PCI_FLAG_DISABLE_LEGACY_BIT) +#define VIRTIO_PCI_FLAG_DISABLE_MODERN (1 << VIRTIO_PCI_FLAG_DISABLE_MODERN_BIT) + typedef struct { MSIMessage msg; int virq;Signature · 1 line
1.8.3.1Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 17/33] virtio-pci: add flags to enable/disable legacy/modern
In reply to Daniel P. BerrangeQuoted 5 lines · Daniel P. Berrange
Quoted 4 lines · Gerd Hoffmann
Add
VIRTIO_PCI_FLAG_DISABLE_LEGACYandVIRTIO_PCI_FLAG_DISABLE_MODERNforVirtIOPCIProxy->flags. Also add properties for them. They can be used to disable modern (virtio 1.0) or legacy (virtio 0.9) modes.
Quoted 8 lines
Quoted 2 lines
By default only legacy is advertized, modern will be turned on by default once all remaining spec compilance issues are addressed.
What is the reason for adding these flags? From the pov of management app integration I think we'd really want the front/back to be automatically negotiating the right compatible featureset. Having mgmt need to set these legacy/modern flags based on guest OS needs seems rather painful. As such I'd be really loathe to support these in libvirt
Usually there should be no need to muck with these, except for development and testing purposes. And of course we need them so we can turn off virtio 1.0 for old machine types via compat properties (once we flip the switch to enable virtio-1.0 by default).
libvirt support for these in the domain xml syntax goes into "nice-to-have" category, but I can equally well live without them and use the <qemu:*> tags to set them if needed.
Support for them higher up in the management stack should not be needed.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 17/33] virtio-pci: add flags to enable/disable legacy/modern
Hi,
Quoted 3 lines
libvirt support for these in the domain xml syntax goes into "nice-to-have" category, but I can equally well live without them and use the <qemu:*> tags to set them if needed.
For anyone playing with this: The magic words to flip the modern switch for virtio-pci devices globally via libvirt domain xml are:
<qemu:commandline>
<qemu:arg value='-global'/>
<qemu:arg value='virtio-pci.disable-modern=off'/></qemu:commandline>
HTH,
Gerd
PATCH 18/33 virtio-pci: make QEMU_VIRTIO_PCI_QUEUE_MEM_MULT smaller
In reply to Gerd Hoffmann--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
@@ -929,7 +929,7 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, cap->cap_len - PCI_CAP_FLAGS); } -#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x10000 +#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000static uint64_t virtio_pci_common_read (void *opaque,hwaddr addr,unsigned size)
Signature · 1 line
1.8.3.1
PATCH 19/33 virtio-pci: change & document virtio pci bar layout.
In reply to Gerd HoffmannThis patch adds variables for the pci bars (to get rid of the magic numbers in the code) and moves the modern virtio bar to region 4 so regions 2+3 are kept free. virtio-vga wants use them.
--- hw/virtio/virtio-pci.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +25 -6
@@ -919,8 +919,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,PCIDevice *dev = &proxy->pci_dev;int offset; - cap->bar =2 ; - offset =pci_add_capability (dev,PCI_CAP_ID_VNDR ,0 , cap->cap_len);assert (offset >0 );
@@ -1196,6 +1194,22 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); +/* +* virtio pci bar layout +* +* region 0 -- virtio legacy io bar +* region 1 -- msi-x bar +* region 2+3 -- not used by virtio-pci +* region 4+5 -- virtio modern memory (64bit) bar +* +* Regions 2+3 can be used by VirtIOPCIProxy subclasses. +* virtio-vga places the vga framebuffer there. +* +*/ +uint32_t legacy_io_bar =0 ; +uint32_t msix_bar =1 ; +uint32_t modern_mem_bar =4 ; + config = proxy->pci_dev.config;if (proxy->class_code) {pci_config_set_class (config, proxy->class_code);
@@ -1221,24 +1235,28 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)struct virtio_pci_cap common = { .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , .cap_len =sizeof common, + .bar = modern_mem_bar, .offset =cpu_to_le32 (0x0 ), .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_cap isr = { .cfg_type =VIRTIO_PCI_CAP_ISR_CFG , .cap_len =sizeof isr, + .bar = modern_mem_bar, .offset =cpu_to_le32 (0x1000 ), .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_cap device = { .cfg_type =VIRTIO_PCI_CAP_DEVICE_CFG , .cap_len =sizeof device, + .bar = modern_mem_bar, .offset =cpu_to_le32 (0x2000 ), .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_notify_cap notify = { .cap.cfg_type =VIRTIO_PCI_CAP_NOTIFY_CFG , .cap.cap_len =sizeof notify, + .cap.bar = modern_mem_bar, .cap.offset =cpu_to_le32 (0x3000 ), .cap.length =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ),
@@ -1318,12 +1336,13 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX);memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify); -pci_register_bar (&proxy->pci_dev,2 ,PCI_BASE_ADDRESS_SPACE_MEMORY , +pci_register_bar (&proxy->pci_dev, modern_mem_bar, +PCI_BASE_ADDRESS_SPACE_MEMORY , &proxy->modern_bar); }if (proxy->nvectors && -msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors,1 )) { +msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors, msix_bar)) {error_report ("unable to init msix vectors to %" PRIu32, proxy->nvectors); proxy->nvectors =0 ;
@@ -1342,8 +1361,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) &virtio_pci_config_ops, proxy, "virtio-pci", size); -pci_register_bar (&proxy->pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_IO , - &proxy->bar); +pci_register_bar (&proxy->pci_dev, legacy_io_bar, +PCI_BASE_ADDRESS_SPACE_IO , &proxy->bar); }if (!kvm_has_many_ioeventfds ()) {
Signature · 1 line
1.8.3.1
PATCH 20/33 virtio-pci: make modern bar 64bit + prefetchable
In reply to Gerd Hoffmann--- hw/virtio/virtio-pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +3 -1
@@ -1337,7 +1337,9 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) VIRTIO_QUEUE_MAX);memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify);pci_register_bar (&proxy->pci_dev, modern_mem_bar, -PCI_BASE_ADDRESS_SPACE_MEMORY , +PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_PREFETCH | +PCI_BASE_ADDRESS_MEM_TYPE_64 , &proxy->modern_bar); }
Signature · 1 line
1.8.3.1
PATCH 21/33 virtio-pci: correctly set host notifiers for modern bar
In reply to Gerd HoffmannFrom: Jason Wang <[email protected]>
Currently, during host notifier set. We only add eventfd for legacy bar, this is not correct since:
- Non-transitional device does not have legacy bar, so qemu will crash since proxy->bar was not initialized.
- Modern device uses modern bar and notify cap to notify the device, we should add eventfd for proxy->notify.
So this patch fixes the above two issues by adding eventfd based on whether legacy or modern device were supported.
--- hw/virtio/virtio-pci.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +25 -6
@@ -135,12 +135,21 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)return 0 ; } +#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000 +static int virtio_pci_set_host_notifier_internal (VirtIOPCIProxy *proxy,int n,bool assign,bool set_handler) {VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus);VirtQueue *vq =virtio_get_queue (vdev, n);EventNotifier *notifier =virtio_queue_get_host_notifier (vq); +bool legacy = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_LEGACY ); +bool modern = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN ); +MemoryRegion *modern_mr = &proxy->notify; +MemoryRegion *legacy_mr = &proxy->bar; +hwaddr modern_addr =QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +virtio_get_queue_index (vq); +hwaddr legacy_addr =VIRTIO_PCI_QUEUE_NOTIFY ;int r =0 ;if (assign) {
@@ -151,11 +160,23 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,return r; }virtio_queue_set_host_notifier_fd_handler (vq, true, set_handler); -memory_region_add_eventfd (&proxy->bar,VIRTIO_PCI_QUEUE_NOTIFY ,2 , - true, n, notifier); +if (modern) { +memory_region_add_eventfd (modern_mr, modern_addr,2 , + true, n, notifier); + } +if (legacy) { +memory_region_add_eventfd (legacy_mr, legacy_addr,2 , + true, n, notifier); + } }else { -memory_region_del_eventfd (&proxy->bar,VIRTIO_PCI_QUEUE_NOTIFY ,2 , - true, n, notifier); +if (modern) { +memory_region_del_eventfd (modern_mr, modern_addr,2 , + true, n, notifier); + } +if (legacy) { +memory_region_del_eventfd (legacy_mr, legacy_addr,2 , + true, n, notifier); + }virtio_queue_set_host_notifier_fd_handler (vq, false, false);event_notifier_cleanup (notifier); }
@@ -927,8 +948,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, cap->cap_len - PCI_CAP_FLAGS); } -#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000 -static uint64_t virtio_pci_common_read (void *opaque,hwaddr addr,unsigned size) {
Signature · 1 line
1.8.3.1
PATCH 22/33 virtio_balloon: header update
In reply to Gerd HoffmannFrom: "Michael S. Tsirkin" <[email protected]>
add modern header
--- include/hw/virtio/virtio-balloon.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/hw/virtio/virtio-balloon.h +6 -0
@@ -25,6 +25,12 @@typedef struct virtio_balloon_stat VirtIOBalloonStat ; +typedef struct virtio_balloon_stat_modern { +uint16_t tag; +uint8_t reserved[6 ]; +uint64_t val; +}VirtIOBalloonStatModern ; + typedef struct VirtIOBalloon { VirtIODevice parent_obj; VirtQueue *ivq, *dvq, *svq;
Signature · 1 line
1.8.3.1
PATCH 23/33 virtio-balloon: switch to virtio_add_feature
In reply to Gerd HoffmannFrom: Cornelia Huck <[email protected]>
This was missed during the conversion of feature bit manipulation.
--- hw/virtio/virtio-balloon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +1 -1
@@ -312,7 +312,7 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,static uint64_t virtio_balloon_get_features (VirtIODevice *vdev,uint64_t f) { - f |= (1 <<VIRTIO_BALLOON_F_STATS_VQ ); +virtio_add_feature (&f,VIRTIO_BALLOON_F_STATS_VQ );return f; }
Signature · 1 line
1.8.3.1
PATCH 24/33 virtio-pci: add struct VirtIOPCIRegion for virtio-1 regions
In reply to Gerd HoffmannFor now just place the MemoryRegion there,
following patches will add more.
--- hw/virtio/virtio-pci.c | 20 +++++++++++--------- hw/virtio/virtio-pci.h | 12 ++++++++---- 2 files changed, 19 insertions(+), 13 deletions(-)
hw/virtio/virtio-pci.c +11 -9
@@ -145,7 +145,7 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,EventNotifier *notifier =virtio_queue_get_host_notifier (vq);bool legacy = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_LEGACY );bool modern = !(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN ); -MemoryRegion *modern_mr = &proxy->notify; +MemoryRegion *modern_mr = &proxy->notify.mr;MemoryRegion *legacy_mr = &proxy->bar;hwaddr modern_addr =QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *virtio_get_queue_index (vq);
@@ -1333,28 +1333,30 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ); -memory_region_init_io (&proxy->common,OBJECT (proxy), +memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy,"virtio-pci-common" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common); -memory_region_init_io (&proxy->isr,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr); -memory_region_init_io (&proxy->device,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0x2000 , &proxy->device); -memory_region_init_io (&proxy->notify,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0x2000 , + &proxy->device.mr); +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-notify" ,QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ); -memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify); +memory_region_add_subregion (&proxy->modern_bar,0x3000 , + &proxy->notify.mr); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
hw/virtio/virtio-pci.h +8 -4
@@ -91,13 +91,17 @@ typedef struct VirtioPCIClass {void (*realize)(VirtIOPCIProxy *vpci_dev,Error **errp); } VirtioPCIClass; +typedef struct VirtIOPCIRegion { +MemoryRegion mr; +}VirtIOPCIRegion ; +struct VirtIOPCIProxy {PCIDevice pci_dev;MemoryRegion bar; -MemoryRegion common; -MemoryRegion isr; -MemoryRegion device; -MemoryRegion notify; +VirtIOPCIRegion common; +VirtIOPCIRegion isr; +VirtIOPCIRegion device; +VirtIOPCIRegion notify;MemoryRegion modern_bar;uint32_t flags;uint32_t class_code;
Signature · 1 line
1.8.3.1
PATCH 25/33 virtio-pci: add virtio_pci_modern_regions_init()
In reply to Gerd HoffmannAdd init function for the modern pci regions,
move over the init code.
--- hw/virtio/virtio-pci.c | 117 +++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 58 deletions(-)
hw/virtio/virtio-pci.c +59 -58
@@ -1201,6 +1201,64 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr, } } +static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy) +{ +static const MemoryRegionOps common_ops = { + .read = virtio_pci_common_read, + .write = virtio_pci_common_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps isr_ops = { + .read = virtio_pci_isr_read, + .write = virtio_pci_isr_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps device_ops = { + .read = virtio_pci_device_read, + .write = virtio_pci_device_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps notify_ops = { + .read = virtio_pci_notify_read, + .write = virtio_pci_notify_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +memory_region_init_io (&proxy->common.mr,OBJECT (proxy), + &common_ops, + proxy, +"virtio-pci-common" ,0x1000 ); +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), + &isr_ops, + proxy, +"virtio-pci-isr" ,0x1000 ); +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), + &device_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-device" ,0x1000 ); +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), + ¬ify_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-notify" , +QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_QUEUE_MAX ); +}/* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged (DeviceState *d,Error **errp)
@@ -1283,46 +1341,6 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT), }; -static const MemoryRegionOps common_ops = { - .read = virtio_pci_common_read, - .write = virtio_pci_common_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps isr_ops = { - .read = virtio_pci_isr_read, - .write = virtio_pci_isr_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps device_ops = { - .read = virtio_pci_device_read, - .write = virtio_pci_device_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps notify_ops = { - .read = virtio_pci_notify_read, - .write = virtio_pci_notify_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; -/* TODO: add io access for speed */ virtio_pci_add_mem_cap (proxy, &common);virtio_pci_add_mem_cap (proxy, &isr);
@@ -1333,28 +1351,11 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ); -memory_region_init_io (&proxy->common.mr,OBJECT (proxy), - &common_ops, - proxy, -"virtio-pci-common" ,0x1000 ); +virtio_pci_modern_regions_init (proxy);memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); -memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), - &isr_ops, - proxy, -"virtio-pci-isr" ,0x1000 );memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); -memory_region_init_io (&proxy->device.mr,OBJECT (proxy), - &device_ops, -virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" ,0x1000 );memory_region_add_subregion (&proxy->modern_bar,0x2000 , &proxy->device.mr); -memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), - ¬ify_ops, -virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify" , -QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_QUEUE_MAX );memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify.mr); pci_register_bar(&proxy->pci_dev, modern_mem_bar,
Signature · 1 line
1.8.3.1
PATCH 26/33 virtio-pci: add virtio_pci_modern_region_map()
In reply to Gerd HoffmannAdd function to map modern virtio regions.
Add offset to VirtIOPCIRegion.
--- hw/virtio/virtio-pci.c | 25 +++++++++++++++++++------ hw/virtio/virtio-pci.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +19 -6
@@ -1244,20 +1244,35 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) &common_ops, proxy, "virtio-pci-common", 0x1000); + proxy->common.offset =0x0 ; +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); + proxy->isr.offset =0x1000 ; +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); + proxy->device.offset =0x2000 ; +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-notify" ,QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ); + proxy->notify.offset =0x3000 ; +} + +static void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, +VirtIOPCIRegion *region) +{ +memory_region_add_subregion (&proxy->modern_bar, + region->offset, + ®ion->mr); }/* This is called by virtio-bus just after the device is plugged. */
@@ -1352,12 +1367,10 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX);virtio_pci_modern_regions_init (proxy); -memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); -memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); -memory_region_add_subregion (&proxy->modern_bar,0x2000 , - &proxy->device.mr); -memory_region_add_subregion (&proxy->modern_bar,0x3000 , - &proxy->notify.mr); +virtio_pci_modern_region_map (proxy, &proxy->common); +virtio_pci_modern_region_map (proxy, &proxy->isr); +virtio_pci_modern_region_map (proxy, &proxy->device); +virtio_pci_modern_region_map (proxy, &proxy->notify); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
hw/virtio/virtio-pci.h +1 -0
@@ -93,6 +93,7 @@ typedef struct VirtioPCIClass {typedef struct VirtIOPCIRegion {MemoryRegion mr; +uint32_t offset; }VirtIOPCIRegion ;struct VirtIOPCIProxy {
Signature · 1 line
1.8.3.1
PATCH 27/33 virtio-pci: move virtio_pci_add_mem_cap call to virtio_pci_modern_region_map
In reply to Gerd HoffmannAlso fill offset and length automatically,
from VirtIOPCIRegion->offset and region size.
--- hw/virtio/virtio-pci.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
hw/virtio/virtio-pci.c +10 -18
@@ -1268,11 +1268,16 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) }static void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, -VirtIOPCIRegion *region) +VirtIOPCIRegion *region, +struct virtio_pci_cap *cap) {memory_region_add_subregion (&proxy->modern_bar, region->offset, ®ion->mr); + + cap->offset =cpu_to_le32 (region->offset); + cap->length =cpu_to_le32 (memory_region_size (®ion->mr)); +virtio_pci_add_mem_cap (proxy, cap); }/* This is called by virtio-bus just after the device is plugged. */
@@ -1328,49 +1333,36 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) .cfg_type = VIRTIO_PCI_CAP_COMMON_CFG, .cap_len = sizeof common, .bar = modern_mem_bar, - .offset = cpu_to_le32(0x0), - .length = cpu_to_le32(0x1000), };struct virtio_pci_cap isr = { .cfg_type =VIRTIO_PCI_CAP_ISR_CFG , .cap_len =sizeof isr, .bar = modern_mem_bar, - .offset =cpu_to_le32 (0x1000 ), - .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_cap device = { .cfg_type =VIRTIO_PCI_CAP_DEVICE_CFG , .cap_len =sizeof device, .bar = modern_mem_bar, - .offset =cpu_to_le32 (0x2000 ), - .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_notify_cap notify = { .cap.cfg_type =VIRTIO_PCI_CAP_NOTIFY_CFG , .cap.cap_len =sizeof notify, .cap.bar = modern_mem_bar, - .cap.offset =cpu_to_le32 (0x3000 ), - .cap.length =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_QUEUE_MAX ), .notify_off_multiplier =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ), };/* TODO: add io access for speed */ -virtio_pci_add_mem_cap (proxy, &common); -virtio_pci_add_mem_cap (proxy, &isr); -virtio_pci_add_mem_cap (proxy, &device); -virtio_pci_add_mem_cap (proxy, ¬ify.cap);virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 );memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX );virtio_pci_modern_regions_init (proxy); -virtio_pci_modern_region_map (proxy, &proxy->common); -virtio_pci_modern_region_map (proxy, &proxy->isr); -virtio_pci_modern_region_map (proxy, &proxy->device); -virtio_pci_modern_region_map (proxy, &proxy->notify); +virtio_pci_modern_region_map (proxy, &proxy->common, &common); +virtio_pci_modern_region_map (proxy, &proxy->isr, &isr); +virtio_pci_modern_region_map (proxy, &proxy->device, &device); +virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
Signature · 1 line
1.8.3.1
PATCH 28/33 virtio-pci: move cap type to VirtIOPCIRegion
In reply to Gerd Hoffmann--- hw/virtio/virtio-pci.c | 9 +++++---- hw/virtio/virtio-pci.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-)
hw/virtio/virtio-pci.c +5 -4
@@ -1245,18 +1245,21 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) proxy, "virtio-pci-common", 0x1000); proxy->common.offset =0x0 ; + proxy->common.type =VIRTIO_PCI_CAP_COMMON_CFG ;memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); proxy->isr.offset =0x1000 ; + proxy->isr.type =VIRTIO_PCI_CAP_ISR_CFG ;memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); proxy->device.offset =0x2000 ; + proxy->device.type =VIRTIO_PCI_CAP_DEVICE_CFG ; memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), ¬ify_ops,
@@ -1265,6 +1268,7 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy)QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX); proxy->notify.offset =0x3000 ; + proxy->notify.type =VIRTIO_PCI_CAP_NOTIFY_CFG ; } static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
@@ -1275,6 +1279,7 @@ static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, region->offset, ®ion->mr); + cap->cfg_type = region->type; cap->offset =cpu_to_le32 (region->offset); cap->length =cpu_to_le32 (memory_region_size (®ion->mr));virtio_pci_add_mem_cap (proxy, cap);
@@ -1330,22 +1335,18 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) if (modern) { struct virtio_pci_cap common = { - .cfg_type = VIRTIO_PCI_CAP_COMMON_CFG, .cap_len = sizeof common, .bar = modern_mem_bar, }; struct virtio_pci_cap isr = { - .cfg_type = VIRTIO_PCI_CAP_ISR_CFG, .cap_len = sizeof isr, .bar = modern_mem_bar, }; struct virtio_pci_cap device = { - .cfg_type = VIRTIO_PCI_CAP_DEVICE_CFG, .cap_len = sizeof device, .bar = modern_mem_bar, }; struct virtio_pci_notify_cap notify = { - .cap.cfg_type = VIRTIO_PCI_CAP_NOTIFY_CFG, .cap.cap_len = sizeof notify, .cap.bar = modern_mem_bar, .notify_off_multiplier =
hw/virtio/virtio-pci.h +1 -0
@@ -94,6 +94,7 @@ typedef struct VirtioPCIClass {typedef struct VirtIOPCIRegion {MemoryRegion mr;uint32_t offset; +uint32_t type; }VirtIOPCIRegion ;struct VirtIOPCIProxy {
Signature · 1 line
1.8.3.1
PATCH 29/33 virtio-pci: drop identical virtio_pci_cap
In reply to Gerd HoffmannNow the three struct virtio_pci_caps are identical, lets drop two of them ;)
--- hw/virtio/virtio-pci.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
hw/virtio/virtio-pci.c +5 -13
@@ -1334,16 +1334,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (modern) { -struct virtio_pci_cap common = { - .cap_len =sizeof common, - .bar = modern_mem_bar, - }; -struct virtio_pci_cap isr = { - .cap_len =sizeof isr, - .bar = modern_mem_bar, - }; -struct virtio_pci_cap device = { - .cap_len =sizeof device, +struct virtio_pci_cap cap = { + .cap_len =sizeof cap, .bar = modern_mem_bar, };struct virtio_pci_notify_cap notify = {
@@ -1360,9 +1352,9 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_QUEUE_MAX);virtio_pci_modern_regions_init (proxy); -virtio_pci_modern_region_map (proxy, &proxy->common, &common); -virtio_pci_modern_region_map (proxy, &proxy->isr, &isr); -virtio_pci_modern_region_map (proxy, &proxy->device, &device); +virtio_pci_modern_region_map (proxy, &proxy->common, &cap); +virtio_pci_modern_region_map (proxy, &proxy->isr, &cap); +virtio_pci_modern_region_map (proxy, &proxy->device, &cap);virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY |
Signature · 1 line
1.8.3.1
PATCH 30/33 virtio-pci: fill VirtIOPCIRegions early.
In reply to Gerd HoffmannInitialize the modern bar and the VirtIOPCIRegion fields early, in realize. Also add a size field to VirtIOPCIRegion and variables for pci bars to VirtIOPCIProxy.
This allows virtio-pci subclasses to change things before the device_plugged callback applies them. virtio-vga will use that to arrange regions in a way that virtio-vga is compatible to both stdvga (in vga mode) and virtio-gpu-pci (in pci mode).
--- hw/virtio/virtio-pci.c | 92 ++++++++++++++++++++++++++++---------------------- hw/virtio/virtio-pci.h | 4 +++ 2 files changed, 55 insertions(+), 41 deletions(-)
hw/virtio/virtio-pci.c +51 -41
@@ -1243,32 +1243,26 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy)memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy, -"virtio-pci-common" ,0x1000 ); - proxy->common.offset =0x0 ; - proxy->common.type =VIRTIO_PCI_CAP_COMMON_CFG ; +"virtio-pci-common" , + proxy->common.size);memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy, -"virtio-pci-isr" ,0x1000 ); - proxy->isr.offset =0x1000 ; - proxy->isr.type =VIRTIO_PCI_CAP_ISR_CFG ; +"virtio-pci-isr" , + proxy->isr.size);memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" ,0x1000 ); - proxy->device.offset =0x2000 ; - proxy->device.type =VIRTIO_PCI_CAP_DEVICE_CFG ; +"virtio-pci-device" , + proxy->device.size);memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-notify" , -QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_QUEUE_MAX ); - proxy->notify.offset =0x3000 ; - proxy->notify.type =VIRTIO_PCI_CAP_NOTIFY_CFG ; + proxy->notify.size); } static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
@@ -1280,8 +1274,9 @@ static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, ®ion->mr); cap->cfg_type = region->type; + cap->bar = proxy->modern_mem_bar; cap->offset =cpu_to_le32 (region->offset); - cap->length =cpu_to_le32 (memory_region_size (®ion->mr)); + cap->length =cpu_to_le32 (region->size);virtio_pci_add_mem_cap (proxy, cap); }
@@ -1296,22 +1291,6 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); -/* -* virtio pci bar layout -* -* region 0 -- virtio legacy io bar -* region 1 -- msi-x bar -* region 2+3 -- not used by virtio-pci -* region 4+5 -- virtio modern memory (64bit) bar -* -* Regions 2+3 can be used by VirtIOPCIProxy subclasses. -* virtio-vga places the vga framebuffer there. -* -*/ -uint32_t legacy_io_bar =0 ; -uint32_t msix_bar =1 ; -uint32_t modern_mem_bar =4 ; - config = proxy->pci_dev.config;if (proxy->class_code) {pci_config_set_class (config, proxy->class_code);
@@ -1336,11 +1315,9 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (modern) {struct virtio_pci_cap cap = { .cap_len =sizeof cap, - .bar = modern_mem_bar, };struct virtio_pci_notify_cap notify = { .cap.cap_len =sizeof notify, - .cap.bar = modern_mem_bar, .notify_off_multiplier =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ), };
@@ -1348,15 +1325,12 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)/* TODO: add io access for speed */ virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 ); -memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" , -2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_QUEUE_MAX );virtio_pci_modern_regions_init (proxy);virtio_pci_modern_region_map (proxy, &proxy->common, &cap);virtio_pci_modern_region_map (proxy, &proxy->isr, &cap);virtio_pci_modern_region_map (proxy, &proxy->device, &cap);virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); - pci_register_bar(&proxy->pci_dev, modern_mem_bar, + pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH | PCI_BASE_ADDRESS_MEM_TYPE_64,
@@ -1364,7 +1338,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) }if (proxy->nvectors && -msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors, msix_bar)) { +msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors, + proxy->msix_bar)) {error_report ("unable to init msix vectors to %" PRIu32, proxy->nvectors); proxy->nvectors =0 ;
@@ -1383,7 +1358,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp) &virtio_pci_config_ops, proxy, "virtio-pci", size); -pci_register_bar (&proxy->pci_dev, legacy_io_bar, +pci_register_bar (&proxy->pci_dev, proxy->legacy_io_bar,PCI_BASE_ADDRESS_SPACE_IO , &proxy->bar); }
@@ -1403,12 +1378,47 @@ static void virtio_pci_device_unplugged(DeviceState *d)static void virtio_pci_realize (PCIDevice *pci_dev,Error **errp) { -VirtIOPCIProxy *dev =VIRTIO_PCI (pci_dev); +VirtIOPCIProxy *proxy =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); -virtio_pci_bus_new (&dev->bus,sizeof (dev->bus), dev); +/* +* virtio pci bar layout used by default. +* subclasses can re-arrange things if needed. +* +* region 0 -- virtio legacy io bar +* region 1 -- msi-x bar +* region 4+5 -- virtio modern memory (64bit) bar +* +*/ + proxy->legacy_io_bar =0 ; + proxy->msix_bar =1 ; + proxy->modern_mem_bar =4 ; + + proxy->common.offset =0x0 ; + proxy->common.size =0x1000 ; + proxy->common.type =VIRTIO_PCI_CAP_COMMON_CFG ; + + proxy->isr.offset =0x1000 ; + proxy->isr.size =0x1000 ; + proxy->isr.type =VIRTIO_PCI_CAP_ISR_CFG ; + + proxy->device.offset =0x2000 ; + proxy->device.size =0x1000 ; + proxy->device.type =VIRTIO_PCI_CAP_DEVICE_CFG ; + + proxy->notify.offset =0x3000 ; + proxy->notify.size = +QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_QUEUE_MAX ; + proxy->notify.type =VIRTIO_PCI_CAP_NOTIFY_CFG ; + +/* subclasses can enforce modern, so do this unconditionally */ +memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" , +2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_QUEUE_MAX ); + +virtio_pci_bus_new (&proxy->bus,sizeof (proxy->bus), proxy);if (k->realize) { - k->realize (dev, errp); + k->realize (proxy, errp); } }
hw/virtio/virtio-pci.h +4 -0
@@ -94,6 +94,7 @@ typedef struct VirtioPCIClass {typedef struct VirtIOPCIRegion {MemoryRegion mr;uint32_t offset; +uint32_t size;uint32_t type; }VirtIOPCIRegion ;
@@ -105,6 +106,9 @@ struct VirtIOPCIProxy {VirtIOPCIRegion device;VirtIOPCIRegion notify;MemoryRegion modern_bar; +uint32_t legacy_io_bar; +uint32_t msix_bar; +uint32_t modern_mem_bar;uint32_t flags;uint32_t class_code;uint32_t nvectors;
Signature · 1 line
1.8.3.1
PATCH 31/33 pci: add PCI_CLASS_INPUT_*
In reply to Gerd Hoffmann--- include/hw/pci/pci_ids.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/hw/pci/pci_ids.h +7 -0
@@ -47,6 +47,13 @@#define PCI_CLASS_COMMUNICATION_SERIAL 0x0700#define PCI_CLASS_COMMUNICATION_OTHER 0x0780 +#define PCI_CLASS_INPUT_KEYBOARD 0x0900 +#define PCI_CLASS_INPUT_PEN 0x0901 +#define PCI_CLASS_INPUT_MOUSE 0x0902 +#define PCI_CLASS_INPUT_SCANNER 0x0903 +#define PCI_CLASS_INPUT_GAMEPORT 0x0904 +#define PCI_CLASS_INPUT_OTHER 0x0980 +#define PCI_CLASS_PROCESSOR_CO 0x0b40#define PCI_CLASS_PROCESSOR_POWERPC 0x0b20
Signature · 1 line
1.8.3.1
PATCH 32/33 virtio-input: core code & base class [pci]
In reply to Gerd HoffmannThis patch adds the virtio-pci support bits for virtio-input-device.
--- hw/virtio/virtio-pci.c | 36 ++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 14 ++++++++++++++ 2 files changed, 50 insertions(+)
hw/virtio/virtio-pci.c +36 -0
@@ -24,6 +24,7 @@#include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-scsi.h" #include "hw/virtio/virtio-balloon.h" +#include "hw/virtio/virtio-input.h" #include "hw/pci/pci.h" #include "qemu/error-report.h" #include "hw/pci/msi.h"
@@ -1890,6 +1891,40 @@ static const TypeInfo virtio_rng_pci_info = { .class_init = virtio_rng_pci_class_init, }; +/* virtio-input-pci */ + +static void virtio_input_pci_realize (VirtIOPCIProxy *vpci_dev,Error **errp) +{ +VirtIOInputPCI *vinput =VIRTIO_INPUT_PCI (vpci_dev); +DeviceState *vdev =DEVICE (&vinput->vdev); + +qdev_set_parent_bus (vdev,BUS (&vpci_dev->bus)); +/* force virtio-1.0 */ + vpci_dev->flags &= ~VIRTIO_PCI_FLAG_DISABLE_MODERN ; + vpci_dev->flags |=VIRTIO_PCI_FLAG_DISABLE_LEGACY ; +object_property_set_bool (OBJECT (vdev), true,"realized" , errp); +} + +static void virtio_input_pci_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtioPCIClass *k =VIRTIO_PCI_CLASS (klass); +PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); + + k->realize = virtio_input_pci_realize; +set_bit (DEVICE_CATEGORY_INPUT , dc->categories); + + pcidev_k->class_id =PCI_CLASS_INPUT_OTHER ; +} + +static const TypeInfo virtio_input_pci_info = { + .name =TYPE_VIRTIO_INPUT_PCI , + .parent =TYPE_VIRTIO_PCI , + .instance_size =sizeof (VirtIOInputPCI), + .class_init = virtio_input_pci_class_init, + .abstract = true, +}; +/* virtio-pci-bus */ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -1931,6 +1966,7 @@ static const TypeInfo virtio_pci_bus_info = {static void virtio_pci_register_types (void ) {type_register_static (&virtio_rng_pci_info); +type_register_static (&virtio_input_pci_info);type_register_static (&virtio_pci_bus_info);type_register_static (&virtio_pci_info);#ifdef CONFIG_VIRTFS
hw/virtio/virtio-pci.h +14 -0
@@ -24,6 +24,7 @@#include "hw/virtio/virtio-balloon.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-9p.h" +#include "hw/virtio/virtio-input.h" #ifdef CONFIG_VIRTFS #include "hw/9pfs/virtio-9p.h" #endif
@@ -39,6 +40,7 @@ typedef struct VirtIOSerialPCI VirtIOSerialPCI;typedef struct VirtIONetPCI VirtIONetPCI ;typedef struct VHostSCSIPCI VHostSCSIPCI ;typedef struct VirtIORngPCI VirtIORngPCI ; +typedef struct VirtIOInputPCI VirtIOInputPCI ;/* virtio-pci-bus */
@@ -234,6 +236,18 @@ struct VirtIORngPCI {VirtIORNG vdev; }; +/* +* virtio-input-pci: This extends VirtioPCIProxy. +*/ +#define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci" +#define VIRTIO_INPUT_PCI (obj) \ + OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI) + +struct VirtIOInputPCI { +VirtIOPCIProxy parent_obj; +VirtIOInput vdev; +}; +/* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0
Signature · 1 line
1.8.3.1
PATCH 33/33 virtio-input: emulated devices [pci]
In reply to Gerd HoffmannThis patch adds virtio-pci support for the emulated virtio-input devices. Using them is as simple as adding "-device virtio-tablet-pci" to your command line. If you want add multiple devices but don't want waste a pci slot for each you can compose a multifunction device this way:
qemu -device virtio-keyboard-pci,addr=0d.0,multifunction=on \
-device virtio-tablet-pci,addr=0d.1,multifunction=on
--- hw/virtio/virtio-pci.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 13 ++++++++ 2 files changed, 97 insertions(+)
hw/virtio/virtio-pci.c +84 -0
@@ -1893,6 +1893,12 @@ static const TypeInfo virtio_rng_pci_info = {/* virtio-input-pci */ +static Property virtio_input_hid_pci_properties[] = { +DEFINE_VIRTIO_INPUT_PROPERTIES (VirtIOInputPCI, vdev.input), +DEFINE_PROP_UINT32 ("vectors" , VirtIOPCIProxy, nvectors,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void virtio_input_pci_realize (VirtIOPCIProxy *vpci_dev,Error **errp) {VirtIOInputPCI *vinput =VIRTIO_INPUT_PCI (vpci_dev);
@@ -1917,6 +1923,49 @@ static void virtio_input_pci_class_init(ObjectClass *klass, void *data) pcidev_k->class_id =PCI_CLASS_INPUT_OTHER ; } +static void virtio_input_hid_pci_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = virtio_input_hid_pci_properties; +} + +static void virtio_input_hid_kbd_pci_class_init (ObjectClass *klass,void *data) +{ +PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); + + pcidev_k->class_id =PCI_CLASS_INPUT_KEYBOARD ; +} + +static void virtio_input_hid_mouse_pci_class_init (ObjectClass *klass, +void *data) +{ +PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); + + pcidev_k->class_id =PCI_CLASS_INPUT_MOUSE ; +} + +static void virtio_keyboard_initfn (Object *obj) +{ +VirtIOInputHIDPCI *dev =VIRTIO_INPUT_HID_PCI (obj); +object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_KEYBOARD ); +object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +} + +static void virtio_mouse_initfn (Object *obj) +{ +VirtIOInputHIDPCI *dev =VIRTIO_INPUT_HID_PCI (obj); +object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_MOUSE ); +object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +} + +static void virtio_tablet_initfn (Object *obj) +{ +VirtIOInputHIDPCI *dev =VIRTIO_INPUT_HID_PCI (obj); +object_initialize (&dev->vdev,sizeof (dev->vdev),TYPE_VIRTIO_TABLET ); +object_property_add_child (obj,"virtio-backend" ,OBJECT (&dev->vdev),NULL ); +} +static const TypeInfo virtio_input_pci_info = { .name =TYPE_VIRTIO_INPUT_PCI , .parent =TYPE_VIRTIO_PCI ,
@@ -1925,6 +1974,37 @@ static const TypeInfo virtio_input_pci_info = { .abstract = true, }; +static const TypeInfo virtio_input_hid_pci_info = { + .name =TYPE_VIRTIO_INPUT_HID_PCI , + .parent =TYPE_VIRTIO_INPUT_PCI , + .instance_size =sizeof (VirtIOInputHIDPCI), + .class_init = virtio_input_hid_pci_class_init, + .abstract = true, +}; + +static const TypeInfo virtio_keyboard_pci_info = { + .name =TYPE_VIRTIO_KEYBOARD_PCI , + .parent =TYPE_VIRTIO_INPUT_HID_PCI , + .class_init = virtio_input_hid_kbd_pci_class_init, + .instance_size =sizeof (VirtIOInputHIDPCI), + .instance_init = virtio_keyboard_initfn, +}; + +static const TypeInfo virtio_mouse_pci_info = { + .name =TYPE_VIRTIO_MOUSE_PCI , + .parent =TYPE_VIRTIO_INPUT_HID_PCI , + .class_init = virtio_input_hid_mouse_pci_class_init, + .instance_size =sizeof (VirtIOInputHIDPCI), + .instance_init = virtio_mouse_initfn, +}; + +static const TypeInfo virtio_tablet_pci_info = { + .name =TYPE_VIRTIO_TABLET_PCI , + .parent =TYPE_VIRTIO_INPUT_HID_PCI , + .instance_size =sizeof (VirtIOInputHIDPCI), + .instance_init = virtio_tablet_initfn, +}; +/* virtio-pci-bus */ static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -1967,6 +2047,10 @@ static void virtio_pci_register_types(void) {type_register_static (&virtio_rng_pci_info);type_register_static (&virtio_input_pci_info); +type_register_static (&virtio_input_hid_pci_info); +type_register_static (&virtio_keyboard_pci_info); +type_register_static (&virtio_mouse_pci_info); +type_register_static (&virtio_tablet_pci_info);type_register_static (&virtio_pci_bus_info);type_register_static (&virtio_pci_info);#ifdef CONFIG_VIRTFS
hw/virtio/virtio-pci.h +13 -0
@@ -41,6 +41,7 @@ typedef struct VirtIONetPCI VirtIONetPCI;typedef struct VHostSCSIPCI VHostSCSIPCI ;typedef struct VirtIORngPCI VirtIORngPCI ;typedef struct VirtIOInputPCI VirtIOInputPCI ; +typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI ;/* virtio-pci-bus */
@@ -248,6 +249,18 @@ struct VirtIOInputPCI {VirtIOInput vdev; }; +#define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci" +#define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci" +#define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci" +#define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci" +#define VIRTIO_INPUT_HID_PCI (obj) \ + OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI) + +struct VirtIOInputHIDPCI { +VirtIOPCIProxy parent_obj; +VirtIOInputHID vdev; +}; +/* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0
Signature · 1 line
1.8.3.1
Quoted 7 lines · Gerd Hoffmann
Hi,
Here comes the virtio 1.0 patch series, rebased to latest master. Patches 1-23 are based on the old branch by cornelia & mst. Patches 24-30 are virtio-pci bits on top of that. Patches 31-33 add virtio-pci support for the virtio-input devices.
Quoted 5 lines
Light testing only so far, posting early nevertheless to parallelize testing efforts and speedup things a bit.
cheers,
Gerd
Excellent, thanks!
Here's an incomplete todo for spec compliance: note that it does not have to block this patchset:
- complete other devices besides net, balloon need to disable a bunch of features
that 1.0 has deprecated
- prevent DMA and interrupts until DRIVER_OK is set (but only when using modern interface) this interacts in a complex way with pci bus master hacks
- go over devices, make sure they don't rely on io vec layout
Quoted 64 lines
Cornelia Huck (10):
virtio: endianness checks for virtio 1.0 devices
virtio: allow virtio-1 queue layout
dataplane: allow virtio-1 devices
virtio: disallow late feature changes for virtio-1
virtio: allow to fail setting status
virtio-net: no writeable mac for virtio-1
virtio-net: support longer header
virtio-net: enable virtio 1.0
vhost: 64 bit features
virtio-balloon: switch tovirtio_add_featureGerd Hoffmann (15):
virtio: 64bit features fixups.
virtio-pci: add flags to enable/disable legacy/modern
virtio-pci: makeQEMU_VIRTIO_PCI_QUEUE_MEM_MULTsmaller
virtio-pci: change & document virtio pci bar layout.
virtio-pci: make modern bar 64bit + prefetchable
virtio-pci: add struct VirtIOPCIRegion for virtio-1 regions
virtio-pci: addvirtio_pci_modern_regions_init()
virtio-pci: addvirtio_pci_modern_region_map()
virtio-pci: movevirtio_pci_add_mem_capcall to
virtio_pci_modern_region_map
virtio-pci: move cap type to VirtIOPCIRegion
virtio-pci: drop identicalvirtio_pci_cap
virtio-pci: fill VirtIOPCIRegions early.
pci: add PCI_CLASS_INPUT_*
virtio-input: core code & base class [pci]
virtio-input: emulated devices [pci]Jason Wang (1):
virtio-pci: correctly set host notifiers for modern barMichael S. Tsirkin (7):
vhost_net: addversion_1feature
linux-headers: addvirtio_pci
virtio-pci: initial virtio 1.0 support
virtio: generation counter support
virtio: add modern config accessors
virtio-pci: switch to modern accessors for 1.0
virtio_balloon: header updatehw/net/vhost_net.c | 14 +- hw/net/virtio-net.c | 25 +- hw/s390x/virtio-ccw.c | 20 +- hw/virtio/dataplane/vring.c | 47 +-- hw/virtio/vhost.c | 14 +- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-mmio.c | 3 + hw/virtio/virtio-pci.c | 612 +++++++++++++++++++++++++++++++++++-- hw/virtio/virtio-pci.h | 59 ++++ hw/virtio/virtio.c | 198 ++++++++++-- include/hw/pci/pci_ids.h | 7 + include/hw/virtio/vhost.h | 6 +- include/hw/virtio/virtio-access.h | 4 + include/hw/virtio/virtio-balloon.h | 6 + include/hw/virtio/virtio.h | 34 ++- include/net/vhost_net.h | 4 +- linux-headers/linux/virtio_pci.h | 192 ++++++++++++ 17 files changed, 1140 insertions(+), 107 deletions(-) create mode 100644 linux-headers/linux/virtio_pci.hSignature · 1 line
1.8.3.1
Hi,
Quoted 5 lines
Here's an incomplete todo for spec compliance: note that it does not have to block this patchset:
- complete other devices besides net, balloon need to disable a bunch of features
that 1.0 has deprecated
So, what is the plan here?
For legacy devices we keep the features, for backward compatibility reasons.
For modern devices we drop the deprecated features.
What about transitional? Drop them too?
Implementation-wise we probably want a mask in VirtIODevice ...
cheers,
Gerd
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
Here's an incomplete todo for spec compliance: note that it does not have to block this patchset:
- complete other devices besides net, balloon need to disable a bunch of features
that 1.0 has deprecated
Quoted 8 lines
So, what is the plan here?
For legacy devices we keep the features, for backward compatibility reasons.
For modern devices we drop the deprecated features.
What about transitional? Drop them too?
Yes.
Quoted 1 line
Implementation-wise we probably want a mask in VirtIODevice ...
Exactly.
Quoted 3 lines
cheers,
Gerd
Hi,
Quoted 2 lines
Light testing only so far, posting early nevertheless to parallelize testing efforts and speedup things a bit.
Upgraded fedora guest from 21 to 22, running @ virtio-1.0 virtio-net and virtio-scsi devices. Ran smooth ...
cheers,
Gerd
Quoted 11 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Light testing only so far, posting early nevertheless to parallelize testing efforts and speedup things a bit.
Upgraded fedora guest from 21 to 22, running @ virtio-1.0 virtio-net and virtio-scsi devices. Ran smooth ...
cheers,
Gerd
Let's merge it, will help more people test it.
We also need to update pxe and blk/scsi ROMs.
Quoted 7 lines · Gerd Hoffmann
Hi,
Here comes the virtio 1.0 patch series, rebased to latest master. Patches 1-23 are based on the old branch by cornelia & mst. Patches 24-30 are virtio-pci bits on top of that. Patches 31-33 add virtio-pci support for the virtio-input devices.
Quoted 5 lines
Light testing only so far, posting early nevertheless to parallelize testing efforts and speedup things a bit.
cheers,
Gerd
So I'm put this in my tree for now.
Let's see how things fare from there.
Quoted 64 lines
Cornelia Huck (10):
virtio: endianness checks for virtio 1.0 devices
virtio: allow virtio-1 queue layout
dataplane: allow virtio-1 devices
virtio: disallow late feature changes for virtio-1
virtio: allow to fail setting status
virtio-net: no writeable mac for virtio-1
virtio-net: support longer header
virtio-net: enable virtio 1.0
vhost: 64 bit features
virtio-balloon: switch tovirtio_add_featureGerd Hoffmann (15):
virtio: 64bit features fixups.
virtio-pci: add flags to enable/disable legacy/modern
virtio-pci: makeQEMU_VIRTIO_PCI_QUEUE_MEM_MULTsmaller
virtio-pci: change & document virtio pci bar layout.
virtio-pci: make modern bar 64bit + prefetchable
virtio-pci: add struct VirtIOPCIRegion for virtio-1 regions
virtio-pci: addvirtio_pci_modern_regions_init()
virtio-pci: addvirtio_pci_modern_region_map()
virtio-pci: movevirtio_pci_add_mem_capcall to
virtio_pci_modern_region_map
virtio-pci: move cap type to VirtIOPCIRegion
virtio-pci: drop identicalvirtio_pci_cap
virtio-pci: fill VirtIOPCIRegions early.
pci: add PCI_CLASS_INPUT_*
virtio-input: core code & base class [pci]
virtio-input: emulated devices [pci]Jason Wang (1):
virtio-pci: correctly set host notifiers for modern barMichael S. Tsirkin (7):
vhost_net: addversion_1feature
linux-headers: addvirtio_pci
virtio-pci: initial virtio 1.0 support
virtio: generation counter support
virtio: add modern config accessors
virtio-pci: switch to modern accessors for 1.0
virtio_balloon: header updatehw/net/vhost_net.c | 14 +- hw/net/virtio-net.c | 25 +- hw/s390x/virtio-ccw.c | 20 +- hw/virtio/dataplane/vring.c | 47 +-- hw/virtio/vhost.c | 14 +- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-mmio.c | 3 + hw/virtio/virtio-pci.c | 612 +++++++++++++++++++++++++++++++++++-- hw/virtio/virtio-pci.h | 59 ++++ hw/virtio/virtio.c | 198 ++++++++++-- include/hw/pci/pci_ids.h | 7 + include/hw/virtio/vhost.h | 6 +- include/hw/virtio/virtio-access.h | 4 + include/hw/virtio/virtio-balloon.h | 6 + include/hw/virtio/virtio.h | 34 ++- include/net/vhost_net.h | 4 +- linux-headers/linux/virtio_pci.h | 192 ++++++++++++ 17 files changed, 1140 insertions(+), 107 deletions(-) create mode 100644 linux-headers/linux/virtio_pci.hSignature · 1 line
1.8.3.1