* [PATCH v4 0/2] Fix handling of S2 stalls
@ 2024-08-30 11:03 Mostafa Saleh
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Mostafa Saleh @ 2024-08-30 11:03 UTC (permalink / raw)
To: linux-kernel, iommu, linux-arm-kernel, will, robin.murphy, joro
Cc: jean-philippe, jgg, nicolinc, mshavit, Mostafa Saleh
While debugging something else, I spent hours looking at hexdumps of
STEs, CDs and commands while comparing them against the arch specs,
where I noticed a minor violation in the driver regarding handling of
S2S bit in the STE.
This has been there for ages, so it’s highly unlikely that any HW (if
it exists with such features) running Linux is affected.
I don’t have access to HW with stalls so I just tested normal usage
and (terminated) translation fault events.
Also, add some unit tests for stall enabled masters.
Mostafa Saleh (2):
iommu/arm-smmu-v3: Match Stall behaviour for S2
iommu/arm-smmu-v3-test: Test masters with stall enabled
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 83 ++++++++++++++-----
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 +
3 files changed, 66 insertions(+), 26 deletions(-)
v4:
- Add S2S bit to get_used for stage-2
- Add unit tests for masters with stall enabled
v3:
- Set S2S for s2 and not s1 domain
- Ignore ats check
v2:
- Fix index of the STE
- Fix conflict with ATS
- Squash the 2 patches and drop enable_nesting
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
2024-08-30 11:03 [PATCH v4 0/2] Fix handling of S2 stalls Mostafa Saleh
@ 2024-08-30 11:03 ` Mostafa Saleh
2024-08-30 16:30 ` Nicolin Chen
2024-08-30 20:20 ` Jason Gunthorpe
2024-08-30 11:03 ` [PATCH v4 2/2] iommu/arm-smmu-v3-test: Test masters with stall enabled Mostafa Saleh
2024-08-30 16:12 ` [PATCH v4 0/2] Fix handling of S2 stalls Will Deacon
2 siblings, 2 replies; 8+ messages in thread
From: Mostafa Saleh @ 2024-08-30 11:03 UTC (permalink / raw)
To: linux-kernel, iommu, linux-arm-kernel, will, robin.murphy, joro
Cc: jean-philippe, jgg, nicolinc, mshavit, Mostafa Saleh
According to the spec (ARM IHI 0070 F.b), in
"5.5 Fault configuration (A, R, S bits)":
A STE with stage 2 translation enabled and STE.S2S == 0 is
considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10.
Also described in the pseudocode “SteIllegal()”
if STE.Config == '11x' then
[..]
if eff_idr0_stall_model == '10' && STE.S2S == '0' then
// stall_model forcing stall, but S2S == 0
return TRUE;
Which means, S2S must be set when stall model is
"ARM_SMMU_FEAT_STALL_FORCE", but currently the driver ignores that.
Although, the driver can do the minimum and only set S2S for
“ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1
behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the
master has requested stalls.
Also, since S2 stalls are enabled now, report them to the IOMMU layer
and for VFIO devices it will fail anyway as VFIO doesn’t register an
iopf handler.
Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +++-----
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 +
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index a31460f9f3d4..a0044ff2facf 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1012,7 +1012,8 @@ void arm_smmu_get_ste_used(const __le64 *ent, __le64 *used_bits)
used_bits[2] |=
cpu_to_le64(STRTAB_STE_2_S2VMID | STRTAB_STE_2_VTCR |
STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2ENDI |
- STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2R);
+ STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2S |
+ STRTAB_STE_2_S2R);
used_bits[3] |= cpu_to_le64(STRTAB_STE_3_S2TTB_MASK);
}
@@ -1646,6 +1647,7 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target,
STRTAB_STE_2_S2ENDI |
#endif
STRTAB_STE_2_S2PTW |
+ (master->stall_enabled ? STRTAB_STE_2_S2S : 0) |
STRTAB_STE_2_S2R);
target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s2_cfg.vttbr &
@@ -1739,10 +1741,6 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt)
return -EOPNOTSUPP;
}
- /* Stage-2 is always pinned at the moment */
- if (evt[1] & EVTQ_1_S2)
- return -EFAULT;
-
if (!(evt[1] & EVTQ_1_STALL))
return -EOPNOTSUPP;
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 14bca41a981b..0dc7ad43c64c 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -267,6 +267,7 @@ struct arm_smmu_ste {
#define STRTAB_STE_2_S2AA64 (1UL << 51)
#define STRTAB_STE_2_S2ENDI (1UL << 52)
#define STRTAB_STE_2_S2PTW (1UL << 54)
+#define STRTAB_STE_2_S2S (1UL << 57)
#define STRTAB_STE_2_S2R (1UL << 58)
#define STRTAB_STE_3_S2TTB_MASK GENMASK_ULL(51, 4)
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 2/2] iommu/arm-smmu-v3-test: Test masters with stall enabled
2024-08-30 11:03 [PATCH v4 0/2] Fix handling of S2 stalls Mostafa Saleh
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
@ 2024-08-30 11:03 ` Mostafa Saleh
2024-08-30 16:12 ` [PATCH v4 0/2] Fix handling of S2 stalls Will Deacon
2 siblings, 0 replies; 8+ messages in thread
From: Mostafa Saleh @ 2024-08-30 11:03 UTC (permalink / raw)
To: linux-kernel, iommu, linux-arm-kernel, will, robin.murphy, joro
Cc: jean-philippe, jgg, nicolinc, mshavit, Mostafa Saleh
At the moment, the SMMUv3 unit tests assume ATS is always enabled,
although this is sufficient to test hitless/non-hitless transitions,
but exercising other features is useful to check ste/cd population
logic (for example the .get_used logic).
Add an enum where bits define features per-master, at the moment there
is only ATS and STALLs which are mutually exclusive, but this would
make it easier to extend with other features in the future.
Also, Add 2 more tests for s1 <-> s2 transitions with stalls enabled.
Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 83 ++++++++++++++-----
1 file changed, 62 insertions(+), 21 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c
index cceb737a7001..84baa021370a 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c
@@ -30,6 +30,11 @@ static struct mm_struct sva_mm = {
.pgd = (void *)0xdaedbeefdeadbeefULL,
};
+enum arm_smmu_test_master_feat {
+ ARM_SMMU_MASTER_TEST_ATS = BIT(0),
+ ARM_SMMU_MASTER_TEST_STALL = BIT(1),
+};
+
static bool arm_smmu_entry_differs_in_used_bits(const __le64 *entry,
const __le64 *used_bits,
const __le64 *target,
@@ -164,16 +169,22 @@ static const dma_addr_t fake_cdtab_dma_addr = 0xF0F0F0F0F0F0;
static void arm_smmu_test_make_cdtable_ste(struct arm_smmu_ste *ste,
unsigned int s1dss,
- const dma_addr_t dma_addr)
+ const dma_addr_t dma_addr,
+ enum arm_smmu_test_master_feat feat)
{
+ bool ats_enabled = feat & ARM_SMMU_MASTER_TEST_ATS;
+ bool stall_enabled = feat & ARM_SMMU_MASTER_TEST_STALL;
+
struct arm_smmu_master master = {
+ .ats_enabled = ats_enabled,
.cd_table.cdtab_dma = dma_addr,
.cd_table.s1cdmax = 0xFF,
.cd_table.s1fmt = STRTAB_STE_0_S1FMT_64K_L2,
.smmu = &smmu,
+ .stall_enabled = stall_enabled,
};
- arm_smmu_make_cdtable_ste(ste, &master, true, s1dss);
+ arm_smmu_make_cdtable_ste(ste, &master, ats_enabled, s1dss);
}
static void arm_smmu_v3_write_ste_test_bypass_to_abort(struct kunit *test)
@@ -204,7 +215,7 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_abort(struct kunit *test)
struct arm_smmu_ste ste;
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &abort_ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -214,7 +225,7 @@ static void arm_smmu_v3_write_ste_test_abort_to_cdtable(struct kunit *test)
struct arm_smmu_ste ste;
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &abort_ste, &ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -224,7 +235,7 @@ static void arm_smmu_v3_write_ste_test_cdtable_to_bypass(struct kunit *test)
struct arm_smmu_ste ste;
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &bypass_ste,
NUM_EXPECTED_SYNCS(3));
}
@@ -234,7 +245,7 @@ static void arm_smmu_v3_write_ste_test_bypass_to_cdtable(struct kunit *test)
struct arm_smmu_ste ste;
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &bypass_ste, &ste,
NUM_EXPECTED_SYNCS(3));
}
@@ -245,9 +256,9 @@ static void arm_smmu_v3_write_ste_test_cdtable_s1dss_change(struct kunit *test)
struct arm_smmu_ste s1dss_bypass;
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
/*
* Flipping s1dss on a CD table STE only involves changes to the second
@@ -265,7 +276,7 @@ arm_smmu_v3_write_ste_test_s1dssbypass_to_stebypass(struct kunit *test)
struct arm_smmu_ste s1dss_bypass;
arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(
test, &s1dss_bypass, &bypass_ste, NUM_EXPECTED_SYNCS(2));
}
@@ -276,16 +287,20 @@ arm_smmu_v3_write_ste_test_stebypass_to_s1dssbypass(struct kunit *test)
struct arm_smmu_ste s1dss_bypass;
arm_smmu_test_make_cdtable_ste(&s1dss_bypass, STRTAB_STE_1_S1DSS_BYPASS,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(
test, &bypass_ste, &s1dss_bypass, NUM_EXPECTED_SYNCS(2));
}
static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste,
- bool ats_enabled)
+ enum arm_smmu_test_master_feat feat)
{
+ bool ats_enabled = feat & ARM_SMMU_MASTER_TEST_ATS;
+ bool stall_enabled = feat & ARM_SMMU_MASTER_TEST_STALL;
struct arm_smmu_master master = {
+ .ats_enabled = ats_enabled,
.smmu = &smmu,
+ .stall_enabled = stall_enabled,
};
struct io_pgtable io_pgtable = {};
struct arm_smmu_domain smmu_domain = {
@@ -308,7 +323,7 @@ static void arm_smmu_v3_write_ste_test_s2_to_abort(struct kunit *test)
{
struct arm_smmu_ste ste;
- arm_smmu_test_make_s2_ste(&ste, true);
+ arm_smmu_test_make_s2_ste(&ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &abort_ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -317,7 +332,7 @@ static void arm_smmu_v3_write_ste_test_abort_to_s2(struct kunit *test)
{
struct arm_smmu_ste ste;
- arm_smmu_test_make_s2_ste(&ste, true);
+ arm_smmu_test_make_s2_ste(&ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &abort_ste, &ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -326,7 +341,7 @@ static void arm_smmu_v3_write_ste_test_s2_to_bypass(struct kunit *test)
{
struct arm_smmu_ste ste;
- arm_smmu_test_make_s2_ste(&ste, true);
+ arm_smmu_test_make_s2_ste(&ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &ste, &bypass_ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -335,7 +350,7 @@ static void arm_smmu_v3_write_ste_test_bypass_to_s2(struct kunit *test)
{
struct arm_smmu_ste ste;
- arm_smmu_test_make_s2_ste(&ste, true);
+ arm_smmu_test_make_s2_ste(&ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &bypass_ste, &ste,
NUM_EXPECTED_SYNCS(2));
}
@@ -346,8 +361,8 @@ static void arm_smmu_v3_write_ste_test_s1_to_s2(struct kunit *test)
struct arm_smmu_ste s2_ste;
arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
- arm_smmu_test_make_s2_ste(&s2_ste, true);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
+ arm_smmu_test_make_s2_ste(&s2_ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &s1_ste, &s2_ste,
NUM_EXPECTED_SYNCS(3));
}
@@ -358,8 +373,8 @@ static void arm_smmu_v3_write_ste_test_s2_to_s1(struct kunit *test)
struct arm_smmu_ste s2_ste;
arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
- arm_smmu_test_make_s2_ste(&s2_ste, true);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
+ arm_smmu_test_make_s2_ste(&s2_ste, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_hitless_transition(test, &s2_ste, &s1_ste,
NUM_EXPECTED_SYNCS(3));
}
@@ -375,9 +390,9 @@ static void arm_smmu_v3_write_ste_test_non_hitless(struct kunit *test)
* s1 dss field in the same update.
*/
arm_smmu_test_make_cdtable_ste(&ste, STRTAB_STE_1_S1DSS_SSID0,
- fake_cdtab_dma_addr);
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_test_make_cdtable_ste(&ste_2, STRTAB_STE_1_S1DSS_BYPASS,
- 0x4B4B4b4B4B);
+ 0x4B4B4b4B4B, ARM_SMMU_MASTER_TEST_ATS);
arm_smmu_v3_test_ste_expect_non_hitless_transition(
test, &ste, &ste_2, NUM_EXPECTED_SYNCS(3));
}
@@ -503,6 +518,30 @@ static void arm_smmu_test_make_sva_release_cd(struct arm_smmu_cd *cd,
arm_smmu_make_sva_cd(cd, &master, NULL, asid);
}
+static void arm_smmu_v3_write_ste_test_s1_to_s2_stall(struct kunit *test)
+{
+ struct arm_smmu_ste s1_ste;
+ struct arm_smmu_ste s2_ste;
+
+ arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0,
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_STALL);
+ arm_smmu_test_make_s2_ste(&s2_ste, ARM_SMMU_MASTER_TEST_STALL);
+ arm_smmu_v3_test_ste_expect_hitless_transition(test, &s1_ste, &s2_ste,
+ NUM_EXPECTED_SYNCS(3));
+}
+
+static void arm_smmu_v3_write_ste_test_s2_to_s1_stall(struct kunit *test)
+{
+ struct arm_smmu_ste s1_ste;
+ struct arm_smmu_ste s2_ste;
+
+ arm_smmu_test_make_cdtable_ste(&s1_ste, STRTAB_STE_1_S1DSS_SSID0,
+ fake_cdtab_dma_addr, ARM_SMMU_MASTER_TEST_STALL);
+ arm_smmu_test_make_s2_ste(&s2_ste, ARM_SMMU_MASTER_TEST_STALL);
+ arm_smmu_v3_test_ste_expect_hitless_transition(test, &s2_ste, &s1_ste,
+ NUM_EXPECTED_SYNCS(3));
+}
+
static void arm_smmu_v3_write_cd_test_sva_clear(struct kunit *test)
{
struct arm_smmu_cd cd = {};
@@ -547,6 +586,8 @@ static struct kunit_case arm_smmu_v3_test_cases[] = {
KUNIT_CASE(arm_smmu_v3_write_ste_test_non_hitless),
KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_clear),
KUNIT_CASE(arm_smmu_v3_write_cd_test_s1_change_asid),
+ KUNIT_CASE(arm_smmu_v3_write_ste_test_s1_to_s2_stall),
+ KUNIT_CASE(arm_smmu_v3_write_ste_test_s2_to_s1_stall),
KUNIT_CASE(arm_smmu_v3_write_cd_test_sva_clear),
KUNIT_CASE(arm_smmu_v3_write_cd_test_sva_release),
{},
--
2.46.0.469.g59c65b2a67-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/2] Fix handling of S2 stalls
2024-08-30 11:03 [PATCH v4 0/2] Fix handling of S2 stalls Mostafa Saleh
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
2024-08-30 11:03 ` [PATCH v4 2/2] iommu/arm-smmu-v3-test: Test masters with stall enabled Mostafa Saleh
@ 2024-08-30 16:12 ` Will Deacon
2 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2024-08-30 16:12 UTC (permalink / raw)
To: linux-kernel, iommu, linux-arm-kernel, robin.murphy, joro,
Mostafa Saleh
Cc: catalin.marinas, kernel-team, Will Deacon, jean-philippe, jgg,
nicolinc, mshavit
On Fri, 30 Aug 2024 11:03:46 +0000, Mostafa Saleh wrote:
> While debugging something else, I spent hours looking at hexdumps of
> STEs, CDs and commands while comparing them against the arch specs,
> where I noticed a minor violation in the driver regarding handling of
> S2S bit in the STE.
>
> This has been there for ages, so it’s highly unlikely that any HW (if
> it exists with such features) running Linux is affected.
>
> [...]
Applied to will (for-joerg/arm-smmu/updates), thanks!
[1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
https://git.kernel.org/will/c/ce7cb08e22e0
[2/2] iommu/arm-smmu-v3-test: Test masters with stall enabled
https://git.kernel.org/will/c/070e326f327a
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
@ 2024-08-30 16:30 ` Nicolin Chen
2024-08-30 17:02 ` Robin Murphy
2024-08-30 20:20 ` Jason Gunthorpe
1 sibling, 1 reply; 8+ messages in thread
From: Nicolin Chen @ 2024-08-30 16:30 UTC (permalink / raw)
To: Mostafa Saleh
Cc: linux-kernel, iommu, linux-arm-kernel, will, robin.murphy, joro,
jean-philippe, jgg, mshavit
On Fri, Aug 30, 2024 at 11:03:47AM +0000, Mostafa Saleh wrote:
> According to the spec (ARM IHI 0070 F.b), in
> "5.5 Fault configuration (A, R, S bits)":
> A STE with stage 2 translation enabled and STE.S2S == 0 is
> considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10.
>
> Also described in the pseudocode “SteIllegal()”
> if STE.Config == '11x' then
> [..]
> if eff_idr0_stall_model == '10' && STE.S2S == '0' then
> // stall_model forcing stall, but S2S == 0
> return TRUE;
>
> Which means, S2S must be set when stall model is
> "ARM_SMMU_FEAT_STALL_FORCE", but currently the driver ignores that.
>
> Although, the driver can do the minimum and only set S2S for
> “ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1
> behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the
> master has requested stalls.
If I read the SteIllegal() correctly, it seems S2S would conflict
against the STE.EATS settings?
// Check ATS configuration
if ((sec_sid == SS_NonSecure && SMMU_IDR0.ATS == '1') ||
(sec_sid == SS_Realm && SMMU_R_IDR0.ATS == '1')) &&
STE.Config != 'x00' then
// Needs to be NS/Realm, ATS enabled, and not Bypass
if STE.EATS == '01' && STE.S2S == '1' then
// Full ATS mode
if STE.Config == '11x' || constr_unpred_EATS_S2S then
// if stage 2 enabled or CONSTRAINED UNPREDICTABLE for SMMUv3.0
return TRUE;
So, if master->stall_enabled and master->ats_enabled, there would
be a bad STE?
Thanks
Nicolin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
2024-08-30 16:30 ` Nicolin Chen
@ 2024-08-30 17:02 ` Robin Murphy
2024-08-30 17:07 ` Nicolin Chen
0 siblings, 1 reply; 8+ messages in thread
From: Robin Murphy @ 2024-08-30 17:02 UTC (permalink / raw)
To: Nicolin Chen, Mostafa Saleh
Cc: linux-kernel, iommu, linux-arm-kernel, will, joro, jean-philippe,
jgg, mshavit
On 30/08/2024 5:30 pm, Nicolin Chen wrote:
> On Fri, Aug 30, 2024 at 11:03:47AM +0000, Mostafa Saleh wrote:
>
>> According to the spec (ARM IHI 0070 F.b), in
>> "5.5 Fault configuration (A, R, S bits)":
>> A STE with stage 2 translation enabled and STE.S2S == 0 is
>> considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10.
>>
>> Also described in the pseudocode “SteIllegal()”
>> if STE.Config == '11x' then
>> [..]
>> if eff_idr0_stall_model == '10' && STE.S2S == '0' then
>> // stall_model forcing stall, but S2S == 0
>> return TRUE;
>>
>> Which means, S2S must be set when stall model is
>> "ARM_SMMU_FEAT_STALL_FORCE", but currently the driver ignores that.
>>
>> Although, the driver can do the minimum and only set S2S for
>> “ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1
>> behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the
>> master has requested stalls.
>
> If I read the SteIllegal() correctly, it seems S2S would conflict
> against the STE.EATS settings?
>
> // Check ATS configuration
> if ((sec_sid == SS_NonSecure && SMMU_IDR0.ATS == '1') ||
> (sec_sid == SS_Realm && SMMU_R_IDR0.ATS == '1')) &&
> STE.Config != 'x00' then
> // Needs to be NS/Realm, ATS enabled, and not Bypass
> if STE.EATS == '01' && STE.S2S == '1' then
> // Full ATS mode
> if STE.Config == '11x' || constr_unpred_EATS_S2S then
> // if stage 2 enabled or CONSTRAINED UNPREDICTABLE for SMMUv3.0
> return TRUE;
>
> So, if master->stall_enabled and master->ats_enabled, there would
> be a bad STE?
Indeed, but as discussed previously, to get there would require either
firmware or hardware to bogusly advertise both stall and ATS
capabilities for the same device, which we decided is beyond the scope
of what's worth trying to reason about. If a nonsensical system leads to
obviously blowing up with C_BAD_STE, that's arguably not such a bad thing.
Thanks,
Robin.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
2024-08-30 17:02 ` Robin Murphy
@ 2024-08-30 17:07 ` Nicolin Chen
0 siblings, 0 replies; 8+ messages in thread
From: Nicolin Chen @ 2024-08-30 17:07 UTC (permalink / raw)
To: Robin Murphy
Cc: Mostafa Saleh, linux-kernel, iommu, linux-arm-kernel, will, joro,
jean-philippe, jgg, mshavit
On Fri, Aug 30, 2024 at 06:02:35PM +0100, Robin Murphy wrote:
> On 30/08/2024 5:30 pm, Nicolin Chen wrote:
> > On Fri, Aug 30, 2024 at 11:03:47AM +0000, Mostafa Saleh wrote:
> >
> > > According to the spec (ARM IHI 0070 F.b), in
> > > "5.5 Fault configuration (A, R, S bits)":
> > > A STE with stage 2 translation enabled and STE.S2S == 0 is
> > > considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10.
> > >
> > > Also described in the pseudocode “SteIllegal()”
> > > if STE.Config == '11x' then
> > > [..]
> > > if eff_idr0_stall_model == '10' && STE.S2S == '0' then
> > > // stall_model forcing stall, but S2S == 0
> > > return TRUE;
> > >
> > > Which means, S2S must be set when stall model is
> > > "ARM_SMMU_FEAT_STALL_FORCE", but currently the driver ignores that.
> > >
> > > Although, the driver can do the minimum and only set S2S for
> > > “ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1
> > > behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the
> > > master has requested stalls.
> >
> > If I read the SteIllegal() correctly, it seems S2S would conflict
> > against the STE.EATS settings?
> >
> > // Check ATS configuration
> > if ((sec_sid == SS_NonSecure && SMMU_IDR0.ATS == '1') ||
> > (sec_sid == SS_Realm && SMMU_R_IDR0.ATS == '1')) &&
> > STE.Config != 'x00' then
> > // Needs to be NS/Realm, ATS enabled, and not Bypass
> > if STE.EATS == '01' && STE.S2S == '1' then
> > // Full ATS mode
> > if STE.Config == '11x' || constr_unpred_EATS_S2S then
> > // if stage 2 enabled or CONSTRAINED UNPREDICTABLE for SMMUv3.0
> > return TRUE;
> >
> > So, if master->stall_enabled and master->ats_enabled, there would
> > be a bad STE?
>
> Indeed, but as discussed previously, to get there would require either
> firmware or hardware to bogusly advertise both stall and ATS
> capabilities for the same device, which we decided is beyond the scope
> of what's worth trying to reason about. If a nonsensical system leads to
> obviously blowing up with C_BAD_STE, that's arguably not such a bad thing.
Oh, I see. Thanks for the note!
Nicolin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
2024-08-30 16:30 ` Nicolin Chen
@ 2024-08-30 20:20 ` Jason Gunthorpe
1 sibling, 0 replies; 8+ messages in thread
From: Jason Gunthorpe @ 2024-08-30 20:20 UTC (permalink / raw)
To: Mostafa Saleh
Cc: linux-kernel, iommu, linux-arm-kernel, will, robin.murphy, joro,
jean-philippe, nicolinc, mshavit
On Fri, Aug 30, 2024 at 11:03:47AM +0000, Mostafa Saleh wrote:
> According to the spec (ARM IHI 0070 F.b), in
> "5.5 Fault configuration (A, R, S bits)":
> A STE with stage 2 translation enabled and STE.S2S == 0 is
> considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10.
>
> Also described in the pseudocode “SteIllegal()”
> if STE.Config == '11x' then
> [..]
> if eff_idr0_stall_model == '10' && STE.S2S == '0' then
> // stall_model forcing stall, but S2S == 0
> return TRUE;
>
> Which means, S2S must be set when stall model is
> "ARM_SMMU_FEAT_STALL_FORCE", but currently the driver ignores that.
>
> Although, the driver can do the minimum and only set S2S for
> “ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1
> behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the
> master has requested stalls.
Hum, that is looking a bit out of date
perhaps. ARM_SMMU_FEAT_STALL_FORCE should definately set stall, but
for stall-optional it should probably only be set if a faulting type
domain is installed (probably on a PASID)..
Still looks Ok
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-08-30 20:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30 11:03 [PATCH v4 0/2] Fix handling of S2 stalls Mostafa Saleh
2024-08-30 11:03 ` [PATCH v4 1/2] iommu/arm-smmu-v3: Match Stall behaviour for S2 Mostafa Saleh
2024-08-30 16:30 ` Nicolin Chen
2024-08-30 17:02 ` Robin Murphy
2024-08-30 17:07 ` Nicolin Chen
2024-08-30 20:20 ` Jason Gunthorpe
2024-08-30 11:03 ` [PATCH v4 2/2] iommu/arm-smmu-v3-test: Test masters with stall enabled Mostafa Saleh
2024-08-30 16:12 ` [PATCH v4 0/2] Fix handling of S2 stalls Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).