Intel IOMMU updates for v6.13
Subsystems (3)
Lu Baolu
maintainerHi Joerg,
The following changes have been queued for v6.13-rc1. They are about new features and code refactoring, including:
- Add domain_alloc_paging support
- Enable user space IOPFs in non-PASID and non-svm cases
- Small code refactoring and cleanups
These patches are based on v6.12-rc6. The complete patches are also available at:
https://github.com/LuBaolu/intel-iommu/commits/vtd-update-for-v6.13
Please consider them for iommu next.
Best regards,
baolu
Andy Shevchenko (1):
iommu/vt-d: Increase buffer size for device name
Dr. David Alan Gilbert (1):
iommu/vt-d: Remove unused dmar_msi_read
Jinjie Ruan (1):
iommu/vt-d: Use PCI_DEVID() macro
Joel Granados (3):
iommu/vt-d: Separate page request queue from SVM iommu/vt-d: Move IOMMU_IOPF into INTEL_IOMMU
iommufd: Enable PRI when doing the iommufd_hwpt_alloc
Klaus Jensen (2):
iommu/vt-d: Remove the pasid present check in prq_event_thread iommu/vt-d: Drop pasid requirement for prq initialization
Lu Baolu (8):
iommu/vt-d: Add domain_alloc_paging support iommu/vt-d: Remove unused domain_alloc callback iommu/vt-d: Enhance compatibility check for paging domain attach iommu/vt-d: Remove domain_update_iommu_cap() iommu/vt-d: Remove domain_update_iommu_superpage() iommu/vt-d: Refactor first_level_by_default() iommu/vt-d: Refine intel_iommu_domain_alloc_user() iommu/vt-d: Drain PRQs when domain removed from RID
Yi Liu (1):
iommu/vt-d: Drop s1_pgtbl from dmar_domain
Zhenzhong Duan (2):
iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() iommu/vt-d: Fix checks and print in pgtable_walk()
drivers/iommu/intel/Kconfig | 2 +- drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/dmar.c | 15 +- drivers/iommu/intel/iommu.c | 404 +++++++-------------------- drivers/iommu/intel/iommu.h | 22 +- drivers/iommu/intel/irq_remapping.c | 4 +- drivers/iommu/intel/nested.c | 3 +- drivers/iommu/intel/pasid.c | 34 +-- drivers/iommu/intel/prq.c | 396 ++++++++++++++++++++++++++ drivers/iommu/intel/svm.c | 397 -------------------------- drivers/iommu/iommufd/hw_pagetable.c | 3 +- include/linux/dmar.h | 1 - 12 files changed, 517 insertions(+), 766 deletions(-) create mode 100644 drivers/iommu/intel/prq.c
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 1/19 iommu/vt-d: Add domain_alloc_paging support
Add the domain_alloc_paging callback for domain allocation using the iommu_paging_domain_alloc() interface.
--- drivers/iommu/intel/iommu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/iommu/intel/iommu.c +14 -0
@@ -4592,6 +4592,19 @@ static struct iommu_domain identity_domain = { }, }; +static struct iommu_domain *intel_iommu_domain_alloc_paging (struct device *dev) +{ +struct dmar_domain *dmar_domain; +bool first_stage; + + first_stage =first_level_by_default (0 ); + dmar_domain =paging_domain_alloc (dev, first_stage); +if (IS_ERR (dmar_domain)) +return ERR_CAST (dmar_domain); + +return &dmar_domain->domain; +} +const struct iommu_ops intel_iommu_ops = { .blocked_domain = &blocking_domain, .release_domain = &blocking_domain,
@@ -4601,6 +4614,7 @@ const struct iommu_ops intel_iommu_ops = { .domain_alloc = intel_iommu_domain_alloc, .domain_alloc_user = intel_iommu_domain_alloc_user, .domain_alloc_sva = intel_svm_domain_alloc, + .domain_alloc_paging = intel_iommu_domain_alloc_paging, .probe_device = intel_iommu_probe_device, .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions,
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 2/19 iommu/vt-d: Remove unused domain_alloc callback
In reply to Lu BaoluWith domain_alloc_paging callback supported, the legacy domain_alloc callback will never be used anymore. Remove it to avoid dead code.
--- drivers/iommu/intel/iommu.c | 90 ------------------------------------- 1 file changed, 90 deletions(-)
drivers/iommu/intel/iommu.c +0 -90
@@ -1454,27 +1454,6 @@ static bool first_level_by_default(unsigned int type)return type !=IOMMU_DOMAIN_UNMANAGED ; } -static struct dmar_domain *alloc_domain (unsigned int type) -{ -struct dmar_domain *domain; - - domain =kzalloc (sizeof (*domain),GFP_KERNEL ); -if (!domain) -return NULL ; - - domain->nid =NUMA_NO_NODE ; -if (first_level_by_default (type)) - domain->use_first_level = true; -INIT_LIST_HEAD (&domain->devices); -INIT_LIST_HEAD (&domain->dev_pasids); -INIT_LIST_HEAD (&domain->cache_tags); -spin_lock_init (&domain->lock); -spin_lock_init (&domain->cache_lock); -xa_init (&domain->iommu_array); - -return domain; -} -int domain_attach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu) {struct iommu_domain_info *info, *curr;
@@ -1546,20 +1525,6 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)spin_unlock (&iommu->lock); } -static int guestwidth_to_adjustwidth (int gaw) -{ -int agaw; -int r = (gaw -12 ) %9 ; - -if (r ==0 ) - agaw = gaw; -else - agaw = gaw +9 - r; -if (agaw >64 ) - agaw =64 ; -return agaw; -} -static void domain_exit (struct dmar_domain *domain) {if (domain->pgd) {
@@ -3381,27 +3346,6 @@ void device_block_translation(struct device *dev) info->domain =NULL ; } -static int md_domain_init (struct dmar_domain *domain,int guest_width) -{ -int adjust_width; - -/* calculate AGAW */ - domain->gaw = guest_width; - adjust_width =guestwidth_to_adjustwidth (guest_width); - domain->agaw =width_to_agaw (adjust_width); - - domain->iommu_coherency = false; - domain->iommu_superpage =0 ; - domain->max_addr =0 ; - -/* always allocate the top pgd */ - domain->pgd =iommu_alloc_page_node (domain->nid,GFP_ATOMIC ); -if (!domain->pgd) -return -ENOMEM ; -domain_flush_cache (domain, domain->pgd,PAGE_SIZE ); -return 0 ; -} -static int blocking_domain_attach_dev (struct iommu_domain *domain,struct device *dev) {
@@ -3488,39 +3432,6 @@ static struct dmar_domain *paging_domain_alloc(struct device *dev, bool first_streturn domain; } -static struct iommu_domain *intel_iommu_domain_alloc (unsigned type) -{ -struct dmar_domain *dmar_domain; -struct iommu_domain *domain; - -switch (type) { -case IOMMU_DOMAIN_DMA : -case IOMMU_DOMAIN_UNMANAGED : - dmar_domain =alloc_domain (type); -if (!dmar_domain) { -pr_err ("Can't allocate dmar_domain\n" ); -return NULL ; - } -if (md_domain_init (dmar_domain,DEFAULT_DOMAIN_ADDRESS_WIDTH )) { -pr_err ("Domain initialization failed\n" ); -domain_exit (dmar_domain); -return NULL ; - } - - domain = &dmar_domain->domain; - domain->geometry.aperture_start =0 ; - domain->geometry.aperture_end = -__DOMAIN_MAX_ADDR (dmar_domain->gaw); - domain->geometry.force_aperture = true; - -return domain; -default : -return NULL ; - } - -return NULL ; -} -static struct iommu_domain * intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent,
@@ -4611,7 +4522,6 @@ const struct iommu_ops intel_iommu_ops = { .identity_domain = &identity_domain, .capable = intel_iommu_capable, .hw_info = intel_iommu_hw_info, - .domain_alloc = intel_iommu_domain_alloc, .domain_alloc_user = intel_iommu_domain_alloc_user, .domain_alloc_sva = intel_svm_domain_alloc, .domain_alloc_paging = intel_iommu_domain_alloc_paging,
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 3/19 iommu/vt-d: Enhance compatibility check for paging domain attach
In reply to Lu BaoluThe driver now supports domain_alloc_paging, ensuring that a valid device pointer is provided whenever a paging domain is allocated. Additionally, the dmar_domain attributes are set up at the time of allocation.
Consistent with the established semantics in the IOMMU core, if a domain is attached to a device and found to be incompatible with the IOMMU hardware capabilities, the operation will return an -EINVAL error. This implicitly advises the caller to allocate a new domain for the device and attempt the domain attachment again.
Rename prepare_domain_attach_device() to a more meaningful name.
--- drivers/iommu/intel/iommu.c | 70 ++++++++++++------------------------ drivers/iommu/intel/iommu.h | 3 +- drivers/iommu/intel/nested.c | 2 +- drivers/iommu/intel/pasid.c | 28 +-------------- 4 files changed, 26 insertions(+), 77 deletions(-)
drivers/iommu/intel/iommu.c +23 -47
@@ -1606,7 +1606,7 @@ static int domain_context_mapping_one(struct dmar_domain *domain,int translation =CONTEXT_TT_MULTI_LEVEL ;struct dma_pte *pgd = domain->pgd;struct context_entry *context; -int agaw, ret; +int ret;pr_debug ("Set context mapping for %02x:%02x.%d\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn));
@@ -1623,27 +1623,15 @@ static int domain_context_mapping_one(struct dmar_domain *domain,copied_context_tear_down (iommu, context, bus, devfn);context_clear_entry (context); -context_set_domain_id (context, did); -/* -* Skip top levels of page tables for iommu which has -* less agaw than default. Unnecessary for PT mode. -*/ -for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { - ret = -ENOMEM ; - pgd =phys_to_virt (dma_pte_addr (pgd)); -if (!dma_pte_present (pgd)) - goto out_unlock; - } -if (info && info->ats_supported) translation =CONTEXT_TT_DEV_IOTLB ;else translation =CONTEXT_TT_MULTI_LEVEL ;context_set_address_root (context,virt_to_phys (pgd)); -context_set_address_width (context, agaw); +context_set_address_width (context, domain->agaw);context_set_translation_type (context, translation);context_set_fault_enable (context);context_set_present (context);
@@ -1876,20 +1864,9 @@ static int domain_setup_first_level(struct intel_iommu *iommu, u32 pasid) {struct dma_pte *pgd = domain->pgd; -int agaw, level; -int flags =0 ; +int level, flags =0 ; -/* -* Skip top levels of page tables for iommu which has -* less agaw than default. Unnecessary for PT mode. -*/ -for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { - pgd =phys_to_virt (dma_pte_addr (pgd)); -if (!dma_pte_present (pgd)) -return -ENOMEM ; - } - - level =agaw_to_level (agaw); + level =agaw_to_level (domain->agaw);if (level !=4 && level !=5 )return -EINVAL ;
@@ -3494,42 +3471,41 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)domain_exit (dmar_domain); } -int prepare_domain_attach_device (struct iommu_domain *domain, -struct device *dev) +int paging_domain_compatible (struct iommu_domain *domain,struct device *dev) {struct device_domain_info *info =dev_iommu_priv_get (dev);struct dmar_domain *dmar_domain =to_dmar_domain (domain);struct intel_iommu *iommu = info->iommu;int addr_width; +if (WARN_ON_ONCE (!(domain->type & __IOMMU_DOMAIN_PAGING))) +return -EPERM ; +if (dmar_domain->force_snooping && !ecap_sc_support (iommu->ecap))return -EINVAL ;if (domain->dirty_ops && !ssads_supported (iommu))return -EINVAL ; +if (dmar_domain->iommu_coherency != +iommu_paging_structure_coherency (iommu)) +return -EINVAL ; + +if (dmar_domain->iommu_superpage != +iommu_superpage_capability (iommu, dmar_domain->use_first_level)) +return -EINVAL ; + +if (dmar_domain->use_first_level && + (!sm_supported (iommu) || !ecap_flts (iommu->ecap))) +return -EINVAL ; +/* check if this iommu agaw is sufficient for max mapped address */ addr_width =agaw_to_width (iommu->agaw);if (addr_width >cap_mgaw (iommu->cap)) addr_width =cap_mgaw (iommu->cap); -if (dmar_domain->max_addr > (1LL << addr_width)) +if (dmar_domain->gaw > addr_width || dmar_domain->agaw > iommu->agaw)return -EINVAL ; - dmar_domain->gaw = addr_width; - -/* -* Knock out extra levels of page tables if necessary -*/ -while (iommu->agaw < dmar_domain->agaw) { -struct dma_pte *pte; - - pte = dmar_domain->pgd; -if (dma_pte_present (pte)) { - dmar_domain->pgd =phys_to_virt (dma_pte_addr (pte)); -iommu_free_page (pte); - } - dmar_domain->agaw--; - }if (sm_supported (iommu) && !dev_is_real_dma_subdevice (dev) &&context_copied (iommu, info->bus, info->devfn))
@@ -3545,7 +3521,7 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,device_block_translation (dev); - ret =prepare_domain_attach_device (domain, dev); + ret =paging_domain_compatible (domain, dev);if (ret)return ret;
@@ -4216,7 +4192,7 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,if (context_copied (iommu, info->bus, info->devfn))return -EBUSY ; - ret =prepare_domain_attach_device (domain, dev); + ret =paging_domain_compatible (domain, dev);if (ret)return ret;
drivers/iommu/intel/iommu.h +1 -2
@@ -1230,8 +1230,7 @@ void __iommu_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,int domain_attach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu);void domain_detach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu);void device_block_translation (struct device *dev); -int prepare_domain_attach_device (struct iommu_domain *domain, -struct device *dev); +int paging_domain_compatible (struct iommu_domain *domain,struct device *dev);void domain_update_iommu_cap (struct dmar_domain *domain);int dmar_ir_support (void );
drivers/iommu/intel/nested.c +1 -1
@@ -40,7 +40,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,* The s2_domain will be used in nested translation, hence needs * to ensure the s2_domain is compatible with this IOMMU. */ - ret =prepare_domain_attach_device (&dmar_domain->s2_domain->domain, dev); + ret =paging_domain_compatible (&dmar_domain->s2_domain->domain, dev);if (ret) {dev_err_ratelimited (dev,"s2 domain is not compatible\n" );return ret;
drivers/iommu/intel/pasid.c +1 -27
@@ -345,25 +345,6 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,return 0 ; } -/* -* Skip top levels of page tables for iommu which has less agaw -* than default. Unnecessary for PT mode. -*/ -static int iommu_skip_agaw (struct dmar_domain *domain, -struct intel_iommu *iommu, -struct dma_pte **pgd) -{ -int agaw; - -for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { - *pgd =phys_to_virt (dma_pte_addr (*pgd)); -if (!dma_pte_present (*pgd)) -return -EINVAL ; - } - -return agaw; -} -/* * Set up the scalable mode pasid entry for second only translation type. */
@@ -374,7 +355,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,struct pasid_entry *pte;struct dma_pte *pgd;u64 pgd_val; -int agaw;u16 did;/*
@@ -388,12 +368,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, } pgd = domain->pgd; - agaw =iommu_skip_agaw (domain, iommu, &pgd); -if (agaw <0 ) { -dev_err (dev,"Invalid domain page table\n" ); -return -EINVAL ; - } - pgd_val =virt_to_phys (pgd); did =domain_id_iommu (domain, iommu);
@@ -412,7 +386,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,pasid_clear_entry (pte);pasid_set_domain_id (pte, did);pasid_set_slptr (pte, pgd_val); -pasid_set_address_width (pte, agaw); +pasid_set_address_width (pte, domain->agaw);pasid_set_translation_type (pte,PASID_ENTRY_PGTT_SL_ONLY );pasid_set_fault_enable (pte);pasid_set_page_snoop (pte, !!ecap_smpwc (iommu->ecap));
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 4/19 iommu/vt-d: Remove domain_update_iommu_cap()
In reply to Lu BaoluThe attributes of a paging domain are initialized during the allocation process, and any attempt to attach a domain that is not compatible will result in a failure. Therefore, there is no need to update the domain attributes at the time of domain attachment.
--- drivers/iommu/intel/iommu.c | 83 ------------------------------------- drivers/iommu/intel/iommu.h | 1 - 2 files changed, 84 deletions(-)
drivers/iommu/intel/iommu.c +0 -83
@@ -352,36 +352,6 @@ static bool iommu_paging_structure_coherency(struct intel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } -static void domain_update_iommu_coherency (struct dmar_domain *domain) -{ -struct iommu_domain_info *info; -struct dmar_drhd_unit *drhd; -struct intel_iommu *iommu; -bool found = false; -unsigned long i; - - domain->iommu_coherency = true; -xa_for_each (&domain->iommu_array, i, info) { - found = true; -if (!iommu_paging_structure_coherency (info->iommu)) { - domain->iommu_coherency = false; -break ; - } - } -if (found) -return ; - -/* No hardware attached; use lowest common denominator */ -rcu_read_lock (); -for_each_active_iommu (iommu, drhd) { -if (!iommu_paging_structure_coherency (iommu)) { - domain->iommu_coherency = false; -break ; - } - } -rcu_read_unlock (); -} -static int domain_update_iommu_superpage (struct dmar_domain *domain,struct intel_iommu *skip) {
@@ -412,29 +382,6 @@ static int domain_update_iommu_superpage(struct dmar_domain *domain,return fls (mask); } -static int domain_update_device_node (struct dmar_domain *domain) -{ -struct device_domain_info *info; -int nid =NUMA_NO_NODE ; -unsigned long flags; - -spin_lock_irqsave (&domain->lock, flags); -list_for_each_entry (info, &domain->devices, link) { -/* -* There could possibly be multiple device numa nodes as devices -* within the same domain may sit behind different IOMMUs. There -* isn't perfect answer in such situation, so we select first -* come first served policy. -*/ - nid =dev_to_node (info->dev); -if (nid !=NUMA_NO_NODE ) -break ; - } -spin_unlock_irqrestore (&domain->lock, flags); - -return nid; -} -/* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap (struct dmar_domain *domain) {
@@ -452,34 +399,6 @@ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain)return bitmap; } -/* Some capabilities may be different across iommus */ -void domain_update_iommu_cap (struct dmar_domain *domain) -{ -domain_update_iommu_coherency (domain); - domain->iommu_superpage =domain_update_iommu_superpage (domain,NULL ); - -/* -* If RHSA is missing, we should default to the device numa domain -* as fall back. -*/ -if (domain->nid ==NUMA_NO_NODE ) - domain->nid =domain_update_device_node (domain); - -/* -* First-level translation restricts the input-address to a -* canonical address (i.e., address bits 63:N have the same -* value as address bit [N-1], where N is 48-bits with 4-level -* paging and 57-bits with 5-level paging). Hence, skip bit -* [N-1]. -*/ -if (domain->use_first_level) - domain->domain.geometry.aperture_end =__DOMAIN_MAX_ADDR (domain->gaw -1 ); -else - domain->domain.geometry.aperture_end =__DOMAIN_MAX_ADDR (domain->gaw); - - domain->domain.pgsize_bitmap |=domain_super_pgsize_bitmap (domain); -} -struct context_entry *iommu_context_addr (struct intel_iommu *iommu,u8 bus,u8 devfn,int alloc) {
@@ -1493,7 +1412,6 @@ int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) ret =xa_err (curr) ? : -EBUSY ; goto err_clear; } -domain_update_iommu_cap (domain);spin_unlock (&iommu->lock);return 0 ;
@@ -1519,7 +1437,6 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)clear_bit (info->did, iommu->domain_ids);xa_erase (&domain->iommu_array, iommu->seq_id); domain->nid =NUMA_NO_NODE ; -domain_update_iommu_cap (domain);kfree (info); }spin_unlock (&iommu->lock);
drivers/iommu/intel/iommu.h +0 -1
@@ -1231,7 +1231,6 @@ int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu);void domain_detach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu);void device_block_translation (struct device *dev);int paging_domain_compatible (struct iommu_domain *domain,struct device *dev); -void domain_update_iommu_cap (struct dmar_domain *domain);int dmar_ir_support (void );
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 5/19 iommu/vt-d: Remove domain_update_iommu_superpage()
In reply to Lu BaoluThe requirement for consistent super page support across all the IOMMU hardware in the system has been removed. In the past, if a new IOMMU was hot-added and lacked consistent super page capability, the hot-add process would be aborted. However, with the updated attachment semantics, it is now permissible for the super page capability to vary among different IOMMU hardware units.
--- drivers/iommu/intel/iommu.c | 39 +------------------------------------ 1 file changed, 1 insertion(+), 38 deletions(-)
drivers/iommu/intel/iommu.c +1 -38
@@ -352,36 +352,6 @@ static bool iommu_paging_structure_coherency(struct intel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } -static int domain_update_iommu_superpage (struct dmar_domain *domain, -struct intel_iommu *skip) -{ -struct dmar_drhd_unit *drhd; -struct intel_iommu *iommu; -int mask =0x3 ; - -if (!intel_iommu_superpage) -return 0 ; - -/* set iommu_superpage to the smallest common denominator */ -rcu_read_lock (); -for_each_active_iommu (iommu, drhd) { -if (iommu != skip) { -if (domain && domain->use_first_level) { -if (!cap_fl1gp_support (iommu->cap)) - mask =0x1 ; - }else { - mask &=cap_super_page_val (iommu->cap); - } - -if (!mask) -break ; - } - } -rcu_read_unlock (); - -return fls (mask); -} -/* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap (struct dmar_domain *domain) {
@@ -2605,20 +2575,13 @@ int dmar_parse_one_satc(struct acpi_dmar_header *hdr, void *arg)static int intel_iommu_add (struct dmar_drhd_unit *dmaru) { -int sp, ret;struct intel_iommu *iommu = dmaru->iommu; +int ret; ret =intel_cap_audit (CAP_AUDIT_HOTPLUG_DMAR , iommu);if (ret) goto out; - sp =domain_update_iommu_superpage (NULL , iommu) -1 ; -if (sp >=0 && !(cap_super_page_val (iommu->cap) & (1 << sp))) { -pr_warn ("%s: Doesn't support large page.\n" , - iommu->name); -return -ENXIO ; - } -/* * Disable translation if already enabled prior to OS handover. */
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 6/19 iommu/vt-d: Refactor first_level_by_default()
In reply to Lu BaoluThe first stage page table is compatible across host and guest kernels. Therefore, this driver uses the first stage page table as the default for paging domains.
The helper first_level_by_default() determines the feasibility of using the first stage page table based on a global policy. This policy requires consistency in scalable mode and first stage translation capability among all iommu units. However, this is unnecessary as domain allocation, attachment, and removal operations are performed on a per-device basis.
The domain type (IOMMU_DOMAIN_DMA vs. IOMMU_DOMAIN_UNMANAGED) should not be a factor in determining the first stage page table usage. Both types are for paging domains, and there's no fundamental difference between them. The driver should not be aware of this distinction unless the core specifies allocation flags that require special handling.
Convert first_level_by_default() from global to per-iommu and remove the 'type' input.
--- drivers/iommu/intel/iommu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/iommu/intel/iommu.c +9 -8
@@ -1329,18 +1329,17 @@ static void free_dmar_iommu(struct intel_iommu *iommu)* Check and return whether first level is used by default for * DMA translation. */ -static bool first_level_by_default (unsigned int type) +static bool first_level_by_default (struct intel_iommu *iommu) {/* Only SL is available in legacy mode */ -if (!scalable_mode_support ()) +if (!sm_supported (iommu))return false;/* Only level (either FL or SL) is available, just use it */ -if (intel_cap_flts_sanity () ^intel_cap_slts_sanity ()) -return intel_cap_flts_sanity (); +if (ecap_flts (iommu->ecap) ^ecap_slts (iommu->ecap)) +return ecap_flts (iommu->ecap); -/* Both levels are available, decide it based on domain type */ -return type !=IOMMU_DOMAIN_UNMANAGED ; +return true; }int domain_attach_iommu (struct dmar_domain *domain,struct intel_iommu *iommu)
@@ -3110,7 +3109,7 @@ int __init intel_iommu_init(void)* the virtual and physical IOMMU page-tables. */ if (cap_caching_mode (iommu->cap) && - !first_level_by_default (IOMMU_DOMAIN_DMA )) { + !first_level_by_default (iommu)) {pr_info_once ("IOMMU batching disallowed due to virtualization\n" );iommu_set_dma_strict (); }
@@ -4361,10 +4360,12 @@ static struct iommu_domain identity_domain = {static struct iommu_domain *intel_iommu_domain_alloc_paging (struct device *dev) { +struct device_domain_info *info =dev_iommu_priv_get (dev); +struct intel_iommu *iommu = info->iommu;struct dmar_domain *dmar_domain;bool first_stage; - first_stage =first_level_by_default (0 ); + first_stage =first_level_by_default (iommu); dmar_domain =paging_domain_alloc (dev, first_stage);if (IS_ERR (dmar_domain))return ERR_CAST (dmar_domain);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 7/19 iommu/vt-d: Refine intel_iommu_domain_alloc_user()
In reply to Lu BaoluThe domain_alloc_user ops should always allocate a guest-compatible page table unless specific allocation flags are specified.
Currently, IOMMU_HWPT_ALLOC_NEST_PARENT and IOMMU_HWPT_ALLOC_DIRTY_TRACKING require special handling, as both require hardware support for scalable mode and second-stage translation. In such cases, the driver should select a second-stage page table for the paging domain.
--- drivers/iommu/intel/iommu.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +15 -2
@@ -3299,6 +3299,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,struct intel_iommu *iommu = info->iommu;struct dmar_domain *dmar_domain;struct iommu_domain *domain; +bool first_stage;/* Must be NESTING domain */ if (parent) {
@@ -3315,8 +3316,20 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,if (user_data || (dirty_tracking && !ssads_supported (iommu)))return ERR_PTR (-EOPNOTSUPP ); -/* Do not use first stage for user domain translation. */ - dmar_domain =paging_domain_alloc (dev, false); +/* +* Always allocate the guest compatible page table unless +* IOMMU_HWPT_ALLOC_NEST_PARENT or IOMMU_HWPT_ALLOC_DIRTY_TRACKING +* is specified. +*/ +if (nested_parent || dirty_tracking) { +if (!sm_supported (iommu) || !ecap_slts (iommu->ecap)) +return ERR_PTR (-EOPNOTSUPP ); + first_stage = false; + }else { + first_stage =first_level_by_default (iommu); + } + + dmar_domain =paging_domain_alloc (dev, first_stage);if (IS_ERR (dmar_domain))return ERR_CAST (dmar_domain); domain = &dmar_domain->domain;
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 8/19 iommu/vt-d: Use PCI_DEVID() macro
In reply to Lu BaoluFrom: Jinjie Ruan <[email protected]>
The macro PCI_DEVID() can be used instead of compose it manually.
--- drivers/iommu/intel/iommu.c | 4 ++-- drivers/iommu/intel/irq_remapping.c | 4 ++-- drivers/iommu/intel/pasid.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -1452,7 +1452,7 @@ static void copied_context_tear_down(struct intel_iommu *iommu,if (did_old <cap_ndoms (iommu->cap)) { iommu->flush.flush_context (iommu, did_old, - (((u16 )bus) <<8 ) | devfn, +PCI_DEVID (bus, devfn),DMA_CCMD_MASK_NOBIT ,DMA_CCMD_DEVICE_INVL ); iommu->flush.flush_iotlb(iommu, did_old, 0, 0,
@@ -1473,7 +1473,7 @@ static void context_present_cache_flush(struct intel_iommu *iommu, u16 did, {if (cap_caching_mode (iommu->cap)) { iommu->flush.flush_context (iommu,0 , - (((u16 )bus) <<8 ) | devfn, +PCI_DEVID (bus, devfn),DMA_CCMD_MASK_NOBIT ,DMA_CCMD_DEVICE_INVL ); iommu->flush.flush_iotlb (iommu, did,0 ,0 ,DMA_TLB_DSI_FLUSH );
drivers/iommu/intel/irq_remapping.c +2 -2
@@ -312,7 +312,7 @@ static int set_ioapic_sid(struct irte *irte, int apic)for (i =0 ; i <MAX_IO_APICS ; i++) {if (ir_ioapic[i].iommu && ir_ioapic[i].id == apic) { - sid = (ir_ioapic[i].bus <<8 ) | ir_ioapic[i].devfn; + sid =PCI_DEVID (ir_ioapic[i].bus, ir_ioapic[i].devfn);break ; } }
@@ -337,7 +337,7 @@ static int set_hpet_sid(struct irte *irte, u8 id)for (i =0 ; i <MAX_HPET_TBS ; i++) {if (ir_hpet[i].iommu && ir_hpet[i].id == id) { - sid = (ir_hpet[i].bus <<8 ) | ir_hpet[i].devfn; + sid =PCI_DEVID (ir_hpet[i].bus, ir_hpet[i].devfn);break ; } }
drivers/iommu/intel/pasid.c +1 -1
@@ -220,7 +220,7 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iommu,if (pci_dev_is_disconnected (to_pci_dev (dev)))return ; - sid = info->bus <<8 | info->devfn; + sid =PCI_DEVID (info->bus, info->devfn); qdep = info->ats_qdep; pfsid = info->pfsid;
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 9/19 iommu/vt-d: Increase buffer size for device name
In reply to Lu BaoluFrom: Andy Shevchenko <[email protected]>
GCC is not happy with the current code, e.g.:
.../iommu/intel/dmar.c:1063:9: note: ‘sprintf’ output between 6 and 15 bytes into a destination of size 13
1063 | sprintf(iommu->name, "dmar%d", iommu->seq_id);
When make W=1 is supplied, this prevents kernel building. Fix it by increasing the buffer size for device name and use sizeoF() instead of hard coded constants.
--- drivers/iommu/intel/dmar.c | 2 +- drivers/iommu/intel/iommu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/dmar.c +1 -1
@@ -1060,7 +1060,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) err = iommu->seq_id; goto error; } -sprintf (iommu->name,"dmar%d" , iommu->seq_id); +snprintf (iommu->name,sizeof (iommu->name),"dmar%d" , iommu->seq_id); err =map_iommu (iommu, drhd);if (err) {
drivers/iommu/intel/iommu.h +1 -1
@@ -720,7 +720,7 @@ struct intel_iommu {int msagaw;/* max sagaw of this iommu */ unsigned int irq, pr_irq, perf_irq;u16 segment;/* PCI segment# */ -unsigned char name[13 ];/* Device Name */ +unsigned char name[16 ];/* Device Name */ #ifdef CONFIG_INTEL_IOMMU unsigned long *domain_ids;/* bitmap of domains */
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 10/19 iommu/vt-d: Remove unused dmar_msi_read
In reply to Lu BaoluFrom: "Dr. David Alan Gilbert" <[email protected]>
dmar_msi_read() has been unused since 2022 in
commit cf8e8658100d ("arch: Remove Itanium (IA-64) architecture")
Remove it.
(dmar_msi_write still exists and is used once).
--- drivers/iommu/intel/dmar.c | 13 ------------- include/linux/dmar.h | 1 - 2 files changed, 14 deletions(-)
drivers/iommu/intel/dmar.c +0 -13
@@ -1895,19 +1895,6 @@ void dmar_msi_write(int irq, struct msi_msg *msg)raw_spin_unlock_irqrestore (&iommu->register_lock, flag); } -void dmar_msi_read (int irq,struct msi_msg *msg) -{ -struct intel_iommu *iommu =irq_get_handler_data (irq); -int reg =dmar_msi_reg (iommu, irq); -unsigned long flag; - -raw_spin_lock_irqsave (&iommu->register_lock, flag); - msg->data =readl (iommu->reg + reg +4 ); - msg->address_lo =readl (iommu->reg + reg +8 ); - msg->address_hi =readl (iommu->reg + reg +12 ); -raw_spin_unlock_irqrestore (&iommu->register_lock, flag); -} -static int dmar_fault_do_one (struct intel_iommu *iommu,int type,u8 fault_reason,u32 pasid,u16 source_id,unsigned long long addr)
include/linux/dmar.h +0 -1
@@ -292,7 +292,6 @@ static inline void dmar_copy_shared_irte(struct irte *dst, struct irte *src)struct irq_data ;extern void dmar_msi_unmask (struct irq_data *data);extern void dmar_msi_mask (struct irq_data *data); -extern void dmar_msi_read (int irq,struct msi_msg *msg);extern void dmar_msi_write (int irq,struct msi_msg *msg);extern int dmar_set_interrupt (struct intel_iommu *iommu);extern irqreturn_t dmar_fault (int irq,void *dev_id);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 11/19 iommu/vt-d: Drop s1_pgtbl from dmar_domain
In reply to Lu BaoluFrom: Yi Liu <[email protected]>
dmar_domian has stored the s1_cfg which includes the s1_pgtbl info, so no need to store s1_pgtbl, hence drop it.
--- drivers/iommu/intel/iommu.h | 2 -- drivers/iommu/intel/nested.c | 1 - drivers/iommu/intel/pasid.c | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/iommu/intel/iommu.h +0 -2
@@ -653,8 +653,6 @@ struct dmar_domain {struct {/* parent page table which the user domain is nested on */ struct dmar_domain *s2_domain; -/* user page table pointer (in GPA) */ -unsigned long s1_pgtbl;/* page table attributes */ struct iommu_hwpt_vtd_s1 s1_cfg;/* link to parent domain siblings */
drivers/iommu/intel/nested.c +0 -1
@@ -162,7 +162,6 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, domain->use_first_level = true; domain->s2_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 ;
drivers/iommu/intel/pasid.c +1 -2
@@ -560,7 +560,6 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, u32 pasid, struct dmar_domain *domain) { struct iommu_hwpt_vtd_s1 *s1_cfg = &domain->s1_cfg; -pgd_t *s1_gpgd = (pgd_t *)(uintptr_t )domain->s1_pgtbl;struct dmar_domain *s2_domain = domain->s2_domain;u16 did =domain_id_iommu (domain, iommu);struct dma_pte *pgd = s2_domain->pgd;
@@ -611,7 +610,7 @@ int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,if (s1_cfg->addr_width ==ADDR_WIDTH_5LEVEL )pasid_set_flpm (pte,1 ); -pasid_set_flptr (pte, (uintptr_t )s1_gpgd); +pasid_set_flptr (pte, s1_cfg->pgtbl_addr);if (s1_cfg->flags &IOMMU_VTD_S1_SRE ) {pasid_set_sre (pte);
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 12/19 iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes()
In reply to Lu BaoluFrom: Zhenzhong Duan <[email protected]>
There are some issues in dmar_fault_dump_ptes():
1. return value of phys_to_virt() is used for checking if an entry is present.
2. dump is confusing, e.g., "pasid table entry is not present", confusing by unpresent pasid table vs. unpresent pasid table entry. Current code means the former.
3. pgtable_walk() is called without checking if page table is present.
Fix 1 by checking present bit of an entry before dump a lower level entry. Fix 2 by removing "entry" string, e.g., "pasid table is not present". Fix 3 by checking page table present before walk.
Take issue 3 for example, before fix:
[ 442.240357] DMAR: pasid dir entry: 0x000000012c83e001 [ 442.246661] DMAR: pasid table entry[0]: 0x0000000000000000 [ 442.253429] DMAR: pasid table entry[1]: 0x0000000000000000 [ 442.260203] DMAR: pasid table entry[2]: 0x0000000000000000 [ 442.266969] DMAR: pasid table entry[3]: 0x0000000000000000 [ 442.273733] DMAR: pasid table entry[4]: 0x0000000000000000 [ 442.280479] DMAR: pasid table entry[5]: 0x0000000000000000 [ 442.287234] DMAR: pasid table entry[6]: 0x0000000000000000 [ 442.293989] DMAR: pasid table entry[7]: 0x0000000000000000 [ 442.300742] DMAR: PTE not present at level 2
After fix:
...
[ 357.241214] DMAR: pasid table entry[6]: 0x0000000000000000 [ 357.248022] DMAR: pasid table entry[7]: 0x0000000000000000 [ 357.254824] DMAR: scalable mode page table is not present
--- drivers/iommu/intel/iommu.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
drivers/iommu/intel/iommu.c +21 -10
@@ -626,11 +626,11 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,pr_info ("Dump %s table entries for IOVA 0x%llx\n" , iommu->name, addr);/* root entry dump */ +if (!iommu->root_entry) { +pr_info ("root table is not present\n" ); +return ; + } rt_entry = &iommu->root_entry[bus]; -if (!rt_entry) { -pr_info ("root table entry is not present\n" ); -return ; - }if (sm_supported (iommu)) pr_info("scalable mode root entry: hi 0x%016llx, low 0x%016llx\n",
@@ -641,7 +641,7 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,/* context entry dump */ ctx_entry =iommu_context_addr (iommu, bus, devfn,0 );if (!ctx_entry) { -pr_info ("context table entry is not present\n" ); +pr_info ("context table is not present\n" );return ; }
@@ -650,17 +650,23 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,/* legacy mode does not require PASID entries */ if (!sm_supported (iommu)) { +if (!context_present (ctx_entry)) { +pr_info ("legacy mode page table is not present\n" ); +return ; + } level =agaw_to_level (ctx_entry->hi &7 ); pgtable =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK ); goto pgtable_walk; } +if (!context_present (ctx_entry)) { +pr_info ("pasid directory table is not present\n" ); +return ; + } +/* get the pointer to pasid directory entry */ dir =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK ); -if (!dir) { -pr_info ("pasid directory entry is not present\n" ); -return ; - } +/* For request-without-pasid, get the pasid from context entry */ if (intel_iommu_sm && pasid ==IOMMU_PASID_INVALID ) pasid =IOMMU_NO_PASID ;
@@ -672,7 +678,7 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,/* get the pointer to the pasid table entry */ entries =get_pasid_table_from_pde (pde);if (!entries) { -pr_info ("pasid table entry is not present\n" ); +pr_info ("pasid table is not present\n" );return ; } index = pasid &PASID_PTE_MASK ;
@@ -680,6 +686,11 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,for (i =0 ; i <ARRAY_SIZE (pte->val); i++)pr_info ("pasid table entry[%d]: 0x%016llx\n" , i, pte->val[i]); +if (!pasid_pte_is_present (pte)) { +pr_info ("scalable mode page table is not present\n" ); +return ; + } +if (pasid_pte_get_pgtt (pte) ==PASID_ENTRY_PGTT_FL_ONLY ) { level = pte->val[2 ] &BIT_ULL (2 ) ?5 :4 ; pgtable =phys_to_virt (pte->val[2 ] &VTD_PAGE_MASK );
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 13/19 iommu/vt-d: Fix checks and print in pgtable_walk()
In reply to Lu BaoluFrom: Zhenzhong Duan <[email protected]>
There are some issues in pgtable_walk():
1. Super page is dumped as non-present page
2. dma_pte_superpage() should not check against leaf page table entries
3. Pointer pte is never NULL so checking it is meaningless
4. When an entry is not present, it still makes sense to dump the entry content.
Fix 1,2 by checking dma_pte_superpage()'s returned value after level check. Fix 3 by removing pte check.
Fix 4 by checking present bit after printing.
By this chance, change to print "page table not present" instead of "PTE not present" to be clearer.
--- drivers/iommu/intel/iommu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/iommu/intel/iommu.c +6 -5
@@ -596,14 +596,15 @@ static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn,while (1 ) { offset =pfn_level_offset (pfn, level); pte = &parent[offset]; -if (!pte || (dma_pte_superpage (pte) || !dma_pte_present (pte))) { -pr_info ("PTE not present at level %d\n" , level); -break ; - }pr_info ("pte level: %d, pte value: 0x%016llx\n" , level, pte->val); -if (level ==1 ) +if (!dma_pte_present (pte)) { +pr_info ("page table not present at level %d\n" , level -1 ); +break ; + } + +if (level ==1 ||dma_pte_superpage (pte))break ; parent =phys_to_virt (dma_pte_addr (pte));
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 14/19 iommu/vt-d: Separate page request queue from SVM
In reply to Lu BaoluFrom: Joel Granados <[email protected]>
IO page faults are no longer dependent on CONFIG_INTEL_IOMMU_SVM. Move all Page Request Queue (PRQ) functions that handle prq events to a new file in drivers/iommu/intel/prq.c. The page_req_des struct is now declared in drivers/iommu/intel/prq.c.
No functional changes are intended. This is a preparation patch to enable the use of IO page faults outside the SVM/PASID use cases.
--- drivers/iommu/intel/Makefile | 2 +- drivers/iommu/intel/iommu.c | 20 +- drivers/iommu/intel/iommu.h | 14 +- drivers/iommu/intel/prq.c | 410 +++++++++++++++++++++++++++++++++++ drivers/iommu/intel/svm.c | 397 --------------------------------- 5 files changed, 424 insertions(+), 419 deletions(-) create mode 100644 drivers/iommu/intel/prq.c
drivers/iommu/intel/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DMAR_TABLE) += dmar.o -obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o nested.o cache.o +obj-$(CONFIG_INTEL_IOMMU) += iommu.o pasid.o nested.o cache.o prq.o obj-$(CONFIG_DMAR_TABLE) += trace.o cap_audit.o obj-$(CONFIG_DMAR_PERF) += perf.o obj-$(CONFIG_INTEL_IOMMU_DEBUGFS) += debugfs.o
drivers/iommu/intel/iommu.c +7 -13
@@ -1329,12 +1329,10 @@ static void free_dmar_iommu(struct intel_iommu *iommu)/* free context mapping */ free_context_table (iommu); -#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_supported (iommu)) {if (ecap_prs (iommu->ecap)) -intel_svm_finish_prq (iommu); +intel_iommu_finish_prq (iommu); } -#endif }/*
@@ -2194,19 +2192,18 @@ static int __init init_dmars(void)iommu_flush_write_buffer (iommu); -#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_supported (iommu) &&ecap_prs (iommu->ecap)) {/* * Call dmar_alloc_hwirq() with dmar_global_lock held, * could cause possible lock race condition. */ up_write (&dmar_global_lock); - ret =intel_svm_enable_prq (iommu); + ret =intel_iommu_enable_prq (iommu);down_write (&dmar_global_lock);if (ret) goto free_iommu; } -#endif + ret =dmar_set_interrupt (iommu);if (ret) goto free_iommu;
@@ -2619,13 +2616,12 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)intel_iommu_init_qi (iommu);iommu_flush_write_buffer (iommu); -#ifdef CONFIG_INTEL_IOMMU_SVM if (pasid_supported (iommu) &&ecap_prs (iommu->ecap)) { - ret =intel_svm_enable_prq (iommu); + ret =intel_iommu_enable_prq (iommu);if (ret) goto disable_iommu; } -#endif + ret =dmar_set_interrupt (iommu);if (ret) goto disable_iommu;
@@ -4074,7 +4070,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,intel_iommu_debugfs_remove_dev_pasid (dev_pasid);kfree (dev_pasid);intel_pasid_tear_down_entry (iommu, dev, pasid, false); -intel_drain_pasid_prq (dev, pasid); +intel_iommu_drain_pasid_prq (dev, pasid); } static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
@@ -4417,9 +4413,7 @@ const struct iommu_ops intel_iommu_ops = { .def_domain_type = device_def_domain_type, .remove_dev_pasid = intel_iommu_remove_dev_pasid, .pgsize_bitmap = SZ_4K, -#ifdef CONFIG_INTEL_IOMMU_SVM - .page_response = intel_svm_page_response, -#endif + .page_response = intel_iommu_page_response, .default_domain_ops = &(const struct iommu_domain_ops ) { .attach_dev = intel_iommu_attach_device, .set_dev_pasid = intel_iommu_set_dev_pasid,
drivers/iommu/intel/iommu.h +6 -8
@@ -728,12 +728,10 @@ struct intel_iommu {struct iommu_flush flush;#endif -#ifdef CONFIG_INTEL_IOMMU_SVM struct page_req_dsc *prq;unsigned char prq_name[16 ];/* Name for PRQ interrupt */ unsigned long prq_seq_number;struct completion prq_complete; -#endif struct iopf_queue *iopf_queue;unsigned char iopfq_name[16 ];/* Synchronization between fault report and iommu device release. */
@@ -1274,18 +1272,18 @@ void intel_context_flush_present(struct device_domain_info *info,struct context_entry *context, u16 did, bool affect_domains); +int intel_iommu_enable_prq (struct intel_iommu *iommu); +int intel_iommu_finish_prq (struct intel_iommu *iommu); +void intel_iommu_page_response (struct device *dev,struct iopf_fault *evt, +struct iommu_page_response *msg); +void intel_iommu_drain_pasid_prq (struct device *dev,u32 pasid); +#ifdef CONFIG_INTEL_IOMMU_SVM void intel_svm_check (struct intel_iommu *iommu); -int intel_svm_enable_prq (struct intel_iommu *iommu); -int intel_svm_finish_prq (struct intel_iommu *iommu); -void intel_svm_page_response (struct device *dev,struct iopf_fault *evt, -struct iommu_page_response *msg);struct iommu_domain *intel_svm_domain_alloc (struct device *dev,struct mm_struct *mm); -void intel_drain_pasid_prq (struct device *dev,u32 pasid);#else static inline void intel_svm_check (struct intel_iommu *iommu) {} -static inline void intel_drain_pasid_prq (struct device *dev,u32 pasid) {}static inline struct iommu_domain *intel_svm_domain_alloc (struct device *dev,struct mm_struct *mm) {
drivers/iommu/intel/prq.c new file +410 -0
410 lines not on this page · raw message
drivers/iommu/intel/svm.c +0 -397
409 lines not on this page · raw message
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 15/19 iommu/vt-d: Remove the pasid present check in prq_event_thread
In reply to Lu BaoluFrom: Klaus Jensen <[email protected]>
PASID is not strictly needed when handling a PRQ event; remove the check for the pasid present bit in the request. This change was not included in the creation of prq.c to emphasize the change in capability checks when handing PRQ events.
--- drivers/iommu/intel/prq.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iommu/intel/prq.c +3 -9
@@ -222,18 +222,12 @@ static irqreturn_t prq_event_thread(int irq, void *d) req = &iommu->prq[head /sizeof (*req)]; address = (u64 )req->addr <<VTD_PAGE_SHIFT ; -if (unlikely (!req->pasid_present)) { -pr_err ("IOMMU: %s: Page request without PASID\n" , - iommu->name); -bad_req: -handle_bad_prq_event (iommu, req,QI_RESP_INVALID ); - goto prq_advance; - } -if (unlikely (!is_canonical_address (address))) {pr_err ("IOMMU: %s: Address is not canonical\n" , iommu->name); - goto bad_req; +bad_req: +handle_bad_prq_event (iommu, req,QI_RESP_INVALID ); + goto prq_advance; }if (unlikely (req->pm_req && (req->rd_req | req->wr_req))) {
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 16/19 iommu/vt-d: Move IOMMU_IOPF into INTEL_IOMMU
In reply to Lu BaoluFrom: Joel Granados <[email protected]>
Move IOMMU_IOPF from under INTEL_IOMMU_SVM into INTEL_IOMMU. This certifies that the core intel iommu utilizes the IOPF library functions, independent of the INTEL_IOMMU_SVM config.
--- drivers/iommu/intel/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/Kconfig +1 -1
@@ -14,6 +14,7 @@ config INTEL_IOMMU depends on PCI_MSI && ACPI && X86 select IOMMU_API select IOMMU_IOVA + select IOMMU_IOPF select IOMMUFD_DRIVER if IOMMUFD select NEED_DMA_MAP_STATE select DMAR_TABLE
@@ -50,7 +51,6 @@ config INTEL_IOMMU_SVM depends on X86_64 select MMU_NOTIFIER select IOMMU_SVA - select IOMMU_IOPF help Shared Virtual Memory (SVM) provides a facility for devices to access DMA resources through process address space by
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 17/19 iommufd: Enable PRI when doing the iommufd_hwpt_alloc
In reply to Lu BaoluFrom: Joel Granados <[email protected]>
Add IOMMU_HWPT_FAULT_ID_VALID as part of the valid flags when doing an iommufd_hwpt_alloc allowing the use of an iommu fault allocation (iommu_fault_alloc) with the IOMMU_HWPT_ALLOC ioctl.
--- drivers/iommu/intel/iommu.c | 3 ++- drivers/iommu/iommufd/hw_pagetable.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -1
@@ -3317,7 +3317,8 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, }if (flags & - (~(IOMMU_HWPT_ALLOC_NEST_PARENT |IOMMU_HWPT_ALLOC_DIRTY_TRACKING ))) + (~(IOMMU_HWPT_ALLOC_NEST_PARENT |IOMMU_HWPT_ALLOC_DIRTY_TRACKING + |IOMMU_HWPT_FAULT_ID_VALID )))return ERR_PTR (-EOPNOTSUPP );if (nested_parent && !nested_supported (iommu))return ERR_PTR (-EOPNOTSUPP );
drivers/iommu/iommufd/hw_pagetable.c +2 -1
@@ -107,7 +107,8 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, const struct iommu_user_data *user_data) {const u32 valid_flags =IOMMU_HWPT_ALLOC_NEST_PARENT | -IOMMU_HWPT_ALLOC_DIRTY_TRACKING ; +IOMMU_HWPT_ALLOC_DIRTY_TRACKING | +IOMMU_HWPT_FAULT_ID_VALID ;const struct iommu_ops *ops =dev_iommu_ops (idev->dev);struct iommufd_hwpt_paging *hwpt_paging;struct iommufd_hw_pagetable *hwpt;
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 18/19 iommu/vt-d: Drop pasid requirement for prq initialization
In reply to Lu BaoluFrom: Klaus Jensen <[email protected]>
PASID support within the IOMMU is not required to enable the Page Request Queue, only the PRS capability.
--- drivers/iommu/intel/iommu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iommu/intel/iommu.c +4 -6
@@ -1329,10 +1329,8 @@ static void free_dmar_iommu(struct intel_iommu *iommu)/* free context mapping */ free_context_table (iommu); -if (pasid_supported (iommu)) { -if (ecap_prs (iommu->ecap)) -intel_iommu_finish_prq (iommu); - } +if (ecap_prs (iommu->ecap)) +intel_iommu_finish_prq (iommu); }/*
@@ -2192,7 +2190,7 @@ static int __init init_dmars(void)iommu_flush_write_buffer (iommu); -if (pasid_supported (iommu) &&ecap_prs (iommu->ecap)) { +if (ecap_prs (iommu->ecap)) {/* * Call dmar_alloc_hwirq() with dmar_global_lock held, * could cause possible lock race condition.
@@ -2616,7 +2614,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru)intel_iommu_init_qi (iommu);iommu_flush_write_buffer (iommu); -if (pasid_supported (iommu) &&ecap_prs (iommu->ecap)) { +if (ecap_prs (iommu->ecap)) { ret =intel_iommu_enable_prq (iommu);if (ret) goto disable_iommu;
Signature · 1 line
2.43.0
Lu Baolu
maintainerPATCH 19/19 iommu/vt-d: Drain PRQs when domain removed from RID
In reply to Lu BaoluAs this iommu driver now supports page faults for requests without PASID, page requests should be drained when a domain is removed from the RID2PASID entry.
This results in the intel_iommu_drain_pasid_prq() call being moved to intel_pasid_tear_down_entry(). This indicates that when a translation is removed from any PASID entry and the PRI has been enabled on the device, page requests are drained in the domain detachment path.
The intel_iommu_drain_pasid_prq() helper has been modified to support sending device TLB invalidation requests for both PASID and non-PASID cases.
--- drivers/iommu/intel/iommu.c | 1 - drivers/iommu/intel/pasid.c | 1 + drivers/iommu/intel/prq.c | 26 +++++++++----------------- 3 files changed, 10 insertions(+), 18 deletions(-)
drivers/iommu/intel/iommu.c +0 -1
@@ -4069,7 +4069,6 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,intel_iommu_debugfs_remove_dev_pasid (dev_pasid);kfree (dev_pasid);intel_pasid_tear_down_entry (iommu, dev, pasid, false); -intel_iommu_drain_pasid_prq (dev, pasid); } static int intel_iommu_set_dev_pasid(struct iommu_domain *domain,
drivers/iommu/intel/pasid.c +1 -0
@@ -265,6 +265,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev, iommu->flush.flush_iotlb (iommu, did,0 ,0 ,DMA_TLB_DSI_FLUSH );devtlb_invalidation_with_pasid (iommu, dev, pasid); +intel_iommu_drain_pasid_prq (dev, pasid); }/*
drivers/iommu/intel/prq.c +9 -17
@@ -63,26 +63,18 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)struct dmar_domain *domain;struct intel_iommu *iommu;struct qi_desc desc[3 ]; -struct pci_dev *pdev;int head, tail;u16 sid, did; -int qdep; info =dev_iommu_priv_get (dev); -if (WARN_ON (!info || !dev_is_pci (dev))) -return ; -if (!info->pri_enabled)return ; iommu = info->iommu; domain = info->domain; - pdev =to_pci_dev (dev); sid =PCI_DEVID (info->bus, info->devfn); did = domain ?domain_id_iommu (domain, iommu) :FLPT_DEFAULT_DID ; - qdep =pci_ats_queue_depth (pdev); -/* * Check and wait until all pending page requests in the queue are * handled by the prq handling thread.
@@ -114,15 +106,15 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid) desc[0 ].qw0 =QI_IWD_STATUS_DATA (QI_DONE ) |QI_IWD_FENCE |QI_IWD_TYPE ; - desc[1 ].qw0 =QI_EIOTLB_PASID (pasid) | -QI_EIOTLB_DID (did) | -QI_EIOTLB_GRAN (QI_GRAN_NONG_PASID ) | -QI_EIOTLB_TYPE ; - desc[2 ].qw0 =QI_DEV_EIOTLB_PASID (pasid) | -QI_DEV_EIOTLB_SID (sid) | -QI_DEV_EIOTLB_QDEP (qdep) | -QI_DEIOTLB_TYPE | -QI_DEV_IOTLB_PFSID (info->pfsid); +if (pasid ==IOMMU_NO_PASID ) { +qi_desc_iotlb (iommu, did,0 ,0 ,DMA_TLB_DSI_FLUSH , &desc[1 ]); +qi_desc_dev_iotlb (sid, info->pfsid, info->ats_qdep,0 , +MAX_AGAW_PFN_WIDTH , &desc[2 ]); + }else { +qi_desc_piotlb (did, pasid,0 ,-1 ,0 , &desc[1 ]); +qi_desc_dev_iotlb_pasid (sid, info->pfsid, pasid, info->ats_qdep, +0 ,MAX_AGAW_PFN_WIDTH , &desc[2 ]); + } qi_retry:reinit_completion (&iommu->prq_complete);qi_submit_sync (iommu, desc,3 ,QI_OPT_WAIT_DRAIN );
Signature · 1 line
2.43.0
Quoted 28 lines · Lu Baolu
Andy Shevchenko (1):
iommu/vt-d: Increase buffer size for device nameDr. David Alan Gilbert (1):
iommu/vt-d: Remove unuseddmar_msi_readJinjie Ruan (1):
iommu/vt-d: UsePCI_DEVID()macroJoel Granados (3):
iommu/vt-d: Separate page request queue from SVM iommu/vt-d: MoveIOMMU_IOPFintoINTEL_IOMMU
iommufd: Enable PRI when doing theiommufd_hwpt_allocKlaus Jensen (2):
iommu/vt-d: Remove the pasid present check inprq_event_threadiommu/vt-d: Drop pasid requirement for prq initializationLu Baolu (8):
iommu/vt-d: Adddomain_alloc_pagingsupport iommu/vt-d: Remove unuseddomain_alloccallback iommu/vt-d: Enhance compatibility check for paging domain attach iommu/vt-d: Removedomain_update_iommu_cap()iommu/vt-d: Removedomain_update_iommu_superpage()iommu/vt-d: Refactorfirst_level_by_default()iommu/vt-d: Refineintel_iommu_domain_alloc_user()iommu/vt-d: Drain PRQs when domain removed from RID
Quoted 6 lines
Yi Liu (1):
iommu/vt-d: Drops1_pgtblfromdmar_domainZhenzhong Duan (2):
iommu/vt-d: Fix checks and print indmar_fault_dump_ptes()iommu/vt-d: Fix checks and print inpgtable_walk()
Applied, thanks Baolu.