From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit dbba197edf32209d110727a02d3a91de4c88520f category:feature bugzilla:NA CVE:NA
-------------------
Some places in the kernel check the iommu_group pointer in 'struct device' in order to find out whether a device is mapped by an IOMMU.
This is not good way to make this check, as the pointer will be moved to 'struct dev_iommu_data'. This way to make the check is also not very readable.
Introduce an explicit function to perform this check.
Acked-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Acked-by: Robin Murphy robin.murphy@arm.com Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- include/linux/device.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/include/linux/device.h b/include/linux/device.h index ee4ed3af30d0..cb9df20a9c97 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1090,6 +1090,16 @@ static inline struct device *kobj_to_dev(struct kobject *kobj) return container_of(kobj, struct device, kobj); }
+/** + * device_iommu_mapped - Returns true when the device DMA is translated + * by an IOMMU + * @dev: Device to perform the check on + */ +static inline bool device_iommu_mapped(struct device *dev) +{ + return (dev->iommu_group != NULL); +} + /* Get the wakeup routines, which depend on struct device */ #include <linux/pm_wakeup.h>
From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit 170ecbd5ff09aa9c8c1025a8563f76e01a24bb50 category:feature bugzilla:NA CVE:NA
-------------------
Use Use device_iommu_mapped() to check if the device is already mapped by an IOMMU.
Acked-by: Robin Murphy robin.murphy@arm.com Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/iommu/of_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 82b46d0de64e..8ca2f0ed2525 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -218,7 +218,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, * If we have reason to believe the IOMMU driver missed the initial * add_device callback for dev, replay it to get things in order. */ - if (ops && ops->add_device && dev->bus && !dev->iommu_group) + if (ops && ops->add_device && dev->bus && !device_iommu_mapped(dev)) err = ops->add_device(dev);
/* Ignore all other errors apart from EPROBE_DEFER */
From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit 13e6a84d697e8eb8b61a3fe55b4109a666c4851d category:feature bugzilla:NA CVE:NA
-------------------
Replace the iommu-check with a proper and readable function call.
Cc: Lorenzo Pieralisi lorenzo.pieralisi@arm.com Acked-by: Robin Murphy robin.murphy@arm.com Acked-by: Hanjun Guo hanjun.guo@linaro.org Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/acpi/arm64/iort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 9c03c8a49c23..9abb86c7044a 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -810,7 +810,7 @@ static inline int iort_add_device_replay(const struct iommu_ops *ops, { int err = 0;
- if (ops->add_device && dev->bus && !dev->iommu_group) + if (ops->add_device && dev->bus && !device_iommu_mapped(dev)) err = ops->add_device(dev);
return err;
From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit bf8763d8f8376e98ea2a8e0fc4803f25ff91393e category:feature bugzilla:NA CVE:NA
-------------------
Use the new function to replace the open-coded iommu check.
Cc: Benjamin Herrenschmidt benh@kernel.crashing.org Cc: Paul Mackerras paulus@samba.org Cc: Russell Currey ruscur@russell.cc Cc: Sam Bobroff sbobroff@linux.ibm.com Acked-by: Robin Murphy robin.murphy@arm.com Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/powerpc/kernel/eeh.c | 2 +- arch/powerpc/kernel/iommu.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c index d123cba0992d..8f43fec905be 100644 --- a/arch/powerpc/kernel/eeh.c +++ b/arch/powerpc/kernel/eeh.c @@ -1486,7 +1486,7 @@ static int dev_has_iommu_table(struct device *dev, void *data) if (!dev) return 0;
- if (dev->iommu_group) { + if (device_iommu_mapped(dev)) { *ppdev = pdev; return 1; } diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index f0dc680e659a..48d58d1dcac2 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1086,7 +1086,7 @@ int iommu_add_device(struct device *dev) if (!device_is_registered(dev)) return -ENOENT;
- if (dev->iommu_group) { + if (device_iommu_mapped(dev)) { pr_debug("%s: Skipping device %s with iommu group %d\n", __func__, dev_name(dev), iommu_group_id(dev->iommu_group)); @@ -1129,7 +1129,7 @@ void iommu_del_device(struct device *dev) * and we needn't detach them from the associated * IOMMU groups */ - if (!dev->iommu_group) { + if (!device_iommu_mapped(dev)) { pr_debug("iommu_tce: skipping device %s with no tbl\n", dev_name(dev)); return; @@ -1148,7 +1148,7 @@ static int tce_iommu_bus_notifier(struct notifier_block *nb, case BUS_NOTIFY_ADD_DEVICE: return iommu_add_device(dev); case BUS_NOTIFY_DEL_DEVICE: - if (dev->iommu_group) + if (device_iommu_mapped(dev)) iommu_del_device(dev); return 0; default:
From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit 05afde1a7ef3ddde5e7657b9faeb6347423a9acb category:feature bugzilla:NA CVE:NA
-------------------
Replace the dev->iommu_group check with a proper function call that better reprensents its purpose.
Cc: Mathias Nyman mathias.nyman@intel.com Acked-by: Robin Murphy robin.murphy@arm.com Acked-by: Mathias Nyman mathias.nyman@linux.intel.com Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/usb/host/xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 24d465cdf05c..9364b8283000 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -242,7 +242,7 @@ static void xhci_zero_64b_regs(struct xhci_hcd *xhci) * an iommu. Doing anything when there is no iommu is definitely * unsafe... */ - if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !dev->iommu_group) + if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !device_iommu_mapped(dev)) return;
xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n");
From: Joerg Roedel jroedel@suse.de
mainline inclusion from mainline-v4.20-rc1 commit f884f6ee62604aec60fe1760f94724be192d97c0 category:feature bugzilla:NA CVE:NA
-------------------
Use Use device_iommu_mapped() to check if the device is already mapped by an IOMMU.
Acked-by: Vinod Koul vkoul@kernel.org Signed-off-by: Joerg Roedel jroedel@suse.de Signed-off-by: Chen Jun chenjun102@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/dma/sh/rcar-dmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 80ff95f75199..bcefcc8704ef 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1831,7 +1831,7 @@ static int rcar_dmac_probe(struct platform_device *pdev) * level we can't disable it selectively, so ignore channel 0 for now if * the device is part of an IOMMU group. */ - if (pdev->dev.iommu_group) { + if (device_iommu_mapped(&pdev->dev)) { dmac->n_channels--; channels_offset = 1; }