virtio,pci: fixes and updates
The following changes since commit d1eb8f2acba579830cf3798c3c15ce51be852c56:
fpu: add mechanism to check for invalid long double formats (2016-09-15 12:43:18 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
for you to fetch changes up to a5a43875b352810d29dc27e7b0fb602eb7ef2d31:
MAINTAINERS: add virtio-* tests (2016-09-15 23:37:16 +0300)
----------------------------------------------------------------
virtio,pci: fixes and updates
AMD IOMMU emulation
virtio feature negotiation rework
----------------------------------------------------------------
David Kiarie (4):
hw/pci: Prepare for AMD IOMMU hw/i386/trace-events: Add AMD IOMMU trace events hw/i386: Introduce AMD IOMMU
hw/i386: AMD IOMMU IVRS table
Greg Kurz (1):
MAINTAINERS: add virtio-* tests
Maxime Coquelin (1):
virtio-bus: Plug devices after features are negotiated
hw/i386/amd_iommu.h | 289 +++++++++ hw/virtio/virtio-pci.h | 5 + include/hw/acpi/aml-build.h | 1 + include/hw/i386/x86-iommu.h | 12 + include/hw/pci/pci.h | 4 +- include/hw/virtio/virtio-bus.h | 10 +- hw/acpi/aml-build.c | 2 +- hw/i386/acpi-build.c | 76 ++- hw/i386/amd_iommu.c | 1383 ++++++++++++++++++++++++++++++++++++++++ hw/i386/intel_iommu.c | 1 + hw/i386/x86-iommu.c | 6 + hw/s390x/virtio-ccw.c | 30 +- hw/virtio/virtio-bus.c | 9 +- hw/virtio/virtio-pci.c | 36 +- MAINTAINERS | 7 + hw/i386/Makefile.objs | 1 + hw/i386/trace-events | 29 + 17 files changed, 1862 insertions(+), 39 deletions(-) create mode 100644 hw/i386/amd_iommu.h create mode 100644 hw/i386/amd_iommu.c
[Qemu-devel] [PULL v3 2/6] hw/pci: Prepare for AMD IOMMU
From: David Kiarie <[email protected]>
Introduce PCI macros from for use by AMD IOMMU
--- include/hw/pci/pci.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/pci/pci.h +3 -1
@@ -11,11 +11,13 @@#include "hw/pci/pcie.h" /* PCI bus */ -#define PCI_DEVFN (slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) +#define PCI_BUS_NUM (x) (((x) >> 8) & 0xff)#define PCI_SLOT (devfn) (((devfn) >> 3) & 0x1f)#define PCI_FUNC (devfn) ((devfn) & 0x07)#define PCI_BUILD_BDF (bus, devfn) ((bus << 8) | (devfn)) +#define PCI_BUS_MAX 256 +#define PCI_DEVFN_MAX 256#define PCI_SLOT_MAX 32#define PCI_FUNC_MAX 8
Signature · 1 line
MST
[Qemu-devel] [PULL v3 1/6] virtio-bus: Plug devices after features are negotiated
In reply to Michael S. TsirkinFrom: Maxime Coquelin <[email protected]>
Currently, devices are plugged before features are negotiated. If the backend doesn't support VIRTIO_F_VERSION_1, the transport needs to rewind some settings.
This is the case for CCW, for which a post_plugged callback had been introduced, where max_rev field is just updated if VIRTIO_F_VERSION_1 is not supported by the backend. For PCI, implementing post_plugged would be much more complicated, so it needs to know whether the backend supports VIRTIO_F_VERSION_1 at plug time.
Currently, nothing is done for PCI. Modern capabilities get exposed to the guest even if VIRTIO_F_VERSION_1 is not supported by the backend, which confuses the guest.
This patch replaces existing post_plugged solution with an approach that fits with both transports.
Features negotiation is performed before ->device_plugged() call. A pre_plugged callback is introduced so that the transports can set their supported features.
--- hw/virtio/virtio-pci.h | 5 +++++ include/hw/virtio/virtio-bus.h | 10 +++++----- hw/s390x/virtio-ccw.c | 30 +++++++++++++++--------------- hw/virtio/virtio-bus.c | 9 +++++---- hw/virtio/virtio-pci.c | 36 ++++++++++++++++++++++++++++++++---- 5 files changed, 62 insertions(+), 28 deletions(-)
hw/virtio/virtio-pci.h +5 -0
@@ -181,6 +181,11 @@ static inline void virtio_pci_force_virtio_1(VirtIOPCIProxy *proxy) proxy->disable_legacy =ON_OFF_AUTO_ON ; } +static inline void virtio_pci_disable_modern (VirtIOPCIProxy *proxy) +{ + proxy->disable_modern = true; +} +/* * virtio-scsi-pci: This extends VirtioPCIProxy. */
include/hw/virtio/virtio-bus.h +5 -5
@@ -54,16 +54,16 @@ typedef struct VirtioBusClass {int (*set_guest_notifiers)(DeviceState *d,int nvqs,bool assign);void (*vmstate_change)(DeviceState *d,bool running);/* +* Expose the features the transport layer supports before +* the negotiation takes place. +*/ +void (*pre_plugged)(DeviceState *d,Error **errp); +/* * transport independent init function. * This is called by virtio-bus just after the device is plugged. */ void (*device_plugged)(DeviceState *d,Error **errp);/* -* Re-evaluate setup after feature bits have been validated -* by the device backend. -*/ -void (*post_plugged)(DeviceState *d,Error **errp); -/* * transport independent exit function. * This is called by virtio-bus just before the device is unplugged. */
hw/s390x/virtio-ccw.c +15 -15
@@ -1261,6 +1261,16 @@ static int virtio_ccw_load_config(DeviceState *d, QEMUFile *f)return 0 ; } +static void virtio_ccw_pre_plugged (DeviceState *d,Error **errp) +{ +VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); +VirtIODevice *vdev =virtio_bus_get_device (&dev->bus); + +if (dev->max_rev >=1 ) { +virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 ); + } +} +/* This is called by virtio-bus just after the device is plugged. */ static void virtio_ccw_device_plugged (DeviceState *d,Error **errp) {
@@ -1270,6 +1280,10 @@ static void virtio_ccw_device_plugged(DeviceState *d, Error **errp)SubchDev *sch = ccw_dev->sch;int n =virtio_get_num_queues (vdev); +if (!virtio_has_feature (vdev->host_features,VIRTIO_F_VERSION_1 )) { + dev->max_rev =0 ; + } +if (virtio_get_num_queues (vdev) >VIRTIO_CCW_QUEUE_MAX ) { error_setg(errp, "The number of virtqueues %d " "exceeds ccw limit %d", n,
@@ -1283,25 +1297,11 @@ static void virtio_ccw_device_plugged(DeviceState *d, Error **errp) sch->id.cu_model =virtio_bus_get_vdev_id (&dev->bus); -if (dev->max_rev >=1 ) { -virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 ); - }css_generate_sch_crws (sch->cssid, sch->ssid, sch->schid, d->hotplugged,1 ); } -static void virtio_ccw_post_plugged (DeviceState *d,Error **errp) -{ -VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); -VirtIODevice *vdev =virtio_bus_get_device (&dev->bus); - -if (!virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 )) { -/* A backend didn't support modern virtio. */ - dev->max_rev =0 ; - } -} -static void virtio_ccw_device_unplugged (DeviceState *d) {VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d);
@@ -1593,8 +1593,8 @@ static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data) k->load_queue = virtio_ccw_load_queue; k->save_config = virtio_ccw_save_config; k->load_config = virtio_ccw_load_config; + k->pre_plugged = virtio_ccw_pre_plugged; k->device_plugged = virtio_ccw_device_plugged; - k->post_plugged = virtio_ccw_post_plugged; k->device_unplugged = virtio_ccw_device_unplugged; k->ioeventfd_started = virtio_ccw_ioeventfd_started; k->ioeventfd_set_started = virtio_ccw_ioeventfd_set_started;
hw/virtio/virtio-bus.c +5 -4
@@ -49,16 +49,17 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)DPRINTF ("%s: plug device.\n" , qbus->name); -if (klass->device_plugged !=NULL ) { - klass->device_plugged (qbus->parent, errp); +if (klass->pre_plugged !=NULL ) { + klass->pre_plugged (qbus->parent, errp); }/* Get the features of the plugged device. */ assert (vdc->get_features !=NULL ); vdev->host_features = vdc->get_features (vdev, vdev->host_features, errp); -if (klass->post_plugged !=NULL ) { - klass->post_plugged (qbus->parent, errp); + +if (klass->device_plugged !=NULL ) { + klass->device_plugged (qbus->parent, errp); } }
hw/virtio/virtio-pci.c +32 -4
@@ -1576,18 +1576,48 @@ static void virtio_pci_modern_io_region_unmap(VirtIOPCIProxy *proxy, ®ion->mr); } +static void virtio_pci_pre_plugged (DeviceState *d,Error **errp) +{ +VirtIOPCIProxy *proxy =VIRTIO_PCI (d); +VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); + +if (virtio_pci_modern (proxy)) { +virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 ); + } + +virtio_add_feature (&vdev->host_features,VIRTIO_F_BAD_FEATURE ); +} +/* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged (DeviceState *d,Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (d);VirtioBusState *bus = &proxy->bus;bool legacy =virtio_pci_legacy (proxy); -bool modern =virtio_pci_modern (proxy); +bool modern;bool modern_pio = proxy->flags &VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY ;uint8_t *config;uint32_t size;VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); +/* +* Virtio capabilities present without +* VIRTIO_F_VERSION_1 confuses guests +*/ +if (!virtio_has_feature (vdev->host_features,VIRTIO_F_VERSION_1 )) { +virtio_pci_disable_modern (proxy); + +if (!legacy) { +error_setg (errp,"Device doesn't support modern mode, and legacy" +" mode is disabled" ); +error_append_hint (errp,"Set disable-legacy to off\n" ); + +return ; + } + } + + modern =virtio_pci_modern (proxy); + config = proxy->pci_dev.config;if (proxy->class_code) {pci_config_set_class (config, proxy->class_code);
@@ -1629,7 +1659,6 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)struct virtio_pci_cfg_cap *cfg_mask; -virtio_add_feature (&vdev->host_features,VIRTIO_F_VERSION_1 );virtio_pci_modern_regions_init (proxy);virtio_pci_modern_mem_region_map (proxy, &proxy->common, &cap);
@@ -1694,8 +1723,6 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ; } - -virtio_add_feature (&vdev->host_features,VIRTIO_F_BAD_FEATURE ); }static void virtio_pci_device_unplugged (DeviceState *d)
@@ -2508,6 +2535,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) k->query_guest_notifiers = virtio_pci_query_guest_notifiers; k->set_guest_notifiers = virtio_pci_set_guest_notifiers; k->vmstate_change = virtio_pci_vmstate_change; + k->pre_plugged = virtio_pci_pre_plugged; k->device_plugged = virtio_pci_device_plugged; k->device_unplugged = virtio_pci_device_unplugged; k->query_nvectors = virtio_pci_query_nvectors;
Signature · 1 line
MST
[Qemu-devel] [PULL v3 3/6] hw/i386/trace-events: Add AMD IOMMU trace events
In reply to Michael S. TsirkinFrom: David Kiarie <[email protected]>
--- hw/i386/trace-events | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
hw/i386/trace-events +29 -0
@@ -13,3 +13,32 @@ mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64 # hw/i386/x86-iommu.c x86_iommu_iec_notify(bool global, uint32_t index, uint32_t mask) "Notify IEC invalidation: global=%d index=%" PRIu32 " mask=%" PRIu32 + +# hw/i386/amd_iommu.c +amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to write at addr 0x%"PRIx64 " + offset 0x%"PRIx32 +amdvi_cache_update(uint16_t domid, uint32_t bus, uint32_t slot, uint32_t func, uint64_t gpa, uint64_t txaddr) " update iotlb domid 0x%"PRIx16" devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64 +amdvi_completion_wait_fail(uint64_t addr) "error: fail to write at address 0x%"PRIx64 +amdvi_mmio_write(const char *reg, uint64_t addr, unsigned size, uint64_t val, unsigned long offset) "%s write addr 0x%"PRIx64 ", size %d, val 0x%"PRIx64 ", offset 0x%0lx" +amdvi_mmio_read(const char *reg, uint64_t addr, unsigned size, uint64_t offset) "%s read addr 0x%"PRIx64", size %d offset 0x%"PRIx64 +amdvi_command_error(uint64_t status) "error: Executing commands with command buffer disabled 0x%"PRIx64 +amdvi_command_read_fail(uint64_t addr, uint32_t head) "error: fail to access memory at 0x%"PRIx64" + 0x%"PRIu32 +amdvi_command_exec(uint32_t head, uint32_t tail, uint64_t buf) "command buffer head at 0x%"PRIx32 " command buffer tail at 0x%"PRIx32" command buffer base at 0x%" PRIx64 +amdvi_unhandled_command(uint8_t type) "unhandled command %d" +amdvi_intr_inval(void) "Interrupt table invalidated" +amdvi_iotlb_inval(void) "IOTLB pages invalidated" +amdvi_prefetch_pages(void) "Pre-fetch of AMD-Vi pages requested" +amdvi_pages_inval(uint16_t domid) "AMD-Vi pages for domain 0x%"PRIx16 " invalidated" +amdvi_all_inval(void) "Invalidation of all AMD-Vi cache requested " +amdvi_ppr_exec(void) "Execution of PPR queue requested " +amdvi_devtab_inval(uint16_t bus, uint16_t slot, uint16_t func) "device table entry for devid: %02x:%02x.%x invalidated" +amdvi_completion_wait(uint64_t addr, uint64_t data) "completion wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64 +amdvi_control_status(uint64_t val) "MMIO_STATUS state 0x%"PRIx64 +amdvi_iotlb_reset(void) "IOTLB exceed size limit - reset " +amdvi_completion_wait_exec(uint64_t addr, uint64_t data) "completion wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64 +amdvi_dte_get_fail(uint64_t addr, uint32_t offset) "error: failed to access Device Entry devtab 0x%"PRIx64" offset 0x%"PRIx32 +amdvi_invalid_dte(uint64_t addr) "PTE entry at 0x%"PRIx64" is invalid " +amdvi_get_pte_hwerror(uint64_t addr) "hardware error eccessing PTE at addr 0x%"PRIx64 +amdvi_mode_invalid(unsigned level, uint64_t addr)"error: translation level 0x%0x translating addr 0x%"PRIx64 +amdvi_page_fault(uint64_t addr) "error: page fault accessing guest physical address 0x%"PRIx64 +amdvi_iotlb_hit(uint16_t bus, uint16_t slot, uint16_t func, uint64_t addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64 +amdvi_translation_result(uint16_t bus, uint16_t slot, uint16_t func, uint64_t addr, uint64_t txaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64
Signature · 1 line
MST
[Qemu-devel] [PULL v3 5/6] hw/i386: AMD IOMMU IVRS table
In reply to Michael S. TsirkinFrom: David Kiarie <[email protected]>
Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU.
--- include/hw/acpi/aml-build.h | 1 + include/hw/i386/x86-iommu.h | 12 +++++++ hw/acpi/aml-build.c | 2 +- hw/i386/acpi-build.c | 76 +++++++++++++++++++++++++++++++++++++++------ hw/i386/amd_iommu.c | 2 ++ hw/i386/intel_iommu.c | 1 + hw/i386/x86-iommu.c | 6 ++++ 7 files changed, 90 insertions(+), 10 deletions(-)
include/hw/acpi/aml-build.h +1 -0
@@ -367,6 +367,7 @@ Aml *aml_sizeof(Aml *arg);Aml *aml_concatenate (Aml *source1,Aml *source2,Aml *target);Aml *aml_object_type (Aml *object); +void build_append_int_noprefix (GArray *table,uint64_t value,int size); void build_header(BIOSLinker *linker, GArray *table_data, AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
include/hw/i386/x86-iommu.h +12 -0
@@ -37,6 +37,12 @@typedef struct X86IOMMUState X86IOMMUState ;typedef struct X86IOMMUClass X86IOMMUClass ; +typedef enum IommuType { +TYPE_INTEL , +TYPE_AMD , +TYPE_NONE +}IommuType ; +struct X86IOMMUClass {SysBusDeviceClass parent;/* Intel/AMD specific realize() hook */
@@ -67,6 +73,7 @@ typedef struct IEC_Notifier IEC_Notifier;struct X86IOMMUState {SysBusDevice busdev;bool intr_supported;/* Whether vIOMMU supports IR */ +IommuType type;/* IOMMU type - AMD/Intel */ QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */ };
@@ -76,6 +83,11 @@ struct X86IOMMUState {*/ X86IOMMUState *x86_iommu_get_default (void ); +/* +* x86_iommu_get_type - get IOMMU type +*/ +IommuType x86_iommu_get_type (void ); +/** * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry * Cache) notifiers
hw/acpi/aml-build.c +1 -1
@@ -226,7 +226,7 @@ static void build_extop_package(GArray *package, uint8_t op)build_prepend_byte (package,0x5B );/* ExtOpPrefix */ } -static void build_append_int_noprefix (GArray *table,uint64_t value,int size) +void build_append_int_noprefix (GArray *table,uint64_t value,int size) {int i;
hw/i386/acpi-build.c +67 -9
100 lines not on this page · raw message
hw/i386/amd_iommu.c +2 -0
@@ -1311,11 +1311,13 @@ static void amdvi_reset(DeviceState *dev)static void amdvi_realize (DeviceState *dev,Error **err) {AMDVIState *s =AMD_IOMMU_DEVICE (dev); +X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);PCIBus *bus =PC_MACHINE (qdev_get_machine ())->bus; s->iotlb =g_hash_table_new_full (amdvi_uint64_hash, amdvi_uint64_equal, g_free, g_free);/* This device should take care of IOMMU PCI properties */ + x86_iommu->type =TYPE_AMD ;qdev_set_parent_bus (DEVICE (&s->pci), &bus->qbus);object_property_set_bool (OBJECT (&s->pci), true,"realized" , err); s->capab_offset = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,
hw/i386/intel_iommu.c +1 -0
@@ -2453,6 +2453,7 @@ static void vtd_realize(DeviceState *dev, Error **errp)X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);VTD_DPRINTF (GENERAL ,"" ); + x86_iommu->type =TYPE_INTEL ;memset (s->vtd_as_by_bus_num,0 ,sizeof (s->vtd_as_by_bus_num));memory_region_init_io (&s->csrmem,OBJECT (s), &vtd_mem_ops, s,"intel_iommu" ,DMAR_REG_SIZE );
hw/i386/x86-iommu.c +6 -0
@@ -71,6 +71,11 @@ X86IOMMUState *x86_iommu_get_default(void)return x86_iommu_default; } +IommuType x86_iommu_get_type (void ) +{ +return x86_iommu_default->type; +} +static void x86_iommu_realize (DeviceState *dev,Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (dev);
@@ -79,6 +84,7 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)if (x86_class->realize) { x86_class->realize (dev, errp); } +x86_iommu_set_default (X86_IOMMU_DEVICE (dev)); }
Signature · 1 line
MST
[Qemu-devel] [PULL v3 6/6] MAINTAINERS: add virtio-* tests
In reply to Michael S. TsirkinFrom: Greg Kurz <[email protected]>
Except virtio-9p, all virtio-* tests are orphan. This patch tries to fix it, according to the following logic:
- when the related subsystem has its own section in MAINTAINERS, the test is added there
- otherwise it is added to the "parent" section (aka. SCSI, Network devices, virtio)
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -830,6 +830,7 @@ Network devices M: Jason Wang <[email protected]> S: Odd Fixes F: hw/net/ +F: tests/virtio-net-test.c T: git git://github.com/jasowang/qemu.git net SCSI
@@ -837,6 +838,7 @@ M: Paolo Bonzini <[email protected]> S: Supported F: include/hw/scsi/* F: hw/scsi/* +F: tests/virtio-scsi-test.c T: git git://github.com/bonzini/qemu.git scsi-next LSI53C895A
@@ -889,6 +891,7 @@ S: Supported F: hw/*/virtio* F: net/vhost-user.c F: include/hw/virtio/ +F: tests/virtio-balloon-test.c virtio-9p M: Aneesh Kumar K.V <[email protected]>
@@ -907,6 +910,7 @@ S: Supported F: hw/block/virtio-blk.c F: hw/block/dataplane/* F: hw/virtio/dataplane/* +F: tests/virtio-blk-test.c T: git git://github.com/stefanha/qemu.git block virtio-ccw
@@ -929,6 +933,8 @@ S: Supported F: hw/char/virtio-serial-bus.c F: hw/char/virtio-console.c F: include/hw/virtio/virtio-serial.h +F: tests/virtio-console-test.c +F: tests/virtio-serial-test.c virtio-rng M: Amit Shah <[email protected]>
@@ -937,6 +943,7 @@ F: hw/virtio/virtio-rng.c F: include/hw/virtio/virtio-rng.h F: include/sysemu/rng*.h F: backends/rng*.c +F: tests/virtio-rng-test.c nvme M: Keith Busch <[email protected]>
Signature · 1 line
MST
[Qemu-devel] [PULL v3 4/6] hw/i386: Introduce AMD IOMMU
In reply to Michael S. TsirkinFrom: David Kiarie <[email protected]>
Add AMD IOMMU emulaton to Qemu in addition to Intel IOMMU. The IOMMU does basic translation, error checking and has a minimal IOTLB implementation. This IOMMU bypassed the need for target aborts by responding with IOMMU_NONE access rights and exempts the region 0xfee00000-0xfeefffff from translation as it is the q35 interrupt region.
We advertise features that are not yet implemented to please the Linux IOMMU driver.
IOTLB aims at implementing commands on real IOMMUs which is essential for debugging and may not offer any performance benefits
--- hw/i386/amd_iommu.h | 289 +++++++++++ hw/i386/amd_iommu.c | 1381 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/Makefile.objs | 1 + 3 files changed, 1671 insertions(+) create mode 100644 hw/i386/amd_iommu.h create mode 100644 hw/i386/amd_iommu.c
hw/i386/amd_iommu.h new file +289 -0
@@ -0,0 +1,289 @@ +/* +* QEMU emulation of an AMD IOMMU (AMD-Vi) +* +* Copyright (C) 2011 Eduard - Gabriel Munteanu +* Copyright (C) 2015 David Kiarie, <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef AMD_IOMMU_H_ +#define AMD_IOMMU_H_ + +#include "hw/hw.h" +#include "hw/pci/pci.h" +#include "hw/pci/msi.h" +#include "hw/sysbus.h" +#include "sysemu/dma.h" +#include "hw/i386/pc.h" +#include "hw/pci/pci_bus.h" +#include "hw/i386/x86-iommu.h" + +/* Capability registers */ +#define AMDVI_CAPAB_BAR_LOW 0x04 +#define AMDVI_CAPAB_BAR_HIGH 0x08 +#define AMDVI_CAPAB_RANGE 0x0C +#define AMDVI_CAPAB_MISC 0x10 + +#define AMDVI_CAPAB_SIZE 0x18 +#define AMDVI_CAPAB_REG_SIZE 0x04 + +/* Capability header data */ +#define AMDVI_CAPAB_ID_SEC 0xf +#define AMDVI_CAPAB_FLAT_EXT (1 << 28) +#define AMDVI_CAPAB_EFR_SUP (1 << 27) +#define AMDVI_CAPAB_FLAG_NPCACHE (1 << 26) +#define AMDVI_CAPAB_FLAG_HTTUNNEL (1 << 25) +#define AMDVI_CAPAB_FLAG_IOTLBSUP (1 << 24) +#define AMDVI_CAPAB_INIT_TYPE (3 << 16) + +/* No. of used MMIO registers */ +#define AMDVI_MMIO_REGS_HIGH 8 +#define AMDVI_MMIO_REGS_LOW 7 + +/* MMIO registers */ +#define AMDVI_MMIO_DEVICE_TABLE 0x0000 +#define AMDVI_MMIO_COMMAND_BASE 0x0008 +#define AMDVI_MMIO_EVENT_BASE 0x0010 +#define AMDVI_MMIO_CONTROL 0x0018 +#define AMDVI_MMIO_EXCL_BASE 0x0020 +#define AMDVI_MMIO_EXCL_LIMIT 0x0028 +#define AMDVI_MMIO_EXT_FEATURES 0x0030 +#define AMDVI_MMIO_COMMAND_HEAD 0x2000 +#define AMDVI_MMIO_COMMAND_TAIL 0x2008 +#define AMDVI_MMIO_EVENT_HEAD 0x2010 +#define AMDVI_MMIO_EVENT_TAIL 0x2018 +#define AMDVI_MMIO_STATUS 0x2020 +#define AMDVI_MMIO_PPR_BASE 0x0038 +#define AMDVI_MMIO_PPR_HEAD 0x2030 +#define AMDVI_MMIO_PPR_TAIL 0x2038 + +#define AMDVI_MMIO_SIZE 0x4000 + +#define AMDVI_MMIO_DEVTAB_SIZE_MASK ((1ULL << 12) - 1) +#define AMDVI_MMIO_DEVTAB_BASE_MASK (((1ULL << 52) - 1) & ~ \ + AMDVI_MMIO_DEVTAB_SIZE_MASK) +#define AMDVI_MMIO_DEVTAB_ENTRY_SIZE 32 +#define AMDVI_MMIO_DEVTAB_SIZE_UNIT 4096 + +/* some of this are similar but just for readability */ +#define AMDVI_MMIO_CMDBUF_SIZE_BYTE (AMDVI_MMIO_COMMAND_BASE + 7) +#define AMDVI_MMIO_CMDBUF_SIZE_MASK 0x0f +#define AMDVI_MMIO_CMDBUF_BASE_MASK AMDVI_MMIO_DEVTAB_BASE_MASK +#define AMDVI_MMIO_CMDBUF_HEAD_MASK (((1ULL << 19) - 1) & ~0x0f) +#define AMDVI_MMIO_CMDBUF_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK + +#define AMDVI_MMIO_EVTLOG_SIZE_BYTE (AMDVI_MMIO_EVENT_BASE + 7) +#define AMDVI_MMIO_EVTLOG_SIZE_MASK AMDVI_MMIO_CMDBUF_SIZE_MASK +#define AMDVI_MMIO_EVTLOG_BASE_MASK AMDVI_MMIO_CMDBUF_BASE_MASK +#define AMDVI_MMIO_EVTLOG_HEAD_MASK (((1ULL << 19) - 1) & ~0x0f) +#define AMDVI_MMIO_EVTLOG_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK + +#define AMDVI_MMIO_PPRLOG_SIZE_BYTE (AMDVI_MMIO_EVENT_BASE + 7) +#define AMDVI_MMIO_PPRLOG_HEAD_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK +#define AMDVI_MMIO_PPRLOG_TAIL_MASK AMDVI_MMIO_EVTLOG_HEAD_MASK +#define AMDVI_MMIO_PPRLOG_BASE_MASK AMDVI_MMIO_EVTLOG_BASE_MASK +#define AMDVI_MMIO_PPRLOG_SIZE_MASK AMDVI_MMIO_EVTLOG_SIZE_MASK + +#define AMDVI_MMIO_EXCL_ENABLED_MASK (1ULL << 0) +#define AMDVI_MMIO_EXCL_ALLOW_MASK (1ULL << 1) +#define AMDVI_MMIO_EXCL_LIMIT_MASK AMDVI_MMIO_DEVTAB_BASE_MASK +#define AMDVI_MMIO_EXCL_LIMIT_LOW 0xfff + +/* mmio control register flags */ +#define AMDVI_MMIO_CONTROL_AMDVIEN (1ULL << 0) +#define AMDVI_MMIO_CONTROL_HTTUNEN (1ULL << 1) +#define AMDVI_MMIO_CONTROL_EVENTLOGEN (1ULL << 2) +#define AMDVI_MMIO_CONTROL_EVENTINTEN (1ULL << 3) +#define AMDVI_MMIO_CONTROL_COMWAITINTEN (1ULL << 4) +#define AMDVI_MMIO_CONTROL_CMDBUFLEN (1ULL << 12) + +/* MMIO status register bits */ +#define AMDVI_MMIO_STATUS_CMDBUF_RUN (1 << 4) +#define AMDVI_MMIO_STATUS_EVT_RUN (1 << 3) +#define AMDVI_MMIO_STATUS_COMP_INT (1 << 2) +#define AMDVI_MMIO_STATUS_EVT_OVF (1 << 0) + +#define AMDVI_CMDBUF_ID_BYTE 0x07 +#define AMDVI_CMDBUF_ID_RSHIFT 4 + +#define AMDVI_CMD_COMPLETION_WAIT 0x01 +#define AMDVI_CMD_INVAL_DEVTAB_ENTRY 0x02 +#define AMDVI_CMD_INVAL_AMDVI_PAGES 0x03 +#define AMDVI_CMD_INVAL_IOTLB_PAGES 0x04 +#define AMDVI_CMD_INVAL_INTR_TABLE 0x05 +#define AMDVI_CMD_PREFETCH_AMDVI_PAGES 0x06 +#define AMDVI_CMD_COMPLETE_PPR_REQUEST 0x07 +#define AMDVI_CMD_INVAL_AMDVI_ALL 0x08 + +#define AMDVI_DEVTAB_ENTRY_SIZE 32 + +/* Device table entry bits 0:63 */ +#define AMDVI_DEV_VALID (1ULL << 0) +#define AMDVI_DEV_TRANSLATION_VALID (1ULL << 1) +#define AMDVI_DEV_MODE_MASK 0x7 +#define AMDVI_DEV_MODE_RSHIFT 9 +#define AMDVI_DEV_PT_ROOT_MASK 0xffffffffff000 +#define AMDVI_DEV_PT_ROOT_RSHIFT 12 +#define AMDVI_DEV_PERM_SHIFT 61 +#define AMDVI_DEV_PERM_READ (1ULL << 61) +#define AMDVI_DEV_PERM_WRITE (1ULL << 62) + +/* Device table entry bits 64:127 */ +#define AMDVI_DEV_DOMID_ID_MASK ((1ULL << 16) - 1) + +/* Event codes and flags, as stored in the info field */ +#define AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY (0x1U << 12) +#define AMDVI_EVENT_IOPF (0x2U << 12) +#define AMDVI_EVENT_IOPF_I (1U << 3) +#define AMDVI_EVENT_DEV_TAB_HW_ERROR (0x3U << 12) +#define AMDVI_EVENT_PAGE_TAB_HW_ERROR (0x4U << 12) +#define AMDVI_EVENT_ILLEGAL_COMMAND_ERROR (0x5U << 12) +#define AMDVI_EVENT_COMMAND_HW_ERROR (0x6U << 12) + +#define AMDVI_EVENT_LEN 16 +#define AMDVI_PERM_READ (1 << 0) +#define AMDVI_PERM_WRITE (1 << 1) + +#define AMDVI_FEATURE_PREFETCH (1ULL << 0)/* page prefetch */ +#define AMDVI_FEATURE_PPR (1ULL << 1)/* PPR Support */ +#define AMDVI_FEATURE_GT (1ULL << 4)/* Guest Translation */ +#define AMDVI_FEATURE_IA (1ULL << 6)/* inval all support */ +#define AMDVI_FEATURE_GA (1ULL << 7)/* guest VAPIC support */ +#define AMDVI_FEATURE_HE (1ULL << 8)/* hardware error regs */ +#define AMDVI_FEATURE_PC (1ULL << 9)/* Perf counters */ + +/* reserved DTE bits */ +#define AMDVI_DTE_LOWER_QUAD_RESERVED 0x80300000000000fc +#define AMDVI_DTE_MIDDLE_QUAD_RESERVED 0x0000000000000100 +#define AMDVI_DTE_UPPER_QUAD_RESERVED 0x08f0000000000000 + +/* AMDVI paging mode */ +#define AMDVI_GATS_MODE (6ULL << 12) +#define AMDVI_HATS_MODE (6ULL << 10) + +/* IOTLB */ +#define AMDVI_IOTLB_MAX_SIZE 1024 +#define AMDVI_DEVID_SHIFT 36 + +/* extended feature support */ +#define AMDVI_EXT_FEATURES (AMDVI_FEATURE_PREFETCH | AMDVI_FEATURE_PPR | \ + AMDVI_FEATURE_IA | AMDVI_FEATURE_GT | AMDVI_FEATURE_HE | \ + AMDVI_GATS_MODE | AMDVI_HATS_MODE) + +/* capabilities header */ +#define AMDVI_CAPAB_FEATURES (AMDVI_CAPAB_FLAT_EXT | \ + AMDVI_CAPAB_FLAG_NPCACHE | AMDVI_CAPAB_FLAG_IOTLBSUP \ + | AMDVI_CAPAB_ID_SEC | AMDVI_CAPAB_INIT_TYPE | \ + AMDVI_CAPAB_FLAG_HTTUNNEL | AMDVI_CAPAB_EFR_SUP) + +/* AMDVI default address */ +#define AMDVI_BASE_ADDR 0xfed80000 + +/* page management constants */ +#define AMDVI_PAGE_SHIFT 12 +#define AMDVI_PAGE_SIZE (1ULL << AMDVI_PAGE_SHIFT) + +#define AMDVI_PAGE_SHIFT_4K 12 +#define AMDVI_PAGE_MASK_4K (~((1ULL << AMDVI_PAGE_SHIFT_4K) - 1)) + +#define AMDVI_MAX_VA_ADDR (48UL << 5) +#define AMDVI_MAX_PH_ADDR (40UL << 8) +#define AMDVI_MAX_GVA_ADDR (48UL << 15) + +/* Completion Wait data size */ +#define AMDVI_COMPLETION_DATA_SIZE 8 + +#define AMDVI_COMMAND_SIZE 16 +/* Completion Wait data size */ +#define AMDVI_COMPLETION_DATA_SIZE 8 + +#define AMDVI_COMMAND_SIZE 16 + +#define AMDVI_INT_ADDR_FIRST 0xfee00000 +#define AMDVI_INT_ADDR_LAST 0xfeefffff + +#define TYPE_AMD_IOMMU_DEVICE "amd-iommu" +#define AMD_IOMMU_DEVICE (obj)\ + OBJECT_CHECK(AMDVIState, (obj), TYPE_AMD_IOMMU_DEVICE) + +#define TYPE_AMD_IOMMU_PCI "AMDVI-PCI" + +typedef struct AMDVIAddressSpace AMDVIAddressSpace ; + +/* functions to steal PCI config space */ +typedef struct AMDVIPCIState { +PCIDevice dev;/* The PCI device itself */ +}AMDVIPCIState ; + +typedef struct AMDVIState { +X86IOMMUState iommu;/* IOMMU bus device */ +AMDVIPCIState pci;/* IOMMU PCI device */ + +uint32_t version; +uint32_t capab_offset;/* capability offset pointer */ + +uint64_t mmio_addr; + +uint32_t devid;/* auto-assigned devid */ + +bool enabled;/* IOMMU enabled */ +bool ats_enabled;/* address translation enabled */ +bool cmdbuf_enabled;/* command buffer enabled */ +bool evtlog_enabled;/* event log enabled */ +bool excl_enabled; + +hwaddr devtab;/* base address device table */ +size_t devtab_len;/* device table length */ + +hwaddr cmdbuf;/* command buffer base address */ +uint64_t cmdbuf_len;/* command buffer length */ +uint32_t cmdbuf_head;/* current IOMMU read position */ +uint32_t cmdbuf_tail;/* next Software write position */ +bool completion_wait_intr; + +hwaddr evtlog;/* base address event log */ +bool evtlog_intr; +uint32_t evtlog_len;/* event log length */ +uint32_t evtlog_head;/* current IOMMU write position */ +uint32_t evtlog_tail;/* current Software read position */ + +/* unused for now */ +hwaddr excl_base;/* base DVA - IOMMU exclusion range */ +hwaddr excl_limit;/* limit of IOMMU exclusion range */ +bool excl_allow;/* translate accesses to the exclusion range */ +bool excl_enable;/* exclusion range enabled */ + +hwaddr ppr_log;/* base address ppr log */ +uint32_t pprlog_len;/* ppr log len */ +uint32_t pprlog_head;/* ppr log head */ +uint32_t pprlog_tail;/* ppr log tail */ + +MemoryRegion mmio;/* MMIO region */ +uint8_t mmior[AMDVI_MMIO_SIZE ];/* read/write MMIO */ +uint8_t w1cmask[AMDVI_MMIO_SIZE ];/* read/write 1 clear mask */ +uint8_t romask[AMDVI_MMIO_SIZE ];/* MMIO read/only mask */ +bool mmio_enabled; + +/* IOMMU function */ +MemoryRegionIOMMUOps iommu_ops; + +/* for each served device */ +AMDVIAddressSpace **address_spaces[PCI_BUS_MAX ]; + +/* IOTLB */ +GHashTable *iotlb; +}AMDVIState ; + +#endif
hw/i386/amd_iommu.c new file +1381 -0
1,381 lines not on this page · raw message
hw/i386/Makefile.objs +1 -0
@@ -3,6 +3,7 @@ obj-y += multiboot.o obj-y += pc.o pc_piix.o pc_q35.o obj-y += pc_sysfw.o obj-y += x86-iommu.o intel_iommu.o +obj-y += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o
Signature · 1 line
MST
Re: [Qemu-devel] [PULL v3 6/6] MAINTAINERS: add virtio-* tests
In reply to Michael S. TsirkinAm 15.09.2016 um 22:38 schrieb Michael S. Tsirkin:
Quoted 10 lines
From: Greg Kurz <[email protected]>
Except virtio-9p, all virtio-* tests are orphan. This patch tries to fix it, according to the following logic:
- when the related subsystem has its own section in
MAINTAINERS, the test is added there
- otherwise it is added to the "parent" section (aka. SCSI, Network devices, virtio)
Quoted 8 lines
Signed-off-by Greg Kurz <[email protected]>Reviewed-by Amit Shah <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
Makes perfect sense, thanks for taking care.
Cheers,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg)
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
d1eb8f2acba579830cf3798c3c15ce51be852c56:fpu: add mechanism to check for invalid long double formats (2016-09-15 12:43:18 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
a5a43875b352810d29dc27e7b0fb602eb7ef2d31:
MAINTAINERS: add virtio-* tests (2016-09-15 23:37:16 +0300)----------------------------------------------------------------
virtio,pci: fixes and updates
Quoted 6 lines
AMD IOMMU emulation
virtio feature negotiation reworkSigned-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Fails to build on ppc64be, still:/home/pm215/qemu/hw/i386/amd_iommu.c:245:5: error: expected ‘,’, ‘;’ or ‘}’ before ‘uint32_t’
uint32_t reserved_3:29;
^
/home/pm215/qemu/hw/i386/amd_iommu.c: In function ‘amdvi_complete_ppr’:
/home/pm215/qemu/hw/i386/amd_iommu.c:588:62: error: ‘CMDCompletePPR’
has no member named ‘reserved_3’
if (pprcomp->reserved_1 || pprcomp->reserved_2 || pprcomp->reserved_3 ||
^
/home/pm215/qemu/hw/i386/amd_iommu.c:589:16: error: ‘CMDCompletePPR’
has no member named ‘reserved_4’
pprcomp->reserved_4 || pprcomp->reserved_5) {
^
/home/pm215/qemu/hw/i386/amd_iommu.c:589:39: error: ‘CMDCompletePPR’
has no member named ‘reserved_5’
pprcomp->reserved_4 || pprcomp->reserved_5) {
^Missing semicolon, again, line 237.
In fact looking at this code it just looks broken. Structures like this:
typedef struct QEMU_PACKED {
#ifdef HOST_WORDS_BIGENDIAN
uint64_t type:4; /* command type */
uint64_t reserved_1:44;
uint64_t devid:16; /* related devid */
#else
uint64_t devid:16;
uint64_t reserved_1:44;
uint64_t type:4;
#endif /* __BIG_ENDIAN_BITFIELD */
uint64_t reserved_2;
} CMDInvalIntrTable;seem to be trying to represent bit layouts in memory using bitfields, but this is just not portable. It's not sufficient to have a "bigendian vs littleendian" set of ifdefs.
The portable way to do this is to write the code to use bitwise logical operations (and functions like extract64 and deposit64) to manipulate things. As a bonus you get rid of all these host-specific #ifdefs that are tripping you up now.
It would be nice if C bitfields worked the way this code wants them to, but they don't, alas.
thanks
-- PMM
Quoted 70 lines · Peter Maydell
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
d1eb8f2acba579830cf3798c3c15ce51be852c56:fpu: add mechanism to check for invalid long double formats (2016-09-15 12:43:18 +0100)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
a5a43875b352810d29dc27e7b0fb602eb7ef2d31:
MAINTAINERS: add virtio-* tests (2016-09-15 23:37:16 +0300)----------------------------------------------------------------
virtio,pci: fixes and updatesQuoted 6 lines
AMD IOMMU emulation
virtio feature negotiation reworkSigned-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
Fails to build on ppc64be, still:
/home/pm215/qemu/hw/i386/amd_iommu.c:245:5: error: expected ‘,’, ‘;’ or ‘}’ before ‘uint32_t’uint32_t reserved_3:29; ^ /home/pm215/qemu/hw/i386/amd_iommu.c: In function ‘amdvi_complete_ppr’: /home/pm215/qemu/hw/i386/amd_iommu.c:588:62: error: ‘CMDCompletePPR’ has no member named ‘reserved_3’ if (pprcomp->reserved_1 || pprcomp->reserved_2 || pprcomp->reserved_3 || ^ /home/pm215/qemu/hw/i386/amd_iommu.c:589:16: error: ‘CMDCompletePPR’ has no member named ‘reserved_4’ pprcomp->reserved_4 || pprcomp->reserved_5) { ^ /home/pm215/qemu/hw/i386/amd_iommu.c:589:39: error: ‘CMDCompletePPR’ has no member named ‘reserved_5’ pprcomp->reserved_4 || pprcomp->reserved_5) { ^Missing semicolon, again, line 237.
In fact looking at this code it just looks broken. Structures like this:
typedef struct
QEMU_PACKED{
#ifdefHOST_WORDS_BIGENDIAN
uint64_ttype:4; /* command type */
uint64_treserved_1:44;
uint64_tdevid:16; /* related devid */#else uint64_t devid:16; uint64_t reserved_1:44; uint64_t type:4; #endif /* __BIG_ENDIAN_BITFIELD */ uint64_t reserved_2; } CMDInvalIntrTable;seem to be trying to represent bit layouts in memory using bitfields, but this is just not portable. It's not sufficient to have a "bigendian vs littleendian" set of ifdefs.
The portable way to do this is to write the code to use bitwise logical operations (and functions like extract64 and deposit64) to manipulate things. As a bonus you get rid of all these host-specific #ifdefs that are tripping you up now.
Quoted 5 lines
It would be nice if C bitfields worked the way this code wants them to, but they don't, alas.
thanks
-- PMM
I agree, I wanted to rework this in tree but maybe best to fix it first. I dropped all this code from tree for now.
Signature · 1 line
MST