iommu/vt-d:Add support for ACPI device in RMRR
Subsystems (2)
PATCH 1/1 iommu/vt-d:Add support for ACPI device in RMRR
Some ACPI devices require access to the specified reserved memory region.BIOS report the specified reserved memory region through RMRR structures.Add analysis of ACPI device in RMRR and establish identity mapping for ACPI device.
--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 47 ++++++++++++++++++++++- drivers/iommu/iommu.c | 5 +++ include/linux/dmar.h | 12 ++++-- include/linux/iommu.h | 3 ++ 5 files changed, 102 insertions(+), 39 deletions(-)
drivers/iommu/intel/dmar.c +41 -33
@@ -215,7 +215,7 @@ static bool dmar_match_pci_path(struct dmar_pci_notify_info *info, int bus, }/* Return: > 0 if match found, 0 if no match found, < 0 if error happens */ -int dmar_insert_dev_scope (struct dmar_pci_notify_info *info, +int dmar_pci_insert_dev_scope (struct dmar_pci_notify_info *info,void *start,void *end,u16 segment,struct dmar_dev_scope *devices,int devices_cnt)
@@ -304,7 +304,7 @@ static int dmar_pci_bus_add_dev(struct dmar_pci_notify_info *info) drhd =container_of (dmaru->hdr, struct acpi_dmar_hardware_unit, header); - ret =dmar_insert_dev_scope (info, (void *)(drhd +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(drhd +1 ), ((void *)drhd) + drhd->header.length, dmaru->segment, dmaru->devices, dmaru->devices_cnt);
@@ -696,48 +696,56 @@ dmar_find_matched_drhd_unit(struct pci_dev *dev)return dmaru; } - -static void __init dmar_acpi_insert_dev_scope (u8 device_number, -struct acpi_device *adev) +int dmar_acpi_insert_dev_scope (u8 device_number, +struct acpi_device *adev, +void *start,void *end, +struct dmar_dev_scope *devices, +int devices_cnt) { -struct dmar_drhd_unit *dmaru; -struct acpi_dmar_hardware_unit *drhd;struct acpi_dmar_device_scope *scope;struct device *tmp;int i;struct acpi_dmar_pci_path *path; +for (; start < end; start += scope->length) { + scope = start; +if (scope->entry_type !=ACPI_DMAR_SCOPE_TYPE_NAMESPACE ) +continue ; +if (scope->enumeration_id != device_number) +continue ; + path = (void *)(scope +1 ); +for_each_dev_scope (devices, devices_cnt, i, tmp) +if (tmp ==NULL ) { + devices[i].bus = scope->bus; + devices[i].devfn =PCI_DEVFN (path->device, path->function); +rcu_assign_pointer (devices[i].dev, +get_device (&adev->dev)); +return 1 ; + } +WARN_ON (i >= devices_cnt); + } +return 0 ; +} +static int dmar_acpi_bus_add_dev (u8 device_number,struct acpi_device *adev) +{ +struct dmar_drhd_unit *dmaru; +struct acpi_dmar_hardware_unit *drhd; +int ret =0 ; +for_each_drhd_unit (dmaru) { drhd =container_of (dmaru->hdr, struct acpi_dmar_hardware_unit, header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(drhd+1 ), + ((void *)drhd)+drhd->header.length, + dmaru->devices, dmaru->devices_cnt); +if (ret) +break ; + } + ret =dmar_rmrr_add_acpi_dev (device_number, adev); -for (scope = (void *)(drhd +1 ); - (unsigned long )scope < ((unsigned long )drhd) + drhd->header.length; - scope = ((void *)scope) + scope->length) { -if (scope->entry_type !=ACPI_DMAR_SCOPE_TYPE_NAMESPACE ) -continue ; -if (scope->enumeration_id != device_number) -continue ; +return ret; - path = (void *)(scope +1 ); -pr_info ("ACPI device \"%s\" under DMAR at %llx as %02x:%02x.%d\n" , -dev_name (&adev->dev), dmaru->reg_base_addr, - scope->bus, path->device, path->function); -for_each_dev_scope (dmaru->devices, dmaru->devices_cnt, i, tmp) -if (tmp ==NULL ) { - dmaru->devices[i].bus = scope->bus; - dmaru->devices[i].devfn =PCI_DEVFN (path->device, - path->function); -rcu_assign_pointer (dmaru->devices[i].dev, -get_device (&adev->dev)); -return ; - } -BUG_ON (i >= dmaru->devices_cnt); - } - } -pr_warn ("No IOMMU scope found for ANDD enumeration ID %d (%s)\n" , - device_number,dev_name (&adev->dev)); }static int __init dmar_acpi_dev_scope_init (void )
@@ -766,7 +774,7 @@ static int __init dmar_acpi_dev_scope_init(void) andd->device_name);continue ; } -dmar_acpi_insert_dev_scope (andd->device_number, adev); +dmar_acpi_bus_add_dev (andd->device_number, adev); } }return 0 ;
drivers/iommu/intel/iommu.c +45 -2
90 lines not on this page · raw message
drivers/iommu/iommu.c +5 -0
@@ -778,6 +778,11 @@ static bool iommu_is_attach_deferred(struct iommu_domain *domain,return false; } +void __acpi_device_create_direct_mappings (struct iommu_group *group,struct device *acpi_device) +{ +iommu_create_device_direct_mappings (group, acpi_device); +} +EXPORT_SYMBOL_GPL (__acpi_device_create_direct_mappings);/** * iommu_group_add_device - add a device to an iommu group
include/linux/dmar.h +8 -4
@@ -113,13 +113,17 @@ extern int dmar_parse_dev_scope(void *start, void *end, int *cnt, struct dmar_dev_scope **devices, u16 segment);extern void *dmar_alloc_dev_scope (void *start,void *end,int *cnt);extern void dmar_free_dev_scope (struct dmar_dev_scope **devices,int *cnt); -extern int dmar_insert_dev_scope (struct dmar_pci_notify_info *info, +extern int dmar_pci_insert_dev_scope (struct dmar_pci_notify_info *info,void *start,void *end,u16 segment,struct dmar_dev_scope *devices,int devices_cnt); -extern int dmar_remove_dev_scope (struct dmar_pci_notify_info *info, -u16 segment,struct dmar_dev_scope *devices, -int count); +extern int dmar_acpi_insert_dev_scope (u8 device_number, +struct acpi_device *adev,void *start,void *end, +struct dmar_dev_scope *devices,int devices_cnt); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev); + +extern int dmar_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment, +struct dmar_dev_scope *devices,int count);/* Intel IOMMU detection */ extern int detect_intel_iommu (void );extern int enable_drhd_fault_handling (void );
include/linux/iommu.h +3 -0
@@ -536,6 +536,9 @@ extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr)extern int report_iommu_fault (struct iommu_domain *domain,struct device *dev,unsigned long iova,int flags); +extern void __acpi_device_create_direct_mappings (struct iommu_group *group, +struct device *acpi_device); +static inline void iommu_flush_tlb_all (struct iommu_domain *domain) {if (domain->ops->flush_iotlb_all)
Signature · 1 line
2.17.1
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi FelixCuioc,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on iommu/next]
[also build test ERROR on linux/master linus/master v5.8-rc7 next-20200730] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/FelixCuioc/iommu-vt-d-Add-support-for-ACPI-device-in-RMRR/20200728-182409 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: x86_64-randconfig-a014-20200731 (attached as .config) compiler: gcc-9 (Debian 9.3.0-14) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
ld: drivers/iommu/intel/dmar.o: in function `dmar_acpi_bus_add_dev':
>> drivers/iommu/intel/dmar.c:745: undefined reference to `dmar_rmrr_add_acpi_dev'
vim +745 drivers/iommu/intel/dmar.c
670
671 struct dmar_drhd_unit *
672 dmar_find_matched_drhd_unit(struct pci_dev *dev)
673 {
674 struct dmar_drhd_unit *dmaru;
675 struct acpi_dmar_hardware_unit *drhd;
676
677 dev = pci_physfn(dev);
678
679 rcu_read_lock();
680 for_each_drhd_unit(dmaru) {
681 drhd = container_of(dmaru->hdr,
682 struct acpi_dmar_hardware_unit,
683 header);
684
685 if (dmaru->include_all &&
686 drhd->segment == pci_domain_nr(dev->bus))
687 goto out;
688
689 if (dmar_pci_device_match(dmaru->devices,
690 dmaru->devices_cnt, dev))
691 goto out;
692 }
693 dmaru = NULL;
694 out:
695 rcu_read_unlock();
696
697 return dmaru;
698 }
699 int dmar_acpi_insert_dev_scope(u8 device_number,
700 struct acpi_device *adev,
701 void *start, void *end,
702 struct dmar_dev_scope *devices,
703 int devices_cnt)
704 {
705 struct acpi_dmar_device_scope *scope;
706 struct device *tmp;
707 int i;
708 struct acpi_dmar_pci_path *path;
709
710 for (; start < end; start += scope->length) {
711 scope = start;
712 if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_NAMESPACE)
713 continue;
714 if (scope->enumeration_id != device_number)
715 continue;
716 path = (void *)(scope + 1);
717 for_each_dev_scope(devices, devices_cnt, i, tmp)
718 if (tmp == NULL) {
719 devices[i].bus = scope->bus;
720 devices[i].devfn = PCI_DEVFN(path->device, path->function);
721 rcu_assign_pointer(devices[i].dev,
722 get_device(&adev->dev));
723 return 1;
724 }
725 WARN_ON(i >= devices_cnt);
726 }
727 return 0;
728 }
729 static int dmar_acpi_bus_add_dev(u8 device_number, struct acpi_device *adev)
730 {
731 struct dmar_drhd_unit *dmaru;
732 struct acpi_dmar_hardware_unit *drhd;
733 int ret = 0;
734
735 for_each_drhd_unit(dmaru) {
736 drhd = container_of(dmaru->hdr,
737 struct acpi_dmar_hardware_unit,
738 header);
739 ret = dmar_acpi_insert_dev_scope(device_number, adev, (void *)(drhd+1),
740 ((void *)drhd)+drhd->header.length,
741 dmaru->devices, dmaru->devices_cnt);
742 if (ret)
743 break;
744 }
> 745 ret = dmar_rmrr_add_acpi_dev(device_number, adev);
746
747 return ret;
748
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org