Offering: HULK hulk inclusion category: feature ------------------ Squash of three commits from the hulk_6.6 tree: 1) support disable BTM by cmdline Offering: HULK category: feature Disabling BTM by configuring IDR0 requires a cold reset. Offer a CONFIG_SMMU_DISABLE_BTM option and a disable_btm module parameter to turn BTM off softly at probe time. 2) Don't set PTM when BTM is enabled Offering: HULK category: bugfix Fixes: 15d1fd835ee0 ("[Backport] iommu/arm-smmu-v3: Bring back SVA BTM support") CR2.PTM==1 would cause the SMMU to ignore DVM broadcast, so if the BTM feature is used, we should not set it, otherwise the broadcast TLBI that BTM relies on never reaches the SMMU and the IOTLB becomes stale. 3) asid_lock unlocked incorrectly Offering: HULK category: bugfix Fixes: 15d1fd835ee0 ("[Backport] iommu/arm-smmu-v3: Bring back SVA BTM support") In arm_smmu_attach_prepare, it should check whether the asid_lock is held, rather than unlock it. Signed-off-by: Zhang Yuwei <zhangyuwei20@huawei.com> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com> --- drivers/iommu/Kconfig | 7 +++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index f91ab5cba204..876a8f39e93b 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -568,4 +568,11 @@ config LOONGARCH_IOMMU can isolate the DMA memory of different devices and protect the system from misbehaving device drivers or hardware. +config SMMU_DISABLE_BTM + bool "disable BTM" + depends on ARM_SMMU_V3=y + help + Disabling BTM by configuring IDR0 requires a cold reset. + Provide a module parameter to disable BTM softly. + endif # IOMMU_SUPPORT 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 dbb3ba046c55..17fab83a0d18 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -42,6 +42,12 @@ #include <asm/hisi_cca_da.h> #endif +static bool disable_btm; +#ifdef CONFIG_SMMU_DISABLE_BTM +module_param(disable_btm, bool, 0444); +MODULE_PARM_DESC(disable_btm, "Disable BTM"); +#endif + static bool disable_msipolling; module_param(disable_msipolling, bool, 0444); MODULE_PARM_DESC(disable_msipolling, @@ -3047,7 +3053,7 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, * arm_smmu_master_domain contents otherwise it could randomly write one * or the other to the CD. */ - mutex_unlock(&master->smmu->asid_lock); + lockdep_assert_held(&master->smmu->asid_lock); if (smmu_domain || state->cd_needs_ats) { /* @@ -4927,11 +4933,14 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool resume) writel_relaxed(reg, smmu->base + ARM_SMMU_CR1); /* CR2 (random crap) */ - reg = CR2_PTM | CR2_RECINVSID; + reg = CR2_RECINVSID; if (smmu->features & ARM_SMMU_FEAT_E2H) reg |= CR2_E2H; + if (!(smmu->features & ARM_SMMU_FEAT_BTM)) + reg |= CR2_PTM; + writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); /* Stream table */ @@ -5344,7 +5353,7 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) * broadcasted TLB invalidations that target EL2-E2H world. Don't enable * BTM in that case. */ - if (reg & IDR0_BTM && (!vhe || reg & IDR0_HYP)) + if (reg & IDR0_BTM && (!vhe || reg & IDR0_HYP) && !disable_btm) smmu->features |= ARM_SMMU_FEAT_BTM; /* -- 2.22.0