ARM SMMUv3: Fix spurious notification errors and fail with VFIO
v4 cover ARM SMMUv3: Fix spurious notification errors and fail with VFIO
As of today when a guest is assigned with a host PCI device and an SMMUv3, VFIO calls memory_region_iommu_replay() default implementation. This translates the whole address range and completely stalls the execution. As VFIO/SMMUv3 integration is not supported yet (it requires SMMUv3 HW nested paging), let's recognize this situation and fail.
Also the series silences some spurious translation configuration decoding errors (STE out of span or invalid STE) that may happen on guest IOVA invalidation notifications.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v4.1.0_smmu_vfio_fail_v4
History:
v3 -> v4:
- see individual patches
v2 -> v3:
- squash IOMMU_ATTR_VFIO_NESTED introduction and SMMUv3 usage
- assert when recognizing VFIO/NESTED case
- collect R-bs
v1 -> v2:
- Added "memory: Remove unused memory_region_iommu_replay_all()" & "hw/arm/smmuv3: Log a guest error when decoding an invalid STE"
- do not attempt to implement replay Cb but rather remove the call in case it is not needed
- explain why we do not remove other log messages on config decoding
Eric Auger (5):
memory: Remove unused memory_region_iommu_replay_all()
memory: Add IOMMU_ATTR_HW_NESTED_PAGING IOMMU memory region attribute hw/vfio/common: Fail on VFIO/HW nested paging detection hw/arm/smmuv3: Log a guest error when decoding an invalid STE hw/arm/smmuv3: Remove spurious error messages on IOVA invalidations
hw/arm/smmuv3-internal.h | 1 + hw/arm/smmuv3.c | 30 +++++++++++++++++++++++------- hw/vfio/common.c | 10 ++++++++++ include/exec/memory.h | 18 +++++++----------- memory.c | 9 --------- 5 files changed, 41 insertions(+), 27 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/5 memory: Remove unused memory_region_iommu_replay_all()
memory_region_iommu_replay_all is not used. Remove it.
--- include/exec/memory.h | 10 ---------- memory.c | 9 --------- 2 files changed, 19 deletions(-)
include/exec/memory.h +0 -10
@@ -1086,16 +1086,6 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr,*/ void memory_region_iommu_replay (IOMMUMemoryRegion *iommu_mr,IOMMUNotifier *n); -/** -* memory_region_iommu_replay_all: replay existing IOMMU translations -* to all the notifiers registered. -* -* Note: this is not related to record-and-replay functionality. -* -* @iommu_mr: the memory region to observe -*/ -void memory_region_iommu_replay_all (IOMMUMemoryRegion *iommu_mr); -/** * memory_region_unregister_iommu_notifier: unregister a notifier for * changes to IOMMU translation entries.
memory.c +0 -9
@@ -1915,15 +1915,6 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n) } } -void memory_region_iommu_replay_all (IOMMUMemoryRegion *iommu_mr) -{ -IOMMUNotifier *notifier; - - IOMMU_NOTIFIER_FOREACH(notifier, iommu_mr) { -memory_region_iommu_replay (iommu_mr, notifier); - } -} -void memory_region_unregister_iommu_notifier (MemoryRegion *mr,IOMMUNotifier *n) {
Signature · 1 line
2.20.1
PATCH v4 2/5 memory: Add IOMMU_ATTR_HW_NESTED_PAGING IOMMU memory region attribute
In reply to Eric AugerWe introduce a new IOMMU Memory Region attribute, IOMMU_ATTR_HW_NESTED_PAGING that tells whether the virtual IOMMU relies on physical IOMMU HW nested paging capability when protecting host assigned devices.
Current Intel virtual IOMMU device supports "Caching Mode" and does not require 2 stages at physical level to be integrated with VFIO. However SMMUv3 does not implement such "caching mode" and requires to use HW nested paging.
As such SMMUv3 is the first IOMMU device to advertise this attribute.
---
v3 -> v4:
- s/IOMMU_ATTR_VFIO_NESTED/IOMMU_ATTR_HW_NESTED_PAGING
- add comments related to the existing attributes
- fix space after the cast
--- hw/arm/smmuv3.c | 12 ++++++++++++ include/exec/memory.h | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
hw/arm/smmuv3.c +12 -0
@@ -1490,6 +1490,17 @@ static void smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu, } } +static int smmuv3_get_attr (IOMMUMemoryRegion *iommu, +enum IOMMUMemoryRegionAttr attr, +void *data) +{ +if (attr ==IOMMU_ATTR_HW_NESTED_PAGING ) { + *(bool *)data = true; +return 0 ; + } +return -EINVAL ; +} +static void smmuv3_iommu_memory_region_class_init (ObjectClass *klass,void *data) {
@@ -1497,6 +1508,7 @@ static void smmuv3_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = smmuv3_translate; imrc->notify_flag_changed = smmuv3_notify_flag_changed; + imrc->get_attr = smmuv3_get_attr; }static const TypeInfo smmuv3_type_info = {
include/exec/memory.h +7 -1
@@ -212,7 +212,13 @@ typedef struct MemoryRegionClass {enum IOMMUMemoryRegionAttr { -IOMMU_ATTR_SPAPR_TCE_FD +/* Retrieve an integer corresponding to the TCE file descriptor */ +IOMMU_ATTR_SPAPR_TCE_FD , +/* +* Retrieve a boolean that indicates whether the virtual IOMMU relies +* on physical IOMMU HW nested paging to protect host assigned devices +*/ +IOMMU_ATTR_HW_NESTED_PAGING , };/**
Signature · 1 line
2.20.1
Re: [Qemu-arm] [PATCH v4 2/5] memory: Add IOMMU_ATTR_HW_NESTED_PAGING IOMMU memory region attribute
Quoted 5 lines · Eric Auger
We introduce a new IOMMU Memory Region attribute,
IOMMU_ATTR_HW_NESTED_PAGINGthat tells whether the virtual IOMMU relies on physical IOMMU HW nested paging capability when protecting host assigned devices.
I'm still not really happy with the name of this attribute. "IOMMU_ATTR_HW_NESTED_PAGING" sounds like it ought to mean "true if this IOMMU supports/is using hardware nested paging". What your commit message suggests it means is "true if this IOMMU *needs* hardware nested paging", but there's no NEEDS in the attribute name.
Quoted 9 lines
Current Intel virtual IOMMU device supports "Caching Mode" and does not require 2 stages at physical level to be integrated with VFIO. However SMMUv3 does not implement such "caching mode" and requires to use HW nested paging.
As such SMMUv3 is the first IOMMU device to advertise this attribute.
Signed-off-by Eric Auger <[email protected]>
The code changes look good to me though.
thanks
-- PMM
Re: [Qemu-arm] [Qemu-devel] [PATCH v4 2/5] memory: Add IOMMU_ATTR_HW_NESTED_PAGING IOMMU memory region attribute
Hi Peter,
Quoted 7 lines · Peter Maydell
Quoted 5 lines · Eric Auger
We introduce a new IOMMU Memory Region attribute,
IOMMU_ATTR_HW_NESTED_PAGINGthat tells whether the virtual IOMMU relies on physical IOMMU HW nested paging capability when protecting host assigned devices.
Quoted 6 lines
I'm still not really happy with the name of this attribute. "
IOMMU_ATTR_HW_NESTED_PAGING" sounds like it ought to mean "true if this IOMMU supports/is using hardware nested paging". What your commit message suggests it means is "true if this IOMMU *needs* hardware nested paging", but there's no NEEDS in the attribute name.
OK I will respin and add "_NEED_".
Thanks
Eric
Quoted 16 lines
Quoted 10 lines
Current Intel virtual IOMMU device supports "Caching Mode" and does not require 2 stages at physical level to be integrated with VFIO. However SMMUv3 does not implement such "caching mode" and requires to use HW nested paging.
As such SMMUv3 is the first IOMMU device to advertise this attribute.
Signed-off-by Eric Auger <[email protected]>The code changes look good to me though.
thanks
-- PMM
PATCH v4 3/5 hw/vfio/common: Fail on VFIO/HW nested paging detection
In reply to Eric AugerAs of today, VFIO only works along with vIOMMU supporting caching mode. The SMMUv3 does not support this mode and requires HW nested paging to work properly with VFIO.
So any attempt to run a VFIO device protected by such IOMMU would prevent the assigned device from working and at the moment the guest does not even boot as the default memory_region_iommu_replay() implementation attempts to translate the whole address space and completely stalls the guest.
So let's fail on that case.
---
v3 -> v4:
- use IOMMU_ATTR_HW_NESTED_PAGING
- do not abort anymore but jump to fail
--- hw/vfio/common.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/vfio/common.c +10 -0
@@ -606,9 +606,19 @@ static void vfio_listener_region_add(MemoryListener *listener,if (memory_region_is_iommu (section->mr)) {VFIOGuestIOMMU *giommu;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); +bool nested;int iommu_idx;trace_vfio_listener_region_add_iommu (iova, end); + +if (!memory_region_iommu_get_attr (iommu_mr, +IOMMU_ATTR_HW_NESTED_PAGING , + (void *)&nested) && nested) { +error_report ("VFIO/vIOMMU integration based on HW nested paging " +"is not yet supported" ); + ret = -EINVAL ; + goto fail; + }/* * FIXME: For VFIO iommu types which have KVM acceleration to * avoid bouncing all map/unmaps through qemu this way, this
Signature · 1 line
2.20.1
PATCH v4 4/5 hw/arm/smmuv3: Log a guest error when decoding an invalid STE
In reply to Eric AugerLog a guest error when encountering an invalid STE.
--- hw/arm/smmuv3.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/smmuv3.c +1 -0
@@ -320,6 +320,7 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg,uint32_t config;if (!STE_VALID (ste)) { +qemu_log_mask (LOG_GUEST_ERROR ,"invalid STE\n" ); goto bad_ste; }
Signature · 1 line
2.20.1
PATCH v4 5/5 hw/arm/smmuv3: Remove spurious error messages on IOVA invalidations
In reply to Eric AugerAn IOVA/ASID invalidation is notified to all IOMMU Memory Regions through smmuv3_inv_notifiers_iova/smmuv3_notify_iova.
When the notification occurs it is possible that some of the PCIe devices associated to the notified regions do not have a valid stream table entry. In that case we output a LOG_GUEST_ERROR message, for example:
invalid sid=<SID> (L1STD span=0)
"smmuv3_notify_iova error decoding the configuration for iommu mr=<MR>
This is unfortunate as the user gets the impression that there are some translation decoding errors whereas there are not.
This patch adds a new field in SMMUEventInfo that tells whether the detection of an invalid STE must lead to an error report. invalid_ste_allowed is set before doing the invalidations and kept unset on actual translation.
The other configuration decoding error messages are kept since if the STE is valid then the rest of the config must be correct.
---
v3 -> v4:
- only remove the trace on !span path but keep the error value
--- hw/arm/smmuv3-internal.h | 1 + hw/arm/smmuv3.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-)
hw/arm/smmuv3-internal.h +1 -0
@@ -381,6 +381,7 @@ typedef struct SMMUEventInfo {uint32_t sid;bool recorded;bool record_trans_faults; +bool inval_ste_allowed; union { struct { uint32_t ssid;
hw/arm/smmuv3.c +11 -8
@@ -320,7 +320,9 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg,uint32_t config;if (!STE_VALID (ste)) { -qemu_log_mask (LOG_GUEST_ERROR ,"invalid STE\n" ); +if (!event->inval_ste_allowed) { +qemu_log_mask (LOG_GUEST_ERROR ,"invalid STE\n" ); + } goto bad_ste; }
@@ -407,8 +409,10 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste,if (!span) {/* l2ptr is not valid */ -qemu_log_mask (LOG_GUEST_ERROR , -"invalid sid=%d (L1STD span=0)\n" , sid); +if (!event->inval_ste_allowed) { +qemu_log_mask (LOG_GUEST_ERROR , +"invalid sid=%d (L1STD span=0)\n" , sid); + } event->type =SMMU_EVT_C_BAD_STREAMID ;return -EINVAL ; }
@@ -603,7 +607,9 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr,SMMUDevice *sdev =container_of (mr, SMMUDevice, iommu);SMMUv3State *s = sdev->smmu;uint32_t sid =smmu_get_sid (sdev); -SMMUEventInfo event = {.type =SMMU_EVT_NONE , .sid = sid}; +SMMUEventInfo event = {.type =SMMU_EVT_NONE , + .sid = sid, + .inval_ste_allowed = false};SMMUPTWEventInfo ptw_info = {};SMMUTranslationStatus status;SMMUState *bs =ARM_SMMU (s);
@@ -796,16 +802,13 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, dma_addr_t iova) {SMMUDevice *sdev =container_of (mr, SMMUDevice, iommu); -SMMUEventInfo event = {}; +SMMUEventInfo event = {.inval_ste_allowed = true};SMMUTransTableInfo *tt;SMMUTransCfg *cfg;IOMMUTLBEntry entry; cfg =smmuv3_get_config (sdev, &event);if (!cfg) { -qemu_log_mask (LOG_GUEST_ERROR , -"%s error decoding the configuration for iommu mr=%s\n" , - __func__, mr->parent_obj.name);return ; }
Signature · 1 line
2.20.1
Quoted 19 lines · Eric Auger
As of today when a guest is assigned with a host PCI device and an SMMUv3, VFIO calls
memory_region_iommu_replay()default implementation. This translates the whole address range and completely stalls the execution. As VFIO/SMMUv3 integration is not supported yet (it requires SMMUv3 HW nested paging), let's recognize this situation and fail.Also the series silences some spurious translation configuration decoding errors (STE out of span or invalid STE) that may happen on guest IOVA invalidation notifications.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v4.1.0_smmu_vfio_fail_v4
Quoted 6 lines
Eric Auger (5):
memory: Remove unusedmemory_region_iommu_replay_all()
memory: AddIOMMU_ATTR_HW_NESTED_PAGINGIOMMU memory region attribute hw/vfio/common: Fail on VFIO/HW nested paging detection hw/arm/smmuv3: Log a guest error when decoding an invalid STE hw/arm/smmuv3: Remove spurious error messages on IOVA invalidations
I've added patches 1, 4 and 5 to target-arm.next.
thanks
-- PMM