ARM SMMUv3 Emulation Support
v5 cover ARM SMMUv3 Emulation Support
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fix SMMU_CMDQ_CONS offset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTE
The smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"
As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Tested Use Cases:
- booted a guest in dt and acpi mode with an iommu_platform virtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)
Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of CMDQ_OP_TLBI_NH_VA commands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.
Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.
Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4
References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.html
History:
v4 -> v5:
- initial_level now part of SMMUTransCfg
- smmu_page_walk_64 takes into account the max input size
- implement sys->iommu_ops.replay and sys->iommu_ops.notify_flag_changed
- smmuv3_translate: bug fix: don't walk on bypass
- smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.
v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fix
v2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature added
v1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- Make SMMU_DPRINTF to internally call qemu_log (since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patches
v0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (only is_ste_consistant() is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI support
v0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000
Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route hw/arm/smmuv3: VFIO integration
Prem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT table
default-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-) create mode 100644 hw/arm/smmu-common.c create mode 100644 hw/arm/smmu-internal.h create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 hw/arm/smmuv3.c create mode 100644 include/hw/arm/smmu-common.h create mode 100644 include/hw/arm/smmuv3.h
Signature · 1 line
2.5.5
RFC v5 1/8 hw/arm/smmu-common: smmu base class
Introduces the base device and class for the ARM smmu. Implements VMSAv8-64 table lookup and translation. VMSAv8-32 is not implemented.
---
v4 -> v5:
- add initial level in translation config
- implement block pte
- rename must_translate into nofail
- introduce call_entry_hook
- small changes to dynamic traces
- smmu_page_walk code moved from smmuv3.c to this file
- remove smmu_translate*
v3 -> v4:
- reworked page table walk to prepare for VFIO integration (capability to scan a range of IOVA). Same function is used for translate for a single iova. This is largely inspired from intel_iommu.c
- as the translate function was not straightforward to me, I tried to stick more closely to the VMSA spec.
- remove support of nested stage (kernel driver does not support it anyway)
- introduce smmu-internal.h to put page table definitions
- added smmu_find_as_from_bus_num
- SMMU_PCI_BUS_MAX and SMMU_PCI_DEVFN_MAX in smmu-common header
- new fields in SMMUState:
- iommu_ops, smmu_as_by_busptr, smmu_as_by_bus_num
- use error_report and trace events
- add aa64[] field in SMMUTransCfg
v3:
- moved the base code in a separate patch to ease the review.
- clearer separation between base class and smmuv3 class
- translate_* only implemented as class methods
--- default-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 ++++++++++++++++++++++++++++++++++++ hw/arm/smmu-internal.h | 97 ++++++++ hw/arm/trace-events | 14 ++ include/hw/arm/smmu-common.h | 127 ++++++++++ 6 files changed, 714 insertions(+) create mode 100644 hw/arm/smmu-common.c create mode 100644 hw/arm/smmu-internal.h create mode 100644 include/hw/arm/smmu-common.h
default-configs/aarch64-softmmu.mak +1 -0
@@ -7,3 +7,4 @@ CONFIG_AUX=y CONFIG_DDC=y CONFIG_DPCD=y CONFIG_XLNX_ZYNQMP=y +CONFIG_ARM_SMMUV3=y
hw/arm/Makefile.objs +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o +obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o
hw/arm/smmu-common.c new file +474 -0
474 lines not on this page · raw message
hw/arm/smmu-internal.h new file +97 -0
97 lines not on this page · raw message
hw/arm/trace-events +14 -0
@@ -2,3 +2,17 @@ # hw/arm/virt-acpi-build.c virt_acpi_setup(void) "No fw cfg or ACPI disabled. Bailing out." + +# hw/arm/smmu-common.c + +smmu_page_walk_64(int stage, uint64_t baseaddr, int first_level, uint64_t start, uint64_t end) "stage=%d, baseaddr=0x%"PRIx64", first level=%d, start=0x%"PRIx64", end=0x%"PRIx64 +smmu_page_walk_level_in(int level, uint64_t baseaddr, int granule_sz, uint64_t start, uint64_t end, uint64_t subpage_size) "level=%d baseaddr=0x%"PRIx64" granule=%d, start=0x%"PRIx64" end=0x%"PRIx64", subpage_size=0x%lx" +smmu_page_walk_level(int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "level=%d iova=0x%lx subpage_sz=0x%lx baseaddr=0x%"PRIx64" offset=%d => pte=0x%lx" +smmu_page_walk_level_res_invalid_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint32_t offset, uint64_t pte) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" offset=%d pte=0x%lx" +smmu_page_walk_level_page_pte(int stage, int level, uint64_t iova, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t address) "stage=%d level=%d iova=0x%"PRIx64" base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" page address = 0x%"PRIx64 +smmu_page_walk_level_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" iova=0x%"PRIx64" block address = 0x%"PRIx64" block size = %d MiB" +smmu_page_walk_level_table_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t address) "stage=%d, level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" next table address = 0x%"PRIx64 +smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64 +smmu_set_translated_address(hwaddr iova, hwaddr pa) "iova = 0x%"PRIx64" -> pa = 0x%"PRIx64 +smmu_walk_pgtable(hwaddr iova, bool is_write) "Input addr: 0x%"PRIx64", is_write=%d" +smmu_walk_pgtable_out(hwaddr addr, uint32_t mask, int perm) "DONE: o/p addr:0x%"PRIx64" mask:0x%x perm:%d"
include/hw/arm/smmu-common.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.5.5
Re: [Qemu-arm] [RFC v5 1/8] hw/arm/smmu-common: smmu base class
Hi Eric,
I found out what is going on regarding vhost-net outgoing packet's payload corruption. My packets were corrupted because of inconsistent IOVA to HVA translation in IOTLB. Please see below.
Quoted 8 lines · Eric Auger
Introduces the base device and class for the ARM smmu. Implements VMSAv8-64 table lookup and translation. VMSAv8-32 is not implemented.
Signed-off-by Eric Auger <[email protected]>Signed-off-by Prem Mallappa <[email protected]>---
[...]
Quoted 57 lines
hw/arm/smmu-common.c new file +57
-0+ +/** +* smmu_page_walk_level_64 - Walk an IOVA range from a specific level +* @baseaddr: table base address corresponding to @level +* @level: level +* @cfg: translation config +* @start: end of the IOVA range +* @end: end of the IOVA range +* @hook_fn: the hook that to be called for each detected area +* @private: private data for the hook function +* @read: whether parent level has read permission +* @write: whether parent level has write permission +* @nofail: indicates whether each iova of the range +* must be translated or whether failure is allowed +* @notify_unmap: whether we should notify invalid entries +* +* Return 0 on success, < 0 on errors not related to translation +* process, > 1 on errors related to translation process (only +* if nofail is set) +*/ +static int +smmu_page_walk_level_64 (dma_addr_t baseaddr,int level, +SMMUTransCfg *cfg,uint64_t start,uint64_t end, +smmu_page_walk_hook hook_fn,void *private, +bool read,bool write,bool nofail, +bool notify_unmap) +{ +uint64_t subpage_size, subpage_mask, pte, iova = start; +bool read_cur, write_cur, entry_valid; +int ret, granule_sz, stage; +IOMMUTLBEntry entry; + + granule_sz = cfg->granule_sz; + stage = cfg->stage; + subpage_size =1ULL <<level_shift (level, granule_sz); + subpage_mask =level_page_mask (level, granule_sz); + +trace_smmu_page_walk_level_in (level, baseaddr, granule_sz, + start, end, subpage_size); + +while (iova < end) { +dma_addr_t next_table_baseaddr; +uint64_t iova_next, pte_addr; +uint32_t offset; + + iova_next = (iova & subpage_mask) + subpage_size; + offset =iova_level_offset (iova, level, granule_sz); + pte_addr = baseaddr + offset *sizeof (pte); + pte =get_pte (baseaddr, offset); + +trace_smmu_page_walk_level (level, iova, subpage_size, + baseaddr, offset, pte); + +if (pte == (uint64_t )-1 ) { +if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + }
hw/arm/smmu-common.c line 247
Quoted 10 lines
hw/arm/smmu-common.c new file +10
-0+ goto next; + } +if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) { +trace_smmu_page_walk_level_res_invalid_pte (stage, level, baseaddr, + pte_addr, offset, pte); +if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + } + goto next; + }
vhost maintains its IOTLB cache and when there is no IOVA->HVA translation, it asks QEMU for help. However, IOTLB entries invalidations are guest initiative so for any DMA unmap at guest side we trap to SMMU emulation code and call:smmu_notify_all -> smmuv3_replay_single -> smmu_page_walk_64 -> smmu_page_walk_level_64 -> smmuv3_replay_hook -> vhost_iommu_unmap_notify
The thing is that smmuv3_replay_hook() is never called because guest zeros PTE before we trap to QEMU so that smmu_page_walk_level_64() fails on ^^^ is_invalid_pte(pte) check. This way we keep old IOTLB entry in vhost and subsequent translations may be broken.
Quoted 58 lines
hw/arm/smmu-common.c new file +58
-0+ + read_cur = read;/* TODO */ + write_cur = write;/* TODO */ + entry_valid = read_cur | write_cur;/* TODO */ + +if (is_page_pte (pte, level)) { +uint64_t gpa =get_page_pte_address (pte, granule_sz); +int perm =IOMMU_ACCESS_FLAG (read_cur, write_cur); + +trace_smmu_page_walk_level_page_pte (stage, level, entry.iova, + baseaddr, pte_addr, pte, gpa); +if (!entry_valid && !notify_unmap) { +printf ("%s entry_valid=%d notify_unmap=%d\n" , __func__, + entry_valid, notify_unmap); + goto next; + } + ret =call_entry_hook (iova, subpage_mask, gpa, perm, + hook_fn, private); +if (ret) { +return ret; + } + goto next; + } +if (is_block_pte (pte, level)) { +uint64_t block_size; +hwaddr gpa =get_block_pte_address (pte, level, granule_sz, + &block_size); +int perm =IOMMU_ACCESS_FLAG (read_cur, write_cur); + +if (gpa ==-1 ) { +if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + }else { + goto next; + } + } +trace_smmu_page_walk_level_block_pte (stage, level, baseaddr, + pte_addr, pte, iova, gpa, + (int )(block_size >>20 )); + + ret =call_entry_hook (iova, subpage_mask, gpa, perm, + hook_fn, private); +if (ret) { +return ret; + } + goto next; + } +if (level ==3 ) { + goto next; + } +/* table pte */ + next_table_baseaddr =get_table_pte_address (pte, granule_sz); +trace_smmu_page_walk_level_table_pte (stage, level, baseaddr, pte_addr, + pte, next_table_baseaddr); + ret =smmu_page_walk_level_64 (next_table_baseaddr, level +1 , cfg, + iova,MIN (iova_next, end), + hook_fn, private, read_cur, write_cur, + nofail, notify_unmap);
hw/arm/smmu-common.c line 315
Quoted 10 lines
hw/arm/smmu-common.c new file +10
-0+if (!ret) { +return ret; + } + +next: + iova = iova_next; + } + +return SMMU_TRANS_ERR_NONE ; +}
Thanks,
Tomasz
Re: [Qemu-arm] [RFC v5 1/8] hw/arm/smmu-common: smmu base class
Hi Tomasz,
Quoted 96 lines · Tomasz Nowicki
Hi Eric,
I found out what is going on regarding vhost-net outgoing packet's payload corruption. My packets were corrupted because of inconsistent IOVA to HVA translation in IOTLB. Please see below.
Quoted 8 lines · Eric Auger
Introduces the base device and class for the ARM smmu. Implements VMSAv8-64 table lookup and translation. VMSAv8-32 is not implemented.
Signed-off-by Eric Auger <[email protected]>Signed-off-by Prem Mallappa <[email protected]>---
[...]
Quoted 64 lines
hw/arm/smmu-common.c new file +61
-0+ +/** +* smmu_page_walk_level_64 - Walk an IOVA range from a specific level +* @baseaddr: table base address corresponding to @level +* @level: level +* @cfg: translation config +* @start: end of the IOVA range +* @end: end of the IOVA range +* @hook_fn: the hook that to be called for each detected area +* @private: private data for the hook function +* @read: whether parent level has read permission +* @write: whether parent level has write permission +* @nofail: indicates whether each iova of the range +* must be translated or whether failure is allowed +* @notify_unmap: whether we should notify invalid entries +* +* Return 0 on success, < 0 on errors not related to translation +* process, > 1 on errors related to translation process (only +* if nofail is set) +*/ +static int +smmu_page_walk_level_64 (dma_addr_t baseaddr,int level, +SMMUTransCfg *cfg,uint64_t start,uint64_t end, +smmu_page_walk_hook hook_fn,void *private, +bool read,bool write,bool nofail, +bool notify_unmap) +{ +uint64_t subpage_size, subpage_mask, pte, iova = start; +bool read_cur, write_cur, entry_valid; +int ret, granule_sz, stage; +IOMMUTLBEntry entry; + + granule_sz = cfg->granule_sz; + stage = cfg->stage; + subpage_size =1ULL <<level_shift (level, granule_sz); + subpage_mask =level_page_mask (level, granule_sz); + +trace_smmu_page_walk_level_in (level, baseaddr, granule_sz, + start, end, subpage_size); + +while (iova < end) { +dma_addr_t next_table_baseaddr; +uint64_t iova_next, pte_addr; +uint32_t offset; + + iova_next = (iova & subpage_mask) + subpage_size; + offset =iova_level_offset (iova, level, granule_sz); + pte_addr = baseaddr + offset *sizeof (pte); + pte =get_pte (baseaddr, offset); + +trace_smmu_page_walk_level (level, iova, subpage_size, + baseaddr, offset, pte); + +if (pte == (uint64_t )-1 ) { +if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + } + goto next; + } +if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) { + trace_smmu_page_walk_level_res_invalid_pte(stage, level,baseaddr,
+pte_addr,
offset, pte);hw/arm/smmu-common.c line 239
Quoted 5 lines
hw/arm/smmu-common.c new file +5
-0+if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + } + goto next; + }vhost maintains its IOTLB cache and when there is no
IOVA->HVAtranslation, it asks QEMU for help. However, IOTLB entries invalidations are guest initiative so for any DMA unmap at guest side we trap to SMMU emulation code and call:smmu_notify_all->smmuv3_replay_single->smmu_page_walk_64->smmu_page_walk_level_64->smmuv3_replay_hook->vhost_iommu_unmap_notify
Quoted 4 lines
The thing is that
smmuv3_replay_hook()is never called because guest zeros PTE before we trap to QEMU so thatsmmu_page_walk_level_64()fails on ^^^is_invalid_pte(pte)check. This way we keep old IOTLB entry in vhost and subsequent translations may be broken.
Thank you for the time you spent on this. I will work on this vhost use case asap and will let you know.
Thanks
Eric
Quoted 79 lines
Quoted 66 lines
hw/arm/smmu-common.c new file +10
-0+ + read_cur = read;/* TODO */ + write_cur = write;/* TODO */ + entry_valid = read_cur | write_cur;/* TODO */ + +if (is_page_pte (pte, level)) { +uint64_t gpa =get_page_pte_address (pte, granule_sz); +int perm =IOMMU_ACCESS_FLAG (read_cur, write_cur); + + trace_smmu_page_walk_level_page_pte(stage, level,entry.iova,
+ baseaddr,pte_addr,
pte, gpa);hw/arm/smmu-common.c new file +27
-0+if (!entry_valid && !notify_unmap) { +printf ("%s entry_valid=%d notify_unmap=%d\n" , __func__, + entry_valid, notify_unmap); + goto next; + } + ret =call_entry_hook (iova, subpage_mask, gpa, perm, + hook_fn, private); +if (ret) { +return ret; + } + goto next; + } +if (is_block_pte (pte, level)) { +uint64_t block_size; +hwaddr gpa =get_block_pte_address (pte, level, granule_sz, + &block_size); +int perm =IOMMU_ACCESS_FLAG (read_cur, write_cur); + +if (gpa ==-1 ) { +if (nofail) { +return SMMU_TRANS_ERR_WALK_EXT_ABRT ; + }else { + goto next; + } + } + trace_smmu_page_walk_level_block_pte(stage, level, baseaddr, + pte_addr, pte, iova,gpa,
+ (int)(block_size >>
20));hw/arm/smmu-common.c new file +14
-0+ + ret =call_entry_hook (iova, subpage_mask, gpa, perm, + hook_fn, private); +if (ret) { +return ret; + } + goto next; + } +if (level ==3 ) { + goto next; + } +/* table pte */ + next_table_baseaddr =get_table_pte_address (pte, granule_sz); + trace_smmu_page_walk_level_table_pte(stage, level, baseaddr,
pte_addr,(quoted diff) +2
-0+ pte, next_table_baseaddr); + ret = smmu_page_walk_level_64(next_table_baseaddr, level + 1,cfg,
(quoted diff) +2
-0+ iova, MIN(iova_next, end), + hook_fn, private, read_cur,
write_cur,hw/arm/smmu-common.c new file +1
-0+ nofail, notify_unmap);hw/arm/smmu-common.c line 315
Quoted 10 lines
hw/arm/smmu-common.c new file +10
-0+if (!ret) { +return ret; + } + +next: + iova = iova_next; + } + +return SMMU_TRANS_ERR_NONE ; +}Thanks,
Tomasz
RFC v5 2/8 hw/arm/smmuv3: smmuv3 emulation model
In reply to Eric AugerFrom: Prem Mallappa <[email protected]>
Introduces the SMMUv3 derived model. This is based on System MMUv3 specification (v17).
---
v4 -> v5:
- change smmuv3_translate proto (IOMMUAccessFlags flag)
- has_stagex replaced by is_ste_stagex
- smmu_cfg_populate removed
- added smmuv3_decode_config and reworked error management
- remwork the naming of IOMMU mrs
- fix SMMU_CMDQ_CONS offset
v3 -> v4
- smmu_irq_update
- fix hash key allocation
- set smmu_iommu_ops
- set SMMU_REG_CR0,
- smmuv3_translate: ret.perm not set in bypass mode
- use trace events
- renamed STM2U64 into L1STD_L2PTR and STMSPAN into L1STD_SPAN
- rework smmu_find_ste
- fix tg2granule in TT0/0b10 corresponds to 16kB
v2 -> v3:
- move creation of include/hw/arm/smmuv3.h to this patch to fix compil issue
- compilation allowed
- fix sbus allocation in smmu_init_pci_iommu
- restructure code into headers
- misc cleanups
--- hw/arm/Makefile.objs | 2 +- hw/arm/smmu-internal.h | 8 - hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++++++++++ hw/arm/smmuv3.c | 1133 ++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 34 ++ include/hw/arm/smmuv3.h | 87 ++++ 6 files changed, 1906 insertions(+), 9 deletions(-) create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 hw/arm/smmuv3.c create mode 100644 include/hw/arm/smmuv3.h
hw/arm/Makefile.objs +1 -1
@@ -18,4 +18,4 @@ obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o -obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o +obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o smmuv3.o
hw/arm/smmu-internal.h +0 -8
@@ -86,12 +86,4 @@ uint64_t iova_level_offset(uint64_t iova, int level, int granule_sz) ((1ULL << (granule_sz - 3)) - 1); } -/* TODO: check this for stage 2 and table concatenation */ -static inline int initial_lookup_level (int tnsz,int granule_sz) -{ -return 4 - (64 - tnsz -4 ) / (granule_sz -3 ); -} - - -#endif
hw/arm/smmuv3-internal.h new file +651 -0
651 lines not on this page · raw message
hw/arm/smmuv3.c new file +1133 -0
1,133 lines not on this page · raw message
hw/arm/trace-events +34 -0
@@ -16,3 +16,37 @@ smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "base smmu_set_translated_address(hwaddr iova, hwaddr pa) "iova = 0x%"PRIx64" -> pa = 0x%"PRIx64 smmu_walk_pgtable(hwaddr iova, bool is_write) "Input addr: 0x%"PRIx64", is_write=%d" smmu_walk_pgtable_out(hwaddr addr, uint32_t mask, int perm) "DONE: o/p addr:0x%"PRIx64" mask:0x%x perm:%d" + +#hw/arm/smmuv3.c +smmuv3_irq_update(uint32_t error, uint32_t gerror, uint32_t gerrorn) "<<<< error:0x%x gerror:0x%x gerrorn:0x%x" +smmuv3_irq_raise(int irq) "irq:%d" +smmuv3_unhandled_cmd(uint32_t type) "Unhandled command type=%d" +smmuv3_cmdq_consume(int error, bool enabled, uint32_t prod, uint32_t cons, uint8_t wrap_prod, uint8_t wrap_cons) "error=%d, enabled=%d prod=%d cons=%d wrap.prod=%d wrap.cons=%d" +smmuv3_cmdq_consume_details(hwaddr base, uint32_t cons, uint32_t prod, uint32_t word, uint8_t wrap_cons) "CMDQ base: 0x%"PRIx64" cons:%d prod:%d val:0x%x wrap:%d" +smmuv3_cmdq_opcode(const char *opcode) "<--- %s" +smmuv3_cmdq_cfgi_ste(int streamid) " |_ streamid =%d" +smmuv3_cmdq_cfgi_ste_range(int start, int end) " |_ start=0x%d - end=0x%d" +smmuv3_cmdq_tlbi_nh_va(int asid, int vmid, uint64_t addr) " |_ asid =%d vmid =%d addr=0x%"PRIx64 +smmuv3_cmdq_consume_sev(void) "CMD_SYNC CS=SEV not supported, ignoring" +smmuv3_cmdq_consume_out(uint8_t prod_wrap, uint32_t prod, uint8_t cons_wrap, uint32_t cons) "prod_wrap:%d, prod:0x%x cons_wrap:%d cons:0x%x" +smmuv3_update(bool is_empty, uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "q empty:%d prod:%d cons:%d p.wrap:%d p.cons:%d" +smmuv3_update_check_cmd(int error) "cmdq not enabled or error :0x%x" +smmuv3_update_irq(bool is_pending, uint32_t gerror, uint32_t gerrorn) "irq pend: %d gerror:0x%x gerrorn:0x%x" +smmuv3_is_ste_consistent(bool cfg, bool granule_supported, bool addr_oor, uint32_t aa64, int s2ha, int s2hd, uint64_t s2ttb ) "config[1]:%d gran:%d addr:%d aa64:%d s2ha:%d s2hd:%d s2ttb:0x%"PRIx64 +smmuv3_find_ste(uint16_t sid, uint32_t features, uint16_t sid_split) "SID:0x%x features:0x%x, sid_split:0x%x" +smmuv3_find_ste_2lvl(uint64_t strtab_base, hwaddr l1ptr, int l1_ste_offset, hwaddr l2ptr, int l2_ste_offset, int max_l2_ste) "strtab_base:%lx l1ptr:0x%"PRIx64" l1_off:0x%x, l2ptr:0x%"PRIx64" l2_off:0x%x max_l2_ste:%d" +smmuv3_get_ste(hwaddr addr) "STE addr: 0x%"PRIx64 +smmuv3_translate_bypass(const char *n, uint16_t sid, hwaddr addr, bool is_write) "%s sid=%d bypass iova:0x%"PRIx64" is_write=%d" +smmuv3_translate_in(uint16_t sid, int pci_bus_num, hwaddr strtab_base) "SID:0x%x bus:%d strtab_base:0x%"PRIx64 +smmuv3_get_cd(hwaddr addr) "CD addr: 0x%"PRIx64 +smmuv3_translate_ok(const char *n, uint16_t sid, hwaddr iova, hwaddr translated, int perm) "%s sid=%d iova=0x%"PRIx64" translated=0x%"PRIx64" perm=0x%x" +smmuv3_update_qreg(uint32_t cons, uint64_t val) "cons written : %d val:0x%"PRIx64 +smmuv3_write_mmio(hwaddr addr, uint64_t val) "addr: 0x%"PRIx64" val:0x%"PRIx64 +smmuv3_write_mmio_idr(hwaddr addr, uint64_t val) "write to RO/Unimpl reg %lx val64:%lx" +smmuv3_write_mmio_evtq_cons_bef_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "Before clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" +smmuv3_write_mmio_evtq_cons_after_clear(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "after clearing interrupt prod:0x%x cons:0x%x prod.w:%d cons.w:%d" +smmuv3_read_mmio(hwaddr addr, uint64_t val, uint32_t cons) "addr: 0x%"PRIx64" val:0x%"PRIx64" cmdq cons:%d" +smmuv3_dump_ste(int i, uint32_t word0, int j, uint32_t word1) "STE[%2d]: %#010x\t STE[%2d]: %#010x" +smmuv3_dump_cd(int i, uint32_t word0, int j, uint32_t word1) "CD[%2d]: %#010x\t CD[%2d]: %#010x" +smmuv3_dump_cmd(int i, uint32_t word0, int j, uint32_t word1) "CMD[%2d]: %#010x\t CMD[%2d]: %#010x" +smmuv3_cfg_stage(int s, uint32_t oas, uint32_t tsz, uint64_t ttbr, bool aa64, uint32_t granule_sz, int initial_level) "TransCFG stage:%d oas:%d tsz:%d ttbr:0x%"PRIx64" aa64:%d granule_sz:%d, initial_level = %d"
include/hw/arm/smmuv3.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.5.5
Re: [Qemu-arm] [RFC v5 2/8] hw/arm/smmuv3: smmuv3 emulation model
Hi Eric,
Quoted 17 lines · Eric Auger
From: Prem Mallappa <[email protected]>
Introduces the SMMUv3 derived model. This is based on System MMUv3 specification (v17).
Signed-off-by Prem Mallappa <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
- changesmmuv3_translateproto (IOMMUAccessFlags flag)
-has_stagexreplaced byis_ste_stagex
-smmu_cfg_populateremoved
- addedsmmuv3_decode_configand reworked error management
- remwork the naming of IOMMU mrs
- fixSMMU_CMDQ_CONSoffset
[...]
Quoted 16 lines
hw/arm/smmuv3-internal.h new file +16
-0+ +/***************************** +* Register Access Primitives +*****************************/ + +static inline void smmu_write64_reg (SMMUV3State *s,uint32_t addr,uint64_t val) +{ + addr >>=2 ; + s->regs[addr] = val &0xFFFFFFFFULL ; + s->regs[addr +1 ] = val & ~0xFFFFFFFFULL ; +} + +static inline void smmu_write_reg (SMMUV3State *s,uint32_t addr,uint64_t val) +{ + s->regs[addr >>2 ] = val; +}
hw/arm/smmuv3-internal.h line 401
Quoted 10 lines
hw/arm/smmuv3-internal.h new file +10
-0+ +static inline uint32_t smmu_read_reg (SMMUV3State *s,uint32_t addr) +{ +return s->regs[addr >>2 ]; +} + +static inline uint64_t smmu_read64_reg (SMMUV3State *s,uint32_t addr) +{ + addr >>=2 ; +return s->regs[addr] | (s->regs[addr +1 ] <<32 );
To be consistent with smmu_write64_reg() we should not shift here second half of register, instead simply:
return s->regs[addr] | s->regs[addr + 1];
Thanks,
Tomasz
Re: [Qemu-devel] [RFC v5 2/8] hw/arm/smmuv3: smmuv3 emulation model
Hi Tomasz,
Quoted 55 lines · Tomasz Nowicki
Hi Eric,
Quoted 17 lines · Eric Auger
From: Prem Mallappa <[email protected]>
Introduces the SMMUv3 derived model. This is based on System MMUv3 specification (v17).
Signed-off-by Prem Mallappa <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
- changesmmuv3_translateproto (IOMMUAccessFlags flag)
-has_stagexreplaced byis_ste_stagex
-smmu_cfg_populateremoved
- addedsmmuv3_decode_configand reworked error management
- remwork the naming of IOMMU mrs
- fixSMMU_CMDQ_CONSoffset[...]
Quoted 18 lines
hw/arm/smmuv3-internal.h new file +6
-0+ +/***************************** +* Register Access Primitives +*****************************/ + +static inline void smmu_write64_reg(SMMUV3State *s, uint32_t addr,
uint64_tval)hw/arm/smmuv3-internal.h new file +7
-0+{ + addr >>=2 ; + s->regs[addr] = val &0xFFFFFFFFULL ; + s->regs[addr +1 ] = val & ~0xFFFFFFFFULL ; +} + +static inline void smmu_write_reg(SMMUV3State *s, uint32_t addr,
uint64_tval)hw/arm/smmuv3-internal.h new file +3
-0+{ + s->regs[addr >>2 ] = val; +}hw/arm/smmuv3-internal.h line 401
Quoted 10 lines
hw/arm/smmuv3-internal.h new file +10
-0+ +static inline uint32_t smmu_read_reg (SMMUV3State *s,uint32_t addr) +{ +return s->regs[addr >>2 ]; +} + +static inline uint64_t smmu_read64_reg (SMMUV3State *s,uint32_t addr) +{ + addr >>=2 ; +return s->regs[addr] | (s->regs[addr +1 ] <<32 );To be consistent with
smmu_write64_reg()we should not shift here second half of register, instead simply:
Quoted 1 line
return s->regs[addr] | s->regs[addr + 1];
Thanks for spotting this. I think regs should be uint32_t instead and extract64() could be used on write64 and shift would stay on read64().
Regards
Eric
Quoted 3 lines
Thanks,
Tomasz
Re: [Qemu-arm] [RFC v5 2/8] hw/arm/smmuv3: smmuv3 emulation model
In reply to Eric AugerHi Eric,
Quoted 17 lines · Eric Auger
From: Prem Mallappa <[email protected]>
Introduces the SMMUv3 derived model. This is based on System MMUv3 specification (v17).
Signed-off-by Prem Mallappa <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
- changesmmuv3_translateproto (IOMMUAccessFlags flag)
-has_stagexreplaced byis_ste_stagex
-smmu_cfg_populateremoved
- addedsmmuv3_decode_configand reworked error management
- remwork the naming of IOMMU mrs
- fixSMMU_CMDQ_CONSoffset
[...]
hw/arm/smmuv3.c line 818
Quoted 6 lines
hw/arm/smmuv3.c new file +6
-0+ +static void smmu_update_qreg (SMMUV3State *s,SMMUQueue *q,hwaddr reg, +uint32_t off,uint64_t val,unsigned size) +{ +if (size ==8 && off ==0 ) { +smmu_write64_reg (s, reg, val);
Based on my observation we never get here.
If I read the code correctly, memory_region_dispatch_{write|read}()->memory_region_{write|read}_accessor() will cut all 8-bytes accesses into 4-bytes slices. However, this makes my SMMUv3 register handling happy:
static const MemoryRegionOps smmu_mem_ops = {
.read = smmu_read_mmio,
.write = smmu_write_mmio,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 8,
},+ .impl = {
+ .min_access_size = 4,
+ .max_access_size = 8,
+ },
};
Thanks,
Tomasz
Re: [Qemu-arm] [RFC v5 2/8] hw/arm/smmuv3: smmuv3 emulation model
Hi Tomasz,
Quoted 45 lines · Tomasz Nowicki
Hi Eric,
Quoted 17 lines · Eric Auger
From: Prem Mallappa <[email protected]>
Introduces the SMMUv3 derived model. This is based on System MMUv3 specification (v17).
Signed-off-by Prem Mallappa <[email protected]>Signed-off-by Eric Auger <[email protected]>---
v4 -> v5:
- changesmmuv3_translateproto (IOMMUAccessFlags flag)
-has_stagexreplaced byis_ste_stagex
-smmu_cfg_populateremoved
- addedsmmuv3_decode_configand reworked error management
- remwork the naming of IOMMU mrs
- fixSMMU_CMDQ_CONSoffset[...]
hw/arm/smmuv3.c line 818
Quoted 6 lines
hw/arm/smmuv3.c new file +6
-0+ +static void smmu_update_qreg (SMMUV3State *s,SMMUQueue *q,hwaddr reg, +uint32_t off,uint64_t val,unsigned size) +{ +if (size ==8 && off ==0 ) { +smmu_write64_reg (s, reg, val);Based on my observation we never get here.
If I read the code correctly, memory_region_dispatch_{write|read}()->memory_region_{write|read}_accessor() will cut all 8-bytes accesses into 4-bytes slices. However, this makes my SMMUv3 register handling happy:
static const MemoryRegionOps smmu_mem_ops = { .read = smmu_read_mmio, .write = smmu_write_mmio, .endianness = DEVICE_LITTLE_ENDIAN, .valid = { .min_access_size = 4, .max_access_size = 8, },
hw/arm/smmuv3.c line 994
Quoted 4 lines
hw/arm/smmuv3.c new file +4
-0+ .impl = { + .min_access_size = 4, + .max_access_size = 8, + },
Yes indeed: without the .impl setting, only 4byte accesses are performed by access_with_adjusted_size() which sets access_size_max to 4.
Thanks a lot.
Best regards
Eric
Quoted 4 lines
};
Thanks,
Tomasz
RFC v5 3/8 hw/arm/virt: Add SMMUv3 to the virt board
In reply to Eric AugerFrom: Prem Mallappa <[email protected]>
Add code to instantiate an smmu-v3 in mach-virt. A new boolean flag is introduced in VirtMachineState to allow this instantiation. It is currently false.
---
v4 -> v5:
- add dma-coherent property
v2 -> v3:
- vbi was removed. Use vms instead
- migrate to new smmu binding format (iommu-map)
- don't use appendprop anymore
- add vms->smmu and guard instantiation with this latter
- interrupts type changed to edge
--- hw/arm/virt.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 4 ++++ 2 files changed, 63 insertions(+)
hw/arm/virt.c +59 -0
@@ -56,6 +56,7 @@#include "hw/smbios/smbios.h" #include "qapi/visitor.h" #include "standard-headers/linux/input.h" +#include "hw/arm/smmuv3.h" #define DEFINE_VIRT_MACHINE_LATEST (major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -139,6 +140,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_FW_CFG] = { 0x09020000, 0x00000018 }, [VIRT_GPIO] = { 0x09030000, 0x00001000 }, [VIRT_SECURE_UART] = { 0x09040000, 0x00001000 }, + [VIRT_SMMU] = { 0x09050000, 0x00020000 }, /* 128K, needed */ [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -159,6 +161,7 @@ static const int a15irqmap[] = { [VIRT_SECURE_UART] = 8, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ + [VIRT_SMMU] = 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */ [VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ };
@@ -991,6 +994,53 @@ static void create_pcie_irq_map(const VirtMachineState *vms, 0x7 /* PCI irq */); } +static void alloc_smmu_phandle (VirtMachineState *vms) +{ +if (vms->smmu && !vms->smmu_phandle) { + vms->smmu_phandle =qemu_fdt_alloc_phandle (vms->fdt); + } +} + +static void create_smmu (const VirtMachineState *vms,qemu_irq *pic) +{ +char *smmu; +const char compat[] ="arm,smmu-v3" ; +int irq = vms->irqmap[VIRT_SMMU ]; +hwaddr base = vms->memmap[VIRT_SMMU ].base; +hwaddr size = vms->memmap[VIRT_SMMU ].size; +const char irq_names[] ="eventq\0priq\0cmdq-sync\0gerror" ; + +if (!vms->smmu) { +return ; + } + +sysbus_create_varargs ("smmuv3" , base, pic[irq], pic[irq +1 ], + pic[irq +2 ], pic[irq +3 ],NULL ); + + smmu =g_strdup_printf ("/smmuv3@%" PRIx64, base); +qemu_fdt_add_subnode (vms->fdt, smmu); +qemu_fdt_setprop (vms->fdt, smmu,"compatible" , compat,sizeof (compat)); +qemu_fdt_setprop_sized_cells (vms->fdt, smmu,"reg" ,2 , base,2 , size); + +qemu_fdt_setprop_cells (vms->fdt, smmu,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq ,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI , +GIC_FDT_IRQ_TYPE_SPI , irq +1 ,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI , +GIC_FDT_IRQ_TYPE_SPI , irq +2 ,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI , +GIC_FDT_IRQ_TYPE_SPI , irq +3 ,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI ); + +qemu_fdt_setprop (vms->fdt, smmu,"interrupt-names" , irq_names, +sizeof (irq_names)); + +qemu_fdt_setprop_cell (vms->fdt, smmu,"clocks" , vms->clock_phandle); +qemu_fdt_setprop_string (vms->fdt, smmu,"clock-names" ,"apb_pclk" ); +qemu_fdt_setprop (vms->fdt, smmu,"dma-coherent" ,NULL ,0 ); + +qemu_fdt_setprop_cell (vms->fdt, smmu,"#iommu-cells" ,1 ); + +qemu_fdt_setprop_cell (vms->fdt, smmu,"phandle" , vms->smmu_phandle); +g_free (smmu); +} +static void create_pcie (const VirtMachineState *vms,qemu_irq *pic) {hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO ].base;
@@ -1103,6 +1153,11 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic)qemu_fdt_setprop_cell (vms->fdt, nodename,"#interrupt-cells" ,1 );create_pcie_irq_map (vms, vms->gic_phandle, irq, nodename); +if (vms->smmu) { +qemu_fdt_setprop_cells (vms->fdt, nodename,"iommu-map" , +0x0 , vms->smmu_phandle,0x0 ,0x10000 ); + } +g_free (nodename); }
@@ -1448,8 +1503,12 @@ static void machvirt_init(MachineState *machine)create_rtc (vms, pic); +alloc_smmu_phandle (vms); +create_pcie (vms, pic); +create_smmu (vms, pic); +create_gpio (vms, pic);/* Create mmio transports, so the user can create virtio backends
include/hw/arm/virt.h +4 -0
@@ -38,6 +38,7 @@#define NUM_GICV2M_SPIS 64#define NUM_VIRTIO_TRANSPORTS 32 +#define NUM_SMMU_IRQS 4#define ARCH_GICV3_MAINT_IRQ 9
@@ -59,6 +60,7 @@ enum {VIRT_GIC_V2M ,VIRT_GIC_ITS ,VIRT_GIC_REDIST , +VIRT_SMMU ,VIRT_UART ,VIRT_MMIO , VIRT_RTC,
@@ -95,6 +97,7 @@ typedef struct {bool highmem;bool its;bool virt; +bool smmu;int32_t gic_version;struct arm_boot_info bootinfo;const MemMapEntry *memmap;
@@ -105,6 +108,7 @@ typedef struct {uint32_t clock_phandle;uint32_t gic_phandle;uint32_t msi_phandle; +uint32_t smmu_phandle;int psci_conduit; } VirtMachineState;
Signature · 1 line
2.5.5
RFC v5 4/8 hw/arm/virt: Add 2.10 machine type
In reply to Eric AugerThe new machine type allows smmuv3 instantiation. A new option is introduced to turn the feature on/off (off by default).
---
Another alternative would be to use the -device option as done on x86. As the smmu is a sysbus device, we would need to use the platform bus framework. This would work fine for the dt generation. However the feasibility needs to be studied for ACPI table generation.
a Veuillez saisir le message de validation pour vos modifications. Les lignes
--- hw/arm/virt.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/hw/arm/virt.h | 1 + 2 files changed, 50 insertions(+), 2 deletions(-)
hw/arm/virt.c +49 -2
@@ -1543,6 +1543,20 @@ static void machvirt_init(MachineState *machine)create_platform_bus (vms, pic); } +static bool virt_get_smmu (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->smmu; +} + +static void virt_set_smmu (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->smmu = value; +} +static bool virt_get_secure (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);
@@ -1698,7 +1712,7 @@ static void machvirt_machine_init(void) }type_init (machvirt_machine_init); -static void virt_2_9_instance_init (Object *obj) +static void virt_2_10_instance_init (Object *obj) {VirtMachineState *vms =VIRT_MACHINE (obj);VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms);
@@ -1754,14 +1768,47 @@ static void virt_2_9_instance_init(Object *obj) NULL); } +if (vmc->no_smmu) { + vms->smmu = false; + }else { +/* Default disallows smmu instantiation */ + vms->smmu = false; +object_property_add_bool (obj,"smmu" , virt_get_smmu, + virt_set_smmu,NULL ); +object_property_set_description (obj,"smmu" , +"Set on/off to enable/disable " +"smmu instantiation (default off)" , +NULL ); + } + vms->memmap = a15memmap; vms->irqmap = a15irqmap; } +static void virt_machine_2_10_options (MachineClass *mc) +{ +} +DEFINE_VIRT_MACHINE_AS_LATEST(2, 10) + +#define VIRT_COMPAT_2_9 \ + HW_COMPAT_2_9 + +static void virt_2_9_instance_init (Object *obj) +{ +virt_2_10_instance_init (obj); +} +static void virt_machine_2_9_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); + +virt_machine_2_10_options (mc); +SET_MACHINE_COMPAT (mc,VIRT_COMPAT_2_9 ); + + vmc->no_smmu = true; } -DEFINE_VIRT_MACHINE_AS_LATEST(2, 9) +DEFINE_VIRT_MACHINE(2, 9) +#define VIRT_COMPAT_2_8 \ HW_COMPAT_2_8
include/hw/arm/virt.h +1 -0
@@ -86,6 +86,7 @@ typedef struct {bool disallow_affinity_adjustment;bool no_its;bool no_pmu; +bool no_smmu;bool claim_edge_triggered_timers; } VirtMachineClass;
Signature · 1 line
2.5.5
RFC v5 5/8 hw/arm/virt-acpi-build: Add smmuv3 node in IORT table
In reply to Eric AugerFrom: Prem Mallappa <[email protected]>
This patch builds the smmuv3 node in the ACPI IORT table.
The RID space of the root complex, which spans 0x0-0x10000 maps to streamid space 0x0-0x10000 in smmuv3, which in turn maps to deviceid space 0x0-0x10000 in the ITS group.
The guest must feature the IOMMU probe deferral series
(https://lkml.org/lkml/2017/4/10/214) wich fixes streamid multiple lookup. This bug is not related to the SMMU emulation.
---
v2 -> v3:
- integrate into the existing IORT table made up of ITS, RC nodes
- take into account vms->smmu
- match linux actbl2.h acpi_iort_smmu_v3 field names
--- hw/arm/virt-acpi-build.c | 56 +++++++++++++++++++++++++++++++++++++++------ include/hw/acpi/acpi-defs.h | 15 ++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-)
hw/arm/virt-acpi-build.c +49 -7
@@ -393,19 +393,26 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset) }static void -build_iort (GArray *table_data,BIOSLinker *linker) +build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms) { -int iort_start = table_data->len; +int nb_nodes, iort_start = table_data->len;AcpiIortIdMapping *idmap;AcpiIortItsGroup *its;AcpiIortTable *iort; -size_t node_size, iort_length; +AcpiIortSmmu3 *smmu; +size_t node_size, iort_length, smmu_offset =0 ;AcpiIortRC *rc; iort =acpi_data_push (table_data,sizeof (*iort)); +if (vms->smmu) { + nb_nodes =3 ;/* RC, ITS, SMMUv3 */ + }else { + nb_nodes =2 ;/* RC, ITS */ + } + iort_length =sizeof (*iort); - iort->node_count =cpu_to_le32 (2 );/* RC and ITS nodes */ + iort->node_count =cpu_to_le32 (nb_nodes); iort->node_offset =cpu_to_le32 (sizeof (*iort));/* ITS group node */
@@ -418,6 +425,35 @@ build_iort(GArray *table_data, BIOSLinker *linker) its->its_count =cpu_to_le32 (1 ); its->identifiers[0 ] =0 ;/* MADT translation_id */ +if (vms->smmu) { +int irq = vms->irqmap[VIRT_SMMU ]; + +/* SMMUv3 node */ + smmu_offset =cpu_to_le32 (iort->node_offset + node_size); + node_size =sizeof (*smmu) +sizeof (*idmap); + iort_length += node_size; + smmu =acpi_data_push (table_data, node_size); + + + smmu->type =ACPI_IORT_NODE_SMMU_V3 ; + smmu->length =cpu_to_le16 (node_size); + smmu->mapping_count =cpu_to_le32 (1 ); + smmu->mapping_offset =cpu_to_le32 (sizeof (*smmu)); + smmu->base_address =cpu_to_le64 (vms->memmap[VIRT_SMMU ].base); + smmu->event_gsiv =cpu_to_le32 (irq); + smmu->pri_gsiv =cpu_to_le32 (irq +1 ); + smmu->gerr_gsiv =cpu_to_le32 (irq +2 ); + smmu->sync_gsiv =cpu_to_le32 (irq +3 ); + +/* Identity RID mapping covering the whole input RID range */ + idmap = &smmu->id_mapping_array[0 ]; + idmap->input_base =0 ; + idmap->id_count =cpu_to_le32 (0xFFFF ); + idmap->output_base =0 ; +/* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =cpu_to_le32 (iort->node_offset); + } +/* Root Complex Node */ node_size =sizeof (*rc) +sizeof (*idmap); iort_length += node_size;
@@ -438,8 +474,14 @@ build_iort(GArray *table_data, BIOSLinker *linker) idmap->input_base =0 ; idmap->id_count =cpu_to_le32 (0xFFFF ); idmap->output_base =0 ; -/* output IORT node is the ITS group node (the first node) */ - idmap->output_reference =cpu_to_le32 (iort->node_offset); + +if (vms->smmu) { +/* output IORT node is the smmuv3 node */ + idmap->output_reference =cpu_to_le32 (smmu_offset); + }else { +/* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =cpu_to_le32 (iort->node_offset); + } iort->length =cpu_to_le32 (iort_length);
@@ -782,7 +824,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)if (its_class_name () && !vmc->no_its) {acpi_add_table (table_offsets, tables_blob); -build_iort (tables_blob, tables->linker); +build_iort (tables_blob, tables->linker, vms); }/* XSDT is pointed to by RSDP */
include/hw/acpi/acpi-defs.h +15 -0
@@ -697,6 +697,21 @@ struct AcpiIortItsGroup { }QEMU_PACKED ;typedef struct AcpiIortItsGroup AcpiIortItsGroup ; +struct AcpiIortSmmu3 { +ACPI_IORT_NODE_HEADER_DEF + uint64_t base_address; +uint32_t flags; +uint32_t reserved2; +uint64_t vatos_address; +uint32_t model; +uint32_t event_gsiv; +uint32_t pri_gsiv; +uint32_t gerr_gsiv; +uint32_t sync_gsiv; +AcpiIortIdMapping id_mapping_array[0 ]; +}QEMU_PACKED ; +typedef struct AcpiIortSmmu3 AcpiIortSmmu3 ; +struct AcpiIortRC {ACPI_IORT_NODE_HEADER_DEF AcpiIortMemoryAccess memory_properties;
Signature · 1 line
2.5.5
RFC v5 6/8 hw/arm/virt: Add tlbi-on-map property to the smmuv3 node
In reply to Eric AugerFor VFIO integration we need to update physical IOMMU mappings each time the guest updates the vIOMMU translation structures. For that, we rely on a special smmuv3 option, "tlbi-on-map" which forces TLB invalidations on map (this mode is similar to the Intel VTD caching Mode). The smmuv3 driver then sends SMMU_CMD_TLBI_NH_VA commands, upon which we will update the physical mappings.
--- hw/arm/virt.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/virt.c +1 -0
@@ -1034,6 +1034,7 @@ static void create_smmu(const VirtMachineState *vms, qemu_irq *pic)qemu_fdt_setprop_cell (vms->fdt, smmu,"clocks" , vms->clock_phandle);qemu_fdt_setprop_string (vms->fdt, smmu,"clock-names" ,"apb_pclk" );qemu_fdt_setprop (vms->fdt, smmu,"dma-coherent" ,NULL ,0 ); +qemu_fdt_setprop (vms->fdt, smmu,"tlbi-on-map" ,NULL ,0 );qemu_fdt_setprop_cell (vms->fdt, smmu,"#iommu-cells" ,1 );
Signature · 1 line
2.5.5
RFC v5 7/8 target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route
In reply to Eric AugerIn case the MSI is translated by an IOMMU we need to fixup the MSI route with the translated address.
---
It is still unclear to me if we need to register an IOMMUNotifier to handle any change in the MSI doorbell which would occur behind the scene and would not lead to any call to kvm_arch_fixup_msi_route().
--- target/arm/kvm.c | 28 ++++++++++++++++++++++++++++ target/arm/trace-events | 3 +++ 2 files changed, 31 insertions(+)
target/arm/kvm.c +28 -0
@@ -20,8 +20,13 @@#include "sysemu/kvm.h" #include "kvm_arm.h" #include "cpu.h" +#include "trace.h" #include "internals.h" #include "hw/arm/arm.h" +#include "hw/pci/pci.h" +#include "hw/pci/msi.h" +#include "hw/arm/smmu-common.h" +#include "hw/arm/smmuv3.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" #include "hw/boards.h"
@@ -611,6 +616,29 @@ int kvm_arm_vgic_probe(void)int kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route,uint64_t address,uint32_t data,PCIDevice *dev) { +AddressSpace *as =pci_device_iommu_address_space (dev); +IOMMUTLBEntry entry; +SMMUDevice *sdev; +SMMUV3State *s3; +SMMUState *s; + +if (as == &address_space_memory) { +return 0 ; + } + +/* MSI doorbell address is translated by an IOMMU */ + sdev =container_of (as, SMMUDevice, as); + s3 = sdev->smmu; + s = &s3->smmu_state; + + entry = s->iommu_ops.translate (&sdev->iommu, address,IOMMU_WO ); + + route->u.msi.address_lo = entry.translated_addr; + route->u.msi.address_hi = entry.translated_addr >>32 ; + +trace_kvm_arm_fixup_msi_route (address, sdev->devfn, sdev->iommu.name, + entry.translated_addr); +return 0 ; }
target/arm/trace-events +3 -0
@@ -8,3 +8,6 @@ arm_gt_tval_write(int timer, uint64_t value) "gt_tval_write: timer %d value %" P arm_gt_ctl_write(int timer, uint64_t value) "gt_ctl_write: timer %d value %" PRIx64 arm_gt_imask_toggle(int timer, int irqstate) "gt_ctl_write: timer %d IMASK toggle, new irqstate %d" arm_gt_cntvoff_write(uint64_t value) "gt_cntvoff_write: value %" PRIx64 + +# target/arm/kvm.c +kvm_arm_fixup_msi_route(uint64_t iova, uint32_t devid, const char *name, uint64_t gpa) "MSI addr = 0x%"PRIx64" is translated for devfn=%d through %s into 0x%"PRIx64
Signature · 1 line
2.5.5
RFC v5 8/8 hw/arm/smmuv3: VFIO integration
In reply to Eric AugerThis patch allows doing PCIe passthrough with a guest exposed with a vSMMUv3. It implements the replay and notify_flag_changed iommu ops. Also on TLB and data structure invalidation commands, we replay the mappings so that the physical IOMMU implements updated stage 1 settings (Guest IOVA -> Guest PA) + stage 2 settings.
This works only if the guest smmuv3 driver implements the "tlbi-on-map" option.
---
at the moment the "tlbi-on-map" option only is set in DT mode.
--- hw/arm/smmuv3.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 6 +++ 2 files changed, 129 insertions(+)
hw/arm/smmuv3.c +123 -0
@@ -143,6 +143,32 @@ static MemTxResult smmu_read_cmdq(SMMUV3State *s, Cmd *cmd)return ret; } +static void smmu_replay_all (SMMUState *s) +{ +SMMUNotifierNode *node; + + QLIST_FOREACH(node, &s->notifiers_list, next) { +memory_region_iommu_replay_all (&node->sdev->iommu); + } +} + +static void smmuv3_replay_single (MemoryRegion *mr,IOMMUNotifier *n, +uint64_t iova); + +static void smmu_notify_all (SMMUState *s,uint64_t iova) +{ +SMMUNotifierNode *node; + + QLIST_FOREACH(node, &s->notifiers_list, next) { +MemoryRegion *mr = &node->sdev->iommu; +IOMMUNotifier *n; + + IOMMU_NOTIFIER_FOREACH(n, mr) { +smmuv3_replay_single (mr, n, iova); + } + } +} +static int smmu_cmdq_consume (SMMUV3State *s) {uint32_t error =SMMU_CMD_ERR_NONE ;
@@ -183,6 +209,7 @@ static int smmu_cmdq_consume(SMMUV3State *s)uint32_t streamid = cmd.word[1 ];trace_smmuv3_cmdq_cfgi_ste (streamid); +smmu_replay_all (&s->smmu_state);break ; }case SMMU_CMD_CFGI_STE_RANGE :/* same as SMMU_CMD_CFGI_ALL */
@@ -192,14 +219,17 @@ static int smmu_cmdq_consume(SMMUV3State *s) range =extract32 (cmd.word[2 ],0 ,5 ); end = start + (1 << (range +1 )) -1 ;trace_smmuv3_cmdq_cfgi_ste_range (start, end); +smmu_replay_all (&s->smmu_state);break ; }case SMMU_CMD_CFGI_CD :case SMMU_CMD_CFGI_CD_ALL : +smmu_replay_all (&s->smmu_state);break ;case SMMU_CMD_TLBI_NH_ALL :case SMMU_CMD_TLBI_NH_ASID :printf ("%s TLBI* replay\n" , __func__); +smmu_replay_all (&s->smmu_state);break ;case SMMU_CMD_TLBI_NH_VA : {
@@ -210,6 +240,7 @@ static int smmu_cmdq_consume(SMMUV3State *s)uint64_t addr = high <<32 | (low <<12 );trace_smmuv3_cmdq_tlbi_nh_va (asid, vmid, addr); +smmu_notify_all (&s->smmu_state, addr);break ; }case SMMU_CMD_TLBI_NH_VAA :
@@ -222,6 +253,7 @@ static int smmu_cmdq_consume(SMMUV3State *s)case SMMU_CMD_TLBI_S12_VMALL :case SMMU_CMD_TLBI_S2_IPA :case SMMU_CMD_TLBI_NSNH_ALL : +smmu_replay_all (&s->smmu_state);break ;case SMMU_CMD_ATC_INV :case SMMU_CMD_PRI_RESP :
@@ -804,6 +836,95 @@ out:return entry; } +static int smmuv3_replay_hook (IOMMUTLBEntry *entry,void *private) +{ +int perm = entry->perm; + +trace_smmuv3_replay_hook (entry->iova, entry->translated_addr, + entry->addr_mask, entry->perm); + entry->perm =IOMMU_NONE ; +memory_region_notify_one ((IOMMUNotifier *)private, entry); + entry->perm = perm; +memory_region_notify_one ((IOMMUNotifier *)private, entry); +return 0 ; +} + +static void smmuv3_replay (MemoryRegion *mr,IOMMUNotifier *n) +{ +SMMUDevice *sdev =container_of (mr, SMMUDevice, iommu); +SMMUV3State *s = sdev->smmu; +SMMUBaseClass *sbc =SMMU_DEVICE_GET_CLASS (s); +SMMUTransCfg cfg = {}; +int ret; + + ret =smmuv3_decode_config (mr, &cfg); +if (ret) { +error_report ("%s error decoding the configuration for iommu mr=%s" , + __func__, mr->name); + } + +if (cfg.disabled || cfg.bypassed) { +return ; + } +/* is the smmu enabled */ + sbc->page_walk_64 (&cfg,0 , (1ULL << (64 - cfg.tsz)) -1 , false, + smmuv3_replay_hook, n); +} + +static void smmuv3_replay_single (MemoryRegion *mr,IOMMUNotifier *n, +uint64_t iova) +{ +SMMUDevice *sdev =container_of (mr, SMMUDevice, iommu); +SMMUV3State *s = sdev->smmu; +SMMUBaseClass *sbc =SMMU_DEVICE_GET_CLASS (s); +SMMUTransCfg cfg = {}; +int ret; + +trace_smmuv3_replay_single (mr->name, iova, n); + ret =smmuv3_decode_config (mr, &cfg); +if (ret) { +error_report ("%s error decoding the configuration for iommu mr=%s" , + __func__, mr->name); + } + +if (cfg.disabled || cfg.bypassed) { +return ; + } +/* is the smmu enabled */ + sbc->page_walk_64 (&cfg, iova, iova +1 , false, + smmuv3_replay_hook, n); +} + +static void smmuv3_notify_flag_changed (MemoryRegion *iommu, +IOMMUNotifierFlag old, +IOMMUNotifierFlag new) +{ +SMMUDevice *sdev =container_of (iommu, SMMUDevice, iommu); +SMMUV3State *s3 = sdev->smmu; +SMMUState *s = &(s3->smmu_state); +SMMUNotifierNode *node =NULL ; +SMMUNotifierNode *next_node =NULL ; + +if (old ==IOMMU_NOTIFIER_NONE ) { +trace_smmuv3_notify_flag_add (iommu->name); + node =g_malloc0 (sizeof (*node)); + node->sdev = sdev; +QLIST_INSERT_HEAD (&s->notifiers_list, node, next); +return ; + } + +/* update notifier node with new flags */ + QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) { +if (node->sdev == sdev) { +if (new ==IOMMU_NOTIFIER_NONE ) { +trace_smmuv3_notify_flag_del (iommu->name); +QLIST_REMOVE (node, next); +g_free (node); + } +return ; + } + } +}static inline void smmu_update_base_reg (SMMUV3State *s,uint64_t *base,uint64_t val)
@@ -1072,6 +1193,8 @@ static void smmu_realize(DeviceState *d, Error **errp)SysBusDevice *dev =SYS_BUS_DEVICE (d); sys->iommu_ops.translate = smmuv3_translate; + sys->iommu_ops.notify_flag_changed = smmuv3_notify_flag_changed; + sys->iommu_ops.replay = smmuv3_replay;/* Register Access */ memset (sys->smmu_as_by_bus_num,0 ,sizeof (sys->smmu_as_by_bus_num)); memory_region_init_io(&sys->iomem, OBJECT(s),
hw/arm/trace-events +6 -0
@@ -50,3 +50,9 @@ smmuv3_dump_ste(int i, uint32_t word0, int j, uint32_t word1) "STE[%2d]: %#010x smmuv3_dump_cd(int i, uint32_t word0, int j, uint32_t word1) "CD[%2d]: %#010x\t CD[%2d]: %#010x" smmuv3_dump_cmd(int i, uint32_t word0, int j, uint32_t word1) "CMD[%2d]: %#010x\t CMD[%2d]: %#010x" smmuv3_cfg_stage(int s, uint32_t oas, uint32_t tsz, uint64_t ttbr, bool aa64, uint32_t granule_sz, int initial_level) "TransCFG stage:%d oas:%d tsz:%d ttbr:0x%"PRIx64" aa64:%d granule_sz:%d, initial_level = %d" + +smmuv3_replay(uint16_t sid, bool enabled) "sid=%d, enabled=%d" +smmuv3_replay_hook(hwaddr iova, hwaddr pa, hwaddr mask, int perm) "iova=0x%"PRIx64" pa=0x%" PRIx64" mask=0x%"PRIx64" perm=%d" +smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s" +smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" +smmuv3_replay_single(const char *name, uint64_t iova, void *n) "iommu mr=%s iova=0x%"PRIx64" n=%p"
Signature · 1 line
2.5.5
A message that is not in the archive (sent off-list or not yet received): CACJhume2HkAXVQ8kSCpGEfQV4NOP_=HrZCHXBNLnbm0B8dGQvw@mail.gmail.com
Hi Eric
Quoted 19 lines
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fixSMMU_CMDQ_CONSoffset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTEThe smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Quoted 5 lines
Tested Use Cases:
- booted a guest in dt and acpi mode with aniommu_platformvirtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.
Verified patches with virtio-net-pci. Not observed any command queue issues like in V4 patch series. There is a huge difference in iperf numbers on guest with and without SMMUv3 emulation i.e (1.5 Gbps with viommu and 9.0 Gbps without viommu). I think this is expected behaviour.
Is there any plan to add device-iotlb and iotlb support in SMMUv3 emulation ?
Thank you,
Geetha.
Quoted 130 lines
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of
CMDQ_OP_TLBI_NH_VAcommands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.htmlHistory:
v4 -> v5:
-initial_levelnow part of SMMUTransCfg
-smmu_page_walk_64takes into account the max input size
- implementsys->iommu_ops.replayandsys->iommu_ops.notify_flag_changed
-smmuv3_translate: bug fix: don't walk on bypass
-smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fixv2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature addedv1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- MakeSMMU_DPRINTFto internally callqemu_log(since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patchesv0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (onlyis_ste_consistant()is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI supportv0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell inkvm_arch_fixup_msi_routehw/arm/smmuv3: VFIO integrationPrem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT tabledefault-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-) create mode 100644 hw/arm/smmu-common.c create mode 100644 hw/arm/smmu-internal.h create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 hw/arm/smmuv3.c create mode 100644 include/hw/arm/smmu-common.h create mode 100644 include/hw/arm/smmuv3.h--
2.5.5
Hi Geetha, Tomasz,
Quoted 22 lines · Geetha Akula
Hi Eric
Quoted 19 lines
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fixSMMU_CMDQ_CONSoffset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTEThe smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Quoted 8 lines
Quoted 5 lines
Tested Use Cases:
- booted a guest in dt and acpi mode with aniommu_platformvirtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.Verified patches with virtio-net-pci. Not observed any command queue issues like in V4 patch series.
Thank you for your comments and sorry for the delay, I was off.
Good to hear it fixes the command queue issues.
There is a huge difference in iperf numbers
Quoted 2 lines
on guest with and without SMMUv3 emulation i.e (1.5 Gbps with viommu and 9.0 Gbps without viommu). I think this is expected behaviour.
The perf can be definitively improved by setting the tlbi-on-map mode for guest smmuv3 only when needed, as it is done with x86 qemu intel-iommu,cache-mode=true explicit option.
Quoted 2 lines
Is there any plan to add device-iotlb and iotlb support in SMMUv3 emulation ?
What does both comprise exactly? do you mean PCI ATS support or vhost device iotlb (ie. the use case exercised by Tomasz). Please can you elaborate?
Thanks
Eric
Quoted 136 lines
Thank you,
Geetha.Quoted 130 lines
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of
CMDQ_OP_TLBI_NH_VAcommands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.htmlHistory:
v4 -> v5:
-initial_levelnow part of SMMUTransCfg
-smmu_page_walk_64takes into account the max input size
- implementsys->iommu_ops.replayandsys->iommu_ops.notify_flag_changed
-smmuv3_translate: bug fix: don't walk on bypass
-smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fixv2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature addedv1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- MakeSMMU_DPRINTFto internally callqemu_log(since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patchesv0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (onlyis_ste_consistant()is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI supportv0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell inkvm_arch_fixup_msi_routehw/arm/smmuv3: VFIO integrationPrem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT tabledefault-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-) create mode 100644 hw/arm/smmu-common.c create mode 100644 hw/arm/smmu-internal.h create mode 100644 hw/arm/smmuv3-internal.h create mode 100644 hw/arm/smmuv3.c create mode 100644 include/hw/arm/smmu-common.h create mode 100644 include/hw/arm/smmuv3.h--
2.5.5
Hi Eric,
With fixes in comments that I made, I was able to run VM with virtio-blk-pci and virtio-net-pci devices.
I have tried vhost-net as well but I am seeing outgoing packets payload corrupted from host perspective, tcpdump on host tun i/f shows zeroes in packet payload. However, tcpdump in VM shows that packets are fine. Have you seen anything like that? Packets incoming to VM are fine though. I will keep debugging on my side too.
Thanks,
Tomasz
Quoted 152 lines · Eric Auger
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fixSMMU_CMDQ_CONSoffset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTEThe smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Tested Use Cases:
- booted a guest in dt and acpi mode with aniommu_platformvirtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of
CMDQ_OP_TLBI_NH_VAcommands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.htmlHistory:
v4 -> v5:
-initial_levelnow part of SMMUTransCfg
-smmu_page_walk_64takes into account the max input size
- implementsys->iommu_ops.replayandsys->iommu_ops.notify_flag_changed
-smmuv3_translate: bug fix: don't walk on bypass
-smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fixv2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature addedv1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- MakeSMMU_DPRINTFto internally callqemu_log(since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patchesv0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (onlyis_ste_consistant()is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI supportv0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell inkvm_arch_fixup_msi_routehw/arm/smmuv3: VFIO integrationPrem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT tabledefault-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-)create mode 100644
hw/arm/smmu-common.c
create mode 100644hw/arm/smmu-internal.h
create mode 100644hw/arm/smmuv3-internal.h
create mode 100644hw/arm/smmuv3.c
create mode 100644include/hw/arm/smmu-common.h
create mode 100644include/hw/arm/smmuv3.h
Hi Eric,
Just letting you know that I am facing another issue with the following setup:
1. host (4.12 kernel & 64K page) and VM (4.12 kernel & 64K page)
2. QEMU + -netdev type=tap,ifname=tap,id=net0 -device virtio-net-pci,netdev=net0,iommu_platform,disable-modern=off,disable-legacy=on
2. On VM, I allocate some huge pages and run DPDK testpmd app:
# echo 4 > /sys/kernel/mm/hugepages/hugepages-524288kB/nr_hugepages # ./dpdk/usertools/dpdk-devbind.py -b vfio-pci 0000:00:02.0 # ./dpdk/build/app/testpmd -l 0-13 -n 4 -w 0000:00:02.0 -- --disable-hw-vlan-filter --disable-rss -i EAL: Detected 14 lcore(s) EAL: Probing VFIO support... EAL: VFIO support initialized EAL: PCI device 0000:00:02.0 on NUMA socket -1 EAL: probe driver: 1af4:1041 net_virtio EAL: using IOMMU type 1 (Type 1) EAL: iommu_map_dma vaddr ffff20000000 size 80000000 iova 120000000 EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (0) EAL: Can't write to PCI bar (0) : offset (4) EAL: Can't write to PCI bar (0) : offset (14) EAL: Can't write to PCI bar (0) : offset (e) EAL: Can't read from PCI bar (0) : offset (c) EAL: Requested device 0000:00:02.0 cannot be used EAL: No probed ethernet devices Interactive-mode selected USER1: create a new mbuf pool <mbuf_pool_socket_0>: n=251456, size=2176, socket=0
When VM uses *4K pages* the same setup works fine. I will work on this but please let me know in case you already know what is going on.
Thanks,
Tomasz
Quoted 152 lines · Eric Auger
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fixSMMU_CMDQ_CONSoffset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTEThe smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Tested Use Cases:
- booted a guest in dt and acpi mode with aniommu_platformvirtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of
CMDQ_OP_TLBI_NH_VAcommands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.htmlHistory:
v4 -> v5:
-initial_levelnow part of SMMUTransCfg
-smmu_page_walk_64takes into account the max input size
- implementsys->iommu_ops.replayandsys->iommu_ops.notify_flag_changed
-smmuv3_translate: bug fix: don't walk on bypass
-smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fixv2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature addedv1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- MakeSMMU_DPRINTFto internally callqemu_log(since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patchesv0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (onlyis_ste_consistant()is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI supportv0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell inkvm_arch_fixup_msi_routehw/arm/smmuv3: VFIO integrationPrem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT tabledefault-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-)create mode 100644
hw/arm/smmu-common.c
create mode 100644hw/arm/smmu-internal.h
create mode 100644hw/arm/smmuv3-internal.h
create mode 100644hw/arm/smmuv3.c
create mode 100644include/hw/arm/smmu-common.h
create mode 100644include/hw/arm/smmuv3.h
Hi Tomasz,
Quoted 37 lines · Tomasz Nowicki
Hi Eric,
Just letting you know that I am facing another issue with the following setup:
1. host (4.12 kernel & 64K page) and VM (4.12 kernel & 64K page)
2. QEMU + -netdev type=tap,ifname=tap,id=net0 -device virtio-net-pci,netdev=net0,iommu_platform,disable-modern=off,disable-legacy=on2. On VM, I allocate some huge pages and run DPDK testpmd app:
# echo 4 > /sys/kernel/mm/hugepages/hugepages-524288kB/nr_hugepages # ./dpdk/usertools/dpdk-devbind.py -b vfio-pci 0000:00:02.0 # ./dpdk/build/app/testpmd -l 0-13 -n 4 -w 0000:00:02.0 -- --disable-hw-vlan-filter --disable-rss -i EAL: Detected 14 lcore(s) EAL: Probing VFIO support... EAL: VFIO support initialized EAL: PCI device 0000:00:02.0 on NUMA socket -1 EAL: probe driver: 1af4:1041 net_virtio EAL: using IOMMU type 1 (Type 1) EAL: iommu_map_dma vaddr ffff20000000 size 80000000 iova 120000000 EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (0) EAL: Can't write to PCI bar (0) : offset (4) EAL: Can't write to PCI bar (0) : offset (14) EAL: Can't write to PCI bar (0) : offset (e) EAL: Can't read from PCI bar (0) : offset (c) EAL: Requested device 0000:00:02.0 cannot be used EAL: No probed ethernet devices Interactive-mode selected USER1: create a new mbuf pool <mbuf_pool_socket_0>: n=251456, size=2176, socket=0
Quoted 2 lines
When VM uses *4K pages* the same setup works fine. I will work on this but please let me know in case you already know what is going on.
No I did not face that one. I was able to launch testpmd without such early message. However I assigned an igbvf device to the guest and then to DPDK. I've never tested your config.
However as stated in my cover letter at the moment DPDK is not working for me because of storms of tlbi-on-maps. I intend to work on this as soon as get some bandwidth, sorry.
Thanks
Eric
Quoted 160 lines
Thanks,
TomaszQuoted 154 lines · Eric Auger
This series implements the emulation code for ARM SMMUv3. This is the continuation of Prem's work [1].
This v5 mainly brings VFIO integration in DT mode. On guest kernel side, this requires a quirk [1] to force TLB invalidation on map.
The following changes also are noticeable:
- fixSMMU_CMDQ_CONSoffset
- adds dma-coherent dt property which fixes the unhandled command opcode bug.
- implements block PTEThe smmu is instantiated when passing the smmu option to machvirt:
"-M virt-2.10,smmu"As I haven't split the code yet so that it can be easily reviewable I don't expect deep reviews at this stage. Also the implementation may be largely sub-optimal.
Tested Use Cases:
- booted a guest in dt and acpi mode with aniommu_platformvirtio-net-pci device (using dma ops). Tested with the following guest combinations: 4K page - 39 bit VA, 4K - 48b, 64K - 39b, 64K - 48b.
- booted a guest (featuring [1]) with PCIe passthrough'ed PCIe devices:
- AMD Overdrive and igbvf passthrough (using gsi direct mapping)
- Cavium ThunderX and ixgbevf passthrough (using KVM MSI routing)Unfortunately I have not been able to run DPDK testpmd yet on guest side. The problem I see is the user space driver dma-maps a huge area and this causes plenty of
CMDQ_OP_TLBI_NH_VAcommands to be sent (tlbi-on-map) which are sent for each page whereas the dma-map covers a huge page. I will work on this issue for next version.Known limitations:
- no VMSAv8-32 suport
- no nested stage support (S1 + S2)
- no support for HYP mappings
- register fine emulation, commands, interrupts and errors were not accurately tested. Handling is sufficient to run use cases described hereafter though.Best Regards
Eric
This series can be found at:
v5: https://github.com/eauger/qemu/tree/v2.9-SMMU-v5
v4: https://github.com/eauger/qemu/tree/v2.9-SMMU-v4References:
[1] [RFC 0/2] arm-smmu-v3 tlbi-on-map option
[2] Prem's last iteration:
- https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03531.htmlHistory:
v4 -> v5:
-initial_levelnow part of SMMUTransCfg
-smmu_page_walk_64takes into account the max input size
- implementsys->iommu_ops.replayandsys->iommu_ops.notify_flag_changed
-smmuv3_translate: bug fix: don't walk on bypass
-smmu_update_qreg: fix PROD index update
- I did not yet address Peter's comments as the code is not mature enough to be split into sub patches.v3 -> v4 [Eric]:
- page table walk rewritten to allow scan of the page table within a range of IOVA. This prepares for VFIO integration and replay.
- configuration parsing partially reworked.
- do not advertise unsupported/untested features: S2, S1 + S2, HYP, PRI, ATS, ..
- added ACPI table generation
- migrated to dynamic traces
- mingw compilation fixv2 -> v3 [Eric]:
- rebased on 2.9
- mostly code and patch reorganization to ease the review process
- optional patches removed. They may be handled separately. I am currently
working on ACPI enablement.
- optional instantiation of the smmu in mach-virt
- removed [2/9] (fdt functions) since not mandated
- start splitting main patch into base and derived object
- no new function feature addedv1 -> v2 [Prem]:
- Adopted review comments from Eric Auger
- MakeSMMU_DPRINTFto internally callqemu_log(since translation requests are too many, we need control on the type of log we want)
- SMMUTransCfg modified to suite simplicity
- Change RegInfo to uint64 register array
- Code cleanup
- Test cleanups
- Reshuffled patchesv0 -> v1 [Prem]:
- As per SMMUv3 spec 16.0 (onlyis_ste_consistant()is noticeable)
- Reworked register access/update logic
- Factored out translation code for
- single point bug fix
- sharing/removal in future
- (optional) Unit tests added, with PCI test device
- S1 with 4k/64k, S1+S2 with 4k/64k
- (S1 or S2) only can be verified by Linux 4.7 driver
- (optional) Priliminary ACPI supportv0 [Prem]:
- Implements SMMUv3 spec 11.0
- Supported for PCIe devices,
- Command Queue and Event Queue supported
- LPAE only, S1 is supported and Tested, S2 not tested
- BE mode Translation not supported
- IRQ support (legacy, no MSI)
- Tested with DPDK and e1000Eric Auger (5):
hw/arm/smmu-common: smmu base class
hw/arm/virt: Add 2.10 machine type
hw/arm/virt: Add tlbi-on-map property to the smmuv3 node target/arm/kvm: Translate the MSI doorbell inkvm_arch_fixup_msi_routehw/arm/smmuv3: VFIO integrationPrem Mallappa (3):
hw/arm/smmuv3: smmuv3 emulation model hw/arm/virt: Add SMMUv3 to the virt board hw/arm/virt-acpi-build: Add smmuv3 node in IORT tabledefault-configs/aarch64-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/smmu-common.c | 474 +++++++++++++ hw/arm/smmu-internal.h | 89 +++ hw/arm/smmuv3-internal.h | 651 ++++++++++++++++++ hw/arm/smmuv3.c | 1256 +++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 54 ++ hw/arm/virt-acpi-build.c | 56 +- hw/arm/virt.c | 111 +++- include/hw/acpi/acpi-defs.h | 15 + include/hw/arm/smmu-common.h | 127 ++++ include/hw/arm/smmuv3.h | 87 +++ include/hw/arm/virt.h | 5 + target/arm/kvm.c | 28 + target/arm/trace-events | 3 + 15 files changed, 2949 insertions(+), 9 deletions(-)create mode 100644
hw/arm/smmu-common.c
create mode 100644hw/arm/smmu-internal.h
create mode 100644hw/arm/smmuv3-internal.h
create mode 100644hw/arm/smmuv3.c
create mode 100644include/hw/arm/smmu-common.h
create mode 100644include/hw/arm/smmuv3.h
Hi Eric,
Quoted 42 lines · Auger Eric
Hi Tomasz,
Quoted 37 lines · Tomasz Nowicki
Hi Eric,
Just letting you know that I am facing another issue with the following setup:
1. host (4.12 kernel & 64K page) and VM (4.12 kernel & 64K page)
2. QEMU + -netdev type=tap,ifname=tap,id=net0 -device virtio-net-pci,netdev=net0,iommu_platform,disable-modern=off,disable-legacy=on2. On VM, I allocate some huge pages and run DPDK testpmd app:
# echo 4 > /sys/kernel/mm/hugepages/hugepages-524288kB/nr_hugepages # ./dpdk/usertools/dpdk-devbind.py -b vfio-pci 0000:00:02.0 # ./dpdk/build/app/testpmd -l 0-13 -n 4 -w 0000:00:02.0 -- --disable-hw-vlan-filter --disable-rss -i EAL: Detected 14 lcore(s) EAL: Probing VFIO support... EAL: VFIO support initialized EAL: PCI device 0000:00:02.0 on NUMA socket -1 EAL: probe driver: 1af4:1041 net_virtio EAL: using IOMMU type 1 (Type 1) EAL: iommu_map_dma vaddr ffff20000000 size 80000000 iova 120000000 EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (0) EAL: Can't write to PCI bar (0) : offset (4) EAL: Can't write to PCI bar (0) : offset (14) EAL: Can't write to PCI bar (0) : offset (e) EAL: Can't read from PCI bar (0) : offset (c) EAL: Requested device 0000:00:02.0 cannot be used EAL: No probed ethernet devices Interactive-mode selected USER1: create a new mbuf pool <mbuf_pool_socket_0>: n=251456, size=2176, socket=0Quoted 2 lines
When VM uses *4K pages* the same setup works fine. I will work on this but please let me know in case you already know what is going on.
Quoted 7 lines
No I did not face that one. I was able to launch testpmd without such early message. However I assigned an igbvf device to the guest and then to DPDK. I've never tested your config.
However as stated in my cover letter at the moment DPDK is not working for me because of storms of tlbi-on-maps. I intend to work on this as soon as get some bandwidth, sorry.
I found what was the reason of failure.
QEMU creates BARs for VIRTIO PCI device. The size of it depends on what is necessary for VIRTIO protocol. In my case the BAR is 16K size which is too small to be mmapable for kernel with 64K pages:vfio_pci_enable() -> vfio_pci_probe_mmaps() ->
here guest kernel checks that BAR size is smaller than current PAGE_SIZE and clears VFIO_REGION_INFO_FLAG_MMAP flag which prevents BAR from being mmapped later on. I added -device virtio-net-pci,...,page-per-vq=on to enlarge BAR size to 8M and now testpmd works fine. I wonder how the same setup is working with e.g. Intel or AMD IOMMU.
Thanks,
Tomasz
Hi Tomasz,
Quoted 56 lines · Tomasz Nowicki
Hi Eric,
Quoted 43 lines · Auger Eric
Hi Tomasz,
Quoted 38 lines · Tomasz Nowicki
Hi Eric,
Just letting you know that I am facing another issue with the following setup:
1. host (4.12 kernel & 64K page) and VM (4.12 kernel & 64K page)
2. QEMU + -netdev type=tap,ifname=tap,id=net0 -device virtio-net-pci,netdev=net0,iommu_platform,disable-modern=off,disable-legacy=on2. On VM, I allocate some huge pages and run DPDK testpmd app:
# echo 4 > /sys/kernel/mm/hugepages/hugepages-524288kB/nr_hugepages # ./dpdk/usertools/dpdk-devbind.py -b vfio-pci 0000:00:02.0 # ./dpdk/build/app/testpmd -l 0-13 -n 4 -w 0000:00:02.0 -- --disable-hw-vlan-filter --disable-rss -i EAL: Detected 14 lcore(s) EAL: Probing VFIO support... EAL: VFIO support initialized EAL: PCI device 0000:00:02.0 on NUMA socket -1 EAL: probe driver: 1af4:1041 net_virtio EAL: using IOMMU type 1 (Type 1) EAL: iommu_map_dma vaddr ffff20000000 size 80000000 iova 120000000 EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (12) EAL: Can't write to PCI bar (0) : offset (12) EAL: Can't read from PCI bar (0) : offset (0) EAL: Can't write to PCI bar (0) : offset (4) EAL: Can't write to PCI bar (0) : offset (14) EAL: Can't write to PCI bar (0) : offset (e) EAL: Can't read from PCI bar (0) : offset (c) EAL: Requested device 0000:00:02.0 cannot be used EAL: No probed ethernet devices Interactive-mode selected USER1: create a new mbuf pool <mbuf_pool_socket_0>: n=251456, size=2176, socket=0Quoted 2 lines
When VM uses *4K pages* the same setup works fine. I will work on this but please let me know in case you already know what is going on.
Quoted 7 lines
No I did not face that one. I was able to launch testpmd without such early message. However I assigned an igbvf device to the guest and then to DPDK. I've never tested your config.
However as stated in my cover letter at the moment DPDK is not working for me because of storms of tlbi-on-maps. I intend to work on this as soon as get some bandwidth, sorry.
I found what was the reason of failure.
Quoted 9 lines
QEMU creates BARs for VIRTIO PCI device. The size of it depends on what is necessary for VIRTIO protocol. In my case the BAR is 16K size which is too small to be mmapable for kernel with 64K pages:
vfio_pci_enable()->vfio_pci_probe_mmaps()->
here guest kernel checks that BAR size is smaller than currentPAGE_SIZEand clearsVFIO_REGION_INFO_FLAG_MMAPflag which prevents BAR from being mmapped later on. I added -device virtio-net-pci,...,page-per-vq=on to enlarge BAR size to 8M and now testpmd works fine. I wonder how the same setup is working with e.g. Intel or AMD IOMMU.
Hum OK. Yet another thing to investigate! thank you for your efforts and excellent news overall. Preparing a rebase ...
Thanks
Eric
Quoted 4 lines
Thanks,
Tomasz