Re: [PATCH v2 2/5] iommu/amd: Fix DTE clearing and rename iommu_ignore_device()
From: Vasant Hegde
Date: Sat Aug 22 2026 - 10:00:35 EST
On 8/14/2026 7:26 AM, Pranjal Shrivastava wrote:
> The iommu_ignore_device() function currently uses memset() to manually
> clear the primary Device Table Entry (DTE), which risks torn writes as
> the hardware reads DTEs as atomic 256-bit qwords. Furthermore, clearing
> the primary devid in the lookup table before calling setup_aliases()
> causes rlookup_amd_iommu() to fail for aliases. This prevents clearing
> the DTEs for DMA aliases.
>
> Fix this by replacing the manual memset with a dedicated helper that
> invalidates the DTE by clearing the lower 128 bits (having the Valid bit)
> first, followed by the upper 128 bits. The cleared state is then
> explicitly cloned to all aliases before the lookup tables are nullified.
>
> Rename the function to iommu_disable_device_dma() more accurately
> reflects its intent, as we still support IRQ remapping for these devices)
>
> Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table")
> Reported-by: sashiko-bot@xxxxxxxxxx
> Closes: https://lore.kernel.org/all/20260529153216.2AD1E1F00899@xxxxxxxxxxxxxxx/
> Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> Signed-off-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
> ---
> drivers/iommu/amd/iommu.c | 53 ++++++++++++++++++++++++++-------------
> 1 file changed, 36 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 9b8ad131ba79..911a95527d74 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -728,22 +728,6 @@ static struct iommu_dev_data *iommu_init_device(struct amd_iommu *iommu,
> return dev_data;
> }
>
> -static void iommu_ignore_device(struct amd_iommu *iommu, struct device *dev)
> -{
> - struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg;
> - struct dev_table_entry *dev_table = get_dev_table(iommu);
> - int devid, sbdf;
> -
> - sbdf = get_device_sbdf_id(dev);
> - if (sbdf < 0)
> - return;
> -
> - devid = PCI_SBDF_TO_DEVID(sbdf);
> - pci_seg->rlookup_table[devid] = NULL;
> - memset(&dev_table[devid], 0, sizeof(struct dev_table_entry));
> -
> - setup_aliases(iommu, dev);
> -}
>
>
> /****************************************************************************
> @@ -2233,6 +2217,41 @@ static void dev_update_dte(struct iommu_dev_data *dev_data, bool set)
> clear_dte_entry(iommu, dev_data);
> }
>
> +/*
> + * Invalidate a DTE by clearing the Valid bit first.
> + * Note: Not to be used on a fully probed device with
> + * live dev_data.
> + */
> +static void amd_iommu_disable_dte(struct dev_table_entry *ptr)
> +{
> + struct dev_table_entry new = {};
> +
> + write_dte_lower128(ptr, &new);
> + write_dte_upper128(ptr, &new);
> +}
> +
> +static void iommu_disable_device_dma(struct amd_iommu *iommu, struct device *dev)
This will disable interrupt remapping support as well. May be we should rename
this function.
Otherwise patch looks good.
-Vasant