2020-03-10 09:14:39

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 00/15 v2] iommu: Move iommu_fwspec out of 'struct device'

Hi,

here is a patch-set to rename iommu_param to dev_iommu and
establish it as a struct for generic per-device iommu-data.
Also move the iommu_fwspec pointer from struct device into
dev_iommu to have less iommu-related pointers in struct
device.

The bigger part of this patch-set moves the iommu_priv
pointer from struct iommu_fwspec to dev_iommu, making is
usable for iommu-drivers which do not use fwspecs.

The changes for that were mostly straightforward, except for
the arm-smmu (_not_ arm-smmu-v3) and the qcom iommu driver.
Unfortunatly I don't have the hardware for those, so any
testing of these drivers is greatly appreciated.

Please review.

Regards,

Joerg

Changes to v1:

- Rebased to v5.6-rc5
- Fixed compile error with CONFIG_IOMMU_API=n
- Added Jean-Philippes fix to the ACPI/IORT patch

Joerg Roedel (15):
iommu: Define dev_iommu_fwspec_get() for !CONFIG_IOMMU_API
ACPI/IORT: Remove direct access of dev->iommu_fwspec
drm/msm/mdp5: Remove direct access of dev->iommu_fwspec
iommu/tegra-gart: Remove direct access of dev->iommu_fwspec
iommu: Rename struct iommu_param to dev_iommu
iommu: Move iommu_fwspec to struct dev_iommu
iommu/arm-smmu: Fix uninitilized variable warning
iommu: Introduce accessors for iommu private data
iommu/arm-smmu-v3: Use accessor functions for iommu private data
iommu/arm-smmu: Use accessor functions for iommu private data
iommu/renesas: Use accessor functions for iommu private data
iommu/mediatek: Use accessor functions for iommu private data
iommu/qcom: Use accessor functions for iommu private data
iommu/virtio: Use accessor functions for iommu private data
iommu: Move fwspec->iommu_priv to struct dev_iommu

drivers/acpi/arm64/iort.c | 6 ++-
drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c | 2 +-
drivers/iommu/arm-smmu-v3.c | 10 ++--
drivers/iommu/arm-smmu.c | 58 +++++++++++-----------
drivers/iommu/iommu.c | 31 ++++++------
drivers/iommu/ipmmu-vmsa.c | 7 +--
drivers/iommu/mtk_iommu.c | 13 +++--
drivers/iommu/mtk_iommu_v1.c | 14 +++---
drivers/iommu/qcom_iommu.c | 61 ++++++++++++++----------
drivers/iommu/tegra-gart.c | 2 +-
drivers/iommu/virtio-iommu.c | 11 ++---
include/linux/device.h | 7 ++-
include/linux/iommu.h | 33 ++++++++++---
13 files changed, 143 insertions(+), 112 deletions(-)

--
2.17.1


2020-03-10 09:14:55

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 09/15] iommu/arm-smmu-v3: Use accessor functions for iommu private data

From: Joerg Roedel <[email protected]>

Make use of dev_iommu_priv_set/get() functions in the code.

Tested-by: Hanjun Guo <[email protected]>
Signed-off-by: Joerg Roedel <[email protected]>
---
drivers/iommu/arm-smmu-v3.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index aa3ac2a03807..2b68498dfb66 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -2659,7 +2659,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
if (!fwspec)
return -ENOENT;

- master = fwspec->iommu_priv;
+ master = dev_iommu_priv_get(dev);
smmu = master->smmu;

arm_smmu_detach_dev(master);
@@ -2795,7 +2795,7 @@ static int arm_smmu_add_device(struct device *dev)
if (!fwspec || fwspec->ops != &arm_smmu_ops)
return -ENODEV;

- if (WARN_ON_ONCE(fwspec->iommu_priv))
+ if (WARN_ON_ONCE(dev_iommu_priv_get(dev)))
return -EBUSY;

smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
@@ -2810,7 +2810,7 @@ static int arm_smmu_add_device(struct device *dev)
master->smmu = smmu;
master->sids = fwspec->ids;
master->num_sids = fwspec->num_ids;
- fwspec->iommu_priv = master;
+ dev_iommu_priv_set(dev, master);

/* Check the SIDs are in range of the SMMU and our stream table */
for (i = 0; i < master->num_sids; i++) {
@@ -2852,7 +2852,7 @@ static int arm_smmu_add_device(struct device *dev)
iommu_device_unlink(&smmu->iommu, dev);
err_free_master:
kfree(master);
- fwspec->iommu_priv = NULL;
+ dev_iommu_priv_set(dev, NULL);
return ret;
}

@@ -2865,7 +2865,7 @@ static void arm_smmu_remove_device(struct device *dev)
if (!fwspec || fwspec->ops != &arm_smmu_ops)
return;

- master = fwspec->iommu_priv;
+ master = dev_iommu_priv_get(dev);
smmu = master->smmu;
arm_smmu_detach_dev(master);
iommu_group_remove_device(dev);
--
2.17.1

2020-03-10 09:15:00

by Joerg Roedel

[permalink] [raw]
Subject: [PATCH 15/15] iommu: Move fwspec->iommu_priv to struct dev_iommu

From: Joerg Roedel <[email protected]>

Move the pointer for iommu private data from struct iommu_fwspec to
struct dev_iommu.

