* [PATCH v3 02/34] iommu: Add def_domain_type() callback in iommu_ops
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA, Sai Praneeth Prakhya,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Sai Praneeth Prakhya <sai.praneeth.prakhya-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Some devices are reqired to use a specific type (identity or dma)
of default domain when they are used with a vendor iommu. When the
system level default domain type is different from it, the vendor
iommu driver has to request a new default domain with
iommu_request_dma_domain_for_dev() and iommu_request_dm_for_dev()
in the add_dev() callback. Unfortunately, these two helpers only
work when the group hasn't been assigned to any other devices,
hence, some vendor iommu driver has to use a private domain if
it fails to request a new default one.
This adds def_domain_type() callback in the iommu_ops, so that
any special requirement of default domain for a device could be
aware by the iommu generic layer.
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Lu Baolu <baolu.lu-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
[ jroedel-l3A5Bk7waGM@public.gmane.org: Added iommu_get_def_domain_type() function and use
it to allocate the default domain ]
Co-developed-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/iommu.c | 20 +++++++++++++++++---
include/linux/iommu.h | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index bfe011760ed1..5877abd9b693 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1361,21 +1361,35 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
}
EXPORT_SYMBOL_GPL(fsl_mc_device_group);
+static int iommu_get_def_domain_type(struct device *dev)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ return (type == 0) ? iommu_def_domain_type : type;
+}
+
static int iommu_alloc_default_domain(struct device *dev,
struct iommu_group *group)
{
struct iommu_domain *dom;
+ unsigned int type;
if (group->default_domain)
return 0;
- dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type);
- if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) {
+ type = iommu_get_def_domain_type(dev);
+
+ dom = __iommu_domain_alloc(dev->bus, type);
+ if (!dom && type != IOMMU_DOMAIN_DMA) {
dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
if (dom) {
dev_warn(dev,
"failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- iommu_def_domain_type);
+ type);
}
}
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 7ef8b0bda695..1f027b07e499 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -248,6 +248,10 @@ struct iommu_iotlb_gather {
* @cache_invalidate: invalidate translation caches
* @sva_bind_gpasid: bind guest pasid and mm
* @sva_unbind_gpasid: unbind guest pasid and mm
+ * @def_domain_type: device default domain type, return value:
+ * - IOMMU_DOMAIN_IDENTITY: must use an identity domain
+ * - IOMMU_DOMAIN_DMA: must use a dma domain
+ * - 0: use the default setting
* @pgsize_bitmap: bitmap of all possible supported page sizes
* @owner: Driver module providing these ops
*/
@@ -318,6 +322,8 @@ struct iommu_ops {
int (*sva_unbind_gpasid)(struct device *dev, int pasid);
+ int (*def_domain_type)(struct device *dev);
+
unsigned long pgsize_bitmap;
struct module *owner;
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 02/34] iommu: Add def_domain_type() callback in iommu_ops
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, Sai Praneeth Prakhya,
linux-arm-msm, linux-kernel, Daniel Drake, linux-rockchip, iommu,
Joerg Roedel, linux-mediatek, linux-tegra, virtualization,
jonathan.derrick
From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Some devices are reqired to use a specific type (identity or dma)
of default domain when they are used with a vendor iommu. When the
system level default domain type is different from it, the vendor
iommu driver has to request a new default domain with
iommu_request_dma_domain_for_dev() and iommu_request_dm_for_dev()
in the add_dev() callback. Unfortunately, these two helpers only
work when the group hasn't been assigned to any other devices,
hence, some vendor iommu driver has to use a private domain if
it fails to request a new default one.
This adds def_domain_type() callback in the iommu_ops, so that
any special requirement of default domain for a device could be
aware by the iommu generic layer.
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
[ jroedel@suse.de: Added iommu_get_def_domain_type() function and use
it to allocate the default domain ]
Co-developed-by: Joerg Roedel <jroedel@suse.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 20 +++++++++++++++++---
include/linux/iommu.h | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index bfe011760ed1..5877abd9b693 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1361,21 +1361,35 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
}
EXPORT_SYMBOL_GPL(fsl_mc_device_group);
+static int iommu_get_def_domain_type(struct device *dev)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ return (type == 0) ? iommu_def_domain_type : type;
+}
+
static int iommu_alloc_default_domain(struct device *dev,
struct iommu_group *group)
{
struct iommu_domain *dom;
+ unsigned int type;
if (group->default_domain)
return 0;
- dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type);
- if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) {
+ type = iommu_get_def_domain_type(dev);
+
+ dom = __iommu_domain_alloc(dev->bus, type);
+ if (!dom && type != IOMMU_DOMAIN_DMA) {
dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
if (dom) {
dev_warn(dev,
"failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- iommu_def_domain_type);
+ type);
}
}
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 7ef8b0bda695..1f027b07e499 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -248,6 +248,10 @@ struct iommu_iotlb_gather {
* @cache_invalidate: invalidate translation caches
* @sva_bind_gpasid: bind guest pasid and mm
* @sva_unbind_gpasid: unbind guest pasid and mm
+ * @def_domain_type: device default domain type, return value:
+ * - IOMMU_DOMAIN_IDENTITY: must use an identity domain
+ * - IOMMU_DOMAIN_DMA: must use a dma domain
+ * - 0: use the default setting
* @pgsize_bitmap: bitmap of all possible supported page sizes
* @owner: Driver module providing these ops
*/
@@ -318,6 +322,8 @@ struct iommu_ops {
int (*sva_unbind_gpasid)(struct device *dev, int pasid);
+ int (*def_domain_type)(struct device *dev);
+
unsigned long pgsize_bitmap;
struct module *owner;
};
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 02/34] iommu: Add def_domain_type() callback in iommu_ops
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Some devices are reqired to use a specific type (identity or dma)
of default domain when they are used with a vendor iommu. When the
system level default domain type is different from it, the vendor
iommu driver has to request a new default domain with
iommu_request_dma_domain_for_dev() and iommu_request_dm_for_dev()
in the add_dev() callback. Unfortunately, these two helpers only
work when the group hasn't been assigned to any other devices,
hence, some vendor iommu driver has to use a private domain if
it fails to request a new default one.
This adds def_domain_type() callback in the iommu_ops, so that
any special requirement of default domain for a device could be
aware by the iommu generic layer.
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
[ jroedel@suse.de: Added iommu_get_def_domain_type() function and use
it to allocate the default domain ]
Co-developed-by: Joerg Roedel <jroedel@suse.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 20 +++++++++++++++++---
include/linux/iommu.h | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index bfe011760ed1..5877abd9b693 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1361,21 +1361,35 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
}
EXPORT_SYMBOL_GPL(fsl_mc_device_group);
+static int iommu_get_def_domain_type(struct device *dev)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ return (type == 0) ? iommu_def_domain_type : type;
+}
+
static int iommu_alloc_default_domain(struct device *dev,
struct iommu_group *group)
{
struct iommu_domain *dom;
+ unsigned int type;
if (group->default_domain)
return 0;
- dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type);
- if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) {
+ type = iommu_get_def_domain_type(dev);
+
+ dom = __iommu_domain_alloc(dev->bus, type);
+ if (!dom && type != IOMMU_DOMAIN_DMA) {
dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
if (dom) {
dev_warn(dev,
"failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- iommu_def_domain_type);
+ type);
}
}
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 7ef8b0bda695..1f027b07e499 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -248,6 +248,10 @@ struct iommu_iotlb_gather {
* @cache_invalidate: invalidate translation caches
* @sva_bind_gpasid: bind guest pasid and mm
* @sva_unbind_gpasid: unbind guest pasid and mm
+ * @def_domain_type: device default domain type, return value:
+ * - IOMMU_DOMAIN_IDENTITY: must use an identity domain
+ * - IOMMU_DOMAIN_DMA: must use a dma domain
+ * - 0: use the default setting
* @pgsize_bitmap: bitmap of all possible supported page sizes
* @owner: Driver module providing these ops
*/
@@ -318,6 +322,8 @@ struct iommu_ops {
int (*sva_unbind_gpasid)(struct device *dev, int pasid);
+ int (*def_domain_type)(struct device *dev);
+
unsigned long pgsize_bitmap;
struct module *owner;
};
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 02/34] iommu: Add def_domain_type() callback in iommu_ops
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Sai Praneeth Prakhya,
Joerg Roedel
From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Some devices are reqired to use a specific type (identity or dma)
of default domain when they are used with a vendor iommu. When the
system level default domain type is different from it, the vendor
iommu driver has to request a new default domain with
iommu_request_dma_domain_for_dev() and iommu_request_dm_for_dev()
in the add_dev() callback. Unfortunately, these two helpers only
work when the group hasn't been assigned to any other devices,
hence, some vendor iommu driver has to use a private domain if
it fails to request a new default one.
This adds def_domain_type() callback in the iommu_ops, so that
any special requirement of default domain for a device could be
aware by the iommu generic layer.
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
[ jroedel@suse.de: Added iommu_get_def_domain_type() function and use
it to allocate the default domain ]
Co-developed-by: Joerg Roedel <jroedel@suse.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 20 +++++++++++++++++---
include/linux/iommu.h | 6 ++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index bfe011760ed1..5877abd9b693 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1361,21 +1361,35 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
}
EXPORT_SYMBOL_GPL(fsl_mc_device_group);
+static int iommu_get_def_domain_type(struct device *dev)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ return (type == 0) ? iommu_def_domain_type : type;
+}
+
static int iommu_alloc_default_domain(struct device *dev,
struct iommu_group *group)
{
struct iommu_domain *dom;
+ unsigned int type;
if (group->default_domain)
return 0;
- dom = __iommu_domain_alloc(dev->bus, iommu_def_domain_type);
- if (!dom && iommu_def_domain_type != IOMMU_DOMAIN_DMA) {
+ type = iommu_get_def_domain_type(dev);
+
+ dom = __iommu_domain_alloc(dev->bus, type);
+ if (!dom && type != IOMMU_DOMAIN_DMA) {
dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
if (dom) {
dev_warn(dev,
"failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- iommu_def_domain_type);
+ type);
}
}
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 7ef8b0bda695..1f027b07e499 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -248,6 +248,10 @@ struct iommu_iotlb_gather {
* @cache_invalidate: invalidate translation caches
* @sva_bind_gpasid: bind guest pasid and mm
* @sva_unbind_gpasid: unbind guest pasid and mm
+ * @def_domain_type: device default domain type, return value:
+ * - IOMMU_DOMAIN_IDENTITY: must use an identity domain
+ * - IOMMU_DOMAIN_DMA: must use a dma domain
+ * - 0: use the default setting
* @pgsize_bitmap: bitmap of all possible supported page sizes
* @owner: Driver module providing these ops
*/
@@ -318,6 +322,8 @@ struct iommu_ops {
int (*sva_unbind_gpasid)(struct device *dev, int pasid);
+ int (*def_domain_type)(struct device *dev);
+
unsigned long pgsize_bitmap;
struct module *owner;
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 05/34] iommu/amd: Remove dma_mask check from check_device()
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
The check was only needed for the DMA-API implementation in the AMD
IOMMU driver, which no longer exists.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 73b4f84cf449..504f2db75eda 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -326,7 +326,7 @@ static bool check_device(struct device *dev)
{
int devid;
- if (!dev || !dev->dma_mask)
+ if (!dev)
return false;
devid = get_device_id(dev);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 05/34] iommu/amd: Remove dma_mask check from check_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
The check was only needed for the DMA-API implementation in the AMD
IOMMU driver, which no longer exists.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 73b4f84cf449..504f2db75eda 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -326,7 +326,7 @@ static bool check_device(struct device *dev)
{
int devid;
- if (!dev || !dev->dma_mask)
+ if (!dev)
return false;
devid = get_device_id(dev);
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 05/34] iommu/amd: Remove dma_mask check from check_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
The check was only needed for the DMA-API implementation in the AMD
IOMMU driver, which no longer exists.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 73b4f84cf449..504f2db75eda 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -326,7 +326,7 @@ static bool check_device(struct device *dev)
{
int devid;
- if (!dev || !dev->dma_mask)
+ if (!dev)
return false;
devid = get_device_id(dev);
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 05/34] iommu/amd: Remove dma_mask check from check_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
The check was only needed for the DMA-API implementation in the AMD
IOMMU driver, which no longer exists.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 73b4f84cf449..504f2db75eda 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -326,7 +326,7 @@ static bool check_device(struct device *dev)
{
int devid;
- if (!dev || !dev->dma_mask)
+ if (!dev)
return false;
devid = get_device_id(dev);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 06/34] iommu/amd: Return -ENODEV in add_device when device is not handled by IOMMU
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
When check_device() fails on the device, it is not handled by the
IOMMU and amd_iommu_add_device() needs to return -ENODEV.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 504f2db75eda..3e0d27f7622e 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2157,9 +2157,12 @@ static int amd_iommu_add_device(struct device *dev)
struct amd_iommu *iommu;
int ret, devid;
- if (!check_device(dev) || get_dev_data(dev))
+ if (get_dev_data(dev))
return 0;
+ if (!check_device(dev))
+ return -ENODEV;
+
devid = get_device_id(dev);
if (devid < 0)
return devid;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 06/34] iommu/amd: Return -ENODEV in add_device when device is not handled by IOMMU
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
When check_device() fails on the device, it is not handled by the
IOMMU and amd_iommu_add_device() needs to return -ENODEV.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 504f2db75eda..3e0d27f7622e 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2157,9 +2157,12 @@ static int amd_iommu_add_device(struct device *dev)
struct amd_iommu *iommu;
int ret, devid;
- if (!check_device(dev) || get_dev_data(dev))
+ if (get_dev_data(dev))
return 0;
+ if (!check_device(dev))
+ return -ENODEV;
+
devid = get_device_id(dev);
if (devid < 0)
return devid;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 06/34] iommu/amd: Return -ENODEV in add_device when device is not handled by IOMMU
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
When check_device() fails on the device, it is not handled by the
IOMMU and amd_iommu_add_device() needs to return -ENODEV.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 504f2db75eda..3e0d27f7622e 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2157,9 +2157,12 @@ static int amd_iommu_add_device(struct device *dev)
struct amd_iommu *iommu;
int ret, devid;
- if (!check_device(dev) || get_dev_data(dev))
+ if (get_dev_data(dev))
return 0;
+ if (!check_device(dev))
+ return -ENODEV;
+
devid = get_device_id(dev);
if (devid < 0)
return devid;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 06/34] iommu/amd: Return -ENODEV in add_device when device is not handled by IOMMU
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
When check_device() fails on the device, it is not handled by the
IOMMU and amd_iommu_add_device() needs to return -ENODEV.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 504f2db75eda..3e0d27f7622e 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2157,9 +2157,12 @@ static int amd_iommu_add_device(struct device *dev)
struct amd_iommu *iommu;
int ret, devid;
- if (!check_device(dev) || get_dev_data(dev))
+ if (get_dev_data(dev))
return 0;
+ if (!check_device(dev))
+ return -ENODEV;
+
devid = get_device_id(dev);
if (devid < 0)
return devid;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 08/34] iommu: Move default domain allocation to iommu_probe_device()
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Well, not really. The call to iommu_alloc_default_domain() in
iommu_group_get_for_dev() has to stay around as long as there are
IOMMU drivers using the add/remove_device() call-backs instead of
probe/release_device().
Those drivers expect that iommu_group_get_for_dev() returns the device
attached to a group and the group set up with a default domain (and
the device attached to the groups current domain).
But when all drivers are converted this compatability mess can be
removed.
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/iommu.c | 102 +++++++++++++++++++++++++++++-------------
1 file changed, 71 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 6cfe7799dc8c..7a385c18e1a5 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -79,6 +79,16 @@ static bool iommu_cmd_line_dma_api(void)
return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
}
+static int iommu_alloc_default_domain(struct device *dev);
+static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
+ unsigned type);
+static int __iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev);
+static int __iommu_attach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+static void __iommu_detach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+
#define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \
struct iommu_group_attribute iommu_group_attr_##_name = \
__ATTR(_name, _mode, _show, _store)
@@ -221,10 +231,29 @@ int iommu_probe_device(struct device *dev)
goto err_free_dev_param;
}
- if (ops->probe_device)
+ if (ops->probe_device) {
+ struct iommu_group *group;
+
ret = __iommu_probe_device(dev);
- else
+
+ /*
+ * Try to allocate a default domain - needs support from the
+ * IOMMU driver. There are still some drivers which don't
+ * support default domains, so the return value is not yet
+ * checked.
+ */
+ if (!ret)
+ iommu_alloc_default_domain(dev);
+
+ group = iommu_group_get(dev);
+ if (group && group->default_domain) {
+ ret = __iommu_attach_device(group->default_domain, dev);
+ iommu_group_put(group);
+ }
+
+ } else {
ret = ops->add_device(dev);
+ }
if (ret)
goto err_module_put;
@@ -268,15 +297,6 @@ void iommu_release_device(struct device *dev)
dev_iommu_free(dev);
}
-static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
- unsigned type);
-static int __iommu_attach_device(struct iommu_domain *domain,
- struct device *dev);
-static int __iommu_attach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-static void __iommu_detach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-
static int __init iommu_set_def_domain_type(char *str)
{
bool pt;
@@ -1423,25 +1443,18 @@ static int iommu_get_def_domain_type(struct device *dev)
return (type == 0) ? iommu_def_domain_type : type;
}
-static int iommu_alloc_default_domain(struct device *dev,
- struct iommu_group *group)
+static int iommu_group_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group,
+ unsigned int type)
{
struct iommu_domain *dom;
- unsigned int type;
-
- if (group->default_domain)
- return 0;
- type = iommu_get_def_domain_type(dev);
-
- dom = __iommu_domain_alloc(dev->bus, type);
+ dom = __iommu_domain_alloc(bus, type);
if (!dom && type != IOMMU_DOMAIN_DMA) {
- dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
- if (dom) {
- dev_warn(dev,
- "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- type);
- }
+ dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
+ if (dom)
+ pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
+ type, group->name);
}
if (!dom)
@@ -1461,6 +1474,23 @@ static int iommu_alloc_default_domain(struct device *dev,
return 0;
}
+static int iommu_alloc_default_domain(struct device *dev)
+{
+ struct iommu_group *group;
+ unsigned int type;
+
+ group = iommu_group_get(dev);
+ if (!group)
+ return -ENODEV;
+
+ if (group->default_domain)
+ return 0;
+
+ type = iommu_get_def_domain_type(dev);
+
+ return iommu_group_alloc_default_domain(dev->bus, group, type);
+}
+
/**
* iommu_group_get_for_dev - Find or create the IOMMU group for a device
* @dev: target device
@@ -1491,16 +1521,26 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (IS_ERR(group))
return group;
+ ret = iommu_group_add_device(group, dev);
+ if (ret)
+ goto out_put_group;
+
/*
* Try to allocate a default domain - needs support from the
* IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked.
+ * default domains, so the return value is not yet checked. Only
+ * allocate the domain here when the driver still has the
+ * add_device/remove_device call-backs implemented.
*/
- iommu_alloc_default_domain(dev, group);
+ if (!ops->probe_device) {
+ iommu_alloc_default_domain(dev);
- ret = iommu_group_add_device(group, dev);
- if (ret)
- goto out_put_group;
+ if (group->default_domain)
+ ret = __iommu_attach_device(group->default_domain, dev);
+
+ if (ret)
+ goto out_put_group;
+ }
return group;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 08/34] iommu: Move default domain allocation to iommu_probe_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Well, not really. The call to iommu_alloc_default_domain() in
iommu_group_get_for_dev() has to stay around as long as there are
IOMMU drivers using the add/remove_device() call-backs instead of
probe/release_device().
Those drivers expect that iommu_group_get_for_dev() returns the device
attached to a group and the group set up with a default domain (and
the device attached to the groups current domain).
But when all drivers are converted this compatability mess can be
removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 102 +++++++++++++++++++++++++++++-------------
1 file changed, 71 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 6cfe7799dc8c..7a385c18e1a5 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -79,6 +79,16 @@ static bool iommu_cmd_line_dma_api(void)
return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
}
+static int iommu_alloc_default_domain(struct device *dev);
+static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
+ unsigned type);
+static int __iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev);
+static int __iommu_attach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+static void __iommu_detach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+
#define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \
struct iommu_group_attribute iommu_group_attr_##_name = \
__ATTR(_name, _mode, _show, _store)
@@ -221,10 +231,29 @@ int iommu_probe_device(struct device *dev)
goto err_free_dev_param;
}
- if (ops->probe_device)
+ if (ops->probe_device) {
+ struct iommu_group *group;
+
ret = __iommu_probe_device(dev);
- else
+
+ /*
+ * Try to allocate a default domain - needs support from the
+ * IOMMU driver. There are still some drivers which don't
+ * support default domains, so the return value is not yet
+ * checked.
+ */
+ if (!ret)
+ iommu_alloc_default_domain(dev);
+
+ group = iommu_group_get(dev);
+ if (group && group->default_domain) {
+ ret = __iommu_attach_device(group->default_domain, dev);
+ iommu_group_put(group);
+ }
+
+ } else {
ret = ops->add_device(dev);
+ }
if (ret)
goto err_module_put;
@@ -268,15 +297,6 @@ void iommu_release_device(struct device *dev)
dev_iommu_free(dev);
}
-static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
- unsigned type);
-static int __iommu_attach_device(struct iommu_domain *domain,
- struct device *dev);
-static int __iommu_attach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-static void __iommu_detach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-
static int __init iommu_set_def_domain_type(char *str)
{
bool pt;
@@ -1423,25 +1443,18 @@ static int iommu_get_def_domain_type(struct device *dev)
return (type == 0) ? iommu_def_domain_type : type;
}
-static int iommu_alloc_default_domain(struct device *dev,
- struct iommu_group *group)
+static int iommu_group_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group,
+ unsigned int type)
{
struct iommu_domain *dom;
- unsigned int type;
-
- if (group->default_domain)
- return 0;
- type = iommu_get_def_domain_type(dev);
-
- dom = __iommu_domain_alloc(dev->bus, type);
+ dom = __iommu_domain_alloc(bus, type);
if (!dom && type != IOMMU_DOMAIN_DMA) {
- dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
- if (dom) {
- dev_warn(dev,
- "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- type);
- }
+ dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
+ if (dom)
+ pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
+ type, group->name);
}
if (!dom)
@@ -1461,6 +1474,23 @@ static int iommu_alloc_default_domain(struct device *dev,
return 0;
}
+static int iommu_alloc_default_domain(struct device *dev)
+{
+ struct iommu_group *group;
+ unsigned int type;
+
+ group = iommu_group_get(dev);
+ if (!group)
+ return -ENODEV;
+
+ if (group->default_domain)
+ return 0;
+
+ type = iommu_get_def_domain_type(dev);
+
+ return iommu_group_alloc_default_domain(dev->bus, group, type);
+}
+
/**
* iommu_group_get_for_dev - Find or create the IOMMU group for a device
* @dev: target device
@@ -1491,16 +1521,26 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (IS_ERR(group))
return group;
+ ret = iommu_group_add_device(group, dev);
+ if (ret)
+ goto out_put_group;
+
/*
* Try to allocate a default domain - needs support from the
* IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked.
+ * default domains, so the return value is not yet checked. Only
+ * allocate the domain here when the driver still has the
+ * add_device/remove_device call-backs implemented.
*/
- iommu_alloc_default_domain(dev, group);
+ if (!ops->probe_device) {
+ iommu_alloc_default_domain(dev);
- ret = iommu_group_add_device(group, dev);
- if (ret)
- goto out_put_group;
+ if (group->default_domain)
+ ret = __iommu_attach_device(group->default_domain, dev);
+
+ if (ret)
+ goto out_put_group;
+ }
return group;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 08/34] iommu: Move default domain allocation to iommu_probe_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Well, not really. The call to iommu_alloc_default_domain() in
iommu_group_get_for_dev() has to stay around as long as there are
IOMMU drivers using the add/remove_device() call-backs instead of
probe/release_device().
Those drivers expect that iommu_group_get_for_dev() returns the device
attached to a group and the group set up with a default domain (and
the device attached to the groups current domain).
But when all drivers are converted this compatability mess can be
removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 102 +++++++++++++++++++++++++++++-------------
1 file changed, 71 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 6cfe7799dc8c..7a385c18e1a5 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -79,6 +79,16 @@ static bool iommu_cmd_line_dma_api(void)
return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
}
+static int iommu_alloc_default_domain(struct device *dev);
+static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
+ unsigned type);
+static int __iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev);
+static int __iommu_attach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+static void __iommu_detach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+
#define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \
struct iommu_group_attribute iommu_group_attr_##_name = \
__ATTR(_name, _mode, _show, _store)
@@ -221,10 +231,29 @@ int iommu_probe_device(struct device *dev)
goto err_free_dev_param;
}
- if (ops->probe_device)
+ if (ops->probe_device) {
+ struct iommu_group *group;
+
ret = __iommu_probe_device(dev);
- else
+
+ /*
+ * Try to allocate a default domain - needs support from the
+ * IOMMU driver. There are still some drivers which don't
+ * support default domains, so the return value is not yet
+ * checked.
+ */
+ if (!ret)
+ iommu_alloc_default_domain(dev);
+
+ group = iommu_group_get(dev);
+ if (group && group->default_domain) {
+ ret = __iommu_attach_device(group->default_domain, dev);
+ iommu_group_put(group);
+ }
+
+ } else {
ret = ops->add_device(dev);
+ }
if (ret)
goto err_module_put;
@@ -268,15 +297,6 @@ void iommu_release_device(struct device *dev)
dev_iommu_free(dev);
}
-static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
- unsigned type);
-static int __iommu_attach_device(struct iommu_domain *domain,
- struct device *dev);
-static int __iommu_attach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-static void __iommu_detach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-
static int __init iommu_set_def_domain_type(char *str)
{
bool pt;
@@ -1423,25 +1443,18 @@ static int iommu_get_def_domain_type(struct device *dev)
return (type == 0) ? iommu_def_domain_type : type;
}
-static int iommu_alloc_default_domain(struct device *dev,
- struct iommu_group *group)
+static int iommu_group_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group,
+ unsigned int type)
{
struct iommu_domain *dom;
- unsigned int type;
-
- if (group->default_domain)
- return 0;
- type = iommu_get_def_domain_type(dev);
-
- dom = __iommu_domain_alloc(dev->bus, type);
+ dom = __iommu_domain_alloc(bus, type);
if (!dom && type != IOMMU_DOMAIN_DMA) {
- dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
- if (dom) {
- dev_warn(dev,
- "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- type);
- }
+ dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
+ if (dom)
+ pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
+ type, group->name);
}
if (!dom)
@@ -1461,6 +1474,23 @@ static int iommu_alloc_default_domain(struct device *dev,
return 0;
}
+static int iommu_alloc_default_domain(struct device *dev)
+{
+ struct iommu_group *group;
+ unsigned int type;
+
+ group = iommu_group_get(dev);
+ if (!group)
+ return -ENODEV;
+
+ if (group->default_domain)
+ return 0;
+
+ type = iommu_get_def_domain_type(dev);
+
+ return iommu_group_alloc_default_domain(dev->bus, group, type);
+}
+
/**
* iommu_group_get_for_dev - Find or create the IOMMU group for a device
* @dev: target device
@@ -1491,16 +1521,26 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (IS_ERR(group))
return group;
+ ret = iommu_group_add_device(group, dev);
+ if (ret)
+ goto out_put_group;
+
/*
* Try to allocate a default domain - needs support from the
* IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked.
+ * default domains, so the return value is not yet checked. Only
+ * allocate the domain here when the driver still has the
+ * add_device/remove_device call-backs implemented.
*/
- iommu_alloc_default_domain(dev, group);
+ if (!ops->probe_device) {
+ iommu_alloc_default_domain(dev);
- ret = iommu_group_add_device(group, dev);
- if (ret)
- goto out_put_group;
+ if (group->default_domain)
+ ret = __iommu_attach_device(group->default_domain, dev);
+
+ if (ret)
+ goto out_put_group;
+ }
return group;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 08/34] iommu: Move default domain allocation to iommu_probe_device()
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Well, not really. The call to iommu_alloc_default_domain() in
iommu_group_get_for_dev() has to stay around as long as there are
IOMMU drivers using the add/remove_device() call-backs instead of
probe/release_device().
Those drivers expect that iommu_group_get_for_dev() returns the device
attached to a group and the group set up with a default domain (and
the device attached to the groups current domain).
But when all drivers are converted this compatability mess can be
removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 102 +++++++++++++++++++++++++++++-------------
1 file changed, 71 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 6cfe7799dc8c..7a385c18e1a5 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -79,6 +79,16 @@ static bool iommu_cmd_line_dma_api(void)
return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
}
+static int iommu_alloc_default_domain(struct device *dev);
+static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
+ unsigned type);
+static int __iommu_attach_device(struct iommu_domain *domain,
+ struct device *dev);
+static int __iommu_attach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+static void __iommu_detach_group(struct iommu_domain *domain,
+ struct iommu_group *group);
+
#define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \
struct iommu_group_attribute iommu_group_attr_##_name = \
__ATTR(_name, _mode, _show, _store)
@@ -221,10 +231,29 @@ int iommu_probe_device(struct device *dev)
goto err_free_dev_param;
}
- if (ops->probe_device)
+ if (ops->probe_device) {
+ struct iommu_group *group;
+
ret = __iommu_probe_device(dev);
- else
+
+ /*
+ * Try to allocate a default domain - needs support from the
+ * IOMMU driver. There are still some drivers which don't
+ * support default domains, so the return value is not yet
+ * checked.
+ */
+ if (!ret)
+ iommu_alloc_default_domain(dev);
+
+ group = iommu_group_get(dev);
+ if (group && group->default_domain) {
+ ret = __iommu_attach_device(group->default_domain, dev);
+ iommu_group_put(group);
+ }
+
+ } else {
ret = ops->add_device(dev);
+ }
if (ret)
goto err_module_put;
@@ -268,15 +297,6 @@ void iommu_release_device(struct device *dev)
dev_iommu_free(dev);
}
-static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
- unsigned type);
-static int __iommu_attach_device(struct iommu_domain *domain,
- struct device *dev);
-static int __iommu_attach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-static void __iommu_detach_group(struct iommu_domain *domain,
- struct iommu_group *group);
-
static int __init iommu_set_def_domain_type(char *str)
{
bool pt;
@@ -1423,25 +1443,18 @@ static int iommu_get_def_domain_type(struct device *dev)
return (type == 0) ? iommu_def_domain_type : type;
}
-static int iommu_alloc_default_domain(struct device *dev,
- struct iommu_group *group)
+static int iommu_group_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group,
+ unsigned int type)
{
struct iommu_domain *dom;
- unsigned int type;
-
- if (group->default_domain)
- return 0;
- type = iommu_get_def_domain_type(dev);
-
- dom = __iommu_domain_alloc(dev->bus, type);
+ dom = __iommu_domain_alloc(bus, type);
if (!dom && type != IOMMU_DOMAIN_DMA) {
- dom = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_DMA);
- if (dom) {
- dev_warn(dev,
- "failed to allocate default IOMMU domain of type %u; falling back to IOMMU_DOMAIN_DMA",
- type);
- }
+ dom = __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA);
+ if (dom)
+ pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_DOMAIN_DMA",
+ type, group->name);
}
if (!dom)
@@ -1461,6 +1474,23 @@ static int iommu_alloc_default_domain(struct device *dev,
return 0;
}
+static int iommu_alloc_default_domain(struct device *dev)
+{
+ struct iommu_group *group;
+ unsigned int type;
+
+ group = iommu_group_get(dev);
+ if (!group)
+ return -ENODEV;
+
+ if (group->default_domain)
+ return 0;
+
+ type = iommu_get_def_domain_type(dev);
+
+ return iommu_group_alloc_default_domain(dev->bus, group, type);
+}
+
/**
* iommu_group_get_for_dev - Find or create the IOMMU group for a device
* @dev: target device
@@ -1491,16 +1521,26 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (IS_ERR(group))
return group;
+ ret = iommu_group_add_device(group, dev);
+ if (ret)
+ goto out_put_group;
+
/*
* Try to allocate a default domain - needs support from the
* IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked.
+ * default domains, so the return value is not yet checked. Only
+ * allocate the domain here when the driver still has the
+ * add_device/remove_device call-backs implemented.
*/
- iommu_alloc_default_domain(dev, group);
+ if (!ops->probe_device) {
+ iommu_alloc_default_domain(dev);
- ret = iommu_group_add_device(group, dev);
- if (ret)
- goto out_put_group;
+ if (group->default_domain)
+ ret = __iommu_attach_device(group->default_domain, dev);
+
+ if (ret)
+ goto out_put_group;
+ }
return group;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 11/34] iommu: Split off default domain allocation from group assignment
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
When a bus is initialized with iommu-ops, all devices on the bus are
scanned and iommu-groups are allocated for them, and each groups will
also get a default domain allocated.
Until now this happened as soon as the group was created and the first
device added to it. When other devices with different default domain
requirements were added to the group later on, the default domain was
re-allocated, if possible.
This resulted in some back and forth and unnecessary allocations, so
change the flow to defer default domain allocation until all devices
have been added to their respective IOMMU groups.
The default domains are allocated for newly allocated groups after
each device on the bus is handled and was probed by the IOMMU driver.
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/iommu.c | 154 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 151 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8be047a4808f..7de0e29db333 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -199,7 +199,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
dev->iommu->iommu_dev = iommu_dev;
group = iommu_group_get_for_dev(dev);
- if (!IS_ERR(group)) {
+ if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto out_release;
}
@@ -1599,6 +1599,37 @@ static int add_iommu_group(struct device *dev, void *data)
return ret;
}
+static int probe_iommu_group(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct list_head *group_list = data;
+ int ret;
+
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_free_dev_iommu;
+ }
+
+ ret = __iommu_probe_device(dev, group_list);
+ if (ret)
+ goto err_module_put;
+
+ return 0;
+
+err_module_put:
+ module_put(ops->owner);
+err_free_dev_iommu:
+ dev_iommu_free(dev);
+
+ if (ret == -ENODEV)
+ ret = 0;
+
+ return ret;
+}
+
static int remove_iommu_group(struct device *dev, void *data)
{
iommu_release_device(dev);
@@ -1658,10 +1689,127 @@ static int iommu_bus_notifier(struct notifier_block *nb,
return 0;
}
+struct __group_domain_type {
+ struct device *dev;
+ unsigned int type;
+};
+
+static int probe_get_default_domain_type(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct __group_domain_type *gtype = data;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ if (type) {
+ if (gtype->type && gtype->type != type) {
+ dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
+ iommu_domain_type_str(type),
+ dev_name(gtype->dev),
+ iommu_domain_type_str(gtype->type));
+ gtype->type = 0;
+ }
+
+ if (!gtype->dev) {
+ gtype->dev = dev;
+ gtype->type = type;
+ }
+ }
+
+ return 0;
+}
+
+static void probe_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group)
+{
+ struct __group_domain_type gtype;
+
+ memset(>ype, 0, sizeof(gtype));
+
+ /* Ask for default domain requirements of all devices in the group */
+ __iommu_group_for_each_dev(group, >ype,
+ probe_get_default_domain_type);
+
+ if (!gtype.type)
+ gtype.type = iommu_def_domain_type;
+
+ iommu_group_alloc_default_domain(bus, group, gtype.type);
+}
+
+static int iommu_group_do_dma_attach(struct device *dev, void *data)
+{
+ struct iommu_domain *domain = data;
+ const struct iommu_ops *ops;
+ int ret;
+
+ ret = __iommu_attach_device(domain, dev);
+
+ ops = domain->ops;
+
+ if (ret == 0 && ops->probe_finalize)
+ ops->probe_finalize(dev);
+
+ return ret;
+}
+
+static int __iommu_group_dma_attach(struct iommu_group *group)
+{
+ return __iommu_group_for_each_dev(group, group->default_domain,
+ iommu_group_do_dma_attach);
+}
+
+static int bus_iommu_probe(struct bus_type *bus)
+{
+ const struct iommu_ops *ops = bus->iommu_ops;
+ int ret;
+
+ if (ops->probe_device) {
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
+
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
+
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
+
+ mutex_lock(&group->mutex);
+
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
+
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
+
+ ret = __iommu_group_dma_attach(group);
+
+ mutex_unlock(&group->mutex);
+
+ if (ret)
+ break;
+ }
+ } else {
+ ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ }
+
+ return ret;
+}
+
static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
{
- int err;
struct notifier_block *nb;
+ int err;
nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
if (!nb)
@@ -1673,7 +1821,7 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
if (err)
goto out_free;
- err = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ err = bus_iommu_probe(bus);
if (err)
goto out_err;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 11/34] iommu: Split off default domain allocation from group assignment
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
When a bus is initialized with iommu-ops, all devices on the bus are
scanned and iommu-groups are allocated for them, and each groups will
also get a default domain allocated.
Until now this happened as soon as the group was created and the first
device added to it. When other devices with different default domain
requirements were added to the group later on, the default domain was
re-allocated, if possible.
This resulted in some back and forth and unnecessary allocations, so
change the flow to defer default domain allocation until all devices
have been added to their respective IOMMU groups.
The default domains are allocated for newly allocated groups after
each device on the bus is handled and was probed by the IOMMU driver.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 154 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 151 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8be047a4808f..7de0e29db333 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -199,7 +199,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
dev->iommu->iommu_dev = iommu_dev;
group = iommu_group_get_for_dev(dev);
- if (!IS_ERR(group)) {
+ if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto out_release;
}
@@ -1599,6 +1599,37 @@ static int add_iommu_group(struct device *dev, void *data)
return ret;
}
+static int probe_iommu_group(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct list_head *group_list = data;
+ int ret;
+
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_free_dev_iommu;
+ }
+
+ ret = __iommu_probe_device(dev, group_list);
+ if (ret)
+ goto err_module_put;
+
+ return 0;
+
+err_module_put:
+ module_put(ops->owner);
+err_free_dev_iommu:
+ dev_iommu_free(dev);
+
+ if (ret == -ENODEV)
+ ret = 0;
+
+ return ret;
+}
+
static int remove_iommu_group(struct device *dev, void *data)
{
iommu_release_device(dev);
@@ -1658,10 +1689,127 @@ static int iommu_bus_notifier(struct notifier_block *nb,
return 0;
}
+struct __group_domain_type {
+ struct device *dev;
+ unsigned int type;
+};
+
+static int probe_get_default_domain_type(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct __group_domain_type *gtype = data;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ if (type) {
+ if (gtype->type && gtype->type != type) {
+ dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
+ iommu_domain_type_str(type),
+ dev_name(gtype->dev),
+ iommu_domain_type_str(gtype->type));
+ gtype->type = 0;
+ }
+
+ if (!gtype->dev) {
+ gtype->dev = dev;
+ gtype->type = type;
+ }
+ }
+
+ return 0;
+}
+
+static void probe_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group)
+{
+ struct __group_domain_type gtype;
+
+ memset(>ype, 0, sizeof(gtype));
+
+ /* Ask for default domain requirements of all devices in the group */
+ __iommu_group_for_each_dev(group, >ype,
+ probe_get_default_domain_type);
+
+ if (!gtype.type)
+ gtype.type = iommu_def_domain_type;
+
+ iommu_group_alloc_default_domain(bus, group, gtype.type);
+}
+
+static int iommu_group_do_dma_attach(struct device *dev, void *data)
+{
+ struct iommu_domain *domain = data;
+ const struct iommu_ops *ops;
+ int ret;
+
+ ret = __iommu_attach_device(domain, dev);
+
+ ops = domain->ops;
+
+ if (ret == 0 && ops->probe_finalize)
+ ops->probe_finalize(dev);
+
+ return ret;
+}
+
+static int __iommu_group_dma_attach(struct iommu_group *group)
+{
+ return __iommu_group_for_each_dev(group, group->default_domain,
+ iommu_group_do_dma_attach);
+}
+
+static int bus_iommu_probe(struct bus_type *bus)
+{
+ const struct iommu_ops *ops = bus->iommu_ops;
+ int ret;
+
+ if (ops->probe_device) {
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
+
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
+
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
+
+ mutex_lock(&group->mutex);
+
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
+
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
+
+ ret = __iommu_group_dma_attach(group);
+
+ mutex_unlock(&group->mutex);
+
+ if (ret)
+ break;
+ }
+ } else {
+ ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ }
+
+ return ret;
+}
+
static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
{
- int err;
struct notifier_block *nb;
+ int err;
nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
if (!nb)
@@ -1673,7 +1821,7 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
if (err)
goto out_free;
- err = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ err = bus_iommu_probe(bus);
if (err)
goto out_err;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 11/34] iommu: Split off default domain allocation from group assignment
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
When a bus is initialized with iommu-ops, all devices on the bus are
scanned and iommu-groups are allocated for them, and each groups will
also get a default domain allocated.
Until now this happened as soon as the group was created and the first
device added to it. When other devices with different default domain
requirements were added to the group later on, the default domain was
re-allocated, if possible.
This resulted in some back and forth and unnecessary allocations, so
change the flow to defer default domain allocation until all devices
have been added to their respective IOMMU groups.
The default domains are allocated for newly allocated groups after
each device on the bus is handled and was probed by the IOMMU driver.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 154 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 151 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8be047a4808f..7de0e29db333 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -199,7 +199,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
dev->iommu->iommu_dev = iommu_dev;
group = iommu_group_get_for_dev(dev);
- if (!IS_ERR(group)) {
+ if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto out_release;
}
@@ -1599,6 +1599,37 @@ static int add_iommu_group(struct device *dev, void *data)
return ret;
}
+static int probe_iommu_group(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct list_head *group_list = data;
+ int ret;
+
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_free_dev_iommu;
+ }
+
+ ret = __iommu_probe_device(dev, group_list);
+ if (ret)
+ goto err_module_put;
+
+ return 0;
+
+err_module_put:
+ module_put(ops->owner);
+err_free_dev_iommu:
+ dev_iommu_free(dev);
+
+ if (ret == -ENODEV)
+ ret = 0;
+
+ return ret;
+}
+
static int remove_iommu_group(struct device *dev, void *data)
{
iommu_release_device(dev);
@@ -1658,10 +1689,127 @@ static int iommu_bus_notifier(struct notifier_block *nb,
return 0;
}
+struct __group_domain_type {
+ struct device *dev;
+ unsigned int type;
+};
+
+static int probe_get_default_domain_type(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct __group_domain_type *gtype = data;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ if (type) {
+ if (gtype->type && gtype->type != type) {
+ dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
+ iommu_domain_type_str(type),
+ dev_name(gtype->dev),
+ iommu_domain_type_str(gtype->type));
+ gtype->type = 0;
+ }
+
+ if (!gtype->dev) {
+ gtype->dev = dev;
+ gtype->type = type;
+ }
+ }
+
+ return 0;
+}
+
+static void probe_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group)
+{
+ struct __group_domain_type gtype;
+
+ memset(>ype, 0, sizeof(gtype));
+
+ /* Ask for default domain requirements of all devices in the group */
+ __iommu_group_for_each_dev(group, >ype,
+ probe_get_default_domain_type);
+
+ if (!gtype.type)
+ gtype.type = iommu_def_domain_type;
+
+ iommu_group_alloc_default_domain(bus, group, gtype.type);
+}
+
+static int iommu_group_do_dma_attach(struct device *dev, void *data)
+{
+ struct iommu_domain *domain = data;
+ const struct iommu_ops *ops;
+ int ret;
+
+ ret = __iommu_attach_device(domain, dev);
+
+ ops = domain->ops;
+
+ if (ret == 0 && ops->probe_finalize)
+ ops->probe_finalize(dev);
+
+ return ret;
+}
+
+static int __iommu_group_dma_attach(struct iommu_group *group)
+{
+ return __iommu_group_for_each_dev(group, group->default_domain,
+ iommu_group_do_dma_attach);
+}
+
+static int bus_iommu_probe(struct bus_type *bus)
+{
+ const struct iommu_ops *ops = bus->iommu_ops;
+ int ret;
+
+ if (ops->probe_device) {
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
+
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
+
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
+
+ mutex_lock(&group->mutex);
+
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
+
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
+
+ ret = __iommu_group_dma_attach(group);
+
+ mutex_unlock(&group->mutex);
+
+ if (ret)
+ break;
+ }
+ } else {
+ ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ }
+
+ return ret;
+}
+
static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
{
- int err;
struct notifier_block *nb;
+ int err;
nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
if (!nb)
@@ -1673,7 +1821,7 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
if (err)
goto out_free;
- err = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ err = bus_iommu_probe(bus);
if (err)
goto out_err;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 11/34] iommu: Split off default domain allocation from group assignment
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
When a bus is initialized with iommu-ops, all devices on the bus are
scanned and iommu-groups are allocated for them, and each groups will
also get a default domain allocated.
Until now this happened as soon as the group was created and the first
device added to it. When other devices with different default domain
requirements were added to the group later on, the default domain was
re-allocated, if possible.
This resulted in some back and forth and unnecessary allocations, so
change the flow to defer default domain allocation until all devices
have been added to their respective IOMMU groups.
The default domains are allocated for newly allocated groups after
each device on the bus is handled and was probed by the IOMMU driver.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 154 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 151 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8be047a4808f..7de0e29db333 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -199,7 +199,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
dev->iommu->iommu_dev = iommu_dev;
group = iommu_group_get_for_dev(dev);
- if (!IS_ERR(group)) {
+ if (IS_ERR(group)) {
ret = PTR_ERR(group);
goto out_release;
}
@@ -1599,6 +1599,37 @@ static int add_iommu_group(struct device *dev, void *data)
return ret;
}
+static int probe_iommu_group(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct list_head *group_list = data;
+ int ret;
+
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_free_dev_iommu;
+ }
+
+ ret = __iommu_probe_device(dev, group_list);
+ if (ret)
+ goto err_module_put;
+
+ return 0;
+
+err_module_put:
+ module_put(ops->owner);
+err_free_dev_iommu:
+ dev_iommu_free(dev);
+
+ if (ret == -ENODEV)
+ ret = 0;
+
+ return ret;
+}
+
static int remove_iommu_group(struct device *dev, void *data)
{
iommu_release_device(dev);
@@ -1658,10 +1689,127 @@ static int iommu_bus_notifier(struct notifier_block *nb,
return 0;
}
+struct __group_domain_type {
+ struct device *dev;
+ unsigned int type;
+};
+
+static int probe_get_default_domain_type(struct device *dev, void *data)
+{
+ const struct iommu_ops *ops = dev->bus->iommu_ops;
+ struct __group_domain_type *gtype = data;
+ unsigned int type = 0;
+
+ if (ops->def_domain_type)
+ type = ops->def_domain_type(dev);
+
+ if (type) {
+ if (gtype->type && gtype->type != type) {
+ dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
+ iommu_domain_type_str(type),
+ dev_name(gtype->dev),
+ iommu_domain_type_str(gtype->type));
+ gtype->type = 0;
+ }
+
+ if (!gtype->dev) {
+ gtype->dev = dev;
+ gtype->type = type;
+ }
+ }
+
+ return 0;
+}
+
+static void probe_alloc_default_domain(struct bus_type *bus,
+ struct iommu_group *group)
+{
+ struct __group_domain_type gtype;
+
+ memset(>ype, 0, sizeof(gtype));
+
+ /* Ask for default domain requirements of all devices in the group */
+ __iommu_group_for_each_dev(group, >ype,
+ probe_get_default_domain_type);
+
+ if (!gtype.type)
+ gtype.type = iommu_def_domain_type;
+
+ iommu_group_alloc_default_domain(bus, group, gtype.type);
+}
+
+static int iommu_group_do_dma_attach(struct device *dev, void *data)
+{
+ struct iommu_domain *domain = data;
+ const struct iommu_ops *ops;
+ int ret;
+
+ ret = __iommu_attach_device(domain, dev);
+
+ ops = domain->ops;
+
+ if (ret == 0 && ops->probe_finalize)
+ ops->probe_finalize(dev);
+
+ return ret;
+}
+
+static int __iommu_group_dma_attach(struct iommu_group *group)
+{
+ return __iommu_group_for_each_dev(group, group->default_domain,
+ iommu_group_do_dma_attach);
+}
+
+static int bus_iommu_probe(struct bus_type *bus)
+{
+ const struct iommu_ops *ops = bus->iommu_ops;
+ int ret;
+
+ if (ops->probe_device) {
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
+
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
+
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
+
+ mutex_lock(&group->mutex);
+
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
+
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
+
+ ret = __iommu_group_dma_attach(group);
+
+ mutex_unlock(&group->mutex);
+
+ if (ret)
+ break;
+ }
+ } else {
+ ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ }
+
+ return ret;
+}
+
static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
{
- int err;
struct notifier_block *nb;
+ int err;
nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
if (!nb)
@@ -1673,7 +1821,7 @@ static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
if (err)
goto out_free;
- err = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ err = bus_iommu_probe(bus);
if (err)
goto out_err;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 13/34] iommu: Export bus_iommu_probe() and make is safe for re-probing
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Add a check to the bus_iommu_probe() call-path to make sure it ignores
devices which have already been successfully probed. Then export the
bus_iommu_probe() function so it can be used by IOMMU drivers.
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/iommu.c | 10 +++++++++-
include/linux/iommu.h | 1 +
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 834a45da0ed0..397fd4fd0c32 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1610,11 +1610,19 @@ static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct list_head *group_list = data;
+ struct iommu_group *group;
int ret;
if (!dev_iommu_get(dev))
return -ENOMEM;
+ /* Device is probed already if in a group */
+ group = iommu_group_get(dev);
+ if (group) {
+ iommu_group_put(group);
+ return 0;
+ }
+
if (!try_module_get(ops->owner)) {
ret = -EINVAL;
goto err_free_dev_iommu;
@@ -1783,7 +1791,7 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
iommu_do_create_direct_mappings);
}
-static int bus_iommu_probe(struct bus_type *bus)
+int bus_iommu_probe(struct bus_type *bus)
{
const struct iommu_ops *ops = bus->iommu_ops;
int ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 30170d191e5e..fea1622408ad 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -445,6 +445,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
#define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
+extern int bus_iommu_probe(struct bus_type *bus);
extern bool iommu_present(struct bus_type *bus);
extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 13/34] iommu: Export bus_iommu_probe() and make is safe for re-probing
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Add a check to the bus_iommu_probe() call-path to make sure it ignores
devices which have already been successfully probed. Then export the
bus_iommu_probe() function so it can be used by IOMMU drivers.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 10 +++++++++-
include/linux/iommu.h | 1 +
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 834a45da0ed0..397fd4fd0c32 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1610,11 +1610,19 @@ static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct list_head *group_list = data;
+ struct iommu_group *group;
int ret;
if (!dev_iommu_get(dev))
return -ENOMEM;
+ /* Device is probed already if in a group */
+ group = iommu_group_get(dev);
+ if (group) {
+ iommu_group_put(group);
+ return 0;
+ }
+
if (!try_module_get(ops->owner)) {
ret = -EINVAL;
goto err_free_dev_iommu;
@@ -1783,7 +1791,7 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
iommu_do_create_direct_mappings);
}
-static int bus_iommu_probe(struct bus_type *bus)
+int bus_iommu_probe(struct bus_type *bus)
{
const struct iommu_ops *ops = bus->iommu_ops;
int ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 30170d191e5e..fea1622408ad 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -445,6 +445,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
#define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
+extern int bus_iommu_probe(struct bus_type *bus);
extern bool iommu_present(struct bus_type *bus);
extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 13/34] iommu: Export bus_iommu_probe() and make is safe for re-probing
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Add a check to the bus_iommu_probe() call-path to make sure it ignores
devices which have already been successfully probed. Then export the
bus_iommu_probe() function so it can be used by IOMMU drivers.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 10 +++++++++-
include/linux/iommu.h | 1 +
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 834a45da0ed0..397fd4fd0c32 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1610,11 +1610,19 @@ static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct list_head *group_list = data;
+ struct iommu_group *group;
int ret;
if (!dev_iommu_get(dev))
return -ENOMEM;
+ /* Device is probed already if in a group */
+ group = iommu_group_get(dev);
+ if (group) {
+ iommu_group_put(group);
+ return 0;
+ }
+
if (!try_module_get(ops->owner)) {
ret = -EINVAL;
goto err_free_dev_iommu;
@@ -1783,7 +1791,7 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
iommu_do_create_direct_mappings);
}
-static int bus_iommu_probe(struct bus_type *bus)
+int bus_iommu_probe(struct bus_type *bus)
{
const struct iommu_ops *ops = bus->iommu_ops;
int ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 30170d191e5e..fea1622408ad 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -445,6 +445,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
#define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
+extern int bus_iommu_probe(struct bus_type *bus);
extern bool iommu_present(struct bus_type *bus);
extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 13/34] iommu: Export bus_iommu_probe() and make is safe for re-probing
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Add a check to the bus_iommu_probe() call-path to make sure it ignores
devices which have already been successfully probed. Then export the
bus_iommu_probe() function so it can be used by IOMMU drivers.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 10 +++++++++-
include/linux/iommu.h | 1 +
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 834a45da0ed0..397fd4fd0c32 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1610,11 +1610,19 @@ static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct list_head *group_list = data;
+ struct iommu_group *group;
int ret;
if (!dev_iommu_get(dev))
return -ENOMEM;
+ /* Device is probed already if in a group */
+ group = iommu_group_get(dev);
+ if (group) {
+ iommu_group_put(group);
+ return 0;
+ }
+
if (!try_module_get(ops->owner)) {
ret = -EINVAL;
goto err_free_dev_iommu;
@@ -1783,7 +1791,7 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
iommu_do_create_direct_mappings);
}
-static int bus_iommu_probe(struct bus_type *bus)
+int bus_iommu_probe(struct bus_type *bus)
{
const struct iommu_ops *ops = bus->iommu_ops;
int ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 30170d191e5e..fea1622408ad 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -445,6 +445,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
#define IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER 6 /* Post Driver unbind */
extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
+extern int bus_iommu_probe(struct bus_type *bus);
extern bool iommu_present(struct bus_type *bus);
extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 14/34] iommu/amd: Remove dev_data->passthrough
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Make use of generic IOMMU infrastructure to gather the same information
carried in dev_data->passthrough and remove the struct member.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 10 +++++-----
drivers/iommu/amd_iommu_types.h | 1 -
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3e0d27f7622e..0b4b4faa876d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2047,8 +2047,8 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev)
static int attach_device(struct device *dev,
struct protection_domain *domain)
{
- struct pci_dev *pdev;
struct iommu_dev_data *dev_data;
+ struct pci_dev *pdev;
unsigned long flags;
int ret;
@@ -2067,8 +2067,10 @@ static int attach_device(struct device *dev,
pdev = to_pci_dev(dev);
if (domain->flags & PD_IOMMUV2_MASK) {
+ struct iommu_domain *def_domain = iommu_get_dma_domain(dev);
+
ret = -EINVAL;
- if (!dev_data->passthrough)
+ if (def_domain->type != IOMMU_DOMAIN_IDENTITY)
goto out;
if (dev_data->iommu_v2) {
@@ -2189,9 +2191,7 @@ static int amd_iommu_add_device(struct device *dev)
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
- if (domain->type == IOMMU_DOMAIN_IDENTITY)
- dev_data->passthrough = true;
- else if (domain->type == IOMMU_DOMAIN_DMA)
+ if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
out:
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index ca8c4522045b..d0d7b6a0c3d8 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -640,7 +640,6 @@ struct iommu_dev_data {
struct pci_dev *pdev;
u16 devid; /* PCI Device ID */
bool iommu_v2; /* Device can make use of IOMMUv2 */
- bool passthrough; /* Device is identity mapped */
struct {
bool enabled;
int qdep;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 14/34] iommu/amd: Remove dev_data->passthrough
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Make use of generic IOMMU infrastructure to gather the same information
carried in dev_data->passthrough and remove the struct member.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 10 +++++-----
drivers/iommu/amd_iommu_types.h | 1 -
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3e0d27f7622e..0b4b4faa876d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2047,8 +2047,8 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev)
static int attach_device(struct device *dev,
struct protection_domain *domain)
{
- struct pci_dev *pdev;
struct iommu_dev_data *dev_data;
+ struct pci_dev *pdev;
unsigned long flags;
int ret;
@@ -2067,8 +2067,10 @@ static int attach_device(struct device *dev,
pdev = to_pci_dev(dev);
if (domain->flags & PD_IOMMUV2_MASK) {
+ struct iommu_domain *def_domain = iommu_get_dma_domain(dev);
+
ret = -EINVAL;
- if (!dev_data->passthrough)
+ if (def_domain->type != IOMMU_DOMAIN_IDENTITY)
goto out;
if (dev_data->iommu_v2) {
@@ -2189,9 +2191,7 @@ static int amd_iommu_add_device(struct device *dev)
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
- if (domain->type == IOMMU_DOMAIN_IDENTITY)
- dev_data->passthrough = true;
- else if (domain->type == IOMMU_DOMAIN_DMA)
+ if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
out:
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index ca8c4522045b..d0d7b6a0c3d8 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -640,7 +640,6 @@ struct iommu_dev_data {
struct pci_dev *pdev;
u16 devid; /* PCI Device ID */
bool iommu_v2; /* Device can make use of IOMMUv2 */
- bool passthrough; /* Device is identity mapped */
struct {
bool enabled;
int qdep;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 14/34] iommu/amd: Remove dev_data->passthrough
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Make use of generic IOMMU infrastructure to gather the same information
carried in dev_data->passthrough and remove the struct member.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 10 +++++-----
drivers/iommu/amd_iommu_types.h | 1 -
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3e0d27f7622e..0b4b4faa876d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2047,8 +2047,8 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev)
static int attach_device(struct device *dev,
struct protection_domain *domain)
{
- struct pci_dev *pdev;
struct iommu_dev_data *dev_data;
+ struct pci_dev *pdev;
unsigned long flags;
int ret;
@@ -2067,8 +2067,10 @@ static int attach_device(struct device *dev,
pdev = to_pci_dev(dev);
if (domain->flags & PD_IOMMUV2_MASK) {
+ struct iommu_domain *def_domain = iommu_get_dma_domain(dev);
+
ret = -EINVAL;
- if (!dev_data->passthrough)
+ if (def_domain->type != IOMMU_DOMAIN_IDENTITY)
goto out;
if (dev_data->iommu_v2) {
@@ -2189,9 +2191,7 @@ static int amd_iommu_add_device(struct device *dev)
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
- if (domain->type == IOMMU_DOMAIN_IDENTITY)
- dev_data->passthrough = true;
- else if (domain->type == IOMMU_DOMAIN_DMA)
+ if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
out:
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index ca8c4522045b..d0d7b6a0c3d8 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -640,7 +640,6 @@ struct iommu_dev_data {
struct pci_dev *pdev;
u16 devid; /* PCI Device ID */
bool iommu_v2; /* Device can make use of IOMMUv2 */
- bool passthrough; /* Device is identity mapped */
struct {
bool enabled;
int qdep;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 14/34] iommu/amd: Remove dev_data->passthrough
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Make use of generic IOMMU infrastructure to gather the same information
carried in dev_data->passthrough and remove the struct member.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 10 +++++-----
drivers/iommu/amd_iommu_types.h | 1 -
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 3e0d27f7622e..0b4b4faa876d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2047,8 +2047,8 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev)
static int attach_device(struct device *dev,
struct protection_domain *domain)
{
- struct pci_dev *pdev;
struct iommu_dev_data *dev_data;
+ struct pci_dev *pdev;
unsigned long flags;
int ret;
@@ -2067,8 +2067,10 @@ static int attach_device(struct device *dev,
pdev = to_pci_dev(dev);
if (domain->flags & PD_IOMMUV2_MASK) {
+ struct iommu_domain *def_domain = iommu_get_dma_domain(dev);
+
ret = -EINVAL;
- if (!dev_data->passthrough)
+ if (def_domain->type != IOMMU_DOMAIN_IDENTITY)
goto out;
if (dev_data->iommu_v2) {
@@ -2189,9 +2191,7 @@ static int amd_iommu_add_device(struct device *dev)
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
- if (domain->type == IOMMU_DOMAIN_IDENTITY)
- dev_data->passthrough = true;
- else if (domain->type == IOMMU_DOMAIN_DMA)
+ if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
out:
diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h
index ca8c4522045b..d0d7b6a0c3d8 100644
--- a/drivers/iommu/amd_iommu_types.h
+++ b/drivers/iommu/amd_iommu_types.h
@@ -640,7 +640,6 @@ struct iommu_dev_data {
struct pci_dev *pdev;
u16 devid; /* PCI Device ID */
bool iommu_v2; /* Device can make use of IOMMUv2 */
- bool passthrough; /* Device is identity mapped */
struct {
bool enabled;
int qdep;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 15/34] iommu/amd: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the AMD IOMMU Driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 71 ++++++++++++---------------------------
1 file changed, 22 insertions(+), 49 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 0b4b4faa876d..c30367413683 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -343,21 +343,9 @@ static bool check_device(struct device *dev)
return true;
}
-static void init_iommu_group(struct device *dev)
-{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return;
-
- iommu_group_put(group);
-}
-
static int iommu_init_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
- struct amd_iommu *iommu;
int devid;
if (dev->archdata.iommu)
@@ -367,8 +355,6 @@ static int iommu_init_device(struct device *dev)
if (devid < 0)
return devid;
- iommu = amd_iommu_rlookup_table[devid];
-
dev_data = find_dev_data(devid);
if (!dev_data)
return -ENOMEM;
@@ -391,8 +377,6 @@ static int iommu_init_device(struct device *dev)
dev->archdata.iommu = dev_data;
- iommu_device_link(&iommu->iommu, dev);
-
return 0;
}
@@ -410,7 +394,7 @@ static void iommu_ignore_device(struct device *dev)
setup_aliases(dev);
}
-static void iommu_uninit_device(struct device *dev)
+static void amd_iommu_uninit_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
struct amd_iommu *iommu;
@@ -429,13 +413,6 @@ static void iommu_uninit_device(struct device *dev)
if (dev_data->domain)
detach_device(dev);
- iommu_device_unlink(&iommu->iommu, dev);
-
- iommu_group_remove_device(dev);
-
- /* Remove dma-ops */
- dev->dma_ops = NULL;
-
/*
* We keep dev_data around for unplugged devices and reuse it when the
* device is re-plugged - not doing so would introduce a ton of races.
@@ -2152,55 +2129,50 @@ static void detach_device(struct device *dev)
spin_unlock_irqrestore(&domain->lock, flags);
}
-static int amd_iommu_add_device(struct device *dev)
+static struct iommu_device *amd_iommu_probe_device(struct device *dev)
{
- struct iommu_dev_data *dev_data;
- struct iommu_domain *domain;
+ struct iommu_device *iommu_dev;
struct amd_iommu *iommu;
int ret, devid;
- if (get_dev_data(dev))
- return 0;
-
if (!check_device(dev))
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
devid = get_device_id(dev);
if (devid < 0)
- return devid;
+ return ERR_PTR(devid);
iommu = amd_iommu_rlookup_table[devid];
+ if (get_dev_data(dev))
+ return &iommu->iommu;
+
ret = iommu_init_device(dev);
if (ret) {
if (ret != -ENOTSUPP)
dev_err(dev, "Failed to initialize - trying to proceed anyway\n");
-
+ iommu_dev = ERR_PTR(ret);
iommu_ignore_device(dev);
- dev->dma_ops = NULL;
- goto out;
+ } else {
+ iommu_dev = &iommu->iommu;
}
- init_iommu_group(dev);
- dev_data = get_dev_data(dev);
+ iommu_completion_wait(iommu);
- BUG_ON(!dev_data);
+ return iommu_dev;
+}
- if (dev_data->iommu_v2)
- iommu_request_dm_for_dev(dev);
+static void amd_iommu_probe_finalize(struct device *dev)
+{
+ struct iommu_domain *domain;
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
-
-out:
- iommu_completion_wait(iommu);
-
- return 0;
}
-static void amd_iommu_remove_device(struct device *dev)
+static void amd_iommu_release_device(struct device *dev)
{
struct amd_iommu *iommu;
int devid;
@@ -2214,7 +2186,7 @@ static void amd_iommu_remove_device(struct device *dev)
iommu = amd_iommu_rlookup_table[devid];
- iommu_uninit_device(dev);
+ amd_iommu_uninit_device(dev);
iommu_completion_wait(iommu);
}
@@ -2687,8 +2659,9 @@ const struct iommu_ops amd_iommu_ops = {
.map = amd_iommu_map,
.unmap = amd_iommu_unmap,
.iova_to_phys = amd_iommu_iova_to_phys,
- .add_device = amd_iommu_add_device,
- .remove_device = amd_iommu_remove_device,
+ .probe_device = amd_iommu_probe_device,
+ .release_device = amd_iommu_release_device,
+ .probe_finalize = amd_iommu_probe_finalize,
.device_group = amd_iommu_device_group,
.domain_get_attr = amd_iommu_domain_get_attr,
.get_resv_regions = amd_iommu_get_resv_regions,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 15/34] iommu/amd: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the AMD IOMMU Driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 71 ++++++++++++---------------------------
1 file changed, 22 insertions(+), 49 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 0b4b4faa876d..c30367413683 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -343,21 +343,9 @@ static bool check_device(struct device *dev)
return true;
}
-static void init_iommu_group(struct device *dev)
-{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return;
-
- iommu_group_put(group);
-}
-
static int iommu_init_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
- struct amd_iommu *iommu;
int devid;
if (dev->archdata.iommu)
@@ -367,8 +355,6 @@ static int iommu_init_device(struct device *dev)
if (devid < 0)
return devid;
- iommu = amd_iommu_rlookup_table[devid];
-
dev_data = find_dev_data(devid);
if (!dev_data)
return -ENOMEM;
@@ -391,8 +377,6 @@ static int iommu_init_device(struct device *dev)
dev->archdata.iommu = dev_data;
- iommu_device_link(&iommu->iommu, dev);
-
return 0;
}
@@ -410,7 +394,7 @@ static void iommu_ignore_device(struct device *dev)
setup_aliases(dev);
}
-static void iommu_uninit_device(struct device *dev)
+static void amd_iommu_uninit_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
struct amd_iommu *iommu;
@@ -429,13 +413,6 @@ static void iommu_uninit_device(struct device *dev)
if (dev_data->domain)
detach_device(dev);
- iommu_device_unlink(&iommu->iommu, dev);
-
- iommu_group_remove_device(dev);
-
- /* Remove dma-ops */
- dev->dma_ops = NULL;
-
/*
* We keep dev_data around for unplugged devices and reuse it when the
* device is re-plugged - not doing so would introduce a ton of races.
@@ -2152,55 +2129,50 @@ static void detach_device(struct device *dev)
spin_unlock_irqrestore(&domain->lock, flags);
}
-static int amd_iommu_add_device(struct device *dev)
+static struct iommu_device *amd_iommu_probe_device(struct device *dev)
{
- struct iommu_dev_data *dev_data;
- struct iommu_domain *domain;
+ struct iommu_device *iommu_dev;
struct amd_iommu *iommu;
int ret, devid;
- if (get_dev_data(dev))
- return 0;
-
if (!check_device(dev))
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
devid = get_device_id(dev);
if (devid < 0)
- return devid;
+ return ERR_PTR(devid);
iommu = amd_iommu_rlookup_table[devid];
+ if (get_dev_data(dev))
+ return &iommu->iommu;
+
ret = iommu_init_device(dev);
if (ret) {
if (ret != -ENOTSUPP)
dev_err(dev, "Failed to initialize - trying to proceed anyway\n");
-
+ iommu_dev = ERR_PTR(ret);
iommu_ignore_device(dev);
- dev->dma_ops = NULL;
- goto out;
+ } else {
+ iommu_dev = &iommu->iommu;
}
- init_iommu_group(dev);
- dev_data = get_dev_data(dev);
+ iommu_completion_wait(iommu);
- BUG_ON(!dev_data);
+ return iommu_dev;
+}
- if (dev_data->iommu_v2)
- iommu_request_dm_for_dev(dev);
+static void amd_iommu_probe_finalize(struct device *dev)
+{
+ struct iommu_domain *domain;
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
-
-out:
- iommu_completion_wait(iommu);
-
- return 0;
}
-static void amd_iommu_remove_device(struct device *dev)
+static void amd_iommu_release_device(struct device *dev)
{
struct amd_iommu *iommu;
int devid;
@@ -2214,7 +2186,7 @@ static void amd_iommu_remove_device(struct device *dev)
iommu = amd_iommu_rlookup_table[devid];
- iommu_uninit_device(dev);
+ amd_iommu_uninit_device(dev);
iommu_completion_wait(iommu);
}
@@ -2687,8 +2659,9 @@ const struct iommu_ops amd_iommu_ops = {
.map = amd_iommu_map,
.unmap = amd_iommu_unmap,
.iova_to_phys = amd_iommu_iova_to_phys,
- .add_device = amd_iommu_add_device,
- .remove_device = amd_iommu_remove_device,
+ .probe_device = amd_iommu_probe_device,
+ .release_device = amd_iommu_release_device,
+ .probe_finalize = amd_iommu_probe_finalize,
.device_group = amd_iommu_device_group,
.domain_get_attr = amd_iommu_domain_get_attr,
.get_resv_regions = amd_iommu_get_resv_regions,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 15/34] iommu/amd: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the AMD IOMMU Driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 71 ++++++++++++---------------------------
1 file changed, 22 insertions(+), 49 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 0b4b4faa876d..c30367413683 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -343,21 +343,9 @@ static bool check_device(struct device *dev)
return true;
}
-static void init_iommu_group(struct device *dev)
-{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return;
-
- iommu_group_put(group);
-}
-
static int iommu_init_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
- struct amd_iommu *iommu;
int devid;
if (dev->archdata.iommu)
@@ -367,8 +355,6 @@ static int iommu_init_device(struct device *dev)
if (devid < 0)
return devid;
- iommu = amd_iommu_rlookup_table[devid];
-
dev_data = find_dev_data(devid);
if (!dev_data)
return -ENOMEM;
@@ -391,8 +377,6 @@ static int iommu_init_device(struct device *dev)
dev->archdata.iommu = dev_data;
- iommu_device_link(&iommu->iommu, dev);
-
return 0;
}
@@ -410,7 +394,7 @@ static void iommu_ignore_device(struct device *dev)
setup_aliases(dev);
}
-static void iommu_uninit_device(struct device *dev)
+static void amd_iommu_uninit_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
struct amd_iommu *iommu;
@@ -429,13 +413,6 @@ static void iommu_uninit_device(struct device *dev)
if (dev_data->domain)
detach_device(dev);
- iommu_device_unlink(&iommu->iommu, dev);
-
- iommu_group_remove_device(dev);
-
- /* Remove dma-ops */
- dev->dma_ops = NULL;
-
/*
* We keep dev_data around for unplugged devices and reuse it when the
* device is re-plugged - not doing so would introduce a ton of races.
@@ -2152,55 +2129,50 @@ static void detach_device(struct device *dev)
spin_unlock_irqrestore(&domain->lock, flags);
}
-static int amd_iommu_add_device(struct device *dev)
+static struct iommu_device *amd_iommu_probe_device(struct device *dev)
{
- struct iommu_dev_data *dev_data;
- struct iommu_domain *domain;
+ struct iommu_device *iommu_dev;
struct amd_iommu *iommu;
int ret, devid;
- if (get_dev_data(dev))
- return 0;
-
if (!check_device(dev))
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
devid = get_device_id(dev);
if (devid < 0)
- return devid;
+ return ERR_PTR(devid);
iommu = amd_iommu_rlookup_table[devid];
+ if (get_dev_data(dev))
+ return &iommu->iommu;
+
ret = iommu_init_device(dev);
if (ret) {
if (ret != -ENOTSUPP)
dev_err(dev, "Failed to initialize - trying to proceed anyway\n");
-
+ iommu_dev = ERR_PTR(ret);
iommu_ignore_device(dev);
- dev->dma_ops = NULL;
- goto out;
+ } else {
+ iommu_dev = &iommu->iommu;
}
- init_iommu_group(dev);
- dev_data = get_dev_data(dev);
+ iommu_completion_wait(iommu);
- BUG_ON(!dev_data);
+ return iommu_dev;
+}
- if (dev_data->iommu_v2)
- iommu_request_dm_for_dev(dev);
+static void amd_iommu_probe_finalize(struct device *dev)
+{
+ struct iommu_domain *domain;
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
-
-out:
- iommu_completion_wait(iommu);
-
- return 0;
}
-static void amd_iommu_remove_device(struct device *dev)
+static void amd_iommu_release_device(struct device *dev)
{
struct amd_iommu *iommu;
int devid;
@@ -2214,7 +2186,7 @@ static void amd_iommu_remove_device(struct device *dev)
iommu = amd_iommu_rlookup_table[devid];
- iommu_uninit_device(dev);
+ amd_iommu_uninit_device(dev);
iommu_completion_wait(iommu);
}
@@ -2687,8 +2659,9 @@ const struct iommu_ops amd_iommu_ops = {
.map = amd_iommu_map,
.unmap = amd_iommu_unmap,
.iova_to_phys = amd_iommu_iova_to_phys,
- .add_device = amd_iommu_add_device,
- .remove_device = amd_iommu_remove_device,
+ .probe_device = amd_iommu_probe_device,
+ .release_device = amd_iommu_release_device,
+ .probe_finalize = amd_iommu_probe_finalize,
.device_group = amd_iommu_device_group,
.domain_get_attr = amd_iommu_domain_get_attr,
.get_resv_regions = amd_iommu_get_resv_regions,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 15/34] iommu/amd: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the AMD IOMMU Driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu.c | 71 ++++++++++++---------------------------
1 file changed, 22 insertions(+), 49 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 0b4b4faa876d..c30367413683 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -343,21 +343,9 @@ static bool check_device(struct device *dev)
return true;
}
-static void init_iommu_group(struct device *dev)
-{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return;
-
- iommu_group_put(group);
-}
-
static int iommu_init_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
- struct amd_iommu *iommu;
int devid;
if (dev->archdata.iommu)
@@ -367,8 +355,6 @@ static int iommu_init_device(struct device *dev)
if (devid < 0)
return devid;
- iommu = amd_iommu_rlookup_table[devid];
-
dev_data = find_dev_data(devid);
if (!dev_data)
return -ENOMEM;
@@ -391,8 +377,6 @@ static int iommu_init_device(struct device *dev)
dev->archdata.iommu = dev_data;
- iommu_device_link(&iommu->iommu, dev);
-
return 0;
}
@@ -410,7 +394,7 @@ static void iommu_ignore_device(struct device *dev)
setup_aliases(dev);
}
-static void iommu_uninit_device(struct device *dev)
+static void amd_iommu_uninit_device(struct device *dev)
{
struct iommu_dev_data *dev_data;
struct amd_iommu *iommu;
@@ -429,13 +413,6 @@ static void iommu_uninit_device(struct device *dev)
if (dev_data->domain)
detach_device(dev);
- iommu_device_unlink(&iommu->iommu, dev);
-
- iommu_group_remove_device(dev);
-
- /* Remove dma-ops */
- dev->dma_ops = NULL;
-
/*
* We keep dev_data around for unplugged devices and reuse it when the
* device is re-plugged - not doing so would introduce a ton of races.
@@ -2152,55 +2129,50 @@ static void detach_device(struct device *dev)
spin_unlock_irqrestore(&domain->lock, flags);
}
-static int amd_iommu_add_device(struct device *dev)
+static struct iommu_device *amd_iommu_probe_device(struct device *dev)
{
- struct iommu_dev_data *dev_data;
- struct iommu_domain *domain;
+ struct iommu_device *iommu_dev;
struct amd_iommu *iommu;
int ret, devid;
- if (get_dev_data(dev))
- return 0;
-
if (!check_device(dev))
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
devid = get_device_id(dev);
if (devid < 0)
- return devid;
+ return ERR_PTR(devid);
iommu = amd_iommu_rlookup_table[devid];
+ if (get_dev_data(dev))
+ return &iommu->iommu;
+
ret = iommu_init_device(dev);
if (ret) {
if (ret != -ENOTSUPP)
dev_err(dev, "Failed to initialize - trying to proceed anyway\n");
-
+ iommu_dev = ERR_PTR(ret);
iommu_ignore_device(dev);
- dev->dma_ops = NULL;
- goto out;
+ } else {
+ iommu_dev = &iommu->iommu;
}
- init_iommu_group(dev);
- dev_data = get_dev_data(dev);
+ iommu_completion_wait(iommu);
- BUG_ON(!dev_data);
+ return iommu_dev;
+}
- if (dev_data->iommu_v2)
- iommu_request_dm_for_dev(dev);
+static void amd_iommu_probe_finalize(struct device *dev)
+{
+ struct iommu_domain *domain;
/* Domains are initialized for this device - have a look what we ended up with */
domain = iommu_get_domain_for_dev(dev);
if (domain->type == IOMMU_DOMAIN_DMA)
iommu_setup_dma_ops(dev, IOVA_START_PFN << PAGE_SHIFT, 0);
-
-out:
- iommu_completion_wait(iommu);
-
- return 0;
}
-static void amd_iommu_remove_device(struct device *dev)
+static void amd_iommu_release_device(struct device *dev)
{
struct amd_iommu *iommu;
int devid;
@@ -2214,7 +2186,7 @@ static void amd_iommu_remove_device(struct device *dev)
iommu = amd_iommu_rlookup_table[devid];
- iommu_uninit_device(dev);
+ amd_iommu_uninit_device(dev);
iommu_completion_wait(iommu);
}
@@ -2687,8 +2659,9 @@ const struct iommu_ops amd_iommu_ops = {
.map = amd_iommu_map,
.unmap = amd_iommu_unmap,
.iova_to_phys = amd_iommu_iova_to_phys,
- .add_device = amd_iommu_add_device,
- .remove_device = amd_iommu_remove_device,
+ .probe_device = amd_iommu_probe_device,
+ .release_device = amd_iommu_release_device,
+ .probe_finalize = amd_iommu_probe_finalize,
.device_group = amd_iommu_device_group,
.domain_get_attr = amd_iommu_domain_get_attr,
.get_resv_regions = amd_iommu_get_resv_regions,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 18/34] iommu/pamu: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the PAMU IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/fsl_pamu_domain.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 06828e2698d5..928d37771ece 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -1016,25 +1016,13 @@ static struct iommu_group *fsl_pamu_device_group(struct device *dev)
return group;
}
-static int fsl_pamu_add_device(struct device *dev)
+static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
-
- iommu_device_link(&pamu_iommu, dev);
-
- return 0;
+ return &pamu_iommu;
}
-static void fsl_pamu_remove_device(struct device *dev)
+static void fsl_pamu_release_device(struct device *dev)
{
- iommu_device_unlink(&pamu_iommu, dev);
- iommu_group_remove_device(dev);
}
static const struct iommu_ops fsl_pamu_ops = {
@@ -1048,8 +1036,8 @@ static const struct iommu_ops fsl_pamu_ops = {
.iova_to_phys = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
- .add_device = fsl_pamu_add_device,
- .remove_device = fsl_pamu_remove_device,
+ .probe_device = fsl_pamu_probe_device,
+ .release_device = fsl_pamu_release_device,
.device_group = fsl_pamu_device_group,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 18/34] iommu/pamu: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the PAMU IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/fsl_pamu_domain.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 06828e2698d5..928d37771ece 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -1016,25 +1016,13 @@ static struct iommu_group *fsl_pamu_device_group(struct device *dev)
return group;
}
-static int fsl_pamu_add_device(struct device *dev)
+static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
-
- iommu_device_link(&pamu_iommu, dev);
-
- return 0;
+ return &pamu_iommu;
}
-static void fsl_pamu_remove_device(struct device *dev)
+static void fsl_pamu_release_device(struct device *dev)
{
- iommu_device_unlink(&pamu_iommu, dev);
- iommu_group_remove_device(dev);
}
static const struct iommu_ops fsl_pamu_ops = {
@@ -1048,8 +1036,8 @@ static const struct iommu_ops fsl_pamu_ops = {
.iova_to_phys = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
- .add_device = fsl_pamu_add_device,
- .remove_device = fsl_pamu_remove_device,
+ .probe_device = fsl_pamu_probe_device,
+ .release_device = fsl_pamu_release_device,
.device_group = fsl_pamu_device_group,
};
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 18/34] iommu/pamu: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the PAMU IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/fsl_pamu_domain.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 06828e2698d5..928d37771ece 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -1016,25 +1016,13 @@ static struct iommu_group *fsl_pamu_device_group(struct device *dev)
return group;
}
-static int fsl_pamu_add_device(struct device *dev)
+static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
-
- iommu_device_link(&pamu_iommu, dev);
-
- return 0;
+ return &pamu_iommu;
}
-static void fsl_pamu_remove_device(struct device *dev)
+static void fsl_pamu_release_device(struct device *dev)
{
- iommu_device_unlink(&pamu_iommu, dev);
- iommu_group_remove_device(dev);
}
static const struct iommu_ops fsl_pamu_ops = {
@@ -1048,8 +1036,8 @@ static const struct iommu_ops fsl_pamu_ops = {
.iova_to_phys = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
- .add_device = fsl_pamu_add_device,
- .remove_device = fsl_pamu_remove_device,
+ .probe_device = fsl_pamu_probe_device,
+ .release_device = fsl_pamu_release_device,
.device_group = fsl_pamu_device_group,
};
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 18/34] iommu/pamu: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the PAMU IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/fsl_pamu_domain.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 06828e2698d5..928d37771ece 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -1016,25 +1016,13 @@ static struct iommu_group *fsl_pamu_device_group(struct device *dev)
return group;
}
-static int fsl_pamu_add_device(struct device *dev)
+static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
-
- iommu_device_link(&pamu_iommu, dev);
-
- return 0;
+ return &pamu_iommu;
}
-static void fsl_pamu_remove_device(struct device *dev)
+static void fsl_pamu_release_device(struct device *dev)
{
- iommu_device_unlink(&pamu_iommu, dev);
- iommu_group_remove_device(dev);
}
static const struct iommu_ops fsl_pamu_ops = {
@@ -1048,8 +1036,8 @@ static const struct iommu_ops fsl_pamu_ops = {
.iova_to_phys = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
- .add_device = fsl_pamu_add_device,
- .remove_device = fsl_pamu_remove_device,
+ .probe_device = fsl_pamu_probe_device,
+ .release_device = fsl_pamu_release_device,
.device_group = fsl_pamu_device_group,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 19/34] iommu/s390: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Joerg Roedel
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the S390 IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/s390-iommu.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 1137f3ddcb85..610f0828f22d 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -166,21 +166,14 @@ static void s390_iommu_detach_device(struct iommu_domain *domain,
}
}
-static int s390_iommu_add_device(struct device *dev)
+static struct iommu_device *s390_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group = iommu_group_get_for_dev(dev);
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&zdev->iommu_dev, dev);
-
- return 0;
+ return &zdev->iommu_dev;
}
-static void s390_iommu_remove_device(struct device *dev)
+static void s390_iommu_release_device(struct device *dev)
{
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
struct iommu_domain *domain;
@@ -191,7 +184,7 @@ static void s390_iommu_remove_device(struct device *dev)
* to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
* the attach_dev), removing the device via
* "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
- * only remove_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
+ * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
* notifier.
*
* So let's call detach_dev from here if it hasn't been called before.
@@ -201,9 +194,6 @@ static void s390_iommu_remove_device(struct device *dev)
if (domain)
s390_iommu_detach_device(domain, dev);
}
-
- iommu_device_unlink(&zdev->iommu_dev, dev);
- iommu_group_remove_device(dev);
}
static int s390_iommu_update_trans(struct s390_domain *s390_domain,
@@ -373,8 +363,8 @@ static const struct iommu_ops s390_iommu_ops = {
.map = s390_iommu_map,
.unmap = s390_iommu_unmap,
.iova_to_phys = s390_iommu_iova_to_phys,
- .add_device = s390_iommu_add_device,
- .remove_device = s390_iommu_remove_device,
+ .probe_device = s390_iommu_probe_device,
+ .release_device = s390_iommu_release_device,
.device_group = generic_device_group,
.pgsize_bitmap = S390_IOMMU_PGSIZES,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 19/34] iommu/s390: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the S390 IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/s390-iommu.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 1137f3ddcb85..610f0828f22d 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -166,21 +166,14 @@ static void s390_iommu_detach_device(struct iommu_domain *domain,
}
}
-static int s390_iommu_add_device(struct device *dev)
+static struct iommu_device *s390_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group = iommu_group_get_for_dev(dev);
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&zdev->iommu_dev, dev);
-
- return 0;
+ return &zdev->iommu_dev;
}
-static void s390_iommu_remove_device(struct device *dev)
+static void s390_iommu_release_device(struct device *dev)
{
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
struct iommu_domain *domain;
@@ -191,7 +184,7 @@ static void s390_iommu_remove_device(struct device *dev)
* to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
* the attach_dev), removing the device via
* "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
- * only remove_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
+ * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
* notifier.
*
* So let's call detach_dev from here if it hasn't been called before.
@@ -201,9 +194,6 @@ static void s390_iommu_remove_device(struct device *dev)
if (domain)
s390_iommu_detach_device(domain, dev);
}
-
- iommu_device_unlink(&zdev->iommu_dev, dev);
- iommu_group_remove_device(dev);
}
static int s390_iommu_update_trans(struct s390_domain *s390_domain,
@@ -373,8 +363,8 @@ static const struct iommu_ops s390_iommu_ops = {
.map = s390_iommu_map,
.unmap = s390_iommu_unmap,
.iova_to_phys = s390_iommu_iova_to_phys,
- .add_device = s390_iommu_add_device,
- .remove_device = s390_iommu_remove_device,
+ .probe_device = s390_iommu_probe_device,
+ .release_device = s390_iommu_release_device,
.device_group = generic_device_group,
.pgsize_bitmap = S390_IOMMU_PGSIZES,
};
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 19/34] iommu/s390: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the S390 IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/s390-iommu.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 1137f3ddcb85..610f0828f22d 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -166,21 +166,14 @@ static void s390_iommu_detach_device(struct iommu_domain *domain,
}
}
-static int s390_iommu_add_device(struct device *dev)
+static struct iommu_device *s390_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group = iommu_group_get_for_dev(dev);
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&zdev->iommu_dev, dev);
-
- return 0;
+ return &zdev->iommu_dev;
}
-static void s390_iommu_remove_device(struct device *dev)
+static void s390_iommu_release_device(struct device *dev)
{
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
struct iommu_domain *domain;
@@ -191,7 +184,7 @@ static void s390_iommu_remove_device(struct device *dev)
* to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
* the attach_dev), removing the device via
* "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
- * only remove_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
+ * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
* notifier.
*
* So let's call detach_dev from here if it hasn't been called before.
@@ -201,9 +194,6 @@ static void s390_iommu_remove_device(struct device *dev)
if (domain)
s390_iommu_detach_device(domain, dev);
}
-
- iommu_device_unlink(&zdev->iommu_dev, dev);
- iommu_group_remove_device(dev);
}
static int s390_iommu_update_trans(struct s390_domain *s390_domain,
@@ -373,8 +363,8 @@ static const struct iommu_ops s390_iommu_ops = {
.map = s390_iommu_map,
.unmap = s390_iommu_unmap,
.iova_to_phys = s390_iommu_iova_to_phys,
- .add_device = s390_iommu_add_device,
- .remove_device = s390_iommu_remove_device,
+ .probe_device = s390_iommu_probe_device,
+ .release_device = s390_iommu_release_device,
.device_group = generic_device_group,
.pgsize_bitmap = S390_IOMMU_PGSIZES,
};
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 19/34] iommu/s390: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the S390 IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/s390-iommu.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index 1137f3ddcb85..610f0828f22d 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -166,21 +166,14 @@ static void s390_iommu_detach_device(struct iommu_domain *domain,
}
}
-static int s390_iommu_add_device(struct device *dev)
+static struct iommu_device *s390_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group = iommu_group_get_for_dev(dev);
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&zdev->iommu_dev, dev);
-
- return 0;
+ return &zdev->iommu_dev;
}
-static void s390_iommu_remove_device(struct device *dev)
+static void s390_iommu_release_device(struct device *dev)
{
struct zpci_dev *zdev = to_pci_dev(dev)->sysdata;
struct iommu_domain *domain;
@@ -191,7 +184,7 @@ static void s390_iommu_remove_device(struct device *dev)
* to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
* the attach_dev), removing the device via
* "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
- * only remove_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
+ * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
* notifier.
*
* So let's call detach_dev from here if it hasn't been called before.
@@ -201,9 +194,6 @@ static void s390_iommu_remove_device(struct device *dev)
if (domain)
s390_iommu_detach_device(domain, dev);
}
-
- iommu_device_unlink(&zdev->iommu_dev, dev);
- iommu_group_remove_device(dev);
}
static int s390_iommu_update_trans(struct s390_domain *s390_domain,
@@ -373,8 +363,8 @@ static const struct iommu_ops s390_iommu_ops = {
.map = s390_iommu_map,
.unmap = s390_iommu_unmap,
.iova_to_phys = s390_iommu_iova_to_phys,
- .add_device = s390_iommu_add_device,
- .remove_device = s390_iommu_remove_device,
+ .probe_device = s390_iommu_probe_device,
+ .release_device = s390_iommu_release_device,
.device_group = generic_device_group,
.pgsize_bitmap = S390_IOMMU_PGSIZES,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 20/34] iommu/virtio: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:36 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the VirtIO IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/virtio-iommu.c | 41 +++++++++---------------------------
1 file changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index d5cac4f46ca5..bda300c2a438 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
return dev ? dev_to_virtio(dev)->priv : NULL;
}
-static int viommu_add_device(struct device *dev)
+static struct iommu_device *viommu_probe_device(struct device *dev)
{
int ret;
- struct iommu_group *group;
struct viommu_endpoint *vdev;
struct viommu_dev *viommu = NULL;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
if (!fwspec || fwspec->ops != &viommu_ops)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
if (!viommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
vdev->dev = dev;
vdev->viommu = viommu;
@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
goto err_free_dev;
}
- ret = iommu_device_link(&viommu->iommu, dev);
- if (ret)
- goto err_free_dev;
+ return &viommu->iommu;
- /*
- * Last step creates a default domain and attaches to it. Everything
- * must be ready.
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- ret = PTR_ERR(group);
- goto err_unlink_dev;
- }
-
- iommu_group_put(group);
-
- return PTR_ERR_OR_ZERO(group);
-
-err_unlink_dev:
- iommu_device_unlink(&viommu->iommu, dev);
err_free_dev:
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
- return ret;
+ return ERR_PTR(ret);
}
-static void viommu_remove_device(struct device *dev)
+static void viommu_release_device(struct device *dev)
{
- struct viommu_endpoint *vdev;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct viommu_endpoint *vdev;
if (!fwspec || fwspec->ops != &viommu_ops)
return;
vdev = dev_iommu_priv_get(dev);
- iommu_group_remove_device(dev);
- iommu_device_unlink(&vdev->viommu->iommu, dev);
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
}
@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
.unmap = viommu_unmap,
.iova_to_phys = viommu_iova_to_phys,
.iotlb_sync = viommu_iotlb_sync,
- .add_device = viommu_add_device,
- .remove_device = viommu_remove_device,
+ .probe_device = viommu_probe_device,
+ .release_device = viommu_release_device,
.device_group = viommu_device_group,
.get_resv_regions = viommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 20/34] iommu/virtio: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the VirtIO IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/virtio-iommu.c | 41 +++++++++---------------------------
1 file changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index d5cac4f46ca5..bda300c2a438 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
return dev ? dev_to_virtio(dev)->priv : NULL;
}
-static int viommu_add_device(struct device *dev)
+static struct iommu_device *viommu_probe_device(struct device *dev)
{
int ret;
- struct iommu_group *group;
struct viommu_endpoint *vdev;
struct viommu_dev *viommu = NULL;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
if (!fwspec || fwspec->ops != &viommu_ops)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
if (!viommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
vdev->dev = dev;
vdev->viommu = viommu;
@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
goto err_free_dev;
}
- ret = iommu_device_link(&viommu->iommu, dev);
- if (ret)
- goto err_free_dev;
+ return &viommu->iommu;
- /*
- * Last step creates a default domain and attaches to it. Everything
- * must be ready.
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- ret = PTR_ERR(group);
- goto err_unlink_dev;
- }
-
- iommu_group_put(group);
-
- return PTR_ERR_OR_ZERO(group);
-
-err_unlink_dev:
- iommu_device_unlink(&viommu->iommu, dev);
err_free_dev:
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
- return ret;
+ return ERR_PTR(ret);
}
-static void viommu_remove_device(struct device *dev)
+static void viommu_release_device(struct device *dev)
{
- struct viommu_endpoint *vdev;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct viommu_endpoint *vdev;
if (!fwspec || fwspec->ops != &viommu_ops)
return;
vdev = dev_iommu_priv_get(dev);
- iommu_group_remove_device(dev);
- iommu_device_unlink(&vdev->viommu->iommu, dev);
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
}
@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
.unmap = viommu_unmap,
.iova_to_phys = viommu_iova_to_phys,
.iotlb_sync = viommu_iotlb_sync,
- .add_device = viommu_add_device,
- .remove_device = viommu_remove_device,
+ .probe_device = viommu_probe_device,
+ .release_device = viommu_release_device,
.device_group = viommu_device_group,
.get_resv_regions = viommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 20/34] iommu/virtio: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the VirtIO IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/virtio-iommu.c | 41 +++++++++---------------------------
1 file changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index d5cac4f46ca5..bda300c2a438 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
return dev ? dev_to_virtio(dev)->priv : NULL;
}
-static int viommu_add_device(struct device *dev)
+static struct iommu_device *viommu_probe_device(struct device *dev)
{
int ret;
- struct iommu_group *group;
struct viommu_endpoint *vdev;
struct viommu_dev *viommu = NULL;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
if (!fwspec || fwspec->ops != &viommu_ops)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
if (!viommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
vdev->dev = dev;
vdev->viommu = viommu;
@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
goto err_free_dev;
}
- ret = iommu_device_link(&viommu->iommu, dev);
- if (ret)
- goto err_free_dev;
+ return &viommu->iommu;
- /*
- * Last step creates a default domain and attaches to it. Everything
- * must be ready.
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- ret = PTR_ERR(group);
- goto err_unlink_dev;
- }
-
- iommu_group_put(group);
-
- return PTR_ERR_OR_ZERO(group);
-
-err_unlink_dev:
- iommu_device_unlink(&viommu->iommu, dev);
err_free_dev:
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
- return ret;
+ return ERR_PTR(ret);
}
-static void viommu_remove_device(struct device *dev)
+static void viommu_release_device(struct device *dev)
{
- struct viommu_endpoint *vdev;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct viommu_endpoint *vdev;
if (!fwspec || fwspec->ops != &viommu_ops)
return;
vdev = dev_iommu_priv_get(dev);
- iommu_group_remove_device(dev);
- iommu_device_unlink(&vdev->viommu->iommu, dev);
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
}
@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
.unmap = viommu_unmap,
.iova_to_phys = viommu_iova_to_phys,
.iotlb_sync = viommu_iotlb_sync,
- .add_device = viommu_add_device,
- .remove_device = viommu_remove_device,
+ .probe_device = viommu_probe_device,
+ .release_device = viommu_release_device,
.device_group = viommu_device_group,
.get_resv_regions = viommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 20/34] iommu/virtio: Convert to probe/release_device() call-backs
@ 2020-04-29 13:36 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:36 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the VirtIO IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/virtio-iommu.c | 41 +++++++++---------------------------
1 file changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index d5cac4f46ca5..bda300c2a438 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -865,24 +865,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode)
return dev ? dev_to_virtio(dev)->priv : NULL;
}
-static int viommu_add_device(struct device *dev)
+static struct iommu_device *viommu_probe_device(struct device *dev)
{
int ret;
- struct iommu_group *group;
struct viommu_endpoint *vdev;
struct viommu_dev *viommu = NULL;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
if (!fwspec || fwspec->ops != &viommu_ops)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode);
if (!viommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
vdev->dev = dev;
vdev->viommu = viommu;
@@ -896,45 +895,25 @@ static int viommu_add_device(struct device *dev)
goto err_free_dev;
}
- ret = iommu_device_link(&viommu->iommu, dev);
- if (ret)
- goto err_free_dev;
+ return &viommu->iommu;
- /*
- * Last step creates a default domain and attaches to it. Everything
- * must be ready.
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- ret = PTR_ERR(group);
- goto err_unlink_dev;
- }
-
- iommu_group_put(group);
-
- return PTR_ERR_OR_ZERO(group);
-
-err_unlink_dev:
- iommu_device_unlink(&viommu->iommu, dev);
err_free_dev:
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
- return ret;
+ return ERR_PTR(ret);
}
-static void viommu_remove_device(struct device *dev)
+static void viommu_release_device(struct device *dev)
{
- struct viommu_endpoint *vdev;
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct viommu_endpoint *vdev;
if (!fwspec || fwspec->ops != &viommu_ops)
return;
vdev = dev_iommu_priv_get(dev);
- iommu_group_remove_device(dev);
- iommu_device_unlink(&vdev->viommu->iommu, dev);
generic_iommu_put_resv_regions(dev, &vdev->resv_regions);
kfree(vdev);
}
@@ -960,8 +939,8 @@ static struct iommu_ops viommu_ops = {
.unmap = viommu_unmap,
.iova_to_phys = viommu_iova_to_phys,
.iotlb_sync = viommu_iotlb_sync,
- .add_device = viommu_add_device,
- .remove_device = viommu_remove_device,
+ .probe_device = viommu_probe_device,
+ .release_device = viommu_release_device,
.device_group = viommu_device_group,
.get_resv_regions = viommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 22/34] iommu/mediatek: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the Mediatek IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/mtk_iommu.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 5f4d6df59cf6..2be96f1cdbd2 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -441,38 +441,26 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
return pa;
}
-static int mtk_iommu_add_device(struct device *dev)
+static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct mtk_iommu_data *data;
- struct iommu_group *group;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
- return -ENODEV; /* Not a iommu client device */
+ return ERR_PTR(-ENODEV); /* Not a iommu client device */
data = dev_iommu_priv_get(dev);
- iommu_device_link(&data->iommu, dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- return 0;
+ return &data->iommu;
}
-static void mtk_iommu_remove_device(struct device *dev)
+static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
- struct mtk_iommu_data *data;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;
- data = dev_iommu_priv_get(dev);
- iommu_device_unlink(&data->iommu, dev);
-
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -526,8 +514,8 @@ static const struct iommu_ops mtk_iommu_ops = {
.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
.iotlb_sync = mtk_iommu_iotlb_sync,
.iova_to_phys = mtk_iommu_iova_to_phys,
- .add_device = mtk_iommu_add_device,
- .remove_device = mtk_iommu_remove_device,
+ .probe_device = mtk_iommu_probe_device,
+ .release_device = mtk_iommu_release_device,
.device_group = mtk_iommu_device_group,
.of_xlate = mtk_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 22/34] iommu/mediatek: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Mediatek IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/mtk_iommu.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 5f4d6df59cf6..2be96f1cdbd2 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -441,38 +441,26 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
return pa;
}
-static int mtk_iommu_add_device(struct device *dev)
+static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct mtk_iommu_data *data;
- struct iommu_group *group;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
- return -ENODEV; /* Not a iommu client device */
+ return ERR_PTR(-ENODEV); /* Not a iommu client device */
data = dev_iommu_priv_get(dev);
- iommu_device_link(&data->iommu, dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- return 0;
+ return &data->iommu;
}
-static void mtk_iommu_remove_device(struct device *dev)
+static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
- struct mtk_iommu_data *data;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;
- data = dev_iommu_priv_get(dev);
- iommu_device_unlink(&data->iommu, dev);
-
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -526,8 +514,8 @@ static const struct iommu_ops mtk_iommu_ops = {
.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
.iotlb_sync = mtk_iommu_iotlb_sync,
.iova_to_phys = mtk_iommu_iova_to_phys,
- .add_device = mtk_iommu_add_device,
- .remove_device = mtk_iommu_remove_device,
+ .probe_device = mtk_iommu_probe_device,
+ .release_device = mtk_iommu_release_device,
.device_group = mtk_iommu_device_group,
.of_xlate = mtk_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 22/34] iommu/mediatek: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Mediatek IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/mtk_iommu.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 5f4d6df59cf6..2be96f1cdbd2 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -441,38 +441,26 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
return pa;
}
-static int mtk_iommu_add_device(struct device *dev)
+static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct mtk_iommu_data *data;
- struct iommu_group *group;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
- return -ENODEV; /* Not a iommu client device */
+ return ERR_PTR(-ENODEV); /* Not a iommu client device */
data = dev_iommu_priv_get(dev);
- iommu_device_link(&data->iommu, dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- return 0;
+ return &data->iommu;
}
-static void mtk_iommu_remove_device(struct device *dev)
+static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
- struct mtk_iommu_data *data;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;
- data = dev_iommu_priv_get(dev);
- iommu_device_unlink(&data->iommu, dev);
-
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -526,8 +514,8 @@ static const struct iommu_ops mtk_iommu_ops = {
.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
.iotlb_sync = mtk_iommu_iotlb_sync,
.iova_to_phys = mtk_iommu_iova_to_phys,
- .add_device = mtk_iommu_add_device,
- .remove_device = mtk_iommu_remove_device,
+ .probe_device = mtk_iommu_probe_device,
+ .release_device = mtk_iommu_release_device,
.device_group = mtk_iommu_device_group,
.of_xlate = mtk_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 22/34] iommu/mediatek: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the Mediatek IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/mtk_iommu.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 5f4d6df59cf6..2be96f1cdbd2 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -441,38 +441,26 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
return pa;
}
-static int mtk_iommu_add_device(struct device *dev)
+static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct mtk_iommu_data *data;
- struct iommu_group *group;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
- return -ENODEV; /* Not a iommu client device */
+ return ERR_PTR(-ENODEV); /* Not a iommu client device */
data = dev_iommu_priv_get(dev);
- iommu_device_link(&data->iommu, dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- return 0;
+ return &data->iommu;
}
-static void mtk_iommu_remove_device(struct device *dev)
+static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
- struct mtk_iommu_data *data;
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;
- data = dev_iommu_priv_get(dev);
- iommu_device_unlink(&data->iommu, dev);
-
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -526,8 +514,8 @@ static const struct iommu_ops mtk_iommu_ops = {
.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
.iotlb_sync = mtk_iommu_iotlb_sync,
.iova_to_phys = mtk_iommu_iova_to_phys,
- .add_device = mtk_iommu_add_device,
- .remove_device = mtk_iommu_remove_device,
+ .probe_device = mtk_iommu_probe_device,
+ .release_device = mtk_iommu_release_device,
.device_group = mtk_iommu_device_group,
.of_xlate = mtk_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 24/34] iommu/qcom: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the QCOM IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/qcom_iommu.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c
index 0e2a96467767..054e476ebd49 100644
--- a/drivers/iommu/qcom_iommu.c
+++ b/drivers/iommu/qcom_iommu.c
@@ -524,14 +524,13 @@ static bool qcom_iommu_capable(enum iommu_cap cap)
}
}
-static int qcom_iommu_add_device(struct device *dev)
+static struct iommu_device *qcom_iommu_probe_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
- struct iommu_group *group;
struct device_link *link;
if (!qcom_iommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
/*
* Establish the link between iommu and master, so that the
@@ -542,28 +541,19 @@ static int qcom_iommu_add_device(struct device *dev)
if (!link) {
dev_err(qcom_iommu->dev, "Unable to create device link between %s and %s\n",
dev_name(qcom_iommu->dev), dev_name(dev));
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&qcom_iommu->iommu, dev);
-
- return 0;
+ return &qcom_iommu->iommu;
}
-static void qcom_iommu_remove_device(struct device *dev)
+static void qcom_iommu_release_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
if (!qcom_iommu)
return;
- iommu_device_unlink(&qcom_iommu->iommu, dev);
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -619,8 +609,8 @@ static const struct iommu_ops qcom_iommu_ops = {
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
.iotlb_sync = qcom_iommu_iotlb_sync,
.iova_to_phys = qcom_iommu_iova_to_phys,
- .add_device = qcom_iommu_add_device,
- .remove_device = qcom_iommu_remove_device,
+ .probe_device = qcom_iommu_probe_device,
+ .release_device = qcom_iommu_release_device,
.device_group = generic_device_group,
.of_xlate = qcom_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 24/34] iommu/qcom: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the QCOM IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/qcom_iommu.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c
index 0e2a96467767..054e476ebd49 100644
--- a/drivers/iommu/qcom_iommu.c
+++ b/drivers/iommu/qcom_iommu.c
@@ -524,14 +524,13 @@ static bool qcom_iommu_capable(enum iommu_cap cap)
}
}
-static int qcom_iommu_add_device(struct device *dev)
+static struct iommu_device *qcom_iommu_probe_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
- struct iommu_group *group;
struct device_link *link;
if (!qcom_iommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
/*
* Establish the link between iommu and master, so that the
@@ -542,28 +541,19 @@ static int qcom_iommu_add_device(struct device *dev)
if (!link) {
dev_err(qcom_iommu->dev, "Unable to create device link between %s and %s\n",
dev_name(qcom_iommu->dev), dev_name(dev));
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&qcom_iommu->iommu, dev);
-
- return 0;
+ return &qcom_iommu->iommu;
}
-static void qcom_iommu_remove_device(struct device *dev)
+static void qcom_iommu_release_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
if (!qcom_iommu)
return;
- iommu_device_unlink(&qcom_iommu->iommu, dev);
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -619,8 +609,8 @@ static const struct iommu_ops qcom_iommu_ops = {
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
.iotlb_sync = qcom_iommu_iotlb_sync,
.iova_to_phys = qcom_iommu_iova_to_phys,
- .add_device = qcom_iommu_add_device,
- .remove_device = qcom_iommu_remove_device,
+ .probe_device = qcom_iommu_probe_device,
+ .release_device = qcom_iommu_release_device,
.device_group = generic_device_group,
.of_xlate = qcom_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 24/34] iommu/qcom: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the QCOM IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/qcom_iommu.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c
index 0e2a96467767..054e476ebd49 100644
--- a/drivers/iommu/qcom_iommu.c
+++ b/drivers/iommu/qcom_iommu.c
@@ -524,14 +524,13 @@ static bool qcom_iommu_capable(enum iommu_cap cap)
}
}
-static int qcom_iommu_add_device(struct device *dev)
+static struct iommu_device *qcom_iommu_probe_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
- struct iommu_group *group;
struct device_link *link;
if (!qcom_iommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
/*
* Establish the link between iommu and master, so that the
@@ -542,28 +541,19 @@ static int qcom_iommu_add_device(struct device *dev)
if (!link) {
dev_err(qcom_iommu->dev, "Unable to create device link between %s and %s\n",
dev_name(qcom_iommu->dev), dev_name(dev));
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&qcom_iommu->iommu, dev);
-
- return 0;
+ return &qcom_iommu->iommu;
}
-static void qcom_iommu_remove_device(struct device *dev)
+static void qcom_iommu_release_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
if (!qcom_iommu)
return;
- iommu_device_unlink(&qcom_iommu->iommu, dev);
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -619,8 +609,8 @@ static const struct iommu_ops qcom_iommu_ops = {
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
.iotlb_sync = qcom_iommu_iotlb_sync,
.iova_to_phys = qcom_iommu_iova_to_phys,
- .add_device = qcom_iommu_add_device,
- .remove_device = qcom_iommu_remove_device,
+ .probe_device = qcom_iommu_probe_device,
+ .release_device = qcom_iommu_release_device,
.device_group = generic_device_group,
.of_xlate = qcom_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 24/34] iommu/qcom: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the QCOM IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/qcom_iommu.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c
index 0e2a96467767..054e476ebd49 100644
--- a/drivers/iommu/qcom_iommu.c
+++ b/drivers/iommu/qcom_iommu.c
@@ -524,14 +524,13 @@ static bool qcom_iommu_capable(enum iommu_cap cap)
}
}
-static int qcom_iommu_add_device(struct device *dev)
+static struct iommu_device *qcom_iommu_probe_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
- struct iommu_group *group;
struct device_link *link;
if (!qcom_iommu)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
/*
* Establish the link between iommu and master, so that the
@@ -542,28 +541,19 @@ static int qcom_iommu_add_device(struct device *dev)
if (!link) {
dev_err(qcom_iommu->dev, "Unable to create device link between %s and %s\n",
dev_name(qcom_iommu->dev), dev_name(dev));
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
- iommu_device_link(&qcom_iommu->iommu, dev);
-
- return 0;
+ return &qcom_iommu->iommu;
}
-static void qcom_iommu_remove_device(struct device *dev)
+static void qcom_iommu_release_device(struct device *dev)
{
struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
if (!qcom_iommu)
return;
- iommu_device_unlink(&qcom_iommu->iommu, dev);
- iommu_group_remove_device(dev);
iommu_fwspec_free(dev);
}
@@ -619,8 +609,8 @@ static const struct iommu_ops qcom_iommu_ops = {
.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
.iotlb_sync = qcom_iommu_iotlb_sync,
.iova_to_phys = qcom_iommu_iova_to_phys,
- .add_device = qcom_iommu_add_device,
- .remove_device = qcom_iommu_remove_device,
+ .probe_device = qcom_iommu_probe_device,
+ .release_device = qcom_iommu_release_device,
.device_group = generic_device_group,
.of_xlate = qcom_iommu_of_xlate,
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 25/34] iommu/rockchip: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Joerg Roedel
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the Rockchip IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/rockchip-iommu.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index b33cdd5aad81..d25c2486ca07 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1054,40 +1054,28 @@ static void rk_iommu_domain_free(struct iommu_domain *domain)
kfree(rk_domain);
}
-static int rk_iommu_add_device(struct device *dev)
+static struct iommu_device *rk_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
- struct rk_iommu *iommu;
struct rk_iommudata *data;
+ struct rk_iommu *iommu;
data = dev->archdata.iommu;
if (!data)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
iommu = rk_iommu_from_dev(dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
- iommu_group_put(group);
-
- iommu_device_link(&iommu->iommu, dev);
data->link = device_link_add(dev, iommu->dev,
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
- return 0;
+ return &iommu->iommu;
}
-static void rk_iommu_remove_device(struct device *dev)
+static void rk_iommu_release_device(struct device *dev)
{
- struct rk_iommu *iommu;
struct rk_iommudata *data = dev->archdata.iommu;
- iommu = rk_iommu_from_dev(dev);
-
device_link_del(data->link);
- iommu_device_unlink(&iommu->iommu, dev);
- iommu_group_remove_device(dev);
}
static struct iommu_group *rk_iommu_device_group(struct device *dev)
@@ -1126,8 +1114,8 @@ static const struct iommu_ops rk_iommu_ops = {
.detach_dev = rk_iommu_detach_device,
.map = rk_iommu_map,
.unmap = rk_iommu_unmap,
- .add_device = rk_iommu_add_device,
- .remove_device = rk_iommu_remove_device,
+ .probe_device = rk_iommu_probe_device,
+ .release_device = rk_iommu_release_device,
.iova_to_phys = rk_iommu_iova_to_phys,
.device_group = rk_iommu_device_group,
.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 25/34] iommu/rockchip: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Rockchip IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/rockchip-iommu.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index b33cdd5aad81..d25c2486ca07 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1054,40 +1054,28 @@ static void rk_iommu_domain_free(struct iommu_domain *domain)
kfree(rk_domain);
}
-static int rk_iommu_add_device(struct device *dev)
+static struct iommu_device *rk_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
- struct rk_iommu *iommu;
struct rk_iommudata *data;
+ struct rk_iommu *iommu;
data = dev->archdata.iommu;
if (!data)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
iommu = rk_iommu_from_dev(dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
- iommu_group_put(group);
-
- iommu_device_link(&iommu->iommu, dev);
data->link = device_link_add(dev, iommu->dev,
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
- return 0;
+ return &iommu->iommu;
}
-static void rk_iommu_remove_device(struct device *dev)
+static void rk_iommu_release_device(struct device *dev)
{
- struct rk_iommu *iommu;
struct rk_iommudata *data = dev->archdata.iommu;
- iommu = rk_iommu_from_dev(dev);
-
device_link_del(data->link);
- iommu_device_unlink(&iommu->iommu, dev);
- iommu_group_remove_device(dev);
}
static struct iommu_group *rk_iommu_device_group(struct device *dev)
@@ -1126,8 +1114,8 @@ static const struct iommu_ops rk_iommu_ops = {
.detach_dev = rk_iommu_detach_device,
.map = rk_iommu_map,
.unmap = rk_iommu_unmap,
- .add_device = rk_iommu_add_device,
- .remove_device = rk_iommu_remove_device,
+ .probe_device = rk_iommu_probe_device,
+ .release_device = rk_iommu_release_device,
.iova_to_phys = rk_iommu_iova_to_phys,
.device_group = rk_iommu_device_group,
.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 25/34] iommu/rockchip: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Rockchip IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/rockchip-iommu.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index b33cdd5aad81..d25c2486ca07 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1054,40 +1054,28 @@ static void rk_iommu_domain_free(struct iommu_domain *domain)
kfree(rk_domain);
}
-static int rk_iommu_add_device(struct device *dev)
+static struct iommu_device *rk_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
- struct rk_iommu *iommu;
struct rk_iommudata *data;
+ struct rk_iommu *iommu;
data = dev->archdata.iommu;
if (!data)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
iommu = rk_iommu_from_dev(dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
- iommu_group_put(group);
-
- iommu_device_link(&iommu->iommu, dev);
data->link = device_link_add(dev, iommu->dev,
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
- return 0;
+ return &iommu->iommu;
}
-static void rk_iommu_remove_device(struct device *dev)
+static void rk_iommu_release_device(struct device *dev)
{
- struct rk_iommu *iommu;
struct rk_iommudata *data = dev->archdata.iommu;
- iommu = rk_iommu_from_dev(dev);
-
device_link_del(data->link);
- iommu_device_unlink(&iommu->iommu, dev);
- iommu_group_remove_device(dev);
}
static struct iommu_group *rk_iommu_device_group(struct device *dev)
@@ -1126,8 +1114,8 @@ static const struct iommu_ops rk_iommu_ops = {
.detach_dev = rk_iommu_detach_device,
.map = rk_iommu_map,
.unmap = rk_iommu_unmap,
- .add_device = rk_iommu_add_device,
- .remove_device = rk_iommu_remove_device,
+ .probe_device = rk_iommu_probe_device,
+ .release_device = rk_iommu_release_device,
.iova_to_phys = rk_iommu_iova_to_phys,
.device_group = rk_iommu_device_group,
.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 25/34] iommu/rockchip: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the Rockchip IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/rockchip-iommu.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index b33cdd5aad81..d25c2486ca07 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1054,40 +1054,28 @@ static void rk_iommu_domain_free(struct iommu_domain *domain)
kfree(rk_domain);
}
-static int rk_iommu_add_device(struct device *dev)
+static struct iommu_device *rk_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
- struct rk_iommu *iommu;
struct rk_iommudata *data;
+ struct rk_iommu *iommu;
data = dev->archdata.iommu;
if (!data)
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
iommu = rk_iommu_from_dev(dev);
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
- iommu_group_put(group);
-
- iommu_device_link(&iommu->iommu, dev);
data->link = device_link_add(dev, iommu->dev,
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
- return 0;
+ return &iommu->iommu;
}
-static void rk_iommu_remove_device(struct device *dev)
+static void rk_iommu_release_device(struct device *dev)
{
- struct rk_iommu *iommu;
struct rk_iommudata *data = dev->archdata.iommu;
- iommu = rk_iommu_from_dev(dev);
-
device_link_del(data->link);
- iommu_device_unlink(&iommu->iommu, dev);
- iommu_group_remove_device(dev);
}
static struct iommu_group *rk_iommu_device_group(struct device *dev)
@@ -1126,8 +1114,8 @@ static const struct iommu_ops rk_iommu_ops = {
.detach_dev = rk_iommu_detach_device,
.map = rk_iommu_map,
.unmap = rk_iommu_unmap,
- .add_device = rk_iommu_add_device,
- .remove_device = rk_iommu_remove_device,
+ .probe_device = rk_iommu_probe_device,
+ .release_device = rk_iommu_release_device,
.iova_to_phys = rk_iommu_iova_to_phys,
.device_group = rk_iommu_device_group,
.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 26/34] iommu/tegra: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Joerg Roedel
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the Tegra IOMMU drivers to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/tegra-gart.c | 24 ++++++------------------
drivers/iommu/tegra-smmu.c | 31 ++++++++-----------------------
2 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index db6559e8336f..5fbdff6ff41a 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap)
return false;
}
-static int gart_iommu_add_device(struct device *dev)
+static struct iommu_device *gart_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
if (!dev_iommu_fwspec_get(dev))
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- iommu_device_link(&gart_handle->iommu, dev);
-
- return 0;
+ return &gart_handle->iommu;
}
-static void gart_iommu_remove_device(struct device *dev)
+static void gart_iommu_release_device(struct device *dev)
{
- iommu_group_remove_device(dev);
- iommu_device_unlink(&gart_handle->iommu, dev);
}
static int gart_iommu_of_xlate(struct device *dev,
@@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = {
.domain_free = gart_iommu_domain_free,
.attach_dev = gart_iommu_attach_dev,
.detach_dev = gart_iommu_detach_dev,
- .add_device = gart_iommu_add_device,
- .remove_device = gart_iommu_remove_device,
+ .probe_device = gart_iommu_probe_device,
+ .release_device = gart_iommu_release_device,
.device_group = generic_device_group,
.map = gart_iommu_map,
.unmap = gart_iommu_unmap,
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 63a147b623e6..7426b7666e2b 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
return 0;
}
-static int tegra_smmu_add_device(struct device *dev)
+static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
{
struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = NULL;
- struct iommu_group *group;
struct of_phandle_args args;
unsigned int index = 0;
int err;
@@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev)
of_node_put(args.np);
if (err < 0)
- return err;
+ return ERR_PTR(err);
/*
* Only a single IOMMU master interface is currently
@@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev)
*/
dev->archdata.iommu = smmu;
- iommu_device_link(&smmu->iommu, dev);
-
break;
}
@@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev)
}
if (!smmu)
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- return 0;
+ return &smmu->iommu;
}
-static void tegra_smmu_remove_device(struct device *dev)
+static void tegra_smmu_release_device(struct device *dev)
{
- struct tegra_smmu *smmu = dev->archdata.iommu;
-
- if (smmu)
- iommu_device_unlink(&smmu->iommu, dev);
-
dev->archdata.iommu = NULL;
- iommu_group_remove_device(dev);
}
static const struct tegra_smmu_group_soc *
@@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = {
.domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev,
- .add_device = tegra_smmu_add_device,
- .remove_device = tegra_smmu_remove_device,
+ .probe_device = tegra_smmu_probe_device,
+ .release_device = tegra_smmu_release_device,
.device_group = tegra_smmu_device_group,
.map = tegra_smmu_map,
.unmap = tegra_smmu_unmap,
@@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
* value. However the IOMMU registration process will attempt to add
* all devices to the IOMMU when bus_set_iommu() is called. In order
* not to rely on global variables to track the IOMMU instance, we
- * set it here so that it can be looked up from the .add_device()
+ * set it here so that it can be looked up from the .probe_device()
* callback via the IOMMU device's .drvdata field.
*/
mc->smmu = smmu;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 26/34] iommu/tegra: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Tegra IOMMU drivers to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/tegra-gart.c | 24 ++++++------------------
drivers/iommu/tegra-smmu.c | 31 ++++++++-----------------------
2 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index db6559e8336f..5fbdff6ff41a 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap)
return false;
}
-static int gart_iommu_add_device(struct device *dev)
+static struct iommu_device *gart_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
if (!dev_iommu_fwspec_get(dev))
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- iommu_device_link(&gart_handle->iommu, dev);
-
- return 0;
+ return &gart_handle->iommu;
}
-static void gart_iommu_remove_device(struct device *dev)
+static void gart_iommu_release_device(struct device *dev)
{
- iommu_group_remove_device(dev);
- iommu_device_unlink(&gart_handle->iommu, dev);
}
static int gart_iommu_of_xlate(struct device *dev,
@@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = {
.domain_free = gart_iommu_domain_free,
.attach_dev = gart_iommu_attach_dev,
.detach_dev = gart_iommu_detach_dev,
- .add_device = gart_iommu_add_device,
- .remove_device = gart_iommu_remove_device,
+ .probe_device = gart_iommu_probe_device,
+ .release_device = gart_iommu_release_device,
.device_group = generic_device_group,
.map = gart_iommu_map,
.unmap = gart_iommu_unmap,
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 63a147b623e6..7426b7666e2b 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
return 0;
}
-static int tegra_smmu_add_device(struct device *dev)
+static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
{
struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = NULL;
- struct iommu_group *group;
struct of_phandle_args args;
unsigned int index = 0;
int err;
@@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev)
of_node_put(args.np);
if (err < 0)
- return err;
+ return ERR_PTR(err);
/*
* Only a single IOMMU master interface is currently
@@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev)
*/
dev->archdata.iommu = smmu;
- iommu_device_link(&smmu->iommu, dev);
-
break;
}
@@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev)
}
if (!smmu)
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- return 0;
+ return &smmu->iommu;
}
-static void tegra_smmu_remove_device(struct device *dev)
+static void tegra_smmu_release_device(struct device *dev)
{
- struct tegra_smmu *smmu = dev->archdata.iommu;
-
- if (smmu)
- iommu_device_unlink(&smmu->iommu, dev);
-
dev->archdata.iommu = NULL;
- iommu_group_remove_device(dev);
}
static const struct tegra_smmu_group_soc *
@@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = {
.domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev,
- .add_device = tegra_smmu_add_device,
- .remove_device = tegra_smmu_remove_device,
+ .probe_device = tegra_smmu_probe_device,
+ .release_device = tegra_smmu_release_device,
.device_group = tegra_smmu_device_group,
.map = tegra_smmu_map,
.unmap = tegra_smmu_unmap,
@@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
* value. However the IOMMU registration process will attempt to add
* all devices to the IOMMU when bus_set_iommu() is called. In order
* not to rely on global variables to track the IOMMU instance, we
- * set it here so that it can be looked up from the .add_device()
+ * set it here so that it can be looked up from the .probe_device()
* callback via the IOMMU device's .drvdata field.
*/
mc->smmu = smmu;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 26/34] iommu/tegra: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the Tegra IOMMU drivers to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/tegra-gart.c | 24 ++++++------------------
drivers/iommu/tegra-smmu.c | 31 ++++++++-----------------------
2 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index db6559e8336f..5fbdff6ff41a 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap)
return false;
}
-static int gart_iommu_add_device(struct device *dev)
+static struct iommu_device *gart_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
if (!dev_iommu_fwspec_get(dev))
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- iommu_device_link(&gart_handle->iommu, dev);
-
- return 0;
+ return &gart_handle->iommu;
}
-static void gart_iommu_remove_device(struct device *dev)
+static void gart_iommu_release_device(struct device *dev)
{
- iommu_group_remove_device(dev);
- iommu_device_unlink(&gart_handle->iommu, dev);
}
static int gart_iommu_of_xlate(struct device *dev,
@@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = {
.domain_free = gart_iommu_domain_free,
.attach_dev = gart_iommu_attach_dev,
.detach_dev = gart_iommu_detach_dev,
- .add_device = gart_iommu_add_device,
- .remove_device = gart_iommu_remove_device,
+ .probe_device = gart_iommu_probe_device,
+ .release_device = gart_iommu_release_device,
.device_group = generic_device_group,
.map = gart_iommu_map,
.unmap = gart_iommu_unmap,
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 63a147b623e6..7426b7666e2b 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
return 0;
}
-static int tegra_smmu_add_device(struct device *dev)
+static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
{
struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = NULL;
- struct iommu_group *group;
struct of_phandle_args args;
unsigned int index = 0;
int err;
@@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev)
of_node_put(args.np);
if (err < 0)
- return err;
+ return ERR_PTR(err);
/*
* Only a single IOMMU master interface is currently
@@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev)
*/
dev->archdata.iommu = smmu;
- iommu_device_link(&smmu->iommu, dev);
-
break;
}
@@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev)
}
if (!smmu)
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- return 0;
+ return &smmu->iommu;
}
-static void tegra_smmu_remove_device(struct device *dev)
+static void tegra_smmu_release_device(struct device *dev)
{
- struct tegra_smmu *smmu = dev->archdata.iommu;
-
- if (smmu)
- iommu_device_unlink(&smmu->iommu, dev);
-
dev->archdata.iommu = NULL;
- iommu_group_remove_device(dev);
}
static const struct tegra_smmu_group_soc *
@@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = {
.domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev,
- .add_device = tegra_smmu_add_device,
- .remove_device = tegra_smmu_remove_device,
+ .probe_device = tegra_smmu_probe_device,
+ .release_device = tegra_smmu_release_device,
.device_group = tegra_smmu_device_group,
.map = tegra_smmu_map,
.unmap = tegra_smmu_unmap,
@@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
* value. However the IOMMU registration process will attempt to add
* all devices to the IOMMU when bus_set_iommu() is called. In order
* not to rely on global variables to track the IOMMU instance, we
- * set it here so that it can be looked up from the .add_device()
+ * set it here so that it can be looked up from the .probe_device()
* callback via the IOMMU device's .drvdata field.
*/
mc->smmu = smmu;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 26/34] iommu/tegra: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the Tegra IOMMU drivers to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/tegra-gart.c | 24 ++++++------------------
drivers/iommu/tegra-smmu.c | 31 ++++++++-----------------------
2 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index db6559e8336f..5fbdff6ff41a 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -243,28 +243,16 @@ static bool gart_iommu_capable(enum iommu_cap cap)
return false;
}
-static int gart_iommu_add_device(struct device *dev)
+static struct iommu_device *gart_iommu_probe_device(struct device *dev)
{
- struct iommu_group *group;
-
if (!dev_iommu_fwspec_get(dev))
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- iommu_device_link(&gart_handle->iommu, dev);
-
- return 0;
+ return &gart_handle->iommu;
}
-static void gart_iommu_remove_device(struct device *dev)
+static void gart_iommu_release_device(struct device *dev)
{
- iommu_group_remove_device(dev);
- iommu_device_unlink(&gart_handle->iommu, dev);
}
static int gart_iommu_of_xlate(struct device *dev,
@@ -290,8 +278,8 @@ static const struct iommu_ops gart_iommu_ops = {
.domain_free = gart_iommu_domain_free,
.attach_dev = gart_iommu_attach_dev,
.detach_dev = gart_iommu_detach_dev,
- .add_device = gart_iommu_add_device,
- .remove_device = gart_iommu_remove_device,
+ .probe_device = gart_iommu_probe_device,
+ .release_device = gart_iommu_release_device,
.device_group = generic_device_group,
.map = gart_iommu_map,
.unmap = gart_iommu_unmap,
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 63a147b623e6..7426b7666e2b 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -757,11 +757,10 @@ static int tegra_smmu_configure(struct tegra_smmu *smmu, struct device *dev,
return 0;
}
-static int tegra_smmu_add_device(struct device *dev)
+static struct iommu_device *tegra_smmu_probe_device(struct device *dev)
{
struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = NULL;
- struct iommu_group *group;
struct of_phandle_args args;
unsigned int index = 0;
int err;
@@ -774,7 +773,7 @@ static int tegra_smmu_add_device(struct device *dev)
of_node_put(args.np);
if (err < 0)
- return err;
+ return ERR_PTR(err);
/*
* Only a single IOMMU master interface is currently
@@ -783,8 +782,6 @@ static int tegra_smmu_add_device(struct device *dev)
*/
dev->archdata.iommu = smmu;
- iommu_device_link(&smmu->iommu, dev);
-
break;
}
@@ -793,26 +790,14 @@ static int tegra_smmu_add_device(struct device *dev)
}
if (!smmu)
- return -ENODEV;
-
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- iommu_group_put(group);
+ return ERR_PTR(-ENODEV);
- return 0;
+ return &smmu->iommu;
}
-static void tegra_smmu_remove_device(struct device *dev)
+static void tegra_smmu_release_device(struct device *dev)
{
- struct tegra_smmu *smmu = dev->archdata.iommu;
-
- if (smmu)
- iommu_device_unlink(&smmu->iommu, dev);
-
dev->archdata.iommu = NULL;
- iommu_group_remove_device(dev);
}
static const struct tegra_smmu_group_soc *
@@ -895,8 +880,8 @@ static const struct iommu_ops tegra_smmu_ops = {
.domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev,
- .add_device = tegra_smmu_add_device,
- .remove_device = tegra_smmu_remove_device,
+ .probe_device = tegra_smmu_probe_device,
+ .release_device = tegra_smmu_release_device,
.device_group = tegra_smmu_device_group,
.map = tegra_smmu_map,
.unmap = tegra_smmu_unmap,
@@ -1015,7 +1000,7 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
* value. However the IOMMU registration process will attempt to add
* all devices to the IOMMU when bus_set_iommu() is called. In order
* not to rely on global variables to track the IOMMU instance, we
- * set it here so that it can be looked up from the .add_device()
+ * set it here so that it can be looked up from the .probe_device()
* callback via the IOMMU device's .drvdata field.
*/
mc->smmu = smmu;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 28/34] iommu/omap: Remove orphan_dev tracking
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Remove the tracking of device which could not be probed because
their IOMMU is not probed yet. Replace it with a call to
bus_iommu_probe() when a new IOMMU is probed.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/omap-iommu.c | 54 +++-----------------------------------
1 file changed, 4 insertions(+), 50 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 887fefcb03b4..ecc9d0829a91 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -35,15 +35,6 @@
static const struct iommu_ops omap_iommu_ops;
-struct orphan_dev {
- struct device *dev;
- struct list_head node;
-};
-
-static LIST_HEAD(orphan_dev_list);
-
-static DEFINE_SPINLOCK(orphan_lock);
-
#define to_iommu(dev) ((struct omap_iommu *)dev_get_drvdata(dev))
/* bitmap of the page sizes currently supported */
@@ -62,8 +53,6 @@ static DEFINE_SPINLOCK(orphan_lock);
static struct platform_driver omap_iommu_driver;
static struct kmem_cache *iopte_cachep;
-static int _omap_iommu_add_device(struct device *dev);
-
/**
* to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain
* @dom: generic iommu domain handle
@@ -1177,7 +1166,6 @@ static int omap_iommu_probe(struct platform_device *pdev)
struct omap_iommu *obj;
struct resource *res;
struct device_node *of = pdev->dev.of_node;
- struct orphan_dev *orphan_dev, *tmp;
if (!of) {
pr_err("%s: only DT-based devices are supported\n", __func__);
@@ -1260,13 +1248,8 @@ static int omap_iommu_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "%s registered\n", obj->name);
- list_for_each_entry_safe(orphan_dev, tmp, &orphan_dev_list, node) {
- err = _omap_iommu_add_device(orphan_dev->dev);
- if (!err) {
- list_del(&orphan_dev->node);
- kfree(orphan_dev);
- }
- }
+ /* Re-probe bus to probe device attached to this IOMMU */
+ bus_iommu_probe(&platform_bus_type);
return 0;
@@ -1657,7 +1640,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int _omap_iommu_add_device(struct device *dev)
+static int omap_iommu_add_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
struct omap_iommu *oiommu;
@@ -1666,8 +1649,6 @@ static int _omap_iommu_add_device(struct device *dev)
struct platform_device *pdev;
int num_iommus, i;
int ret;
- struct orphan_dev *orphan_dev;
- unsigned long flags;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1702,23 +1683,7 @@ static int _omap_iommu_add_device(struct device *dev)
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- spin_lock_irqsave(&orphan_lock, flags);
- list_for_each_entry(orphan_dev, &orphan_dev_list,
- node) {
- if (orphan_dev->dev == dev)
- break;
- }
- spin_unlock_irqrestore(&orphan_lock, flags);
-
- if (orphan_dev && orphan_dev->dev == dev)
- return -EPROBE_DEFER;
-
- orphan_dev = kzalloc(sizeof(*orphan_dev), GFP_KERNEL);
- orphan_dev->dev = dev;
- spin_lock_irqsave(&orphan_lock, flags);
- list_add(&orphan_dev->node, &orphan_dev_list);
- spin_unlock_irqrestore(&orphan_lock, flags);
- return -EPROBE_DEFER;
+ return -ENODEV;
}
oiommu = platform_get_drvdata(pdev);
@@ -1764,17 +1729,6 @@ static int _omap_iommu_add_device(struct device *dev)
return 0;
}
-static int omap_iommu_add_device(struct device *dev)
-{
- int ret;
-
- ret = _omap_iommu_add_device(dev);
- if (ret == -EPROBE_DEFER)
- return 0;
-
- return ret;
-}
-
static void omap_iommu_remove_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 28/34] iommu/omap: Remove orphan_dev tracking
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Remove the tracking of device which could not be probed because
their IOMMU is not probed yet. Replace it with a call to
bus_iommu_probe() when a new IOMMU is probed.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 54 +++-----------------------------------
1 file changed, 4 insertions(+), 50 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 887fefcb03b4..ecc9d0829a91 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -35,15 +35,6 @@
static const struct iommu_ops omap_iommu_ops;
-struct orphan_dev {
- struct device *dev;
- struct list_head node;
-};
-
-static LIST_HEAD(orphan_dev_list);
-
-static DEFINE_SPINLOCK(orphan_lock);
-
#define to_iommu(dev) ((struct omap_iommu *)dev_get_drvdata(dev))
/* bitmap of the page sizes currently supported */
@@ -62,8 +53,6 @@ static DEFINE_SPINLOCK(orphan_lock);
static struct platform_driver omap_iommu_driver;
static struct kmem_cache *iopte_cachep;
-static int _omap_iommu_add_device(struct device *dev);
-
/**
* to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain
* @dom: generic iommu domain handle
@@ -1177,7 +1166,6 @@ static int omap_iommu_probe(struct platform_device *pdev)
struct omap_iommu *obj;
struct resource *res;
struct device_node *of = pdev->dev.of_node;
- struct orphan_dev *orphan_dev, *tmp;
if (!of) {
pr_err("%s: only DT-based devices are supported\n", __func__);
@@ -1260,13 +1248,8 @@ static int omap_iommu_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "%s registered\n", obj->name);
- list_for_each_entry_safe(orphan_dev, tmp, &orphan_dev_list, node) {
- err = _omap_iommu_add_device(orphan_dev->dev);
- if (!err) {
- list_del(&orphan_dev->node);
- kfree(orphan_dev);
- }
- }
+ /* Re-probe bus to probe device attached to this IOMMU */
+ bus_iommu_probe(&platform_bus_type);
return 0;
@@ -1657,7 +1640,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int _omap_iommu_add_device(struct device *dev)
+static int omap_iommu_add_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
struct omap_iommu *oiommu;
@@ -1666,8 +1649,6 @@ static int _omap_iommu_add_device(struct device *dev)
struct platform_device *pdev;
int num_iommus, i;
int ret;
- struct orphan_dev *orphan_dev;
- unsigned long flags;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1702,23 +1683,7 @@ static int _omap_iommu_add_device(struct device *dev)
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- spin_lock_irqsave(&orphan_lock, flags);
- list_for_each_entry(orphan_dev, &orphan_dev_list,
- node) {
- if (orphan_dev->dev == dev)
- break;
- }
- spin_unlock_irqrestore(&orphan_lock, flags);
-
- if (orphan_dev && orphan_dev->dev == dev)
- return -EPROBE_DEFER;
-
- orphan_dev = kzalloc(sizeof(*orphan_dev), GFP_KERNEL);
- orphan_dev->dev = dev;
- spin_lock_irqsave(&orphan_lock, flags);
- list_add(&orphan_dev->node, &orphan_dev_list);
- spin_unlock_irqrestore(&orphan_lock, flags);
- return -EPROBE_DEFER;
+ return -ENODEV;
}
oiommu = platform_get_drvdata(pdev);
@@ -1764,17 +1729,6 @@ static int _omap_iommu_add_device(struct device *dev)
return 0;
}
-static int omap_iommu_add_device(struct device *dev)
-{
- int ret;
-
- ret = _omap_iommu_add_device(dev);
- if (ret == -EPROBE_DEFER)
- return 0;
-
- return ret;
-}
-
static void omap_iommu_remove_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 28/34] iommu/omap: Remove orphan_dev tracking
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Remove the tracking of device which could not be probed because
their IOMMU is not probed yet. Replace it with a call to
bus_iommu_probe() when a new IOMMU is probed.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 54 +++-----------------------------------
1 file changed, 4 insertions(+), 50 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 887fefcb03b4..ecc9d0829a91 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -35,15 +35,6 @@
static const struct iommu_ops omap_iommu_ops;
-struct orphan_dev {
- struct device *dev;
- struct list_head node;
-};
-
-static LIST_HEAD(orphan_dev_list);
-
-static DEFINE_SPINLOCK(orphan_lock);
-
#define to_iommu(dev) ((struct omap_iommu *)dev_get_drvdata(dev))
/* bitmap of the page sizes currently supported */
@@ -62,8 +53,6 @@ static DEFINE_SPINLOCK(orphan_lock);
static struct platform_driver omap_iommu_driver;
static struct kmem_cache *iopte_cachep;
-static int _omap_iommu_add_device(struct device *dev);
-
/**
* to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain
* @dom: generic iommu domain handle
@@ -1177,7 +1166,6 @@ static int omap_iommu_probe(struct platform_device *pdev)
struct omap_iommu *obj;
struct resource *res;
struct device_node *of = pdev->dev.of_node;
- struct orphan_dev *orphan_dev, *tmp;
if (!of) {
pr_err("%s: only DT-based devices are supported\n", __func__);
@@ -1260,13 +1248,8 @@ static int omap_iommu_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "%s registered\n", obj->name);
- list_for_each_entry_safe(orphan_dev, tmp, &orphan_dev_list, node) {
- err = _omap_iommu_add_device(orphan_dev->dev);
- if (!err) {
- list_del(&orphan_dev->node);
- kfree(orphan_dev);
- }
- }
+ /* Re-probe bus to probe device attached to this IOMMU */
+ bus_iommu_probe(&platform_bus_type);
return 0;
@@ -1657,7 +1640,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int _omap_iommu_add_device(struct device *dev)
+static int omap_iommu_add_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
struct omap_iommu *oiommu;
@@ -1666,8 +1649,6 @@ static int _omap_iommu_add_device(struct device *dev)
struct platform_device *pdev;
int num_iommus, i;
int ret;
- struct orphan_dev *orphan_dev;
- unsigned long flags;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1702,23 +1683,7 @@ static int _omap_iommu_add_device(struct device *dev)
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- spin_lock_irqsave(&orphan_lock, flags);
- list_for_each_entry(orphan_dev, &orphan_dev_list,
- node) {
- if (orphan_dev->dev == dev)
- break;
- }
- spin_unlock_irqrestore(&orphan_lock, flags);
-
- if (orphan_dev && orphan_dev->dev == dev)
- return -EPROBE_DEFER;
-
- orphan_dev = kzalloc(sizeof(*orphan_dev), GFP_KERNEL);
- orphan_dev->dev = dev;
- spin_lock_irqsave(&orphan_lock, flags);
- list_add(&orphan_dev->node, &orphan_dev_list);
- spin_unlock_irqrestore(&orphan_lock, flags);
- return -EPROBE_DEFER;
+ return -ENODEV;
}
oiommu = platform_get_drvdata(pdev);
@@ -1764,17 +1729,6 @@ static int _omap_iommu_add_device(struct device *dev)
return 0;
}
-static int omap_iommu_add_device(struct device *dev)
-{
- int ret;
-
- ret = _omap_iommu_add_device(dev);
- if (ret == -EPROBE_DEFER)
- return 0;
-
- return ret;
-}
-
static void omap_iommu_remove_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 28/34] iommu/omap: Remove orphan_dev tracking
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Remove the tracking of device which could not be probed because
their IOMMU is not probed yet. Replace it with a call to
bus_iommu_probe() when a new IOMMU is probed.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 54 +++-----------------------------------
1 file changed, 4 insertions(+), 50 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 887fefcb03b4..ecc9d0829a91 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -35,15 +35,6 @@
static const struct iommu_ops omap_iommu_ops;
-struct orphan_dev {
- struct device *dev;
- struct list_head node;
-};
-
-static LIST_HEAD(orphan_dev_list);
-
-static DEFINE_SPINLOCK(orphan_lock);
-
#define to_iommu(dev) ((struct omap_iommu *)dev_get_drvdata(dev))
/* bitmap of the page sizes currently supported */
@@ -62,8 +53,6 @@ static DEFINE_SPINLOCK(orphan_lock);
static struct platform_driver omap_iommu_driver;
static struct kmem_cache *iopte_cachep;
-static int _omap_iommu_add_device(struct device *dev);
-
/**
* to_omap_domain - Get struct omap_iommu_domain from generic iommu_domain
* @dom: generic iommu domain handle
@@ -1177,7 +1166,6 @@ static int omap_iommu_probe(struct platform_device *pdev)
struct omap_iommu *obj;
struct resource *res;
struct device_node *of = pdev->dev.of_node;
- struct orphan_dev *orphan_dev, *tmp;
if (!of) {
pr_err("%s: only DT-based devices are supported\n", __func__);
@@ -1260,13 +1248,8 @@ static int omap_iommu_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "%s registered\n", obj->name);
- list_for_each_entry_safe(orphan_dev, tmp, &orphan_dev_list, node) {
- err = _omap_iommu_add_device(orphan_dev->dev);
- if (!err) {
- list_del(&orphan_dev->node);
- kfree(orphan_dev);
- }
- }
+ /* Re-probe bus to probe device attached to this IOMMU */
+ bus_iommu_probe(&platform_bus_type);
return 0;
@@ -1657,7 +1640,7 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int _omap_iommu_add_device(struct device *dev)
+static int omap_iommu_add_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
struct omap_iommu *oiommu;
@@ -1666,8 +1649,6 @@ static int _omap_iommu_add_device(struct device *dev)
struct platform_device *pdev;
int num_iommus, i;
int ret;
- struct orphan_dev *orphan_dev;
- unsigned long flags;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1702,23 +1683,7 @@ static int _omap_iommu_add_device(struct device *dev)
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- spin_lock_irqsave(&orphan_lock, flags);
- list_for_each_entry(orphan_dev, &orphan_dev_list,
- node) {
- if (orphan_dev->dev == dev)
- break;
- }
- spin_unlock_irqrestore(&orphan_lock, flags);
-
- if (orphan_dev && orphan_dev->dev == dev)
- return -EPROBE_DEFER;
-
- orphan_dev = kzalloc(sizeof(*orphan_dev), GFP_KERNEL);
- orphan_dev->dev = dev;
- spin_lock_irqsave(&orphan_lock, flags);
- list_add(&orphan_dev->node, &orphan_dev_list);
- spin_unlock_irqrestore(&orphan_lock, flags);
- return -EPROBE_DEFER;
+ return -ENODEV;
}
oiommu = platform_get_drvdata(pdev);
@@ -1764,17 +1729,6 @@ static int _omap_iommu_add_device(struct device *dev)
return 0;
}
-static int omap_iommu_add_device(struct device *dev)
-{
- int ret;
-
- ret = _omap_iommu_add_device(dev);
- if (ret == -EPROBE_DEFER)
- return 0;
-
- return ret;
-}
-
static void omap_iommu_remove_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 29/34] iommu/omap: Convert to probe/release_device() call-backs
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel Drake,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Joerg Roedel,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Convert the OMAP IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/omap-iommu.c | 49 ++++++++++----------------------------
1 file changed, 13 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index ecc9d0829a91..6699fe6d9e06 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int omap_iommu_add_device(struct device *dev)
+static struct iommu_device *omap_iommu_probe_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
+ struct platform_device *pdev;
struct omap_iommu *oiommu;
- struct iommu_group *group;
struct device_node *np;
- struct platform_device *pdev;
int num_iommus, i;
- int ret;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev)
* IOMMU users.
*/
if (!dev->of_node)
- return 0;
+ return ERR_PTR(-ENODEV);
/*
* retrieve the count of IOMMU nodes using phandle size as element size
@@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev)
arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL);
if (!arch_data)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
np = of_parse_phandle(dev->of_node, "iommus", i);
if (!np) {
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
pdev = of_find_device_by_node(np);
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
tmp->iommu_dev = oiommu;
@@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev)
of_node_put(np);
}
+ dev->archdata.iommu = arch_data;
+
/*
* use the first IOMMU alone for the sysfs device linking.
* TODO: Evaluate if a single iommu_group needs to be
* maintained for both IOMMUs
*/
oiommu = arch_data->iommu_dev;
- ret = iommu_device_link(&oiommu->iommu, dev);
- if (ret) {
- kfree(arch_data);
- return ret;
- }
-
- dev->archdata.iommu = arch_data;
-
- /*
- * IOMMU group initialization calls into omap_iommu_device_group, which
- * needs a valid dev->archdata.iommu pointer
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- iommu_device_unlink(&oiommu->iommu, dev);
- dev->archdata.iommu = NULL;
- kfree(arch_data);
- return PTR_ERR(group);
- }
- iommu_group_put(group);
- return 0;
+ return &oiommu->iommu;
}
-static void omap_iommu_remove_device(struct device *dev)
+static void omap_iommu_release_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
if (!dev->of_node || !arch_data)
return;
- iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
- iommu_group_remove_device(dev);
-
dev->archdata.iommu = NULL;
kfree(arch_data);
@@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = {
.map = omap_iommu_map,
.unmap = omap_iommu_unmap,
.iova_to_phys = omap_iommu_iova_to_phys,
- .add_device = omap_iommu_add_device,
- .remove_device = omap_iommu_remove_device,
+ .probe_device = omap_iommu_probe_device,
+ .release_device = omap_iommu_release_device,
.device_group = omap_iommu_device_group,
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 29/34] iommu/omap: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the OMAP IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 49 ++++++++++----------------------------
1 file changed, 13 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index ecc9d0829a91..6699fe6d9e06 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int omap_iommu_add_device(struct device *dev)
+static struct iommu_device *omap_iommu_probe_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
+ struct platform_device *pdev;
struct omap_iommu *oiommu;
- struct iommu_group *group;
struct device_node *np;
- struct platform_device *pdev;
int num_iommus, i;
- int ret;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev)
* IOMMU users.
*/
if (!dev->of_node)
- return 0;
+ return ERR_PTR(-ENODEV);
/*
* retrieve the count of IOMMU nodes using phandle size as element size
@@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev)
arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL);
if (!arch_data)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
np = of_parse_phandle(dev->of_node, "iommus", i);
if (!np) {
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
pdev = of_find_device_by_node(np);
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
tmp->iommu_dev = oiommu;
@@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev)
of_node_put(np);
}
+ dev->archdata.iommu = arch_data;
+
/*
* use the first IOMMU alone for the sysfs device linking.
* TODO: Evaluate if a single iommu_group needs to be
* maintained for both IOMMUs
*/
oiommu = arch_data->iommu_dev;
- ret = iommu_device_link(&oiommu->iommu, dev);
- if (ret) {
- kfree(arch_data);
- return ret;
- }
-
- dev->archdata.iommu = arch_data;
-
- /*
- * IOMMU group initialization calls into omap_iommu_device_group, which
- * needs a valid dev->archdata.iommu pointer
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- iommu_device_unlink(&oiommu->iommu, dev);
- dev->archdata.iommu = NULL;
- kfree(arch_data);
- return PTR_ERR(group);
- }
- iommu_group_put(group);
- return 0;
+ return &oiommu->iommu;
}
-static void omap_iommu_remove_device(struct device *dev)
+static void omap_iommu_release_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
if (!dev->of_node || !arch_data)
return;
- iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
- iommu_group_remove_device(dev);
-
dev->archdata.iommu = NULL;
kfree(arch_data);
@@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = {
.map = omap_iommu_map,
.unmap = omap_iommu_unmap,
.iova_to_phys = omap_iommu_iova_to_phys,
- .add_device = omap_iommu_add_device,
- .remove_device = omap_iommu_remove_device,
+ .probe_device = omap_iommu_probe_device,
+ .release_device = omap_iommu_release_device,
.device_group = omap_iommu_device_group,
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
};
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 29/34] iommu/omap: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
Convert the OMAP IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 49 ++++++++++----------------------------
1 file changed, 13 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index ecc9d0829a91..6699fe6d9e06 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int omap_iommu_add_device(struct device *dev)
+static struct iommu_device *omap_iommu_probe_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
+ struct platform_device *pdev;
struct omap_iommu *oiommu;
- struct iommu_group *group;
struct device_node *np;
- struct platform_device *pdev;
int num_iommus, i;
- int ret;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev)
* IOMMU users.
*/
if (!dev->of_node)
- return 0;
+ return ERR_PTR(-ENODEV);
/*
* retrieve the count of IOMMU nodes using phandle size as element size
@@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev)
arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL);
if (!arch_data)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
np = of_parse_phandle(dev->of_node, "iommus", i);
if (!np) {
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
pdev = of_find_device_by_node(np);
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
tmp->iommu_dev = oiommu;
@@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev)
of_node_put(np);
}
+ dev->archdata.iommu = arch_data;
+
/*
* use the first IOMMU alone for the sysfs device linking.
* TODO: Evaluate if a single iommu_group needs to be
* maintained for both IOMMUs
*/
oiommu = arch_data->iommu_dev;
- ret = iommu_device_link(&oiommu->iommu, dev);
- if (ret) {
- kfree(arch_data);
- return ret;
- }
-
- dev->archdata.iommu = arch_data;
-
- /*
- * IOMMU group initialization calls into omap_iommu_device_group, which
- * needs a valid dev->archdata.iommu pointer
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- iommu_device_unlink(&oiommu->iommu, dev);
- dev->archdata.iommu = NULL;
- kfree(arch_data);
- return PTR_ERR(group);
- }
- iommu_group_put(group);
- return 0;
+ return &oiommu->iommu;
}
-static void omap_iommu_remove_device(struct device *dev)
+static void omap_iommu_release_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
if (!dev->of_node || !arch_data)
return;
- iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
- iommu_group_remove_device(dev);
-
dev->archdata.iommu = NULL;
kfree(arch_data);
@@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = {
.map = omap_iommu_map,
.unmap = omap_iommu_unmap,
.iova_to_phys = omap_iommu_iova_to_phys,
- .add_device = omap_iommu_add_device,
- .remove_device = omap_iommu_remove_device,
+ .probe_device = omap_iommu_probe_device,
+ .release_device = omap_iommu_release_device,
.device_group = omap_iommu_device_group,
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
};
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 29/34] iommu/omap: Convert to probe/release_device() call-backs
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
Convert the OMAP IOMMU driver to use the probe_device() and
release_device() call-backs of iommu_ops, so that the iommu core code
does the group and sysfs setup.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/omap-iommu.c | 49 ++++++++++----------------------------
1 file changed, 13 insertions(+), 36 deletions(-)
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index ecc9d0829a91..6699fe6d9e06 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1640,15 +1640,13 @@ static phys_addr_t omap_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static int omap_iommu_add_device(struct device *dev)
+static struct iommu_device *omap_iommu_probe_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data, *tmp;
+ struct platform_device *pdev;
struct omap_iommu *oiommu;
- struct iommu_group *group;
struct device_node *np;
- struct platform_device *pdev;
int num_iommus, i;
- int ret;
/*
* Allocate the archdata iommu structure for DT-based devices.
@@ -1657,7 +1655,7 @@ static int omap_iommu_add_device(struct device *dev)
* IOMMU users.
*/
if (!dev->of_node)
- return 0;
+ return ERR_PTR(-ENODEV);
/*
* retrieve the count of IOMMU nodes using phandle size as element size
@@ -1670,27 +1668,27 @@ static int omap_iommu_add_device(struct device *dev)
arch_data = kcalloc(num_iommus + 1, sizeof(*arch_data), GFP_KERNEL);
if (!arch_data)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
for (i = 0, tmp = arch_data; i < num_iommus; i++, tmp++) {
np = of_parse_phandle(dev->of_node, "iommus", i);
if (!np) {
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
pdev = of_find_device_by_node(np);
if (!pdev) {
of_node_put(np);
kfree(arch_data);
- return -ENODEV;
+ return ERR_PTR(-ENODEV);
}
oiommu = platform_get_drvdata(pdev);
if (!oiommu) {
of_node_put(np);
kfree(arch_data);
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
tmp->iommu_dev = oiommu;
@@ -1699,46 +1697,25 @@ static int omap_iommu_add_device(struct device *dev)
of_node_put(np);
}
+ dev->archdata.iommu = arch_data;
+
/*
* use the first IOMMU alone for the sysfs device linking.
* TODO: Evaluate if a single iommu_group needs to be
* maintained for both IOMMUs
*/
oiommu = arch_data->iommu_dev;
- ret = iommu_device_link(&oiommu->iommu, dev);
- if (ret) {
- kfree(arch_data);
- return ret;
- }
-
- dev->archdata.iommu = arch_data;
-
- /*
- * IOMMU group initialization calls into omap_iommu_device_group, which
- * needs a valid dev->archdata.iommu pointer
- */
- group = iommu_group_get_for_dev(dev);
- if (IS_ERR(group)) {
- iommu_device_unlink(&oiommu->iommu, dev);
- dev->archdata.iommu = NULL;
- kfree(arch_data);
- return PTR_ERR(group);
- }
- iommu_group_put(group);
- return 0;
+ return &oiommu->iommu;
}
-static void omap_iommu_remove_device(struct device *dev)
+static void omap_iommu_release_device(struct device *dev)
{
struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
if (!dev->of_node || !arch_data)
return;
- iommu_device_unlink(&arch_data->iommu_dev->iommu, dev);
- iommu_group_remove_device(dev);
-
dev->archdata.iommu = NULL;
kfree(arch_data);
@@ -1763,8 +1740,8 @@ static const struct iommu_ops omap_iommu_ops = {
.map = omap_iommu_map,
.unmap = omap_iommu_unmap,
.iova_to_phys = omap_iommu_iova_to_phys,
- .add_device = omap_iommu_add_device,
- .remove_device = omap_iommu_remove_device,
+ .probe_device = omap_iommu_probe_device,
+ .release_device = omap_iommu_release_device,
.device_group = omap_iommu_device_group,
.pgsize_bitmap = OMAP_IOMMU_PGSIZES,
};
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 30/34] iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Joerg Roedel
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
On Exynos platforms there can be more than one SYSMMU (IOMMU) for one
DMA master device. Since the IOMMU core code expects only one hardware
IOMMU, use the first SYSMMU in the list.
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/exynos-iommu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 186ff5cc975c..09cdd163560a 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -1261,6 +1261,11 @@ static int exynos_iommu_add_device(struct device *dev)
}
iommu_group_put(group);
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_link(&data->iommu, dev);
+
return 0;
}
@@ -1286,6 +1291,11 @@ static void exynos_iommu_remove_device(struct device *dev)
list_for_each_entry(data, &owner->controllers, owner_node)
device_link_del(data->link);
+
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_unlink(&data->iommu, dev);
}
static int exynos_iommu_of_xlate(struct device *dev,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 30/34] iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
On Exynos platforms there can be more than one SYSMMU (IOMMU) for one
DMA master device. Since the IOMMU core code expects only one hardware
IOMMU, use the first SYSMMU in the list.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/exynos-iommu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 186ff5cc975c..09cdd163560a 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -1261,6 +1261,11 @@ static int exynos_iommu_add_device(struct device *dev)
}
iommu_group_put(group);
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_link(&data->iommu, dev);
+
return 0;
}
@@ -1286,6 +1291,11 @@ static void exynos_iommu_remove_device(struct device *dev)
list_for_each_entry(data, &owner->controllers, owner_node)
device_link_del(data->link);
+
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_unlink(&data->iommu, dev);
}
static int exynos_iommu_of_xlate(struct device *dev,
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 30/34] iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
On Exynos platforms there can be more than one SYSMMU (IOMMU) for one
DMA master device. Since the IOMMU core code expects only one hardware
IOMMU, use the first SYSMMU in the list.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/exynos-iommu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 186ff5cc975c..09cdd163560a 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -1261,6 +1261,11 @@ static int exynos_iommu_add_device(struct device *dev)
}
iommu_group_put(group);
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_link(&data->iommu, dev);
+
return 0;
}
@@ -1286,6 +1291,11 @@ static void exynos_iommu_remove_device(struct device *dev)
list_for_each_entry(data, &owner->controllers, owner_node)
device_link_del(data->link);
+
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_unlink(&data->iommu, dev);
}
static int exynos_iommu_of_xlate(struct device *dev,
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 30/34] iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
On Exynos platforms there can be more than one SYSMMU (IOMMU) for one
DMA master device. Since the IOMMU core code expects only one hardware
IOMMU, use the first SYSMMU in the list.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/exynos-iommu.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 186ff5cc975c..09cdd163560a 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -1261,6 +1261,11 @@ static int exynos_iommu_add_device(struct device *dev)
}
iommu_group_put(group);
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_link(&data->iommu, dev);
+
return 0;
}
@@ -1286,6 +1291,11 @@ static void exynos_iommu_remove_device(struct device *dev)
list_for_each_entry(data, &owner->controllers, owner_node)
device_link_del(data->link);
+
+ /* There is always at least one entry, see exynos_iommu_of_xlate() */
+ data = list_first_entry(&owner->controllers,
+ struct sysmmu_drvdata, owner_node);
+ iommu_device_unlink(&data->iommu, dev);
}
static int exynos_iommu_of_xlate(struct device *dev,
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 32/34] iommu: Remove add_device()/remove_device() code-paths
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-04-29 13:37 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-tegra-u79uwXL29TY76Z2rM5mHXA,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Joerg Roedel
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
All drivers are converted to use the probe/release_device()
call-backs, so the add_device/remove_device() pointers are unused and
the code using them can be removed.
Tested-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Acked-by: Marek Szyprowski <m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
drivers/iommu/iommu.c | 158 ++++++++++--------------------------------
include/linux/iommu.h | 4 --
2 files changed, 38 insertions(+), 124 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 397fd4fd0c32..7f99e5ae432c 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -220,12 +220,20 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
return ret;
}
-static int __iommu_probe_device_helper(struct device *dev)
+int iommu_probe_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
int ret;
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_out;
+ }
+
ret = __iommu_probe_device(dev, NULL);
if (ret)
goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev)
err_release:
iommu_release_device(dev);
+
err_out:
return ret;
}
-int iommu_probe_device(struct device *dev)
+void iommu_release_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
- struct iommu_group *group;
- int ret;
-
- WARN_ON(dev->iommu_group);
-
- if (!ops)
- return -EINVAL;
-
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_free_dev_param;
- }
-
- if (ops->probe_device)
- return __iommu_probe_device_helper(dev);
-
- ret = ops->add_device(dev);
- if (ret)
- goto err_module_put;
- group = iommu_group_get(dev);
- iommu_create_device_direct_mappings(group, dev);
- iommu_group_put(group);
-
- if (ops->probe_finalize)
- ops->probe_finalize(dev);
-
- return 0;
-
-err_module_put:
- module_put(ops->owner);
-err_free_dev_param:
- dev_iommu_free(dev);
- return ret;
-}
-
-static void __iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
+ if (!dev->iommu)
+ return;
iommu_device_unlink(dev->iommu->iommu_dev, dev);
-
iommu_group_remove_device(dev);
ops->release_device(dev);
-}
-
-void iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
-
- if (!dev->iommu)
- return;
-
- if (ops->release_device)
- __iommu_release_device(dev);
- else if (dev->iommu_group)
- ops->remove_device(dev);
module_put(ops->owner);
dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (ret)
goto out_put_group;
- /*
- * Try to allocate a default domain - needs support from the
- * IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked. Only
- * allocate the domain here when the driver still has the
- * add_device/remove_device call-backs implemented.
- */
- if (!ops->probe_device) {
- iommu_alloc_default_domain(dev);
-
- if (group->default_domain)
- ret = __iommu_attach_device(group->default_domain, dev);
-
- if (ret)
- goto out_put_group;
- }
-
return group;
out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
return group->default_domain;
}
-static int add_iommu_group(struct device *dev, void *data)
-{
- int ret = iommu_probe_device(dev);
-
- /*
- * We ignore -ENODEV errors for now, as they just mean that the
- * device is not translated by an IOMMU. We still care about
- * other errors and fail to initialize when they happen.
- */
- if (ret == -ENODEV)
- ret = 0;
-
- return ret;
-}
-
static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -1793,47 +1717,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
int bus_iommu_probe(struct bus_type *bus)
{
- const struct iommu_ops *ops = bus->iommu_ops;
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
int ret;
- if (ops->probe_device) {
- struct iommu_group *group, *next;
- LIST_HEAD(group_list);
-
- /*
- * This code-path does not allocate the default domain when
- * creating the iommu group, so do it after the groups are
- * created.
- */
- ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
- if (ret)
- return ret;
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
- list_for_each_entry_safe(group, next, &group_list, entry) {
- /* Remove item from the list */
- list_del_init(&group->entry);
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
- mutex_lock(&group->mutex);
+ mutex_lock(&group->mutex);
- /* Try to allocate default domain */
- probe_alloc_default_domain(bus, group);
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
- if (!group->default_domain) {
- mutex_unlock(&group->mutex);
- continue;
- }
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
- iommu_group_create_direct_mappings(group);
+ iommu_group_create_direct_mappings(group);
- ret = __iommu_group_dma_attach(group);
+ ret = __iommu_group_dma_attach(group);
- mutex_unlock(&group->mutex);
+ mutex_unlock(&group->mutex);
- if (ret)
- break;
- }
- } else {
- ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ if (ret)
+ break;
}
return ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fea1622408ad..dd076366383f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather {
* @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
* queue
* @iova_to_phys: translate iova to physical address
- * @add_device: add device to iommu grouping
- * @remove_device: remove device from iommu grouping
* @probe_device: Add device to iommu driver handling
* @release_device: Remove device from iommu driver handling
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops {
void (*iotlb_sync)(struct iommu_domain *domain,
struct iommu_iotlb_gather *iotlb_gather);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
- int (*add_device)(struct device *dev);
- void (*remove_device)(struct device *dev);
struct iommu_device *(*probe_device)(struct device *dev);
void (*release_device)(struct device *dev);
void (*probe_finalize)(struct device *dev);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 32/34] iommu: Remove add_device()/remove_device() code-paths
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
All drivers are converted to use the probe/release_device()
call-backs, so the add_device/remove_device() pointers are unused and
the code using them can be removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 158 ++++++++++--------------------------------
include/linux/iommu.h | 4 --
2 files changed, 38 insertions(+), 124 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 397fd4fd0c32..7f99e5ae432c 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -220,12 +220,20 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
return ret;
}
-static int __iommu_probe_device_helper(struct device *dev)
+int iommu_probe_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
int ret;
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_out;
+ }
+
ret = __iommu_probe_device(dev, NULL);
if (ret)
goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev)
err_release:
iommu_release_device(dev);
+
err_out:
return ret;
}
-int iommu_probe_device(struct device *dev)
+void iommu_release_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
- struct iommu_group *group;
- int ret;
-
- WARN_ON(dev->iommu_group);
-
- if (!ops)
- return -EINVAL;
-
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_free_dev_param;
- }
-
- if (ops->probe_device)
- return __iommu_probe_device_helper(dev);
-
- ret = ops->add_device(dev);
- if (ret)
- goto err_module_put;
- group = iommu_group_get(dev);
- iommu_create_device_direct_mappings(group, dev);
- iommu_group_put(group);
-
- if (ops->probe_finalize)
- ops->probe_finalize(dev);
-
- return 0;
-
-err_module_put:
- module_put(ops->owner);
-err_free_dev_param:
- dev_iommu_free(dev);
- return ret;
-}
-
-static void __iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
+ if (!dev->iommu)
+ return;
iommu_device_unlink(dev->iommu->iommu_dev, dev);
-
iommu_group_remove_device(dev);
ops->release_device(dev);
-}
-
-void iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
-
- if (!dev->iommu)
- return;
-
- if (ops->release_device)
- __iommu_release_device(dev);
- else if (dev->iommu_group)
- ops->remove_device(dev);
module_put(ops->owner);
dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (ret)
goto out_put_group;
- /*
- * Try to allocate a default domain - needs support from the
- * IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked. Only
- * allocate the domain here when the driver still has the
- * add_device/remove_device call-backs implemented.
- */
- if (!ops->probe_device) {
- iommu_alloc_default_domain(dev);
-
- if (group->default_domain)
- ret = __iommu_attach_device(group->default_domain, dev);
-
- if (ret)
- goto out_put_group;
- }
-
return group;
out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
return group->default_domain;
}
-static int add_iommu_group(struct device *dev, void *data)
-{
- int ret = iommu_probe_device(dev);
-
- /*
- * We ignore -ENODEV errors for now, as they just mean that the
- * device is not translated by an IOMMU. We still care about
- * other errors and fail to initialize when they happen.
- */
- if (ret == -ENODEV)
- ret = 0;
-
- return ret;
-}
-
static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -1793,47 +1717,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
int bus_iommu_probe(struct bus_type *bus)
{
- const struct iommu_ops *ops = bus->iommu_ops;
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
int ret;
- if (ops->probe_device) {
- struct iommu_group *group, *next;
- LIST_HEAD(group_list);
-
- /*
- * This code-path does not allocate the default domain when
- * creating the iommu group, so do it after the groups are
- * created.
- */
- ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
- if (ret)
- return ret;
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
- list_for_each_entry_safe(group, next, &group_list, entry) {
- /* Remove item from the list */
- list_del_init(&group->entry);
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
- mutex_lock(&group->mutex);
+ mutex_lock(&group->mutex);
- /* Try to allocate default domain */
- probe_alloc_default_domain(bus, group);
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
- if (!group->default_domain) {
- mutex_unlock(&group->mutex);
- continue;
- }
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
- iommu_group_create_direct_mappings(group);
+ iommu_group_create_direct_mappings(group);
- ret = __iommu_group_dma_attach(group);
+ ret = __iommu_group_dma_attach(group);
- mutex_unlock(&group->mutex);
+ mutex_unlock(&group->mutex);
- if (ret)
- break;
- }
- } else {
- ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ if (ret)
+ break;
}
return ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fea1622408ad..dd076366383f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather {
* @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
* queue
* @iova_to_phys: translate iova to physical address
- * @add_device: add device to iommu grouping
- * @remove_device: remove device from iommu grouping
* @probe_device: Add device to iommu driver handling
* @release_device: Remove device from iommu driver handling
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops {
void (*iotlb_sync)(struct iommu_domain *domain,
struct iommu_iotlb_gather *iotlb_gather);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
- int (*add_device)(struct device *dev);
- void (*remove_device)(struct device *dev);
struct iommu_device *(*probe_device)(struct device *dev);
void (*release_device)(struct device *dev);
void (*probe_finalize)(struct device *dev);
--
2.17.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 32/34] iommu: Remove add_device()/remove_device() code-paths
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: linux-s390, linux-samsung-soc, linux-arm-msm, linux-kernel,
Daniel Drake, linux-rockchip, iommu, Joerg Roedel,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
From: Joerg Roedel <jroedel@suse.de>
All drivers are converted to use the probe/release_device()
call-backs, so the add_device/remove_device() pointers are unused and
the code using them can be removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 158 ++++++++++--------------------------------
include/linux/iommu.h | 4 --
2 files changed, 38 insertions(+), 124 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 397fd4fd0c32..7f99e5ae432c 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -220,12 +220,20 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
return ret;
}
-static int __iommu_probe_device_helper(struct device *dev)
+int iommu_probe_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
int ret;
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_out;
+ }
+
ret = __iommu_probe_device(dev, NULL);
if (ret)
goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev)
err_release:
iommu_release_device(dev);
+
err_out:
return ret;
}
-int iommu_probe_device(struct device *dev)
+void iommu_release_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
- struct iommu_group *group;
- int ret;
-
- WARN_ON(dev->iommu_group);
-
- if (!ops)
- return -EINVAL;
-
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_free_dev_param;
- }
-
- if (ops->probe_device)
- return __iommu_probe_device_helper(dev);
-
- ret = ops->add_device(dev);
- if (ret)
- goto err_module_put;
- group = iommu_group_get(dev);
- iommu_create_device_direct_mappings(group, dev);
- iommu_group_put(group);
-
- if (ops->probe_finalize)
- ops->probe_finalize(dev);
-
- return 0;
-
-err_module_put:
- module_put(ops->owner);
-err_free_dev_param:
- dev_iommu_free(dev);
- return ret;
-}
-
-static void __iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
+ if (!dev->iommu)
+ return;
iommu_device_unlink(dev->iommu->iommu_dev, dev);
-
iommu_group_remove_device(dev);
ops->release_device(dev);
-}
-
-void iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
-
- if (!dev->iommu)
- return;
-
- if (ops->release_device)
- __iommu_release_device(dev);
- else if (dev->iommu_group)
- ops->remove_device(dev);
module_put(ops->owner);
dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (ret)
goto out_put_group;
- /*
- * Try to allocate a default domain - needs support from the
- * IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked. Only
- * allocate the domain here when the driver still has the
- * add_device/remove_device call-backs implemented.
- */
- if (!ops->probe_device) {
- iommu_alloc_default_domain(dev);
-
- if (group->default_domain)
- ret = __iommu_attach_device(group->default_domain, dev);
-
- if (ret)
- goto out_put_group;
- }
-
return group;
out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
return group->default_domain;
}
-static int add_iommu_group(struct device *dev, void *data)
-{
- int ret = iommu_probe_device(dev);
-
- /*
- * We ignore -ENODEV errors for now, as they just mean that the
- * device is not translated by an IOMMU. We still care about
- * other errors and fail to initialize when they happen.
- */
- if (ret == -ENODEV)
- ret = 0;
-
- return ret;
-}
-
static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -1793,47 +1717,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
int bus_iommu_probe(struct bus_type *bus)
{
- const struct iommu_ops *ops = bus->iommu_ops;
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
int ret;
- if (ops->probe_device) {
- struct iommu_group *group, *next;
- LIST_HEAD(group_list);
-
- /*
- * This code-path does not allocate the default domain when
- * creating the iommu group, so do it after the groups are
- * created.
- */
- ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
- if (ret)
- return ret;
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
- list_for_each_entry_safe(group, next, &group_list, entry) {
- /* Remove item from the list */
- list_del_init(&group->entry);
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
- mutex_lock(&group->mutex);
+ mutex_lock(&group->mutex);
- /* Try to allocate default domain */
- probe_alloc_default_domain(bus, group);
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
- if (!group->default_domain) {
- mutex_unlock(&group->mutex);
- continue;
- }
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
- iommu_group_create_direct_mappings(group);
+ iommu_group_create_direct_mappings(group);
- ret = __iommu_group_dma_attach(group);
+ ret = __iommu_group_dma_attach(group);
- mutex_unlock(&group->mutex);
+ mutex_unlock(&group->mutex);
- if (ret)
- break;
- }
- } else {
- ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ if (ret)
+ break;
}
return ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fea1622408ad..dd076366383f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather {
* @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
* queue
* @iova_to_phys: translate iova to physical address
- * @add_device: add device to iommu grouping
- * @remove_device: remove device from iommu grouping
* @probe_device: Add device to iommu driver handling
* @release_device: Remove device from iommu driver handling
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops {
void (*iotlb_sync)(struct iommu_domain *domain,
struct iommu_iotlb_gather *iotlb_gather);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
- int (*add_device)(struct device *dev);
- void (*remove_device)(struct device *dev);
struct iommu_device *(*probe_device)(struct device *dev);
void (*release_device)(struct device *dev);
void (*probe_finalize)(struct device *dev);
--
2.17.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 163+ messages in thread
* [PATCH v3 32/34] iommu: Remove add_device()/remove_device() code-paths
@ 2020-04-29 13:37 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-04-29 13:37 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski,
Kukjin Kim, Krzysztof Kozlowski, David Woodhouse, Lu Baolu,
Andy Gross, Bjorn Andersson, Matthias Brugger, Rob Clark,
Heiko Stuebner, Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker
Cc: Daniel Drake, jonathan.derrick, iommu, linux-kernel,
linux-samsung-soc, linux-arm-msm, linux-mediatek, linux-rockchip,
linux-s390, linux-tegra, virtualization, Joerg Roedel
From: Joerg Roedel <jroedel@suse.de>
All drivers are converted to use the probe/release_device()
call-backs, so the add_device/remove_device() pointers are unused and
the code using them can be removed.
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/iommu.c | 158 ++++++++++--------------------------------
include/linux/iommu.h | 4 --
2 files changed, 38 insertions(+), 124 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 397fd4fd0c32..7f99e5ae432c 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -220,12 +220,20 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
return ret;
}
-static int __iommu_probe_device_helper(struct device *dev)
+int iommu_probe_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
int ret;
+ if (!dev_iommu_get(dev))
+ return -ENOMEM;
+
+ if (!try_module_get(ops->owner)) {
+ ret = -EINVAL;
+ goto err_out;
+ }
+
ret = __iommu_probe_device(dev, NULL);
if (ret)
goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev)
err_release:
iommu_release_device(dev);
+
err_out:
return ret;
}
-int iommu_probe_device(struct device *dev)
+void iommu_release_device(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
- struct iommu_group *group;
- int ret;
-
- WARN_ON(dev->iommu_group);
-
- if (!ops)
- return -EINVAL;
-
- if (!dev_iommu_get(dev))
- return -ENOMEM;
-
- if (!try_module_get(ops->owner)) {
- ret = -EINVAL;
- goto err_free_dev_param;
- }
-
- if (ops->probe_device)
- return __iommu_probe_device_helper(dev);
-
- ret = ops->add_device(dev);
- if (ret)
- goto err_module_put;
- group = iommu_group_get(dev);
- iommu_create_device_direct_mappings(group, dev);
- iommu_group_put(group);
-
- if (ops->probe_finalize)
- ops->probe_finalize(dev);
-
- return 0;
-
-err_module_put:
- module_put(ops->owner);
-err_free_dev_param:
- dev_iommu_free(dev);
- return ret;
-}
-
-static void __iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
+ if (!dev->iommu)
+ return;
iommu_device_unlink(dev->iommu->iommu_dev, dev);
-
iommu_group_remove_device(dev);
ops->release_device(dev);
-}
-
-void iommu_release_device(struct device *dev)
-{
- const struct iommu_ops *ops = dev->bus->iommu_ops;
-
- if (!dev->iommu)
- return;
-
- if (ops->release_device)
- __iommu_release_device(dev);
- else if (dev->iommu_group)
- ops->remove_device(dev);
module_put(ops->owner);
dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
if (ret)
goto out_put_group;
- /*
- * Try to allocate a default domain - needs support from the
- * IOMMU driver. There are still some drivers which don't support
- * default domains, so the return value is not yet checked. Only
- * allocate the domain here when the driver still has the
- * add_device/remove_device call-backs implemented.
- */
- if (!ops->probe_device) {
- iommu_alloc_default_domain(dev);
-
- if (group->default_domain)
- ret = __iommu_attach_device(group->default_domain, dev);
-
- if (ret)
- goto out_put_group;
- }
-
return group;
out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
return group->default_domain;
}
-static int add_iommu_group(struct device *dev, void *data)
-{
- int ret = iommu_probe_device(dev);
-
- /*
- * We ignore -ENODEV errors for now, as they just mean that the
- * device is not translated by an IOMMU. We still care about
- * other errors and fail to initialize when they happen.
- */
- if (ret == -ENODEV)
- ret = 0;
-
- return ret;
-}
-
static int probe_iommu_group(struct device *dev, void *data)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -1793,47 +1717,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group)
int bus_iommu_probe(struct bus_type *bus)
{
- const struct iommu_ops *ops = bus->iommu_ops;
+ struct iommu_group *group, *next;
+ LIST_HEAD(group_list);
int ret;
- if (ops->probe_device) {
- struct iommu_group *group, *next;
- LIST_HEAD(group_list);
-
- /*
- * This code-path does not allocate the default domain when
- * creating the iommu group, so do it after the groups are
- * created.
- */
- ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
- if (ret)
- return ret;
+ /*
+ * This code-path does not allocate the default domain when
+ * creating the iommu group, so do it after the groups are
+ * created.
+ */
+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
+ if (ret)
+ return ret;
- list_for_each_entry_safe(group, next, &group_list, entry) {
- /* Remove item from the list */
- list_del_init(&group->entry);
+ list_for_each_entry_safe(group, next, &group_list, entry) {
+ /* Remove item from the list */
+ list_del_init(&group->entry);
- mutex_lock(&group->mutex);
+ mutex_lock(&group->mutex);
- /* Try to allocate default domain */
- probe_alloc_default_domain(bus, group);
+ /* Try to allocate default domain */
+ probe_alloc_default_domain(bus, group);
- if (!group->default_domain) {
- mutex_unlock(&group->mutex);
- continue;
- }
+ if (!group->default_domain) {
+ mutex_unlock(&group->mutex);
+ continue;
+ }
- iommu_group_create_direct_mappings(group);
+ iommu_group_create_direct_mappings(group);
- ret = __iommu_group_dma_attach(group);
+ ret = __iommu_group_dma_attach(group);
- mutex_unlock(&group->mutex);
+ mutex_unlock(&group->mutex);
- if (ret)
- break;
- }
- } else {
- ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
+ if (ret)
+ break;
}
return ret;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index fea1622408ad..dd076366383f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather {
* @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
* queue
* @iova_to_phys: translate iova to physical address
- * @add_device: add device to iommu grouping
- * @remove_device: remove device from iommu grouping
* @probe_device: Add device to iommu driver handling
* @release_device: Remove device from iommu driver handling
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops {
void (*iotlb_sync)(struct iommu_domain *domain,
struct iommu_iotlb_gather *iotlb_gather);
phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
- int (*add_device)(struct device *dev);
- void (*remove_device)(struct device *dev);
struct iommu_device *(*probe_device)(struct device *dev);
void (*release_device)(struct device *dev);
void (*probe_finalize)(struct device *dev);
--
2.17.1
^ permalink raw reply related [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
2020-04-29 13:36 ` Joerg Roedel
(?)
(?)
@ 2020-07-01 0:40 ` Qian Cai
-1 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-01 0:40 UTC (permalink / raw)
To: Joerg Roedel
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel
On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> Hi,
>
> here is the third version of this patch-set. Older versions can be found
> here:
>
> v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org/
> (Has some more introductory text)
>
> v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org/
>
> Changes v2 -> v3:
>
> * Rebased v5.7-rc3
>
> * Added a missing iommu_group_put() as reported by Lu Baolu.
>
> * Added a patch to consolidate more initialization work in
> __iommu_probe_device(), fixing a bug where no 'struct
> device_iommu' was allocated in the hotplug path.
>
> There is also a git-branch available with these patches applied:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
>
> Please review. If there are no objections I plan to put these patches
> into the IOMMU tree early next week.
Looks like this patchset introduced an use-after-free on arm-smmu-v3.
Reproduced using mlx5,
# echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
# echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
The .config,
https://github.com/cailca/linux-mm/blob/master/arm64.config
Looking at the free stack,
iommu_release_device->iommu_group_remove_device
was introduced in 07/34 ("iommu: Add probe_device() and release_device()
call-backs").
[ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
[ 9426.731347][ T3356] ==================================================================
[ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
__lock_acquire at kernel/locking/lockdep.c:4250
[ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
[ 9426.753601][ T3356]
[ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
[ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
[ 9426.774111][ T3356] Call trace:
[ 9426.777245][ T3356] dump_backtrace+0x0/0x398
[ 9426.781593][ T3356] show_stack+0x14/0x20
[ 9426.785596][ T3356] dump_stack+0x140/0x1b8
[ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
[ 9426.795855][ T3356] kasan_report+0x134/0x1b8
[ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
[ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
[ 9426.810373][ T3356] lock_acquire+0x204/0xf10
[ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
[ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
[ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
(inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
[ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
iommu_release_device at drivers/iommu/iommu.c:302
[ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
[ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
[ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9426.855929][ T3356] device_del+0x618/0xa00
[ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9426.876100][ T3356] sriov_disable+0x8c/0x348
[ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
[ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
[ 9426.896417][ T3356] dev_attr_store+0x38/0x68
[ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
[ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
[ 9426.909897][ T3356] __vfs_write+0x54/0xe8
[ 9426.913984][ T3356] vfs_write+0x124/0x3f0
[ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
[ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
[ 9426.926766][ T3356] do_el0_svc+0x124/0x220
[ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
[ 9426.935634][ T3356] el0_sync+0x140/0x180
[ 9426.939633][ T3356]
[ 9426.941810][ T3356] Allocated by task 3356:
[ 9426.945985][ T3356] save_stack+0x24/0x50
[ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
[ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
[ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
[ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
[ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
[ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
[ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
[ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
[ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
[ 9426.995017][ T3356] really_probe+0x124/0x6d8
[ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
[ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
[ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
[ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
[ 9427.018749][ T3356] device_attach+0x10/0x18
[ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
[ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
[ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
[ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
[ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
[ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
[ 9427.052784][ T3356] dev_attr_store+0x38/0x68
[ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.066260][ T3356] __vfs_write+0x54/0xe8
[ 9427.070346][ T3356] vfs_write+0x124/0x3f0
[ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
[ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.083127][ T3356] do_el0_svc+0x124/0x220
[ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
[ 9427.091994][ T3356] el0_sync+0x140/0x180
[ 9427.095992][ T3356]
[ 9427.098168][ T3356] Freed by task 3356:
[ 9427.101995][ T3356] save_stack+0x24/0x50
[ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
[ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
[ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
[ 9427.120512][ T3356] kfree+0x128/0x668
[ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
[ 9427.129206][ T3356] iommu_group_release+0xec/0x160
[ 9427.134074][ T3356] kobject_put+0xf4/0x238
[ 9427.138247][ T3356] kobject_del+0x110/0x190
[ 9427.142507][ T3356] kobject_put+0x1e4/0x238
[ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
[ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
iommu_release_device at drivers/iommu/iommu.c:300
[ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
[ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
[ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9427.178233][ T3356] device_del+0x618/0xa00
[ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9427.198399][ T3356] sriov_disable+0x8c/0x348
[ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
[ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
[ 9427.218698][ T3356] dev_attr_store+0x38/0x68
[ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.232173][ T3356] __vfs_write+0x54/0xe8
[ 9427.236259][ T3356] vfs_write+0x124/0x3f0
[ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
[ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.249041][ T3356] do_el0_svc+0x124/0x220
[ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
[ 9427.257908][ T3356] el0_sync+0x140/0x180
[ 9427.261907][ T3356]
[ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
[ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
[ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
[ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
[ 9427.291094][ T3356] The buggy address belongs to the page:
[ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
[ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
[ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
[ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
[ 9427.328374][ T3356] page dumped because: kasan: bad access detected
[ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
[ 9427.339670][ T3356]
[ 9427.341846][ T3356] Memory state around the buggy address:
[ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.371038][ T3356] ^
[ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 9427.394146][ T3356] ==================================================================
[ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> Thanks,
>
> Joerg
>
> Joerg Roedel (33):
> iommu: Move default domain allocation to separate function
> iommu/amd: Implement iommu_ops->def_domain_type call-back
> iommu/vt-d: Wire up iommu_ops->def_domain_type
> iommu/amd: Remove dma_mask check from check_device()
> iommu/amd: Return -ENODEV in add_device when device is not handled by
> IOMMU
> iommu: Add probe_device() and release_device() call-backs
> iommu: Move default domain allocation to iommu_probe_device()
> iommu: Keep a list of allocated groups in __iommu_probe_device()
> iommu: Move new probe_device path to separate function
> iommu: Split off default domain allocation from group assignment
> iommu: Move iommu_group_create_direct_mappings() out of
> iommu_group_add_device()
> iommu: Export bus_iommu_probe() and make is safe for re-probing
> iommu/amd: Remove dev_data->passthrough
> iommu/amd: Convert to probe/release_device() call-backs
> iommu/vt-d: Convert to probe/release_device() call-backs
> iommu/arm-smmu: Convert to probe/release_device() call-backs
> iommu/pamu: Convert to probe/release_device() call-backs
> iommu/s390: Convert to probe/release_device() call-backs
> iommu/virtio: Convert to probe/release_device() call-backs
> iommu/msm: Convert to probe/release_device() call-backs
> iommu/mediatek: Convert to probe/release_device() call-backs
> iommu/mediatek-v1 Convert to probe/release_device() call-backs
> iommu/qcom: Convert to probe/release_device() call-backs
> iommu/rockchip: Convert to probe/release_device() call-backs
> iommu/tegra: Convert to probe/release_device() call-backs
> iommu/renesas: Convert to probe/release_device() call-backs
> iommu/omap: Remove orphan_dev tracking
> iommu/omap: Convert to probe/release_device() call-backs
> iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> iommu/exynos: Convert to probe/release_device() call-backs
> iommu: Remove add_device()/remove_device() code-paths
> iommu: Move more initialization to __iommu_probe_device()
> iommu: Unexport iommu_group_get_for_dev()
>
> Sai Praneeth Prakhya (1):
> iommu: Add def_domain_type() callback in iommu_ops
>
> drivers/iommu/amd_iommu.c | 97 ++++----
> drivers/iommu/amd_iommu_types.h | 1 -
> drivers/iommu/arm-smmu-v3.c | 38 +---
> drivers/iommu/arm-smmu.c | 39 ++--
> drivers/iommu/exynos-iommu.c | 24 +-
> drivers/iommu/fsl_pamu_domain.c | 22 +-
> drivers/iommu/intel-iommu.c | 68 +-----
> drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> drivers/iommu/ipmmu-vmsa.c | 60 ++---
> drivers/iommu/msm_iommu.c | 34 +--
> drivers/iommu/mtk_iommu.c | 24 +-
> drivers/iommu/mtk_iommu_v1.c | 50 ++---
> drivers/iommu/omap-iommu.c | 99 ++------
> drivers/iommu/qcom_iommu.c | 24 +-
> drivers/iommu/rockchip-iommu.c | 26 +--
> drivers/iommu/s390-iommu.c | 22 +-
> drivers/iommu/tegra-gart.c | 24 +-
> drivers/iommu/tegra-smmu.c | 31 +--
> drivers/iommu/virtio-iommu.c | 41 +---
> include/linux/iommu.h | 21 +-
> 20 files changed, 531 insertions(+), 601 deletions(-)
>
> --
> 2.17.1
>
> _______________________________________________
> iommu mailing list
> iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 0:40 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-01 0:40 UTC (permalink / raw)
To: Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Marek Szyprowski,
Jean-Philippe Brucker, linux-samsung-soc, iommu,
Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip, Andy Gross,
jonathan.derrick, linux-s390, linux-arm-msm, linux-mediatek,
Matthias Brugger, virtualization, Gerald Schaefer,
David Woodhouse, linux-kernel, Rob Clark, Kukjin Kim,
Robin Murphy, Lu Baolu
On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> Hi,
>
> here is the third version of this patch-set. Older versions can be found
> here:
>
> v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> (Has some more introductory text)
>
> v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
>
> Changes v2 -> v3:
>
> * Rebased v5.7-rc3
>
> * Added a missing iommu_group_put() as reported by Lu Baolu.
>
> * Added a patch to consolidate more initialization work in
> __iommu_probe_device(), fixing a bug where no 'struct
> device_iommu' was allocated in the hotplug path.
>
> There is also a git-branch available with these patches applied:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
>
> Please review. If there are no objections I plan to put these patches
> into the IOMMU tree early next week.
Looks like this patchset introduced an use-after-free on arm-smmu-v3.
Reproduced using mlx5,
# echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
# echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
The .config,
https://github.com/cailca/linux-mm/blob/master/arm64.config
Looking at the free stack,
iommu_release_device->iommu_group_remove_device
was introduced in 07/34 ("iommu: Add probe_device() and release_device()
call-backs").
[ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
[ 9426.731347][ T3356] ==================================================================
[ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
__lock_acquire at kernel/locking/lockdep.c:4250
[ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
[ 9426.753601][ T3356]
[ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
[ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
[ 9426.774111][ T3356] Call trace:
[ 9426.777245][ T3356] dump_backtrace+0x0/0x398
[ 9426.781593][ T3356] show_stack+0x14/0x20
[ 9426.785596][ T3356] dump_stack+0x140/0x1b8
[ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
[ 9426.795855][ T3356] kasan_report+0x134/0x1b8
[ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
[ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
[ 9426.810373][ T3356] lock_acquire+0x204/0xf10
[ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
[ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
[ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
(inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
[ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
iommu_release_device at drivers/iommu/iommu.c:302
[ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
[ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
[ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9426.855929][ T3356] device_del+0x618/0xa00
[ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9426.876100][ T3356] sriov_disable+0x8c/0x348
[ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
[ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
[ 9426.896417][ T3356] dev_attr_store+0x38/0x68
[ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
[ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
[ 9426.909897][ T3356] __vfs_write+0x54/0xe8
[ 9426.913984][ T3356] vfs_write+0x124/0x3f0
[ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
[ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
[ 9426.926766][ T3356] do_el0_svc+0x124/0x220
[ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
[ 9426.935634][ T3356] el0_sync+0x140/0x180
[ 9426.939633][ T3356]
[ 9426.941810][ T3356] Allocated by task 3356:
[ 9426.945985][ T3356] save_stack+0x24/0x50
[ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
[ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
[ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
[ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
[ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
[ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
[ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
[ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
[ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
[ 9426.995017][ T3356] really_probe+0x124/0x6d8
[ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
[ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
[ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
[ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
[ 9427.018749][ T3356] device_attach+0x10/0x18
[ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
[ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
[ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
[ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
[ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
[ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
[ 9427.052784][ T3356] dev_attr_store+0x38/0x68
[ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.066260][ T3356] __vfs_write+0x54/0xe8
[ 9427.070346][ T3356] vfs_write+0x124/0x3f0
[ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
[ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.083127][ T3356] do_el0_svc+0x124/0x220
[ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
[ 9427.091994][ T3356] el0_sync+0x140/0x180
[ 9427.095992][ T3356]
[ 9427.098168][ T3356] Freed by task 3356:
[ 9427.101995][ T3356] save_stack+0x24/0x50
[ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
[ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
[ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
[ 9427.120512][ T3356] kfree+0x128/0x668
[ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
[ 9427.129206][ T3356] iommu_group_release+0xec/0x160
[ 9427.134074][ T3356] kobject_put+0xf4/0x238
[ 9427.138247][ T3356] kobject_del+0x110/0x190
[ 9427.142507][ T3356] kobject_put+0x1e4/0x238
[ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
[ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
iommu_release_device at drivers/iommu/iommu.c:300
[ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
[ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
[ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9427.178233][ T3356] device_del+0x618/0xa00
[ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9427.198399][ T3356] sriov_disable+0x8c/0x348
[ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
[ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
[ 9427.218698][ T3356] dev_attr_store+0x38/0x68
[ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.232173][ T3356] __vfs_write+0x54/0xe8
[ 9427.236259][ T3356] vfs_write+0x124/0x3f0
[ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
[ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.249041][ T3356] do_el0_svc+0x124/0x220
[ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
[ 9427.257908][ T3356] el0_sync+0x140/0x180
[ 9427.261907][ T3356]
[ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
[ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
[ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
[ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
[ 9427.291094][ T3356] The buggy address belongs to the page:
[ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
[ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
[ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
[ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
[ 9427.328374][ T3356] page dumped because: kasan: bad access detected
[ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
[ 9427.339670][ T3356]
[ 9427.341846][ T3356] Memory state around the buggy address:
[ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.371038][ T3356] ^
[ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 9427.394146][ T3356] ==================================================================
[ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> Thanks,
>
> Joerg
>
> Joerg Roedel (33):
> iommu: Move default domain allocation to separate function
> iommu/amd: Implement iommu_ops->def_domain_type call-back
> iommu/vt-d: Wire up iommu_ops->def_domain_type
> iommu/amd: Remove dma_mask check from check_device()
> iommu/amd: Return -ENODEV in add_device when device is not handled by
> IOMMU
> iommu: Add probe_device() and release_device() call-backs
> iommu: Move default domain allocation to iommu_probe_device()
> iommu: Keep a list of allocated groups in __iommu_probe_device()
> iommu: Move new probe_device path to separate function
> iommu: Split off default domain allocation from group assignment
> iommu: Move iommu_group_create_direct_mappings() out of
> iommu_group_add_device()
> iommu: Export bus_iommu_probe() and make is safe for re-probing
> iommu/amd: Remove dev_data->passthrough
> iommu/amd: Convert to probe/release_device() call-backs
> iommu/vt-d: Convert to probe/release_device() call-backs
> iommu/arm-smmu: Convert to probe/release_device() call-backs
> iommu/pamu: Convert to probe/release_device() call-backs
> iommu/s390: Convert to probe/release_device() call-backs
> iommu/virtio: Convert to probe/release_device() call-backs
> iommu/msm: Convert to probe/release_device() call-backs
> iommu/mediatek: Convert to probe/release_device() call-backs
> iommu/mediatek-v1 Convert to probe/release_device() call-backs
> iommu/qcom: Convert to probe/release_device() call-backs
> iommu/rockchip: Convert to probe/release_device() call-backs
> iommu/tegra: Convert to probe/release_device() call-backs
> iommu/renesas: Convert to probe/release_device() call-backs
> iommu/omap: Remove orphan_dev tracking
> iommu/omap: Convert to probe/release_device() call-backs
> iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> iommu/exynos: Convert to probe/release_device() call-backs
> iommu: Remove add_device()/remove_device() code-paths
> iommu: Move more initialization to __iommu_probe_device()
> iommu: Unexport iommu_group_get_for_dev()
>
> Sai Praneeth Prakhya (1):
> iommu: Add def_domain_type() callback in iommu_ops
>
> drivers/iommu/amd_iommu.c | 97 ++++----
> drivers/iommu/amd_iommu_types.h | 1 -
> drivers/iommu/arm-smmu-v3.c | 38 +---
> drivers/iommu/arm-smmu.c | 39 ++--
> drivers/iommu/exynos-iommu.c | 24 +-
> drivers/iommu/fsl_pamu_domain.c | 22 +-
> drivers/iommu/intel-iommu.c | 68 +-----
> drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> drivers/iommu/ipmmu-vmsa.c | 60 ++---
> drivers/iommu/msm_iommu.c | 34 +--
> drivers/iommu/mtk_iommu.c | 24 +-
> drivers/iommu/mtk_iommu_v1.c | 50 ++---
> drivers/iommu/omap-iommu.c | 99 ++------
> drivers/iommu/qcom_iommu.c | 24 +-
> drivers/iommu/rockchip-iommu.c | 26 +--
> drivers/iommu/s390-iommu.c | 22 +-
> drivers/iommu/tegra-gart.c | 24 +-
> drivers/iommu/tegra-smmu.c | 31 +--
> drivers/iommu/virtio-iommu.c | 41 +---
> include/linux/iommu.h | 21 +-
> 20 files changed, 531 insertions(+), 601 deletions(-)
>
> --
> 2.17.1
>
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 0:40 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-01 0:40 UTC (permalink / raw)
To: Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc, iommu, Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip, Andy Gross, jonathan.derrick, linux-s390,
linux-arm-msm, linux-mediatek, Matthias Brugger, virtualization,
Gerald Schaefer, David Woodhouse, linux-kernel, Kukjin Kim,
Robin Murphy
On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> Hi,
>
> here is the third version of this patch-set. Older versions can be found
> here:
>
> v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> (Has some more introductory text)
>
> v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
>
> Changes v2 -> v3:
>
> * Rebased v5.7-rc3
>
> * Added a missing iommu_group_put() as reported by Lu Baolu.
>
> * Added a patch to consolidate more initialization work in
> __iommu_probe_device(), fixing a bug where no 'struct
> device_iommu' was allocated in the hotplug path.
>
> There is also a git-branch available with these patches applied:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
>
> Please review. If there are no objections I plan to put these patches
> into the IOMMU tree early next week.
Looks like this patchset introduced an use-after-free on arm-smmu-v3.
Reproduced using mlx5,
# echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
# echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
The .config,
https://github.com/cailca/linux-mm/blob/master/arm64.config
Looking at the free stack,
iommu_release_device->iommu_group_remove_device
was introduced in 07/34 ("iommu: Add probe_device() and release_device()
call-backs").
[ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
[ 9426.731347][ T3356] ==================================================================
[ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
__lock_acquire at kernel/locking/lockdep.c:4250
[ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
[ 9426.753601][ T3356]
[ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
[ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
[ 9426.774111][ T3356] Call trace:
[ 9426.777245][ T3356] dump_backtrace+0x0/0x398
[ 9426.781593][ T3356] show_stack+0x14/0x20
[ 9426.785596][ T3356] dump_stack+0x140/0x1b8
[ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
[ 9426.795855][ T3356] kasan_report+0x134/0x1b8
[ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
[ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
[ 9426.810373][ T3356] lock_acquire+0x204/0xf10
[ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
[ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
[ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
(inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
[ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
iommu_release_device at drivers/iommu/iommu.c:302
[ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
[ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
[ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9426.855929][ T3356] device_del+0x618/0xa00
[ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9426.876100][ T3356] sriov_disable+0x8c/0x348
[ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
[ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
[ 9426.896417][ T3356] dev_attr_store+0x38/0x68
[ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
[ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
[ 9426.909897][ T3356] __vfs_write+0x54/0xe8
[ 9426.913984][ T3356] vfs_write+0x124/0x3f0
[ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
[ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
[ 9426.926766][ T3356] do_el0_svc+0x124/0x220
[ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
[ 9426.935634][ T3356] el0_sync+0x140/0x180
[ 9426.939633][ T3356]
[ 9426.941810][ T3356] Allocated by task 3356:
[ 9426.945985][ T3356] save_stack+0x24/0x50
[ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
[ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
[ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
[ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
[ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
[ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
[ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
[ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
[ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
[ 9426.995017][ T3356] really_probe+0x124/0x6d8
[ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
[ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
[ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
[ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
[ 9427.018749][ T3356] device_attach+0x10/0x18
[ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
[ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
[ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
[ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
[ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
[ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
[ 9427.052784][ T3356] dev_attr_store+0x38/0x68
[ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.066260][ T3356] __vfs_write+0x54/0xe8
[ 9427.070346][ T3356] vfs_write+0x124/0x3f0
[ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
[ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.083127][ T3356] do_el0_svc+0x124/0x220
[ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
[ 9427.091994][ T3356] el0_sync+0x140/0x180
[ 9427.095992][ T3356]
[ 9427.098168][ T3356] Freed by task 3356:
[ 9427.101995][ T3356] save_stack+0x24/0x50
[ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
[ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
[ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
[ 9427.120512][ T3356] kfree+0x128/0x668
[ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
[ 9427.129206][ T3356] iommu_group_release+0xec/0x160
[ 9427.134074][ T3356] kobject_put+0xf4/0x238
[ 9427.138247][ T3356] kobject_del+0x110/0x190
[ 9427.142507][ T3356] kobject_put+0x1e4/0x238
[ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
[ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
iommu_release_device at drivers/iommu/iommu.c:300
[ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
[ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
[ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9427.178233][ T3356] device_del+0x618/0xa00
[ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9427.198399][ T3356] sriov_disable+0x8c/0x348
[ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
[ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
[ 9427.218698][ T3356] dev_attr_store+0x38/0x68
[ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.232173][ T3356] __vfs_write+0x54/0xe8
[ 9427.236259][ T3356] vfs_write+0x124/0x3f0
[ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
[ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.249041][ T3356] do_el0_svc+0x124/0x220
[ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
[ 9427.257908][ T3356] el0_sync+0x140/0x180
[ 9427.261907][ T3356]
[ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
[ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
[ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
[ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
[ 9427.291094][ T3356] The buggy address belongs to the page:
[ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
[ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
[ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
[ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
[ 9427.328374][ T3356] page dumped because: kasan: bad access detected
[ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
[ 9427.339670][ T3356]
[ 9427.341846][ T3356] Memory state around the buggy address:
[ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.371038][ T3356] ^
[ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 9427.394146][ T3356] ==================================================================
[ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> Thanks,
>
> Joerg
>
> Joerg Roedel (33):
> iommu: Move default domain allocation to separate function
> iommu/amd: Implement iommu_ops->def_domain_type call-back
> iommu/vt-d: Wire up iommu_ops->def_domain_type
> iommu/amd: Remove dma_mask check from check_device()
> iommu/amd: Return -ENODEV in add_device when device is not handled by
> IOMMU
> iommu: Add probe_device() and release_device() call-backs
> iommu: Move default domain allocation to iommu_probe_device()
> iommu: Keep a list of allocated groups in __iommu_probe_device()
> iommu: Move new probe_device path to separate function
> iommu: Split off default domain allocation from group assignment
> iommu: Move iommu_group_create_direct_mappings() out of
> iommu_group_add_device()
> iommu: Export bus_iommu_probe() and make is safe for re-probing
> iommu/amd: Remove dev_data->passthrough
> iommu/amd: Convert to probe/release_device() call-backs
> iommu/vt-d: Convert to probe/release_device() call-backs
> iommu/arm-smmu: Convert to probe/release_device() call-backs
> iommu/pamu: Convert to probe/release_device() call-backs
> iommu/s390: Convert to probe/release_device() call-backs
> iommu/virtio: Convert to probe/release_device() call-backs
> iommu/msm: Convert to probe/release_device() call-backs
> iommu/mediatek: Convert to probe/release_device() call-backs
> iommu/mediatek-v1 Convert to probe/release_device() call-backs
> iommu/qcom: Convert to probe/release_device() call-backs
> iommu/rockchip: Convert to probe/release_device() call-backs
> iommu/tegra: Convert to probe/release_device() call-backs
> iommu/renesas: Convert to probe/release_device() call-backs
> iommu/omap: Remove orphan_dev tracking
> iommu/omap: Convert to probe/release_device() call-backs
> iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> iommu/exynos: Convert to probe/release_device() call-backs
> iommu: Remove add_device()/remove_device() code-paths
> iommu: Move more initialization to __iommu_probe_device()
> iommu: Unexport iommu_group_get_for_dev()
>
> Sai Praneeth Prakhya (1):
> iommu: Add def_domain_type() callback in iommu_ops
>
> drivers/iommu/amd_iommu.c | 97 ++++----
> drivers/iommu/amd_iommu_types.h | 1 -
> drivers/iommu/arm-smmu-v3.c | 38 +---
> drivers/iommu/arm-smmu.c | 39 ++--
> drivers/iommu/exynos-iommu.c | 24 +-
> drivers/iommu/fsl_pamu_domain.c | 22 +-
> drivers/iommu/intel-iommu.c | 68 +-----
> drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> drivers/iommu/ipmmu-vmsa.c | 60 ++---
> drivers/iommu/msm_iommu.c | 34 +--
> drivers/iommu/mtk_iommu.c | 24 +-
> drivers/iommu/mtk_iommu_v1.c | 50 ++---
> drivers/iommu/omap-iommu.c | 99 ++------
> drivers/iommu/qcom_iommu.c | 24 +-
> drivers/iommu/rockchip-iommu.c | 26 +--
> drivers/iommu/s390-iommu.c | 22 +-
> drivers/iommu/tegra-gart.c | 24 +-
> drivers/iommu/tegra-smmu.c | 31 +--
> drivers/iommu/virtio-iommu.c | 41 +---
> include/linux/iommu.h | 21 +-
> 20 files changed, 531 insertions(+), 601 deletions(-)
>
> --
> 2.17.1
>
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 0:40 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-01 0:40 UTC (permalink / raw)
To: Joerg Roedel
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390, linux-samsung-soc,
linux-arm-msm, linux-kernel, Daniel Drake, linux-rockchip, iommu,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> Hi,
>
> here is the third version of this patch-set. Older versions can be found
> here:
>
> v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> (Has some more introductory text)
>
> v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
>
> Changes v2 -> v3:
>
> * Rebased v5.7-rc3
>
> * Added a missing iommu_group_put() as reported by Lu Baolu.
>
> * Added a patch to consolidate more initialization work in
> __iommu_probe_device(), fixing a bug where no 'struct
> device_iommu' was allocated in the hotplug path.
>
> There is also a git-branch available with these patches applied:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
>
> Please review. If there are no objections I plan to put these patches
> into the IOMMU tree early next week.
Looks like this patchset introduced an use-after-free on arm-smmu-v3.
Reproduced using mlx5,
# echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
# echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
The .config,
https://github.com/cailca/linux-mm/blob/master/arm64.config
Looking at the free stack,
iommu_release_device->iommu_group_remove_device
was introduced in 07/34 ("iommu: Add probe_device() and release_device()
call-backs").
[ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
[ 9426.731347][ T3356] ==================================================================
[ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
__lock_acquire at kernel/locking/lockdep.c:4250
[ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
[ 9426.753601][ T3356]
[ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
[ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
[ 9426.774111][ T3356] Call trace:
[ 9426.777245][ T3356] dump_backtrace+0x0/0x398
[ 9426.781593][ T3356] show_stack+0x14/0x20
[ 9426.785596][ T3356] dump_stack+0x140/0x1b8
[ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
[ 9426.795855][ T3356] kasan_report+0x134/0x1b8
[ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
[ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
[ 9426.810373][ T3356] lock_acquire+0x204/0xf10
[ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
[ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
[ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
(inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
[ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
iommu_release_device at drivers/iommu/iommu.c:302
[ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
[ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
[ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9426.855929][ T3356] device_del+0x618/0xa00
[ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9426.876100][ T3356] sriov_disable+0x8c/0x348
[ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
[ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
[ 9426.896417][ T3356] dev_attr_store+0x38/0x68
[ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
[ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
[ 9426.909897][ T3356] __vfs_write+0x54/0xe8
[ 9426.913984][ T3356] vfs_write+0x124/0x3f0
[ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
[ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
[ 9426.926766][ T3356] do_el0_svc+0x124/0x220
[ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
[ 9426.935634][ T3356] el0_sync+0x140/0x180
[ 9426.939633][ T3356]
[ 9426.941810][ T3356] Allocated by task 3356:
[ 9426.945985][ T3356] save_stack+0x24/0x50
[ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
[ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
[ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
[ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
[ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
[ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
[ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
[ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
[ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
[ 9426.995017][ T3356] really_probe+0x124/0x6d8
[ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
[ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
[ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
[ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
[ 9427.018749][ T3356] device_attach+0x10/0x18
[ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
[ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
[ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
[ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
[ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
[ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
[ 9427.052784][ T3356] dev_attr_store+0x38/0x68
[ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.066260][ T3356] __vfs_write+0x54/0xe8
[ 9427.070346][ T3356] vfs_write+0x124/0x3f0
[ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
[ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.083127][ T3356] do_el0_svc+0x124/0x220
[ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
[ 9427.091994][ T3356] el0_sync+0x140/0x180
[ 9427.095992][ T3356]
[ 9427.098168][ T3356] Freed by task 3356:
[ 9427.101995][ T3356] save_stack+0x24/0x50
[ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
[ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
[ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
[ 9427.120512][ T3356] kfree+0x128/0x668
[ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
[ 9427.129206][ T3356] iommu_group_release+0xec/0x160
[ 9427.134074][ T3356] kobject_put+0xf4/0x238
[ 9427.138247][ T3356] kobject_del+0x110/0x190
[ 9427.142507][ T3356] kobject_put+0x1e4/0x238
[ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
[ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
iommu_release_device at drivers/iommu/iommu.c:300
[ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
[ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
[ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
[ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
[ 9427.178233][ T3356] device_del+0x618/0xa00
[ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
[ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
[ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
[ 9427.198399][ T3356] sriov_disable+0x8c/0x348
[ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
[ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
[ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
[ 9427.218698][ T3356] dev_attr_store+0x38/0x68
[ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
[ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
[ 9427.232173][ T3356] __vfs_write+0x54/0xe8
[ 9427.236259][ T3356] vfs_write+0x124/0x3f0
[ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
[ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
[ 9427.249041][ T3356] do_el0_svc+0x124/0x220
[ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
[ 9427.257908][ T3356] el0_sync+0x140/0x180
[ 9427.261907][ T3356]
[ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
[ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
[ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
[ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
[ 9427.291094][ T3356] The buggy address belongs to the page:
[ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
[ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
[ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
[ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
[ 9427.328374][ T3356] page dumped because: kasan: bad access detected
[ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
[ 9427.339670][ T3356]
[ 9427.341846][ T3356] Memory state around the buggy address:
[ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.371038][ T3356] ^
[ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[ 9427.394146][ T3356] ==================================================================
[ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> Thanks,
>
> Joerg
>
> Joerg Roedel (33):
> iommu: Move default domain allocation to separate function
> iommu/amd: Implement iommu_ops->def_domain_type call-back
> iommu/vt-d: Wire up iommu_ops->def_domain_type
> iommu/amd: Remove dma_mask check from check_device()
> iommu/amd: Return -ENODEV in add_device when device is not handled by
> IOMMU
> iommu: Add probe_device() and release_device() call-backs
> iommu: Move default domain allocation to iommu_probe_device()
> iommu: Keep a list of allocated groups in __iommu_probe_device()
> iommu: Move new probe_device path to separate function
> iommu: Split off default domain allocation from group assignment
> iommu: Move iommu_group_create_direct_mappings() out of
> iommu_group_add_device()
> iommu: Export bus_iommu_probe() and make is safe for re-probing
> iommu/amd: Remove dev_data->passthrough
> iommu/amd: Convert to probe/release_device() call-backs
> iommu/vt-d: Convert to probe/release_device() call-backs
> iommu/arm-smmu: Convert to probe/release_device() call-backs
> iommu/pamu: Convert to probe/release_device() call-backs
> iommu/s390: Convert to probe/release_device() call-backs
> iommu/virtio: Convert to probe/release_device() call-backs
> iommu/msm: Convert to probe/release_device() call-backs
> iommu/mediatek: Convert to probe/release_device() call-backs
> iommu/mediatek-v1 Convert to probe/release_device() call-backs
> iommu/qcom: Convert to probe/release_device() call-backs
> iommu/rockchip: Convert to probe/release_device() call-backs
> iommu/tegra: Convert to probe/release_device() call-backs
> iommu/renesas: Convert to probe/release_device() call-backs
> iommu/omap: Remove orphan_dev tracking
> iommu/omap: Convert to probe/release_device() call-backs
> iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> iommu/exynos: Convert to probe/release_device() call-backs
> iommu: Remove add_device()/remove_device() code-paths
> iommu: Move more initialization to __iommu_probe_device()
> iommu: Unexport iommu_group_get_for_dev()
>
> Sai Praneeth Prakhya (1):
> iommu: Add def_domain_type() callback in iommu_ops
>
> drivers/iommu/amd_iommu.c | 97 ++++----
> drivers/iommu/amd_iommu_types.h | 1 -
> drivers/iommu/arm-smmu-v3.c | 38 +---
> drivers/iommu/arm-smmu.c | 39 ++--
> drivers/iommu/exynos-iommu.c | 24 +-
> drivers/iommu/fsl_pamu_domain.c | 22 +-
> drivers/iommu/intel-iommu.c | 68 +-----
> drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> drivers/iommu/ipmmu-vmsa.c | 60 ++---
> drivers/iommu/msm_iommu.c | 34 +--
> drivers/iommu/mtk_iommu.c | 24 +-
> drivers/iommu/mtk_iommu_v1.c | 50 ++---
> drivers/iommu/omap-iommu.c | 99 ++------
> drivers/iommu/qcom_iommu.c | 24 +-
> drivers/iommu/rockchip-iommu.c | 26 +--
> drivers/iommu/s390-iommu.c | 22 +-
> drivers/iommu/tegra-gart.c | 24 +-
> drivers/iommu/tegra-smmu.c | 31 +--
> drivers/iommu/virtio-iommu.c | 41 +---
> include/linux/iommu.h | 21 +-
> 20 files changed, 531 insertions(+), 601 deletions(-)
>
> --
> 2.17.1
>
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
[parent not found: <20200701004020.GA6221-J5quhbR+WMc@public.gmane.org>]
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
2020-07-01 0:40 ` Qian Cai
(?)
(?)
@ 2020-07-01 10:53 ` Robin Murphy
-1 siblings, 0 replies; 163+ messages in thread
From: Robin Murphy @ 2020-07-01 10:53 UTC (permalink / raw)
To: Qian Cai, Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson,
linux-tegra-u79uwXL29TY76Z2rM5mHXA, Thierry Reding, Daniel Drake,
Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Andy Gross,
jonathan.derrick-ral2JQCrhuEAvxtiuMwx3w,
linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
Matthias Brugger,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
Gerald Schaefer, David Woodhouse
On 2020-07-01 01:40, Qian Cai wrote:
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
Right, iommu_group_remove_device can tear down the group and call
->domain_free before the driver has any knowledge of the last device
going away via the ->release_device call.
I guess the question is do we simply flip the call order in
iommu_release_device() so drivers can easily clean up their internal
per-device state first, or do we now want them to be robust against
freeing domains with devices still nominally attached?
Robin.
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 10:53 ` Robin Murphy
0 siblings, 0 replies; 163+ messages in thread
From: Robin Murphy @ 2020-07-01 10:53 UTC (permalink / raw)
To: Qian Cai, Joerg Roedel
Cc: Heiko Stuebner, virtualization, Matthias Brugger, Thierry Reding,
Daniel Drake, Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc, Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip, Andy Gross, jonathan.derrick, linux-s390,
linux-arm-msm, linux-mediatek, linux-tegra, Bjorn Andersson,
Gerald Schaefer, linux-kernel, iommu, Kukjin Kim,
David Woodhouse
On 2020-07-01 01:40, Qian Cai wrote:
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
Right, iommu_group_remove_device can tear down the group and call
->domain_free before the driver has any knowledge of the last device
going away via the ->release_device call.
I guess the question is do we simply flip the call order in
iommu_release_device() so drivers can easily clean up their internal
per-device state first, or do we now want them to be robust against
freeing domains with devices still nominally attached?
Robin.
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 10:53 ` Robin Murphy
0 siblings, 0 replies; 163+ messages in thread
From: Robin Murphy @ 2020-07-01 10:53 UTC (permalink / raw)
To: Qian Cai, Joerg Roedel
Cc: Heiko Stuebner, virtualization, Matthias Brugger, Thierry Reding,
Daniel Drake, Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc, Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip, Andy Gross, jonathan.derrick, linux-s390,
linux-arm-msm, linux-mediatek, linux-tegra, Bjorn Andersson,
Gerald Schaefer, linux-kernel, iommu, Kukjin Kim,
David Woodhouse
On 2020-07-01 01:40, Qian Cai wrote:
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
Right, iommu_group_remove_device can tear down the group and call
->domain_free before the driver has any knowledge of the last device
going away via the ->release_device call.
I guess the question is do we simply flip the call order in
iommu_release_device() so drivers can easily clean up their internal
per-device state first, or do we now want them to be robust against
freeing domains with devices still nominally attached?
Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-01 10:53 ` Robin Murphy
0 siblings, 0 replies; 163+ messages in thread
From: Robin Murphy @ 2020-07-01 10:53 UTC (permalink / raw)
To: Qian Cai, Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc, iommu, Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip, Andy Gross, jonathan.derrick, linux-s390,
linux-arm-msm, linux-mediatek, Matthias Brugger, virtualization,
Gerald Schaefer, David Woodhouse, linux-kernel, Kukjin Kim
On 2020-07-01 01:40, Qian Cai wrote:
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
Right, iommu_group_remove_device can tear down the group and call
->domain_free before the driver has any knowledge of the last device
going away via the ->release_device call.
I guess the question is do we simply flip the call order in
iommu_release_device() so drivers can easily clean up their internal
per-device state first, or do we now want them to be robust against
freeing domains with devices still nominally attached?
Robin.
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
2020-07-01 0:40 ` Qian Cai
(?)
(?)
@ 2020-07-04 0:17 ` Qian Cai
-1 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-04 0:17 UTC (permalink / raw)
To: Joerg Roedel
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel
On Tue, Jun 30, 2020 at 08:40:28PM -0400, Qian Cai wrote:
> On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> > Hi,
> >
> > here is the third version of this patch-set. Older versions can be found
> > here:
> >
> > v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org/
> > (Has some more introductory text)
> >
> > v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org/
> >
> > Changes v2 -> v3:
> >
> > * Rebased v5.7-rc3
> >
> > * Added a missing iommu_group_put() as reported by Lu Baolu.
> >
> > * Added a patch to consolidate more initialization work in
> > __iommu_probe_device(), fixing a bug where no 'struct
> > device_iommu' was allocated in the hotplug path.
> >
> > There is also a git-branch available with these patches applied:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
> >
> > Please review. If there are no objections I plan to put these patches
> > into the IOMMU tree early next week.
>
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
FYI, I have just sent a patch to fix this,
https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai-J5quhbR+WMc@public.gmane.org/
>
> [ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
> [ 9426.731347][ T3356] ==================================================================
> [ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
> __lock_acquire at kernel/locking/lockdep.c:4250
> [ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
> [ 9426.753601][ T3356]
> [ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
> [ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
> [ 9426.774111][ T3356] Call trace:
> [ 9426.777245][ T3356] dump_backtrace+0x0/0x398
> [ 9426.781593][ T3356] show_stack+0x14/0x20
> [ 9426.785596][ T3356] dump_stack+0x140/0x1b8
> [ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
> [ 9426.795855][ T3356] kasan_report+0x134/0x1b8
> [ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
> [ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
> [ 9426.810373][ T3356] lock_acquire+0x204/0xf10
> [ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
> [ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
> arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
> [ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
> arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
> (inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
> [ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
> iommu_release_device at drivers/iommu/iommu.c:302
> [ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
> [ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9426.855929][ T3356] device_del+0x618/0xa00
> [ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9426.876100][ T3356] sriov_disable+0x8c/0x348
> [ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9426.896417][ T3356] dev_attr_store+0x38/0x68
> [ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9426.909897][ T3356] __vfs_write+0x54/0xe8
> [ 9426.913984][ T3356] vfs_write+0x124/0x3f0
> [ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
> [ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
> [ 9426.926766][ T3356] do_el0_svc+0x124/0x220
> [ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
> [ 9426.935634][ T3356] el0_sync+0x140/0x180
> [ 9426.939633][ T3356]
> [ 9426.941810][ T3356] Allocated by task 3356:
> [ 9426.945985][ T3356] save_stack+0x24/0x50
> [ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
> [ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
> [ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
> [ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
> [ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
> [ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
> [ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
> [ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
> [ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
> [ 9426.995017][ T3356] really_probe+0x124/0x6d8
> [ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
> [ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
> [ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
> [ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
> [ 9427.018749][ T3356] device_attach+0x10/0x18
> [ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
> [ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
> [ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
> [ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
> [ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
> [ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
> [ 9427.052784][ T3356] dev_attr_store+0x38/0x68
> [ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.066260][ T3356] __vfs_write+0x54/0xe8
> [ 9427.070346][ T3356] vfs_write+0x124/0x3f0
> [ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.083127][ T3356] do_el0_svc+0x124/0x220
> [ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.091994][ T3356] el0_sync+0x140/0x180
> [ 9427.095992][ T3356]
> [ 9427.098168][ T3356] Freed by task 3356:
> [ 9427.101995][ T3356] save_stack+0x24/0x50
> [ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
> [ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
> [ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
> [ 9427.120512][ T3356] kfree+0x128/0x668
> [ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
> [ 9427.129206][ T3356] iommu_group_release+0xec/0x160
> [ 9427.134074][ T3356] kobject_put+0xf4/0x238
> [ 9427.138247][ T3356] kobject_del+0x110/0x190
> [ 9427.142507][ T3356] kobject_put+0x1e4/0x238
> [ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
> [ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
> iommu_release_device at drivers/iommu/iommu.c:300
> [ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
> [ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9427.178233][ T3356] device_del+0x618/0xa00
> [ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9427.198399][ T3356] sriov_disable+0x8c/0x348
> [ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9427.218698][ T3356] dev_attr_store+0x38/0x68
> [ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.232173][ T3356] __vfs_write+0x54/0xe8
> [ 9427.236259][ T3356] vfs_write+0x124/0x3f0
> [ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.249041][ T3356] do_el0_svc+0x124/0x220
> [ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.257908][ T3356] el0_sync+0x140/0x180
> [ 9427.261907][ T3356]
> [ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
> [ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
> [ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
> [ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
> [ 9427.291094][ T3356] The buggy address belongs to the page:
> [ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
> [ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
> [ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
> [ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
> [ 9427.328374][ T3356] page dumped because: kasan: bad access detected
> [ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
> [ 9427.339670][ T3356]
> [ 9427.341846][ T3356] Memory state around the buggy address:
> [ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.371038][ T3356] ^
> [ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [ 9427.394146][ T3356] ==================================================================
> [ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> >
> > Thanks,
> >
> > Joerg
> >
> > Joerg Roedel (33):
> > iommu: Move default domain allocation to separate function
> > iommu/amd: Implement iommu_ops->def_domain_type call-back
> > iommu/vt-d: Wire up iommu_ops->def_domain_type
> > iommu/amd: Remove dma_mask check from check_device()
> > iommu/amd: Return -ENODEV in add_device when device is not handled by
> > IOMMU
> > iommu: Add probe_device() and release_device() call-backs
> > iommu: Move default domain allocation to iommu_probe_device()
> > iommu: Keep a list of allocated groups in __iommu_probe_device()
> > iommu: Move new probe_device path to separate function
> > iommu: Split off default domain allocation from group assignment
> > iommu: Move iommu_group_create_direct_mappings() out of
> > iommu_group_add_device()
> > iommu: Export bus_iommu_probe() and make is safe for re-probing
> > iommu/amd: Remove dev_data->passthrough
> > iommu/amd: Convert to probe/release_device() call-backs
> > iommu/vt-d: Convert to probe/release_device() call-backs
> > iommu/arm-smmu: Convert to probe/release_device() call-backs
> > iommu/pamu: Convert to probe/release_device() call-backs
> > iommu/s390: Convert to probe/release_device() call-backs
> > iommu/virtio: Convert to probe/release_device() call-backs
> > iommu/msm: Convert to probe/release_device() call-backs
> > iommu/mediatek: Convert to probe/release_device() call-backs
> > iommu/mediatek-v1 Convert to probe/release_device() call-backs
> > iommu/qcom: Convert to probe/release_device() call-backs
> > iommu/rockchip: Convert to probe/release_device() call-backs
> > iommu/tegra: Convert to probe/release_device() call-backs
> > iommu/renesas: Convert to probe/release_device() call-backs
> > iommu/omap: Remove orphan_dev tracking
> > iommu/omap: Convert to probe/release_device() call-backs
> > iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> > iommu/exynos: Convert to probe/release_device() call-backs
> > iommu: Remove add_device()/remove_device() code-paths
> > iommu: Move more initialization to __iommu_probe_device()
> > iommu: Unexport iommu_group_get_for_dev()
> >
> > Sai Praneeth Prakhya (1):
> > iommu: Add def_domain_type() callback in iommu_ops
> >
> > drivers/iommu/amd_iommu.c | 97 ++++----
> > drivers/iommu/amd_iommu_types.h | 1 -
> > drivers/iommu/arm-smmu-v3.c | 38 +---
> > drivers/iommu/arm-smmu.c | 39 ++--
> > drivers/iommu/exynos-iommu.c | 24 +-
> > drivers/iommu/fsl_pamu_domain.c | 22 +-
> > drivers/iommu/intel-iommu.c | 68 +-----
> > drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> > drivers/iommu/ipmmu-vmsa.c | 60 ++---
> > drivers/iommu/msm_iommu.c | 34 +--
> > drivers/iommu/mtk_iommu.c | 24 +-
> > drivers/iommu/mtk_iommu_v1.c | 50 ++---
> > drivers/iommu/omap-iommu.c | 99 ++------
> > drivers/iommu/qcom_iommu.c | 24 +-
> > drivers/iommu/rockchip-iommu.c | 26 +--
> > drivers/iommu/s390-iommu.c | 22 +-
> > drivers/iommu/tegra-gart.c | 24 +-
> > drivers/iommu/tegra-smmu.c | 31 +--
> > drivers/iommu/virtio-iommu.c | 41 +---
> > include/linux/iommu.h | 21 +-
> > 20 files changed, 531 insertions(+), 601 deletions(-)
> >
> > --
> > 2.17.1
> >
> > _______________________________________________
> > iommu mailing list
> > iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-04 0:17 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-04 0:17 UTC (permalink / raw)
To: Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Marek Szyprowski,
Jean-Philippe Brucker, linux-samsung-soc, iommu,
Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip, Andy Gross,
jonathan.derrick, linux-s390, linux-arm-msm, linux-mediatek,
Matthias Brugger, virtualization, Gerald Schaefer,
David Woodhouse, linux-kernel, Rob Clark, Kukjin Kim,
Robin Murphy, Lu Baolu
On Tue, Jun 30, 2020 at 08:40:28PM -0400, Qian Cai wrote:
> On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> > Hi,
> >
> > here is the third version of this patch-set. Older versions can be found
> > here:
> >
> > v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> > (Has some more introductory text)
> >
> > v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
> >
> > Changes v2 -> v3:
> >
> > * Rebased v5.7-rc3
> >
> > * Added a missing iommu_group_put() as reported by Lu Baolu.
> >
> > * Added a patch to consolidate more initialization work in
> > __iommu_probe_device(), fixing a bug where no 'struct
> > device_iommu' was allocated in the hotplug path.
> >
> > There is also a git-branch available with these patches applied:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
> >
> > Please review. If there are no objections I plan to put these patches
> > into the IOMMU tree early next week.
>
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
FYI, I have just sent a patch to fix this,
https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
>
> [ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
> [ 9426.731347][ T3356] ==================================================================
> [ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
> __lock_acquire at kernel/locking/lockdep.c:4250
> [ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
> [ 9426.753601][ T3356]
> [ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
> [ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
> [ 9426.774111][ T3356] Call trace:
> [ 9426.777245][ T3356] dump_backtrace+0x0/0x398
> [ 9426.781593][ T3356] show_stack+0x14/0x20
> [ 9426.785596][ T3356] dump_stack+0x140/0x1b8
> [ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
> [ 9426.795855][ T3356] kasan_report+0x134/0x1b8
> [ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
> [ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
> [ 9426.810373][ T3356] lock_acquire+0x204/0xf10
> [ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
> [ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
> arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
> [ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
> arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
> (inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
> [ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
> iommu_release_device at drivers/iommu/iommu.c:302
> [ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
> [ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9426.855929][ T3356] device_del+0x618/0xa00
> [ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9426.876100][ T3356] sriov_disable+0x8c/0x348
> [ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9426.896417][ T3356] dev_attr_store+0x38/0x68
> [ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9426.909897][ T3356] __vfs_write+0x54/0xe8
> [ 9426.913984][ T3356] vfs_write+0x124/0x3f0
> [ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
> [ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
> [ 9426.926766][ T3356] do_el0_svc+0x124/0x220
> [ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
> [ 9426.935634][ T3356] el0_sync+0x140/0x180
> [ 9426.939633][ T3356]
> [ 9426.941810][ T3356] Allocated by task 3356:
> [ 9426.945985][ T3356] save_stack+0x24/0x50
> [ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
> [ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
> [ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
> [ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
> [ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
> [ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
> [ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
> [ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
> [ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
> [ 9426.995017][ T3356] really_probe+0x124/0x6d8
> [ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
> [ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
> [ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
> [ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
> [ 9427.018749][ T3356] device_attach+0x10/0x18
> [ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
> [ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
> [ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
> [ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
> [ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
> [ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
> [ 9427.052784][ T3356] dev_attr_store+0x38/0x68
> [ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.066260][ T3356] __vfs_write+0x54/0xe8
> [ 9427.070346][ T3356] vfs_write+0x124/0x3f0
> [ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.083127][ T3356] do_el0_svc+0x124/0x220
> [ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.091994][ T3356] el0_sync+0x140/0x180
> [ 9427.095992][ T3356]
> [ 9427.098168][ T3356] Freed by task 3356:
> [ 9427.101995][ T3356] save_stack+0x24/0x50
> [ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
> [ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
> [ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
> [ 9427.120512][ T3356] kfree+0x128/0x668
> [ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
> [ 9427.129206][ T3356] iommu_group_release+0xec/0x160
> [ 9427.134074][ T3356] kobject_put+0xf4/0x238
> [ 9427.138247][ T3356] kobject_del+0x110/0x190
> [ 9427.142507][ T3356] kobject_put+0x1e4/0x238
> [ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
> [ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
> iommu_release_device at drivers/iommu/iommu.c:300
> [ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
> [ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9427.178233][ T3356] device_del+0x618/0xa00
> [ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9427.198399][ T3356] sriov_disable+0x8c/0x348
> [ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9427.218698][ T3356] dev_attr_store+0x38/0x68
> [ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.232173][ T3356] __vfs_write+0x54/0xe8
> [ 9427.236259][ T3356] vfs_write+0x124/0x3f0
> [ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.249041][ T3356] do_el0_svc+0x124/0x220
> [ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.257908][ T3356] el0_sync+0x140/0x180
> [ 9427.261907][ T3356]
> [ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
> [ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
> [ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
> [ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
> [ 9427.291094][ T3356] The buggy address belongs to the page:
> [ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
> [ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
> [ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
> [ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
> [ 9427.328374][ T3356] page dumped because: kasan: bad access detected
> [ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
> [ 9427.339670][ T3356]
> [ 9427.341846][ T3356] Memory state around the buggy address:
> [ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.371038][ T3356] ^
> [ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [ 9427.394146][ T3356] ==================================================================
> [ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> >
> > Thanks,
> >
> > Joerg
> >
> > Joerg Roedel (33):
> > iommu: Move default domain allocation to separate function
> > iommu/amd: Implement iommu_ops->def_domain_type call-back
> > iommu/vt-d: Wire up iommu_ops->def_domain_type
> > iommu/amd: Remove dma_mask check from check_device()
> > iommu/amd: Return -ENODEV in add_device when device is not handled by
> > IOMMU
> > iommu: Add probe_device() and release_device() call-backs
> > iommu: Move default domain allocation to iommu_probe_device()
> > iommu: Keep a list of allocated groups in __iommu_probe_device()
> > iommu: Move new probe_device path to separate function
> > iommu: Split off default domain allocation from group assignment
> > iommu: Move iommu_group_create_direct_mappings() out of
> > iommu_group_add_device()
> > iommu: Export bus_iommu_probe() and make is safe for re-probing
> > iommu/amd: Remove dev_data->passthrough
> > iommu/amd: Convert to probe/release_device() call-backs
> > iommu/vt-d: Convert to probe/release_device() call-backs
> > iommu/arm-smmu: Convert to probe/release_device() call-backs
> > iommu/pamu: Convert to probe/release_device() call-backs
> > iommu/s390: Convert to probe/release_device() call-backs
> > iommu/virtio: Convert to probe/release_device() call-backs
> > iommu/msm: Convert to probe/release_device() call-backs
> > iommu/mediatek: Convert to probe/release_device() call-backs
> > iommu/mediatek-v1 Convert to probe/release_device() call-backs
> > iommu/qcom: Convert to probe/release_device() call-backs
> > iommu/rockchip: Convert to probe/release_device() call-backs
> > iommu/tegra: Convert to probe/release_device() call-backs
> > iommu/renesas: Convert to probe/release_device() call-backs
> > iommu/omap: Remove orphan_dev tracking
> > iommu/omap: Convert to probe/release_device() call-backs
> > iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> > iommu/exynos: Convert to probe/release_device() call-backs
> > iommu: Remove add_device()/remove_device() code-paths
> > iommu: Move more initialization to __iommu_probe_device()
> > iommu: Unexport iommu_group_get_for_dev()
> >
> > Sai Praneeth Prakhya (1):
> > iommu: Add def_domain_type() callback in iommu_ops
> >
> > drivers/iommu/amd_iommu.c | 97 ++++----
> > drivers/iommu/amd_iommu_types.h | 1 -
> > drivers/iommu/arm-smmu-v3.c | 38 +---
> > drivers/iommu/arm-smmu.c | 39 ++--
> > drivers/iommu/exynos-iommu.c | 24 +-
> > drivers/iommu/fsl_pamu_domain.c | 22 +-
> > drivers/iommu/intel-iommu.c | 68 +-----
> > drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> > drivers/iommu/ipmmu-vmsa.c | 60 ++---
> > drivers/iommu/msm_iommu.c | 34 +--
> > drivers/iommu/mtk_iommu.c | 24 +-
> > drivers/iommu/mtk_iommu_v1.c | 50 ++---
> > drivers/iommu/omap-iommu.c | 99 ++------
> > drivers/iommu/qcom_iommu.c | 24 +-
> > drivers/iommu/rockchip-iommu.c | 26 +--
> > drivers/iommu/s390-iommu.c | 22 +-
> > drivers/iommu/tegra-gart.c | 24 +-
> > drivers/iommu/tegra-smmu.c | 31 +--
> > drivers/iommu/virtio-iommu.c | 41 +---
> > include/linux/iommu.h | 21 +-
> > 20 files changed, 531 insertions(+), 601 deletions(-)
> >
> > --
> > 2.17.1
> >
> > _______________________________________________
> > iommu mailing list
> > iommu@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-04 0:17 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-04 0:17 UTC (permalink / raw)
To: Joerg Roedel
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Jean-Philippe Brucker,
linux-samsung-soc, iommu, Krzysztof Kozlowski, Jonathan Hunter,
linux-rockchip, Andy Gross, jonathan.derrick, linux-s390,
linux-arm-msm, linux-mediatek, Matthias Brugger, virtualization,
Gerald Schaefer, David Woodhouse, linux-kernel, Kukjin Kim,
Robin Murphy
On Tue, Jun 30, 2020 at 08:40:28PM -0400, Qian Cai wrote:
> On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> > Hi,
> >
> > here is the third version of this patch-set. Older versions can be found
> > here:
> >
> > v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> > (Has some more introductory text)
> >
> > v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
> >
> > Changes v2 -> v3:
> >
> > * Rebased v5.7-rc3
> >
> > * Added a missing iommu_group_put() as reported by Lu Baolu.
> >
> > * Added a patch to consolidate more initialization work in
> > __iommu_probe_device(), fixing a bug where no 'struct
> > device_iommu' was allocated in the hotplug path.
> >
> > There is also a git-branch available with these patches applied:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
> >
> > Please review. If there are no objections I plan to put these patches
> > into the IOMMU tree early next week.
>
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
FYI, I have just sent a patch to fix this,
https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
>
> [ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
> [ 9426.731347][ T3356] ==================================================================
> [ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
> __lock_acquire at kernel/locking/lockdep.c:4250
> [ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
> [ 9426.753601][ T3356]
> [ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
> [ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
> [ 9426.774111][ T3356] Call trace:
> [ 9426.777245][ T3356] dump_backtrace+0x0/0x398
> [ 9426.781593][ T3356] show_stack+0x14/0x20
> [ 9426.785596][ T3356] dump_stack+0x140/0x1b8
> [ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
> [ 9426.795855][ T3356] kasan_report+0x134/0x1b8
> [ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
> [ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
> [ 9426.810373][ T3356] lock_acquire+0x204/0xf10
> [ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
> [ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
> arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
> [ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
> arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
> (inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
> [ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
> iommu_release_device at drivers/iommu/iommu.c:302
> [ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
> [ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9426.855929][ T3356] device_del+0x618/0xa00
> [ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9426.876100][ T3356] sriov_disable+0x8c/0x348
> [ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9426.896417][ T3356] dev_attr_store+0x38/0x68
> [ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9426.909897][ T3356] __vfs_write+0x54/0xe8
> [ 9426.913984][ T3356] vfs_write+0x124/0x3f0
> [ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
> [ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
> [ 9426.926766][ T3356] do_el0_svc+0x124/0x220
> [ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
> [ 9426.935634][ T3356] el0_sync+0x140/0x180
> [ 9426.939633][ T3356]
> [ 9426.941810][ T3356] Allocated by task 3356:
> [ 9426.945985][ T3356] save_stack+0x24/0x50
> [ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
> [ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
> [ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
> [ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
> [ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
> [ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
> [ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
> [ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
> [ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
> [ 9426.995017][ T3356] really_probe+0x124/0x6d8
> [ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
> [ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
> [ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
> [ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
> [ 9427.018749][ T3356] device_attach+0x10/0x18
> [ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
> [ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
> [ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
> [ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
> [ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
> [ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
> [ 9427.052784][ T3356] dev_attr_store+0x38/0x68
> [ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.066260][ T3356] __vfs_write+0x54/0xe8
> [ 9427.070346][ T3356] vfs_write+0x124/0x3f0
> [ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.083127][ T3356] do_el0_svc+0x124/0x220
> [ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.091994][ T3356] el0_sync+0x140/0x180
> [ 9427.095992][ T3356]
> [ 9427.098168][ T3356] Freed by task 3356:
> [ 9427.101995][ T3356] save_stack+0x24/0x50
> [ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
> [ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
> [ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
> [ 9427.120512][ T3356] kfree+0x128/0x668
> [ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
> [ 9427.129206][ T3356] iommu_group_release+0xec/0x160
> [ 9427.134074][ T3356] kobject_put+0xf4/0x238
> [ 9427.138247][ T3356] kobject_del+0x110/0x190
> [ 9427.142507][ T3356] kobject_put+0x1e4/0x238
> [ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
> [ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
> iommu_release_device at drivers/iommu/iommu.c:300
> [ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
> [ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9427.178233][ T3356] device_del+0x618/0xa00
> [ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9427.198399][ T3356] sriov_disable+0x8c/0x348
> [ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9427.218698][ T3356] dev_attr_store+0x38/0x68
> [ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.232173][ T3356] __vfs_write+0x54/0xe8
> [ 9427.236259][ T3356] vfs_write+0x124/0x3f0
> [ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.249041][ T3356] do_el0_svc+0x124/0x220
> [ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.257908][ T3356] el0_sync+0x140/0x180
> [ 9427.261907][ T3356]
> [ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
> [ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
> [ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
> [ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
> [ 9427.291094][ T3356] The buggy address belongs to the page:
> [ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
> [ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
> [ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
> [ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
> [ 9427.328374][ T3356] page dumped because: kasan: bad access detected
> [ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
> [ 9427.339670][ T3356]
> [ 9427.341846][ T3356] Memory state around the buggy address:
> [ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.371038][ T3356] ^
> [ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [ 9427.394146][ T3356] ==================================================================
> [ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> >
> > Thanks,
> >
> > Joerg
> >
> > Joerg Roedel (33):
> > iommu: Move default domain allocation to separate function
> > iommu/amd: Implement iommu_ops->def_domain_type call-back
> > iommu/vt-d: Wire up iommu_ops->def_domain_type
> > iommu/amd: Remove dma_mask check from check_device()
> > iommu/amd: Return -ENODEV in add_device when device is not handled by
> > IOMMU
> > iommu: Add probe_device() and release_device() call-backs
> > iommu: Move default domain allocation to iommu_probe_device()
> > iommu: Keep a list of allocated groups in __iommu_probe_device()
> > iommu: Move new probe_device path to separate function
> > iommu: Split off default domain allocation from group assignment
> > iommu: Move iommu_group_create_direct_mappings() out of
> > iommu_group_add_device()
> > iommu: Export bus_iommu_probe() and make is safe for re-probing
> > iommu/amd: Remove dev_data->passthrough
> > iommu/amd: Convert to probe/release_device() call-backs
> > iommu/vt-d: Convert to probe/release_device() call-backs
> > iommu/arm-smmu: Convert to probe/release_device() call-backs
> > iommu/pamu: Convert to probe/release_device() call-backs
> > iommu/s390: Convert to probe/release_device() call-backs
> > iommu/virtio: Convert to probe/release_device() call-backs
> > iommu/msm: Convert to probe/release_device() call-backs
> > iommu/mediatek: Convert to probe/release_device() call-backs
> > iommu/mediatek-v1 Convert to probe/release_device() call-backs
> > iommu/qcom: Convert to probe/release_device() call-backs
> > iommu/rockchip: Convert to probe/release_device() call-backs
> > iommu/tegra: Convert to probe/release_device() call-backs
> > iommu/renesas: Convert to probe/release_device() call-backs
> > iommu/omap: Remove orphan_dev tracking
> > iommu/omap: Convert to probe/release_device() call-backs
> > iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> > iommu/exynos: Convert to probe/release_device() call-backs
> > iommu: Remove add_device()/remove_device() code-paths
> > iommu: Move more initialization to __iommu_probe_device()
> > iommu: Unexport iommu_group_get_for_dev()
> >
> > Sai Praneeth Prakhya (1):
> > iommu: Add def_domain_type() callback in iommu_ops
> >
> > drivers/iommu/amd_iommu.c | 97 ++++----
> > drivers/iommu/amd_iommu_types.h | 1 -
> > drivers/iommu/arm-smmu-v3.c | 38 +---
> > drivers/iommu/arm-smmu.c | 39 ++--
> > drivers/iommu/exynos-iommu.c | 24 +-
> > drivers/iommu/fsl_pamu_domain.c | 22 +-
> > drivers/iommu/intel-iommu.c | 68 +-----
> > drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> > drivers/iommu/ipmmu-vmsa.c | 60 ++---
> > drivers/iommu/msm_iommu.c | 34 +--
> > drivers/iommu/mtk_iommu.c | 24 +-
> > drivers/iommu/mtk_iommu_v1.c | 50 ++---
> > drivers/iommu/omap-iommu.c | 99 ++------
> > drivers/iommu/qcom_iommu.c | 24 +-
> > drivers/iommu/rockchip-iommu.c | 26 +--
> > drivers/iommu/s390-iommu.c | 22 +-
> > drivers/iommu/tegra-gart.c | 24 +-
> > drivers/iommu/tegra-smmu.c | 31 +--
> > drivers/iommu/virtio-iommu.c | 41 +---
> > include/linux/iommu.h | 21 +-
> > 20 files changed, 531 insertions(+), 601 deletions(-)
> >
> > --
> > 2.17.1
> >
> > _______________________________________________
> > iommu mailing list
> > iommu@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-04 0:17 ` Qian Cai
0 siblings, 0 replies; 163+ messages in thread
From: Qian Cai @ 2020-07-04 0:17 UTC (permalink / raw)
To: Joerg Roedel
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390, linux-samsung-soc,
linux-arm-msm, linux-kernel, Daniel Drake, linux-rockchip, iommu,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
On Tue, Jun 30, 2020 at 08:40:28PM -0400, Qian Cai wrote:
> On Wed, Apr 29, 2020 at 03:36:38PM +0200, Joerg Roedel wrote:
> > Hi,
> >
> > here is the third version of this patch-set. Older versions can be found
> > here:
> >
> > v1: https://lore.kernel.org/lkml/20200407183742.4344-1-joro@8bytes.org/
> > (Has some more introductory text)
> >
> > v2: https://lore.kernel.org/lkml/20200414131542.25608-1-joro@8bytes.org/
> >
> > Changes v2 -> v3:
> >
> > * Rebased v5.7-rc3
> >
> > * Added a missing iommu_group_put() as reported by Lu Baolu.
> >
> > * Added a patch to consolidate more initialization work in
> > __iommu_probe_device(), fixing a bug where no 'struct
> > device_iommu' was allocated in the hotplug path.
> >
> > There is also a git-branch available with these patches applied:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/joro/linux.git/log/?h=iommu-probe-device-v3
> >
> > Please review. If there are no objections I plan to put these patches
> > into the IOMMU tree early next week.
>
> Looks like this patchset introduced an use-after-free on arm-smmu-v3.
>
> Reproduced using mlx5,
>
> # echo 1 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
> # echo 0 > /sys/class/net/enp11s0f1np1/device/sriov_numvfs
>
> The .config,
> https://github.com/cailca/linux-mm/blob/master/arm64.config
>
> Looking at the free stack,
>
> iommu_release_device->iommu_group_remove_device
>
> was introduced in 07/34 ("iommu: Add probe_device() and release_device()
> call-backs").
FYI, I have just sent a patch to fix this,
https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
>
> [ 9426.724641][ T3356] pci 0000:0b:01.2: Removing from iommu group 3
> [ 9426.731347][ T3356] ==================================================================
> [ 9426.739263][ T3356] BUG: KASAN: use-after-free in __lock_acquire+0x3458/0x4440
> __lock_acquire at kernel/locking/lockdep.c:4250
> [ 9426.746477][ T3356] Read of size 8 at addr ffff0089df1a6f68 by task bash/3356
> [ 9426.753601][ T3356]
> [ 9426.755782][ T3356] CPU: 5 PID: 3356 Comm: bash Not tainted 5.8.0-rc3-next-20200630 #2
> [ 9426.763687][ T3356] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
> [ 9426.774111][ T3356] Call trace:
> [ 9426.777245][ T3356] dump_backtrace+0x0/0x398
> [ 9426.781593][ T3356] show_stack+0x14/0x20
> [ 9426.785596][ T3356] dump_stack+0x140/0x1b8
> [ 9426.789772][ T3356] print_address_description.isra.12+0x54/0x4a8
> [ 9426.795855][ T3356] kasan_report+0x134/0x1b8
> [ 9426.800203][ T3356] __asan_report_load8_noabort+0x2c/0x50
> [ 9426.805679][ T3356] __lock_acquire+0x3458/0x4440
> [ 9426.810373][ T3356] lock_acquire+0x204/0xf10
> [ 9426.814722][ T3356] _raw_spin_lock_irqsave+0xf8/0x180
> [ 9426.819853][ T3356] arm_smmu_detach_dev+0xd8/0x4a0
> arm_smmu_detach_dev at drivers/iommu/arm-smmu-v3.c:2776
> [ 9426.824721][ T3356] arm_smmu_release_device+0xb4/0x1c8
> arm_smmu_disable_pasid at drivers/iommu/arm-smmu-v3.c:2754
> (inlined by) arm_smmu_release_device at drivers/iommu/arm-smmu-v3.c:3000
> [ 9426.829937][ T3356] iommu_release_device+0xc0/0x178
> iommu_release_device at drivers/iommu/iommu.c:302
> [ 9426.834892][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9426.839762][ T3356] notifier_call_chain+0xa4/0x128
> [ 9426.844630][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9426.850367][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9426.855929][ T3356] device_del+0x618/0xa00
> [ 9426.860105][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9426.865233][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9426.870972][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9426.876100][ T3356] sriov_disable+0x8c/0x348
> [ 9426.880447][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9426.885117][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9426.891549][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9426.896417][ T3356] dev_attr_store+0x38/0x68
> [ 9426.900766][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9426.905200][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9426.909897][ T3356] __vfs_write+0x54/0xe8
> [ 9426.913984][ T3356] vfs_write+0x124/0x3f0
> [ 9426.918070][ T3356] ksys_write+0xe8/0x1b8
> [ 9426.922157][ T3356] __arm64_sys_write+0x68/0x98
> [ 9426.926766][ T3356] do_el0_svc+0x124/0x220
> [ 9426.930941][ T3356] el0_sync_handler+0x260/0x408
> [ 9426.935634][ T3356] el0_sync+0x140/0x180
> [ 9426.939633][ T3356]
> [ 9426.941810][ T3356] Allocated by task 3356:
> [ 9426.945985][ T3356] save_stack+0x24/0x50
> [ 9426.949986][ T3356] __kasan_kmalloc.isra.13+0xc4/0xe0
> [ 9426.955114][ T3356] kasan_kmalloc+0xc/0x18
> [ 9426.959288][ T3356] kmem_cache_alloc_trace+0x1ec/0x318
> [ 9426.964503][ T3356] arm_smmu_domain_alloc+0x54/0x148
> [ 9426.969545][ T3356] iommu_group_alloc_default_domain+0xc0/0x440
> [ 9426.975541][ T3356] iommu_probe_device+0x1c0/0x308
> [ 9426.980409][ T3356] iort_iommu_configure+0x434/0x518
> [ 9426.985452][ T3356] acpi_dma_configure+0xf0/0x128
> [ 9426.990235][ T3356] pci_dma_configure+0x114/0x160
> [ 9426.995017][ T3356] really_probe+0x124/0x6d8
> [ 9426.999364][ T3356] driver_probe_device+0xc4/0x180
> [ 9427.004232][ T3356] __device_attach_driver+0x184/0x1e8
> [ 9427.009447][ T3356] bus_for_each_drv+0x114/0x1a0
> [ 9427.014142][ T3356] __device_attach+0x19c/0x2a8
> [ 9427.018749][ T3356] device_attach+0x10/0x18
> [ 9427.023009][ T3356] pci_bus_add_device+0x70/0xf8
> [ 9427.027704][ T3356] pci_iov_add_virtfn+0x7b4/0xb40
> [ 9427.032571][ T3356] sriov_enable+0x5c8/0xc30
> [ 9427.036918][ T3356] pci_enable_sriov+0x64/0x80
> [ 9427.041485][ T3356] mlx5_core_sriov_configure+0x58/0x260 [mlx5_core]
> [ 9427.047917][ T3356] sriov_numvfs_store+0x1c0/0x318
> [ 9427.052784][ T3356] dev_attr_store+0x38/0x68
> [ 9427.057131][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.061565][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.066260][ T3356] __vfs_write+0x54/0xe8
> [ 9427.070346][ T3356] vfs_write+0x124/0x3f0
> [ 9427.074433][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.078519][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.083127][ T3356] do_el0_svc+0x124/0x220
> [ 9427.087300][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.091994][ T3356] el0_sync+0x140/0x180
> [ 9427.095992][ T3356]
> [ 9427.098168][ T3356] Freed by task 3356:
> [ 9427.101995][ T3356] save_stack+0x24/0x50
> [ 9427.105996][ T3356] __kasan_slab_free+0x124/0x198
> [ 9427.110777][ T3356] kasan_slab_free+0x10/0x18
> [ 9427.115210][ T3356] slab_free_freelist_hook+0x110/0x298
> [ 9427.120512][ T3356] kfree+0x128/0x668
> [ 9427.124252][ T3356] arm_smmu_domain_free+0xf4/0x1a0
> [ 9427.129206][ T3356] iommu_group_release+0xec/0x160
> [ 9427.134074][ T3356] kobject_put+0xf4/0x238
> [ 9427.138247][ T3356] kobject_del+0x110/0x190
> [ 9427.142507][ T3356] kobject_put+0x1e4/0x238
> [ 9427.146767][ T3356] iommu_group_remove_device+0x394/0x938
> [ 9427.152242][ T3356] iommu_release_device+0x9c/0x178
> iommu_release_device at drivers/iommu/iommu.c:300
> [ 9427.157196][ T3356] iommu_bus_notifier+0x118/0x160
> [ 9427.162065][ T3356] notifier_call_chain+0xa4/0x128
> [ 9427.166934][ T3356] __blocking_notifier_call_chain+0x70/0xa8
> [ 9427.172670][ T3356] blocking_notifier_call_chain+0x14/0x20
> [ 9427.178233][ T3356] device_del+0x618/0xa00
> [ 9427.182406][ T3356] pci_remove_bus_device+0x108/0x2d8
> [ 9427.187535][ T3356] pci_stop_and_remove_bus_device+0x1c/0x28
> [ 9427.193271][ T3356] pci_iov_remove_virtfn+0x228/0x368
> [ 9427.198399][ T3356] sriov_disable+0x8c/0x348
> [ 9427.202746][ T3356] pci_disable_sriov+0x5c/0x70
> [ 9427.207398][ T3356] mlx5_core_sriov_configure+0xd8/0x260 [mlx5_core]
> [ 9427.213830][ T3356] sriov_numvfs_store+0x240/0x318
> [ 9427.218698][ T3356] dev_attr_store+0x38/0x68
> [ 9427.223045][ T3356] sysfs_kf_write+0xdc/0x128
> [ 9427.227478][ T3356] kernfs_fop_write+0x23c/0x448
> [ 9427.232173][ T3356] __vfs_write+0x54/0xe8
> [ 9427.236259][ T3356] vfs_write+0x124/0x3f0
> [ 9427.240346][ T3356] ksys_write+0xe8/0x1b8
> [ 9427.244433][ T3356] __arm64_sys_write+0x68/0x98
> [ 9427.249041][ T3356] do_el0_svc+0x124/0x220
> [ 9427.253215][ T3356] el0_sync_handler+0x260/0x408
> [ 9427.257908][ T3356] el0_sync+0x140/0x180
> [ 9427.261907][ T3356]
> [ 9427.264084][ T3356] The buggy address belongs to the object at ffff0089df1a6e00
> [ 9427.264084][ T3356] which belongs to the cache kmalloc-512 of size 512
> [ 9427.277980][ T3356] The buggy address is located 360 bytes inside of
> [ 9427.277980][ T3356] 512-byte region [ffff0089df1a6e00, ffff0089df1a7000)
> [ 9427.291094][ T3356] The buggy address belongs to the page:
> [ 9427.296571][ T3356] page:ffffffe02257c680 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff0089df1a1400
> [ 9427.306823][ T3356] flags: 0x7ffff800000200(slab)
> [ 9427.311520][ T3356] raw: 007ffff800000200 ffffffe02246b8c8 ffffffe02257ff88 ffff000000320680
> [ 9427.319949][ T3356] raw: ffff0089df1a1400 00000000002a000e 00000001ffffffff ffff0089df1a5001
> [ 9427.328374][ T3356] page dumped because: kasan: bad access detected
> [ 9427.334630][ T3356] page->mem_cgroup:ffff0089df1a5001
> [ 9427.339670][ T3356]
> [ 9427.341846][ T3356] Memory state around the buggy address:
> [ 9427.347322][ T3356] ffff0089df1a6e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.355228][ T3356] ffff0089df1a6e80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.363133][ T3356] >ffff0089df1a6f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.371038][ T3356] ^
> [ 9427.378337][ T3356] ffff0089df1a6f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [ 9427.386242][ T3356] ffff0089df1a7000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [ 9427.394146][ T3356] ==================================================================
> [ 9427.402052][ T3356] Disabling lock debugging due to kernel taint
>
> >
> > Thanks,
> >
> > Joerg
> >
> > Joerg Roedel (33):
> > iommu: Move default domain allocation to separate function
> > iommu/amd: Implement iommu_ops->def_domain_type call-back
> > iommu/vt-d: Wire up iommu_ops->def_domain_type
> > iommu/amd: Remove dma_mask check from check_device()
> > iommu/amd: Return -ENODEV in add_device when device is not handled by
> > IOMMU
> > iommu: Add probe_device() and release_device() call-backs
> > iommu: Move default domain allocation to iommu_probe_device()
> > iommu: Keep a list of allocated groups in __iommu_probe_device()
> > iommu: Move new probe_device path to separate function
> > iommu: Split off default domain allocation from group assignment
> > iommu: Move iommu_group_create_direct_mappings() out of
> > iommu_group_add_device()
> > iommu: Export bus_iommu_probe() and make is safe for re-probing
> > iommu/amd: Remove dev_data->passthrough
> > iommu/amd: Convert to probe/release_device() call-backs
> > iommu/vt-d: Convert to probe/release_device() call-backs
> > iommu/arm-smmu: Convert to probe/release_device() call-backs
> > iommu/pamu: Convert to probe/release_device() call-backs
> > iommu/s390: Convert to probe/release_device() call-backs
> > iommu/virtio: Convert to probe/release_device() call-backs
> > iommu/msm: Convert to probe/release_device() call-backs
> > iommu/mediatek: Convert to probe/release_device() call-backs
> > iommu/mediatek-v1 Convert to probe/release_device() call-backs
> > iommu/qcom: Convert to probe/release_device() call-backs
> > iommu/rockchip: Convert to probe/release_device() call-backs
> > iommu/tegra: Convert to probe/release_device() call-backs
> > iommu/renesas: Convert to probe/release_device() call-backs
> > iommu/omap: Remove orphan_dev tracking
> > iommu/omap: Convert to probe/release_device() call-backs
> > iommu/exynos: Use first SYSMMU in controllers list for IOMMU core
> > iommu/exynos: Convert to probe/release_device() call-backs
> > iommu: Remove add_device()/remove_device() code-paths
> > iommu: Move more initialization to __iommu_probe_device()
> > iommu: Unexport iommu_group_get_for_dev()
> >
> > Sai Praneeth Prakhya (1):
> > iommu: Add def_domain_type() callback in iommu_ops
> >
> > drivers/iommu/amd_iommu.c | 97 ++++----
> > drivers/iommu/amd_iommu_types.h | 1 -
> > drivers/iommu/arm-smmu-v3.c | 38 +---
> > drivers/iommu/arm-smmu.c | 39 ++--
> > drivers/iommu/exynos-iommu.c | 24 +-
> > drivers/iommu/fsl_pamu_domain.c | 22 +-
> > drivers/iommu/intel-iommu.c | 68 +-----
> > drivers/iommu/iommu.c | 387 +++++++++++++++++++++++++-------
> > drivers/iommu/ipmmu-vmsa.c | 60 ++---
> > drivers/iommu/msm_iommu.c | 34 +--
> > drivers/iommu/mtk_iommu.c | 24 +-
> > drivers/iommu/mtk_iommu_v1.c | 50 ++---
> > drivers/iommu/omap-iommu.c | 99 ++------
> > drivers/iommu/qcom_iommu.c | 24 +-
> > drivers/iommu/rockchip-iommu.c | 26 +--
> > drivers/iommu/s390-iommu.c | 22 +-
> > drivers/iommu/tegra-gart.c | 24 +-
> > drivers/iommu/tegra-smmu.c | 31 +--
> > drivers/iommu/virtio-iommu.c | 41 +---
> > include/linux/iommu.h | 21 +-
> > 20 files changed, 531 insertions(+), 601 deletions(-)
> >
> > --
> > 2.17.1
> >
> > _______________________________________________
> > iommu mailing list
> > iommu@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
[parent not found: <20200704001709.GA1502-J5quhbR+WMc@public.gmane.org>]
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
2020-07-04 0:17 ` Qian Cai
(?)
(?)
@ 2020-07-09 15:24 ` Joerg Roedel
-1 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-07-09 15:24 UTC (permalink / raw)
To: Qian Cai
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390-u79uwXL29TY76Z2rM5mHXA,
linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Daniel
On Fri, Jul 03, 2020 at 08:17:09PM -0400, Qian Cai wrote:
> FYI, I have just sent a patch to fix this,
>
> https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai-J5quhbR+WMc@public.gmane.org/
Just queued that fix, thanks. Please don't send patches to my suse
email address, use only the 8bytes.org one.
Thanks,
Joerg
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-09 15:24 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-07-09 15:24 UTC (permalink / raw)
To: Qian Cai
Cc: Heiko Stuebner, Bjorn Andersson, linux-tegra, Thierry Reding,
Daniel Drake, Will Deacon, Marek Szyprowski,
Jean-Philippe Brucker, linux-samsung-soc, iommu,
Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip, Andy Gross,
jonathan.derrick, linux-s390, linux-arm-msm, linux-mediatek,
Matthias Brugger, virtualization, Gerald Schaefer,
David Woodhouse, linux-kernel, Rob Clark, Kukjin Kim,
Robin Murphy, Lu Baolu
On Fri, Jul 03, 2020 at 08:17:09PM -0400, Qian Cai wrote:
> FYI, I have just sent a patch to fix this,
>
> https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
Just queued that fix, thanks. Please don't send patches to my suse
email address, use only the 8bytes.org one.
Thanks,
Joerg
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-09 15:24 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-07-09 15:24 UTC (permalink / raw)
To: Qian Cai
Cc: Heiko Stuebner, linux-tegra, Thierry Reding, Daniel Drake,
Will Deacon, Jean-Philippe Brucker, linux-samsung-soc, iommu,
Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip, Andy Gross,
jonathan.derrick, linux-s390, linux-arm-msm, linux-mediatek,
Matthias Brugger, virtualization, Gerald Schaefer,
David Woodhouse, linux-kernel, Kukjin Kim, Robin Murphy
On Fri, Jul 03, 2020 at 08:17:09PM -0400, Qian Cai wrote:
> FYI, I have just sent a patch to fix this,
>
> https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
Just queued that fix, thanks. Please don't send patches to my suse
email address, use only the 8bytes.org one.
Thanks,
Joerg
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 163+ messages in thread
* Re: [PATCH v3 00/34] iommu: Move iommu_group setup to IOMMU core code
@ 2020-07-09 15:24 ` Joerg Roedel
0 siblings, 0 replies; 163+ messages in thread
From: Joerg Roedel @ 2020-07-09 15:24 UTC (permalink / raw)
To: Qian Cai
Cc: Will Deacon, Robin Murphy, Marek Szyprowski, Kukjin Kim,
Krzysztof Kozlowski, David Woodhouse, Lu Baolu, Andy Gross,
Bjorn Andersson, Matthias Brugger, Rob Clark, Heiko Stuebner,
Gerald Schaefer, Thierry Reding, Jonathan Hunter,
Jean-Philippe Brucker, linux-s390, linux-samsung-soc,
linux-arm-msm, linux-kernel, Daniel Drake, linux-rockchip, iommu,
linux-mediatek, linux-tegra, virtualization, jonathan.derrick
On Fri, Jul 03, 2020 at 08:17:09PM -0400, Qian Cai wrote:
> FYI, I have just sent a patch to fix this,
>
> https://lore.kernel.org/linux-iommu/20200704001003.2303-1-cai@lca.pw/
Just queued that fix, thanks. Please don't send patches to my suse
email address, use only the 8bytes.org one.
Thanks,
Joerg
^ permalink raw reply [flat|nested] 163+ messages in thread