* [PATCH 1/2] iommu: Retire iommu_capable()
@ 2022-08-15 15:26 Robin Murphy
2022-08-15 15:26 ` [PATCH 2/2] iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better Robin Murphy
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Robin Murphy @ 2022-08-15 15:26 UTC (permalink / raw)
To: joro, will; +Cc: iommu, linux-arm-kernel
With all callers now converted to the device-specific version, retire
the old bus-based interface, and give drivers the chance to indicate
accurate per-instance capabilities.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/amd/iommu.c | 2 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +-
drivers/iommu/arm/arm-smmu/qcom_iommu.c | 2 +-
drivers/iommu/fsl_pamu_domain.c | 2 +-
drivers/iommu/intel/iommu.c | 2 +-
drivers/iommu/iommu.c | 11 +----------
drivers/iommu/s390-iommu.c | 2 +-
include/linux/iommu.h | 8 +-------
9 files changed, 9 insertions(+), 24 deletions(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 65b8e4fd8217..94220eb5bff3 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2251,7 +2251,7 @@ static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
return ops->iova_to_phys(ops, iova);
}
-static bool amd_iommu_capable(enum iommu_cap cap)
+static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
{
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index d32b02336411..ab919ec43c4d 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1992,7 +1992,7 @@ static const struct iommu_flush_ops arm_smmu_flush_ops = {
};
/* IOMMU API */
-static bool arm_smmu_capable(enum iommu_cap cap)
+static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
{
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index dfa82df00342..ce036a053fb8 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1330,7 +1330,7 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
return ops->iova_to_phys(ops, iova);
}
-static bool arm_smmu_capable(enum iommu_cap cap)
+static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
{
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 17235116d3bb..66ca47f2e57f 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -493,7 +493,7 @@ static phys_addr_t qcom_iommu_iova_to_phys(struct iommu_domain *domain,
return ret;
}
-static bool qcom_iommu_capable(enum iommu_cap cap)
+static bool qcom_iommu_capable(struct device *dev, enum iommu_cap cap)
{
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 011f9ab7f743..08fd9089e3ba 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -178,7 +178,7 @@ static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
return iova;
}
-static bool fsl_pamu_capable(enum iommu_cap cap)
+static bool fsl_pamu_capable(struct device *dev, enum iommu_cap cap)
{
return cap == IOMMU_CAP_CACHE_COHERENCY;
}
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 7cca030a508e..da63b358ef4a 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4429,7 +4429,7 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
return true;
}
-static bool intel_iommu_capable(enum iommu_cap cap)
+static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
{
if (cap == IOMMU_CAP_CACHE_COHERENCY)
return true;
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 780fb7071577..6283a8b4def4 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1869,19 +1869,10 @@ bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
if (!ops->capable)
return false;
- return ops->capable(cap);
+ return ops->capable(dev, cap);
}
EXPORT_SYMBOL_GPL(device_iommu_capable);
-bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
-{
- if (!bus->iommu_ops || !bus->iommu_ops->capable)
- return false;
-
- return bus->iommu_ops->capable(cap);
-}
-EXPORT_SYMBOL_GPL(iommu_capable);
-
/**
* iommu_set_fault_handler() - set a fault handler for an iommu domain
* @domain: iommu domain
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index c898bcbbce11..cd0ee89d63e0 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -39,7 +39,7 @@ static struct s390_domain *to_s390_domain(struct iommu_domain *dom)
return container_of(dom, struct s390_domain, domain);
}
-static bool s390_iommu_capable(enum iommu_cap cap)
+static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
{
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ea30f00dc145..e39372dfe8c4 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -227,7 +227,7 @@ struct iommu_iotlb_gather {
* @owner: Driver module providing these ops
*/
struct iommu_ops {
- bool (*capable)(enum iommu_cap);
+ bool (*capable)(struct device *dev, enum iommu_cap);
/* Domain allocation and freeing by the iommu driver */
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
@@ -420,7 +420,6 @@ 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 device_iommu_capable(struct device *dev, enum iommu_cap cap);
-extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
extern struct iommu_group *iommu_group_get_by_id(int id);
extern void iommu_domain_free(struct iommu_domain *domain);
@@ -697,11 +696,6 @@ static inline bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
return false;
}
-static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
-{
- return false;
-}
-
static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
{
return NULL;
--
2.36.1.dirty
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better
2022-08-15 15:26 [PATCH 1/2] iommu: Retire iommu_capable() Robin Murphy
@ 2022-08-15 15:26 ` Robin Murphy
2022-08-17 8:41 ` [PATCH 1/2] iommu: Retire iommu_capable() Baolu Lu
2022-09-07 12:17 ` Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Robin Murphy @ 2022-08-15 15:26 UTC (permalink / raw)
To: joro, will; +Cc: iommu, linux-arm-kernel
Assuming that any SMMU can enforce coherency for any device is clearly
nonsense. Although technically even a single SMMU instance can be wired
up to only be capable of emitting coherent traffic for some of the
devices it translates, it's a fairly realistic approximation that if the
SMMU's pagetable walker is wired up to a coherent interconnect then all
its translation units probably are too, and conversely that lack of
coherent table walks implies a non-coherent system in general. Either
way it's still less inaccurate than what we've been claiming so far.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 5 ++++-
drivers/iommu/arm/arm-smmu/arm-smmu.c | 9 ++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index ab919ec43c4d..fceab59113ba 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1994,9 +1994,12 @@ static const struct iommu_flush_ops arm_smmu_flush_ops = {
/* IOMMU API */
static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
{
+ struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
- return true;
+ /* Assume that a coherent TCU implies coherent TBUs */
+ return master->smmu->features & ARM_SMMU_FEAT_COHERENCY;
case IOMMU_CAP_NOEXEC:
return true;
default:
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index ce036a053fb8..8039c8bc8470 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1332,13 +1332,12 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
{
+ struct arm_smmu_master_cfg *cfg = dev_iommu_priv_get(dev);
+
switch (cap) {
case IOMMU_CAP_CACHE_COHERENCY:
- /*
- * Return true here as the SMMU can always send out coherent
- * requests.
- */
- return true;
+ /* Assume that a coherent TCU implies coherent TBUs */
+ return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK;
case IOMMU_CAP_NOEXEC:
return true;
default:
--
2.36.1.dirty
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] iommu: Retire iommu_capable()
2022-08-15 15:26 [PATCH 1/2] iommu: Retire iommu_capable() Robin Murphy
2022-08-15 15:26 ` [PATCH 2/2] iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better Robin Murphy
@ 2022-08-17 8:41 ` Baolu Lu
2022-09-07 12:17 ` Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Baolu Lu @ 2022-08-17 8:41 UTC (permalink / raw)
To: Robin Murphy, joro, will; +Cc: baolu.lu, iommu, linux-arm-kernel
On 2022/8/15 23:26, Robin Murphy wrote:
> With all callers now converted to the device-specific version, retire
> the old bus-based interface, and give drivers the chance to indicate
> accurate per-instance capabilities.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Best regards,
baolu
> ---
> drivers/iommu/amd/iommu.c | 2 +-
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
> drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +-
> drivers/iommu/arm/arm-smmu/qcom_iommu.c | 2 +-
> drivers/iommu/fsl_pamu_domain.c | 2 +-
> drivers/iommu/intel/iommu.c | 2 +-
> drivers/iommu/iommu.c | 11 +----------
> drivers/iommu/s390-iommu.c | 2 +-
> include/linux/iommu.h | 8 +-------
> 9 files changed, 9 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 65b8e4fd8217..94220eb5bff3 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -2251,7 +2251,7 @@ static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
> return ops->iova_to_phys(ops, iova);
> }
>
> -static bool amd_iommu_capable(enum iommu_cap cap)
> +static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
> {
> switch (cap) {
> case IOMMU_CAP_CACHE_COHERENCY:
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index d32b02336411..ab919ec43c4d 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -1992,7 +1992,7 @@ static const struct iommu_flush_ops arm_smmu_flush_ops = {
> };
>
> /* IOMMU API */
> -static bool arm_smmu_capable(enum iommu_cap cap)
> +static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
> {
> switch (cap) {
> case IOMMU_CAP_CACHE_COHERENCY:
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> index dfa82df00342..ce036a053fb8 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> @@ -1330,7 +1330,7 @@ static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
> return ops->iova_to_phys(ops, iova);
> }
>
> -static bool arm_smmu_capable(enum iommu_cap cap)
> +static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
> {
> switch (cap) {
> case IOMMU_CAP_CACHE_COHERENCY:
> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> index 17235116d3bb..66ca47f2e57f 100644
> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> @@ -493,7 +493,7 @@ static phys_addr_t qcom_iommu_iova_to_phys(struct iommu_domain *domain,
> return ret;
> }
>
> -static bool qcom_iommu_capable(enum iommu_cap cap)
> +static bool qcom_iommu_capable(struct device *dev, enum iommu_cap cap)
> {
> switch (cap) {
> case IOMMU_CAP_CACHE_COHERENCY:
> diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
> index 011f9ab7f743..08fd9089e3ba 100644
> --- a/drivers/iommu/fsl_pamu_domain.c
> +++ b/drivers/iommu/fsl_pamu_domain.c
> @@ -178,7 +178,7 @@ static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
> return iova;
> }
>
> -static bool fsl_pamu_capable(enum iommu_cap cap)
> +static bool fsl_pamu_capable(struct device *dev, enum iommu_cap cap)
> {
> return cap == IOMMU_CAP_CACHE_COHERENCY;
> }
> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> index 7cca030a508e..da63b358ef4a 100644
> --- a/drivers/iommu/intel/iommu.c
> +++ b/drivers/iommu/intel/iommu.c
> @@ -4429,7 +4429,7 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
> return true;
> }
>
> -static bool intel_iommu_capable(enum iommu_cap cap)
> +static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
> {
> if (cap == IOMMU_CAP_CACHE_COHERENCY)
> return true;
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 780fb7071577..6283a8b4def4 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1869,19 +1869,10 @@ bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
> if (!ops->capable)
> return false;
>
> - return ops->capable(cap);
> + return ops->capable(dev, cap);
> }
> EXPORT_SYMBOL_GPL(device_iommu_capable);
>
> -bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
> -{
> - if (!bus->iommu_ops || !bus->iommu_ops->capable)
> - return false;
> -
> - return bus->iommu_ops->capable(cap);
> -}
> -EXPORT_SYMBOL_GPL(iommu_capable);
> -
> /**
> * iommu_set_fault_handler() - set a fault handler for an iommu domain
> * @domain: iommu domain
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index c898bcbbce11..cd0ee89d63e0 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -39,7 +39,7 @@ static struct s390_domain *to_s390_domain(struct iommu_domain *dom)
> return container_of(dom, struct s390_domain, domain);
> }
>
> -static bool s390_iommu_capable(enum iommu_cap cap)
> +static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
> {
> switch (cap) {
> case IOMMU_CAP_CACHE_COHERENCY:
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index ea30f00dc145..e39372dfe8c4 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -227,7 +227,7 @@ struct iommu_iotlb_gather {
> * @owner: Driver module providing these ops
> */
> struct iommu_ops {
> - bool (*capable)(enum iommu_cap);
> + bool (*capable)(struct device *dev, enum iommu_cap);
>
> /* Domain allocation and freeing by the iommu driver */
> struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
> @@ -420,7 +420,6 @@ 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 device_iommu_capable(struct device *dev, enum iommu_cap cap);
> -extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
> extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
> extern struct iommu_group *iommu_group_get_by_id(int id);
> extern void iommu_domain_free(struct iommu_domain *domain);
> @@ -697,11 +696,6 @@ static inline bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
> return false;
> }
>
> -static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
> -{
> - return false;
> -}
> -
> static inline struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
> {
> return NULL;
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] iommu: Retire iommu_capable()
2022-08-15 15:26 [PATCH 1/2] iommu: Retire iommu_capable() Robin Murphy
2022-08-15 15:26 ` [PATCH 2/2] iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better Robin Murphy
2022-08-17 8:41 ` [PATCH 1/2] iommu: Retire iommu_capable() Baolu Lu
@ 2022-09-07 12:17 ` Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2022-09-07 12:17 UTC (permalink / raw)
To: Robin Murphy; +Cc: will, iommu, linux-arm-kernel
On Mon, Aug 15, 2022 at 04:26:49PM +0100, Robin Murphy wrote:
> With all callers now converted to the device-specific version, retire
> the old bus-based interface, and give drivers the chance to indicate
> accurate per-instance capabilities.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Applied, thanks Robin.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-07 12:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-15 15:26 [PATCH 1/2] iommu: Retire iommu_capable() Robin Murphy
2022-08-15 15:26 ` [PATCH 2/2] iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better Robin Murphy
2022-08-17 8:41 ` [PATCH 1/2] iommu: Retire iommu_capable() Baolu Lu
2022-09-07 12:17 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).