[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/21] hw/arm/smmuv3: Make TLB lookup work for stage-2
|
From: |
Peter Maydell |
|
Subject: |
[PULL 07/21] hw/arm/smmuv3: Make TLB lookup work for stage-2 |
|
Date: |
Tue, 30 May 2023 14:26:06 +0100 |
From: Mostafa Saleh <smostafa@google.com>
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 <smostafa@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Message-id: 20230516203327.2051088-7-smostafa@google.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/arm/smmuv3.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 27840f2d666..a6714e04207 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -720,6 +720,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;
@@ -817,6 +820,11 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion
*mr, hwaddr addr,
.addr_mask = ~(hwaddr)0,
.perm = IOMMU_NONE,
};
+ /*
+ * Combined attributes used for TLB lookup, as only one stage is supported,
+ * it will hold attributes based on the enabled stage.
+ */
+ SMMUTransTableInfo tt_combined;
qemu_mutex_lock(&s->mutex);
@@ -845,21 +853,35 @@ 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;
- }
+ tt_combined.granule_sz = tt->granule_sz;
+ tt_combined.tsz = tt->tsz;
- page_mask = (1ULL << (tt->granule_sz)) - 1;
+ } else {
+ /* Stage2. */
+ tt_combined.granule_sz = cfg->s2cfg.granule_sz;
+ tt_combined.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 << tt_combined.granule_sz) - 1;
aligned_addr = addr & ~page_mask;
- cached_entry = smmu_iotlb_lookup(bs, cfg, tt, aligned_addr);
+ cached_entry = smmu_iotlb_lookup(bs, cfg, &tt_combined, aligned_addr);
if (cached_entry) {
if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & IOMMU_WO)) {
status = SMMU_TRANS_ERROR;
--
2.34.1
- [PULL 12/21] hw/dma/xilinx_axidma: Check DMASR.HALTED to prevent infinite loop., (continued)
- [PULL 12/21] hw/dma/xilinx_axidma: Check DMASR.HALTED to prevent infinite loop., Peter Maydell, 2023/05/30
- [PULL 01/21] fsl-imx6: Add SNVS support for i.MX6 boards, Peter Maydell, 2023/05/30
- [PULL 09/21] hw/arm/smmuv3: Add CMDs related to stage-2, Peter Maydell, 2023/05/30
- [PULL 19/21] Update copyright dates to 2023, Peter Maydell, 2023/05/30
- [PULL 06/21] hw/arm/smmuv3: Parse STE config for stage-2, Peter Maydell, 2023/05/30
- [PULL 05/21] hw/arm/smmuv3: Add page table walk for stage-2, Peter Maydell, 2023/05/30
- [PULL 14/21] tests/qtest: Run arm-specific tests only if the required machine is available, Peter Maydell, 2023/05/30
- [PULL 20/21] hw/arm/sbsa-ref: add GIC node into DT, Peter Maydell, 2023/05/30
- [PULL 21/21] docs: sbsa: correct graphics card name, Peter Maydell, 2023/05/30
- [PULL 16/21] target/arm: Explain why we need to select ARM_V7M, Peter Maydell, 2023/05/30
- [PULL 07/21] hw/arm/smmuv3: Make TLB lookup work for stage-2,
Peter Maydell <=
- Re: [PULL 00/21] target-arm queue, Richard Henderson, 2023/05/30