Re: [PATCH 2/6] iommu/amd: Clear DTE with update_dte256 in iommu_ignore_device()
From: Vasant Hegde
Date: Tue Jun 02 2026 - 05:04:18 EST
On 6/1/2026 7:12 PM, Pranjal Shrivastava wrote:
> The iommu_ignore_device() function currently uses memset() to clear
> the Device Table Entry (DTE), which risks torn writes because the
> hardware reads DTEs as atomic 256-bit qwords. Fix this by using
> update_dte256() to perform a hardware-safe atomic clear when a live
> dev_data entry is available.
>
> Fixes: 99fc4ac3d297 ("iommu/amd: Introduce per PCI segment alias_table")
> Reported-by: sashiko-bot@xxxxxxxxxx
> Closes: https://lore.kernel.org/all/20260529153216.2AD1E1F00899@xxxxxxxxxxxxxxx/
> Signed-off-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
> ---
> drivers/iommu/amd/iommu.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index a94de66a885e..9b5861e241d7 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -750,7 +750,16 @@ static void iommu_ignore_device(struct amd_iommu *iommu, struct device *dev)
> setup_aliases(iommu, dev);
>
> pci_seg->rlookup_table[devid] = NULL;
> - memset(&dev_table[devid], 0, sizeof(struct dev_table_entry));
> +
> + /* Clear DTE if we have a live entry */
> + if (dev_data) {
> + struct dev_table_entry new = {};
> +
> + amd_iommu_make_clear_dte(dev_data, &new);
> + update_dte256(iommu, dev_data, &new);
> + } else {
> + memset(&dev_table[devid], 0, sizeof(struct dev_table_entry));
> + }
> }
>
Why not clear_dte_entry() that will disable the DMA for device and alias
devices? May be we should rename fucntion name as well iommu_ignore_device ->
iommu_disable_device_dma or something.
-Vasant