Messages in this thread | | | Date | Mon, 13 Mar 2023 21:51:27 +0800 | Subject | Re: [PATCH v2 5/5] iommu/vt-d: Add nested domain support | From | "Liu, Jingqi" <> |
| |
On 3/9/2023 4:22 PM, Yi Liu wrote: > From: Lu Baolu <baolu.lu@linux.intel.com> > > This adds nested domain support in the Intel IOMMU driver. It allows to > allocate and free a nested domain, set the nested domain to a device, > and synchronize the caches when the userspace managed page tables are > updated. > > Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> > Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> > Signed-off-by: Yi Liu <yi.l.liu@intel.com> > --- > drivers/iommu/intel/Makefile | 2 +- > drivers/iommu/intel/iommu.c | 38 ++++++---- > drivers/iommu/intel/iommu.h | 15 ++++ > drivers/iommu/intel/nested.c | 143 +++++++++++++++++++++++++++++++++++ > 4 files changed, 182 insertions(+), 16 deletions(-) > create mode 100644 drivers/iommu/intel/nested.c [...]
> + > +struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *s2_domain, > + const void *user_data) > +{ > + const struct iommu_hwpt_intel_vtd *vtd = user_data; > + struct dmar_domain *domain; > +
Would it be better to add the following check ?
if (WARN_ON(!user_data)) return NULL;
> + domain = kzalloc(sizeof(*domain), GFP_KERNEL_ACCOUNT); > + if (!domain) > + return NULL; > + > + domain->use_first_level = true; > + domain->s2_domain = to_dmar_domain(s2_domain); > + domain->s1_pgtbl = vtd->pgtbl_addr; > + domain->s1_cfg = *vtd; > + domain->domain.ops = &intel_nested_domain_ops; > + domain->domain.type = IOMMU_DOMAIN_NESTED; > + INIT_LIST_HEAD(&domain->devices); > + spin_lock_init(&domain->lock); > + xa_init(&domain->iommu_array); > + > + return &domain->domain; > +}
Thanks,
Jingqi
| |