pci, pc, virtio: fixes, features
The following changes since commit 13399aad4fa87b2878c49d02a5d3bafa6c966ba3:
Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-10-22' into staging (2018-10-23 17:20:23 +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 57b279df457c2c4ef66ce9e1b813df35abde69f7:
vhost-scsi: prevent using uninitialized vqs (2018-10-23 19:29:58 -0400)
----------------------------------------------------------------
pci, pc, virtio: fixes, features
AMD IOMMU VAPIC support + fixes all over the place.
----------------------------------------------------------------
Gerd Hoffmann (1):
pci-testdev: add optional memory bar
Laszlo Ersek (4):
MAINTAINERS: list "tests/acpi-test-data" files in ACPI/SMBIOS section hw/pci-host/x86: extract get_pci_hole64_start_value() helpers hw/pci-host/x86: extend the 64-bit PCI hole relative to the fw-assigned base tests/bios-tables-test: add 64-bit PCI MMIO aperture round-up test on Q35
Li Qiang (3):
i440fx: use ARRAY_SIZE for pam_regions
piix: use TYPE_FOO constants than string constats
piix_pci: fix i440fx data sheet link
Mao Zhongyi (1):
pci_bridge: fix typo in comment
Peter Xu (4):
intel_iommu: introduce vtd_reset_caches()
intel_iommu: better handling of dmar state switch
intel_iommu: move ce fetching out when sync shadow
intel_iommu: handle invalid ce for shadow sync
Philippe Mathieu-Daudé (3):
hw/pci-bridge/xio3130: Remove unused functions hw/pci-bridge/ioh3420: Remove unuseful header hw/pci: Add missing include
Singh, Brijesh (9):
x86_iommu: move the kernel-irqchip check in common code
x86_iommu: move vtd_generate_msi_message in common file x86_iommu/amd: remove V=1 check from amdvi_validate_dte() x86_iommu/amd: make the address space naming consistent with intel-iommu x86_iommu/amd: Prepare for interrupt remap support x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled
i386: acpi: add IVHD device entry for IOAPIC
x86_iommu/amd: Add interrupt remap support when VAPIC is enabled x86_iommu/amd: Enable Guest virtual APIC support
Yaowei Bai (1):
virtio-blk: fix comment for virtio_blk_rw_complete
Yongji Xie (1):
vhost-user-blk: start vhost when guest kicks
yuchenlin (1):
vhost-scsi: prevent using uninitialized vqs
docs/specs/pci-testdev.txt | 15 +- hw/i386/amd_iommu.h | 96 +++++++- hw/pci-bridge/ioh3420.h | 6 - hw/pci-bridge/xio3130_downstream.h | 11 - hw/pci-bridge/xio3130_upstream.h | 10 - include/hw/i386/intel_iommu.h | 59 ----- include/hw/i386/x86-iommu.h | 66 ++++++ include/hw/pci/pci_bus.h | 2 + hw/block/vhost-user-blk.c | 25 +++ hw/block/virtio-blk.c | 4 +- hw/i386/acpi-build.c | 31 ++- hw/i386/amd_iommu.c | 414 ++++++++++++++++++++++++++++++++++- hw/i386/intel_iommu.c | 131 +++++------ hw/i386/x86-iommu.c | 33 +++ hw/misc/pci-testdev.c | 19 ++ hw/pci-bridge/ioh3420.c | 2 +- hw/pci-bridge/xio3130_downstream.c | 28 +-- hw/pci-bridge/xio3130_upstream.c | 24 +- hw/pci-host/piix.c | 34 ++- hw/pci-host/q35.c | 17 +- hw/pci/pci_bridge.c | 2 +- hw/scsi/vhost-scsi.c | 2 +- tests/bios-tables-test.c | 16 ++ MAINTAINERS | 2 + dtc | 2 +- hw/i386/trace-events | 14 ++ tests/acpi-test-data/q35/DSDT.mmio64 | Bin 0 -> 8947 bytes tests/acpi-test-data/q35/SRAT.mmio64 | Bin 0 -> 224 bytes 28 files changed, 812 insertions(+), 253 deletions(-) delete mode 100644 hw/pci-bridge/ioh3420.h delete mode 100644 hw/pci-bridge/xio3130_downstream.h delete mode 100644 hw/pci-bridge/xio3130_upstream.h create mode 100644 tests/acpi-test-data/q35/DSDT.mmio64 create mode 100644 tests/acpi-test-data/q35/SRAT.mmio64
[Qemu-devel] [PULL 04/28] intel_iommu: move ce fetching out when sync shadow
From: Peter Xu <[email protected]>
There are two callers for vtd_sync_shadow_page_table_range(): one provided a valid context entry and one not. Move that fetching operation into the caller vtd_sync_shadow_page_table() where we need to fetch the context entry.
Meanwhile, remove the error_report_once() directly since we're already tracing all the error cases in the previous call. Instead, return error number back to caller. This will not change anything functional since callers are dropping it after all.
We do this move majorly because we want to do something more later in vtd_sync_shadow_page_table().
--- hw/i386/intel_iommu.c | 41 +++++++++++++---------------------------- dtc | 2 +- 2 files changed, 14 insertions(+), 29 deletions(-)
hw/i386/intel_iommu.c +13 -28
@@ -1045,7 +1045,6 @@ static int vtd_sync_shadow_page_hook(IOMMUTLBEntry *entry,return 0 ; } -/* If context entry is NULL, we'll try to fetch it on our own. */ static int vtd_sync_shadow_page_table_range (VTDAddressSpace *vtd_as,VTDContextEntry *ce,hwaddr addr,hwaddr size)
@@ -1057,39 +1056,25 @@ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as, .notify_unmap = true, .aw = s->aw_bits, .as = vtd_as, + .domain_id = VTD_CONTEXT_ENTRY_DID(ce->hi), }; -VTDContextEntry ce_cache; -int ret; -if (ce) { -/* If the caller provided context entry, use it */ - ce_cache = *ce; - }else { -/* If the caller didn't provide ce, try to fetch */ - ret =vtd_dev_to_context_entry (s,pci_bus_num (vtd_as->bus), - vtd_as->devfn, &ce_cache); -if (ret) { -/* -* This should not really happen, but in case it happens, -* we just skip the sync for this time. After all we even -* don't have the root table pointer! -*/ -error_report_once ("%s: invalid context entry for bus 0x%x" -" devfn 0x%x" , - __func__,pci_bus_num (vtd_as->bus), - vtd_as->devfn); -return 0 ; - } - } - - info.domain_id =VTD_CONTEXT_ENTRY_DID (ce_cache.hi); - -return vtd_page_walk (&ce_cache, addr, addr + size, &info); +return vtd_page_walk (ce, addr, addr + size, &info); }static int vtd_sync_shadow_page_table (VTDAddressSpace *vtd_as) { -return vtd_sync_shadow_page_table_range (vtd_as,NULL ,0 ,UINT64_MAX ); +int ret; +VTDContextEntry ce; + + ret =vtd_dev_to_context_entry (vtd_as->iommu_state, +pci_bus_num (vtd_as->bus), + vtd_as->devfn, &ce); +if (ret) { +return ret; + } + +return vtd_sync_shadow_page_table_range (vtd_as, &ce,0 ,UINT64_MAX ); }/*
dtc +1 -1
@@ -1 +1 @@ -Subproject commit 88f18909db731a627456f26d779445f84e449536 +Subproject commit e54388015af1fb4bf04d0bca99caba1074d9cc42
Signature · 1 line
MST
[Qemu-devel] [PULL 01/28] virtio-blk: fix comment for virtio_blk_rw_complete
In reply to Michael S. TsirkinFrom: Yaowei Bai <[email protected]>
Here should be submit_requests, there is no submit_merged_requests function.
--- hw/block/virtio-blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/virtio-blk.c +2 -2
@@ -97,8 +97,8 @@ static void virtio_blk_rw_complete(void *opaque, int ret)if (req->qiov.nalloc !=-1 ) {/* If nalloc is != 1 req->qiov is a local copy of the original -* external iovec. It was allocated in submit_merged_requests -* to be able to merge requests. */ +* external iovec. It was allocated in submit_requests to be +* able to merge requests. */ qemu_iovec_destroy (&req->qiov); }
Signature · 1 line
MST
[Qemu-devel] [PULL 02/28] intel_iommu: introduce vtd_reset_caches()
In reply to Michael S. TsirkinFrom: Peter Xu <[email protected]>
Provide the function and use it in vtd_init(). Used to reset both context entry cache and iotlb cache for the whole IOMMU unit.
--- hw/i386/intel_iommu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/i386/intel_iommu.c +9 -4
@@ -227,6 +227,14 @@ static void vtd_reset_iotlb(IntelIOMMUState *s)vtd_iommu_unlock (s); } +static void vtd_reset_caches (IntelIOMMUState *s) +{ +vtd_iommu_lock (s); +vtd_reset_iotlb_locked (s); +vtd_reset_context_cache_locked (s); +vtd_iommu_unlock (s); +} +static uint64_t vtd_get_iotlb_key (uint64_t gfn,uint16_t source_id,uint32_t level) {
@@ -3160,10 +3168,7 @@ static void vtd_init(IntelIOMMUState *s) s->cap |=VTD_CAP_CM ; } -vtd_iommu_lock (s); -vtd_reset_context_cache_locked (s); -vtd_reset_iotlb_locked (s); -vtd_iommu_unlock (s); +vtd_reset_caches (s);/* Define registers with default values and bit semantics */ vtd_define_long (s,DMAR_VER_REG ,0x10UL ,0 ,0 );
Signature · 1 line
MST
[Qemu-devel] [PULL 05/28] intel_iommu: handle invalid ce for shadow sync
In reply to Michael S. TsirkinFrom: Peter Xu <[email protected]>
We should handle VTD_FR_CONTEXT_ENTRY_P properly when synchronizing shadow page tables. Having invalid context entry there is perfectly valid when we move a device out of an existing domain. When that happens, instead of posting an error we invalidate the whole region.
Without this patch, QEMU will crash if we do these steps:
(1) start QEMU with VT-d IOMMU and two 10G NICs (ixgbe)
(2) bind the NICs with vfio-pci in the guest
(3) start testpmd with the NICs applied
(4) stop testpmd
(5) rebind the NIC back to ixgbe kernel driver
The patch should fix it.
--- hw/i386/intel_iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/i386/intel_iommu.c +17 -0
@@ -38,6 +38,7 @@#include "trace.h" static void vtd_address_space_refresh_all (IntelIOMMUState *s); +static void vtd_address_space_unmap (VTDAddressSpace *as,IOMMUNotifier *n);static void vtd_define_quad (IntelIOMMUState *s,hwaddr addr,uint64_t val,uint64_t wmask,uint64_t w1cmask)
@@ -1066,11 +1067,27 @@ static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as) {int ret;VTDContextEntry ce; +IOMMUNotifier *n; ret =vtd_dev_to_context_entry (vtd_as->iommu_state,pci_bus_num (vtd_as->bus), vtd_as->devfn, &ce);if (ret) { +if (ret == -VTD_FR_CONTEXT_ENTRY_P ) { +/* +* It's a valid scenario to have a context entry that is +* not present. For example, when a device is removed +* from an existing domain then the context entry will be +* zeroed by the guest before it was put into another +* domain. When this happens, instead of synchronizing +* the shadow pages we should invalidate all existing +* mappings and notify the backends. +*/ + IOMMU_NOTIFIER_FOREACH(n, &vtd_as->iommu) { +vtd_address_space_unmap (vtd_as, n); + } + ret =0 ; + }return ret; }
Signature · 1 line
MST
[Qemu-devel] [PULL 07/28] x86_iommu: move the kernel-irqchip check in common code
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Interrupt remapping needs kernel-irqchip={off|split} on both Intel and AMD platforms. Move the check in common place.
--- hw/i386/intel_iommu.c | 7 ------- hw/i386/x86-iommu.c | 9 +++++++++ 2 files changed, 9 insertions(+), 7 deletions(-)
hw/i386/intel_iommu.c +0 -7
@@ -3262,13 +3262,6 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s); -/* Currently Intel IOMMU IR only support "kernel-irqchip={off|split}" */ -if (x86_iommu->intr_supported &&kvm_irqchip_in_kernel () && - !kvm_irqchip_is_split ()) { -error_setg (errp,"Intel Interrupt Remapping cannot work with " -"kernel-irqchip=on, please use 'split|off'." ); -return false; - }if (s->intr_eim ==ON_OFF_AUTO_ON && !x86_iommu->intr_supported) {error_setg (errp,"eim=on cannot be selected without intremap=on" );return false;
hw/i386/x86-iommu.c +9 -0
@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "trace.h" +#include "sysemu/kvm.h" void x86_iommu_iec_register_notifier (X86IOMMUState *iommu,iec_notify_fn fn,void *data)
@@ -94,6 +95,14 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp)return ; } +/* Both Intel and AMD IOMMU IR only support "kernel-irqchip={off|split}" */ +if (x86_iommu->intr_supported &&kvm_irqchip_in_kernel () && + !kvm_irqchip_is_split ()) { +error_setg (errp,"Interrupt Remapping cannot work with " +"kernel-irqchip=on, please use 'split|off'." ); +return ; + } +if (x86_class->realize) { x86_class->realize (dev, errp); }
Signature · 1 line
MST
[Qemu-devel] [PULL 09/28] x86_iommu/amd: remove V=1 check from amdvi_validate_dte()
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Currently, the amdvi_validate_dte() assumes that a valid DTE will always have V=1. This is not true. The V=1 means that bit[127:1] are valid. A valid DTE can have IV=1 and V=0 (i.e address translation disabled and interrupt remapping enabled)
Remove the V=1 check from amdvi_validate_dte(), make the caller responsible to check for V or IV bits.
This also fixes a bug in existing code that when error is detected during the translation we'll fail the translation instead of assuming a passthrough mode.
--- hw/i386/amd_iommu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/i386/amd_iommu.c +7 -3
@@ -807,7 +807,7 @@ static inline uint64_t amdvi_get_perms(uint64_t entry)AMDVI_DEV_PERM_SHIFT ; } -/* a valid entry should have V = 1 and reserved bits honoured */ +/* validate that reserved bits are honoured */ static bool amdvi_validate_dte (AMDVIState *s,uint16_t devid,uint64_t *dte) {
@@ -820,7 +820,7 @@ static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid,return false; } -return dte[0 ] &AMDVI_DEV_VALID ; +return true; }/* get a device table entry given the devid */
@@ -966,8 +966,12 @@ static void amdvi_do_translate(AMDVIAddressSpace *as, hwaddr addr,return ; } -/* devices with V = 0 are not translated */ if (!amdvi_get_dte (s, devid, entry)) { +return ; + } + +/* devices with V = 0 are not translated */ +if (!(entry[0 ] &AMDVI_DEV_VALID )) { goto out; }
Signature · 1 line
MST
[Qemu-devel] [PULL 10/28] x86_iommu/amd: make the address space naming consistent with intel-iommu
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
To be consistent with intel-iommu:
- rename the address space to use '_' instead of '-'
- update the memory region relationships
--- hw/i386/amd_iommu.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
hw/i386/amd_iommu.c +27 -7
@@ -55,6 +55,7 @@ struct AMDVIAddressSpace {uint8_t bus_num;/* bus number */ uint8_t devfn;/* device function */ AMDVIState *iommu_state;/* AMDVI - one per machine */ +MemoryRegion root;/* AMDVI Root memory map region */ IOMMUMemoryRegion iommu;/* Device's address translation region */ MemoryRegion iommu_ir;/* Device's interrupt remapping region */ AddressSpace as;/* device's corresponding address space */
@@ -1032,8 +1033,9 @@ static IOMMUTLBEntry amdvi_translate(IOMMUMemoryRegion *iommu, hwaddr addr,static AddressSpace *amdvi_host_dma_iommu (PCIBus *bus,void *opaque,int devfn) { +char name[128 ];AMDVIState *s = opaque; -AMDVIAddressSpace **iommu_as; +AMDVIAddressSpace **iommu_as, *amdvi_dev_as;int bus_num =pci_bus_num (bus); iommu_as = s->address_spaces[bus_num];
@@ -1046,19 +1048,37 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)/* set up AMD-Vi region */ if (!iommu_as[devfn]) { +snprintf (name,sizeof (name),"amd_iommu_devfn_%d" , devfn); + iommu_as[devfn] =g_malloc0 (sizeof (AMDVIAddressSpace)); iommu_as[devfn]->bus_num = (uint8_t )bus_num; iommu_as[devfn]->devfn = (uint8_t )devfn; iommu_as[devfn]->iommu_state = s; -memory_region_init_iommu (&iommu_as[devfn]->iommu, -sizeof (iommu_as[devfn]->iommu), + amdvi_dev_as = iommu_as[devfn]; + +/* +* Memory region relationships looks like (Address range shows +* only lower 32 bits to make it short in length...): +* +* |-----------------+-------------------+----------| +* | Name | Address range | Priority | +* |-----------------+-------------------+----------+ +* | amdvi_root | 00000000-ffffffff | 0 | +* | amdvi_iommu | 00000000-ffffffff | 1 | +* |-----------------+-------------------+----------| +*/ +memory_region_init_iommu (&amdvi_dev_as->iommu, +sizeof (amdvi_dev_as->iommu),TYPE_AMD_IOMMU_MEMORY_REGION ,OBJECT (s), -"amd-iommu" ,UINT64_MAX ); -address_space_init (&iommu_as[devfn]->as, -MEMORY_REGION (&iommu_as[devfn]->iommu), -"amd-iommu" ); +"amd_iommu" ,UINT64_MAX ); +memory_region_init (&amdvi_dev_as->root,OBJECT (s), +"amdvi_root" ,UINT64_MAX ); +address_space_init (&amdvi_dev_as->as, &amdvi_dev_as->root, name); +memory_region_add_subregion_overlap (&amdvi_dev_as->root,0 , +MEMORY_REGION (&amdvi_dev_as->iommu), +1 ); }return &iommu_as[devfn]->as; }
Signature · 1 line
MST
[Qemu-devel] [PULL 16/28] MAINTAINERS: list "tests/acpi-test-data" files in ACPI/SMBIOS section
In reply to Michael S. TsirkinFrom: Laszlo Ersek <[email protected]>
The "tests/acpi-test-data" files are currently not covered by any section in MAINTAINERS, and "scripts/checkpatch.pl" complains when new data files are added.
--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -1113,6 +1113,8 @@ F: hw/i386/acpi-build.[hc] F: hw/arm/virt-acpi-build.c F: tests/bios-tables-test.c F: tests/acpi-utils.[hc] +F: tests/acpi-test-data/* +F: tests/acpi-test-data/*/* ppc4xx M: Alexander Graf <[email protected]>
Signature · 1 line
MST
[Qemu-devel] [PULL 17/28] pci-testdev: add optional memory bar
In reply to Michael S. TsirkinFrom: Gerd Hoffmann <[email protected]>
Add memory bar to pci-testdev. Size is configurable using the membar property. Setting the size to zero (default) turns it off. Can be used to check whether guests handle large pci bars correctly.
--- docs/specs/pci-testdev.txt | 15 ++++++++++----- hw/misc/pci-testdev.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-)
docs/specs/pci-testdev.txt +10 -5
@@ -1,11 +1,11 @@ pci-test is a device used for testing low level IO -device implements up to two BARs: BAR0 and BAR1. -Each BAR can be memory or IO. Guests must detect -BAR type and act accordingly. +device implements up to three BARs: BAR0, BAR1 and BAR2. +Each of BAR 0+1 can be memory or IO. Guests must detect +BAR types and act accordingly. -Each BAR size is up to 4K bytes. -Each BAR starts with the following header: +BAR 0+1 size is up to 4K bytes each. +BAR 0+1 starts with the following header: typedef struct PCITestDevHdr { uint8_t test; <- write-only, starts a given test number
@@ -24,3 +24,8 @@ All registers are little endian. device is expected to always implement tests 0 to N on each BAR, and to add new tests with higher numbers. In this way a guest can scan test numbers until it detects an access type that it does not support on this BAR, then stop. + +BAR2 is a 64bit memory bar, without backing storage. It is disabled +by default and can be enabled using the membar=<size> property. This +can be used to test whether guests handle pci bars of a specific +(possibly quite large) size correctly.
hw/misc/pci-testdev.c +19 -0
@@ -85,6 +85,9 @@ typedef struct PCITestDevState {MemoryRegion portio;IOTest *tests;int current; + +size_t membar_size; +MemoryRegion membar; } PCITestDevState;#define TYPE_PCI_TEST_DEV "pci-testdev"
@@ -253,6 +256,16 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &d->mmio);pci_register_bar (pci_dev,1 ,PCI_BASE_ADDRESS_SPACE_IO , &d->portio); +if (d->membar_size) { +memory_region_init (&d->membar,OBJECT (d),"pci-testdev-membar" , + d->membar_size); +pci_register_bar (pci_dev,2 , +PCI_BASE_ADDRESS_SPACE_MEMORY | +PCI_BASE_ADDRESS_MEM_PREFETCH | +PCI_BASE_ADDRESS_MEM_TYPE_64 , + &d->membar); + } + d->current =-1 ; d->tests =g_malloc0 (IOTEST_MAX *sizeof *d->tests);for (i =0 ; i <IOTEST_MAX ; ++i) {
@@ -305,6 +318,11 @@ static void qdev_pci_testdev_reset(DeviceState *dev)pci_testdev_reset (d); } +static Property pci_testdev_properties[] = { +DEFINE_PROP_SIZE ("membar" , PCITestDevState, membar_size,0 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void pci_testdev_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -319,6 +337,7 @@ static void pci_testdev_class_init(ObjectClass *klass, void *data) dc->desc ="PCI Test Device" ;set_bit (DEVICE_CATEGORY_MISC , dc->categories); dc->reset = qdev_pci_testdev_reset; + dc->props = pci_testdev_properties; }static const TypeInfo pci_testdev_info = {
Signature · 1 line
MST
[Qemu-devel] [PULL 06/28] vhost-user-blk: start vhost when guest kicks
In reply to Michael S. TsirkinFrom: Yongji Xie <[email protected]>
Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early") kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This violates the virtio spec. But virtio 1.0 transitional devices support this behaviour. So we should start vhost when guest kicks in this case.
--- hw/block/vhost-user-blk.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
hw/block/vhost-user-blk.c +25 -0
@@ -217,7 +217,32 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,static void vhost_user_blk_handle_output (VirtIODevice *vdev,VirtQueue *vq) { +VHostUserBlk *s =VHOST_USER_BLK (vdev); +int i; +if (!(virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && + !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 ))) { +return ; + } + +if (s->dev.started) { +return ; + } + +/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start +* vhost here instead of waiting for .set_status(). +*/ +vhost_user_blk_start (vdev); + +/* Kick right away to begin processing requests already in vring */ +for (i =0 ; i < s->dev.nvqs; i++) { +VirtQueue *kick_vq =virtio_get_queue (vdev, i); + +if (!virtio_queue_get_desc_addr (vdev, i)) { +continue ; + } +event_notifier_set (virtio_queue_get_host_notifier (kick_vq)); + } }static void vhost_user_blk_device_realize (DeviceState *dev,Error **errp)
Signature · 1 line
MST
[Qemu-devel] [PULL 13/28] i386: acpi: add IVHD device entry for IOAPIC
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
When interrupt remapping is enabled, add a special IVHD device (type IOAPIC).
--- hw/i386/acpi-build.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
hw/i386/acpi-build.c +27 -1
@@ -2467,9 +2467,12 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker)* IVRS table as specified in AMD IOMMU Specification v2.62, Section 5.2 * accessible here http://support.amd.com/TechDocs/48882_IOMMU.pdf */ +#define IOAPIC_SB_DEVID (uint64_t)PCI_BUILD_BDF(0, PCI_DEVFN(0x14, 0)) +static void build_amd_iommu (GArray *table_data,BIOSLinker *linker) { +int ivhd_table_len =28 ;int iommu_start = table_data->len;AMDVIState *s =AMD_IOMMU_DEVICE (x86_iommu_get_default ());
@@ -2491,8 +2494,16 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker) (1UL <<6 ) |/* PrefSup */ (1UL <<7 ),/* PPRSup */ 1); + +/* +* When interrupt remapping is supported, we add a special IVHD device +* for type IO-APIC. +*/ +if (x86_iommu_get_default ()->intr_supported) { + ivhd_table_len +=8 ; + }/* IVHD length */ -build_append_int_noprefix (table_data,28 ,2 ); +build_append_int_noprefix (table_data, ivhd_table_len,2 );/* DeviceID */ build_append_int_noprefix (table_data, s->devid,2 );/* Capability offset */
@@ -2516,6 +2527,21 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)*/ build_append_int_noprefix (table_data,0x0000001 ,4 ); +/* +* Add a special IVHD device type. +* Refer to spec - Table 95: IVHD device entry type codes +* +* Linux IOMMU driver checks for the special IVHD device (type IO-APIC). +* See Linux kernel commit 'c2ff5cf5294bcbd7fa50f7d860e90a66db7e5059' +*/ +if (x86_iommu_get_default ()->intr_supported) { +build_append_int_noprefix (table_data, + (0x1ull <<56 ) |/* type IOAPIC */ + (IOAPIC_SB_DEVID <<40 ) |/* IOAPIC devid */ +0x48 ,/* special device */ +8 ); + } +build_header (linker, table_data, (void *)(table_data->data + iommu_start),"IVRS" , table_data->len - iommu_start,1 ,NULL ,NULL ); }
Signature · 1 line
MST
[Qemu-devel] [PULL 24/28] pci_bridge: fix typo in comment
In reply to Michael S. TsirkinFrom: Mao Zhongyi <[email protected]>
--- hw/pci/pci_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci_bridge.c +1 -1
@@ -399,7 +399,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)/* * before qdev initialization(qdev_init()), this function sets bus_name and -* map_irq callback which are necessry for pci_bridge_initfn() to +* map_irq callback which are necessary for pci_bridge_initfn() to * initialize bus. */ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,
Signature · 1 line
MST
[Qemu-devel] [PULL 11/28] x86_iommu/amd: Prepare for interrupt remap support
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Register the interrupt remapping callback and read/write ops for the amd-iommu-ir memory region.
amd-iommu-ir is set to higher priority to ensure that this region won't be masked out by other memory regions.
--- hw/i386/amd_iommu.h | 14 +++++- hw/i386/amd_iommu.c | 106 +++++++++++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 5 ++ 3 files changed, 123 insertions(+), 2 deletions(-)
hw/i386/amd_iommu.h +12 -2
@@ -206,8 +206,18 @@#define AMDVI_COMMAND_SIZE 16 -#define AMDVI_INT_ADDR_FIRST 0xfee00000 -#define AMDVI_INT_ADDR_LAST 0xfeefffff +#define AMDVI_INT_ADDR_FIRST 0xfee00000 +#define AMDVI_INT_ADDR_LAST 0xfeefffff +#define AMDVI_INT_ADDR_SIZE (AMDVI_INT_ADDR_LAST - AMDVI_INT_ADDR_FIRST + 1) +#define AMDVI_MSI_ADDR_HI_MASK (0xffffffff00000000ULL) +#define AMDVI_MSI_ADDR_LO_MASK (0x00000000ffffffffULL) + +/* SB IOAPIC is always on this device in AMD systems */ +#define AMDVI_IOAPIC_SB_DEVID PCI_BUILD_BDF(0, PCI_DEVFN(0x14, 0)) + +/* Interrupt remapping errors */ +#define AMDVI_IR_ERR 0x1 +#define TYPE_AMD_IOMMU_DEVICE "amd-iommu"#define AMD_IOMMU_DEVICE (obj)\
hw/i386/amd_iommu.c +106 -0
142 lines not on this page · raw message
hw/i386/trace-events +5 -0
@@ -101,6 +101,11 @@ amdvi_mode_invalid(uint8_t level, uint64_t addr)"error: translation level 0x%"PR amdvi_page_fault(uint64_t addr) "error: page fault accessing guest physical address 0x%"PRIx64 amdvi_iotlb_hit(uint8_t bus, uint8_t slot, uint8_t func, uint64_t addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64" hpa 0x%"PRIx64 amdvi_translation_result(uint8_t bus, uint8_t slot, uint8_t func, uint64_t addr, uint64_t txaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64" hpa 0x%"PRIx64 +amdvi_mem_ir_write_req(uint64_t addr, uint64_t val, uint32_t size) "addr 0x%"PRIx64" data 0x%"PRIx64" size 0x%"PRIx32 +amdvi_mem_ir_write(uint64_t addr, uint64_t val) "addr 0x%"PRIx64" data 0x%"PRIx64 +amdvi_ir_remap_msi_req(uint64_t addr, uint64_t data, uint8_t devid) "addr 0x%"PRIx64" data 0x%"PRIx64" devid 0x%"PRIx8 +amdvi_ir_remap_msi(uint64_t addr, uint64_t data, uint64_t addr2, uint64_t data2) "(addr 0x%"PRIx64", data 0x%"PRIx64") -> (addr 0x%"PRIx64", data 0x%"PRIx64")" +amdvi_err(const char *str) "%s" # hw/i386/vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p"
Signature · 1 line
MST
[Qemu-devel] [PULL 25/28] i440fx: use ARRAY_SIZE for pam_regions
In reply to Michael S. TsirkinFrom: Li Qiang <[email protected]>
--- hw/pci-host/piix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +2 -2
@@ -142,7 +142,7 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)PCIDevice *pd =PCI_DEVICE (d);memory_region_transaction_begin (); -for (i =0 ; i <13 ; i++) { +for (i =0 ; i <ARRAY_SIZE (d->pam_regions); i++) {pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + (DIV_ROUND_UP (i,2 ))]); }
@@ -412,7 +412,7 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,init_pam (dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[0 ],PAM_BIOS_BASE ,PAM_BIOS_SIZE ); -for (i =0 ; i <12 ; ++i) { +for (i =0 ; i <ARRAY_SIZE (f->pam_regions) -1 ; ++i) {init_pam (dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[i+1 ],PAM_EXPAN_BASE + i *PAM_EXPAN_SIZE ,PAM_EXPAN_SIZE );
Signature · 1 line
MST
[Qemu-devel] [PULL 08/28] x86_iommu: move vtd_generate_msi_message in common file
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
The vtd_generate_msi_message() in intel-iommu is used to construct a MSI Message from IRQ. A similar function will be needed when we add interrupt remapping support in amd-iommu. Moving the function in common file to avoid the code duplication. Rename it to x86_iommu_irq_to_msi_message(). There is no logic changes in the code flow.
--- include/hw/i386/intel_iommu.h | 59 ------------------------------- include/hw/i386/x86-iommu.h | 66 +++++++++++++++++++++++++++++++++++ hw/i386/intel_iommu.c | 32 +++-------------- hw/i386/x86-iommu.c | 24 +++++++++++++ 4 files changed, 94 insertions(+), 87 deletions(-)
include/hw/i386/intel_iommu.h +0 -59
@@ -66,8 +66,6 @@ typedef struct VTDIOTLBEntry VTDIOTLBEntry;typedef struct VTDBus VTDBus ;typedef union VTD_IR_TableEntry VTD_IR_TableEntry ;typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress ; -typedef struct VTDIrq VTDIrq ; -typedef struct VTD_MSIMessage VTD_MSIMessage ;/* Context-Entry */ struct VTDContextEntry {
@@ -197,63 +195,6 @@ union VTD_IR_MSIAddress {uint32_t data; }; -/* Generic IRQ entry information */ -struct VTDIrq { -/* Used by both IOAPIC/MSI interrupt remapping */ -uint8_t trigger_mode; -uint8_t vector; -uint8_t delivery_mode; -uint32_t dest; -uint8_t dest_mode; - -/* only used by MSI interrupt remapping */ -uint8_t redir_hint; -uint8_t msi_addr_last_bits; -}; - -struct VTD_MSIMessage { -union { -struct { -#ifdef HOST_WORDS_BIGENDIAN -uint32_t __addr_head:12 ;/* 0xfee */ -uint32_t dest:8 ; -uint32_t __reserved:8 ; -uint32_t redir_hint:1 ; -uint32_t dest_mode:1 ; -uint32_t __not_used:2 ; -#else -uint32_t __not_used:2 ; -uint32_t dest_mode:1 ; -uint32_t redir_hint:1 ; -uint32_t __reserved:8 ; -uint32_t dest:8 ; -uint32_t __addr_head:12 ;/* 0xfee */ -#endif -uint32_t __addr_hi; - } QEMU_PACKED; -uint64_t msi_addr; - }; -union { -struct { -#ifdef HOST_WORDS_BIGENDIAN -uint16_t trigger_mode:1 ; -uint16_t level:1 ; -uint16_t __resved:3 ; -uint16_t delivery_mode:3 ; -uint16_t vector:8 ; -#else -uint16_t vector:8 ; -uint16_t delivery_mode:3 ; -uint16_t __resved:3 ; -uint16_t level:1 ; -uint16_t trigger_mode:1 ; -#endif -uint16_t __resved1; - } QEMU_PACKED; -uint32_t msi_data; - }; -}; -/* When IR is enabled, all MSI/MSI-X data bits should be zero */ #define VTD_IR_MSI_DATA (0)
include/hw/i386/x86-iommu.h +66 -0
88 lines not on this page · raw message
hw/i386/intel_iommu.c +4 -28
@@ -2716,7 +2716,7 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uint16_t index,/* Fetch IRQ information of specific IR index */ static int vtd_remap_irq_get (IntelIOMMUState *iommu,uint16_t index, -VTDIrq *irq,uint16_t sid) +X86IOMMUIrq *irq,uint16_t sid) {VTD_IR_TableEntry irte = {};int ret =0 ;
@@ -2745,30 +2745,6 @@ static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index,return 0 ; } -/* Generate one MSI message from VTDIrq info */ -static void vtd_generate_msi_message (VTDIrq *irq,MSIMessage *msg_out) -{ -VTD_MSIMessage msg = {}; - -/* Generate address bits */ - msg.dest_mode = irq->dest_mode; - msg.redir_hint = irq->redir_hint; - msg.dest = irq->dest; - msg.__addr_hi = irq->dest &0xffffff00 ; - msg.__addr_head =cpu_to_le32 (0xfee ); -/* Keep this from original MSI address bits */ - msg.__not_used = irq->msi_addr_last_bits; - -/* Generate data bits */ - msg.vector = irq->vector; - msg.delivery_mode = irq->delivery_mode; - msg.level =1 ; - msg.trigger_mode = irq->trigger_mode; - - msg_out->address = msg.msi_addr; - msg_out->data = msg.msi_data; -} -/* Interrupt remapping for MSI/MSI-X entry */ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu, MSIMessage *origin,
@@ -2778,7 +2754,7 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu,int ret =0 ;VTD_IR_MSIAddress addr;uint16_t index; -VTDIrq irq = {}; +X86IOMMUIrq irq = {};assert (origin && translated);
@@ -2857,8 +2833,8 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu,*/ irq.msi_addr_last_bits = addr.addr.__not_care; -/* Translate VTDIrq to MSI message */ -vtd_generate_msi_message (&irq, translated); +/* Translate X86IOMMUIrq to MSI message */ +x86_iommu_irq_to_msi_message (&irq, translated); out: trace_vtd_ir_remap_msi(origin->address, origin->data,
hw/i386/x86-iommu.c +24 -0
@@ -53,6 +53,30 @@ void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global, } } +/* Generate one MSI message from VTDIrq info */ +void x86_iommu_irq_to_msi_message (X86IOMMUIrq *irq,MSIMessage *msg_out) +{ +X86IOMMU_MSIMessage msg = {}; + +/* Generate address bits */ + msg.dest_mode = irq->dest_mode; + msg.redir_hint = irq->redir_hint; + msg.dest = irq->dest; + msg.__addr_hi = irq->dest &0xffffff00 ; + msg.__addr_head =cpu_to_le32 (0xfee ); +/* Keep this from original MSI address bits */ + msg.__not_used = irq->msi_addr_last_bits; + +/* Generate data bits */ + msg.vector = irq->vector; + msg.delivery_mode = irq->delivery_mode; + msg.level =1 ; + msg.trigger_mode = irq->trigger_mode; + + msg_out->address = msg.msi_addr; + msg_out->data = msg.msi_data; +} +/* Default X86 IOMMU device */ static X86IOMMUState *x86_iommu_default =NULL ;
Signature · 1 line
MST
[Qemu-devel] [PULL 12/28] x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Emulate the interrupt remapping support when guest virtual APIC is not enabled.
For more info Refer: AMD IOMMU spec Rev 3.0 - section 2.2.5.1
When VAPIC is not enabled, it uses interrupt remapping as defined in Table 20 and Figure 15 from IOMMU spec.
--- hw/i386/amd_iommu.h | 44 ++++++++++ hw/i386/amd_iommu.c | 199 ++++++++++++++++++++++++++++++++++++++++++- hw/i386/trace-events | 7 ++ 3 files changed, 249 insertions(+), 1 deletion(-)
hw/i386/amd_iommu.h +44 -0
@@ -217,7 +217,51 @@/* Interrupt remapping errors */ #define AMDVI_IR_ERR 0x1 +#define AMDVI_IR_GET_IRTE 0x2 +#define AMDVI_IR_TARGET_ABORT 0x3 +/* Interrupt remapping */ +#define AMDVI_IR_REMAP_ENABLE 1ULL +#define AMDVI_IR_INTCTL_SHIFT 60 +#define AMDVI_IR_INTCTL_ABORT 0 +#define AMDVI_IR_INTCTL_PASS 1 +#define AMDVI_IR_INTCTL_REMAP 2 + +#define AMDVI_IR_PHYS_ADDR_MASK (((1ULL << 45) - 1) << 6) + +/* MSI data 10:0 bits (section 2.2.5.1 Fig 14) */ +#define AMDVI_IRTE_OFFSET 0x7ff + +/* Delivery mode of MSI data (same as IOAPIC deilver mode encoding) */ +#define AMDVI_IOAPIC_INT_TYPE_FIXED 0x0 +#define AMDVI_IOAPIC_INT_TYPE_ARBITRATED 0x1 +#define AMDVI_IOAPIC_INT_TYPE_SMI 0x2 +#define AMDVI_IOAPIC_INT_TYPE_NMI 0x4 +#define AMDVI_IOAPIC_INT_TYPE_INIT 0x5 +#define AMDVI_IOAPIC_INT_TYPE_EINT 0x7 + +/* Pass through interrupt */ +#define AMDVI_DEV_INT_PASS_MASK (1UL << 56) +#define AMDVI_DEV_EINT_PASS_MASK (1UL << 57) +#define AMDVI_DEV_NMI_PASS_MASK (1UL << 58) +#define AMDVI_DEV_LINT0_PASS_MASK (1UL << 62) +#define AMDVI_DEV_LINT1_PASS_MASK (1UL << 63) + +/* Interrupt remapping table fields (Guest VAPIC not enabled) */ +union irte { +uint32_t val; +struct { +uint32_t valid:1 , + no_fault:1 , + int_type:3 , + rq_eoi:1 , + dm:1 , + guest_mode:1 , + destination:8 , + vector:8 , + rsvd:8 ; + } fields; +};#define TYPE_AMD_IOMMU_DEVICE "amd-iommu"#define AMD_IOMMU_DEVICE (obj)\
hw/i386/amd_iommu.c +198 -1
235 lines not on this page · raw message
hw/i386/trace-events +7 -0
@@ -106,6 +106,13 @@ amdvi_mem_ir_write(uint64_t addr, uint64_t val) "addr 0x%"PRIx64" data 0x%"PRIx6 amdvi_ir_remap_msi_req(uint64_t addr, uint64_t data, uint8_t devid) "addr 0x%"PRIx64" data 0x%"PRIx64" devid 0x%"PRIx8 amdvi_ir_remap_msi(uint64_t addr, uint64_t data, uint64_t addr2, uint64_t data2) "(addr 0x%"PRIx64", data 0x%"PRIx64") -> (addr 0x%"PRIx64", data 0x%"PRIx64")" amdvi_err(const char *str) "%s" +amdvi_ir_irte(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" offset 0x%"PRIx64 +amdvi_ir_irte_val(uint32_t data) "data 0x%"PRIx32 +amdvi_ir_err(const char *str) "%s" +amdvi_ir_intctl(uint8_t val) "int_ctl 0x%"PRIx8 +amdvi_ir_target_abort(const char *str) "%s" +amdvi_ir_delivery_mode(const char *str) "%s" +amdvi_ir_generate_msi_message(uint8_t vector, uint8_t delivery_mode, uint8_t dest_mode, uint8_t dest, uint8_t rh) "vector %d delivery-mode %d dest-mode %d dest-id %d rh %d" # hw/i386/vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p"
Signature · 1 line
MST
[Qemu-devel] [PULL 14/28] x86_iommu/amd: Add interrupt remap support when VAPIC is enabled
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Emulate the interrupt remapping support when guest virtual APIC is enabled.
For more information refer: IOMMU spec rev 3.0 (section 2.2.5.2)
When VAPIC is enabled, it uses interrupt remapping as defined in Table 22 and Figure 17 from IOMMU spec.
--- hw/i386/amd_iommu.h | 36 +++++++++++++++++++++++ hw/i386/amd_iommu.c | 69 +++++++++++++++++++++++++++++++++++++++++++- hw/i386/trace-events | 2 ++ 3 files changed, 106 insertions(+), 1 deletion(-)
hw/i386/amd_iommu.h +36 -0
@@ -103,6 +103,7 @@#define AMDVI_MMIO_CONTROL_EVENTINTEN (1ULL << 3)#define AMDVI_MMIO_CONTROL_COMWAITINTEN (1ULL << 4)#define AMDVI_MMIO_CONTROL_CMDBUFLEN (1ULL << 12) +#define AMDVI_MMIO_CONTROL_GAEN (1ULL << 17)/* MMIO status register bits */ #define AMDVI_MMIO_STATUS_CMDBUF_RUN (1 << 4)
@@ -263,6 +264,38 @@ union irte { } fields; }; +/* Interrupt remapping table fields (Guest VAPIC is enabled) */ +union irte_ga_lo { +uint64_t val; + +/* For int remapping */ +struct { +uint64_t valid:1 , + no_fault:1 , +/* ------ */ + int_type:3 , + rq_eoi:1 , + dm:1 , +/* ------ */ + guest_mode:1 , + destination:8 , + rsvd_1:48 ; + } fields_remap; +}; + +union irte_ga_hi { +uint64_t val; +struct { +uint64_t vector:8 , + rsvd_2:56 ; + } fields; +}; + +struct irte_ga { +union irte_ga_lo lo; +union irte_ga_hi hi; +}; +#define TYPE_AMD_IOMMU_DEVICE "amd-iommu"#define AMD_IOMMU_DEVICE (obj)\ OBJECT_CHECK(AMDVIState, (obj), TYPE_AMD_IOMMU_DEVICE)
@@ -332,6 +365,9 @@ typedef struct AMDVIState {/* IOTLB */ GHashTable *iotlb; + +/* Interrupt remapping */ + bool ga_enabled; } AMDVIState;#endif
hw/i386/amd_iommu.c +68 -1
93 lines not on this page · raw message
hw/i386/trace-events +2 -0
@@ -113,6 +113,8 @@ amdvi_ir_intctl(uint8_t val) "int_ctl 0x%"PRIx8 amdvi_ir_target_abort(const char *str) "%s" amdvi_ir_delivery_mode(const char *str) "%s" amdvi_ir_generate_msi_message(uint8_t vector, uint8_t delivery_mode, uint8_t dest_mode, uint8_t dest, uint8_t rh) "vector %d delivery-mode %d dest-mode %d dest-id %d rh %d" +amdvi_ir_irte_ga(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" offset 0x%"PRIx64 +amdvi_ir_irte_ga_val(uint64_t hi, uint64_t lo) "hi 0x%"PRIx64" lo 0x%"PRIx64 # hw/i386/vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p"
Signature · 1 line
MST
[Qemu-devel] [PULL 15/28] x86_iommu/amd: Enable Guest virtual APIC support
In reply to Michael S. TsirkinFrom: "Singh, Brijesh" <[email protected]>
Now that amd-iommu support interrupt remapping, enable the GASup in IVRS table and GASup in extended feature register to indicate that IOMMU support guest virtual APIC mode. GASup provides option to guest OS to make use of 128-bit IRTE.
Note that the GAMSup is set to zero to indicate that amd-iommu does not support guest virtual APIC mode (aka AVIC) which would be used for the nested VMs.
See Table 21 from IOMMU spec for interrupt virtualization controls
--- hw/i386/amd_iommu.h | 2 +- hw/i386/acpi-build.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
hw/i386/amd_iommu.h +1 -1
@@ -176,7 +176,7 @@/* 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) + AMDVI_GATS_MODE | AMDVI_HATS_MODE | AMDVI_FEATURE_GA)/* capabilities header */ #define AMDVI_CAPAB_FEATURES (AMDVI_CAPAB_FLAT_EXT | \
hw/i386/acpi-build.c +2 -1
@@ -2518,7 +2518,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)build_append_int_noprefix (table_data, (48UL <<30 ) |/* HATS */ (48UL <<28 ) |/* GATS */ - (1UL <<2 ),/* GTSup */ + (1UL <<2 ) |/* GTSup */ + (1UL <<6 ),/* GASup */ 4 );/* * Type 1 device entry reporting all devices
Signature · 1 line
MST
[Qemu-devel] [PULL 18/28] hw/pci-host/x86: extract get_pci_hole64_start_value() helpers
In reply to Michael S. TsirkinFrom: Laszlo Ersek <[email protected]>
Expose the calculated "hole64 start" GPAs as plain uint64_t values, extracting the internals of the current property getters.
This patch doesn't change behavior.
--- hw/pci-host/piix.c | 15 +++++++++++---- hw/pci-host/q35.c | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-)
hw/pci-host/piix.c +11 -4
@@ -249,9 +249,7 @@ static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v,* the 64bit PCI hole will start after "over 4G RAM" and the * reserved space for memory hotplug if any. */ -static void i440fx_pcihost_get_pci_hole64_start (Object *obj,Visitor *v, -const char *name, -void *opaque,Error **errp) +static uint64_t i440fx_pcihost_get_pci_hole64_start_value (Object *obj) {PCIHostState *h =PCI_HOST_BRIDGE (obj);I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj);
@@ -263,7 +261,16 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v,if (!value && s->pci_hole64_fix) { value =pc_pci_hole64_start (); } -visit_type_uint64 (v, name, &value, errp); +return value; +} + +static void i440fx_pcihost_get_pci_hole64_start (Object *obj,Visitor *v, +const char *name, +void *opaque,Error **errp) +{ +uint64_t hole64_start =i440fx_pcihost_get_pci_hole64_start_value (obj); + +visit_type_uint64 (v, name, &hole64_start, errp); }/*
hw/pci-host/q35.c +11 -4
@@ -113,9 +113,7 @@ static void q35_host_get_pci_hole_end(Object *obj, Visitor *v,* the 64bit PCI hole will start after "over 4G RAM" and the * reserved space for memory hotplug if any. */ -static void q35_host_get_pci_hole64_start (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) +static uint64_t q35_host_get_pci_hole64_start_value (Object *obj) {PCIHostState *h =PCI_HOST_BRIDGE (obj);Q35PCIHost *s =Q35_HOST_DEVICE (obj);
@@ -127,7 +125,16 @@ static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v,if (!value && s->pci_hole64_fix) { value =pc_pci_hole64_start (); } -visit_type_uint64 (v, name, &value, errp); +return value; +} + +static void q35_host_get_pci_hole64_start (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +uint64_t hole64_start =q35_host_get_pci_hole64_start_value (obj); + +visit_type_uint64 (v, name, &hole64_start, errp); }/*
Signature · 1 line
MST
[Qemu-devel] [PULL 19/28] hw/pci-host/x86: extend the 64-bit PCI hole relative to the fw-assigned base
In reply to Michael S. TsirkinFrom: Laszlo Ersek <[email protected]>
In commit 9fa99d2519cb ("hw/pci-host: Fix x86 Host Bridges 64bit PCI hole", 2017-11-16), we meant to expose such a 64-bit PCI MMIO aperture in the ACPI DSDT that would be at least as large as the new "pci-hole64-size" property (2GB on i440fx, 32GB on q35). The goal was to offer "enough" 64-bit MMIO aperture to the guest OS for hotplug purposes.
In that commit, we added or modified five functions:
- pc_pci_hole64_start(): shared between i440fx and q35. Provides a default 64-bit base, which starts beyond the cold-plugged 64-bit RAM, and skips the DIMM hotplug area too (if any).
- i440fx_pcihost_get_pci_hole64_start(), q35_host_get_pci_hole64_start():
board-specific 64-bit base property getters called abstractly by the ACPI generator. Both of these fall back to pc_pci_hole64_start() if the firmware didn't program any 64-bit hole (i.e. if the firmware didn't assign a 64-bit GPA to any MMIO BAR on any device). Otherwise, they honor the firmware's BAR assignments (i.e., they treat the lowest 64-bit GPA programmed by the firmware as the base address for the aperture).
- i440fx_pcihost_get_pci_hole64_end(), q35_host_get_pci_hole64_end():
these intended to extend the aperture to our size recommendation, calculated relative to the base of the aperture.
Despite the original intent, i440fx_pcihost_get_pci_hole64_end() and q35_host_get_pci_hole64_end() currently only extend the aperture relative to the default base (pc_pci_hole64_start()), ignoring any programming done by the firmware. This means that our size recommendation may not be met. Fix it by honoring the firmware's address assignments.
The strange extension sizes were spotted by Alex, in the log of a guest kernel running on top of OVMF (which prefers to assign 64-bit GPAs to 64-bit BARs).
This change only affects DSDT generation, therefore no new compat property is being introduced.
Using an i440fx OVMF guest with 5GB RAM, an example _CRS change is:
Review line 889
Quoted 12 lines
(quoted diff) +2
-2@@ -881,9 +881,9 @@ QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, 0x0000000000000000, // Granularity 0x0000000800000000, // Range Minimum - 0x000000080001C0FF, // Range Maximum + 0x000000087FFFFFFF, // Range Maximum 0x0000000000000000, // Translation Offset - 0x000000000001C100, // Length + 0x0000000080000000, // Length ,, , AddressRangeMemory, TypeStatic) }) Device (GPE0)
(On i440fx, the low RAM split is at 3GB, in this case. Therefore, with 5GB guest RAM and no DIMM hotplug range, pc_pci_hole64_start() returns 4 + (5-3) = 6 GB. Adding the 2GB extension to that yields 8GB, which is below the firmware-programmed base of 32GB, before the patch. Therefore, before the patch, the extension is ineffective. After the patch, we add the 2GB extension to the firmware-programmed base, namely 32GB.)
Using a q35 OVMF guest with 5GB RAM, an example _CRS change is:
Review line 3170
Quoted 12 lines
(quoted diff) +2
-2@@ -3162,9 +3162,9 @@ QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, 0x0000000000000000, // Granularity 0x0000000800000000, // Range Minimum - 0x00000009BFFFFFFF, // Range Maximum + 0x0000000FFFFFFFFF, // Range Maximum 0x0000000000000000, // Translation Offset - 0x00000001C0000000, // Length + 0x0000000800000000, // Length ,, , AddressRangeMemory, TypeStatic) }) Device (GPE0)
(On Q35, the low RAM split is at 2GB. Therefore, with 5GB guest RAM and no DIMM hotplug range, pc_pci_hole64_start() returns 4 + (5-2) = 7 GB. Adding the 32GB extension to that yields 39GB (0x0000_0009_BFFF_FFFF + 1), before the patch. After the patch, we add the 32GB extension to the firmware-programmed base, namely 32GB.)
The ACPI test data for the bios-tables-test case that we added earlier in this series are corrected too, as follows:
Review line 3347
Quoted 12 lines
(quoted diff) +2
-2@@ -3339,9 +3339,9 @@ QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, 0x0000000000000000, // Granularity 0x0000000200000000, // Range Minimum - 0x00000009BFFFFFFF, // Range Maximum + 0x00000009FFFFFFFF, // Range Maximum 0x0000000000000000, // Translation Offset - 0x00000007C0000000, // Length + 0x0000000800000000, // Length ,, , AddressRangeMemory, TypeStatic) }) Device (GPE0)
--- hw/pci-host/piix.c | 2 +- hw/pci-host/q35.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +1 -1
@@ -285,7 +285,7 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, {PCIHostState *h =PCI_HOST_BRIDGE (obj);I440FXState *s =I440FX_PCI_HOST_BRIDGE (obj); -uint64_t hole64_start =pc_pci_hole64_start (); +uint64_t hole64_start =i440fx_pcihost_get_pci_hole64_start_value (obj);Range w64;uint64_t value, hole64_end;
hw/pci-host/q35.c +1 -1
@@ -149,7 +149,7 @@ static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v, {PCIHostState *h =PCI_HOST_BRIDGE (obj);Q35PCIHost *s =Q35_HOST_DEVICE (obj); -uint64_t hole64_start =pc_pci_hole64_start (); +uint64_t hole64_start =q35_host_get_pci_hole64_start_value (obj);Range w64;uint64_t value, hole64_end;
Signature · 1 line
MST
[Qemu-devel] [PULL 21/28] hw/pci-bridge/xio3130: Remove unused functions
In reply to Michael S. TsirkinFrom: Philippe Mathieu-Daudé <[email protected]>
Introduced in 48ebf2f90f8 and faf1e708d5b, these functions were never used. Remove them.
--- hw/pci-bridge/xio3130_downstream.h | 11 ----------- hw/pci-bridge/xio3130_upstream.h | 10 ---------- hw/pci-bridge/xio3130_downstream.c | 28 +--------------------------- hw/pci-bridge/xio3130_upstream.c | 24 +----------------------- 4 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 hw/pci-bridge/xio3130_downstream.h delete mode 100644 hw/pci-bridge/xio3130_upstream.h
hw/pci-bridge/xio3130_downstream.h deleted +0 -11
@@ -1,11 +0,0 @@ -#ifndef QEMU_XIO3130_DOWNSTREAM_H -#define QEMU_XIO3130_DOWNSTREAM_H - -#include "hw/pci/pcie_port.h" - -PCIESlot *xio3130_downstream_init (PCIBus *bus,int devfn,bool multifunction, -const char *bus_name,pci_map_irq_fn map_irq, -uint8_t port,uint8_t chassis, -uint16_t slot); - -#endif /* QEMU_XIO3130_DOWNSTREAM_H */
hw/pci-bridge/xio3130_upstream.h deleted +0 -10
@@ -1,10 +0,0 @@ -#ifndef QEMU_XIO3130_UPSTREAM_H -#define QEMU_XIO3130_UPSTREAM_H - -#include "hw/pci/pcie_port.h" - -PCIEPort *xio3130_upstream_init (PCIBus *bus,int devfn,bool multifunction, -const char *bus_name,pci_map_irq_fn map_irq, -uint8_t port); - -#endif /* QEMU_XIO3130_UPSTREAM_H */
hw/pci-bridge/xio3130_downstream.c +1 -27
@@ -23,7 +23,7 @@#include "hw/pci/pci_ids.h" #include "hw/pci/msi.h" #include "hw/pci/pcie.h" -#include "xio3130_downstream.h" +#include "hw/pci/pcie_port.h" #include "qapi/error.h" #define PCI_DEVICE_ID_TI_XIO3130D 0x8233/* downstream port */
@@ -127,32 +127,6 @@ static void xio3130_downstream_exitfn(PCIDevice *d)pci_bridge_exitfn (d); } -PCIESlot *xio3130_downstream_init (PCIBus *bus,int devfn,bool multifunction, -const char *bus_name,pci_map_irq_fn map_irq, -uint8_t port,uint8_t chassis, -uint16_t slot) -{ -PCIDevice *d; -PCIBridge *br; -DeviceState *qdev; - - d =pci_create_multifunction (bus, devfn, multifunction, -"xio3130-downstream" ); -if (!d) { -return NULL ; - } - br =PCI_BRIDGE (d); - - qdev =DEVICE (d); -pci_bridge_map_irq (br, bus_name, map_irq); -qdev_prop_set_uint8 (qdev,"port" , port); -qdev_prop_set_uint8 (qdev,"chassis" , chassis); -qdev_prop_set_uint16 (qdev,"slot" , slot); -qdev_init_nofail (qdev); - -return PCIE_SLOT (d); -} -static Property xio3130_downstream_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true),
hw/pci-bridge/xio3130_upstream.c +1 -23
@@ -23,7 +23,7 @@#include "hw/pci/pci_ids.h" #include "hw/pci/msi.h" #include "hw/pci/pcie.h" -#include "xio3130_upstream.h" +#include "hw/pci/pcie_port.h" #define PCI_DEVICE_ID_TI_XIO3130U 0x8232/* upstream port */ #define XIO3130_REVISION 0x2
@@ -108,28 +108,6 @@ static void xio3130_upstream_exitfn(PCIDevice *d)pci_bridge_exitfn (d); } -PCIEPort *xio3130_upstream_init (PCIBus *bus,int devfn,bool multifunction, -const char *bus_name,pci_map_irq_fn map_irq, -uint8_t port) -{ -PCIDevice *d; -PCIBridge *br; -DeviceState *qdev; - - d =pci_create_multifunction (bus, devfn, multifunction,"x3130-upstream" ); -if (!d) { -return NULL ; - } - br =PCI_BRIDGE (d); - - qdev =DEVICE (d); -pci_bridge_map_irq (br, bus_name, map_irq); -qdev_prop_set_uint8 (qdev,"port" , port); -qdev_init_nofail (qdev); - -return PCIE_PORT (d); -} -static const VMStateDescription vmstate_xio3130_upstream = { .name ="xio3130-express-upstream-port" , .priority =MIG_PRI_PCI_BUS ,
Signature · 1 line
MST
[Qemu-devel] [PULL 22/28] hw/pci-bridge/ioh3420: Remove unuseful header
In reply to Michael S. TsirkinFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/pci-bridge/ioh3420.h | 6 ------ hw/pci-bridge/ioh3420.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 hw/pci-bridge/ioh3420.h
hw/pci-bridge/ioh3420.h deleted +0 -6
@@ -1,6 +0,0 @@ -#ifndef QEMU_IOH3420_H -#define QEMU_IOH3420_H - -#include "hw/pci/pcie_port.h" - -#endif /* QEMU_IOH3420_H */
hw/pci-bridge/ioh3420.c +1 -1
@@ -24,7 +24,7 @@#include "hw/pci/pci_ids.h" #include "hw/pci/msi.h" #include "hw/pci/pcie.h" -#include "ioh3420.h" +#include "hw/pci/pcie_port.h" #define PCI_DEVICE_ID_IOH_EPORT 0x3420/* D0:F0 express mode */ #define PCI_DEVICE_ID_IOH_REV 0x2
Signature · 1 line
MST
[Qemu-devel] [PULL 23/28] hw/pci: Add missing include
In reply to Michael S. TsirkinFrom: Philippe Mathieu-Daudé <[email protected]>
Noted while refactoring:
CC mips-softmmu/hw/mips/gt64xxx_pci.o
In file included from include/hw/pci-host/gt64xxx.h:2,
from hw/mips/gt64xxx_pci.c:30:
include/hw/pci/pci_bus.h:23:5: error: unknown type name ‘PCIIOMMUFunc’
PCIIOMMUFunc iommu_fn;
^~~~~~~~~~~~
include/hw/pci/pci_bus.h:27:5: error: unknown type name ‘pci_set_irq_fn’
pci_set_irq_fn set_irq;
^~~~~~~~~~~~~~
include/hw/pci/pci_bus.h:28:5: error: unknown type name ‘pci_map_irq_fn’
pci_map_irq_fn map_irq;
^~~~~~~~~~~~~~
include/hw/pci/pci_bus.h:29:5: error: unknown type name ‘pci_route_irq_fn’
pci_route_irq_fn route_intx_to_irq;
^~~~~~~~~~~~~~~~
include/hw/pci/pci_bus.h:31:24: error: ‘PCI_SLOT_MAX’ undeclared here (not in a function)
PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX];
^~~~~~~~~~~~
include/hw/pci/pci_bus.h:31:39: error: ‘PCI_FUNC_MAX’ undeclared here (not in a function)
PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX];
^~~~~~~~~~~~
make[1]: *** [rules.mak:69: hw/mips/gt64xxx_pci.o] Error 1
make: *** [Makefile:482: subdir-mips-softmmu] Error 2--- include/hw/pci/pci_bus.h | 2 ++ 1 file changed, 2 insertions(+)
include/hw/pci/pci_bus.h +2 -0
@@ -1,6 +1,8 @@#ifndef QEMU_PCI_BUS_H #define QEMU_PCI_BUS_H +#include "hw/pci/pci.h" +/* * PCI Bus datastructures. *
Signature · 1 line
MST
[Qemu-devel] [PULL 27/28] piix_pci: fix i440fx data sheet link
In reply to Michael S. TsirkinFrom: Li Qiang <[email protected]>
It seems that the intel link is unavailable, change it to point to the qemu site.
--- hw/pci-host/piix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-host/piix.c +1 -1
@@ -40,7 +40,7 @@/* * I440FX chipset data sheet. -* http://download.intel.com/design/chipsets/datashts/29054901.pdf +* https://wiki.qemu.org/File:29054901.pdf */ #define I440FX_PCI_HOST_BRIDGE (obj) \
Signature · 1 line
MST
[Qemu-devel] [PULL 28/28] vhost-scsi: prevent using uninitialized vqs
In reply to Michael S. TsirkinFrom: yuchenlin <[email protected]>
There are 3 virtqueues (ctrl, event and cmd) for virtio scsi device, but seabios will only set the physical address for the 3rd one (cmd). Then in vhost_virtqueue_start(), virtio_queue_get_desc_addr() will be 0 for ctrl and event vq.
In this case, ctrl and event vq are not initialized. vhost_verify_ring_mappings may use uninitialized vhost_virtqueue such that vhost_verify_ring_part_mapping returns ENOMEM.
When encountered this problem, we got the following logs:
qemu-system-x86_64: Unable to map available ring for ring 0
qemu-system-x86_64: Verify ring failure on region 0
--- hw/scsi/vhost-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/vhost-scsi.c +1 -1
@@ -183,7 +183,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) } vsc->dev.nvqs =VHOST_SCSI_VQ_NUM_FIXED + vs->conf.num_queues; - vsc->dev.vqs = g_new(struct vhost_virtqueue, vsc->dev.nvqs); + vsc->dev.vqs = g_new0(struct vhost_virtqueue, vsc->dev.nvqs); vsc->dev.vq_index =0 ; vsc->dev.backend_features =0 ;
Signature · 1 line
MST
[Qemu-devel] [PULL 03/28] intel_iommu: better handling of dmar state switch
In reply to Michael S. TsirkinFrom: Peter Xu <[email protected]>
QEMU is not handling the global DMAR switch well, especially when from "on" to "off".
Let's first take the example of system reset.
Assuming that a guest has IOMMU enabled. When it reboots, we will drop all the existing DMAR mappings to handle the system reset, however we'll still keep the existing memory layouts which has the IOMMU memory region enabled. So after the reboot and before the kernel reloads again, there will be no mapping at all for the host device. That's problematic since any software (for example, SeaBIOS) that runs earlier than the kernel after the reboot will assume the IOMMU is disabled, so any DMA from the software will fail.
For example, a guest that boots on an assigned NVMe device might fail to find the boot device after a system reboot/reset and we'll be able to observe SeaBIOS errors if we capture the debugging log:
WARNING - Timeout at nvme_wait:144!
Meanwhile, we should see DMAR errors on the host of that NVMe device. It's the DMA fault that caused a NVMe driver timeout.
The correct fix should be that we do proper switching of device DMA address spaces when system resets, which will setup correct memory regions and notify the backend of the devices. This might not affect much on non-assigned devices since QEMU VT-d emulation will assume a default passthrough mapping if DMAR is not enabled in the GCMD register (please refer to vtd_iommu_translate). However that's required for an assigned devices, since that'll rebuild the correct GPA to HPA mapping that is needed for any DMA operation during guest bootstrap.
Besides the system reset, we have some other places that might change the global DMAR status and we'd better do the same thing there. For example, when we change the state of GCMD register, or the DMAR root pointer. Do the same refresh for all these places. For these two places we'll also need to explicitly invalidate the context entry cache and iotlb cache.
--
v2:
- do the same for GCMD write, or root pointer update [Alex]
- test is carried out by me this time, by observing the vtd_switch_address_space tracepoint after system reboot
v3:
- rewrite commit message as suggested by Alex
--- hw/i386/intel_iommu.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
hw/i386/intel_iommu.c +14 -7
@@ -37,6 +37,8 @@#include "kvm_i386.h" #include "trace.h" +static void vtd_address_space_refresh_all (IntelIOMMUState *s); +static void vtd_define_quad (IntelIOMMUState *s,hwaddr addr,uint64_t val,uint64_t wmask,uint64_t w1cmask) {
@@ -1436,7 +1438,7 @@ static void vtd_context_global_invalidate(IntelIOMMUState *s)vtd_reset_context_cache_locked (s); }vtd_iommu_unlock (s); -vtd_switch_address_space_all (s); +vtd_address_space_refresh_all (s);/* * From VT-d spec 6.5.2.1, a global context entry invalidation * should be followed by a IOTLB global invalidation, so we should
@@ -1727,6 +1729,8 @@ static void vtd_handle_gcmd_srtp(IntelIOMMUState *s)vtd_root_table_setup (s);/* Ok - report back to driver */ vtd_set_clear_mask_long (s,DMAR_GSTS_REG ,0 ,VTD_GSTS_RTPS ); +vtd_reset_caches (s); +vtd_address_space_refresh_all (s); }/* Set Interrupt Remap Table Pointer */
@@ -1759,7 +1763,8 @@ static void vtd_handle_gcmd_te(IntelIOMMUState *s, bool en)vtd_set_clear_mask_long (s,DMAR_GSTS_REG ,VTD_GSTS_TES ,0 ); } -vtd_switch_address_space_all (s); +vtd_reset_caches (s); +vtd_address_space_refresh_all (s); }/* Handle Interrupt Remap Enable/Disable */
@@ -3059,6 +3064,12 @@ static void vtd_address_space_unmap_all(IntelIOMMUState *s) } } +static void vtd_address_space_refresh_all (IntelIOMMUState *s) +{ +vtd_address_space_unmap_all (s); +vtd_switch_address_space_all (s); +} +static int vtd_replay_hook (IOMMUTLBEntry *entry,void *private) {memory_region_notify_one ((IOMMUNotifier *)private, entry);
@@ -3231,11 +3242,7 @@ static void vtd_reset(DeviceState *dev)IntelIOMMUState *s =INTEL_IOMMU_DEVICE (dev);vtd_init (s); - -/* -* When device reset, throw away all mappings and external caches -*/ -vtd_address_space_unmap_all (s); +vtd_address_space_refresh_all (s); }static AddressSpace *vtd_host_dma_iommu (PCIBus *bus,void *opaque,int devfn)
Signature · 1 line
MST
[Qemu-devel] [PULL 20/28] tests/bios-tables-test: add 64-bit PCI MMIO aperture round-up test on Q35
In reply to Michael S. TsirkinFrom: Laszlo Ersek <[email protected]>
In commit 9fa99d2519cb ("hw/pci-host: Fix x86 Host Bridges 64bit PCI hole", 2017-11-16), we meant to expose such a 64-bit PCI MMIO aperture in the ACPI DSDT that would be at least as large as the new "pci-hole64-size" property (2GB on i440fx, 32GB on q35). The goal was to offer "enough" 64-bit MMIO aperture to the guest OS for hotplug purposes.
Currently the aperture is extended relative to a possibly incorrect base. This may result in an aperture size that is smaller than the intent of commit 9fa99d2519cb.
We're going to fix the error in a later patch in this series; now we just add a test case that reproduces and captures the problem. In the fix, the test data will be updated as well.
In the test case being added:
- use 128 MB initial RAM size,
- ask for one DIMM hotplug slot,
- ask for 2 GB maximum RAM size,
- use a pci-testdev with a 64-bit BAR of 2 GB size.
Consequences:
(1) In pc_memory_init() [hw/i386/pc.c], the DIMM hotplug area size is initially set to 2048-128 = 1920 MB. (Maximum RAM size minus initial RAM size.)
(2) The DIMM area base is set to 4096 MB (because the initial RAM is only 128 MB -- there is no initial "high RAM").
(3) Due to commit 085f8e88ba73 ("pc: count in 1Gb hugepage alignment when sizing hotplug-memory container", 2014-11-24), we add 1 GB for the one DIMM hotplug slot that was specified. This sets the DIMM area size to 1920+1024 = 2944 MB.
(4) The reserved-memory-end address (exclusive) is set to 4096 + 2944 = 7040 MB (DIMM area base plus DIMM area size).
(5) The reserved-memory-end address is rounded up to GB alignment,
yielding 7 GB (7168 MB).
(6) Given the 2 GB BAR size of pci-testdev, SeaBIOS allocates said 64-bit BAR in 64-bit address space.
(7) Because reserved-memory-end is at 7 GB, it is unaligned for the 2 GB BAR. Therefore SeaBIOS allocates the BAR at 8 GB. QEMU then (correctly) assigns the root bridge aperture base this BAR address, to be exposed in \_SB.PCI0._CRS.
(8) The intent of commit 9fa99d2519cb dictates that QEMU extend the aperture size to 32 GB, implying a 40 GB end address. However, QEMU performs the extension relative to reserved-memory-end (7 GB), not relative to the bridge aperture base that was correctly deduced from SeaBIOS's BAR programming (8 GB). Therefore we see 39 GB as the aperture end address in \_SB.PCI0._CRS:
Quoted 7 lines
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity 0x0000000200000000, // Range Minimum 0x00000009BFFFFFFF, // Range Maximum 0x0000000000000000, // Translation Offset 0x00000007C0000000, // Length ,, , AddressRangeMemory, TypeStatic)
--- tests/bios-tables-test.c | 16 ++++++++++++++++ tests/acpi-test-data/q35/DSDT.mmio64 | Bin 0 -> 8947 bytes tests/acpi-test-data/q35/SRAT.mmio64 | Bin 0 -> 224 bytes 3 files changed, 16 insertions(+) create mode 100644 tests/acpi-test-data/q35/DSDT.mmio64 create mode 100644 tests/acpi-test-data/q35/SRAT.mmio64
tests/bios-tables-test.c +16 -0
@@ -708,6 +708,21 @@ static void test_acpi_q35_tcg_bridge(void)free_test_data (&data); } +static void test_acpi_q35_tcg_mmio64 (void ) +{ +test_data data = { + .machine =MACHINE_Q35 , + .variant =".mmio64" , + .required_struct_types = base_required_struct_types, + .required_struct_types_len =ARRAY_SIZE (base_required_struct_types) + }; + +test_acpi_one ("-m 128M,slots=1,maxmem=2G " +"-device pci-testdev,membar=2G" , + &data); +free_test_data (&data); +} +static void test_acpi_piix4_tcg_cphp (void ) {test_data data;
@@ -875,6 +890,7 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/piix4/bridge" , test_acpi_piix4_tcg_bridge);qtest_add_func ("acpi/q35" , test_acpi_q35_tcg);qtest_add_func ("acpi/q35/bridge" , test_acpi_q35_tcg_bridge); +qtest_add_func ("acpi/q35/mmio64" , test_acpi_q35_tcg_mmio64);qtest_add_func ("acpi/piix4/ipmi" , test_acpi_piix4_tcg_ipmi);qtest_add_func ("acpi/q35/ipmi" , test_acpi_q35_tcg_ipmi);qtest_add_func ("acpi/piix4/cpuhp" , test_acpi_piix4_tcg_cphp);
tests/acpi-test-data/q35/DSDT.mmio64 new file binary +0 -0
tests/acpi-test-data/q35/SRAT.mmio64 new file binary +0 -0
Signature · 1 line
MST
[Qemu-devel] [PULL 26/28] piix: use TYPE_FOO constants than string constats
In reply to Michael S. TsirkinFrom: Li Qiang <[email protected]>
Make them more QOMConventional.
Cc:[email protected]
--- hw/pci-host/piix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/pci-host/piix.c +7 -4
@@ -95,6 +95,9 @@ typedef struct PIIX3State {#define I440FX_PCI_DEVICE (obj) \ OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) +#define TYPE_PIIX3_DEVICE "PIIX3" +#define TYPE_PIIX3_XEN_DEVICE "PIIX3-xen" +struct PCII440FXState {/*< private >*/ PCIDevice parent_obj;
@@ -424,13 +427,13 @@ PCIBus *i440fx_init(const char *host_type, const char *pci_type,* These additional routes can be discovered through ACPI. */ if (xen_enabled ()) {PCIDevice *pci_dev =pci_create_simple_multifunction (b, --1 , true,"PIIX3-xen" ); +-1 , true,TYPE_PIIX3_XEN_DEVICE ); piix3 =PIIX3_PCI_DEVICE (pci_dev);pci_bus_irqs (b, xen_piix3_set_irq, xen_pci_slot_get_pirq, piix3,XEN_PIIX_NUM_PIRQS ); }else {PCIDevice *pci_dev =pci_create_simple_multifunction (b, --1 , true,"PIIX3" ); +-1 , true,TYPE_PIIX3_DEVICE ); piix3 =PIIX3_PCI_DEVICE (pci_dev);pci_bus_irqs (b, piix3_set_irq, pci_slot_get_pirq, piix3,PIIX_NUM_PIRQS );
@@ -748,7 +751,7 @@ static void piix3_class_init(ObjectClass *klass, void *data) }static const TypeInfo piix3_info = { - .name ="PIIX3" , + .name =TYPE_PIIX3_DEVICE , .parent =TYPE_PIIX3_PCI_DEVICE , .class_init = piix3_class_init, };
@@ -761,7 +764,7 @@ static void piix3_xen_class_init(ObjectClass *klass, void *data) };static const TypeInfo piix3_xen_info = { - .name ="PIIX3-xen" , + .name =TYPE_PIIX3_XEN_DEVICE , .parent =TYPE_PIIX3_PCI_DEVICE , .class_init = piix3_xen_class_init, };
Signature · 1 line
MST
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
13399aad4fa87b2878c49d02a5d3bafa6c966ba3:Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-10-22' into staging (2018-10-23 17:20:23 +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
57b279df457c2c4ef66ce9e1b813df35abde69f7:vhost-scsi: prevent using uninitialized vqs (2018-10-23 19:29:58 -0400)
----------------------------------------------------------------
pci, pc, virtio: fixes, features
Quoted 7 lines
AMD IOMMU VAPIC support + fixes all over the place.
Signed-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
dtc | 2 +-
Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.
Could you fix that and resubmit, please?
thanks
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 1 line
dtc | 2 +-Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "
intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.Could you fix that and resubmit, please?
It's my fault.
Michael, please let me know if you want me to post that single patch again without that.
Regards,
Signature · 1 line
Peter Xu
Quoted 8 lines · Peter Xu
Quoted 7 lines · Peter Maydell
Quoted 1 line
dtc | 2 +-Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "
intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.
Quoted 11 lines
Quoted 1 line
Could you fix that and resubmit, please?
It's my fault.
Michael, please let me know if you want me to post that single patch again without that.
Regards,
Signature · 1 line
Peter Xu
I'll try to fix it myself now.
Signature · 1 line
MST
Quoted 29 lines · Peter Maydell
Quoted 15 lines · Michael S. Tsirkin
The following changes since commit
13399aad4fa87b2878c49d02a5d3bafa6c966ba3:Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-10-22' into staging (2018-10-23 17:20:23 +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
57b279df457c2c4ef66ce9e1b813df35abde69f7:vhost-scsi: prevent using uninitialized vqs (2018-10-23 19:29:58 -0400)
----------------------------------------------------------------
pci, pc, virtio: fixes, featuresQuoted 7 lines
AMD IOMMU VAPIC support + fixes all over the place.
Signed-off-by Michael S. Tsirkin <[email protected]>----------------------------------------------------------------
dtc | 2 +-Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "
intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.
Quoted 4 lines
Could you fix that and resubmit, please?
thanks
-- PMM
Oh not again. At least now you have scripts that catch it, I should write a script for that too. Thanks and sorry.
Signature · 1 line
MST
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "
intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.Oh not again. At least now you have scripts that catch it, I should write a script for that too. Thanks and sorry.
The relevant part of my scripts is this bit:
https://git.linaro.org/people/peter.maydell/misc-scripts.git/tree/apply-pullreq?id=eeb001fcc1aabd8f077cd2846724120a3aa8f962#n107
Specifically,
if git diff master..staging | grep -q 'Subproject commit'; then
# there's a submodule update in this set of commits
fi
thanks
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Peter Maydell
Hi. This pull request seems to include an accidental update to the dtc submodule. It's in the "
intel_iommu: move ce fetching out when sync shadow" commit, and it's not mentioned in the commit message, so I am assuming it is unintentional.Oh not again. At least now you have scripts that catch it, I should write a script for that too. Thanks and sorry.
The relevant part of my scripts is this bit:
https://git.linaro.org/people/peter.maydell/misc-scripts.git/tree/apply-pullreq?id=eeb001fcc1aabd8f077cd2846724120a3aa8f962#n107
Quoted 8 lines
Specifically,
if git diff master..staging | grep -q 'Subproject commit'; then
# there's a submodule update in this set of commits
fithanks
-- PMM
Thanks added to my pull request script.
Signature · 1 line
MST