[PATCH v2] iommu/of: Fix pci_request_acs() before enumerating PCI devices
From: Xingang Wang When booting with devicetree, the pci_request_acs() is called after the enumeration and initialization of PCI devices, thus the ACS is not enabled. This patch add check for IOMMU in of_core_init(), and call pci_request_acs() when iommu is detected, making sure that the ACS will be enabled. Fixes: 6bf6c24720d33 ("iommu/of: Request ACS from the PCI core when configuring IOMMU linkage") Signed-off-by: Xingang Wang --- drivers/iommu/of_iommu.c | 1 - drivers/of/base.c| 9 - 2 files changed, 8 insertions(+), 2 deletions(-) Change log: v1->v2: - remove pci_request_acs() in of_iommu_configure - check and call pci_request_acs() in of_core_init() diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a9d2df001149..54a14da242cc 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -205,7 +205,6 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, .np = master_np, }; - pci_request_acs(); err = pci_for_each_dma_alias(to_pci_dev(dev), of_pci_iommu_init, &info); } else { diff --git a/drivers/of/base.c b/drivers/of/base.c index 48e941f99558..95cd8f0e5435 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -166,7 +167,7 @@ void __of_phandle_cache_inv_entry(phandle handle) void __init of_core_init(void) { struct device_node *np; - + bool of_iommu_detect = false; /* Create the kset, and register existing nodes */ mutex_lock(&of_mutex); @@ -180,6 +181,12 @@ void __init of_core_init(void) __of_attach_node_sysfs(np); if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)]) phandle_cache[of_phandle_cache_hash(np->phandle)] = np; + + /* Detect IOMMU and make sure ACS will be enabled */ + if (!of_iommu_detect && of_get_property(np, "iommu-map", NULL)) { + of_iommu_detect = true; + pci_request_acs(); + } } mutex_unlock(&of_mutex); -- 2.19.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v3] iommu/of: Fix pci_request_acs() before enumerating PCI devices
From: Xingang Wang When booting with devicetree, the pci_request_acs() is called after the enumeration and initialization of PCI devices, thus the ACS is not enabled. And ACS should be enabled when IOMMU is detected for the PCI host bridge, so add check for IOMMU before probe of PCI host and call pci_request_acs() to make sure ACS will be enabled when enumerating PCI devices. Fixes: 6bf6c24720d33 ("iommu/of: Request ACS from the PCI core when configuring IOMMU linkage") Signed-off-by: Xingang Wang --- drivers/iommu/of_iommu.c | 1 - drivers/pci/controller/pci-host-common.c | 17 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a9d2df001149..54a14da242cc 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -205,7 +205,6 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, .np = master_np, }; - pci_request_acs(); err = pci_for_each_dma_alias(to_pci_dev(dev), of_pci_iommu_init, &info); } else { diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c index d3924a44db02..5904ad0bd9ae 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -49,6 +49,21 @@ static struct pci_config_window *gen_pci_init(struct device *dev, return cfg; } +static void pci_host_enable_acs(struct pci_host_bridge *bridge) +{ + struct device_node *np = bridge->dev.parent->of_node; + static bool acs_enabled; + + if (!np || acs_enabled) + return; + + /* Detect IOMMU and make sure ACS will be enabled */ + if (of_property_read_bool(np, "iommu-map")) { + acs_enabled = true; + pci_request_acs(); + } +} + int pci_host_common_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -81,6 +96,8 @@ int pci_host_common_probe(struct platform_device *pdev) bridge->ops = (struct pci_ops *)&ops->pci_ops; bridge->msi_domain = true; + pci_host_enable_acs(bridge); + return pci_host_probe(bridge); } EXPORT_SYMBOL_GPL(pci_host_common_probe); -- 2.19.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v4] iommu/of: Fix pci_request_acs() before enumerating PCI devices
From: Xingang Wang When booting with devicetree, the pci_request_acs() is called after the enumeration and initialization of PCI devices, thus the ACS is not enabled. And ACS should be enabled when IOMMU is detected for the PCI host bridge, so add check for IOMMU before probe of PCI host and call pci_request_acs() to make sure ACS will be enabled when enumerating PCI devices. Fixes: 6bf6c24720d33 ("iommu/of: Request ACS from the PCI core when configuring IOMMU linkage") Signed-off-by: Xingang Wang --- drivers/iommu/of_iommu.c | 1 - drivers/pci/of.c | 8 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a9d2df001149..54a14da242cc 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -205,7 +205,6 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, .np = master_np, }; - pci_request_acs(); err = pci_for_each_dma_alias(to_pci_dev(dev), of_pci_iommu_init, &info); } else { diff --git a/drivers/pci/of.c b/drivers/pci/of.c index da5b414d585a..2313c3f848b0 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -581,9 +581,15 @@ static int pci_parse_request_of_pci_ranges(struct device *dev, int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) { - if (!dev->of_node) + struct device_node *node = dev->of_node; + + if (!node) return 0; + /* Detect IOMMU and make sure ACS will be enabled */ + if (of_property_read_bool(node, "iommu-map")) + pci_request_acs(); + bridge->swizzle_irq = pci_common_swizzle; bridge->map_irq = of_irq_parse_and_map_pci; -- 2.19.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v13 07/15] iommu/smmuv3: Allow stage 1 invalidation with unmanaged ASIDs
Thanks for your reply. We are testing vSVA, and will let you know if other problems are found. On 2020/12/1 21:58, Auger Eric wrote: Hi Xingang, On 12/1/20 2:33 PM, Xingang Wang wrote: Hi Eric On Wed, 18 Nov 2020 12:21:43, Eric Auger wrote: @@ -1710,7 +1710,11 @@ static void arm_smmu_tlb_inv_context(void *cookie) * insertion to guarantee those are observed before the TLBI. Do be * careful, 007. */ - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + if (ext_asid >= 0) { /* guest stage 1 invalidation */ + cmd.opcode = CMDQ_OP_TLBI_NH_ASID; + cmd.tlbi.asid = ext_asid; + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; + } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { Found a problem here, the cmd for guest stage 1 invalidation is built, but it is not delivered to smmu. Thank you for the report. I will fix that soon. With that fixed, have you been able to run vSVA on top of the series. Do you need other stuff to be fixed at SMMU level? As I am going to respin soon, please let me know what is the best branch to rebase to alleviate your integration. Best Regards Eric . ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 1/1] iommu/of: Fix request and enable ACS for of_iommu_configure
From: Xingang Wang When request ACS for PCI device in of_iommu_configure, the pci device has already been scanned and added with 'pci_acs_enable=0'. So the pci_request_acs() in current procedure does not work for enabling ACS. Besides, the ACS should be enabled only if there's an IOMMU in system. So this fix the call of pci_request_acs() and call pci_enable_acs() to make sure ACS is enabled for the pci_device. Fixes: 6bf6c24720d33 ("iommu/of: Request ACS from the PCI core when configuring IOMMU linkage") Signed-off-by: Xingang Wang --- drivers/iommu/of_iommu.c | 10 +- drivers/pci/pci.c| 2 +- include/linux/pci.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index a9d2df001149..dc621861ae72 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -205,7 +205,6 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, .np = master_np, }; - pci_request_acs(); err = pci_for_each_dma_alias(to_pci_dev(dev), of_pci_iommu_init, &info); } else { @@ -222,6 +221,15 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, /* The fwspec pointer changed, read it again */ fwspec = dev_iommu_fwspec_get(dev); ops= fwspec->ops; + + /* +* If we found an IOMMU and the device is pci, +* make sure we enable ACS. +*/ + if (dev_is_pci(dev)) { + pci_request_acs(); + pci_enable_acs(to_pci_dev(dev)); + } } /* * If we have reason to believe the IOMMU driver missed the initial diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b717680377a9..4e4f98ee2870 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -926,7 +926,7 @@ static void pci_std_enable_acs(struct pci_dev *dev) * pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device */ -static void pci_enable_acs(struct pci_dev *dev) +void pci_enable_acs(struct pci_dev *dev) { if (!pci_acs_enable) goto disable_acs_redir; diff --git a/include/linux/pci.h b/include/linux/pci.h index c20211e59a57..e6a8bfbc9c98 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2223,6 +2223,7 @@ static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev) } void pci_request_acs(void); +void pci_enable_acs(struct pci_dev *dev); bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags); bool pci_acs_path_enabled(struct pci_dev *start, struct pci_dev *end, u16 acs_flags); -- 2.19.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 0/1] iommu/of: Fix request and enable ACS for of_iommu_configure
From: Xingang Wang When request ACS in of_iommu_configure, the pci_acs_init procedure has already been called. The pci device probe procedure is like the following: pci_host_common_probe pci_device_add pci_acs_init of_iommu_configure pci_request_acs The pci_request_acs() does not work because the pci_acs_init and pci_enable_acs procedure has already finished, so the ACS is not enabled as expected. Besides, the ACS is enabled only if IOMMU is detected and the device is pci. So this fix 6bf6c24720d33 ("iommu/of: Request ACS from the PCI core when configuring IOMMU linkage"), add pci_enable_acs() and IOMMU check to make sure ACS is enabled for the pci_device. Xingang Wang (1): iommu/of: Fix request and enable ACS for of_iommu_configure drivers/iommu/of_iommu.c | 10 +- drivers/pci/pci.c| 2 +- include/linux/pci.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) -- 2.19.1 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu