Re: [PATCH v4 6/7] iommu/vt-d: Add support for static identity domain

From: Baolu Lu
Date: Sat Aug 10 2024 - 04:01:57 EST


On 2024/8/9 16:29, Tian, Kevin wrote:
From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Sent: Friday, August 9, 2024 1:55 PM

+static int context_setup_pass_through(struct device *dev, u8 bus, u8 devfn)
+{
+ struct device_domain_info *info = dev_iommu_priv_get(dev);
+ struct intel_iommu *iommu = info->iommu;
+ struct context_entry *context;
+
+ spin_lock(&iommu->lock);
+ context = iommu_context_addr(iommu, bus, devfn, 1);
+ if (!context) {
+ spin_unlock(&iommu->lock);
+ return -ENOMEM;
+ }
+
+ if (context_present(context) && !context_copied(iommu, bus, devfn))
{
+ spin_unlock(&iommu->lock);
+ return 0;
+ }

Is it a valid case to setup passthrough on a present entry?

It's valid but unnecessary.

Since the context is present, it indicates that the configuration has
already been setup by a PCI aliased device. The iommu group mandates
that all PCI aliased devices must be attached to the same iommu domain.
Consequently, there's no need for additional configuration.

While it's feasible to remove this line of code due to the check in the
pci_for_each_dma_alias() callback:

static int context_setup_pass_through_cb(struct pci_dev *pdev, u16 alias, void *data)
{
struct device *dev = data;

if (dev != &pdev->dev)
return 0;

return context_setup_pass_through(dev, PCI_BUS_NUM(alias), alias & 0xff);
}

But it's in the original code, I've retained it to prevent any potential
regression.

Thanks,
baolu