Tested-by: Will Deacon <[email protected]> # arm-smmu
Signed-off-by: Joerg Roedel <[email protected]>
---
include/linux/iommu.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 056900e75758..8c4d45fce042 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -369,6 +369,7 @@ struct iommu_fault_param {
*
* @fault_param: IOMMU detected device fault reporting data
* @fwspec: IOMMU fwspec data
+ * @priv: IOMMU Driver private data
*
* TODO: migrate other per device data pointers under iommu_dev_data, e.g.
* struct iommu_group *iommu_group;
@@ -377,6 +378,7 @@ struct dev_iommu {
struct mutex lock;
struct iommu_fault_param *fault_param;
struct iommu_fwspec *fwspec;
+ void *priv;
};

int iommu_device_register(struct iommu_device *iommu);
@@ -589,7 +591,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev);
struct iommu_fwspec {
const struct iommu_ops *ops;
struct fwnode_handle *iommu_fwnode;
- void *iommu_priv;
u32 flags;
u32 num_pasid_bits;
unsigned int num_ids;
@@ -629,12 +630,12 @@ static inline void dev_iommu_fwspec_set(struct device *dev,

static inline void *dev_iommu_priv_get(struct device *dev)
{
- return dev->iommu->fwspec->iommu_priv;
+ return dev->iommu->priv;
}

static inline void dev_iommu_priv_set(struct device *dev, void *priv)
{
- dev->iommu->fwspec->iommu_priv = priv;
+ dev->iommu->priv = priv;
}

int iommu_probe_device(struct device *dev);
--
2.17.1

2020-03-16 15:51:39

by Jean-Philippe Brucker

[permalink] [raw]
Subject: Re: [PATCH 09/15] iommu/arm-smmu-v3: Use accessor functions for iommu private data

On Tue, Mar 10, 2020 at 10:12:23AM +0100, Joerg Roedel wrote:
> From: Joerg Roedel <[email protected]>
>
> Make use of dev_iommu_priv_set/get() functions in the code.
>
> Tested-by: Hanjun Guo <[email protected]>
> Signed-off-by: Joerg Roedel <[email protected]>

Reviewed-by: Jean-Philippe Brucker <[email protected]>

> ---
> drivers/iommu/arm-smmu-v3.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index aa3ac2a03807..2b68498dfb66 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -2659,7 +2659,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
> if (!fwspec)
> return -ENOENT;
>
> - master = fwspec->iommu_priv;
> + master = dev_iommu_priv_get(dev);
> smmu = master->smmu;
>
> arm_smmu_detach_dev(master);
> @@ -2795,7 +2795,7 @@ static int arm_smmu_add_device(struct device *dev)
> if (!fwspec || fwspec->ops != &arm_smmu_ops)
> return -ENODEV;
>
> - if (WARN_ON_ONCE(fwspec->iommu_priv))
> + if (WARN_ON_ONCE(dev_iommu_priv_get(dev)))
> return -EBUSY;
>
> smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
> @@ -2810,7 +2810,7 @@ static int arm_smmu_add_device(struct device *dev)
> master->smmu = smmu;
> master->sids = fwspec->ids;
> master->num_sids = fwspec->num_ids;
> - fwspec->iommu_priv = master;
> + dev_iommu_priv_set(dev, master);
>
> /* Check the SIDs are in range of the SMMU and our stream table */
> for (i = 0; i < master->num_sids; i++) {
> @@ -2852,7 +2852,7 @@ static int arm_smmu_add_device(struct device *dev)
> iommu_device_unlink(&smmu->iommu, dev);
> err_free_master:
> kfree(master);
> - fwspec->iommu_priv = NULL;
> + dev_iommu_priv_set(dev, NULL);
> return ret;
> }
>
> @@ -2865,7 +2865,7 @@ static void arm_smmu_remove_device(struct device *dev)
> if (!fwspec || fwspec->ops != &arm_smmu_ops)
> return;
>
> - master = fwspec->iommu_priv;
> + master = dev_iommu_priv_get(dev);
> smmu = master->smmu;
> arm_smmu_detach_dev(master);
> iommu_group_remove_device(dev);
> --
> 2.17.1
>

2020-03-16 15:59:40

by Jean-Philippe Brucker

[permalink] [raw]
Subject: Re: [PATCH 15/15] iommu: Move fwspec->iommu_priv to struct dev_iommu

On Tue, Mar 10, 2020 at 10:12:29AM +0100, Joerg Roedel wrote:
> From: Joerg Roedel <[email protected]>
>
> Move the pointer for iommu private data from struct iommu_fwspec to
> struct dev_iommu.
>
> Tested-by: Will Deacon <[email protected]> # arm-smmu
> Signed-off-by: Joerg Roedel <[email protected]>

Reviewed-by: Jean-Philippe Brucker <[email protected]>

> ---
> include/linux/iommu.h | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 056900e75758..8c4d45fce042 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -369,6 +369,7 @@ struct iommu_fault_param {
> *
> * @fault_param: IOMMU detected device fault reporting data
> * @fwspec: IOMMU fwspec data
> + * @priv: IOMMU Driver private data
> *
> * TODO: migrate other per device data pointers under iommu_dev_data, e.g.
> * struct iommu_group *iommu_group;
> @@ -377,6 +378,7 @@ struct dev_iommu {
> struct mutex lock;
> struct iommu_fault_param *fault_param;
> struct iommu_fwspec *fwspec;
> + void *priv;
> };
>
> int iommu_device_register(struct iommu_device *iommu);
> @@ -589,7 +591,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev);
> struct iommu_fwspec {
> const struct iommu_ops *ops;
> struct fwnode_handle *iommu_fwnode;
> - void *iommu_priv;
> u32 flags;
> u32 num_pasid_bits;
> unsigned int num_ids;
> @@ -629,12 +630,12 @@ static inline void dev_iommu_fwspec_set(struct device *dev,
>
> static inline void *dev_iommu_priv_get(struct device *dev)
> {
> - return dev->iommu->fwspec->iommu_priv;
> + return dev->iommu->priv;
> }
>
> static inline void dev_iommu_priv_set(struct device *dev, void *priv)
> {
> - dev->iommu->fwspec->iommu_priv = priv;
> + dev->iommu->priv = priv;
> }
>
> int iommu_probe_device(struct device *dev);
> --
> 2.17.1
>