sriov vf get iommu group kernel code trace

VF device driver call:
pci_enable_sriov -> sriov_enable -> pci_iov_add_virtfn -> pci_device_add -> device_add ->
                                             BUS_NOTIFY_ADD_DEVICE, dev);
pci bus register a iommu notifier will be called when device_add start to notify:
static int __init pci_iommu_init(void)
        if (iommu_detected)

        return 0;

/* Must execute after PCI subsystem */

intel_iommu_init -> iommu_bus_init -> “nb->notifier_call = iommu_bus_notifier;”

        if (action == BUS_NOTIFY_ADD_DEVICE) {
                if (ops->add_device)
                        return ops->add_device(dev);
static struct iommu_ops intel_iommu_ops = {
        .capable        = intel_iommu_capable,
        .domain_alloc   = intel_iommu_domain_alloc,
        .domain_free    = intel_iommu_domain_free,
        .attach_dev     = intel_iommu_attach_device,
        .detach_dev     = intel_iommu_detach_device,
        .map            = intel_iommu_map,
        .unmap          = intel_iommu_unmap,
        .map_sg         = default_iommu_map_sg,
        .iova_to_phys   = intel_iommu_iova_to_phys,
        .add_device     =intel_iommu_add_device,
        .remove_device  = intel_iommu_remove_device,
        .pgsize_bitmap  = INTEL_IOMMU_PGSIZES,


static int intel_iommu_add_device(struct device *dev)
        struct intel_iommu *iommu;
        struct iommu_group *group;
        u8 bus, devfn;

        iommu = device_to_iommu(dev, &bus, &devfn);
        if (!iommu)
                return -ENODEV;

        iommu_device_link(iommu->iommu_dev, dev);

        group = iommu_group_get_for_dev(dev);

        if (IS_ERR(group))
                return PTR_ERR(group);

        return 0;
this will find or create an iommu group for the VF device

Leave a Reply

Your email address will not be published. Required fields are marked *