* [PATCH v2 1/2] iommu/ipmmu-vmsa: Propagate errors from iommu_fwspec_add_ids()
2026-11-05 2:49 [PATCH v2 0/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use Koichiro Den
@ 2026-11-05 2:49 ` Koichiro Den
2026-11-05 2:49 ` [PATCH v2 2/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use Koichiro Den
2026-12-02 13:24 ` [PATCH v2 0/2] " Koichiro Den
2 siblings, 0 replies; 5+ messages in thread
From: Koichiro Den @ 2026-11-05 2:49 UTC (permalink / raw)
To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Magnus Damm,
Jason Gunthorpe, Lu Baolu
Cc: Geert Uytterhoeven, Marek Vasut, Yoshihiro Shimoda, iommu,
linux-renesas-soc, linux-kernel
iommu_fwspec_add_ids() can fail while extending the ID array. Ignoring
its return value lets IOMMU setup continue with missing micro-TLB IDs.
Propagate the error so of_iommu_configure() can discard the incomplete
fwspec.
Cc: stable@vger.kernel.org
Fixes: 7b2d59611fef ("iommu/ipmmu-vmsa: Replace local utlb code with fwspec ids")
Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
Changes in v2:
- No changes.
drivers/iommu/ipmmu-vmsa.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 9386b752dea2..99586c68ef35 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -778,10 +778,14 @@ static bool ipmmu_device_is_allowed(struct device *dev)
static int ipmmu_of_xlate(struct device *dev,
const struct of_phandle_args *spec)
{
+ int ret;
+
if (!ipmmu_device_is_allowed(dev))
return -ENODEV;
- iommu_fwspec_add_ids(dev, spec->args, 1);
+ ret = iommu_fwspec_add_ids(dev, spec->args, 1);
+ if (ret)
+ return ret;
/* Initialize once - xlate() will call multiple times */
if (to_ipmmu(dev))
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use
2026-11-05 2:49 [PATCH v2 0/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use Koichiro Den
2026-11-05 2:49 ` [PATCH v2 1/2] iommu/ipmmu-vmsa: Propagate errors from iommu_fwspec_add_ids() Koichiro Den
@ 2026-11-05 2:49 ` Koichiro Den
2026-12-02 13:24 ` [PATCH v2 0/2] " Koichiro Den
2 siblings, 0 replies; 5+ messages in thread
From: Koichiro Den @ 2026-11-05 2:49 UTC (permalink / raw)
To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Magnus Damm,
Jason Gunthorpe, Lu Baolu
Cc: Geert Uytterhoeven, Marek Vasut, Yoshihiro Shimoda, iommu,
linux-renesas-soc, linux-kernel
PCI functions can share a micro-TLB. ipmmu_release_device() disables it
unconditionally, so removing one function makes DMA from the others
bypass translation even though they remain attached to a paging domain.
Leave micro-TLBs unchanged on device release, as other devices may still
use the domain. Instead, disable the micro-TLBs that still select its
context when that context is destroyed. Check the recorded context ID so
freeing an old domain does not disable a micro-TLB already switched to
another one.
Cc: stable@vger.kernel.org
Fixes: 24dfb197c3b7 ("iommu/ipmmu-vmsa: Call arm_iommu_release_mapping() in release path")
Suggested-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
Changes in v2:
- Disable micro-TLBs still selecting a context when that context is
destroyed, rather than reference-counting their users. (Robin)
- Remove the per-device state and restore the original identity-attach
behavior accordingly.
drivers/iommu/ipmmu-vmsa.c | 36 +++++++++++++-----------------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 99586c68ef35..f13131916b7c 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -281,11 +281,6 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
{
struct ipmmu_vmsa_device *mmu = domain->mmu;
- /*
- * TODO: Reference-count the microTLB as several bus masters can be
- * connected to the same microTLB.
- */
-
/* TODO: What should we set the ASID to ? */
ipmmu_imuasid_write(mmu, utlb, 0);
/* TODO: Do we need to flush the microTLB ? */
@@ -466,9 +461,18 @@ static int ipmmu_domain_init_context(struct ipmmu_vmsa_domain *domain)
static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain)
{
- if (!domain->mmu)
+ struct ipmmu_vmsa_device *mmu = domain->mmu;
+ unsigned int i;
+
+ if (!mmu)
return;
+ /* Released devices may have left micro-TLBs selecting this context. */
+ for (i = 0; i < mmu->features->num_utlbs; i++) {
+ if (mmu->utlb_ctx[i] == domain->context_id)
+ ipmmu_utlb_disable(domain, i);
+ }
+
/*
* Disable the context. Flush the TLB as required when modifying the
* context registers.
@@ -477,7 +481,7 @@ static void ipmmu_domain_destroy_context(struct ipmmu_vmsa_domain *domain)
*/
ipmmu_ctx_write_all(domain, IMCTR, IMCTR_FLUSH);
ipmmu_tlb_sync(domain);
- ipmmu_domain_free_context(domain->mmu->root, domain->context_id);
+ ipmmu_domain_free_context(mmu->root, domain->context_id);
}
/* -----------------------------------------------------------------------------
@@ -580,10 +584,6 @@ static void ipmmu_domain_free(struct iommu_domain *io_domain)
{
struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain);
- /*
- * Free the domain resources. We assume that all devices have already
- * been detached.
- */
ipmmu_domain_destroy_context(domain);
free_io_pgtable_ops(domain->iop);
kfree(domain);
@@ -863,18 +863,8 @@ static void ipmmu_probe_finalize(struct device *dev)
static void ipmmu_release_device(struct device *dev)
{
- struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
- struct ipmmu_vmsa_device *mmu = to_ipmmu(dev);
- unsigned int i;
-
- for (i = 0; i < fwspec->num_ids; ++i) {
- unsigned int utlb = fwspec->ids[i];
-
- ipmmu_imuctr_write(mmu, utlb, 0);
- mmu->utlb_ctx[utlb] = IPMMU_CTX_INVALID;
- }
-
- arm_iommu_release_mapping(mmu->mapping);
+ /* Micro-TLBs may be shared. Domain teardown handles their cleanup. */
+ arm_iommu_release_mapping(to_ipmmu(dev)->mapping);
}
static const struct iommu_ops ipmmu_ops = {
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 0/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use
2026-11-05 2:49 [PATCH v2 0/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use Koichiro Den
2026-11-05 2:49 ` [PATCH v2 1/2] iommu/ipmmu-vmsa: Propagate errors from iommu_fwspec_add_ids() Koichiro Den
2026-11-05 2:49 ` [PATCH v2 2/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use Koichiro Den
@ 2026-12-02 13:24 ` Koichiro Den
2026-12-02 14:00 ` Robin Murphy
2 siblings, 1 reply; 5+ messages in thread
From: Koichiro Den @ 2026-12-02 13:24 UTC (permalink / raw)
To: Joerg Roedel (AMD), Robin Murphy
Cc: Will Deacon, Magnus Damm, Jason Gunthorpe, Lu Baolu,
Geert Uytterhoeven, Marek Vasut, Yoshihiro Shimoda, iommu,
linux-renesas-soc, linux-kernel
On Thu, Nov 05, 2026 at 11:49:08AM +0900, Koichiro Den wrote:
> Hi,
>
> Removing one PCI function can disable the micro-TLB still used by other
> functions, causing their DMA to bypass the IOMMU. This series leaves
> shared micro-TLBs unchanged on device release and cleans them up when
> their domain's context is destroyed.
>
> v2 was retested in the same manner as v1 (with the Linux PCI endpoint
> framework exposing two functions to an R-Car S4 Spider host, by removing
> an unused function that shares a micro-TLB with the remaining function.)
Hi Joerg, Robin,
If it looks fine, could you please queue this on renesas/ipmmu for 7.5-rc1?
Best regards,
Koichiro Den
>
> Best regards,
> Koichiro Den
> ---
> v1->v2 changes:
> - Move micro-TLB cleanup from device release to context destruction,
> drop per-device reference counting. (Robin)
> - Drop v1 patch 2, as it is no longer needed.
>
> v1: https://lore.kernel.org/r/20261104162251.1749998-1-den@valinux.co.jp/
>
>
> Koichiro Den (2):
> iommu/ipmmu-vmsa: Propagate errors from iommu_fwspec_add_ids()
> iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use
>
> drivers/iommu/ipmmu-vmsa.c | 42 ++++++++++++++++----------------------
> 1 file changed, 18 insertions(+), 24 deletions(-)
>
>
> base-commit: 528280c12a26c9da2449c42c5ab4a5c4fe6dbb9c
> --
> 2.54.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use
2026-12-02 13:24 ` [PATCH v2 0/2] " Koichiro Den
@ 2026-12-02 14:00 ` Robin Murphy
0 siblings, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2026-12-02 14:00 UTC (permalink / raw)
To: Koichiro Den, Joerg Roedel (AMD)
Cc: Will Deacon, Magnus Damm, Jason Gunthorpe, Lu Baolu,
Geert Uytterhoeven, Marek Vasut, Yoshihiro Shimoda, iommu,
linux-renesas-soc, linux-kernel
On 02/12/2026 1:24 pm, Koichiro Den wrote:
> On Thu, Nov 05, 2026 at 11:49:08AM +0900, Koichiro Den wrote:
>> Hi,
>>
>> Removing one PCI function can disable the micro-TLB still used by other
>> functions, causing their DMA to bypass the IOMMU. This series leaves
>> shared micro-TLBs unchanged on device release and cleans them up when
>> their domain's context is destroyed.
>>
>> v2 was retested in the same manner as v1 (with the Linux PCI endpoint
>> framework exposing two functions to an R-Car S4 Spider host, by removing
>> an unused function that shares a micro-TLB with the remaining function.)
>
> Hi Joerg, Robin,
>
> If it looks fine, could you please queue this on renesas/ipmmu for 7.5-rc1?
Ah, indeed I had looked and thought "yeah, that looks pretty neat now",
but it probably helps if I transmit that thought beyond the inside of my
head...
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
>
> Best regards,
> Koichiro Den
>
>>
>> Best regards,
>> Koichiro Den
>> ---
>> v1->v2 changes:
>> - Move micro-TLB cleanup from device release to context destruction,
>> drop per-device reference counting. (Robin)
>> - Drop v1 patch 2, as it is no longer needed.
>>
>> v1: https://lore.kernel.org/r/20261104162251.1749998-1-den@valinux.co.jp/
>>
>>
>> Koichiro Den (2):
>> iommu/ipmmu-vmsa: Propagate errors from iommu_fwspec_add_ids()
>> iommu/ipmmu-vmsa: Keep shared micro-TLBs enabled while in use
>>
>> drivers/iommu/ipmmu-vmsa.c | 42 ++++++++++++++++----------------------
>> 1 file changed, 18 insertions(+), 24 deletions(-)
>>
>>
>> base-commit: 528280c12a26c9da2449c42c5ab4a5c4fe6dbb9c
>> --
>> 2.54.0
>>
^ permalink raw reply [flat|nested] 5+ messages in thread