[PATCH v3 0/2] Add support for ACPI device in RMRR
BIOS allocate reserved memory ranges that may be DMA targets. BIOS may report each such reserved memory region through the RMRR structures,along with the devices that requires access to the specified reserved memory region. The purpose of this series is to achieve ACPI device in RMRR access reserved memory.Therefore,it is necessary to increase the analysis of acpi device in RMRR and establish a mapping for this device. The first patch adds interfaces for detecting ACPI device in RMRR and in order to distinguish it from pci device, some interface functions are modified. The second patch adds support for probing ACPI device in RMRR. In probe_acpi_namespace_devices(),add support for direct mapping of ACPI device and add support for physical node of acpi device to be NULL. v2->v3: - Add the blank line between functions. - Make dmar_acpi_insert_dev_scope() bool,change the 1/0 to true/false and add a comment explaining. - Delete unused initialization. - if dmar_acpi_insert_dev_scope() always returns zero,will not call dmar_rmrr_add_acpi_dev(). - Use a proper error code. - Use if(!pdev). - Use goto unlock instead of mutex_unlock(). FelixCuioc (2): iommu/vt-d:Add support for detecting ACPI device in RMRR iommu/vt-d:Add support for probing ACPI device in RMRR drivers/iommu/intel/dmar.c | 76 + drivers/iommu/intel/iommu.c | 52 - drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h| 12 +- include/linux/iommu.h | 2 + 5 files changed, 113 insertions(+), 35 deletions(-) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v3 2/2] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 29 + drivers/iommu/iommu.c | 6 ++ include/linux/iommu.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 594b2f29c043..a0fe867aa1f5 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4844,6 +4844,21 @@ 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 = _iommu_ops; + group = iommu_group_get(pn_dev); + if (!group) { + pr_warn("ACPI name space devices create direct mappings wrong!\n"); + return -EINVAL; + } + __acpi_device_create_direct_mappings(group, acpi_device); + + return 0; +} + static int __init probe_acpi_namespace_devices(void) { struct dmar_drhd_unit *drhd; @@ -4858,6 +4873,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 != _bus_type) continue; @@ -4868,6 +4884,7 @@ static int __init probe_acpi_namespace_devices(void) >physical_node_list, node) { group = iommu_group_get(pn->dev); if (group) { + pn_dev = pn->dev; iommu_group_put(group); continue; } @@ -4876,7 +4893,19 @@ static int __init probe_acpi_namespace_devices(void) ret = iommu_probe_device(pn->dev); if (ret) break; + pn_dev = pn->dev; + } + if (!pn_dev) { + dev->bus->iommu_ops = _iommu_ops; + ret = iommu_probe_device(dev); + if (ret) { + pr_err("acpi_device probe fail! ret:%d\n", ret); + goto unlock; + } + goto unlock; } + ret = acpi_device_create_direct_mappings(pn_dev, dev); +unlock: mutex_unlock(>physical_node_lock); if (ret) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 6d847027d35e..ffd470297ea6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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/iommu.h b/include/linux/iommu.h index 82876f682367..bfc46e538c29 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -516,6 +516,8 @@ 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_iotlb_all(struct iommu_domain *domain) { -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v3 1/2] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 76 + drivers/iommu/intel/iommu.c | 23 ++- include/linux/dmar.h| 12 +- 3 files changed, 76 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 54d790f75824..5ebe317280a6 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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); @@ -697,47 +697,59 @@ 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) +/* Return: > 0 if match found, 0 if no match found */ +bool 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(>dev)); + return true; + } + WARN_ON(i >= devices_cnt); + } + return false; +} + +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; + 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; + } + if (ret > 0) + 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(>dev), dmaru->reg_base_addr, - scope->bus, path-&g
[PATCH v3 0/2] Add support for ACPI device in RMRR
BIOS allocate reserved memory ranges that may be DMA targets. BIOS may report each such reserved memory region through the RMRR structures,along with the devices that requires access to the specified reserved memory region. The purpose of this series is to achieve ACPI device in RMRR access reserved memory.Therefore,it is necessary to increase the analysis of acpi device in RMRR and establish a mapping for this device. The first patch adds interfaces for detecting ACPI device in RMRR and in order to distinguish it from pci device, some interface functions are modified. The second patch adds support for probing ACPI device in RMRR. In probe_acpi_namespace_devices(),add support for direct mapping of ACPI device and add support for physical node of acpi device to be NULL. v2->v3: - Add the blank line between functions. - Make dmar_acpi_insert_dev_scope() bool,change the 1/0 to true/false and add a comment explaining. - Delete unused initialization. - if dmar_acpi_insert_dev_scope() always returns zero,will not call dmar_rmrr_add_acpi_dev(). - Use a proper error code. - Use if(!pdev). - Use goto unlock instead of mutex_unlock(). FelixCuioc (2): iommu/vt-d:Add support for detecting ACPI device in RMRR iommu/vt-d:Add support for probing ACPI device in RMRR drivers/iommu/intel/dmar.c | 76 + drivers/iommu/intel/iommu.c | 52 - drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h| 12 +- include/linux/iommu.h | 3 ++ 5 files changed, 114 insertions(+), 35 deletions(-) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v3 2/2] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 29 + drivers/iommu/iommu.c | 6 ++ include/linux/iommu.h | 3 +++ 3 files changed, 38 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 208a91605288..51d7a5b18f41 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4799,6 +4799,21 @@ 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 = _iommu_ops; + group = iommu_group_get(pn_dev); + if (!group) { + pr_warn("ACPI name space devices create direct mappings wrong!\n"); + return -EINVAL; + } + __acpi_device_create_direct_mappings(group, acpi_device); + + return 0; +} + static int __init probe_acpi_namespace_devices(void) { struct dmar_drhd_unit *drhd; @@ -4813,6 +4828,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 != _bus_type) continue; @@ -4823,6 +4839,7 @@ static int __init probe_acpi_namespace_devices(void) >physical_node_list, node) { group = iommu_group_get(pn->dev); if (group) { + pn_dev = pn->dev; iommu_group_put(group); continue; } @@ -4831,7 +4848,19 @@ static int __init probe_acpi_namespace_devices(void) ret = iommu_probe_device(pn->dev); if (ret) break; + pn_dev = pn->dev; + } + if (!pn_dev) { + dev->bus->iommu_ops = _iommu_ops; + ret = iommu_probe_device(dev); + if (ret) { + pr_err("acpi_device probe fail! ret:%d\n", ret); + goto unlock; + } + goto unlock; } + ret = acpi_device_create_direct_mappings(pn_dev, dev); +unlock: mutex_unlock(>physical_node_lock); if (ret) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 609bd25bf154..4f714a2d5ef7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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/iommu.h b/include/linux/iommu.h index fee209efb756..9be134775886 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -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) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v3 1/2] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 76 + drivers/iommu/intel/iommu.c | 23 ++- include/linux/dmar.h| 12 +- 3 files changed, 76 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..f6691c36bd3f 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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); @@ -697,47 +697,59 @@ 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) +/* Return: > 0 if match found, 0 if no match found */ +bool 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(>dev)); + return true; + } + WARN_ON(i >= devices_cnt); + } + return false; +} + +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; + 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; + } + if (ret > 0) + 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(>dev), dmaru->reg_base_addr, - scope->bus, path-&g
[PATCH v2 3/3] iommu/vt-d:Add mutex_unlock() before returning
In the probe_acpi_namespace_devices function,when the physical node of the acpi device is NULL,the unlock function is missing. Add mutex_unlock(>physical_node_lock). Reported-by: Dan Carpenter Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b31f02f41c96..25e9853cba1b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4851,6 +4851,7 @@ static int __init probe_acpi_namespace_devices(void) if (pn_dev == NULL) { dev->bus->iommu_ops = _iommu_ops; ret = iommu_probe_device(dev); + mutex_unlock(>physical_node_lock); if (ret) { pr_err("acpi_device probe fail! ret:%d\n", ret); return ret; -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v2 1/3] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 22 ++- include/linux/dmar.h| 12 +- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..024ca38dba12 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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(>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(>dev), dmaru->reg_base_addr, - scope->bus, path->device, path->function); - for_each_dev_scope(dmaru->devices, dmaru->devices_cnt, i, tmp) -
[PATCH v2 0/3] Add support for ACPI device in RMRR to access reserved memory
BIOS allocate reserved memory ranges that may be DMA targets. BIOS may report each such reserved memory region through the RMRR structures,along with the devices that requires access to the specified reserved memory region. The purpose of this series is to achieve ACPI device in RMRR access reserved memory.Therefore,it is necessary to increase the analysis of acpi device in RMRR and establish a mapping for this device. The first patch adds interfaces for detecting ACPI device in RMRR and in order to distinguish it from pci device,some interface functions are modified. The second patch adds support for probing ACPI device in RMRR. In probe_acpi_namespace_devices(),add support for direct mapping of ACPI device and add support for physical node of acpi device to be NULL. The last patch adds mutex_unlock(>physical_node_lock) before returning in probe_acpi_namespace_devices(). v1->v2: - Split the patch set to small series of patches - Move the processing of physical node of acpi device for NULL to probe_acpi_namespace_devices(). - Add mutex_unlock(>physical_node_lock) before returning in probe_acpi_namespace_devices(). FelixCuioc (3): iommu/vt-d:Add support for detecting ACPI device in RMRR iommu/vt-d:Add support for probing ACPI device in RMRR iommu/vt-d:Add mutex_unlock() before returning drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 50 - drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h| 12 +- include/linux/iommu.h | 3 ++ 5 files changed, 109 insertions(+), 36 deletions(-) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v2 2/3] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 27 +++ drivers/iommu/iommu.c | 6 ++ include/linux/iommu.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f774ef63d473..b31f02f41c96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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 = _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 != _bus_type) continue; @@ -4822,6 +4837,7 @@ static int __init probe_acpi_namespace_devices(void) >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 = _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(>physical_node_lock); if (ret) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 609bd25bf154..4f714a2d5ef7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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/iommu.h b/include/linux/iommu.h index fee209efb756..9be134775886 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -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) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 3/3] iommu/vt-d:Add mutex_unlock() before returning
In the probe_acpi_namespace_devices function,when the physical node of the acpi device is NULL,the unlock function is missing. Add mutex_unlock(>physical_node_lock). Reported-by: Dan Carpenter Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b31f02f41c96..25e9853cba1b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4851,6 +4851,7 @@ static int __init probe_acpi_namespace_devices(void) if (pn_dev == NULL) { dev->bus->iommu_ops = _iommu_ops; ret = iommu_probe_device(dev); + mutex_unlock(>physical_node_lock); if (ret) { pr_err("acpi_device probe fail! ret:%d\n", ret); return ret; -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 1/3] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 22 ++- include/linux/dmar.h| 12 +- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..024ca38dba12 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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(>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(>dev), dmaru->reg_base_addr, - scope->bus, path->device, path->function); - for_each_dev_scope(dmaru->devices, dmaru->devices_cnt, i, tmp) -
[PATCH v2 0/3] Add support for ACPI device in RMRR to access reserved memory
BIOS allocate reserved memory ranges that may be DMA targets. BIOS may report each such reserved memory region through the RMRR structures,along with the devices that requires access to the specified reserved memory region. The purpose of this series is to achieve ACPI device in RMRR access reserved memory.Therefore,it is necessary to increase the analysis of acpi device in RMRR and establish a mapping for this device. The first patch adds interfaces for detecting ACPI device in RMRR and in order to distinguish it from pci device,some interface functions are modified. The second patch adds support for probing ACPI device in RMRR. In probe_acpi_namespace_devices(),add support for direct mapping of ACPI device and add support for physical node of acpi device to be NULL. The last patch adds mutex_unlock(>physical_node_lock) before returning in probe_acpi_namespace_devices(). v1->v2: - Split the patch set to small series of patches - Move the processing of physical node of acpi device for NULL to probe_acpi_namespace_devices(). - Add mutex_unlock(>physical_node_lock) before returning in probe_acpi_namespace_devices(). FelixCuioc (3): iommu/vt-d:Add support for detecting ACPI device in RMRR iommu/vt-d:Add support for probing ACPI device in RMRR iommu/vt-d:Add mutex_unlock() before returning drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 50 - drivers/iommu/iommu.c | 6 +++ include/linux/dmar.h| 12 +- include/linux/iommu.h | 3 ++ 5 files changed, 109 insertions(+), 36 deletions(-) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 2/3] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 27 +++ drivers/iommu/iommu.c | 6 ++ include/linux/iommu.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f774ef63d473..b31f02f41c96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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 = _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 != _bus_type) continue; @@ -4822,6 +4837,7 @@ static int __init probe_acpi_namespace_devices(void) >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 = _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(>physical_node_lock); if (ret) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 609bd25bf154..4f714a2d5ef7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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/iommu.h b/include/linux/iommu.h index fee209efb756..9be134775886 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -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) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 2/2] iommu/vt-d:Add support for probing ACPI device in RMRR
In the probe_acpi_namespace_devices function,when the physical node of the acpi device is NULL,the unlock function is missing. Add mutex_unlock(>physical_node_lock). Reported-by: Dan Carpenter Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b31f02f41c96..25e9853cba1b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4851,6 +4851,7 @@ static int __init probe_acpi_namespace_devices(void) if (pn_dev == NULL) { dev->bus->iommu_ops = _iommu_ops; ret = iommu_probe_device(dev); + mutex_unlock(>physical_node_lock); if (ret) { pr_err("acpi_device probe fail! ret:%d\n", ret); return ret; -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/iommu.c | 27 +++ drivers/iommu/iommu.c | 6 ++ include/linux/iommu.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f774ef63d473..b31f02f41c96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -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 = _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 != _bus_type) continue; @@ -4822,6 +4837,7 @@ static int __init probe_acpi_namespace_devices(void) >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 = _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(>physical_node_lock); if (ret) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 609bd25bf154..4f714a2d5ef7 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -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/iommu.h b/include/linux/iommu.h index fee209efb756..9be134775886 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -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) -- 2.17.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 22 ++- include/linux/dmar.h| 12 +- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..024ca38dba12 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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(>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(>dev), dmaru->reg_base_addr, - scope->bus, path->device, path->function); - for_each_dev_scope(dmaru->devices, dmaru->devices_cnt, i, tmp) -
[PATCH] 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. Reported-by: kernel test robot Signed-off-by: FelixCuioc --- 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(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..024ca38dba12 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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(>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(>dev), dmaru->reg_base_addr, - scope->bus, path->devi
[PATCH] 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. Signed-off-by: FelixCuioc --- drivers/iommu/intel/dmar.c | 74 - drivers/iommu/intel/iommu.c | 47 ++- drivers/iommu/iommu.c | 5 +++ include/linux/dmar.h| 12 -- include/linux/iommu.h | 3 ++ 5 files changed, 102 insertions(+), 39 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 93e6345f3414..024ca38dba12 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -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(>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(>dev), dmaru->reg_base_addr, - scope->bus, path->devi