Re: [PATCH v1 07/10] iommu/vt-d: Use an xarray for global device_domain_info
From: Christoph Hellwig
Date: Mon Feb 07 2022 - 02:18:25 EST
> + #define DEVI_IDX(seg, bus, devfn) ((((u16)(seg)) << 16) | PCI_DEVID(bus, devfn))
Please turn this into an real function.
> /*
> - * Iterate over elements in device_domain_list and call the specified
> + * Iterate over elements in device_domain_array and call the specified
> * callback @fn against each element.
> */
> int for_each_device_domain(int (*fn)(struct device_domain_info *info,
> void *data), void *data)
> {
> struct device_domain_info *info;
> + unsigned long index;
> + int ret = 0;
>
> + rcu_read_lock();
> + xa_for_each(&device_domain_array, index, info) {
> ret = fn(info, data);
> + if (ret)
> + break;
> }
> + rcu_read_unlock();
Can't we just open code this in the caller now?
> const struct iommu_ops intel_iommu_ops;
> @@ -900,7 +898,8 @@ static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn, u8 bus, u
> struct dmar_domain *domain;
> int offset, level;
>
> - info = dmar_search_domain_by_dev_info(iommu->segment, bus, devfn);
> + info = xa_load(&device_domain_array,
> + DEVI_IDX(iommu->segment, bus, devfn));
> if (!info || !info->domain) {
> pr_info("device [%02x:%02x.%d] not probed\n",
> bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
Is there any refcounting or other life time protection for the info
structures?