History

iommu/amd: Invalidate IRT cache for DMA aliases

DMA aliasing causes interrupt remapping table entries (IRTEs) to be shared between multiple device IDs. See commit 3c124435e8dd ("iommu/amd: Support multiple PCI DMA aliases in IRQ Remapping") for more information on this. However, the AMD IOMMU driver currently invalidates IRTE cache entries on a per-device basis whenever an IRTE is updated, not for each alias. This approach leaves stale IRTE cache entries when an IRTE is cached under one DMA alias but later updated and invalidated through a different alias. In such cases, the original device ID is never invalidated, since it is programmed via aliasing. This incoherency bug has been observed when IRTEs are cached for one Non-Transparent Bridge (NTB) DMA alias, later updated via another. Fix this by invalidating the interrupt remapping table cache for all DMA aliases when updating an IRTE.

Magnus Kalland committed 7 months ago

Commit 5aac2871 parent faad2241 file · +23 −5Browse files

Unified · Split

drivers/iommu/amd/iommu.c+23−5
@@ -3167,26 +3167,44 @@ const struct iommu_ops amd_iommu_ops = { · 3166 unmodified lines
3167static struct irq_chip amd_ir_chip;3167static struct irq_chip amd_ir_chip;
3168static DEFINE_SPINLOCK(iommu_table_lock);3168static DEFINE_SPINLOCK(iommu_table_lock);
3169 3169
3170static int iommu_flush_dev_irt(struct pci_dev *unused, u16 devid, void *data)
3171{
3172 int ret;
3173 struct iommu_cmd cmd;
3174 struct amd_iommu *iommu = data;
3175
3176 build_inv_irt(&cmd, devid);
3177 ret = __iommu_queue_command_sync(iommu, &cmd, true);
3178 return ret;
3179}
3180
3170static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid)3181static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid)
3171{3182{
3172 int ret;3183 int ret;
3173 u64 data;3184 u64 data;
3174 unsigned long flags;3185 unsigned long flags;
3175 struct iommu_cmd cmd, cmd2;3186 struct iommu_cmd cmd;
3187 struct pci_dev *pdev = NULL;
3188 struct iommu_dev_data *dev_data = search_dev_data(iommu, devid);
3176 3189
3177 if (iommu->irtcachedis_enabled)3190 if (iommu->irtcachedis_enabled)
3178 return;3191 return;
3179 3192
3180 build_inv_irt(&cmd, devid);3193 if (dev_data && dev_data->dev && dev_is_pci(dev_data->dev))
3194 pdev = to_pci_dev(dev_data->dev);
3181 3195
3182 raw_spin_lock_irqsave(&iommu->lock, flags);3196 raw_spin_lock_irqsave(&iommu->lock, flags);
3183 data = get_cmdsem_val(iommu);3197 data = get_cmdsem_val(iommu);
3184 build_completion_wait(&cmd2, iommu, data);3198 build_completion_wait(&cmd, iommu, data);
3185 3199
3186 ret = __iommu_queue_command_sync(iommu, &cmd, true);3200 if (pdev)
3201 ret = pci_for_each_dma_alias(pdev, iommu_flush_dev_irt, iommu);
3202 else
3203 ret = iommu_flush_dev_irt(NULL, devid, iommu);
3187 if (ret)3204 if (ret)
3188 goto out_err;3205 goto out_err;
3189 ret = __iommu_queue_command_sync(iommu, &cmd2, false);3206
3207 ret = __iommu_queue_command_sync(iommu, &cmd, false);
3190 if (ret)3208 if (ret)
3191 goto out_err;3209 goto out_err;
3192 raw_spin_unlock_irqrestore(&iommu->lock, flags);3210 raw_spin_unlock_irqrestore(&iommu->lock, flags);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t