mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
iommu: Express DMA strictness via the domain type
Eliminate the iommu_get_dma_strict() indirection and pipe the information through the domain type from the beginning. Besides the flow simplification this also has several nice side-effects: - Automatically implies strict mode for untrusted devices by virtue of their IOMMU_DOMAIN_DMA override. - Ensures that we only end up using flush queues for drivers which are aware of them and can actually benefit. - Allows us to handle flush queue init failure by falling back to strict mode instead of leaving it to possibly blow up later. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/47083d69155577f1367877b1594921948c366eb3.1628682049.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
78ca078459
commit
c208916fe6
@ -370,13 +370,15 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
|
||||
|
||||
init_iova_domain(iovad, 1UL << order, base_pfn);
|
||||
|
||||
if (!cookie->fq_domain && !dev_is_untrusted(dev) &&
|
||||
domain->ops->flush_iotlb_all && !iommu_get_dma_strict(domain)) {
|
||||
/* If the FQ fails we can simply fall back to strict mode */
|
||||
if (domain->type == IOMMU_DOMAIN_DMA_FQ && !cookie->fq_domain) {
|
||||
if (init_iova_flush_queue(iovad, iommu_dma_flush_iotlb_all,
|
||||
iommu_dma_entry_dtor))
|
||||
iommu_dma_entry_dtor)) {
|
||||
pr_warn("iova flush queue initialization failed\n");
|
||||
else
|
||||
domain->type = IOMMU_DOMAIN_DMA;
|
||||
} else {
|
||||
cookie->fq_domain = domain;
|
||||
}
|
||||
}
|
||||
|
||||
return iova_reserve_iommu_regions(dev, domain);
|
||||
|
@ -136,6 +136,9 @@ static int __init iommu_subsys_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (!iommu_default_passthrough() && !iommu_dma_strict)
|
||||
iommu_def_domain_type = IOMMU_DOMAIN_DMA_FQ;
|
||||
|
||||
pr_info("Default domain type: %s %s\n",
|
||||
iommu_domain_type_str(iommu_def_domain_type),
|
||||
(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API) ?
|
||||
@ -355,17 +358,10 @@ early_param("iommu.strict", iommu_dma_setup);
|
||||
void iommu_set_dma_strict(void)
|
||||
{
|
||||
iommu_dma_strict = true;
|
||||
if (iommu_def_domain_type == IOMMU_DOMAIN_DMA_FQ)
|
||||
iommu_def_domain_type = IOMMU_DOMAIN_DMA;
|
||||
}
|
||||
|
||||
bool iommu_get_dma_strict(struct iommu_domain *domain)
|
||||
{
|
||||
/* only allow lazy flushing for DMA domains */
|
||||
if (domain->type == IOMMU_DOMAIN_DMA)
|
||||
return iommu_dma_strict;
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_get_dma_strict);
|
||||
|
||||
static ssize_t iommu_group_attr_show(struct kobject *kobj,
|
||||
struct attribute *__attr, char *buf)
|
||||
{
|
||||
|
@ -504,7 +504,6 @@ int iommu_set_pgtable_quirks(struct iommu_domain *domain,
|
||||
unsigned long quirks);
|
||||
|
||||
void iommu_set_dma_strict(void);
|
||||
bool iommu_get_dma_strict(struct iommu_domain *domain);
|
||||
|
||||
extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
|
||||
unsigned long iova, int flags);
|
||||
|
Loading…
Reference in New Issue
Block a user