mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vasant Hegde <vasant.hegde@amd.com>
To: Magnus Kalland <magnus@dolphinics.com>,
	suravee.suthikulpanit@amd.com, joro@8bytes.org,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: dhsrivas@amd.com, "Lars B . Kristiansen" <larsk@dolphinics.com>,
	Jonas Markussen <jonas@dolphinics.com>,
	"Tore H . Larsen" <torel@simula.no>
Subject: Re: [PATCH v3 3/3] iommu/amd: Invalidate IRT cache for DMA aliases
Date: Mon, 30 Mar 2026 16:48:23 +0530	[thread overview]
Message-ID: <2f486ae6-d22b-4a30-b93c-f019feb8043c@amd.com> (raw)
In-Reply-To: <20260225202330.23027-4-magnus@dolphinics.com>

Hi Magnus,


On 2/26/2026 1:53 AM, Magnus Kalland wrote:
> IRTEs may be shared between multiple device IDs when PCIe DMA
> aliasing is in use. The AMD IOMMU driver currently invalidates
> the interrupt remapping table cache only for the device ID used
> to update the IRTE.
> 
> If the same IRTE is cached under a different DMA alias, this
> leaves stale cache entries that are never invalidated.
> 
> Iterate over all device IDs sharing the same DMA alias and
> invalidate the IRT cache for each of them when an IRTE is updated.
> 
> Co-developed-by: Lars B. Kristiansen <larsk@dolphinics.com>
> Signed-off-by: Lars B. Kristiansen <larsk@dolphinics.com>
> Co-developed-by: Jonas Markussen <jonas@dolphinics.com>
> Signed-off-by: Jonas Markussen <jonas@dolphinics.com>
> Co-developed-by: Tore H. Larsen <torel@simula.no>
> Signed-off-by: Tore H. Larsen <torel@simula.no>
> Signed-off-by: Magnus Kalland <magnus@dolphinics.com>
> Link: https://lore.kernel.org/linux-iommu/26cfa307-6c33-41f9-a7a0-fbf202b38a00@amd.com/
> 
> ---
>  drivers/iommu/amd/iommu.c | 39 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 5dec3502c8b3..d9a91d1a083e 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3166,6 +3166,31 @@ const struct iommu_ops amd_iommu_ops = {
>  static struct irq_chip amd_ir_chip;
>  static DEFINE_RAW_SPINLOCK(iommu_table_lock);
>  
> +static int iommu_flush_irt_for_aliases(struct amd_iommu *iommu,
> +				       u16 alias)
> +{
> +	struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg;
> +	struct iommu_cmd cmd;
> +	unsigned long flags;
> +	u32 devid;
> +	int ret = 0;
> +
> +	raw_spin_lock_irqsave(&iommu_table_lock, flags);

There is a possible deadlock. Actually we can remove lock here?


path 1) alloc_irq_table() -> holds iommu_table_lock [A] -> iommu->lock [B]
path 2) iommu_flush_irt_and_complete -> holds iommu->lock [B] ->
iommu_table_lock [A]


> +
> +	for (devid = 0; devid <= pci_seg->last_bdf; ++devid) {
> +		if (pci_seg->alias_table[devid] != alias)

This is heavy hammer. Why not use pci_for_each_dma_alias() like we do in DTE
flush path?


-Vasant

> +			continue;
> +
> +		build_inv_irt(&cmd, devid);
> +		ret = __iommu_queue_command_sync(iommu, &cmd, true);
> +		if (ret)
> +			goto out;
> +	}
> +
> +out:
> +	raw_spin_unlock_irqrestore(&iommu_table_lock, flags);
> +	return ret;
> +}
>  
>  static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid)
>  {
> @@ -3173,19 +3198,29 @@ static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid)
>  	u64 data;
>  	unsigned long flags;
>  	struct iommu_cmd cmd, cmd2;
> +	u16 alias;
>  
>  	if (iommu->irtcachedis_enabled)
>  		return;
>  
> -	build_inv_irt(&cmd, devid);
> +	raw_spin_lock_irqsave(&iommu_table_lock, flags);
> +	alias = iommu->pci_seg->alias_table[devid];
> +	raw_spin_unlock_irqrestore(&iommu_table_lock, flags);
>  
>  	raw_spin_lock_irqsave(&iommu->lock, flags);
>  	data = get_cmdsem_val(iommu);
>  	build_completion_wait(&cmd2, iommu, data);
>  
> -	ret = __iommu_queue_command_sync(iommu, &cmd, true);
> +	if (alias == devid) {
> +		build_inv_irt(&cmd, devid);
> +		ret = __iommu_queue_command_sync(iommu, &cmd, true);
> +	} else {
> +		ret = iommu_flush_irt_for_aliases(iommu, alias);
> +	}
> +
>  	if (ret)
>  		goto out_err;
> +
>  	ret = __iommu_queue_command_sync(iommu, &cmd2, false);
>  	if (ret)
>  		goto out_err;


  reply	other threads:[~2026-03-30 11:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 20:23 [PATCH v3 0/3] " Magnus Kalland
2026-02-25 20:23 ` [PATCH v3 1/3] iommu/amd: Use raw spinlock for interrupt remapping tables Magnus Kalland
2026-03-30 15:23   ` Vasant Hegde
2026-03-31 13:10     ` Magnus Kalland
2026-02-25 20:23 ` [PATCH v3 2/3] iommu/amd: Track PCIe DMA aliases in set_remap_table_entry_alias Magnus Kalland
2026-02-25 20:23 ` [PATCH v3 3/3] iommu/amd: Invalidate IRT cache for DMA aliases Magnus Kalland
2026-03-30 11:18   ` Vasant Hegde [this message]
2026-03-31 12:48     ` Magnus Kalland
2026-04-01  7:44       ` Vasant Hegde
2026-04-01 10:34         ` Magnus Kalland
2026-04-01 10:46           ` Vasant Hegde
2026-04-01 11:38             ` Magnus Kalland
2026-03-06  9:22 [PATCH v3 0/3] " Magnus Kalland
2026-03-06  9:22 ` [PATCH v3 3/3] " Magnus Kalland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f486ae6-d22b-4a30-b93c-f019feb8043c@amd.com \
    --to=vasant.hegde@amd.com \
    --cc=dhsrivas@amd.com \
    --cc=iommu@lists.linux.dev \
    --cc=jonas@dolphinics.com \
    --cc=joro@8bytes.org \
    --cc=larsk@dolphinics.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=magnus@dolphinics.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=torel@simula.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®