Add stage-2 translation for SMMUv3
v2 cover Add stage-2 translation for SMMUv3
This patch series adds stage-2 translation support for SMMUv3. It is controlled by a new system property “arm-smmuv3.stage”.
- When set to “1”: Stage-1 only would be advertised and supported (default behaviour)
- When set to “2”: Stage-2 only would be advertised and supported.
- Value “all” is reserved for nesting support. However it is not implemented in this patch series (more about this in the end)
Features implemented in stage-2 are mostly synonymous with stage-1
- VMID16.
- Only AArch64 translation tables are supported.
- Stall is not supported.
- HTTU is not supported, SW is expected to maintain the Access flag.
To make it easy to support nesting, a new structure(SMMUS2Cfg) is embedded within SMMUTransCfg, to hold stage-2 configuration.
TLBs were updated to support VMID, where when stage-2 is used ASID are set to -1 and ignored and when stage-1 is used VMID is set to -1 and ignored.
As only one stage is supported at a time at the moment, TLB will represent IPA=>PA translation with proper attributes(granularity and t0sz) parsed from STEs for stage-2, and will represent VA=>PA translation with proper attributes parsed from the CDs for stage-1.
New commands where added that are used with stage-2
- CMD_TLBI_S12_VMALL: Invalidate all translations for a VMID.
- CMD_TLBI_S2_IPA: Invalidate stage-2 by VMID and IPA
These patches update OAS, as it used to be hardcoded to 44 bits, and according to user manual ”6.3.6 SMMU_IDR5”, OAS must match the system physical address size, so OAS is updated to be read from CPU PARANGE.
This patch series can be used to run Linux pKVM SMMUv3 patches (currently on the list) which controls stage-2 (from EL2) while providing a paravirtualized interface the host(EL1)
https://lore.kernel.org/kvmarm/[email protected]/
Looking forward, nesting is the next feature to go for, here are some thoughts about this:
- TLB would require big changes for this, we can go either for a combined implementation or per stage one. This would affect returns from PTW and invalidation commands.
- Stage-1 data structures should be translated by stage-2 if enabled (as context descriptors and ttb0/ttb1)
- Translated addresses from stage-1 should be translated by stage-2 if enabled.
- Record faults should be separated between stage-1 (CD_R) and stage-2 (S2R).
- Some existing commands(as CMD_TLBI_S2_IPA, CMD_TLBI_NH_ASID …) would be modified and some of those would be based on the design of the TLBs.
- Currently, VMID is ignored when stage-1 is used as it can’t be used with stage-2. However when nesting is advertised VMID shouldn’t be ignored even if stage-2 is bypassed.
Changes in v2:
-Collected Reviewed-by tags
-Add oas to SMMUS2Cfg, and use it in PTW
-Add stage member to to SMMUPTWEventInfo to differentiate stage-1 and
stage-2 PTW faults
-Move stage-2 knob to the last patch
-Add all STE parsing in one patch
-Pares and use S2PS and S2ENDI
-Split S2AFF patch over PTW and STE patches.
-Fix TLB aliasing issue
-Renaming and refactoring and rewording commits.
-Populate OAS based on PARANGE
-Add checks for stage-1 only commands
-Update trace events to hold translation stage, vmid when possible -Remove feature flags for supported stages as they were redundant with IDR0
Mostafa Saleh (11):
hw/arm/smmuv3: Add missing fields for IDR0
hw/arm/smmuv3: Update translation config to hold stage-2 hw/arm/smmuv3: Refactor stage-1 PTW
hw/arm/smmuv3: Add page table walk for stage-2 hw/arm/smmuv3: Parse STE config for stage-2
hw/arm/smmuv3: Make TLB lookup work for stage-2 hw/arm/smmuv3: Add VMID to tlb tagging
hw/arm/smmuv3: Add CMDs related to stage-2
hw/arm/smmuv3: Add stage-2 support in iova notifier hw/arm/smmuv3: Populate OAS based on CPU PARANGE hw/arm/smmuv3: Add knob to choose translation stage and enable stage-2
hw/arm/smmu-common.c | 212 ++++++++++++++++++--- hw/arm/smmu-internal.h | 41 ++++ hw/arm/smmuv3-internal.h | 21 +-- hw/arm/smmuv3.c | 352 ++++++++++++++++++++++++++++++----- hw/arm/trace-events | 14 +- include/hw/arm/smmu-common.h | 32 +++- include/hw/arm/smmuv3.h | 4 + 7 files changed, 577 insertions(+), 99 deletions(-)
Signature · 1 line
2.39.2.637.g21b0678d19-goog
RFC PATCH v2 1/11 hw/arm/smmuv3: Add missing fields for IDR0
In preparation for adding stage-2 support.
Add IDR0 fields related to stage-2.
VMID16: 16-bit VMID supported.
S2P: Stage-2 translation supported.
They are described in 6.3.1 SMMU_IDR0.
No functional change intended.
---
Changes in V2:
- Collected Reviewed-by tags.
--- hw/arm/smmuv3-internal.h | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/smmuv3-internal.h +2 -0
@@ -34,10 +34,12 @@ typedef enum SMMUTranslationStatus {/* MMIO Registers */ REG32(IDR0, 0x0) + FIELD(IDR0, S2P, 0 , 1) FIELD(IDR0, S1P, 1 , 1) FIELD(IDR0, TTF, 2 , 2) FIELD(IDR0, COHACC, 4 , 1) FIELD(IDR0, ASID16, 12, 1) + FIELD(IDR0, VMID16, 18, 1) FIELD(IDR0, TTENDIAN, 21, 2) FIELD(IDR0, STALL_MODEL, 24, 2)FIELD (IDR0 ,TERM_MODEL ,26 ,1 )
Signature · 1 line
2.39.2.637.g21b0678d19-goog
RFC PATCH v2 2/11 hw/arm/smmuv3: Update translation config to hold stage-2
In reply to Mostafa SalehIn preparation for adding stage-2 support, add a S2 config struct(SMMUS2Cfg), composed of the following fields and embedded in the main SMMUTransCfg:
-tsz: Input range
-sl0: start level of translation
-affd: AF fault disable
-granule_sz: Granule page shift
-vmid: VMID
-vttb: PA of translation table
-oas: Output address size
They will be used in the next patches in stage-2 address translation.
No functional change intended.
---
Changes in v2:
-Add oas
--- include/hw/arm/smmu-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/hw/arm/smmu-common.h +11 -0
@@ -58,6 +58,16 @@ typedef struct SMMUTLBEntry {uint8_t granule; } SMMUTLBEntry; +typedef struct SMMUS2Cfg { +uint8_t tsz;/* Input range */ +uint8_t sl0;/* Start level of translation */ +bool affd;/* AF Fault Disable */ +uint8_t granule_sz;/* Granule page shift */ +uint8_t oas;/* Output address size */ +uint16_t vmid;/* Virtual machine ID */ +uint64_t vttb;/* PA of translation table */ +}SMMUS2Cfg ; +/* * Generic structure populated by derived SMMU devices * after decoding the configuration information and used as
@@ -77,6 +87,7 @@ typedef struct SMMUTransCfg {SMMUTransTableInfo tt[2 ];uint32_t iotlb_hits;/* counts IOTLB hits for this asid */ uint32_t iotlb_misses;/* counts IOTLB misses for this asid */ +struct SMMUS2Cfg s2cfg; } SMMUTransCfg; typedef struct SMMUDevice {
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 02/11] hw/arm/smmuv3: Update translation config to hold stage-2
Hi Mostafa,
Quoted 28 lines · Mostafa Saleh
In preparation for adding stage-2 support, add a S2 config struct(SMMUS2Cfg), composed of the following fields and embedded in the main SMMUTransCfg:
-tsz: Input range
-sl0: start level of translation
-affd: AF fault disable
-granule_sz: Granule page shift
-vmid: VMID
-vttb: PA of translation table
-oas: Output address sizeThey will be used in the next patches in stage-2 address translation.
No functional change intended.
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:(quoted diff) +0
-2-Add oas --- include/hw/arm/smmu-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/hw/arm/smmu-common.h +0
-0
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 62
Quoted 5 lines
include/hw/arm/smmu-common.h +2
-0@@ -58,6 +58,16 @@ typedef struct SMMUTLBEntry {uint8_t granule; } SMMUTLBEntry; +typedef struct SMMUS2Cfg { + uint8_t tsz; /* Input range */
nit: Size of IPA input region. Called t0sz
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 66
Quoted 4 lines
include/hw/arm/smmu-common.h +4
-0+uint8_t sl0;/* Start level of translation */ +bool affd;/* AF Fault Disable */ +uint8_t granule_sz;/* Granule page shift */ +uint8_t oas;/* Output address size */
called s2ps. if you don't want to rename you may add this in the comment.
I am suprised to not see S2R which would match S1 record_faults.
Also without further reading we can wonder wheter the parent iotlb_hits/misses also record S2 events?
I think we need to be/make clear what fields of the original S1 parent struct also are relevant for the S2 only case.
Maybe tag them with a specific comment S1-only or S1 | S2. It may be cleaner to introduce a union and common fields in the parent struct though.
Thanks
Eric
Quoted 15 lines
include/hw/arm/smmu-common.h +5
-0+uint16_t vmid;/* Virtual machine ID */ +uint64_t vttb;/* PA of translation table */ +} SMMUS2Cfg; +/* * Generic structure populated by derived SMMU devices * after decoding the configuration information and used as @@ -77,6 +87,7 @@ typedef struct SMMUTransCfg {SMMUTransTableInfo tt[2 ];uint32_t iotlb_hits;/* counts IOTLB hits for this asid */ uint32_t iotlb_misses;/* counts IOTLB misses for this asid */ +struct SMMUS2Cfg s2cfg; } SMMUTransCfg; typedef struct SMMUDevice {
Re: [RFC PATCH v2 02/11] hw/arm/smmuv3: Update translation config to hold stage-2
Hi Eric,
Thanks for reviewing the patch.
Quoted 34 lines · Eric Auger
Hi Mostafa,
Quoted 31 lines · Mostafa Saleh
In preparation for adding stage-2 support, add a S2 config struct(SMMUS2Cfg), composed of the following fields and embedded in the main SMMUTransCfg:
-tsz: Input range
-sl0: start level of translation
-affd: AF fault disable
-granule_sz: Granule page shift
-vmid: VMID
-vttb: PA of translation table
-oas: Output address sizeThey will be used in the next patches in stage-2 address translation.
No functional change intended.
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:(quoted diff) +0
-2-Add oas --- include/hw/arm/smmu-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/hw/arm/smmu-common.h +0
-0@@ -58,6 +58,16 @@ typedef struct SMMUTLBEntry {uint8_t granule; } SMMUTLBEntry;
Quoted 3 lines
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 62
Quoted 2 lines
include/hw/arm/smmu-common.h +2
-0+typedef struct SMMUS2Cfg { + uint8_t tsz; /* Input range */nit: Size of IPA input region. Called t0sz
I named it this way to be similar to stage-1, as SMMUTransTableInfo just calls it tsz, I guess that is because it can hold either t0sz or t1sz.
I can rename it for stage-2 to t0sz.
Quoted 5 lines
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 66
Quoted 4 lines
include/hw/arm/smmu-common.h +4
-0+uint8_t sl0;/* Start level of translation */ +bool affd;/* AF Fault Disable */ +uint8_t granule_sz;/* Granule page shift */ +uint8_t oas;/* Output address size */ called s2ps. if you don't want to rename you may add this in the comment.
This is not the S2PS parsed from the STE, but the effective value which is capped to SMMU_IDR5.OAS, which is used for checking output size, I can add a clarifying comment.
Quoted 1 line
I am suprised to not see S2R which would match S1
record_faults.
I was thinking about this also, right now we piggy back on record_faults in SMMUTransCfg.
But it makes more sense to separate this from the beginning as other fields. I will update that by adding record_faults field in SMMUS2Cfg.
Quoted 2 lines
Also without further reading we can wonder wheter the parent iotlb_hits/misses also record S2 events?
For iotlb_*, they are shared also. However, I think this is not important for now as it is not architectural, and it produces the correct output as only one stage is advertised at the moment.
When nesting is supported, TLB implementation might change and then we can take a decision about this.
Quoted 4 lines
I think we need to be/make clear what fields of the original S1 parent struct also are relevant for the S2 only case.
Maybe tag them with a specific comment S1-only or S1 | S2. It may be cleaner to introduce a union and common fields in the parent struct though.
I agree, maybe we encapsulate stage-1 only fields in a similar struct and leave common fields outside.
struct SMMUTransCfg:
stage, bypassed, disabled, iotlb_* //common fields struct SMMUS2Cfg struct SMMUS1Cfg ttb,asid....
Or we can add SMMUS1Cfg and SMMUS2Cfg in a union for now and when nesting is supported we separate them.
Thanks,
Mostafa
Re: [RFC PATCH v2 02/11] hw/arm/smmuv3: Update translation config to hold stage-2
Hi Mostafa,
Quoted 39 lines · Mostafa Saleh
Hi Eric,
Thanks for reviewing the patch.
Quoted 34 lines · Eric Auger
Hi Mostafa,
Quoted 31 lines · Mostafa Saleh
In preparation for adding stage-2 support, add a S2 config struct(SMMUS2Cfg), composed of the following fields and embedded in the main SMMUTransCfg:
-tsz: Input range
-sl0: start level of translation
-affd: AF fault disable
-granule_sz: Granule page shift
-vmid: VMID
-vttb: PA of translation table
-oas: Output address sizeThey will be used in the next patches in stage-2 address translation.
No functional change intended.
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:(quoted diff) +0
-2-Add oas --- include/hw/arm/smmu-common.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/hw/arm/smmu-common.h +0
-0@@ -58,6 +58,16 @@ typedef struct SMMUTLBEntry {uint8_t granule; } SMMUTLBEntry;
Quoted 7 lines
Quoted 3 lines
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 62
Quoted 2 lines
include/hw/arm/smmu-common.h +2
-0+typedef struct SMMUS2Cfg { + uint8_t tsz; /* Input range */nit: Size of IPA input region. Called t0sz
I named it this way to be similar to stage-1, as SMMUTransTableInfo just calls it tsz, I guess that is because it can hold either t0sz or t1sz.
I can rename it for stage-2 to t0sz.
no strong opinion though, you can simply add this in the comment
Quoted 9 lines
Quoted 6 lines
include/hw/arm/smmu-common.h typedef struct SMMUTLBEntry { · line 66
Quoted 5 lines
include/hw/arm/smmu-common.h +4
-0+uint8_t sl0;/* Start level of translation */ +bool affd;/* AF Fault Disable */ +uint8_t granule_sz;/* Granule page shift */ +uint8_t oas;/* Output address size */ called s2ps. if you don't want to rename you may add this in the comment.
This is not the S2PS parsed from the STE, but the effective value which is capped to SMMU_IDR5.OAS, which is used for checking output size, I can add a clarifying comment.
ok
Quoted 6 lines
Quoted 2 lines
I am suprised to not see S2R which would match S1
record_faults.I was thinking about this also, right now we piggy back on
record_faultsin SMMUTransCfg.
But it makes more sense to separate this from the beginning as other fields. I will update that by addingrecord_faultsfield in SMMUS2Cfg.
ok
Quoted 16 lines
Quoted 3 lines
Also without further reading we can wonder wheter the parent iotlb_hits/misses also record S2 events?
For iotlb_*, they are shared also. However, I think this is not important for now as it is not architectural, and it produces the correct output as only one stage is advertised at the moment.
When nesting is supported, TLB implementation might change and then we can take a decision about this.Quoted 4 lines
I think we need to be/make clear what fields of the original S1 parent struct also are relevant for the S2 only case.
Maybe tag them with a specific comment S1-only or S1 | S2. It may be cleaner to introduce a union and common fields in the parent struct though.I agree, maybe we encapsulate stage-1 only fields in a similar struct and leave common fields outside.
Quoted 8 lines
struct SMMUTransCfg:
stage, bypassed, disabled, iotlb_* //common fields struct SMMUS2Cfg struct SMMUS1Cfg ttb,asid....Or we can add SMMUS1Cfg and SMMUS2Cfg in a union for now and when nesting is supported we separate them.
yeah that would be cleaner but it is also more invasive. At least make it clear in the comments and commit msg what is used for each stage.
Thanks
Eric
Quoted 5 lines
Thanks,
Mostafa
RFC PATCH v2 3/11 hw/arm/smmuv3: Refactor stage-1 PTW
In reply to Mostafa SalehIn preparation for adding stage-2 support, rename smmu_ptw_64 to smmu_ptw_64_s1 and refactor some of the code so it can be reused in stage-2 page table walk.
Remove AA64 check from PTW as decode_cd already ensures that AA64 is used, otherwise it faults with C_BAD_CD.
A stage member is added to SMMUPTWEventInfo to differentiate between stage-1 and stage-2 ptw faults.
Add stage argument to trace_smmu_ptw_level be consistent with other trace events.
---
Changes in v2:
- Refactor common functions to be use in stage-2.
- Add stage to SMMUPTWEventInfo.
- Remove AA64 check.
--- hw/arm/smmu-common.c | 27 ++++++++++----------------- hw/arm/smmuv3.c | 2 ++ hw/arm/trace-events | 2 +- include/hw/arm/smmu-common.h | 15 ++++++++++++--- 4 files changed, 25 insertions(+), 21 deletions(-)
hw/arm/smmu-common.c +10 -17
@@ -264,7 +264,7 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_t iova) }/** -* smmu_ptw_64 - VMSAv8-64 Walk of the page tables for a given IOVA +* smmu_ptw_64_s1 - VMSAv8-64 Walk of the page tables for a given IOVA * @cfg: translation config * @iova: iova to translate * @perm: access type
@@ -276,9 +276,9 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_t iova)* Upon success, @tlbe is filled with translated_addr and entry * permission rights. */ -static int smmu_ptw_64 (SMMUTransCfg *cfg, -dma_addr_t iova,IOMMUAccessFlags perm, -SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) +static int smmu_ptw_64_s1 (SMMUTransCfg *cfg, +dma_addr_t iova,IOMMUAccessFlags perm, +SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) {dma_addr_t baseaddr, indexmask;int stage = cfg->stage;
@@ -291,14 +291,14 @@ static int smmu_ptw_64(SMMUTransCfg *cfg, } granule_sz = tt->granule_sz; - stride = granule_sz -3 ; + stride =SMMU_STRIDE (granule_sz); inputsize =64 - tt->tsz; level =4 - (inputsize -4 ) / stride; - indexmask = (1ULL << (inputsize - (stride * (4 - level)))) -1 ; + indexmask =SMMU_IDXMSK (inputsize, stride, level); baseaddr =extract64 (tt->ttb,0 ,48 ); baseaddr &= ~indexmask; -while (level <=3 ) { +while (level <SMMU_LEVELS ) {uint64_t subpage_size =1ULL <<level_shift (level, granule_sz);uint64_t mask = subpage_size -1 ;uint32_t offset =iova_level_offset (iova, inputsize, level, granule_sz);
@@ -309,7 +309,7 @@ static int smmu_ptw_64(SMMUTransCfg *cfg,if (get_pte (baseaddr, offset, &pte, info)) { goto error; } -trace_smmu_ptw_level (level, iova, subpage_size, +trace_smmu_ptw_level (stage, level, iova, subpage_size, baseaddr, offset, pte);if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) {
@@ -358,6 +358,7 @@ static int smmu_ptw_64(SMMUTransCfg *cfg, info->type =SMMU_PTW_ERR_TRANSLATION ; error: + info->stage =1 ; tlbe->entry.perm =IOMMU_NONE ;return -EINVAL ; }
@@ -376,15 +377,7 @@ error:int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) { -if (!cfg->aa64) { -/* -* This code path is not entered as we check this while decoding -* the configuration data in the derived SMMU model. -*/ -g_assert_not_reached (); - } - -return smmu_ptw_64 (cfg, iova, perm, tlbe, info); +return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); }/**
hw/arm/smmuv3.c +2 -0
@@ -716,6 +716,8 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, cached_entry =g_new0 (SMMUTLBEntry,1 );if (smmu_ptw (cfg, aligned_addr, flag, cached_entry, &ptw_info)) { +/* All faults from PTW has S2 field. */ + event.u.f_walk_eabt.s2 = (ptw_info.stage ==2 );g_free (cached_entry);switch (ptw_info.type) {case SMMU_PTW_ERR_WALK_EABT :
hw/arm/trace-events +1 -1
@@ -5,7 +5,7 @@ virt_acpi_setup(void) "No fw cfg or ACPI disabled. Bailing out." # smmu-common.c smmu_add_mr(const char *name) "%s" -smmu_ptw_level(int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "level=%d iova=0x%"PRIx64" subpage_sz=0x%zx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 +smmu_ptw_level(int stage, int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "stage=%d level=%d iova=0x%"PRIx64" subpage_sz=0x%zx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 smmu_ptw_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%"PRIx64 smmu_ptw_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_ptw_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"
include/hw/arm/smmu-common.h +12 -3
@@ -23,9 +23,17 @@#include "hw/pci/pci.h" #include "qom/object.h" -#define SMMU_PCI_BUS_MAX 256 -#define SMMU_PCI_DEVFN_MAX 256 -#define SMMU_PCI_DEVFN (sid) (sid & 0xFF) +#define SMMU_PCI_BUS_MAX 256 +#define SMMU_PCI_DEVFN_MAX 256 +#define SMMU_PCI_DEVFN (sid) (sid & 0xFF) + +#define SMMU_LEVELS 4 + +#define SMMU_STRIDE (gran) ((gran) - SMMU_LEVELS + 1) +#define SMMU_BIT_LVL (isz, strd, lvl) ((isz) - (strd) * \ + (SMMU_LEVELS - (lvl))) +#define SMMU_IDXMSK (isz, strd, lvl) ((1ULL << \ + SMMU_BIT_LVL(isz, strd, lvl)) - 1)/* * Page table walk error types
@@ -40,6 +48,7 @@ typedef enum { } SMMUPTWEventType;typedef struct SMMUPTWEventInfo { +int stage;SMMUPTWEventType type;dma_addr_t addr;/* fetched address that induced an abort, if any */ }SMMUPTWEventInfo ;
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 03/11] hw/arm/smmuv3: Refactor stage-1 PTW
Hi Mostafa,
Quoted 142 lines · Mostafa Saleh
In preparation for adding stage-2 support, rename
smmu_ptw_64tosmmu_ptw_64_s1and refactor some of the code so it can be reused in stage-2 page table walk.Remove AA64 check from PTW as
decode_cdalready ensures that AA64 is used, otherwise it faults withC_BAD_CD.A stage member is added to SMMUPTWEventInfo to differentiate between stage-1 and stage-2 ptw faults.
Add stage argument to
trace_smmu_ptw_levelbe consistent with other trace events.Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:
- Refactor common functions to be use in stage-2.
- Add stage to SMMUPTWEventInfo.
- Remove AA64 check.--- hw/arm/smmu-common.c | 27 ++++++++++----------------- hw/arm/smmuv3.c | 2 ++ hw/arm/trace-events | 2 +- include/hw/arm/smmu-common.h | 15 ++++++++++++--- 4 files changed, 25 insertions(+), 21 deletions(-)hw/arm/smmu-common.c +10
-17@@ -264,7 +264,7 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_t iova) }/** -* smmu_ptw_64 - VMSAv8-64 Walk of the page tables for a given IOVA +* smmu_ptw_64_s1 - VMSAv8-64 Walk of the page tables for a given IOVA * @cfg: translation config * @iova: iova to translate * @perm: access type @@ -276,9 +276,9 @@ SMMUTransTableInfo *select_tt(SMMUTransCfg *cfg, dma_addr_t iova)* Upon success, @tlbe is filled with translated_addr and entry * permission rights. */ -static int smmu_ptw_64 (SMMUTransCfg *cfg, -dma_addr_t iova,IOMMUAccessFlags perm, -SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) +static int smmu_ptw_64_s1 (SMMUTransCfg *cfg, +dma_addr_t iova,IOMMUAccessFlags perm, +SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) {dma_addr_t baseaddr, indexmask;int stage = cfg->stage;@@ -291,14 +291,14 @@ static int smmu_ptw_64(SMMUTransCfg *cfg, } granule_sz = tt->granule_sz; - stride = granule_sz -3 ; + stride =SMMU_STRIDE (granule_sz); inputsize =64 - tt->tsz; level =4 - (inputsize -4 ) / stride; - indexmask = (1ULL << (inputsize - (stride * (4 - level)))) -1 ; + indexmask =SMMU_IDXMSK (inputsize, stride, level); baseaddr =extract64 (tt->ttb,0 ,48 ); baseaddr &= ~indexmask; -while (level <=3 ) { +while (level <SMMU_LEVELS ) {uint64_t subpage_size =1ULL <<level_shift (level, granule_sz);uint64_t mask = subpage_size -1 ;uint32_t offset =iova_level_offset (iova, inputsize, level, granule_sz);@@ -309,7 +309,7 @@ static int smmu_ptw_64(SMMUTransCfg *cfg,if (get_pte (baseaddr, offset, &pte, info)) { goto error; } -trace_smmu_ptw_level (level, iova, subpage_size, +trace_smmu_ptw_level (stage, level, iova, subpage_size, baseaddr, offset, pte);if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) {@@ -358,6 +358,7 @@ static int smmu_ptw_64(SMMUTransCfg *cfg, info->type =SMMU_PTW_ERR_TRANSLATION ; error: + info->stage =1 ; tlbe->entry.perm =IOMMU_NONE ;return -EINVAL ; }@@ -376,15 +377,7 @@ error:int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) { -if (!cfg->aa64) { -/* -* This code path is not entered as we check this while decoding -* the configuration data in the derived SMMU model. -*/ -g_assert_not_reached (); - } - -return smmu_ptw_64 (cfg, iova, perm, tlbe, info); +return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); }/** hw/arm/smmuv3.c +2
-0@@ -716,6 +716,8 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, cached_entry =g_new0 (SMMUTLBEntry,1 );if (smmu_ptw (cfg, aligned_addr, flag, cached_entry, &ptw_info)) { +/* All faults from PTW has S2 field. */ + event.u.f_walk_eabt.s2 = (ptw_info.stage ==2 );g_free (cached_entry);switch (ptw_info.type) {case SMMU_PTW_ERR_WALK_EABT :hw/arm/trace-events +1
-1@@ -5,7 +5,7 @@ virt_acpi_setup(void) "No fw cfg or ACPI disabled. Bailing out." # smmu-common.c smmu_add_mr(const char *name) "%s" -smmu_ptw_level(int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "level=%d iova=0x%"PRIx64" subpage_sz=0x%zx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 +smmu_ptw_level(int stage, int level, uint64_t iova, size_t subpage_size, uint64_t baseaddr, uint32_t offset, uint64_t pte) "stage=%d level=%d iova=0x%"PRIx64" subpage_sz=0x%zx baseaddr=0x%"PRIx64" offset=%d => pte=0x%"PRIx64 smmu_ptw_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%"PRIx64 smmu_ptw_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_ptw_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"include/hw/arm/smmu-common.h +1
-3@@ -23,9 +23,17 @@#include "hw/pci/pci.h" #include "qom/object.h" -#define SMMU_PCI_BUS_MAX 256 -#define SMMU_PCI_DEVFN_MAX 256 -#define SMMU_PCI_DEVFN (sid) (sid & 0xFF) +#define SMMU_PCI_BUS_MAX 256
include/hw/arm/smmu-common.h line 36
Quoted 10 lines
include/hw/arm/smmu-common.h +10
-0+#define SMMU_PCI_DEVFN_MAX 256 +#define SMMU_PCI_DEVFN (sid) (sid & 0xFF) + +#define SMMU_LEVELS 4 + +#define SMMU_STRIDE (gran) ((gran) - SMMU_LEVELS + 1) +#define SMMU_BIT_LVL (isz, strd, lvl) ((isz) - (strd) * \ + (SMMU_LEVELS - (lvl))) +#define SMMU_IDXMSK (isz, strd, lvl) ((1ULL << \ + SMMU_BIT_LVL(isz, strd, lvl)) - 1)
This looks good to me. Just a question about the BIT_LVL and IDXMSK defines. Do they correspond to any documented pseudocode functions documented somewhere in the ARM ARM?
Besides
Thanks
Eric
Quoted 11 lines
include/hw/arm/smmu-common.h +1
-0/* * Page table walk error types @@ -40,6 +48,7 @@ typedef enum { } SMMUPTWEventType;typedef struct SMMUPTWEventInfo { +int stage;SMMUPTWEventType type;dma_addr_t addr;/* fetched address that induced an abort, if any */ }SMMUPTWEventInfo ;
Re: [RFC PATCH v2 03/11] hw/arm/smmuv3: Refactor stage-1 PTW
Hi Eric,
Quoted 10 lines · Eric Auger
include/hw/arm/smmu-common.h line 36
Quoted 7 lines
include/hw/arm/smmu-common.h +7
-0+#define SMMU_LEVELS 4 + +#define SMMU_STRIDE (gran) ((gran) - SMMU_LEVELS + 1) +#define SMMU_BIT_LVL (isz, strd, lvl) ((isz) - (strd) * \ + (SMMU_LEVELS - (lvl))) +#define SMMU_IDXMSK (isz, strd, lvl) ((1ULL << \ + SMMU_BIT_LVL(isz, strd, lvl)) - 1)This looks good to me. Just a question about the
BIT_LVLand IDXMSK defines. Do they correspond to any documented pseudocode functions documented somewhere in the ARM ARM?
I see they are not implemented as functions in ARM ARM, but as part of aarch64/translation/vmsa_addrcalc/AArch64.TTBaseAddress:
constant integer FINAL_LEVEL = 3; levels = FINAL_LEVEL - startlevel; tsize = (iasize - (levels*stride + granulebits)) + 3; tablebase = Align(tablebase, 1 << tsize);
This gives the same result, however the equations are a bit different as they use final level(3), while we use number of levels(4).
Thanks,
Mostafa
RFC PATCH v2 4/11 hw/arm/smmuv3: Add page table walk for stage-2
In reply to Mostafa SalehIn preparation for adding stage-2 support, add Stage-2 PTW code. Only Aarch64 format is supported as stage-1.
Nesting stage-1 and stage-2 is not supported right now.
HTTU is not supported, SW is expected to maintain the Access flag. This is described in the SMMUv3 manual "5.2. Stream Table Entry" in "[181] S2AFFD".
This flag determines the behavior on access of a stage-2 page whose descriptor has AF == 0:
- 0b0: An Access flag fault occurs (stall not supported).
- 0b1: An Access flag fault never occurs.
An Access fault takes priority over a Permission fault.
Checks for IPA and output PA are done according to the user manual "3.4 Address sizes".
---
Changes in v2:
- Squash S2AFF PTW code.
- Use common functions between stage-1 and stage-2.
- Add checks for IPA and out PA.
--- hw/arm/smmu-common.c | 132 ++++++++++++++++++++++++++++++++++++++++- hw/arm/smmu-internal.h | 39 ++++++++++++ 2 files changed, 170 insertions(+), 1 deletion(-)
hw/arm/smmu-common.c +131 -1
@@ -363,6 +363,130 @@ error:return -EINVAL ; } +/** +* smmu_ptw_64_s2 - VMSAv8-64 Walk of the page tables for a given IOVA +* for stage-2. +* @cfg: translation config +* @iova: iova to translate +* @perm: access type +* @tlbe: SMMUTLBEntry (out) +* @info: handle to an error info +* +* Return 0 on success, < 0 on error. In case of error, @info is filled +* and tlbe->perm is set to IOMMU_NONE. +* Upon success, @tlbe is filled with translated_addr and entry +* permission rights. +*/ +static int smmu_ptw_64_s2 (SMMUTransCfg *cfg, +dma_addr_t iova,IOMMUAccessFlags perm, +SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) +{ +const int stage =2 ; +int granule_sz = cfg->s2cfg.granule_sz; +/* ARM ARM: Table D8-7. */ +int inputsize =64 - cfg->s2cfg.tsz; +int level =get_start_level (cfg->s2cfg.sl0, granule_sz); +int stride =SMMU_STRIDE (granule_sz); +int idx =pgd_idx (level, granule_sz, iova); +/* +* Get the ttb from concatenated structure. +* The offset is the idx * size of each ttb(number of ptes * (sizeof(pte)) +*/ +uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 ,48 ) + (1 << stride) * + idx *sizeof (uint64_t ); +dma_addr_t indexmask =SMMU_IDXMSK (inputsize, stride, level); + + baseaddr &= ~indexmask; + +/* +* If the input address of a transaction exceeds the size of the IAS, a +* stage 1 Address Size fault occurs. +* For AA64, IAS = OAS +*/ +if (iova >= (1ULL << cfg->s2cfg.oas)) { + info->type =SMMU_PTW_ERR_ADDR_SIZE ; + info->stage =1 ; + goto error_no_stage; + } + +while (level <SMMU_LEVELS ) { +uint64_t subpage_size =1ULL <<level_shift (level, granule_sz); +uint64_t mask = subpage_size -1 ; +uint32_t offset =iova_level_offset (iova, inputsize, level, granule_sz); +uint64_t pte, gpa; +dma_addr_t pte_addr = baseaddr + offset *sizeof (pte); +uint8_t ap; + +if (get_pte (baseaddr, offset, &pte, info)) { + goto error; + } +trace_smmu_ptw_level (stage, level, iova, subpage_size, + baseaddr, offset, pte); +if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) { +trace_smmu_ptw_invalid_pte (stage, level, baseaddr, + pte_addr, offset, pte); +break ; + } + +if (is_table_pte (pte, level)) { + baseaddr =get_table_pte_address (pte, granule_sz); + level++; +continue ; + }else if (is_page_pte (pte, level)) { + gpa =get_page_pte_address (pte, granule_sz); +trace_smmu_ptw_page_pte (stage, level, iova, + baseaddr, pte_addr, pte, gpa); + }else { +uint64_t block_size; + + gpa =get_block_pte_address (pte, level, granule_sz, + &block_size); +trace_smmu_ptw_block_pte (stage, level, baseaddr, + pte_addr, pte, iova, gpa, + block_size >>20 ); + } + +/* +* If S2AFFD and PTE.AF are 0 => fault. (5.2. Stream Table Entry) +* An Access fault takes priority over a Permission fault. +*/ +if (!PTE_AF (pte) && !cfg->s2cfg.affd) { + info->type =SMMU_PTW_ERR_ACCESS ; + goto error; + } + + ap =PTE_AP (pte); +if (is_permission_fault_s2 (ap, perm)) { + info->type =SMMU_PTW_ERR_PERMISSION ; + goto error; + } + +/* +* The address output from the translation causes a stage 2 Address +* Size fault if it exceeds the effective PA output range. +*/ +if (gpa >= (1ULL << cfg->s2cfg.oas)) { + info->type =SMMU_PTW_ERR_ADDR_SIZE ; + goto error; + } + + tlbe->entry.translated_addr = gpa; + tlbe->entry.iova = iova & ~mask; + tlbe->entry.addr_mask = mask; + tlbe->entry.perm = ap; + tlbe->level = level; + tlbe->granule = granule_sz; +return 0 ; + } + info->type =SMMU_PTW_ERR_TRANSLATION ; + +error: + info->stage =2 ; +error_no_stage: + tlbe->entry.perm =IOMMU_NONE ; +return -EINVAL ; +} +/** * smmu_ptw - Walk the page tables for an IOVA, according to @cfg *
@@ -377,7 +501,13 @@ error:int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) { -return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); +if (cfg->stage ==1 ) { +return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); + }else if (cfg->stage ==2 ) { +return smmu_ptw_64_s2 (cfg, iova, perm, tlbe, info); + } + +g_assert_not_reached (); }/**
hw/arm/smmu-internal.h +39 -0
@@ -66,6 +66,8 @@#define PTE_APTABLE (pte) \ (extract64(pte, 61, 2)) +#define PTE_AF (pte) \ + (extract64(pte, 10, 1))/* * TODO: At the moment all transactions are considered as privileged (EL1) * as IOMMU translation callback does not pass user/priv attributes.
@@ -73,6 +75,9 @@#define is_permission_fault (ap, perm) \ (((perm) & IOMMU_WO) && ((ap) & 0x2)) +#define is_permission_fault_s2 (ap, perm) \ + (!((ap & perm) == perm)) +#define PTE_AP_TO_PERM (ap) \ (IOMMU_ACCESS_FLAG(true, !((ap) & 0x2)))
@@ -96,6 +101,40 @@ uint64_t iova_level_offset(uint64_t iova, int inputsize,MAKE_64BIT_MASK (0 , gsz -3 ); } +#define SMMU_MAX_S2_CONCAT 16 + +/* +* Relies on correctness of gran and sl0 from caller. +* FEAT_LPA2 and FEAT_TTST are not implemented. +*/ +static inline int get_start_level (int sl0 ,int gran) +{ +/* ARM ARM: Table D8-12. */ +if (gran ==12 ) { +return 2 - sl0; + } +/* ARM ARM: Table D8-22 and Table D8-31. */ +return 3 - sl0; +} + +/* +* Index in a concatenated first level stage-2 page table. +* ARM ARM: D8.2.2 Concatenated translation tables. +*/ +static inline int pgd_idx (int start_level,int granule,dma_addr_t iova) +{ +uint64_t ret; +/* +* Get the number of bits handled by next levels, then any extra bits in +* the address should index the concatenated tables. This relation can +* deduced from tables in ARM ARM: D8.2.7-9 +*/ +int shift = (SMMU_LEVELS - start_level) * (granule -3 ) + granule; + + ret = iova >> shift; +return ret; +} +#define SMMU_IOTLB_ASID (key) ((key).asid) typedef struct SMMUIOTLBPageInvInfo {
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 04/11] hw/arm/smmuv3: Add page table walk for stage-2
Hi Mostafa,
Quoted 14 lines · Mostafa Saleh
In preparation for adding stage-2 support, add Stage-2 PTW code. Only Aarch64 format is supported as stage-1.
Nesting stage-1 and stage-2 is not supported right now.
HTTU is not supported, SW is expected to maintain the Access flag. This is described in the SMMUv3 manual "5.2. Stream Table Entry" in "[181] S2AFFD".
This flag determines the behavior on access of a stage-2 page whose descriptor has AF == 0:
- 0b0: An Access flag fault occurs (stall not supported).
- 0b1: An Access flag fault never occurs.
An Access fault takes priority over a Permission fault.
Quoted 2 lines
Checks for IPA and output PA are done according to the user manual "3.4 Address sizes".
replace user manual by the exact ref of the doc. I guess this is IHI0070E
Quoted 26 lines
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:
- Squash S2AFF PTW code.
- Use common functions between stage-1 and stage-2.
- Add checks for IPA and out PA.--- hw/arm/smmu-common.c | 132 ++++++++++++++++++++++++++++++++++++++++- hw/arm/smmu-internal.h | 39 ++++++++++++ 2 files changed, 170 insertions(+), 1 deletion(-)hw/arm/smmu-common.c +6
-0@@ -363,6 +363,130 @@ error:return -EINVAL ; } +/** +* smmu_ptw_64_s2 - VMSAv8-64 Walk of the page tables for a given IOVA +* for stage-2. +* @cfg: translation config +* @iova: iova to translate +* @perm: access type
hw/arm/smmu-common.c error: · line 381
Quoted 10 lines
hw/arm/smmu-common.c +10
-0+* @tlbe: SMMUTLBEntry (out) +* @info: handle to an error info +* +* Return 0 on success, < 0 on error. In case of error, @info is filled +* and tlbe->perm is set to IOMMU_NONE. +* Upon success, @tlbe is filled with translated_addr and entry +* permission rights. +*/ +static int smmu_ptw_64_s2(SMMUTransCfg *cfg, + dma_addr_t iova, IOMMUAccessFlags perm,
Rename iova into ipa?
hw/arm/smmu-common.c error: · line 386
Quoted 5 lines
hw/arm/smmu-common.c +5
-0+ SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) +{ +const int stage =2 ; +int granule_sz = cfg->s2cfg.granule_sz; +/* ARM ARM: Table D8-7. */
You may refer the full reference
in DDI0487I.a as the chapter/table may vary. For instance in ARM DDI 0487F.c D8 corresponds to the activity monitor extensions
hw/arm/smmu-common.c error: · line 394
Quoted 8 lines
hw/arm/smmu-common.c +8
-0+int inputsize =64 - cfg->s2cfg.tsz; +int level =get_start_level (cfg->s2cfg.sl0, granule_sz); +int stride =SMMU_STRIDE (granule_sz); +int idx =pgd_idx (level, granule_sz, iova); +/* +* Get the ttb from concatenated structure. +* The offset is the idx * size of each ttb(number of ptes * (sizeof(pte)) +*/
what I don't get is the spec that concatenated tables are used if the initial lookup level would require less or equal than 16 entries. I don't see such kind of check or is done implicitly somewhere else?
hw/arm/smmu-common.c error: · line 404
Quoted 10 lines
hw/arm/smmu-common.c +10
-0+uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 ,48 ) + (1 << stride) * + idx *sizeof (uint64_t ); +dma_addr_t indexmask =SMMU_IDXMSK (inputsize, stride, level); + + baseaddr &= ~indexmask; + +/* +* If the input address of a transaction exceeds the size of the IAS, a +* stage 1 Address Size fault occurs. +* For AA64, IAS = OAS
then you may use a local variable max_as = cfg->s2cfg.oas used below and in
if (gpa >= (1ULL << cfg->s2cfg.oas)) {
this is not obvious though that the ias = oas. Where does it come from?
In implementations of SMMUv3.1 and later, this value is Reserved and S2PS behaves as 0b110 (52 bits). Effective_S2PS = MIN(STE.S2PS, SMMU_IDR5.OAS);
OAS is a maximum of 52 bits in SMMUv3.1 and later
hw/arm/smmu-common.c error: · line 412
Quoted 8 lines
hw/arm/smmu-common.c +8
-0+*/ +if (iova >= (1ULL << cfg->s2cfg.oas)) { + info->type =SMMU_PTW_ERR_ADDR_SIZE ; + info->stage =1 ; + goto error_no_stage; + } + +while (level <SMMU_LEVELS ) {
I would rename SMMU_LEVELs
Quoted 109 lines
hw/arm/smmu-common.c +84
-1+uint64_t subpage_size =1ULL <<level_shift (level, granule_sz); +uint64_t mask = subpage_size -1 ; +uint32_t offset =iova_level_offset (iova, inputsize, level, granule_sz); +uint64_t pte, gpa; +dma_addr_t pte_addr = baseaddr + offset *sizeof (pte); +uint8_t ap; + +if (get_pte (baseaddr, offset, &pte, info)) { + goto error; + } +trace_smmu_ptw_level (stage, level, iova, subpage_size, + baseaddr, offset, pte); +if (is_invalid_pte (pte) ||is_reserved_pte (pte, level)) { +trace_smmu_ptw_invalid_pte (stage, level, baseaddr, + pte_addr, offset, pte); +break ; + } + +if (is_table_pte (pte, level)) { + baseaddr =get_table_pte_address (pte, granule_sz); + level++; +continue ; + }else if (is_page_pte (pte, level)) { + gpa =get_page_pte_address (pte, granule_sz); +trace_smmu_ptw_page_pte (stage, level, iova, + baseaddr, pte_addr, pte, gpa); + }else { +uint64_t block_size; + + gpa =get_block_pte_address (pte, level, granule_sz, + &block_size); +trace_smmu_ptw_block_pte (stage, level, baseaddr, + pte_addr, pte, iova, gpa, + block_size >>20 ); + } + +/* +* If S2AFFD and PTE.AF are 0 => fault. (5.2. Stream Table Entry) +* An Access fault takes priority over a Permission fault. +*/ +if (!PTE_AF (pte) && !cfg->s2cfg.affd) { + info->type =SMMU_PTW_ERR_ACCESS ; + goto error; + } + + ap =PTE_AP (pte); +if (is_permission_fault_s2 (ap, perm)) { + info->type =SMMU_PTW_ERR_PERMISSION ; + goto error; + } + +/* +* The address output from the translation causes a stage 2 Address +* Size fault if it exceeds the effective PA output range. +*/ +if (gpa >= (1ULL << cfg->s2cfg.oas)) { + info->type =SMMU_PTW_ERR_ADDR_SIZE ; + goto error; + } + + tlbe->entry.translated_addr = gpa; + tlbe->entry.iova = iova & ~mask; + tlbe->entry.addr_mask = mask; + tlbe->entry.perm = ap; + tlbe->level = level; + tlbe->granule = granule_sz; +return 0 ; + } + info->type =SMMU_PTW_ERR_TRANSLATION ; + +error: + info->stage =2 ; +error_no_stage: + tlbe->entry.perm =IOMMU_NONE ; +return -EINVAL ; +} +/** * smmu_ptw - Walk the page tables for an IOVA, according to @cfg * @@ -377,7 +501,13 @@ error:int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) { -return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); +if (cfg->stage ==1 ) { +return smmu_ptw_64_s1 (cfg, iova, perm, tlbe, info); + }else if (cfg->stage ==2 ) { +return smmu_ptw_64_s2 (cfg, iova, perm, tlbe, info); + } + +g_assert_not_reached (); }/** hw/arm/smmu-internal.h +2
-0@@ -66,6 +66,8 @@#define PTE_APTABLE (pte) \ (extract64(pte, 61, 2)) +#define PTE_AF (pte) \ + (extract64(pte, 10, 1))/* * TODO: At the moment all transactions are considered as privileged (EL1) * as IOMMU translation callback does not pass user/priv attributes.
hw/arm/smmu-internal.h line 78
Quoted 4 lines
hw/arm/smmu-internal.h +1
-0@@ -73,6 +75,9 @@#define is_permission_fault (ap, perm) \ (((perm) & IOMMU_WO) && ((ap) & 0x2)) +#define is_permission_fault_s2 (ap, perm) \
I would rename ap param into s2ap. This is the name of the field in the spec
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 104
Quoted 10 lines
hw/arm/smmu-internal.h +3
-0+ (!((ap & perm) == perm)) +#define PTE_AP_TO_PERM (ap) \ (IOMMU_ACCESS_FLAG(true, !((ap) & 0x2)))@@ -96,6 +101,40 @@ uint64_t iova_level_offset(uint64_t iova, int inputsize,MAKE_64BIT_MASK (0 , gsz -3 ); } +#define SMMU_MAX_S2_CONCAT 16
it is not really an SMMU property (same as SMMU_LEVELS by the way). This is rather something related to VMSA spec, no?.
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 107
Quoted 3 lines
hw/arm/smmu-internal.h +3
-0+ +/* +* Relies on correctness of gran and sl0 from caller.
I would remove the above line as we generally expect the caller to behave properly or do you mean we do not handle any sanity check? I refer to some of them in target/arm/ptw.c:check_s2_mmu_setup()
Quoted 7 lines
hw/arm/smmu-internal.h +7
-0+* FEAT_LPA2 and FEAT_TTST are not implemented. +*/ +static inline int get_start_level (int sl0 ,int gran) +{ +/* ARM ARM: Table D8-12. */ +if (gran ==12 ) { +return 2 - sl0;
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 124
Quoted 10 lines
hw/arm/smmu-internal.h +10
-0+ } +/* ARM ARM: Table D8-22 and Table D8-31. */ +return 3 - sl0; +} + +/* +* Index in a concatenated first level stage-2 page table. +* ARM ARM: D8.2.2 Concatenated translation tables. +*/ +static inline int pgd_idx (int start_level,int granule,dma_addr_t iova)
then the name of the function may better reflect what is does?
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 132
Quoted 8 lines
hw/arm/smmu-internal.h +8
-0+{ +uint64_t ret; +/* +* Get the number of bits handled by next levels, then any extra bits in +* the address should index the concatenated tables. This relation can +* deduced from tables in ARM ARM: D8.2.7-9 +*/ +int shift = (SMMU_LEVELS - start_level) * (granule -3 ) + granule;
this looks like level_shift() with level = start_level - 1, no. s/granule_sz/gsz or granule_sz to match the rest of the code
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 140
Quoted 8 lines
hw/arm/smmu-internal.h +5
-0+ + ret = iova >> shift; +return ret; +} +#define SMMU_IOTLB_ASID (key) ((key).asid) typedef struct SMMUIOTLBPageInvInfo {
Thanks
Eric
Re: [RFC PATCH v2 04/11] hw/arm/smmuv3: Add page table walk for stage-2
Hi Eric,
Quoted 17 lines · Eric Auger
Hi Mostafa,
Quoted 14 lines · Mostafa Saleh
In preparation for adding stage-2 support, add Stage-2 PTW code. Only Aarch64 format is supported as stage-1.
Nesting stage-1 and stage-2 is not supported right now.
HTTU is not supported, SW is expected to maintain the Access flag. This is described in the SMMUv3 manual "5.2. Stream Table Entry" in "[181] S2AFFD".
This flag determines the behavior on access of a stage-2 page whose descriptor has AF == 0:
- 0b0: An Access flag fault occurs (stall not supported).
- 0b1: An Access flag fault never occurs.
An Access fault takes priority over a Permission fault.
Quoted 3 lines
Quoted 2 lines
Checks for IPA and output PA are done according to the user manual "3.4 Address sizes".
replace user manual by the exact ref of the doc. I guess this is IHI0070E
Will do.
Quoted 8 lines
hw/arm/smmu-common.c error: · line 381
Quoted 7 lines
+ * Return 0 on success, < 0 on error. In case of error, @info is filled
+ * andtlbe->permis set toIOMMU_NONE.
+ * Upon success, @tlbe is filled withtranslated_addrand entry
+ * permission rights.
+ */hw/arm/smmu-common.c +2
-0+static int smmu_ptw_64_s2(SMMUTransCfg *cfg, + dma_addr_t iova, IOMMUAccessFlags perm,Rename iova into ipa?
Will do.
Quoted 8 lines
hw/arm/smmu-common.c error: · line 386
Quoted 5 lines
hw/arm/smmu-common.c +5
-0+ SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) +{ +const int stage =2 ; +int granule_sz = cfg->s2cfg.granule_sz; +/* ARM ARM: Table D8-7. */ You may refer the full reference
in DDI0487I.a as the chapter/table may vary. For instance in ARM DDI0487F.cD8 corresponds to the activity monitor extensions
Will do.
Quoted 11 lines
hw/arm/smmu-common.c error: · line 394
Quoted 8 lines
hw/arm/smmu-common.c +8
-0+int inputsize =64 - cfg->s2cfg.tsz; +int level =get_start_level (cfg->s2cfg.sl0, granule_sz); +int stride =SMMU_STRIDE (granule_sz); +int idx =pgd_idx (level, granule_sz, iova); +/* +* Get the ttb from concatenated structure. +* The offset is the idx * size of each ttb(number of ptes * (sizeof(pte)) +*/ what I don't get is the spec that concatenated tables are used if the initial lookup level would require less or equal than 16 entries. I don't see such kind of check or is done implicitly somewhere else?
Yes, this is checked in the STE patch in function s2_pgtable_config_valid, where it checks that the max input will not need more than 16 tables which means that the pagetable config is inconsistent, which means the STE is ILLEGAL.
Quoted 13 lines
hw/arm/smmu-common.c error: · line 404
Quoted 10 lines
hw/arm/smmu-common.c +10
-0+uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 ,48 ) + (1 << stride) * + idx *sizeof (uint64_t ); +dma_addr_t indexmask =SMMU_IDXMSK (inputsize, stride, level); + + baseaddr &= ~indexmask; + +/* +* If the input address of a transaction exceeds the size of the IAS, a +* stage 1 Address Size fault occurs. +* For AA64, IAS = OAS then you may use a local variable
max_as=cfg->s2cfg.oasused below and in
Quoted 6 lines
if (gpa >= (1ULL <<
cfg->s2cfg.oas)) {
this is not obvious though that the ias = oas. Where does it come from?In implementations of SMMUv3.1 and later, this value is Reserved and S2PS behaves as 0b110 (52 bits).
Effective_S2PS=MIN(STE.S2PS, SMMU_IDR5.OAS);
OAS is a maximum of 52 bits in SMMUv3.1 and later
IAS = OAS for AA64. Described in "3.4 Address sizes".
The first check is actually not correct, as input address should be compared to IAS(or OAS) while s2cfg.oas is effective PS.
I will rename s2cfg.oas to s2cfg.eff_ps to avoid confusion. I will change the check here to be against s2t0sz and in this case it causes stage-2 addr size fault.
I think the check for the IAS shouldn't be done here.
Quoted 9 lines
hw/arm/smmu-common.c error: · line 412
Quoted 8 lines
hw/arm/smmu-common.c +8
-0+*/ +if (iova >= (1ULL << cfg->s2cfg.oas)) { + info->type =SMMU_PTW_ERR_ADDR_SIZE ; + info->stage =1 ; + goto error_no_stage; + } + +while (level <SMMU_LEVELS ) {I would rename
SMMU_LEVELs
You mean replace SMMU_LEVELS with SMMU_LEVELs?
Quoted 10 lines
Quoted 10 lines
hw/arm/smmu-internal.h +2
-0+#define PTE_AF (pte) \ + (extract64(pte, 10, 1))/* * TODO: At the moment all transactions are considered as privileged (EL1) * as IOMMU translation callback does not pass user/priv attributes. @@ -73,6 +75,9 @@#define is_permission_fault (ap, perm) \ (((perm) & IOMMU_WO) && ((ap) & 0x2))
Quoted 2 lines
hw/arm/smmu-internal.h line 78
Quoted 1 line
hw/arm/smmu-internal.h +1
-0+#define is_permission_fault_s2 (ap, perm) \I would rename ap param into s2ap. This is the name of the field in the spec
Will do.
Quoted 5 lines
Quoted 5 lines
hw/arm/smmu-internal.h +2
-0+ (!((ap & perm) == perm)) +#define PTE_AP_TO_PERM (ap) \ (IOMMU_ACCESS_FLAG(true, !((ap) & 0x2)))
Quoted 7 lines
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 104
Quoted 5 lines
hw/arm/smmu-internal.h +1
-0@@ -96,6 +101,40 @@ uint64_t iova_level_offset(uint64_t iova, int inputsize,MAKE_64BIT_MASK (0 , gsz -3 ); } +#define SMMU_MAX_S2_CONCAT 16it is not really an SMMU property (same as
SMMU_LEVELSby the way). This is rather something related to VMSA spec, no?.
Yes, they are part of VMSA, however they are named this way as they are part of SMMU headers, should we rename them to something else?
Quoted 6 lines
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 107
Quoted 3 lines
hw/arm/smmu-internal.h +3
-0+ +/* +* Relies on correctness of gran and sl0 from caller. I would remove the above line as we generally expect the caller to behave properly or do you mean we do not handle any sanity check? I refer to some of them in target/arm/ptw.c:check_s2_mmu_setup()
We do sanity check in STE parsing, I added this line as this function is in a header file and anyone can use it, so to make it clear. However, it is very trivial, I will remove the comment.
Quoted 10 lines
Quoted 10 lines
hw/arm/smmu-internal.h +10
-0+* FEAT_LPA2 and FEAT_TTST are not implemented. +*/ +static inline int get_start_level (int sl0 ,int gran) +{ +/* ARM ARM: Table D8-12. */ +if (gran ==12 ) { +return 2 - sl0; + } +/* ARM ARM: Table D8-22 and Table D8-31. */ +return 3 - sl0;
Quoted 8 lines
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 124
Quoted 7 lines
hw/arm/smmu-internal.h +7
-0+} + +/* +* Index in a concatenated first level stage-2 page table. +* ARM ARM: D8.2.2 Concatenated translation tables. +*/ +static inline int pgd_idx (int start_level,int granule,dma_addr_t iova)then the name of the function may better reflect what is does?
This returns the index of the page table descriptor in a concatenated structure, this is actually close to what kvm calls it “kvm_pgd_page_idx()”, however, I can call it something more clear as pgd_concatenated_idx()?
Quoted 9 lines
hw/arm/smmu-internal.h uint64_t iova_level_offset(uint64_t iova, int inputsize, · line 132
Quoted 8 lines
hw/arm/smmu-internal.h +8
-0+{ +uint64_t ret; +/* +* Get the number of bits handled by next levels, then any extra bits in +* the address should index the concatenated tables. This relation can +* deduced from tables in ARM ARM: D8.2.7-9 +*/ +int shift = (SMMU_LEVELS - start_level) * (granule -3 ) + granule;this looks like
level_shift()with level =start_level- 1, no.
Yes, I will use level_shift() instead.
Quoted 1 line
s/granule_sz/gsz or
granule_szto match the rest of the code
Will do.
Thanks,
Mostafa
RFC PATCH v2 5/11 hw/arm/smmuv3: Parse STE config for stage-2
In reply to Mostafa SalehParse stage-2 configuration from STE and populate it in SMMUS2Cfg. Validity of these value are checked when possible.
Only AA64 tables are supported and STT is not supported.
According to SMMUv3 user manual "5.2 Stream Table Entry": All fields with an S2 prefix (with the exception of S2VMID) are IGNORED when stage-2 bypasses translation (Config[1] == 0).
Which means that VMID can be used(for TLB tagging) even if stage-2 is bypassed, so we parse it unconditionally when S2P exists. Otherwise it is set to -1.(only S1P)
As stall is not supported, if S2S is set the translation would abort. For S2R, we reuse the same code used for stage-1 with flag record_faults. However when nested translation is supported we would need to separate stage-1 and stage-2 faults.
---
Changes in V2:
- Parse S2PS and S2ENDI
- Squash with S2VMID parsing patch
- Squash with S2AFF parsing
- Squash with fault reporting patch
- Add check for S2T0SZ
- Renaming and refactoring code
--- hw/arm/smmuv3-internal.h | 4 ++ hw/arm/smmuv3.c | 138 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/smmuv3.h | 3 + 3 files changed, 145 insertions(+)
hw/arm/smmuv3-internal.h +4 -0
@@ -526,9 +526,13 @@ typedef struct CD {#define STE_S2TG (x) extract32((x)->word[5], 14, 2)#define STE_S2PS (x) extract32((x)->word[5], 16, 3)#define STE_S2AA64 (x) extract32((x)->word[5], 19, 1) +#define STE_S2ENDI (x) extract32((x)->word[5], 20, 1) +#define STE_S2AFFD (x) extract32((x)->word[5], 21, 1)#define STE_S2HD (x) extract32((x)->word[5], 24, 1)#define STE_S2HA (x) extract32((x)->word[5], 25, 1)#define STE_S2S (x) extract32((x)->word[5], 26, 1) +#define STE_S2R (x) extract32((x)->word[5], 27, 1) +#define STE_CTXPTR (x) \ ({ \ unsigned long addr; \
hw/arm/smmuv3.c +138 -0
151 lines not on this page · raw message
include/hw/arm/smmuv3.h +3 -0
@@ -83,4 +83,7 @@ struct SMMUv3Class {#define TYPE_ARM_SMMUV3 "arm-smmuv3" OBJECT_DECLARE_TYPE(SMMUv3State, SMMUv3Class, ARM_SMMUV3) +#define STAGE1_SUPPORTED (s) FIELD_EX32(s->idr[0], IDR0, S1P) +#define STAGE2_SUPPORTED (s) FIELD_EX32(s->idr[0], IDR0, S2P) +#endif
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 05/11] hw/arm/smmuv3: Parse STE config for stage-2
Hi Mostafa,
Quoted 2 lines · Mostafa Saleh
Parse stage-2 configuration from STE and populate it in SMMUS2Cfg. Validity of these value are checked when possible.
s/these value/field values
Quoted 2 lines
Only AA64 tables are supported and STT is not supported.
Small Translation Tables (STT)
Quoted 2 lines
According to SMMUv3 user manual "5.2 Stream Table Entry": All fields
it is not a user manual but rather an IP architecture spec. put the full ref?
Quoted 32 lines
with an S2 prefix (with the exception of S2VMID) are IGNORED when stage-2 bypasses translation (Config[1] == 0).
Which means that VMID can be used(for TLB tagging) even if stage-2 is bypassed, so we parse it unconditionally when S2P exists. Otherwise it is set to -1.(only S1P)
As stall is not supported, if S2S is set the translation would abort. For S2R, we reuse the same code used for stage-1 with flag
record_faults. However when nested translation is supported we would need to separate stage-1 and stage-2 faults.Signed-off-by Mostafa Saleh <[email protected]>---
Changes in V2:
- Parse S2PS and S2ENDI
- Squash with S2VMID parsing patch
- Squash with S2AFF parsing
- Squash with fault reporting patch
- Add check for S2T0SZ
- Renaming and refactoring code--- hw/arm/smmuv3-internal.h | 4 ++ hw/arm/smmuv3.c | 138 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/smmuv3.h | 3 + 3 files changed, 145 insertions(+)hw/arm/smmuv3-internal.h +0
-0
hw/arm/smmuv3-internal.h typedef struct CD { · line 530
Quoted 5 lines
hw/arm/smmuv3-internal.h +2
-0@@ -526,9 +526,13 @@ typedef struct CD {#define STE_S2TG (x) extract32((x)->word[5], 14, 2)#define STE_S2PS (x) extract32((x)->word[5], 16, 3)#define STE_S2AA64 (x) extract32((x)->word[5], 19, 1) +#define STE_S2ENDI (x) extract32((x)->word[5], 20, 1) +#define STE_S2AFFD (x) extract32((x)->word[5], 21, 1)
I am afraid there is a shift in the fields below. S2HD should be 23 (problem in the original code) and everything is shifted.
Quoted 14 lines
hw/arm/smmuv3-internal.h +2
-0#define STE_S2HD (x) extract32((x)->word[5], 24, 1)#define STE_S2HA (x) extract32((x)->word[5], 25, 1)#define STE_S2S (x) extract32((x)->word[5], 26, 1) +#define STE_S2R (x) extract32((x)->word[5], 27, 1) +#define STE_CTXPTR (x) \ ({ \ unsigned long addr; \hw/arm/smmuv3.c +0
-0@@ -329,6 +329,46 @@ static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid,return 0 ;
hw/arm/smmuv3.c static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid, · line 339
Quoted 10 lines
hw/arm/smmuv3.c +8
-0} +/* +* Max valid value is 39 when SMMU_IDR3.STT == 0. +* In architectures after SMMUv3.0: +* - If STE.S2TG selects a 4KB or 16KB granule, the minimum valid value for this +* field is MAX(16, 64-IAS) +* - If STE.S2TG selects a 64KB granule, the minimum valid value for this field +* is (64-IAS). +* As we only support AA64, IAS = OAS.
OK this comes from STE.S2T0SZ description on the SMMU arch spec. You can add this in previous patch too.
hw/arm/smmuv3.c static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid, · line 341
Quoted 2 lines
hw/arm/smmuv3.c +2
-0+*/ +static bool t0sz_valid (SMMUTransCfg *cfg)
use S2t0sz to avoid confusion with S1 stuff
hw/arm/smmuv3.c static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid, · line 352
Quoted 11 lines
hw/arm/smmuv3.c +11
-0+{ +if (cfg->s2cfg.tsz >39 ) { +return false; + } + +if (cfg->s2cfg.granule_sz ==16 ) { +return (cfg->s2cfg.tsz >=64 - cfg->s2cfg.oas); + } + +return (cfg->s2cfg.tsz >=MAX (64 - cfg->s2cfg.oas,16 )); +}
this chapter also states:
"The usable range of values is further constrained by a function of the starting level set by S2SL0 and, if S2AA64 == 1, granule size set by S2TG as described by the Armv8 translation system. Use of a value of S2T0SZ that is inconsistent with the permitted range (given S2SL0 and S2TG) is ILLEGAL."
hw/arm/smmuv3.c static int smmu_get_cd(SMMUv3State *s, STE *ste, uint32_t ssid, · line 360
Quoted 8 lines
hw/arm/smmuv3.c +8
-0+ +/* +* Return true if s2 page table config is valid. +* This checks with the configured start level, ias_bits and granularity we can +* have a valid page table as described in ARM ARM D8.2 Translation process. +* The idea here is to see for the highest possible number of IPA bits, how +* many concatenated tables we would need, if it is more than 16, then this is +* not possible.
why? in that case doesn't it mean that we can't use concatanated tables?
Quoted 30 lines
hw/arm/smmuv3.c +23
-0+*/ +static bool s2_pgtable_config_valid (uint8_t sl0,uint8_t t0sz,uint8_t gran) +{ +int level =get_start_level (sl0, gran); +uint64_t ipa_bits =64 - t0sz; +uint64_t max_ipa = (1ULL << ipa_bits) -1 ; +int nr_concat =pgd_idx (level, gran, max_ipa) +1 ; + +return nr_concat <=SMMU_MAX_S2_CONCAT ; +} +/* Returns < 0 in case of invalid STE, 0 otherwise */ static int decode_ste (SMMUv3State *s,SMMUTransCfg *cfg,STE *ste,SMMUEventInfo *event)@@ -354,7 +394,105 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg,return 0 ; } +/* +* If a stage is enabled in SW while not advertised, throw bad ste +* according to SMMU manual 5.2 Stream Table Entry - [3:1] Config. +*/ +if (!STAGE1_SUPPORTED (s) &&STE_CFG_S1_ENABLED (config)) { +qemu_log_mask (LOG_GUEST_ERROR ,"SMMUv3 S1 used but not supported.\n" ); + goto bad_ste; + } +if (!STAGE2_SUPPORTED (s) &&STE_CFG_S2_ENABLED (config)) { +qemu_log_mask (LOG_GUEST_ERROR ,"SMMUv3 S2 used but not supported.\n" ); + goto bad_ste; + }
hw/arm/smmuv3.c static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, · line 418
Quoted 10 lines
hw/arm/smmuv3.c +9
-0+ +if (STAGE2_SUPPORTED (s)) { +/* VMID is considered even if s2 is disabled. */ + cfg->s2cfg.vmid =STE_S2VMID (ste); + }else { +/* Default to -1 */ + cfg->s2cfg.vmid =-1 ; + } +if (STE_CFG_S2_ENABLED (config)) {
I think it would improve the readability to introduce a separate function decode_ste_s2_cftg() taking the s2cfg to be populated
Quoted 50 lines
hw/arm/smmuv3.c +50
-0+ cfg->stage =2 ; + +if (STE_S2AA64 (ste) ==0x0 ) { +qemu_log_mask (LOG_UNIMP , +"SMMUv3 AArch32 tables not supported\n" ); +g_assert_not_reached (); + } + +switch (STE_S2TG (ste)) { +case 0x0 :/* 4KB */ + cfg->s2cfg.granule_sz =12 ; +break ; +case 0x1 :/* 64KB */ + cfg->s2cfg.granule_sz =16 ; +break ; +case 0x2 :/* 16KB */ + cfg->s2cfg.granule_sz =14 ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"SMMUv3 bad STE S2TG: %x\n" ,STE_S2TG (ste)); + goto bad_ste; + } + + cfg->s2cfg.vttb =STE_S2TTB (ste); + + cfg->s2cfg.sl0 =STE_S2SL0 (ste); +/* FEAT_TTST not supported. */ +if (cfg->s2cfg.sl0 ==0x3 ) { +qemu_log_mask (LOG_UNIMP ,"SMMUv3 S2SL0 = 0x3 has no meaning!\n" ); + goto bad_ste; + } + + + cfg->s2cfg.oas =oas2bits (MIN (STE_S2PS (ste),SMMU_IDR5_OAS )); +/* +* It is ILLEGAL for the address in S2TTB to be outside the range +* described by the effective S2PS value. +*/ +if (cfg->s2cfg.vttb & ~(MAKE_64BIT_MASK (0 , cfg->s2cfg.oas))) { + goto bad_ste; + } + + cfg->s2cfg.tsz =STE_S2T0SZ (ste); + +if (!t0sz_valid (cfg)) { +qemu_log_mask (LOG_GUEST_ERROR ,"SMMUv3 bad STE S2T0SZ = %d\n" , + cfg->s2cfg.tsz); + goto bad_ste; + }
hw/arm/smmuv3.c static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, · line 478
Quoted 10 lines
hw/arm/smmuv3.c +10
-0+ +if (!s2_pgtable_config_valid (cfg->s2cfg.sl0, cfg->s2cfg.tsz, + cfg->s2cfg.granule_sz)) { +qemu_log_mask (LOG_GUEST_ERROR , +"SMMUv3 STE stage 2 config not valid!\n" ); + goto bad_ste; + } + +/* Only LE supported(IDR0.TTENDIAN). */ +if (STE_S2ENDI (ste)) {
qemu_log
Quoted 25 lines
hw/arm/smmuv3.c +17
-0+ goto bad_ste; + } + + cfg->s2cfg.affd =STE_S2AFFD (ste); +/* +* We reuse the same code used for stage-1 with flag record_faults. +* However when nested translation is supported we would +* need to separate stage-1 and stage-2 faults. +*/ + cfg->record_faults =STE_S2R (ste); +/* As stall is not supported. */ +if (STE_S2S (ste)) { +qemu_log_mask (LOG_UNIMP ,"SMMUv3 Stall not implemented!\n" ); + goto bad_ste; + } + +/* This is still here as stage 2 has not been fully enabled yet. */ qemu_log_mask (LOG_UNIMP ,"SMMUv3 does not support stage 2 yet\n" ); goto bad_ste; }include/hw/arm/smmuv3.h +0
-0
include/hw/arm/smmuv3.h struct SMMUv3Class { · line 89
Quoted 7 lines
include/hw/arm/smmuv3.h +3
-0@@ -83,4 +83,7 @@ struct SMMUv3Class {#define TYPE_ARM_SMMUV3 "arm-smmuv3" OBJECT_DECLARE_TYPE(SMMUv3State, SMMUv3Class, ARM_SMMUV3) +#define STAGE1_SUPPORTED (s) FIELD_EX32(s->idr[0], IDR0, S1P) +#define STAGE2_SUPPORTED (s) FIELD_EX32(s->idr[0], IDR0, S2P) +#endif
Thanks
Eric
Re: [RFC PATCH v2 05/11] hw/arm/smmuv3: Parse STE config for stage-2
Hi Eric,
Quoted 6 lines · Eric Auger
Hi Mostafa,
Quoted 2 lines · Mostafa Saleh
Parse stage-2 configuration from STE and populate it in SMMUS2Cfg. Validity of these value are checked when possible.
s/these value/field values
Will do.
Quoted 3 lines
Quoted 2 lines
Only AA64 tables are supported and STT is not supported.
Small Translation Tables (STT)
Will do.
Quoted 4 lines
Quoted 2 lines
According to SMMUv3 user manual "5.2 Stream Table Entry": All fields
it is not a user manual but rather an IP architecture spec. put the full ref?
This is mentioned in the SMMU manual with the same wording “All fields with an S2 prefix (with the exception of S2VMID) are IGNORED when stage 2 bypasses translation (Config[1] == 0)” in “5.2 Stream Table Entry” in page 179, ARM IHI0070.E.a
Quoted 14 lines
hw/arm/smmuv3-internal.h typedef struct CD { · line 530
Quoted 12 lines
3 files changed, 145 insertions(+)hw/arm/smmuv3-internal.h +2
-0@@ -526,9 +526,13 @@ typedef struct CD {#define STE_S2TG (x) extract32((x)->word[5], 14, 2)#define STE_S2PS (x) extract32((x)->word[5], 16, 3)#define STE_S2AA64 (x) extract32((x)->word[5], 19, 1) +#define STE_S2ENDI (x) extract32((x)->word[5], 20, 1) +#define STE_S2AFFD (x) extract32((x)->word[5], 21, 1)I am afraid there is a shift in the fields below. S2HD should be 23 (problem in the original code) and everything is shifted.
Oh, yes, I should have checked that, I just relied they are next to it. I will fix them.
Quoted 8 lines
hw/arm/smmuv3-internal.h typedef struct CD { · line 538
Quoted 8 lines
hw/arm/smmuv3-internal.h +8
-0+/* +* Max valid value is 39 when SMMU_IDR3.STT == 0. +* In architectures after SMMUv3.0: +* - If STE.S2TG selects a 4KB or 16KB granule, the minimum valid value for this +* field is MAX(16, 64-IAS) +* - If STE.S2TG selects a 64KB granule, the minimum valid value for this field +* is (64-IAS). +* As we only support AA64, IAS = OAS.
Quoted 5 lines
OK this comes from STE.S2T0SZ description on the SMMU arch spec. You can add this in previous patch too.
Quoted 2 lines
+ */
+static boolt0sz_valid(SMMUTransCfg *cfg)use S2t0sz to avoid confusion with S1 stuff
Will do.
Quoted 10 lines
Quoted 10 lines
hw/arm/smmuv3-internal.h +10
-0+{ +if (cfg->s2cfg.tsz >39 ) { +return false; + } + +if (cfg->s2cfg.granule_sz ==16 ) { +return (cfg->s2cfg.tsz >=64 - cfg->s2cfg.oas); + } + +return (cfg->s2cfg.tsz >=MAX (64 - cfg->s2cfg.oas,16 ));
Quoted 8 lines
Quoted 1 line
+}
this chapter also states:
"The usable range of values is further constrained by a function of the starting level set by S2SL0 and, if S2AA64 == 1, granule size set by S2TG as described by the Armv8 translation system. Use of a value of S2T0SZ that is inconsistent with the permitted range (given S2SL0 and S2TG) is ILLEGAL."
Yes, my understanding is that with some configurations the values of S2SL0 and S2T0SZ are correct but the final configuration will lead to input address that needs more than 16 concatenated tables which is invalid, this is checked in s2_pgtable_config_valid()
For example:
A configuration with granularity 4K (granule_sz = 12) SL0 = 1 (start level = 1)
S2T0SZ = 16 (48 bits)
This means that the 3 levels would cover 3*9 = 27 + 12 = 39 bits So there are extra 48-39 = 9 bits which requires 512 concatenated tables. This is invalid.
Quoted 9 lines
hw/arm/smmuv3-internal.h
Quoted 8 lines
hw/arm/smmuv3-internal.h +8
-0+ +/* +* Return true if s2 page table config is valid. +* This checks with the configured start level, ias_bits and granularity we can +* have a valid page table as described in ARM ARM D8.2 Translation process. +* The idea here is to see for the highest possible number of IPA bits, how +* many concatenated tables we would need, if it is more than 16, then this is +* not possible. why? in that case doesn't it mean that we can't use concatanated tables?
Yes, that means that we would need more than 16 tables, as mentioned above this is illegal.
Quoted 6 lines
Quoted 6 lines
hw/arm/smmuv3-internal.h +6
-0+ goto bad_ste; + } + +if (STAGE2_SUPPORTED (s)) { +/* VMID is considered even if s2 is disabled. */ + cfg->s2cfg.vmid =STE_S2VMID (ste);
Quoted 8 lines
hw/arm/smmuv3-internal.h
Quoted 6 lines
hw/arm/smmuv3-internal.h +5
-0+ }else { +/* Default to -1 */ + cfg->s2cfg.vmid =-1 ; + } +if (STE_CFG_S2_ENABLED (config)) {I think it would improve the readability to introduce a separate function
decode_ste_s2_cftg()taking the s2cfg to be populated
Yes, will do.
Quoted 11 lines
hw/arm/smmuv3-internal.h
Quoted 10 lines
hw/arm/smmuv3-internal.h +10
-0+ +if (!s2_pgtable_config_valid (cfg->s2cfg.sl0, cfg->s2cfg.tsz, + cfg->s2cfg.granule_sz)) { +qemu_log_mask (LOG_GUEST_ERROR , +"SMMUv3 STE stage 2 config not valid!\n" ); + goto bad_ste; + } + +/* Only LE supported(IDR0.TTENDIAN). */ +if (STE_S2ENDI (ste)) {
qemu_log
Will do.
Thanks,
Mostafa
RFC PATCH v2 6/11 hw/arm/smmuv3: Make TLB lookup work for stage-2
In reply to Mostafa SalehRight now, either stage-1 or stage-2 are supported, this simplifies how we can deal with TLBs.
This patch makes TLB lookup work if stage-2 is enabled instead of stage-1.
TLB lookup is done before a PTW, if a valid entry is found we won't do the PTW.
To be able to do TLB lookup, we need the correct tagging info, as granularity and input size, so we get this based on the supported translation stage. The TLB entries are added correctly from each stage PTW.
When nested translation is supported, this would need to change, for example if we go with a combined TLB implementation, we would need to use the min of the granularities in TLB.
As stage-2 shouldn't be tagged by ASID, it will be set to -1 if S1P is not enabled.
---
Changes in v2:
- check if S1 is enabled(not supported) when reading S1 TT.
--- hw/arm/smmuv3.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-)
hw/arm/smmuv3.c +34 -11
@@ -697,6 +697,9 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, SMMUTransCfg *cfg,STE ste;CD cd; +/* ASID defaults to -1 (if s1 is not supported). */ + cfg->asid =-1 ; + ret =smmu_find_ste (s, sid, &ste, event);if (ret) {return ret;
@@ -787,6 +790,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr,SMMUTLBEntry *cached_entry =NULL ;SMMUTransTableInfo *tt;SMMUTransCfg *cfg =NULL ; +uint8_t granule_sz, tsz;IOMMUTLBEntry entry = { .target_as = &address_space_memory, .iova = addr,
@@ -822,21 +826,40 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, goto epilogue; } - tt =select_tt (cfg, addr); -if (!tt) { -if (cfg->record_faults) { - event.type =SMMU_EVT_F_TRANSLATION ; - event.u.f_translation.addr = addr; - event.u.f_translation.rnw = flag &0x1 ; +if (cfg->stage ==1 ) { +/* Select stage1 translation table. */ + tt =select_tt (cfg, addr); +if (!tt) { +if (cfg->record_faults) { + event.type =SMMU_EVT_F_TRANSLATION ; + event.u.f_translation.addr = addr; + event.u.f_translation.rnw = flag &0x1 ; + } + status =SMMU_TRANS_ERROR ; + goto epilogue; } - status =SMMU_TRANS_ERROR ; - goto epilogue; - } + granule_sz = tt->granule_sz; + tsz = tt->tsz; - page_mask = (1ULL << (tt->granule_sz)) -1 ; + }else { +/* Stage2. */ + granule_sz = cfg->s2cfg.granule_sz; + tsz = cfg->s2cfg.tsz; + } +/* +* TLB lookup looks for granule and input size for a translation stage, +* as only one stage is supported right now, choose the right values +* from the configuration. +*/ + page_mask = (1ULL << granule_sz) -1 ; aligned_addr = addr & ~page_mask; - cached_entry =smmu_iotlb_lookup (bs, cfg, tt, aligned_addr); +SMMUTransTableInfo temp = { + .granule_sz = granule_sz, + .tsz = tsz, + }; + + cached_entry =smmu_iotlb_lookup (bs, cfg, &temp, aligned_addr);if (cached_entry) {if ((flag &IOMMU_WO ) && !(cached_entry->entry.perm &IOMMU_WO )) { status =SMMU_TRANS_ERROR ;
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 06/11] hw/arm/smmuv3: Make TLB lookup work for stage-2
Hi Mostafa,
Quoted 82 lines · Mostafa Saleh
Right now, either stage-1 or stage-2 are supported, this simplifies how we can deal with TLBs.
This patch makes TLB lookup work if stage-2 is enabled instead of stage-1.
TLB lookup is done before a PTW, if a valid entry is found we won't do the PTW.
To be able to do TLB lookup, we need the correct tagging info, as granularity and input size, so we get this based on the supported translation stage. The TLB entries are added correctly from each stage PTW.When nested translation is supported, this would need to change, for example if we go with a combined TLB implementation, we would need to use the min of the granularities in TLB.
As stage-2 shouldn't be tagged by ASID, it will be set to -1 if S1P is not enabled.
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:
- check if S1 is enabled(not supported) when reading S1 TT.--- hw/arm/smmuv3.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-)hw/arm/smmuv3.c +22
-10@@ -697,6 +697,9 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, SMMUTransCfg *cfg,STE ste;CD cd; +/* ASID defaults to -1 (if s1 is not supported). */ + cfg->asid =-1 ; + ret =smmu_find_ste (s, sid, &ste, event);if (ret) {return ret;@@ -787,6 +790,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr,SMMUTLBEntry *cached_entry =NULL ;SMMUTransTableInfo *tt;SMMUTransCfg *cfg =NULL ; +uint8_t granule_sz, tsz;IOMMUTLBEntry entry = { .target_as = &address_space_memory, .iova = addr,@@ -822,21 +826,40 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, goto epilogue; } - tt =select_tt (cfg, addr); -if (!tt) { -if (cfg->record_faults) { - event.type =SMMU_EVT_F_TRANSLATION ; - event.u.f_translation.addr = addr; - event.u.f_translation.rnw = flag &0x1 ; +if (cfg->stage ==1 ) { +/* Select stage1 translation table. */ + tt =select_tt (cfg, addr); +if (!tt) { +if (cfg->record_faults) { + event.type =SMMU_EVT_F_TRANSLATION ; + event.u.f_translation.addr = addr; + event.u.f_translation.rnw = flag &0x1 ; + } + status =SMMU_TRANS_ERROR ; + goto epilogue; } - status =SMMU_TRANS_ERROR ; - goto epilogue; - } + granule_sz = tt->granule_sz; + tsz = tt->tsz; - page_mask = (1ULL << (tt->granule_sz)) -1 ; + }else { +/* Stage2. */ + granule_sz = cfg->s2cfg.granule_sz; + tsz = cfg->s2cfg.tsz; + }
hw/arm/smmuv3.c static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, · line 857
Quoted 10 lines
hw/arm/smmuv3.c +7
-1+/* +* TLB lookup looks for granule and input size for a translation stage, +* as only one stage is supported right now, choose the right values +* from the configuration. +*/ + page_mask = (1ULL << granule_sz) -1 ; aligned_addr = addr & ~page_mask; - cached_entry =smmu_iotlb_lookup (bs, cfg, tt, aligned_addr); +SMMUTransTableInfo temp = {
Move the declaration at the top. Also rename temp into tt to be more explicit about what it is?
hw/arm/smmuv3.c static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, · line 865
Quoted 8 lines
hw/arm/smmuv3.c +5
-0+ .granule_sz = granule_sz, + .tsz = tsz, + }; + + cached_entry =smmu_iotlb_lookup (bs, cfg, &temp, aligned_addr);if (cached_entry) {if ((flag &IOMMU_WO ) && !(cached_entry->entry.perm &IOMMU_WO )) { status =SMMU_TRANS_ERROR ;
Besides, looks good to me
Thanks
Eric
Re: [RFC PATCH v2 06/11] hw/arm/smmuv3: Make TLB lookup work for stage-2
Hi Eric,
Quoted 8 lines · Eric Auger
Quoted 8 lines
hw/arm/smmuv3.c +6
-0+/* +* TLB lookup looks for granule and input size for a translation stage, +* as only one stage is supported right now, choose the right values +* from the configuration. +*/ + page_mask = (1ULL << granule_sz) -1 ; aligned_addr = addr & ~page_mask;
Quoted 4 lines
hw/arm/smmuv3.c static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, · line 857
Quoted 2 lines
hw/arm/smmuv3.c +1
-1- cached_entry =smmu_iotlb_lookup (bs, cfg, tt, aligned_addr); +SMMUTransTableInfo temp = {Move the declaration at the top. Also rename temp into tt to be more explicit about what it is?
I will move it to the top and remove granule_sz and tsz and just assign values to this struct.
There is a pointer already called tt, I can call it tt_combined as ideally this will hold the combined attributes for the TLB lookup.
Thanks,
Mostafa
RFC PATCH v2 7/11 hw/arm/smmuv3: Add VMID to tlb tagging
In reply to Mostafa SalehAllow TLB to be tagged with VMID.
If stage-1 is only supported, VMID is set to -1 and ignored from STE and CMD_TLBI_NH* cmds.
Update smmu_iotlb_insert trace event to have vmid.
---
Changes in v2:
-Fix TLB aliasing issue from missing check in smmu_iotlb_key_equal. -Add vmid to traces smmu_iotlb_insert and smmu_iotlb_lookup_hit/miss. -Add vmid to hash function.
--- hw/arm/smmu-common.c | 36 ++++++++++++++++++++++-------------- hw/arm/smmu-internal.h | 2 ++ hw/arm/smmuv3.c | 12 +++++++++--- hw/arm/trace-events | 6 +++--- include/hw/arm/smmu-common.h | 5 +++-- 5 files changed, 39 insertions(+), 22 deletions(-)
hw/arm/smmu-common.c +22 -14
@@ -38,7 +38,7 @@ static guint smmu_iotlb_key_hash(gconstpointer v)/* Jenkins hash */ a = b = c =JHASH_INITVAL +sizeof (*key); - a += key->asid + key->level + key->tg; + a += key->asid + key->vmid + key->level + key->tg; b +=extract64 (key->iova,0 ,32 ); c +=extract64 (key->iova,32 ,32 );
@@ -53,13 +53,15 @@ static gboolean smmu_iotlb_key_equal(gconstpointer v1, gconstpointer v2)SMMUIOTLBKey *k1 = (SMMUIOTLBKey *)v1, *k2 = (SMMUIOTLBKey *)v2;return (k1->asid == k2->asid) && (k1->iova == k2->iova) && - (k1->level == k2->level) && (k1->tg == k2->tg); + (k1->level == k2->level) && (k1->tg == k2->tg) && + (k1->vmid == k2->vmid); } -SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint64_t iova, +SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint16_t vmid,uint64_t iova,uint8_t tg,uint8_t level) { -SMMUIOTLBKey key = {.asid = asid, .iova = iova, .tg = tg, .level = level}; +SMMUIOTLBKey key = {.asid = asid, .vmid = vmid, .iova = iova, + .tg = tg, .level = level};return key; }
@@ -78,7 +80,8 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg,uint64_t mask = subpage_size -1 ;SMMUIOTLBKey key; - key =smmu_get_iotlb_key (cfg->asid, iova & ~mask, tg, level); + key =smmu_get_iotlb_key (cfg->asid, cfg->s2cfg.vmid, + iova & ~mask, tg, level); entry =g_hash_table_lookup (bs->iotlb, &key);if (entry) {break ;
@@ -88,13 +91,13 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg,if (entry) { cfg->iotlb_hits++; -trace_smmu_iotlb_lookup_hit (cfg->asid, iova, +trace_smmu_iotlb_lookup_hit (cfg->asid, cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses,100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses)); }else { cfg->iotlb_misses++; -trace_smmu_iotlb_lookup_miss (cfg->asid, iova, +trace_smmu_iotlb_lookup_miss (cfg->asid, cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses,100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses));
@@ -111,8 +114,10 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new)smmu_iotlb_inv_all (bs); } - *key =smmu_get_iotlb_key (cfg->asid, new->entry.iova, tg, new->level); -trace_smmu_iotlb_insert (cfg->asid, new->entry.iova, tg, new->level); + *key =smmu_get_iotlb_key (cfg->asid, cfg->s2cfg.vmid, new->entry.iova, + tg, new->level); +trace_smmu_iotlb_insert (cfg->asid, cfg->s2cfg.vmid, new->entry.iova, + tg, new->level);g_hash_table_insert (bs->iotlb, key, new); }
@@ -130,8 +135,7 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,return SMMU_IOTLB_ASID (*iotlb_key) == asid; } - -static gboolean smmu_hash_remove_by_asid_iova (gpointer key,gpointer value, +static gboolean smmu_hash_remove_by_asid_vmid_iova (gpointer key,gpointer value,gpointer user_data) {SMMUTLBEntry *iter = (SMMUTLBEntry *)value;
@@ -142,18 +146,21 @@ static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value,if (info->asid >=0 && info->asid !=SMMU_IOTLB_ASID (iotlb_key)) {return false; } +if (info->vmid >=0 && info->vmid !=SMMU_IOTLB_VMID (iotlb_key)) { +return false; + }return ((info->iova & ~entry->addr_mask) == entry->iova) || ((entry->iova & ~info->mask) == info->iova); } -void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova, +void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl) {/* if tg is not set we use 4KB range invalidation */ uint8_t granule = tg ? tg *2 +10 :12 ;if (ttl && (num_pages ==1 ) && (asid >=0 )) { -SMMUIOTLBKey key =smmu_get_iotlb_key (asid, iova, tg, ttl); +SMMUIOTLBKey key =smmu_get_iotlb_key (asid, vmid, iova, tg, ttl);if (g_hash_table_remove (s->iotlb, &key)) {return ;
@@ -166,10 +173,11 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,SMMUIOTLBPageInvInfo info = { .asid = asid, .iova = iova, + .vmid = vmid, .mask = (num_pages *1 << granule) -1 };g_hash_table_foreach_remove (s->iotlb, - smmu_hash_remove_by_asid_iova, + smmu_hash_remove_by_asid_vmid_iova, &info); }
hw/arm/smmu-internal.h +2 -0
@@ -136,9 +136,11 @@ static inline int pgd_idx(int start_level, int granule, dma_addr_t iova) }#define SMMU_IOTLB_ASID (key) ((key).asid) +#define SMMU_IOTLB_VMID (key) ((key).vmid)typedef struct SMMUIOTLBPageInvInfo {int asid; +int vmid;uint64_t iova;uint64_t mask; }SMMUIOTLBPageInvInfo ;
hw/arm/smmuv3.c +9 -3
@@ -1038,7 +1038,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd) {dma_addr_t end, addr =CMD_ADDR (cmd);uint8_t type =CMD_TYPE (cmd); -uint16_t vmid =CMD_VMID (cmd); +int vmid =-1 ;uint8_t scale =CMD_SCALE (cmd);uint8_t num =CMD_NUM (cmd);uint8_t ttl =CMD_TTL (cmd);
@@ -1047,6 +1047,12 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)uint64_t num_pages;uint8_t granule;int asid =-1 ; +SMMUv3State *smmuv3 =ARM_SMMUV3 (s); + +/* Only consider VMID if stage-2 is supported. */ +if (STAGE2_SUPPORTED (smmuv3)) { + vmid =CMD_VMID (cmd); + }if (type ==SMMU_CMD_TLBI_NH_VA ) { asid =CMD_ASID (cmd);
@@ -1055,7 +1061,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)if (!tg) {trace_smmuv3_s1_range_inval (vmid, asid, addr, tg,1 , ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg,1 ); -smmu_iotlb_inv_iova (s, asid, addr, tg,1 , ttl); +smmu_iotlb_inv_iova (s, asid, vmid, addr, tg,1 , ttl);return ; }
@@ -1073,7 +1079,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd) num_pages = (mask +1 ) >> granule;trace_smmuv3_s1_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg, num_pages); -smmu_iotlb_inv_iova (s, asid, addr, tg, num_pages, ttl); +smmu_iotlb_inv_iova (s, asid, vmid, addr, tg, num_pages, ttl); addr += mask +1 ; } }
hw/arm/trace-events +3 -3
@@ -14,9 +14,9 @@ smmu_iotlb_inv_all(void) "IOTLB invalidate all" smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" -smmu_iotlb_lookup_hit(uint16_t asid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" -smmu_iotlb_lookup_miss(uint16_t asid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" -smmu_iotlb_insert(uint16_t asid, uint64_t addr, uint8_t tg, uint8_t level) "IOTLB ++ asid=%d addr=0x%"PRIx64" tg=%d level=%d" +smmu_iotlb_lookup_hit(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" +smmu_iotlb_lookup_miss(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" +smmu_iotlb_insert(uint16_t asid, uint16_t vmid, uint64_t addr, uint8_t tg, uint8_t level) "IOTLB ++ asid=%d vmid=%d addr=0x%"PRIx64" tg=%d level=%d" # smmuv3.c smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)"
include/hw/arm/smmu-common.h +3 -2
@@ -118,6 +118,7 @@ typedef struct SMMUPciBus {typedef struct SMMUIOTLBKey {uint64_t iova;uint16_t asid; +uint16_t vmid;uint8_t tg;uint8_t level; }SMMUIOTLBKey ;
@@ -181,11 +182,11 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid);SMMUTLBEntry *smmu_iotlb_lookup (SMMUState *bs,SMMUTransCfg *cfg,SMMUTransTableInfo *tt,hwaddr iova);void smmu_iotlb_insert (SMMUState *bs,SMMUTransCfg *cfg,SMMUTLBEntry *entry); -SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint64_t iova, +SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint16_t vmid,uint64_t iova,uint8_t tg,uint8_t level);void smmu_iotlb_inv_all (SMMUState *s);void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid); -void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova, +void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl);/* Unmap the range of all the notifiers registered to any IOMMU mr */
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 07/11] hw/arm/smmuv3: Add VMID to tlb tagging
Hi Mostafa,
Quoted 1 line · Mostafa Saleh
Allow TLB to be tagged with VMID.
s/tlb/TLB in the commit msg.
Quoted 231 lines
If stage-1 is only supported, VMID is set to -1 and ignored from STE and CMD_TLBI_NH* cmds.
Update
smmu_iotlb_inserttrace event to have vmid.Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:(quoted diff) +0
-4-Fix TLB aliasing issue from missing check in smmu_iotlb_key_equal. -Add vmid to traces smmu_iotlb_insert and smmu_iotlb_lookup_hit/miss. -Add vmid to hash function. --- hw/arm/smmu-common.c | 36 ++++++++++++++++++++++-------------- hw/arm/smmu-internal.h | 2 ++ hw/arm/smmuv3.c | 12 +++++++++--- hw/arm/trace-events | 6 +++--- include/hw/arm/smmu-common.h | 5 +++-- 5 files changed, 39 insertions(+), 22 deletions(-)hw/arm/smmu-common.c +22
-14@@ -38,7 +38,7 @@ static guint smmu_iotlb_key_hash(gconstpointer v)/* Jenkins hash */ a = b = c =JHASH_INITVAL +sizeof (*key); - a += key->asid + key->level + key->tg; + a += key->asid + key->vmid + key->level + key->tg; b +=extract64 (key->iova,0 ,32 ); c +=extract64 (key->iova,32 ,32 );@@ -53,13 +53,15 @@ static gboolean smmu_iotlb_key_equal(gconstpointer v1, gconstpointer v2)SMMUIOTLBKey *k1 = (SMMUIOTLBKey *)v1, *k2 = (SMMUIOTLBKey *)v2;return (k1->asid == k2->asid) && (k1->iova == k2->iova) && - (k1->level == k2->level) && (k1->tg == k2->tg); + (k1->level == k2->level) && (k1->tg == k2->tg) && + (k1->vmid == k2->vmid); } -SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint64_t iova, +SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint16_t vmid,uint64_t iova,uint8_t tg,uint8_t level) { -SMMUIOTLBKey key = {.asid = asid, .iova = iova, .tg = tg, .level = level}; +SMMUIOTLBKey key = {.asid = asid, .vmid = vmid, .iova = iova, + .tg = tg, .level = level};return key; }@@ -78,7 +80,8 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg,uint64_t mask = subpage_size -1 ;SMMUIOTLBKey key; - key =smmu_get_iotlb_key (cfg->asid, iova & ~mask, tg, level); + key =smmu_get_iotlb_key (cfg->asid, cfg->s2cfg.vmid, + iova & ~mask, tg, level); entry =g_hash_table_lookup (bs->iotlb, &key);if (entry) {break ;@@ -88,13 +91,13 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg,if (entry) { cfg->iotlb_hits++; -trace_smmu_iotlb_lookup_hit (cfg->asid, iova, +trace_smmu_iotlb_lookup_hit (cfg->asid, cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses,100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses)); }else { cfg->iotlb_misses++; -trace_smmu_iotlb_lookup_miss (cfg->asid, iova, +trace_smmu_iotlb_lookup_miss (cfg->asid, cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses,100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses));@@ -111,8 +114,10 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new)smmu_iotlb_inv_all (bs); } - *key =smmu_get_iotlb_key (cfg->asid, new->entry.iova, tg, new->level); -trace_smmu_iotlb_insert (cfg->asid, new->entry.iova, tg, new->level); + *key =smmu_get_iotlb_key (cfg->asid, cfg->s2cfg.vmid, new->entry.iova, + tg, new->level); +trace_smmu_iotlb_insert (cfg->asid, cfg->s2cfg.vmid, new->entry.iova, + tg, new->level);g_hash_table_insert (bs->iotlb, key, new); }@@ -130,8 +135,7 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,return SMMU_IOTLB_ASID (*iotlb_key) == asid; } - -static gboolean smmu_hash_remove_by_asid_iova (gpointer key,gpointer value, +static gboolean smmu_hash_remove_by_asid_vmid_iova (gpointer key,gpointer value,gpointer user_data) {SMMUTLBEntry *iter = (SMMUTLBEntry *)value;@@ -142,18 +146,21 @@ static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value,if (info->asid >=0 && info->asid !=SMMU_IOTLB_ASID (iotlb_key)) {return false; } +if (info->vmid >=0 && info->vmid !=SMMU_IOTLB_VMID (iotlb_key)) { +return false; + }return ((info->iova & ~entry->addr_mask) == entry->iova) || ((entry->iova & ~info->mask) == info->iova); } -void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova, +void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl) {/* if tg is not set we use 4KB range invalidation */ uint8_t granule = tg ? tg *2 +10 :12 ;if (ttl && (num_pages ==1 ) && (asid >=0 )) { -SMMUIOTLBKey key =smmu_get_iotlb_key (asid, iova, tg, ttl); +SMMUIOTLBKey key =smmu_get_iotlb_key (asid, vmid, iova, tg, ttl);if (g_hash_table_remove (s->iotlb, &key)) {return ;@@ -166,10 +173,11 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,SMMUIOTLBPageInvInfo info = { .asid = asid, .iova = iova, + .vmid = vmid, .mask = (num_pages *1 << granule) -1 };g_hash_table_foreach_remove (s->iotlb, - smmu_hash_remove_by_asid_iova, + smmu_hash_remove_by_asid_vmid_iova, &info); }hw/arm/smmu-internal.h +2
-0@@ -136,9 +136,11 @@ static inline int pgd_idx(int start_level, int granule, dma_addr_t iova) }#define SMMU_IOTLB_ASID (key) ((key).asid) +#define SMMU_IOTLB_VMID (key) ((key).vmid)typedef struct SMMUIOTLBPageInvInfo {int asid; +int vmid;uint64_t iova;uint64_t mask; }SMMUIOTLBPageInvInfo ;hw/arm/smmuv3.c +9
-3@@ -1038,7 +1038,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd) {dma_addr_t end, addr =CMD_ADDR (cmd);uint8_t type =CMD_TYPE (cmd); -uint16_t vmid =CMD_VMID (cmd); +int vmid =-1 ;uint8_t scale =CMD_SCALE (cmd);uint8_t num =CMD_NUM (cmd);uint8_t ttl =CMD_TTL (cmd);@@ -1047,6 +1047,12 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)uint64_t num_pages;uint8_t granule;int asid =-1 ; +SMMUv3State *smmuv3 =ARM_SMMUV3 (s); + +/* Only consider VMID if stage-2 is supported. */ +if (STAGE2_SUPPORTED (smmuv3)) { + vmid =CMD_VMID (cmd); + }if (type ==SMMU_CMD_TLBI_NH_VA ) { asid =CMD_ASID (cmd);@@ -1055,7 +1061,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)if (!tg) {trace_smmuv3_s1_range_inval (vmid, asid, addr, tg,1 , ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg,1 ); -smmu_iotlb_inv_iova (s, asid, addr, tg,1 , ttl); +smmu_iotlb_inv_iova (s, asid, vmid, addr, tg,1 , ttl);return ; }@@ -1073,7 +1079,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd) num_pages = (mask +1 ) >> granule;trace_smmuv3_s1_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg, num_pages); -smmu_iotlb_inv_iova (s, asid, addr, tg, num_pages, ttl); +smmu_iotlb_inv_iova (s, asid, vmid, addr, tg, num_pages, ttl); addr += mask +1 ; } }hw/arm/trace-events +3
-3@@ -14,9 +14,9 @@ smmu_iotlb_inv_all(void) "IOTLB invalidate all" smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" -smmu_iotlb_lookup_hit(uint16_t asid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" -smmu_iotlb_lookup_miss(uint16_t asid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" -smmu_iotlb_insert(uint16_t asid, uint64_t addr, uint8_t tg, uint8_t level) "IOTLB ++ asid=%d addr=0x%"PRIx64" tg=%d level=%d" +smmu_iotlb_lookup_hit(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" +smmu_iotlb_lookup_miss(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" +smmu_iotlb_insert(uint16_t asid, uint16_t vmid, uint64_t addr, uint8_t tg, uint8_t level) "IOTLB ++ asid=%d vmid=%d addr=0x%"PRIx64" tg=%d level=%d" # smmuv3.c smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)"include/hw/arm/smmu-common.h +1
-0@@ -118,6 +118,7 @@ typedef struct SMMUPciBus {typedef struct SMMUIOTLBKey {uint64_t iova;uint16_t asid; +uint16_t vmid;uint8_t tg;uint8_t level; }SMMUIOTLBKey ;@@ -181,11 +182,11 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid);SMMUTLBEntry *smmu_iotlb_lookup (SMMUState *bs,SMMUTransCfg *cfg,SMMUTransTableInfo *tt,hwaddr iova);void smmu_iotlb_insert (SMMUState *bs,SMMUTransCfg *cfg,SMMUTLBEntry *entry);
include/hw/arm/smmu-common.h IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid); · line 192
Quoted 10 lines
include/hw/arm/smmu-common.h +2
-2-SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint64_t iova, +SMMUIOTLBKey smmu_get_iotlb_key (uint16_t asid,uint16_t vmid,uint64_t iova,uint8_t tg,uint8_t level);void smmu_iotlb_inv_all (SMMUState *s);void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid); -void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova, +void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl);/* Unmap the range of all the notifiers registered to any IOMMU mr */
Looks good to me:
Eric
RFC PATCH v2 8/11 hw/arm/smmuv3: Add CMDs related to stage-2
In reply to Mostafa SalehCMD_TLBI_S2_IPA: As S1+S2 is not enabled, for now this can be the same as CMD_TLBI_NH_VAA.
CMD_TLBI_S12_VMALL: Added new function to invalidate TLB by VMID.
For stage-1 only commands, add a check to to throw CERROR_ILL if used when stage-1 is not supported.
---
Changes in v2:
- Add checks for stage-1 only commands
- Rename smmuv3_s1_range_inval to smmuv3_range_inval
--- hw/arm/smmu-common.c | 16 ++++++++++++ hw/arm/smmuv3.c | 47 +++++++++++++++++++++++++++++++----- hw/arm/trace-events | 4 ++- include/hw/arm/smmu-common.h | 1 + 4 files changed, 61 insertions(+), 7 deletions(-)
hw/arm/smmu-common.c +16 -0
@@ -135,6 +135,16 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,return SMMU_IOTLB_ASID (*iotlb_key) == asid; } + +static gboolean smmu_hash_remove_by_vmid (gpointer key,gpointer value, +gpointer user_data) +{ +uint16_t vmid = *(uint16_t *)user_data; +SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key; + +return SMMU_IOTLB_VMID (*iotlb_key) == vmid; +} +static gboolean smmu_hash_remove_by_asid_vmid_iova (gpointer key,gpointer value,gpointer user_data) {
@@ -187,6 +197,12 @@ void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_asid, &asid); } +inline void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid) +{ +trace_smmu_iotlb_inv_vmid (vmid); +g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_vmid, &vmid); +} +/* VMSAv8-64 Translation */ /**
hw/arm/smmuv3.c +41 -6
89 lines not on this page · raw message
hw/arm/trace-events +3 -1
@@ -12,6 +12,7 @@ smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, ui 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_iotlb_inv_all(void) "IOTLB invalidate all" smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=%d" +smmu_iotlb_inv_vmid(uint16_t vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" smmu_iotlb_lookup_hit(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d"
@@ -45,9 +46,10 @@ smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache HIT for sid=0x%x (hits=%d, misses=%d, hit rate=%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache MISS for sid=0x%x (hits=%d, misses=%d, hit rate=%d)" -smmuv3_s1_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d" +smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d" smmuv3_cmdq_tlbi_nh(void) "" smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=%d" +smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" 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"
include/hw/arm/smmu-common.h +1 -0
@@ -186,6 +186,7 @@ SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint8_t level);void smmu_iotlb_inv_all (SMMUState *s);void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid); +void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid);void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl);
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 08/11] hw/arm/smmuv3: Add CMDs related to stage-2
Hi Mostafa,
Quoted 6 lines · Mostafa Saleh
CMD_TLBI_S2_IPA: As S1+S2 is not enabled, for now this can be the same asCMD_TLBI_NH_VAA.
CMD_TLBI_S12_VMALL: Added new function to invalidate TLB by VMID.For stage-1 only commands, add a check to to throw
CERROR_ILLif used
s/to to/to
Quoted 80 lines
when stage-1 is not supported.
Signed-off-by Mostafa Saleh <[email protected]>---
Changes in v2:
- Add checks for stage-1 only commands
- Renamesmmuv3_s1_range_invaltosmmuv3_range_inval--- hw/arm/smmu-common.c | 16 ++++++++++++ hw/arm/smmuv3.c | 47 +++++++++++++++++++++++++++++++----- hw/arm/trace-events | 4 ++- include/hw/arm/smmu-common.h | 1 + 4 files changed, 61 insertions(+), 7 deletions(-)hw/arm/smmu-common.c +16
-0@@ -135,6 +135,16 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value,return SMMU_IOTLB_ASID (*iotlb_key) == asid; } + +static gboolean smmu_hash_remove_by_vmid (gpointer key,gpointer value, +gpointer user_data) +{ +uint16_t vmid = *(uint16_t *)user_data; +SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key; + +return SMMU_IOTLB_VMID (*iotlb_key) == vmid; +} +static gboolean smmu_hash_remove_by_asid_vmid_iova (gpointer key,gpointer value,gpointer user_data) {@@ -187,6 +197,12 @@ void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_asid, &asid); } +inline void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid) +{ +trace_smmu_iotlb_inv_vmid (vmid); +g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_vmid, &vmid); +} +/* VMSAv8-64 Translation */ /** hw/arm/smmuv3.c +3
-3@@ -1034,7 +1034,7 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, dma_addr_t iova, } } -static void smmuv3_s1_range_inval (SMMUState *s,Cmd *cmd) +static void smmuv3_range_inval (SMMUState *s,Cmd *cmd) {dma_addr_t end, addr =CMD_ADDR (cmd);uint8_t type =CMD_TYPE (cmd);@@ -1059,7 +1059,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd) }if (!tg) { -trace_smmuv3_s1_range_inval (vmid, asid, addr, tg,1 , ttl, leaf); +trace_smmuv3_range_inval (vmid, asid, addr, tg,1 , ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg,1 );smmu_iotlb_inv_iova (s, asid, vmid, addr, tg,1 , ttl);return ;@@ -1077,7 +1077,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)uint64_t mask =dma_aligned_pow2_mask (addr, end,64 ); num_pages = (mask +1 ) >> granule; -trace_smmuv3_s1_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf); +trace_smmuv3_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf);smmuv3_inv_notifiers_iova (s, asid, addr, tg, num_pages);smmu_iotlb_inv_iova (s, asid, vmid, addr, tg, num_pages, ttl); addr += mask +1 ;
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s) · line 1215
Quoted 5 lines
hw/arm/smmuv3.c +2
-0@@ -1211,12 +1211,22 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) {uint16_t asid =CMD_ASID (&cmd); +if (!STAGE1_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ;
Well looking further this is not said explicitly this should return
SMMU_CERROR_ILL. Maybe you should mark it as a guest error because we do not expect a guest to send such command when S1 is not supported?
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s) · line 1227
Quoted 12 lines
hw/arm/smmuv3.c +6
-0+break ; + } +trace_smmuv3_cmdq_tlbi_nh_asid (asid);smmu_inv_notifiers_all (&s->smmu_state);smmu_iotlb_inv_asid (bs, asid);break ; }case SMMU_CMD_TLBI_NH_ALL : +if (!STAGE1_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ; +break ;
there is a VMID field. Can't this be used in S2 mode as well?
Quoted 79 lines
hw/arm/smmuv3.c +30
-3+ } +QEMU_FALLTHROUGH ;case SMMU_CMD_TLBI_NSNH_ALL :trace_smmuv3_cmdq_tlbi_nh ();smmu_inv_notifiers_all (&s->smmu_state);@@ -1224,7 +1234,34 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)break ;case SMMU_CMD_TLBI_NH_VAA :case SMMU_CMD_TLBI_NH_VA : -smmuv3_s1_range_inval (bs, &cmd); +if (!STAGE1_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +smmuv3_range_inval (bs, &cmd); +break ; +case SMMU_CMD_TLBI_S12_VMALL : +uint16_t vmid =CMD_VMID (&cmd); + +if (!STAGE2_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } + +trace_smmuv3_cmdq_tlbi_s12_vmid (vmid); +smmu_inv_notifiers_all (&s->smmu_state); +smmu_iotlb_inv_vmid (bs, vmid); +break ; +case SMMU_CMD_TLBI_S2_IPA : +if (!STAGE2_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ; +break ; + } +/* +* As currently only either s1 or s2 are supported +* we can reuse same function for s2. +*/ +smmuv3_range_inval (bs, &cmd);break ;case SMMU_CMD_TLBI_EL3_ALL :case SMMU_CMD_TLBI_EL3_VA :@@ -1232,8 +1269,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)case SMMU_CMD_TLBI_EL2_ASID :case SMMU_CMD_TLBI_EL2_VA :case SMMU_CMD_TLBI_EL2_VAA : -case SMMU_CMD_TLBI_S12_VMALL : -case SMMU_CMD_TLBI_S2_IPA :case SMMU_CMD_ATC_INV :case SMMU_CMD_PRI_RESP :case SMMU_CMD_RESUME :hw/arm/trace-events +3
-1@@ -12,6 +12,7 @@ smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, ui 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_iotlb_inv_all(void) "IOTLB invalidate all" smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=%d" +smmu_iotlb_inv_vmid(uint16_t vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" smmu_iotlb_lookup_hit(uint16_t asid, uint16_t vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d"@@ -45,9 +46,10 @@ smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache HIT for sid=0x%x (hits=%d, misses=%d, hit rate=%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache MISS for sid=0x%x (hits=%d, misses=%d, hit rate=%d)" -smmuv3_s1_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d" +smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d" smmuv3_cmdq_tlbi_nh(void) "" smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=%d" +smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" 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"include/hw/arm/smmu-common.h +0
-0
include/hw/arm/smmu-common.h SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iova, · line 192
Quoted 7 lines
include/hw/arm/smmu-common.h +1
-0@@ -186,6 +186,7 @@ SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint8_t level);void smmu_iotlb_inv_all (SMMUState *s);void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid); +void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid);void smmu_iotlb_inv_iova (SMMUState *s,int asid,int vmid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl);
Thanks
Eric
Re: [RFC PATCH v2 08/11] hw/arm/smmuv3: Add CMDs related to stage-2
Hi Eric,
Quoted 10 lines · Eric Auger
Hi Mostafa,
Quoted 6 lines · Mostafa Saleh
CMD_TLBI_S2_IPA: As S1+S2 is not enabled, for now this can be the same asCMD_TLBI_NH_VAA.
CMD_TLBI_S12_VMALL: Added new function to invalidate TLB by VMID.For stage-1 only commands, add a check to to throw
CERROR_ILLif useds/to to/to
Will do.
Quoted 10 lines
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s) · line 1215
Quoted 6 lines
hw/arm/smmuv3.c +2
-0@@ -1211,12 +1211,22 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) {uint16_t asid =CMD_ASID (&cmd); +if (!STAGE1_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ;Well looking further this is not said explicitly this should return
SMMU_CERROR_ILL. Maybe you should mark it as a guest error because we do not expect a guest to send such command when S1 is not supported?
I can add a check after the switch for SMMU_CERROR_ILL to log a guest error.
Quoted 13 lines
hw/arm/smmuv3.c static int smmuv3_cmdq_consume(SMMUv3State *s) · line 1227
Quoted 12 lines
hw/arm/smmuv3.c +6
-0+break ; + } +trace_smmuv3_cmdq_tlbi_nh_asid (asid);smmu_inv_notifiers_all (&s->smmu_state);smmu_iotlb_inv_asid (bs, asid);break ; }case SMMU_CMD_TLBI_NH_ALL : +if (!STAGE1_SUPPORTED (s)) { + cmd_error =SMMU_CERROR_ILL ; +break ;
Quoted 1 line
there is a VMID field. Can't this be used in S2 mode as well?
According to the user manual "4.4.2 TLB invalidation of stage 1" CMD_TLBI_NH_ALL causes CERROR_ILL if stage-1 is not supported.
Thanks,
Mostafa
RFC PATCH v2 9/11 hw/arm/smmuv3: Add stage-2 support in iova notifier
In reply to Mostafa SalehIn smmuv3_notify_iova, read the granule based on translation stage and use VMID if valid value is sent.
--- hw/arm/smmuv3.c | 39 ++++++++++++++++++++++++++------------- hw/arm/trace-events | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-)
hw/arm/smmuv3.c +26 -13
@@ -971,18 +971,21 @@ epilogue:* @mr: IOMMU mr region handle * @n: notifier to be called * @asid: address space ID or negative value if we don't care +* @vmid: virtual machine ID or negative value if we don't care * @iova: iova * @tg: translation granule (if communicated through range invalidation) * @num_pages: number of @granule sized pages (if tg != 0), otherwise 1 */ static void smmuv3_notify_iova (IOMMUMemoryRegion *mr,IOMMUNotifier *n, -int asid,dma_addr_t iova, -uint8_t tg,uint64_t num_pages) +int asid,int vmid, +dma_addr_t iova,uint8_t tg, +uint64_t num_pages) {SMMUDevice *sdev =container_of (mr, SMMUDevice, iommu);IOMMUTLBEvent event;uint8_t granule; +SMMUv3State *s = sdev->smmu;if (!tg) {SMMUEventInfo event = {.inval_ste_allowed = true};
@@ -997,11 +1000,20 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,return ; } - tt =select_tt (cfg, iova); -if (!tt) { +if (vmid >=0 && cfg->s2cfg.vmid != vmid) {return ; } - granule = tt->granule_sz; + +if (STAGE1_SUPPORTED (s)) { + tt =select_tt (cfg, iova); +if (!tt) { +return ; + } + granule = tt->granule_sz; + }else { + granule = cfg->s2cfg.granule_sz; + } + }else { granule = tg *2 +10 ; }
@@ -1015,9 +1027,10 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,memory_region_notify_iommu_one (n, &event); } -/* invalidate an asid/iova range tuple in all mr's */ -static void smmuv3_inv_notifiers_iova (SMMUState *s,int asid,dma_addr_t iova, -uint8_t tg,uint64_t num_pages) +/* invalidate an asid/vmid/iova range tuple in all mr's */ +static void smmuv3_inv_notifiers_iova (SMMUState *s,int asid,int vmid, +dma_addr_t iova,uint8_t tg, +uint64_t num_pages) {SMMUDevice *sdev;
@@ -1025,11 +1038,11 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, dma_addr_t iova,IOMMUMemoryRegion *mr = &sdev->iommu;IOMMUNotifier *n; -trace_smmuv3_inv_notifiers_iova (mr->parent_obj.name, asid, iova, - tg, num_pages); +trace_smmuv3_inv_notifiers_iova (mr->parent_obj.name, asid, vmid, + iova, tg, num_pages); IOMMU_NOTIFIER_FOREACH(n, mr) { -smmuv3_notify_iova (mr, n, asid, iova, tg, num_pages); +smmuv3_notify_iova (mr, n, asid, vmid, iova, tg, num_pages); } } }
@@ -1060,7 +1073,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd)if (!tg) {trace_smmuv3_range_inval (vmid, asid, addr, tg,1 , ttl, leaf); -smmuv3_inv_notifiers_iova (s, asid, addr, tg,1 ); +smmuv3_inv_notifiers_iova (s, asid, vmid, addr, tg,1 );smmu_iotlb_inv_iova (s, asid, vmid, addr, tg,1 , ttl);return ; }
@@ -1078,7 +1091,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd) num_pages = (mask +1 ) >> granule;trace_smmuv3_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf); -smmuv3_inv_notifiers_iova (s, asid, addr, tg, num_pages); +smmuv3_inv_notifiers_iova (s, asid, vmid, addr, tg, num_pages);smmu_iotlb_inv_iova (s, asid, vmid, addr, tg, num_pages, ttl); addr += mask +1 ; }
hw/arm/trace-events +1 -1
@@ -53,5 +53,5 @@ smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" 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_inv_notifiers_iova(const char *name, uint16_t asid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64 +smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 09/11] hw/arm/smmuv3: Add stage-2 support in iova notifier
Hi,
Quoted 24 lines · Mostafa Saleh
In
smmuv3_notify_iova, read the granule based on translation stage and use VMID if valid value is sent.Signed-off-by Mostafa Saleh <[email protected]>--- hw/arm/smmuv3.c | 39 ++++++++++++++++++++++++++------------- hw/arm/trace-events | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-)hw/arm/smmuv3.c +1
-0@@ -971,18 +971,21 @@ epilogue:* @mr: IOMMU mr region handle * @n: notifier to be called * @asid: address space ID or negative value if we don't care +* @vmid: virtual machine ID or negative value if we don't care * @iova: iova * @tg: translation granule (if communicated through range invalidation) * @num_pages: number of @granule sized pages (if tg != 0), otherwise 1 */ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, IOMMUNotifier *n,
hw/arm/smmuv3.c epilogue: · line 988
Quoted 10 lines
hw/arm/smmuv3.c +4
-2- int asid, dma_addr_t iova, - uint8_t tg, uint64_t num_pages) + int asid, int vmid, + dma_addr_t iova, uint8_t tg, + uint64_t num_pages) { SMMUDevice *sdev = container_of(mr, SMMUDevice, iommu);IOMMUTLBEvent event;uint8_t granule; +SMMUv3State *s = sdev->smmu;
I am not sure notifiers are likely to be registered in the S2 case because it is mostly meant to integrate with vhost or VFIO. The code in this patch would rather prepare for nested stage support I guess, I don't think it can harm.
Eric
Quoted 85 lines
hw/arm/smmuv3.c +21
-11if (!tg) {SMMUEventInfo event = {.inval_ste_allowed = true};@@ -997,11 +1000,20 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,return ; } - tt =select_tt (cfg, iova); -if (!tt) { +if (vmid >=0 && cfg->s2cfg.vmid != vmid) {return ; } - granule = tt->granule_sz; + +if (STAGE1_SUPPORTED (s)) { + tt =select_tt (cfg, iova); +if (!tt) { +return ; + } + granule = tt->granule_sz; + }else { + granule = cfg->s2cfg.granule_sz; + } + }else { granule = tg *2 +10 ; }@@ -1015,9 +1027,10 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr,memory_region_notify_iommu_one (n, &event); } -/* invalidate an asid/iova range tuple in all mr's */ -static void smmuv3_inv_notifiers_iova (SMMUState *s,int asid,dma_addr_t iova, -uint8_t tg,uint64_t num_pages) +/* invalidate an asid/vmid/iova range tuple in all mr's */ +static void smmuv3_inv_notifiers_iova (SMMUState *s,int asid,int vmid, +dma_addr_t iova,uint8_t tg, +uint64_t num_pages) {SMMUDevice *sdev;@@ -1025,11 +1038,11 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, dma_addr_t iova,IOMMUMemoryRegion *mr = &sdev->iommu;IOMMUNotifier *n; -trace_smmuv3_inv_notifiers_iova (mr->parent_obj.name, asid, iova, - tg, num_pages); +trace_smmuv3_inv_notifiers_iova (mr->parent_obj.name, asid, vmid, + iova, tg, num_pages); IOMMU_NOTIFIER_FOREACH(n, mr) { -smmuv3_notify_iova (mr, n, asid, iova, tg, num_pages); +smmuv3_notify_iova (mr, n, asid, vmid, iova, tg, num_pages); } } }@@ -1060,7 +1073,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd)if (!tg) {trace_smmuv3_range_inval (vmid, asid, addr, tg,1 , ttl, leaf); -smmuv3_inv_notifiers_iova (s, asid, addr, tg,1 ); +smmuv3_inv_notifiers_iova (s, asid, vmid, addr, tg,1 );smmu_iotlb_inv_iova (s, asid, vmid, addr, tg,1 , ttl);return ; }@@ -1078,7 +1091,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd) num_pages = (mask +1 ) >> granule;trace_smmuv3_range_inval (vmid, asid, addr, tg, num_pages, ttl, leaf); -smmuv3_inv_notifiers_iova (s, asid, addr, tg, num_pages); +smmuv3_inv_notifiers_iova (s, asid, vmid, addr, tg, num_pages);smmu_iotlb_inv_iova (s, asid, vmid, addr, tg, num_pages, ttl); addr += mask +1 ; }hw/arm/trace-events +1
-1@@ -53,5 +53,5 @@ smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" 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_inv_notifiers_iova(const char *name, uint16_t asid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64 +smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d vmid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64
RFC PATCH v2 10/11 hw/arm/smmuv3: Populate OAS based on CPU PARANGE
In reply to Mostafa SalehOAS used to be hardcoded to 44 bits, however according to SMMU manual 6.3.6 SMMU_IDR5, OAS must match the system physical address size, so we read it from CPU PARANGE.
Remove PA_MAX and pa_range as they were not used.
Add SMMUv3State as an argument to decode_cd, so it can read the SMMU OAS.
As CPU can use PARANGE with 52 bits, add 52 bits check to oas2bits, and cap OAS to 48 bits for stage-1 and stage-2 if granule is not 64KB as specified for SMMUv3.1 and later.
--- hw/arm/smmu-common.c | 13 +++++++++---- hw/arm/smmuv3-internal.h | 15 ++------------- hw/arm/smmuv3.c | 41 ++++++++++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 23 deletions(-)
hw/arm/smmu-common.c +9 -4
@@ -307,7 +307,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg,dma_addr_t baseaddr, indexmask;int stage = cfg->stage;SMMUTransTableInfo *tt =select_tt (cfg, iova); -uint8_t level, granule_sz, inputsize, stride; +uint8_t level, granule_sz, inputsize, stride, oas;if (!tt || tt->disabled) { info->type =SMMU_PTW_ERR_TRANSLATION ;
@@ -319,7 +319,12 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, inputsize =64 - tt->tsz; level =4 - (inputsize -4 ) / stride; indexmask =SMMU_IDXMSK (inputsize, stride, level); - baseaddr =extract64 (tt->ttb,0 ,48 ); + oas = cfg->oas; +if (tt->granule_sz !=16 ) { + oas =MIN (oas,48 ); + } + + baseaddr =extract64 (tt->ttb,0 , oas); baseaddr &= ~indexmask;while (level <SMMU_LEVELS ) {
@@ -416,8 +421,8 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg,* Get the ttb from concatenated structure. * The offset is the idx * size of each ttb(number of ptes * (sizeof(pte)) */ -uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 ,48 ) + (1 << stride) * - idx *sizeof (uint64_t ); +uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 , cfg->s2cfg.oas) + + (1 << stride) * idx *sizeof (uint64_t );dma_addr_t indexmask =SMMU_IDXMSK (inputsize, stride, level); baseaddr &= ~indexmask;
hw/arm/smmuv3-internal.h +2 -13
@@ -564,23 +564,12 @@ static inline int oas2bits(int oas_field)return 44 ;case 5 :return 48 ; +case 6 : +return 52 ; }return -1 ; } -static inline int pa_range (STE *ste) -{ -int oas_field =MIN (STE_S2PS (ste),SMMU_IDR5_OAS ); - -if (!STE_S2AA64 (ste)) { -return 40 ; - } - -return oas2bits (oas_field); -} - -#define MAX_PA (ste) ((1 << pa_range(ste)) - 1) -/* CD fields */ #define CD_VALID (x) extract32((x)->word[0], 31, 1)
hw/arm/smmuv3.c +35 -6
94 lines not on this page · raw message
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Hi Mostafa,
Quoted 93 lines · Mostafa Saleh
OAS used to be hardcoded to 44 bits, however according to SMMU manual 6.3.6
SMMU_IDR5, OAS must match the system physical address size, so we read it from CPU PARANGE.Remove
PA_MAXandpa_rangeas they were not used.Add SMMUv3State as an argument to
decode_cd, so it can read the SMMU OAS.As CPU can use PARANGE with 52 bits, add 52 bits check to oas2bits, and cap OAS to 48 bits for stage-1 and stage-2 if granule is not 64KB as specified for SMMUv3.1 and later.
Signed-off-by Mostafa Saleh <[email protected]>--- hw/arm/smmu-common.c | 13 +++++++++---- hw/arm/smmuv3-internal.h | 15 ++------------- hw/arm/smmuv3.c | 41 ++++++++++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 23 deletions(-)hw/arm/smmu-common.c +9
-4@@ -307,7 +307,7 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg,dma_addr_t baseaddr, indexmask;int stage = cfg->stage;SMMUTransTableInfo *tt =select_tt (cfg, iova); -uint8_t level, granule_sz, inputsize, stride; +uint8_t level, granule_sz, inputsize, stride, oas;if (!tt || tt->disabled) { info->type =SMMU_PTW_ERR_TRANSLATION ;@@ -319,7 +319,12 @@ static int smmu_ptw_64_s1(SMMUTransCfg *cfg, inputsize =64 - tt->tsz; level =4 - (inputsize -4 ) / stride; indexmask =SMMU_IDXMSK (inputsize, stride, level); - baseaddr =extract64 (tt->ttb,0 ,48 ); + oas = cfg->oas; +if (tt->granule_sz !=16 ) { + oas =MIN (oas,48 ); + } + + baseaddr =extract64 (tt->ttb,0 , oas); baseaddr &= ~indexmask;while (level <SMMU_LEVELS ) {@@ -416,8 +421,8 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg,* Get the ttb from concatenated structure. * The offset is the idx * size of each ttb(number of ptes * (sizeof(pte)) */ -uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 ,48 ) + (1 << stride) * - idx *sizeof (uint64_t ); +uint64_t baseaddr =extract64 (cfg->s2cfg.vttb,0 , cfg->s2cfg.oas) + + (1 << stride) * idx *sizeof (uint64_t );dma_addr_t indexmask =SMMU_IDXMSK (inputsize, stride, level); baseaddr &= ~indexmask;hw/arm/smmuv3-internal.h +2
-13@@ -564,23 +564,12 @@ static inline int oas2bits(int oas_field)return 44 ;case 5 :return 48 ; +case 6 : +return 52 ; }return -1 ; } -static inline int pa_range (STE *ste) -{ -int oas_field =MIN (STE_S2PS (ste),SMMU_IDR5_OAS ); - -if (!STE_S2AA64 (ste)) { -return 40 ; - } - -return oas2bits (oas_field); -} - -#define MAX_PA (ste) ((1 << pa_range(ste)) - 1) -/* CD fields */ #define CD_VALID (x) extract32((x)->word[0], 31, 1)hw/arm/smmuv3.c +0
-0
hw/arm/smmuv3.c void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) · line 246
Quoted 9 lines
hw/arm/smmuv3.c +6
-0@@ -238,6 +238,13 @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info)static void smmuv3_init_regs (SMMUv3State *s) { +/* +* According to 6.3.6 SMMU_IDR5, OAS must match the system physical address +* size. +*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );
is this working in accelerated mode?
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 10 lines
hw/arm/smmuv3.c +2
-1+/** * IDR0: stage1 only, AArch64 only, coherent access, 16b ASID, * multi-level stream table @@ -265,7 +272,7 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);
I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
Thanks
Eric
Quoted 82 lines
hw/arm/smmuv3.c +27
-5s->cmdq.base =deposit64 (s->cmdq.base,0 ,5 ,SMMU_CMDQS ); s->cmdq.prod =0 ;@@ -374,6 +381,7 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, STE *ste, SMMUEventInfo *event) {uint32_t config; +uint8_t oas =FIELD_EX32 (s->idr[5 ],IDR5 ,OAS );if (!STE_VALID (ste)) {if (!event->inval_ste_allowed) {@@ -450,7 +458,16 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, } - cfg->s2cfg.oas =oas2bits (MIN (STE_S2PS (ste),SMMU_IDR5_OAS )); + cfg->s2cfg.oas =oas2bits (MIN (STE_S2PS (ste), oas)); +/* +* For SMMUv3.1 and later, when OAS == IAS == 52, the stage 2 input +* range is further limited to 48 bits unless STE.S2TG indicates a +* 64KB granule. +*/ +if (cfg->s2cfg.granule_sz !=16 ) { + cfg->s2cfg.oas =MIN (cfg->s2cfg.oas,48 ); + } +/* * It is ILLEGAL for the address in S2TTB to be outside the range * described by the effective S2PS value. @@ -607,10 +624,12 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste,return 0 ; } -static int decode_cd (SMMUTransCfg *cfg,CD *cd,SMMUEventInfo *event) +static int decode_cd (SMMUv3State *s,SMMUTransCfg *cfg,CD *cd, +SMMUEventInfo *event) {int ret = -EINVAL ;int i; +uint8_t oas =FIELD_EX32 (s->idr[5 ],IDR5 ,OAS );if (!CD_VALID (cd) || !CD_AARCH64 (cd)) { goto bad_cd;@@ -630,7 +649,8 @@ static int decode_cd(SMMUTransCfg *cfg, CD *cd, SMMUEventInfo *event) cfg->stage =1 ; cfg->oas =oas2bits (CD_IPS (cd)); - cfg->oas =MIN (oas2bits (SMMU_IDR5_OAS ), cfg->oas); + cfg->oas =MIN (oas2bits (oas), cfg->oas); + cfg->tbi =CD_TBI (cd); cfg->asid =CD_ASID (cd);@@ -658,9 +678,18 @@ static int decode_cd(SMMUTransCfg *cfg, CD *cd, SMMUEventInfo *event) goto bad_cd; } +/* +* An address greater than 48 bits in size can only be output from a +* TTD when, in SMMUv3.1 and later, the effective IPS is 52 and a 64KB +* granule is in use for that translation table +*/ +if (tt->granule_sz !=16 ) { + oas =MIN (cfg->oas,48 ); + } + tt->tsz = tsz; tt->ttb =CD_TTB (cd, i); -if (tt->ttb & ~(MAKE_64BIT_MASK (0 , cfg->oas))) { +if (tt->ttb & ~(MAKE_64BIT_MASK (0 , oas))) { goto bad_cd; } tt->had =CD_HAD (cd, i);@@ -719,7 +748,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, SMMUTransCfg *cfg,return ret; } -return decode_cd (cfg, &cd, event); +return decode_cd (s, cfg, &cd, event); }/**
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Hi Eric,
Quoted 6 lines
hw/arm/smmuv3.c void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) · line 246
Quoted 5 lines
hw/arm/smmuv3.c +5
-0+* According to 6.3.6 SMMU_IDR5, OAS must match the system physical address +* size. +*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );is this working in accelerated mode?
I didn't try with accel, I will give it a try, but from what I see, that ARM_CPU() is used to get the CPU in traget/arm/kvm.c which is used from accel/kvm-all.c, so it seems this would work for accelerated mode.
Quoted 4 lines
Quoted 4 lines
+
/**
* IDR0: stage1 only, AArch64 only, coherent access, 16b ASID,
* multi-level stream table
Quoted 8 lines
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 6 lines
hw/arm/smmuv3.c +1
-1@@ -265,7 +272,7 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Hi Mostafa,
Quoted 11 lines · Mostafa Saleh
Hi Eric,
Quoted 6 lines
hw/arm/smmuv3.c void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) · line 246
Quoted 5 lines
hw/arm/smmuv3.c +5
-0+* According to 6.3.6 SMMU_IDR5, OAS must match the system physical address +* size. +*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );is this working in accelerated mode?
I didn't try with accel, I will give it a try, but from what I see, that
ARM_CPU()is used to get the CPU intraget/arm/kvm.cwhich is used fromaccel/kvm-all.c, so it seems this would work for accelerated mode.
yeah I ma not familiar enough with that code but it is worth to be checked.
Quoted 13 lines
Quoted 13 lines
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 11 lines
hw/arm/smmuv3.c +2
-1+/** * IDR0: stage1 only, AArch64 only, coherent access, 16b ASID, * multi-level stream table @@ -265,7 +272,7 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
Quoted 4 lines
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.
Indeed tehy are not migrated so it can lead to inconsistent behavior in both source and dest. This deserves more analysis to me. In case you would decide to migrate IDR regs this would need to be done in that series I think. Migration must not be broken by this series.
Thanks
Eric
Quoted 4 lines
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Quoted 5 lines · Eric Auger
Quoted 5 lines
Quoted 5 lines
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 3 lines
s->idr[5] = FIELD_DP32(s->idr[5], IDR5, GRAN64K, 1);hw/arm/smmuv3.c +1
-1- s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
Quoted 8 lines
Quoted 4 lines
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.Indeed tehy are not migrated so it can lead to inconsistent behavior in both source and dest. This deserves more analysis to me. In case you would decide to migrate IDR regs this would need to be done in that series I think. Migration must not be broken by this series
I agree, I meant to drop this patch from the series as it is not really related to stage-2, and we can have another patch for this + migration for IDR if needed after doing proper analysis.
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Quoted 10 lines · Mostafa Saleh
Quoted 9 lines · Eric Auger
Quoted 9 lines
Quoted 5 lines
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 3 lines
s->idr[5] = FIELD_DP32(s->idr[5], IDR5, GRAN64K, 1);hw/arm/smmuv3.c +1
-1- s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.
Quoted 7 lines
Quoted 4 lines
Indeed tehy are not migrated so it can lead to inconsistent behavior in both source and dest. This deserves more analysis to me. In case you would decide to migrate IDR regs this would need to be done in that series I think. Migration must not be broken by this series
I agree, I meant to drop this patch from the series as it is not really related to stage-2, and we can have another patch for this + migration for IDR if needed after doing proper analysis.
Ah OK. I get it now. Yes this looks sensible
Thanks
Eric
Quoted 4 lines
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
In reply to Eric AugerQuoted 11 lines · Eric Auger
Hi Mostafa,
Quoted 7 lines · Mostafa Saleh
Hi Eric,
Quoted 5 lines
Quoted 5 lines
hw/arm/smmuv3.c +5
-0+* According to 6.3.6 SMMU_IDR5, OAS must match the system physical address +* size. +*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
is this working in accelerated mode?
I didn't try with accel, I will give it a try, but from what I see, that
ARM_CPU()is used to get the CPU intraget/arm/kvm.cwhich is used fromaccel/kvm-all.c, so it seems this would work for accelerated mode.yeah I ma not familiar enough with that code but it is worth to be checked.
I'm a bit unsure about fishing around in the CPU ID registers for this. That's not what you would do in real hardware, you'd just say "the system is supposed to configure the CPU and the SMMU correctly".
Also, there is no guarantee that CPU 0 is related to this SMMU in particular.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
hw/arm/smmuv3.c static void smmuv3_init_regs(SMMUv3State *s) · line 275
Quoted 11 lines
hw/arm/smmuv3.c +2
-1+/** * IDR0: stage1 only, AArch64 only, coherent access, 16b ASID, * multi-level stream table @@ -265,7 +272,7 @@ static void smmuv3_init_regs(SMMUv3State *s) s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN4K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN16K ,1 ); s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,GRAN64K ,1 ); - s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS ,SMMU_IDR5_OAS );/* 44 bits */ + s->idr[5 ] =FIELD_DP32 (s->idr[5 ],IDR5 ,OAS , oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
Quoted 8 lines
Quoted 4 lines
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.Indeed tehy are not migrated so it can lead to inconsistent behavior in both source and dest. This deserves more analysis to me. In case you would decide to migrate IDR regs this would need to be done in that series I think. Migration must not be broken by this series.
Jumping in here without having read much of the context, but why would we need to migrate the ID registers? They are constant, read-only, so they will be the same value on both source and destination.
thanks
-- PMM
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Hi Peter,
Quoted 7 lines · Peter Maydell
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ s->idr[5] =
FIELD_DP32(s->idr[5], IDR5, OAS, oas);I am not sure you can change that easily. In case of migration this is going to change the behavior of the device, no?
I see IDR registers are not migrated. I guess we can add them in a subsection and if they were not passed (old instances) we set OAS to 44.
Maybe this should be another change outside of this series.
Quoted 8 lines
Quoted 4 lines
Indeed tehy are not migrated so it can lead to inconsistent behavior in both source and dest. This deserves more analysis to me. In case you would decide to migrate IDR regs this would need to be done in that series I think. Migration must not be broken by this series.
Jumping in here without having read much of the context, but why would we need to migrate the ID registers? They are constant, read-only, so they will be the same value on both source and destination.
Currently OAS for SMMU is hardcoded to 44 bits, and the SMMU manual says "OAS reflects the maximum usable PA output from the last stage of AArch64 translations, and must match the system physical address size. The OAS is discoverable from SMMU_IDR5.OAS."
This patch implements OAS based on CPU PARANGE, but this would break migration from old instances that ran with 44 bits OAS to new code that configures it based on the current CPU.
So one idea is to migrate the IDRs (or atleast IDR5).
Maybe that is not the best solution, we just need a way to know if the old instance needs to be 44 bits or not.
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
In reply to Peter MaydellHi Peter,
Quoted 3 lines · Peter Maydell
thout having read much of the context, but why
would we need to migrate the ID registers? They are constant, read-only, so they will be the same value on both source and destination.
this series modifies the values of IDR[5] (oas). So my understanding is the guest is likely to behave differently on src and dst, depending on the qemu version, no?
Thanks
Eric
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
In reply to Peter MaydellHi Peter,
Quoted 8 lines · Peter Maydell
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
hw/arm/smmuv3.c void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) · line 246
Quoted 3 lines
hw/arm/smmuv3.c +3
-0+*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );is this working in accelerated mode?
I didn't try with accel, I will give it a try, but from what I see, that
ARM_CPU()is used to get the CPU intraget/arm/kvm.cwhich is used fromaccel/kvm-all.c, so it seems this would work for accelerated mode.
Quoted 8 lines
Quoted 1 line
yeah I ma not familiar enough with that code but it is worth to be checked.
I'm a bit unsure about fishing around in the CPU ID registers for this. That's not what you would do in real hardware, you'd just say "the system is supposed to configure the CPU and the SMMU correctly".
Also, there is no guarantee that CPU 0 is related to this SMMU in particular.
Sorry, missed this point in last email.
So, we leave it this way, or there is a better way to discover PARANGE?
Thanks,
Mostafa
Re: [RFC PATCH v2 10/11] hw/arm/smmuv3: Populate OAS based on CPU PARANGE
Quoted 18 lines · Mostafa Saleh
Hi Peter,
Quoted 14 lines · Peter Maydell
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
hw/arm/smmuv3.c void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) · line 246
Quoted 3 lines
hw/arm/smmuv3.c +3
-0+*/ +ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 )); +uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE );is this working in accelerated mode?
I didn't try with accel, I will give it a try, but from what I see, that
ARM_CPU()is used to get the CPU intraget/arm/kvm.cwhich is used fromaccel/kvm-all.c, so it seems this would work for accelerated mode.yeah I ma not familiar enough with that code but it is worth to be checked.
I'm a bit unsure about fishing around in the CPU ID registers for this. That's not what you would do in real hardware, you'd just say "the system is supposed to configure the CPU and the SMMU correctly".
Quoted 5 lines
Quoted 2 lines
Also, there is no guarantee that CPU 0 is related to this SMMU in particular.
Sorry, missed this point in last email.
So, we leave it this way, or there is a better way to discover PARANGE?
If you really need to know it, put a QOM property on the SMMU device and have the board code set it. (This is analogous to how it works in hardware: there are tie-off signals on the SMMU for the OAS value.)
-- PMM
RFC PATCH v2 11/11 hw/arm/smmuv3: Add knob to choose translation stage and enable stage-2
In reply to Mostafa SalehAs everything is in place, we can use a new system property to advertise which stage is supported and remove bad_ste from STE stage2 config.
The property added arm-smmuv3.stage can have 3 values:
- "1": Stage-1 only is advertised.
- "2": Stage-2 only is advertised.
- "all": Stage-1 + Stage-2 are supported, which is not implemented in this patch series.
If not passed or an unsupported value is passed, it will default to stage-1.
Advertise VMID16.
Don't try to decode CD, if stage-2 is configured.
---
Changes in v2:
- Squash knob patch with stage-2 enable patch.
- Don't try to decode CD, if stage-2 is configured.
--- hw/arm/smmuv3.c | 34 +++++++++++++++++++++++++--------- include/hw/arm/smmuv3.h | 1 + 2 files changed, 26 insertions(+), 9 deletions(-)
hw/arm/smmuv3.c +25 -9
@@ -21,6 +21,7 @@#include "hw/irq.h" #include "hw/sysbus.h" #include "migration/vmstate.h" +#include "hw/qdev-properties.h" #include "hw/qdev-core.h" #include "hw/pci/pci.h" #include "cpu.h"
@@ -245,14 +246,20 @@ static void smmuv3_init_regs(SMMUv3State *s)ARMCPU *armcpu =ARM_CPU (qemu_get_cpu (0 ));uint8_t oas =FIELD_EX64 (armcpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE ); -/** -* IDR0: stage1 only, AArch64 only, coherent access, 16b ASID, -* multi-level stream table +/* +* Based on sys property, the stages supported in smmu will be advertised. +* At the moment "all" is not supported and default to stage-1. */ - s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,S1P ,1 );/* stage 1 supported */ +if (s->stage && !strcmp ("2" , s->stage)) { + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,S2P ,1 ); + }else { + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,S1P ,1 ); + } + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,TTF ,2 );/* AArch64 PTW only */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,COHACC ,1 );/* IO coherent */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,ASID16 ,1 );/* 16-bit ASID */ + s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,VMID16 ,1 );/* 16-bit VMID */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,TTENDIAN ,2 );/* little endian */ s->idr[0 ] =FIELD_DP32 (s->idr[0 ],IDR0 ,STALL_MODEL ,1 );/* No stall */ /* terminated transaction will always be aborted/error returned */
@@ -508,10 +515,6 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg,qemu_log_mask (LOG_UNIMP ,"SMMUv3 Stall not implemented!\n" ); goto bad_ste; } - -/* This is still here as stage 2 has not been fully enabled yet. */ -qemu_log_mask (LOG_UNIMP ,"SMMUv3 does not support stage 2 yet\n" ); - goto bad_ste; }if (STE_S1CDMAX (ste) !=0 ) {
@@ -739,7 +742,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, SMMUTransCfg *cfg,return ret; } -if (cfg->aborted || cfg->bypassed) { +if (cfg->aborted || cfg->bypassed || (cfg->stage ==2 )) {return 0 ; }
@@ -1801,6 +1804,18 @@ static const VMStateDescription vmstate_smmuv3 = { } }; +static Property smmuv3_properties[] = { +/* +* Stages of translation advertised. +* "1": Stage 1 +* "2": Stage 2 +* "all": Stage 1 + Stage 2 +* Defaults to stage 1 +*/ +DEFINE_PROP_STRING ("stage" , SMMUv3State, stage), +DEFINE_PROP_END_OF_LIST () +}; +static void smmuv3_instance_init (Object *obj) {/* Nothing much to do here as of now */
@@ -1817,6 +1832,7 @@ static void smmuv3_class_init(ObjectClass *klass, void *data) &c->parent_phases); c->parent_realize = dc->realize; dc->realize = smmu_realize; +device_class_set_props (dc, smmuv3_properties); } static int smmuv3_notify_flag_changed(IOMMUMemoryRegion *iommu,
include/hw/arm/smmuv3.h +1 -0
@@ -62,6 +62,7 @@ struct SMMUv3State {qemu_irq irq[4 ];QemuMutex mutex; +char *stage; }; typedef enum {
Signature · 1 line
2.39.2.637.g21b0678d19-goog