Skip to content

Commit

Permalink
iommu: Introduce iommu_get_nesting
Browse files Browse the repository at this point in the history
Add iommu_get_nesting() which allow to retrieve whether a domain
uses nested stages.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
  • Loading branch information
eauger authored and intel-lab-lkp committed Oct 27, 2021
1 parent 83072c8 commit bd101c4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
Expand Up @@ -2731,6 +2731,13 @@ static int arm_smmu_enable_nesting(struct iommu_domain *domain)
return ret;
}

static bool arm_smmu_get_nesting(struct iommu_domain *domain)
{
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);

return smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED;
}

static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args)
{
return iommu_fwspec_add_ids(dev, args->args, 1);
Expand Down Expand Up @@ -2845,6 +2852,7 @@ static struct iommu_ops arm_smmu_ops = {
.release_device = arm_smmu_release_device,
.device_group = arm_smmu_device_group,
.enable_nesting = arm_smmu_enable_nesting,
.get_nesting = arm_smmu_get_nesting,
.of_xlate = arm_smmu_of_xlate,
.get_resv_regions = arm_smmu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
Expand Down
8 changes: 8 additions & 0 deletions drivers/iommu/arm/arm-smmu/arm-smmu.c
Expand Up @@ -1522,6 +1522,13 @@ static int arm_smmu_enable_nesting(struct iommu_domain *domain)
return ret;
}

static bool arm_smmu_get_nesting(struct iommu_domain *domain)
{
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);

return smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED;
}

static int arm_smmu_set_pgtable_quirks(struct iommu_domain *domain,
unsigned long quirks)
{
Expand Down Expand Up @@ -1595,6 +1602,7 @@ static struct iommu_ops arm_smmu_ops = {
.probe_finalize = arm_smmu_probe_finalize,
.device_group = arm_smmu_device_group,
.enable_nesting = arm_smmu_enable_nesting,
.get_nesting = arm_smmu_get_nesting,
.set_pgtable_quirks = arm_smmu_set_pgtable_quirks,
.of_xlate = arm_smmu_of_xlate,
.get_resv_regions = arm_smmu_get_resv_regions,
Expand Down
13 changes: 13 additions & 0 deletions drivers/iommu/intel/iommu.c
Expand Up @@ -5602,6 +5602,18 @@ intel_iommu_enable_nesting(struct iommu_domain *domain)
return ret;
}

static bool intel_iommu_get_nesting(struct iommu_domain *domain)
{
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
bool nesting;

spin_lock_irqsave(&device_domain_lock, flags);
nesting = dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE &&
!(dmar_domain->flags & DOMAIN_FLAG_USE_FIRST_LEVEL);
spin_unlock_irqrestore(&device_domain_lock, flags);
return nesting;
}

/*
* Check that the device does not live on an external facing PCI port that is
* marked as untrusted. Such devices should not be able to apply quirks and
Expand Down Expand Up @@ -5639,6 +5651,7 @@ const struct iommu_ops intel_iommu_ops = {
.domain_alloc = intel_iommu_domain_alloc,
.domain_free = intel_iommu_domain_free,
.enable_nesting = intel_iommu_enable_nesting,
.get_nesting = intel_iommu_get_nesting,
.attach_dev = intel_iommu_attach_device,
.detach_dev = intel_iommu_detach_device,
.aux_attach_dev = intel_iommu_aux_attach_device,
Expand Down
10 changes: 10 additions & 0 deletions drivers/iommu/iommu.c
Expand Up @@ -2842,6 +2842,16 @@ int iommu_enable_nesting(struct iommu_domain *domain)
}
EXPORT_SYMBOL_GPL(iommu_enable_nesting);

bool iommu_get_nesting(struct iommu_domain *domain)
{
if (domain->type != IOMMU_DOMAIN_UNMANAGED)
return false;
if (!domain->ops->enable_nesting)
return false;
return domain->ops->get_nesting(domain);
}
EXPORT_SYMBOL_GPL(iommu_get_nesting);

int iommu_set_pgtable_quirks(struct iommu_domain *domain,
unsigned long quirk)
{
Expand Down
8 changes: 8 additions & 0 deletions include/linux/iommu.h
Expand Up @@ -213,6 +213,7 @@ struct iommu_iotlb_gather {
* group and attached to the groups domain
* @device_group: find iommu group for a particular device
* @enable_nesting: Enable nesting
* @get_nesting: get whether the domain uses nested stages
* @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*)
* @get_resv_regions: Request list of reserved regions for a device
* @put_resv_regions: Free list of reserved regions for a device
Expand Down Expand Up @@ -271,6 +272,7 @@ struct iommu_ops {
void (*probe_finalize)(struct device *dev);
struct iommu_group *(*device_group)(struct device *dev);
int (*enable_nesting)(struct iommu_domain *domain);
bool (*get_nesting)(struct iommu_domain *domain);
int (*set_pgtable_quirks)(struct iommu_domain *domain,
unsigned long quirks);

Expand Down Expand Up @@ -690,6 +692,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev,
void *drvdata);
void iommu_sva_unbind_device(struct iommu_sva *handle);
u32 iommu_sva_get_pasid(struct iommu_sva *handle);
bool iommu_get_nesting(struct iommu_domain *domain);

#else /* CONFIG_IOMMU_API */

Expand Down Expand Up @@ -1108,6 +1111,11 @@ static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
{
return NULL;
}

static inline bool iommu_get_nesting(struct iommu_domain *domain)
{
return false;
}
#endif /* CONFIG_IOMMU_API */

/**
Expand Down

0 comments on commit bd101c4

Please sign in to comment.