mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Magnus Kalland <magnus@dolphinics.com>
To: vasant.hegde@amd.com
Cc: dhsrivas@amd.com, iommu@lists.linux.dev, jonas@dolphinics.com,
	joro@8bytes.org, larsk@dolphinics.com,
	linux-kernel@vger.kernel.org, magnus@dolphinics.com,
	suravee.suthikulpanit@amd.com, torel@simula.no
Subject: Re: [PATCH v3 3/3] iommu/amd: Invalidate IRT cache for DMA aliases
Date: Tue, 31 Mar 2026 14:48:03 +0200	[thread overview]
Message-ID: <20260331124830.53189-1-magnus@dolphinics.com> (raw)
In-Reply-To: <2f486ae6-d22b-4a30-b93c-f019feb8043c@amd.com>

Hi Vasant, and thank you for the review.

On Mon, Mar 30, 2026 at 04:48:23PM +0530, Vasant Hegde wrote:
> 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]

You are correct, there is a possible deadlock. We can avoid it by grabbing
iommu_table_lock, creating a local copy of the aliases, releasing it, then
flushing the aliases. This way, there is no nested locking in
iommu_flush_irt_and_complete.

We notice that the alias table is read in other paths without holding
iommu_table_lock (amd_iommu_change_top, setup_aliases). If we can do the same,
then that is of course another way to avoid the deadlock. What do you think?

> > +
> > +	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?

Agree this is heavy.

We cannot use pci_for_each_dma_alias. See the reply to our v1:
https://lore.kernel.org/linux-iommu/26cfa307-6c33-41f9-a7a0-fbf202b38a00@amd.com/

However, we have a v4 ready doing 256 loop iterations instead, since aliases
are always on the same bus. I think that's a better approach.
What do you think?

Thanks,
Magnus

Signed-off-by: Magnus Kalland <magnus@dolphinics.com>

  reply	other threads:[~2026-03-31 12:48 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
2026-03-31 12:48     ` Magnus Kalland [this message]
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=20260331124830.53189-1-magnus@dolphinics.com \
    --to=magnus@dolphinics.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=suravee.suthikulpanit@amd.com \
    --cc=torel@simula.no \
    --cc=vasant.hegde@amd.com \
    /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®