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 | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 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 +44 -2
89 lines not on this page · raw message
drivers/iommu/iommu.c +6 -0
@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held)
include/linux/dmar.h +11 -1
@@ -113,10 +113,14 @@ 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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);
@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }
@@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev) +{ +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;
include/linux/iommu.h +3 -0
@@ -514,6 +514,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
Lu Baolu
maintainerHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>
No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baolu
Quoted 290 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 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 +44
-2@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev) +{ +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(atsr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(atsr +1 ), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices, atsru->devices_cnt);@@ -4779,6 +4797,26 @@ static int __init platform_optin_force_iommu(void)return 1 ; } +static int acpi_device_create_direct_mappings (struct device *pn_dev,struct device *acpi_device) +{ +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ) {@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c +6
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) include/linux/dmar.h +11
-1@@ -113,10 +113,14 @@ 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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }@@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev) +{ +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h +0
-0
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 9 lines
include/linux/iommu.h +3
-0@@ -514,6 +514,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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope type ACPI_NAMESPACE_DEVICE in RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR is ACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope type ACPI_NAMESPACE_DEVICE in RMRR structure and establish identity mapping for these ACPI devices. In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device. You can refer to the description of type in 8.3.1 device scope in vt-d spec.
Best regards
FelixCui-oc
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>
No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baolu
Quoted 307 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +38
-30- -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
__initdmar_acpi_dev_scope_init(void)
andd->device_name);
continue;
}drivers/iommu/intel/dmar.c +1
-1-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 +18
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info){drivers/iommu/intel/iommu.c +2
-2@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,
atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device *pn_dev, +struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +13
-1@@ -113,10 +113,14 @@ 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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +3
-0@@ -514,6 +514,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)
Lu Baolu
maintainerHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.
So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baolu
Quoted 342 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 307 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +38
-30- -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
__initdmar_acpi_dev_scope_init(void)andd->device_name); continue; }drivers/iommu/intel/dmar.c +1
-1-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 +18
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info){drivers/iommu/intel/iommu.c +2
-2@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device *pn_dev, +struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +13
-1@@ -113,10 +113,14 @@ 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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +3
-0@@ -514,6 +514,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)
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.
Best regards
Felix cui
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.
So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baolu
Quoted 346 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 308 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +39
-30- -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
__initdmar_acpi_dev_scope_init(void)andd->device_name); continue; }drivers/iommu/intel/dmar.c +1
-1-dmar_acpi_insert_dev_scope (andd->device_number, adev); +dmar_acpi_bus_add_dev (andd->device_number, adev); } }return 0 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +18
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info){drivers/iommu/intel/iommu.c +2
-2@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device *pn_dev, +struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +0
-0@@ -113,10 +113,14 @@ 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,include/linux/dmar.h +13
-1+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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +3
-0@@ -514,6 +514,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)
Lu Baolu
maintainerQuoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.
The namespace devices are enumerated in probe_acpi_namespace_devices(). It calls iommu_probe_device() to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?
Best regards,
baolu
Quoted 376 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 346 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 308 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +39
-30- -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
__initdmar_acpi_dev_scope_init(void)andd->device_name); continue; }drivers/iommu/intel/dmar.c +1
-1-dmar_acpi_insert_dev_scope (andd->device_number, adev); +dmar_acpi_bus_add_dev (andd->device_number, adev); } }return 0 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +18
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info){drivers/iommu/intel/iommu.c +2
-2@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device *pn_dev, +struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +0
-0@@ -113,10 +113,14 @@ 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,include/linux/dmar.h +13
-1+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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +3
-0@@ -514,6 +514,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)
Hi baolu:
"The namespace devices are enumerated in probe_acpi_namespace_devices(). It calls iommu_probe_device() to process the enumeration and setup the identity mappings."
This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.
Best regards
Felix cui
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Quoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.
The namespace devices are enumerated in probe_acpi_namespace_devices().
It calls iommu_probe_device() to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?
Best regards,
baolu
Quoted 374 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 341 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]> 主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 303 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +0
-0@@ -113,10 +113,14 @@ 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,include/linux/dmar.h +13
-1+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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi baolu,
dmar_acpi_dev_scope_init() parse ANDD structure and enumerated namespaces device in DRHD. But the namespace device in RMRR is not enumerated, right?
Best regards
Felix cui-oc
-----邮件原件-----
发件人: FelixCui-oc
发送时间: 2020年8月3日 17:02
收件人: 'Lu Baolu' <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi baolu:
"The namespace devices are enumerated in probe_acpi_namespace_devices(). It calls iommu_probe_device() to process the enumeration and setup the identity mappings."
This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.
Best regards
Felix cui
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Quoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.
The namespace devices are enumerated in probe_acpi_namespace_devices().
It calls iommu_probe_device() to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?
Best regards,
baolu
Quoted 374 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 341 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]> 主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 303 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +0
-0@@ -113,10 +113,14 @@ 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,include/linux/dmar.h +13
-1+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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
dmar_acpi_dev_scope_init()parse ANDD structure and enumerated namespaces device in DRHD.
Yes.
Quoted 1 line
But the namespace device in RMRR is not enumerated, right?
It should be probed in probe_acpi_namespace_devices().
Best regards,
baolu
Quoted 421 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: FelixCui-oc
发送时间: 2020年8月3日 17:02
收件人: 'Lu Baolu' <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi baolu:
"The namespace devices are enumerated inprobe_acpi_namespace_devices(). It callsiommu_probe_device()to process the enumeration and setup the identity mappings."This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRQuoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.The namespace devices are enumerated in
probe_acpi_namespace_devices().
It callsiommu_probe_device()to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?Best regards,
baoluQuoted 374 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 341 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]> 主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 303 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +0
-0@@ -113,10 +113,14 @@ 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,include/linux/dmar.h +13
-1+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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init(void) { return -ENODEV; } @@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi baolu ,
When creating a identity mapping for a namespace device in RMRR, you need to add the namespace device to the rmrr->device[] , right? The dmar_acpi_bus_add_dev() in patch adds the enumeration of the namespace device in RMRR. This is similar to
enumerating pci devices. Do you think this is unreasonable? If it is unreasonable, please tell me why it is unreasonable.
Best regards
Felix cui-oc
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月4日 9:12
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
dmar_acpi_dev_scope_init()parse ANDD structure and enumerated namespaces device in DRHD.
Yes.
Quoted 1 line
But the namespace device in RMRR is not enumerated, right?
It should be probed in probe_acpi_namespace_devices().
Best regards,
baolu
Quoted 430 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: FelixCui-oc
发送时间: 2020年8月3日 17:02
收件人: 'Lu Baolu' <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi baolu:
"The namespace devices are enumerated inprobe_acpi_namespace_devices(). It callsiommu_probe_device()to process the enumeration and setup the identity mappings."This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRQuoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.The namespace devices are enumerated in
probe_acpi_namespace_devices().
It callsiommu_probe_device()to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?Best regards,
baoluQuoted 377 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 344 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 305 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)(quoted diff) +0
-0
b/drivers/iommu/intel/dmar.cindex93e6345f3414..024ca38dba12100644drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +8
-0@@ -113,10 +113,14 @@ 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(structdmar_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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }@@
-150,6 +155,11 @@ static inline voidintel_iommu_shutdown(void){ }#define dmar_check_one_atsr dmar_res_noop #define dmar_release_one_atsr dmar_res_noopinclude/linux/dmar.h +5
-0+static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerHi,
Quoted 2 lines · FelixCui-oc
Hi baolu ,
When creating a identity mapping for a namespace device in RMRR, you need to add the namespace device to the rmrr->device[] , right?
Yes. You are right.
Quoted 1 line
The
dmar_acpi_bus_add_dev()in patch adds the enumeration of the namespace device in RMRR. This is similar to > enumerating pci devices. Do you think this is unreasonable? If it is
unreasonable, please tell me why it is unreasonable.
It looks reasonable. Thanks for the explanation.
But I don't think we need to add acpi_device_create_direct_mappings() since the rmrr identity mapping is already done in the iommu core.
Best regards,
baolu
Quoted 458 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月4日 9:12
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
dmar_acpi_dev_scope_init()parse ANDD structure and enumerated namespaces device in DRHD.Yes.
Quoted 1 line
But the namespace device in RMRR is not enumerated, right?
It should be probed in
probe_acpi_namespace_devices().Best regards,
baoluQuoted 430 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: FelixCui-oc
发送时间: 2020年8月3日 17:02
收件人: 'Lu Baolu' <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi baolu:
"The namespace devices are enumerated inprobe_acpi_namespace_devices(). It callsiommu_probe_device()to process the enumeration and setup the identity mappings."This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRQuoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.The namespace devices are enumerated in
probe_acpi_namespace_devices().
It callsiommu_probe_device()to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?Best regards,
baoluQuoted 377 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 344 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 305 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)(quoted diff) +0
-0
b/drivers/iommu/intel/dmar.cindex93e6345f3414..024ca38dba12100644drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +8
-0@@ -113,10 +113,14 @@ 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(structdmar_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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }@@
-150,6 +155,11 @@ static inline voidintel_iommu_shutdown(void){ }#define dmar_check_one_atsr dmar_res_noop #define dmar_release_one_atsr dmar_res_noopinclude/linux/dmar.h +5
-0+static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi baolu,
Let me talk about why acpi_device_create_direct_mappings() is needed and please tell me if there is an error.
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices. Therefore, the namespace device in RMRR is not mapped in probe_acpi_namespace_devices(). acpi_device_create_direct_mappings() is to create direct mappings for namespace devices in RMRR.
Best regards
Felix cui-oc
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月5日 10:57
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi,
Quoted 2 lines · FelixCui-oc
Hi baolu ,
When creating a identity mapping for a namespace device in RMRR, you need to add the namespace device to the rmrr->device[] , right?
Yes. You are right.
Quoted 3 lines
The
dmar_acpi_bus_add_dev()in patch adds the enumeration of the
namespace device in RMRR. This is similar to > enumerating pci devices. Do you think this is unreasonable? If it is
unreasonable, please tell me why it is unreasonable.
It looks reasonable. Thanks for the explanation.
But I don't think we need to add acpi_device_create_direct_mappings() since the rmrr identity mapping is already done in the iommu core.
Best regards,
baolu
Quoted 464 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月4日 9:12
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
dmar_acpi_dev_scope_init()parse ANDD structure and enumerated namespaces device in DRHD.Yes.
Quoted 1 line
But the namespace device in RMRR is not enumerated, right?
It should be probed in
probe_acpi_namespace_devices().Best regards,
baoluQuoted 432 lines
Best regards
Felix cui-oc-----邮件原件-----
发件人: FelixCui-oc
发送时间: 2020年8月3日 17:02
收件人: 'Lu Baolu' <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi baolu:
"The namespace devices are enumerated inprobe_acpi_namespace_devices(). It callsiommu_probe_device()to process the enumeration and setup the identity mappings."This situation only applies to the physical node of the namespaces device as the pci device. In fact, the physical node of the namespaces device can be a platform device or NULL.
If the physical node of the namespaces is a platform device or NULL, it has not actually been enumerated. So it is necessary to increase the analysis of the namespaces device in RMRR and establish an identity mapping.Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 16:26
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRQuoted 3 lines · FelixCui-oc
Hi baolu ,
Yes ,that's right.
This patch is to achieve acpi namespace devices to access the RMRR region.The namespace devices are enumerated in
probe_acpi_namespace_devices().
It callsiommu_probe_device()to process the enumeration and setup the identity mappings. Can you please check why that code doesn't work for you?Best regards,
baoluQuoted 377 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 14:19
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 5 lines · FelixCui-oc
Hi baolu:
Some ACPI devices need to issue dma requests to access the reserved memory area.
So bios uses the device scope typeACPI_NAMESPACE_DEVICEin RMRR to report these ACPI devices.
At present, there is no analysis in the kernel that the device scope type in RMRR isACPI_NAMESPACE_DEVICE.
This patch is mainly to add the analysis of the device scope typeACPI_NAMESPACE_DEVICEin RMRR structure and establish identity mapping for > these ACPI devices.So the problem is "although namespace devices in RMRR have been parsed, but the identity map for those devices aren't created. As the result, the namespace devices fail to access the RMRR region."
Do I understand it right?
Best regards,
baoluQuoted 344 lines
In addition, some naming changes have been made in patch in order to distinguish acpi device from pci device.
You can refer to the description of type in 8.3.1 device scope in vt-d spec.Best regards
FelixCui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月3日 10:32
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; Cobe Chen(BJ-RD) <[email protected]>; Raymond Pang(BJ-RD) <[email protected]>
主题: Re: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi,
Quoted 4 lines · FelixCuioc
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.
Can you please add more words about the problem you want to solve? Do you mean some RMRRs are not enumerated correctly? Or, enumerated, but not identity mapped?
Nit: add version and change log once you refreshed your patch.
Quoted 2 lines
Reported-by kernel test robot <[email protected]>No need to add this. The problem you want to solve through this patch is not reported by lkp.
Best regards,
baoluQuoted 305 lines
Signed-off-by FelixCuioc <[email protected]>--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 46 ++++++++++++++++++++++- drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h | 12 +++++- include/linux/iommu.h | 3 ++ 5 files changed, 105 insertions(+), 36 deletions(-)(quoted diff) +0
-0
b/drivers/iommu/intel/dmar.cindex93e6345f3414..024ca38dba12100644drivers/iommu/intel/dmar.c +0
-0@@ -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,drivers/iommu/intel/dmar.c +2
-1+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; }drivers/iommu/intel/dmar.c +41
-31- -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 ;(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cindexca557d351518..be1793415326100644drivers/iommu/intel/iommu.c +0
-0@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct
pci_dev
*dev)return ret; }drivers/iommu/intel/iommu.c +20
-2+int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device +*adev) { +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret = dmar_insert_dev_scope(info, (void *)(atsr + 1), + ret = dmar_pci_insert_dev_scope(info, (void *)(atsr + 1), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices,atsru->devices_cnt);drivers/iommu/intel/iommu.c +20
-0@@ -4779,6 +4797,26 @@ static int __initplatform_optin_force_iommu (void ) return 1; } +static int acpi_device_create_direct_mappings (struct device +*pn_dev,struct device *acpi_device) { +int ret; +struct iommu_group *group; + +if (pn_dev ==NULL ) { + acpi_device->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (acpi_device); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; + } + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ){drivers/iommu/intel/iommu.c +4
-0@@ -4794,6 +4832,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;@@ -4804,6 +4843,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }@@ -4812,7 +4852,9 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)drivers/iommu/iommu.c index renamed from drivers/iommu/iommu.c +0
-0
609bd25bf154..4f714a2d5ef7100644drivers/iommu/iommu.c +5
-0@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held) diff --git
a/include/linux/dmar.hb/include/linux/dmar.hindex65565820328a..881ac61a4336100644include/linux/dmar.h +8
-0@@ -113,10 +113,14 @@ 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(structdmar_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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }@@
-150,6 +155,11 @@ static inline voidintel_iommu_shutdown(void){ }#define dmar_check_one_atsr dmar_res_noop #define dmar_release_one_atsr dmar_res_noopinclude/linux/dmar.h +5
-0+static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct +acpi_device *adev) { +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;include/linux/iommu.h index renamed from include/linux/iommu.h +0
-0
fee209efb756..9be134775886100644include/linux/iommu.h +0
-0@@ -514,6 +514,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);
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
include/linux/iommu.h extern void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr) · line 522
Quoted 7 lines
include/linux/iommu.h +3
-0+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)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Lu Baolu
maintainerHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.
Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence iommu_create_device_direct_mappings() doesn't work for this device.
At the same time, probe_acpi_namespace_devices() doesn't work for this device, hence you want to add a home-made acpi_device_create_direct_mappings() helper.
Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.
The namespace device has been probed and put in one drhd's device list. Hence, it should be processed by probe_acpi_namespace_devices(). So the question is why there are no devices in addev->physical_node_list?
Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.
Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi baolu,
>Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. >Current code doesn't enumerate that device for the RMRR, hence iommu_create_device_direct_mappings() doesn't work for this device.
>At the same time, probe_acpi_namespace_devices() doesn't work for this device, hence you want to add a home-made >acpi_device_create_direct_mappings() helper.
Your understanding is right.
But there is a problem that even if the namespace device in rmrr is enumerated in the code, probe_acpi_namespace_devices() also doesn't work for this device. This is because the dev parameter of the iommu_create_device_direct_mappings() is not the namespace device in RMRR.
The actual parameter passed in is the namespace device's physical node device.
In iommu_create_device_direct_mappings(), the physical node device passed in cannot match the namespace device in rmrr->device[],right? We need acpi_device_create_direct_mappings() helper ?
In addition, adev->physical_node_list is related to the __HID of namespace device reported by the bios. For example, if the __HID reported by the bios belongs to acpi_pnp_device_ids[], adev->physical_node_list has no devices. So in acpi_device_create_direct_mappings(), I added the case that adev->physical_node_list is empty.
Best regards
Felix cui
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月6日 10:36
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.
Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence iommu_create_device_direct_mappings() doesn't work for this device.
At the same time, probe_acpi_namespace_devices() doesn't work for this device, hence you want to add a home-made acpi_device_create_direct_mappings() helper.
Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.
The namespace device has been probed and put in one drhd's device list.
Hence, it should be processed by probe_acpi_namespace_devices(). So the question is why there are no devices in addev->physical_node_list?
Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.
Best regards,
baolu
Lu Baolu
maintainerHi Felix,
Quoted 14 lines · FelixCui-oc
Hi baolu,
>Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. >Current code doesn't enumerate that device for the RMRR, henceiommu_create_device_direct_mappings()doesn't work for this device.>At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-made >acpi_device_create_direct_mappings() helper.Your understanding is right.
But there is a problem that even if the namespace device in rmrr is enumerated in the code,probe_acpi_namespace_devices()also doesn't work for this device. This is because the dev parameter of theiommu_create_device_direct_mappings()is not the namespace device in RMRR.
The actual parameter passed in is the namespace device's physical node device.
Iniommu_create_device_direct_mappings(), the physical node device passed in cannot match the namespace device in rmrr->device[],right? We needacpi_device_create_direct_mappings()helper ?
Quoted 3 lines
In addition,
adev->physical_node_listis related to the__HIDof namespace device reported by the bios. For example, if the__HIDreported by the bios belongs to acpi_pnp_device_ids[],adev->physical_node_listhas no devices. So inacpi_device_create_direct_mappings(), I added the case thatadev->physical_node_listis empty.
Got you. Thanks!
Have you ever tried to have probe_acpi_namespace_devices() handle the case of empty adev->physical_node_list at the same time?
Best regards,
baolu
Quoted 40 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月6日 10:36
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence
iommu_create_device_direct_mappings()doesn't work for this device.At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-madeacpi_device_create_direct_mappings()helper.Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.The namespace device has been probed and put in one drhd's device list.
Hence, it should be processed byprobe_acpi_namespace_devices(). So the question is why there are no devices inaddev->physical_node_list?Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.Best regards,
baolu
Hi baolu,
I understand what you mean is that you want to put the following processing code in the acpi_device_create_direct_mappings() into the probe_acpi_namespace_devices() ,right?
If you mean it , I think it's OK.
if (pn_dev == NULL) {
acpi_device->bus->iommu_ops = &intel_iommu_ops;
ret = iommu_probe_device(acpi_device);
if (ret) {
pr_err("acpi_device probe fail! ret:%d\n", ret);
return ret;
}
return 0;
}Best regards
Felix cui-oc
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月7日 9:08
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi Felix,
Quoted 14 lines · FelixCui-oc
Hi baolu,
>Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. >Current code doesn't enumerate that device for the RMRR, henceiommu_create_device_direct_mappings()doesn't work for this device.>At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-made >acpi_device_create_direct_mappings() helper.Your understanding is right.
But there is a problem that even if the namespace device in rmrr is enumerated in the code,probe_acpi_namespace_devices()also doesn't work for this device. This is because the dev parameter of theiommu_create_device_direct_mappings()is not the namespace device in RMRR.
The actual parameter passed in is the namespace device's physical node device.
Iniommu_create_device_direct_mappings(), the physical node device passed in cannot match the namespace device in rmrr->device[],right? We needacpi_device_create_direct_mappings()helper ?
Quoted 3 lines
In addition,
adev->physical_node_listis related to the__HIDof namespace device reported by the bios. For example, if the__HIDreported by the bios belongs to acpi_pnp_device_ids[],adev->physical_node_listhas no devices. So inacpi_device_create_direct_mappings(), I added the case thatadev->physical_node_listis empty.
Got you. Thanks!
Have you ever tried to have probe_acpi_namespace_devices() handle the case of empty adev->physical_node_list at the same time?
Best regards,
baolu
Quoted 45 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月6日 10:36
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence
iommu_create_device_direct_mappings()doesn't work for this device.At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-madeacpi_device_create_direct_mappings()helper.Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.The namespace device has been probed and put in one drhd's device list.
Hence, it should be processed byprobe_acpi_namespace_devices(). So the question is why there are no devices inaddev->physical_node_list?Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.Best regards,
baolu
Lu Baolu
maintainerHi,
Quoted 3 lines · FelixCui-oc
Hi baolu,
I understand what you mean is that you want to put the following processing code in theacpi_device_create_direct_mappings()into theprobe_acpi_namespace_devices(),right? If you mean it , I think it's OK.
Yes. If the acpi device has companion physical devices, then probe the companion devices; otherwise, probe the acpi device instead. Also, let's put detecting and probing acpi devices in different patches so that they could be easier for reviewing.
Best regards,
baolu
Quoted 98 lines
if (pn_dev == NULL) { acpi_device->bus->iommu_ops = &intel_iommu_ops; ret = iommu_probe_device(acpi_device); if (ret) { pr_err("acpi_device probe fail! ret:%d\n", ret); return ret; } return 0; }Best regards
Felix cui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月7日 9:08
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 14 lines · FelixCui-oc
Hi baolu,
>Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. >Current code doesn't enumerate that device for the RMRR, henceiommu_create_device_direct_mappings()doesn't work for this device.>At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-made >acpi_device_create_direct_mappings() helper.Your understanding is right.
But there is a problem that even if the namespace device in rmrr is enumerated in the code,probe_acpi_namespace_devices()also doesn't work for this device. This is because the dev parameter of theiommu_create_device_direct_mappings()is not the namespace device in RMRR.
The actual parameter passed in is the namespace device's physical node device.
Iniommu_create_device_direct_mappings(), the physical node device passed in cannot match the namespace device in rmrr->device[],right? We needacpi_device_create_direct_mappings()helper ?Quoted 3 lines
In addition,
adev->physical_node_listis related to the__HIDof namespace device reported by the bios. For example, if the__HIDreported by the bios belongs to acpi_pnp_device_ids[],adev->physical_node_listhas no devices. So inacpi_device_create_direct_mappings(), I added the case thatadev->physical_node_listis empty.Got you. Thanks!
Have you ever tried to have
probe_acpi_namespace_devices()handle the case of emptyadev->physical_node_listat the same time?Best regards,
baoluQuoted 45 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月6日 10:36
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence
iommu_create_device_direct_mappings()doesn't work for this device.At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-madeacpi_device_create_direct_mappings()helper.Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.The namespace device has been probed and put in one drhd's device list.
Hence, it should be processed byprobe_acpi_namespace_devices(). So the question is why there are no devices inaddev->physical_node_list?Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.Best regards,
baolu
Hi baolu,
The attachment is the new patch.
If you have any questions, you can contact me at any time. Thanks.
Best regards
Felix cui-oc
-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月7日 16:08
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]>
主题: Re: 答复: 答复: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRR
Hi,
Quoted 3 lines · FelixCui-oc
Hi baolu,
I understand what you mean is that you want to put the following processing code in theacpi_device_create_direct_mappings()into theprobe_acpi_namespace_devices(),right? If you mean it , I think it's OK.
Yes. If the acpi device has companion physical devices, then probe the companion devices; otherwise, probe the acpi device instead. Also, let's put detecting and probing acpi devices in different patches so that they could be easier for reviewing.
Best regards,
baolu
Quoted 50 lines
if (pn_dev == NULL) { acpi_device->bus->iommu_ops = &intel_iommu_ops; ret = iommu_probe_device(acpi_device); if (ret) { pr_err("acpi_device probe fail! ret:%d\n", ret); return ret; } return 0; }Best regards
Felix cui-oc-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月7日 9:08
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 14 lines · FelixCui-oc
Hi baolu,
>Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. >Current code doesn't enumerate that device for the RMRR, henceiommu_create_device_direct_mappings()doesn't work for this device.>At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-made >acpi_device_create_direct_mappings() helper.Your understanding is right.
But there is a problem that even if the namespace device in rmrr is enumerated in the code,probe_acpi_namespace_devices()also doesn't work for this device. This is because the dev parameter of theiommu_create_device_direct_mappings()is not the namespace device in RMRR.
The actual parameter passed in is the namespace device's physical node device.
Iniommu_create_device_direct_mappings(), the physical node device passed in cannot match the namespace device in rmrr->device[],right? We needacpi_device_create_direct_mappings()helper ?Quoted 3 lines
In addition,
adev->physical_node_listis related to the__HIDof namespace device reported by the bios. For example, if the__HIDreported by the bios belongs to acpi_pnp_device_ids[],adev->physical_node_listhas no devices. So inacpi_device_create_direct_mappings(), I added the case thatadev->physical_node_listis empty.
Quoted 52 lines
Got you. Thanks!
Have you ever tried to have
probe_acpi_namespace_devices()handle the case of emptyadev->physical_node_listat the same time?Best regards,
baoluQuoted 45 lines
Best regards
Felix cui-----邮件原件-----
发件人: Lu Baolu <[email protected]>
发送时间: 2020年8月6日 10:36
收件人: FelixCui-oc <[email protected]>; Joerg Roedel <[email protected]>; [email protected]; [email protected]; David Woodhouse <[email protected]> 抄送: [email protected]; RaymondPang-oc <[email protected]>; CobeChen-oc <[email protected]> 主题: Re: 答复: 答复: 答复: 答复: 答复: [PATCH] iommu/vt-d:Add support for ACPI device in RMRRHi Felix,
Quoted 2 lines · FelixCui-oc
Hi baolu,
Let me talk about whyacpi_device_create_direct_mappings()is needed and please tell me if there is an error.Sure. Before that, let me sync my understanding with you. You have an acpi namespace device in ANDD table, it also shows up in the device scope of a RMRR. Current code doesn't enumerate that device for the RMRR, hence
iommu_create_device_direct_mappings()doesn't work for this device.At the same time,
probe_acpi_namespace_devices()doesn't work for this device, hence you want to add a home-madeacpi_device_create_direct_mappings()helper.Did I get it right?
Quoted 2 lines
In the probe_acpi_namespace_devices() function, only the device in the addev->physical_node_list is probed, but we need to establish identity mapping for the namespace device in RMRR. These are two different devices.The namespace device has been probed and put in one drhd's device list.
Hence, it should be processed byprobe_acpi_namespace_devices(). So the question is why there are no devices inaddev->physical_node_list?Quoted 2 lines
Therefore, the namespace device in RMRR is not mapped in
probe_acpi_namespace_devices().acpi_device_create_direct_mappings()is to create direct mappings for namespace devices in RMRR.Best regards,
baolu
From d5bb22f767f6336e1014ff6adb86c7654287b9b4 Mon Sep 17 00:00:00 2001
From: FelixCuioc <[email protected]>
Date: Sat, 8 Aug 2020 00:56:43 -0400
Subject: [PATCH] iommu/vt-d:Add support for detecting ACPI device in RMRR
Some ACPI devices need to issue dma requests to access the reserved memory area.BIOS uses the device scope type ACPI_NAMESPACE_DEVICE in RMRR to report these ACPI devices. This patch add support for detecting ACPI devices in RMRR.
--- drivers/iommu/intel/dmar.c | 74 ++++++++++++++++++++----------------- drivers/iommu/intel/iommu.c | 22 ++++++++++- include/linux/dmar.h | 12 +++++- 3 files changed, 72 insertions(+), 36 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 +20 -2
@@ -4507,6 +4507,24 @@ int dmar_find_matched_atsr_unit(struct pci_dev *dev)return ret; } +int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev) +{ +int ret; +struct dmar_rmrr_unit *rmrru; +struct acpi_dmar_reserved_memory *rmrr; + +list_for_each_entry (rmrru, &dmar_rmrr_units, list) { + rmrr =container_of (rmrru->hdr, + struct acpi_dmar_reserved_memory, + header); + ret =dmar_acpi_insert_dev_scope (device_number, adev, (void *)(rmrr +1 ), + ((void *)rmrr) + rmrr->header.length, + rmrru->devices, rmrru->devices_cnt); +if (ret) +break ; + } +return 0 ; +}int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {
@@ -4523,7 +4541,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) rmrr =container_of (rmrru->hdr, struct acpi_dmar_reserved_memory, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(rmrr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(rmrr +1 ), ((void *)rmrr) + rmrr->header.length, rmrr->segment, rmrru->devices, rmrru->devices_cnt);
@@ -4541,7 +4559,7 @@ int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info) atsr = container_of(atsru->hdr, struct acpi_dmar_atsr, header);if (info->event ==BUS_NOTIFY_ADD_DEVICE ) { - ret =dmar_insert_dev_scope (info, (void *)(atsr +1 ), + ret =dmar_pci_insert_dev_scope (info, (void *)(atsr +1 ), (void *)atsr + atsr->header.length, atsr->segment, atsru->devices, atsru->devices_cnt);
include/linux/dmar.h +11 -1
@@ -113,10 +113,14 @@ 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_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_remove_dev_scope (struct dmar_pci_notify_info *info,u16 segment,struct dmar_dev_scope *devices,int count);
@@ -140,6 +144,7 @@ extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);extern int dmar_check_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_release_one_atsr (struct acpi_dmar_header *hdr,void *arg);extern int dmar_iommu_hotplug (struct dmar_drhd_unit *dmaru,bool insert); +extern int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev);extern int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info);#else /* !CONFIG_INTEL_IOMMU: */ static inline int intel_iommu_init (void ) {return -ENODEV ; }
@@ -150,6 +155,11 @@ static inline void intel_iommu_shutdown(void) { }#define dmar_check_one_atsr dmar_res_noop#define dmar_release_one_atsr dmar_res_noop +static inline int dmar_rmrr_add_acpi_dev (u8 device_number,struct acpi_device *adev) +{ +return 0 ; +} +static inline int dmar_iommu_notify_scope_dev (struct dmar_pci_notify_info *info) {return 0 ;
Signature · 1 line
2.17.1
From a43a44fc775ec6fe6a7fe71b1fbe175b1e834e7c Mon Sep 17 00:00:00 2001
From: FelixCuioc <[email protected]>
Date: Sat, 8 Aug 2020 02:43:50 -0400
Subject: [PATCH] iommu/vt-d:Add support for probing ACPI device in RMRR
After acpi device in RMRR is detected,it is necessary to establish a mapping for these devices.
In acpi_device_create_direct_mappings(),create a mapping for the acpi device in RMRR.
Add a helper to achieve the acpi namespace device can access the RMRR region.
--- drivers/iommu/intel/iommu.c | 27 +++++++++++++++++++++++++++ drivers/iommu/iommu.c | 6 ++++++ include/linux/iommu.h | 3 +++ 3 files changed, 36 insertions(+)
drivers/iommu/intel/iommu.c +27 -0
@@ -4797,6 +4797,20 @@ static int __init platform_optin_force_iommu(void)return 1 ; } +static int acpi_device_create_direct_mappings (struct device *pn_dev,struct device *acpi_device) +{ +struct iommu_group *group; + + acpi_device->bus->iommu_ops = &intel_iommu_ops; + group =iommu_group_get (pn_dev); +if (!group) { +pr_warn ("ACPI name space devices create direct mappings wrong!\n" ); +return -1 ; + } +__acpi_device_create_direct_mappings (group, acpi_device); + +return 0 ; +}static int __init probe_acpi_namespace_devices (void ) {
@@ -4812,6 +4826,7 @@ static int __init probe_acpi_namespace_devices(void)struct acpi_device_physical_node *pn;struct iommu_group *group;struct acpi_device *adev; +struct device *pn_dev =NULL ;if (dev->bus != &acpi_bus_type)continue ;
@@ -4822,6 +4837,7 @@ static int __init probe_acpi_namespace_devices(void) &adev->physical_node_list, node) { group =iommu_group_get (pn->dev);if (group) { + pn_dev = pn->dev;iommu_group_put (group);continue ; }
@@ -4830,7 +4846,18 @@ static int __init probe_acpi_namespace_devices(void) ret =iommu_probe_device (pn->dev);if (ret)break ; + pn_dev = pn->dev; + } +if (pn_dev ==NULL ) { + dev->bus->iommu_ops = &intel_iommu_ops; + ret =iommu_probe_device (dev); +if (ret) { +pr_err ("acpi_device probe fail! ret:%d\n" , ret); +return ret; + } +return 0 ; } + ret =acpi_device_create_direct_mappings (pn_dev, dev);mutex_unlock (&adev->physical_node_lock);if (ret)
drivers/iommu/iommu.c +6 -0
@@ -779,6 +779,12 @@ 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 * @group: the group into which to add the device (reference should be held)
include/linux/iommu.h +3 -0
@@ -514,6 +514,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