[PATCH v2 5/7] iommu: Mark dev_iommu_priv_set() with a lockdep

2023-12-07 Thread Jason Gunthorpe
tin Signed-off-by: Jason Gunthorpe --- drivers/iommu/amd/iommu.c | 2 -- drivers/iommu/apple-dart.c | 1 - drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 - drivers/iommu/arm/arm-smmu/arm-smmu.c | 1 - drivers/iommu/intel/iommu.c | 2 -- driv

[PATCH v2 0/7] IOMMU related FW parsing cleanup

2023-12-07 Thread Jason Gunthorpe
ant enough to argue. v1: https://lore.kernel.org/r/0-v1-720585788a7d+811b-iommu_fwspec_p1_...@nvidia.com Jason Gunthorpe (7): iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops() iommmu/of: Do not return struct iommu_ops from of_iommu_configure() iommu/of: Use -ENODEV co

[PATCH v2 1/7] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops()

2023-12-07 Thread Jason Gunthorpe
Snitselaar Reviewed-by: Lu Baolu Reviewed-by: Moritz Fischer Acked-by: Christoph Hellwig Acked-by: Rob Herring Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- arch/arc/mm/dma.c | 2 +- arch/arm/mm/dma-mapping-nommu.c | 2 +- arch/arm/mm/dma-mapping.c | 10

[PATCH v2 6/7] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id()

2023-12-07 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Acked-by: Rafael J. Wysocki Reviewed-by: Jerry Snitselaar Reviewed-by: Lu Baolu Reviewed-by: Moritz Fischer Tested-by: Hector Martin Signed-off-by: Jason

[PATCH v2 3/7] iommu/of: Use -ENODEV consistently in of_iommu_configure()

2023-12-07 Thread Jason Gunthorpe
led configure functions thought there was an iommu and we should try to probe it. Remove it. Reviewed-by: Jerry Snitselaar Reviewed-by: Moritz Fischer Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 49 1 file changed,

[PATCH v2 2/7] iommmu/of: Do not return struct iommu_ops from of_iommu_configure()

2023-12-07 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Reviewed-by: Jerry Snitselaar Reviewed-by: Lu Baolu Acked-by: Rob Herring Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c

[PATCH v2 4/7] iommu: Mark dev_iommu_get() with lockdep

2023-12-07 Thread Jason Gunthorpe
Allocation of dev->iommu must be done under the iommu_probe_device_lock. Mark this with lockdep to discourage future mistakes. Reviewed-by: Jerry Snitselaar Tested-by: Hector Martin Reviewed-by: Lu Baolu Reviewed-by: Moritz Fischer Signed-off-by: Jason Gunthorpe --- drivers/iommu/iomm

[PATCH v2 7/7] iommu/tegra: Use tegra_dev_iommu_get_stream_id() in the remaining places

2023-12-07 Thread Jason Gunthorpe
This API was defined to formalize the access to internal iommu details on some Tegra SOCs, but a few callers got missed. Add them. The helper already masks by 0x so remove this code from the callers. Suggested-by: Thierry Reding Reviewed-by: Thierry Reding Signed-off-by: Jason Gunthorpe

Re: [PATCH 10/10] ACPI: IORT: Allow COMPILE_TEST of IORT

2023-11-30 Thread Jason Gunthorpe
On Thu, Nov 30, 2023 at 02:10:48PM +, Robin Murphy wrote: > > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig > > index 7673bb82945b6c..309378e76a9bc9 100644 > > --- a/drivers/iommu/Kconfig > > +++ b/drivers/iommu/Kconfig > > @@ -318,6 +318,7 @@ config ARM_SMMU > > select

Re: [PATCH 10/10] ACPI: IORT: Allow COMPILE_TEST of IORT

2023-11-30 Thread Jason Gunthorpe
On Thu, Nov 30, 2023 at 12:12:26PM +0100, Lorenzo Pieralisi wrote: > On Wed, Nov 29, 2023 at 03:12:40PM -0400, Jason Gunthorpe wrote: > > On Wed, Nov 29, 2023 at 01:55:04PM +0100, Lorenzo Pieralisi wrote: > > > > > I don't think it should be done this way. Is the goal co

Re: [PATCH 08/10] iommu/tegra: Use tegra_dev_iommu_get_stream_id() in the remaining places

2023-11-29 Thread Jason Gunthorpe
On Wed, Nov 29, 2023 at 05:23:13PM +0100, Thierry Reding wrote: > > diff --git a/drivers/memory/tegra/tegra186.c > > b/drivers/memory/tegra/tegra186.c > > index 533f85a4b2bdb7..3e4fbe94dd666e 100644 > > --- a/drivers/memory/tegra/tegra186.c > > +++ b/drivers/memory/tegra/tegra186.c > > @@ -111,21

Re: [PATCH 10/10] ACPI: IORT: Allow COMPILE_TEST of IORT

2023-11-29 Thread Jason Gunthorpe
On Wed, Nov 29, 2023 at 01:55:04PM +0100, Lorenzo Pieralisi wrote: > I don't think it should be done this way. Is the goal compile testing > IORT code ? Yes > If so, why are we forcing it through the SMMU (only because > it can be compile tested while eg SMMUv3 driver can't ?) menu entry ?

Re: [PATCH 06/10] iommu: Replace iommu_device_lock with iommu_probe_device_lock

2023-11-29 Thread Jason Gunthorpe
On Wed, Nov 29, 2023 at 05:58:08PM +, Robin Murphy wrote: > On 29/11/2023 12:48 am, Jason Gunthorpe wrote: > > The iommu_device_lock protects the iommu_device_list which is only read by > > iommu_ops_from_fwnode(). > > > > This is now always called under the iom

[PATCH 03/10] iommu/of: Use -ENODEV consistently in of_iommu_configure()

2023-11-28 Thread Jason Gunthorpe
led configure functions thought there was an iommu and we should try to probe it. Remove it. Reviewed-by: Jerry Snitselaar Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 49 1 file changed, 15 insertions(+), 34 deleti

[PATCH 08/10] iommu/tegra: Use tegra_dev_iommu_get_stream_id() in the remaining places

2023-11-28 Thread Jason Gunthorpe
This API was defined to formalize the access to internal iommu details on some Tegra SOCs, but a few callers got missed. Add them. The helper already masks by 0x so remove this code from the callers. Suggested-by: Thierry Reding Signed-off-by: Jason Gunthorpe --- drivers/dma/tegra186-gpc

[PATCH 02/10] iommmu/of: Do not return struct iommu_ops from of_iommu_configure()

2023-11-28 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Reviewed-by: Jerry Snitselaar Acked-by: Rob Herring Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 31

[PATCH 01/10] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops()

2023-11-28 Thread Jason Gunthorpe
Snitselaar Reviewed-by: Lu Baolu Reviewed-by: Moritz Fischer Acked-by: Christoph Hellwig Acked-by: Rob Herring Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- arch/arc/mm/dma.c | 2 +- arch/arm/mm/dma-mapping-nommu.c | 2 +- arch/arm/mm/dma-mapping.c | 10

[PATCH 10/10] ACPI: IORT: Allow COMPILE_TEST of IORT

2023-11-28 Thread Jason Gunthorpe
The arm-smmu driver can COMPILE_TEST on x86, so expand this to also enable the IORT code so it can be COMPILE_TEST'd too. Signed-off-by: Jason Gunthorpe --- drivers/acpi/Kconfig| 2 -- drivers/acpi/Makefile | 2 +- drivers/acpi/arm64/Kconfig | 1 + drivers/acpi/arm64/Makefile | 2

[PATCH 04/10] iommu: Mark dev_iommu_get() with lockdep

2023-11-28 Thread Jason Gunthorpe
Allocation of dev->iommu must be done under the iommu_probe_device_lock. Mark this with lockdep to discourage future mistakes. Reviewed-by: Jerry Snitselaar Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --

[PATCH 06/10] iommu: Replace iommu_device_lock with iommu_probe_device_lock

2023-11-28 Thread Jason Gunthorpe
The iommu_device_lock protects the iommu_device_list which is only read by iommu_ops_from_fwnode(). This is now always called under the iommu_probe_device_lock, so we don't need to double lock the linked list. Use the iommu_probe_device_lock on the write side too. Signed-off-by: Jason Gunthorpe

[PATCH 05/10] iommu: Mark dev_iommu_priv_set() with a lockdep

2023-11-28 Thread Jason Gunthorpe
tin Signed-off-by: Jason Gunthorpe --- drivers/iommu/amd/iommu.c | 2 -- drivers/iommu/apple-dart.c | 1 - drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 - drivers/iommu/arm/arm-smmu/arm-smmu.c | 1 - drivers/iommu/intel/iommu.c | 2 -- driv

[PATCH 07/10] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id()

2023-11-28 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Acked-by: Rafael J. Wysocki Reviewed-by: Jerry Snitselaar Tested-by: Hector Martin Signed-off-by: Jason Gunthorpe --- drivers/acpi/scan.c | 29

[PATCH 09/10] ACPI: IORT: Cast from ULL to phys_addr_t

2023-11-28 Thread Jason Gunthorpe
= DMA_BIT_MASK(ncomp->memory_address_limit); Because DMA_BIT_MASK returns a large ULL constant. Explicitly truncate it to phys_addr_t. Signed-off-by: Jason Gunthorpe --- drivers/acpi/arm64/iort.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/arm64/iort.

[PATCH 00/10] IOMMU related FW parsing cleanup

2023-11-28 Thread Jason Gunthorpe
ed to call tegra_dev_iommu_get_stream_id() Jason Gunthorpe (10): iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops() iommmu/of: Do not return struct iommu_ops from of_iommu_configure() iommu/of: Use -ENODEV consistently in of_iommu_configure() iommu: Mark dev_iommu_get() with lockd

Re: [PATCH v2 00/17] Solve iommu probe races around iommu_fwspec

2023-11-21 Thread Jason Gunthorpe
On Tue, Nov 21, 2023 at 04:06:15PM +, Robin Murphy wrote: > > Obviously. I rejected that right away because of how incredibly > > wrongly layered and hacky it is to do something like that. > > What, and dressing up the fundamental layering violation by baking it even > further into the API

Re: [PATCH v2 06/17] iommu: Add iommu_fwspec_alloc/dealloc()

2023-11-21 Thread Jason Gunthorpe
On Tue, Nov 21, 2023 at 03:47:48PM +0900, Hector Martin wrote: > > Which is sensitive only to !NULL fwspec, and if EPROBE_DEFER is > > returned fwspec will be freed and dev->iommu->fwspec will be NULL > > here. > > > > In the NULL case it does a 'bus probe' with a NULL fwspec and all the > >

Re: [PATCH v2 06/17] iommu: Add iommu_fwspec_alloc/dealloc()

2023-11-19 Thread Jason Gunthorpe
On Sun, Nov 19, 2023 at 06:19:43PM +0900, Hector Martin wrote: > >> +static int iommu_fwspec_assign_iommu(struct iommu_fwspec *fwspec, > >> + struct device *dev, > >> + struct fwnode_handle *iommu_fwnode) > >> +{ > >> + const struct

Re: [PATCH v2 00/17] Solve iommu probe races around iommu_fwspec

2023-11-15 Thread Jason Gunthorpe
On Wed, Nov 15, 2023 at 08:23:54PM +, Robin Murphy wrote: > On 2023-11-15 3:36 pm, Jason Gunthorpe wrote: > > On Wed, Nov 15, 2023 at 03:22:09PM +, Robin Murphy wrote: > > > On 2023-11-15 2:05 pm, Jason Gunthorpe wrote: > > > > [Several people have teste

Re: [PATCH v2 00/17] Solve iommu probe races around iommu_fwspec

2023-11-15 Thread Jason Gunthorpe
On Wed, Nov 15, 2023 at 03:22:09PM +, Robin Murphy wrote: > On 2023-11-15 2:05 pm, Jason Gunthorpe wrote: > > [Several people have tested this now, so it is something that should sit in > > linux-next for a while] > > What's the aim here? This is obviously far, far too mu

[PATCH v2 11/17] iommu: Hold iommu_probe_device_lock while calling ops->of_xlate

2023-11-15 Thread Jason Gunthorpe
gt;probe observing a partially initialized fwspec. Reviewed-by: Jerry Snitselaar Reported-by: Zhenhua Huang Closes: https://lore.kernel.org/linux-arm-kernel/20231017163337.ge282...@ziepe.ca/T/#mee0d7bdc375541934a571ae69f43b9660f8e7312 Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c |

[PATCH v2 13/17] iommu: Remove dev_iommu_fwspec_set()

2023-11-15 Thread Jason Gunthorpe
This is only used internally to iommu.c now, get rid of it to discourage things outside iommu.c from trying to manipulate dev->iommu->fwspec. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 2 +- include/linux/iommu.h | 6 -- 2 files chan

[PATCH v2 12/17] iommu: Make iommu_ops_from_fwnode() static

2023-11-15 Thread Jason Gunthorpe
There are no external callers now. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 3 ++- include/linux/iommu.h | 7 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 5af98cad06f9ef..ea6aede326131e 100644

[PATCH v2 06/17] iommu: Add iommu_fwspec_alloc/dealloc()

2023-11-15 Thread Jason Gunthorpe
Allow fwspec to exist independently from the dev->iommu by providing functions to allow allocating and freeing the raw struct iommu_fwspec. Reflow the existing paths to call the new alloc/dealloc functions. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/iomm

[PATCH v2 00/17] Solve iommu probe races around iommu_fwspec

2023-11-15 Thread Jason Gunthorpe
ved logging v1: https://lore.kernel.org/r/0-v1-5f734af130a3+34f-iommu_fwspec_...@nvidia.com Jason Gunthorpe (17): iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops() iommmu/of: Do not return struct iommu_ops from of_iommu_configure() iommu/of: Use -ENODEV consistently in of_iommu_c

[PATCH v2 15/17] iommu: Add ops->of_xlate_fwspec()

2023-11-15 Thread Jason Gunthorpe
at all, and doesn't require the iommu_probe_device_lock. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 8 +--- drivers/iommu/iommu.c | 3 +++ drivers/iommu/

[PATCH v2 07/17] iommu: Add iommu_probe_device_fwspec()

2023-11-15 Thread Jason Gunthorpe
he bus. The lifecycle logic is a bit tortured because of how the existing driver code works. The new routine unconditionally takes ownership, even for failure. This could be simplified we can get rid of the remaining iommu_fwspec_init() callers someday. Reviewed-by: Jerry Snitselaar Signed-off-by:

[PATCH v2 03/17] iommu/of: Use -ENODEV consistently in of_iommu_configure()

2023-11-15 Thread Jason Gunthorpe
led configure functions thought there was an iommu and we should try to probe it. Remove it. Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 48 +--- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/io

[PATCH v2 05/17] iommu: Make iommu_fwspec->ids a distinct allocation

2023-11-15 Thread Jason Gunthorpe
ase optimization. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 20 include/linux/iommu.h | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f17a1113f3d

[PATCH v2 08/17] iommu/of: Do not use dev->iommu within of_iommu_configure()

2023-11-15 Thread Jason Gunthorpe
iewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c| 29 ++ drivers/iommu/of_iommu.c | 82 +--- include/linux/iommu.h| 3 ++ 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/drivers/iommu/iommu.c

[PATCH v2 14/17] iommu: Remove pointless iommu_fwspec_free()

2023-11-15 Thread Jason Gunthorpe
These days the core code will free the fwspec if probe fails, no reason for any driver to call this on a probe failure path. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 14 +- drivers/iommu/tegra-smmu.c| 1

[PATCH v2 17/17] iommu: Mark dev_iommu_priv_set() with a lockdep

2023-11-15 Thread Jason Gunthorpe
turned on because FSL_PAMU uses a global static for its priv and abuses priv for its domain. Remove the pointless stores of NULL, all these are on paths where the core code will free dev->iommu after the op returns. Reviewed-by: Lu Baolu Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Guntho

[PATCH v2 10/17] acpi: Do not use dev->iommu within acpi_iommu_configure()

2023-11-15 Thread Jason Gunthorpe
cher Signed-off-by: Jason Gunthorpe --- drivers/acpi/arm64/iort.c | 42 +- drivers/acpi/scan.c | 89 ++- drivers/acpi/viot.c | 45 +++- drivers/iommu/iommu.c | 5 +-- include/acpi/acpi_bus.h | 8 ++-- i

[PATCH v2 02/17] iommmu/of: Do not return struct iommu_ops from of_iommu_configure()

2023-11-15 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Reviewed-by: Jerry Snitselaar Acked-by: Rob Herring Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 31 +++ drivers

[PATCH v2 09/17] iommu: Add iommu_fwspec_append_ids()

2023-11-15 Thread Jason Gunthorpe
This is a version of iommu_fwspec_add_ids() that takes in the fwspec as an argument instead of getting it through dev->iommu. Reviewed-by: Jerry Snitselaar Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 17 +++-- include/linux/iommu.h | 1 + 2 files changed,

[PATCH v2 01/17] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops()

2023-11-15 Thread Jason Gunthorpe
Snitselaar Reviewed-by: Lu Baolu Reviewed-by: Moritz Fischer Acked-by: Christoph Hellwig Acked-by: Rob Herring Signed-off-by: Jason Gunthorpe --- arch/arc/mm/dma.c | 2 +- arch/arm/mm/dma-mapping-nommu.c | 2 +- arch/arm/mm/dma-mapping.c | 10 +- arch/arm64/mm/dma

[PATCH v2 04/17] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id()

2023-11-15 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Acked-by: Rafael J. Wysocki Signed-off-by: Jason Gunthorpe --- drivers/acpi/scan.c | 24 +++- 1 file changed, 15 insertions(+), 9 deletions

Re: [PATCH RFC 10/17] acpi: Do not use dev->iommu within acpi_iommu_configure()

2023-11-13 Thread Jason Gunthorpe
On Sun, Nov 12, 2023 at 09:44:18AM -0800, Moritz Fischer wrote: > On Fri, Nov 03, 2023 at 01:44:55PM -0300, Jason Gunthorpe wrote: > > This call chain is using dev->iommu->fwspec to pass around the fwspec > > between the three parts (acpi_iommu_configure(), a

Re: [PATCH RFC 00/17] Solve iommu probe races around iommu_fwspec

2023-11-08 Thread Jason Gunthorpe
On Wed, Nov 08, 2023 at 06:34:58PM +, André Draszik wrote: > For me, it's working fine so far on master, and I've also done my own back > port > to 6.1 and am currently testing both. An official back port once finalised > could be useful, though :-) Great, I'll post a non-RFC version next

Re: [PATCH RFC 02/17] of: Do not return struct iommu_ops from of_iommu_configure()

2023-11-05 Thread Jason Gunthorpe
On Fri, Nov 03, 2023 at 02:42:01PM -0700, Jerry Snitselaar wrote: > On Fri, Nov 03, 2023 at 01:44:47PM -0300, Jason Gunthorpe wrote: > > Nothing needs this pointer. Return a normal error code with the usual > > IOMMU semantic that ENODEV means 'there is no IOMMU driver'. >

Re: [PATCH RFC 03/17] of: Use -ENODEV consistently in of_iommu_configure()

2023-11-05 Thread Jason Gunthorpe
On Fri, Nov 03, 2023 at 03:03:53PM -0700, Jerry Snitselaar wrote: > With this the following can be simplified in of_iommu_configure_dev_id: > > diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c > index 4f77495a2543..b9b995712029 100644 > --- a/drivers/iommu/of_iommu.c > +++

Re: [PATCH RFC 04/17] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id()

2023-11-05 Thread Jason Gunthorpe
On Fri, Nov 03, 2023 at 05:48:01PM -0700, Jerry Snitselaar wrote: > > @@ -1632,10 +1633,15 @@ int acpi_dma_configure_id(struct device *dev, enum > > dev_dma_attr attr, > > > > acpi_arch_dma_setup(dev); > > > > - iommu = acpi_iommu_configure_id(dev, input_id); > > - if (PTR_ERR(iommu)

[PATCH RFC 17/17] iommu: Mark dev_iommu_priv_set() with a lockdep

2023-11-03 Thread Jason Gunthorpe
turned on because FSL_PAMU uses a global static for its priv and abuses priv for its domain. Remove the pointless stores of NULL, all these are on paths where the core code will free dev->iommu after the op returns. Signed-off-by: Jason Gunthorpe --- drivers/iommu/amd/iommu.c

[PATCH RFC 02/17] of: Do not return struct iommu_ops from of_iommu_configure()

2023-11-03 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 29 ++--- drivers/of/device.c | 22 +++--- include/linux

[PATCH RFC 10/17] acpi: Do not use dev->iommu within acpi_iommu_configure()

2023-11-03 Thread Jason Gunthorpe
the start of acpu_iommu_configure(), pass it through all functions on the stack to fill it with data, and finally pass it into iommu_probe_device_fwspec() which will load it into dev->iommu under a lock. Signed-off-by: Jason Gunthorpe --- drivers/acpi/arm64/iort.c | 39 -

[PATCH RFC 14/17] iommu: Remove pointless iommu_fwspec_free()

2023-11-03 Thread Jason Gunthorpe
These days the core code will free the fwspec if probe fails, no reason for any driver to call this on a probe failure path. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 14 +- drivers/iommu/tegra-smmu.c| 1 - 2 files changed, 5 insertions

[PATCH RFC 12/17] iommu: Make iommu_ops_from_fwnode() static

2023-11-03 Thread Jason Gunthorpe
There are no external callers now. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 3 ++- include/linux/iommu.h | 6 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 62c82a28cd5db3..becd1b881e62dc 100644

[PATCH RFC 15/17] iommu: Add ops->of_xlate_fwspec()

2023-11-03 Thread Jason Gunthorpe
at all, and doesn't require the iommu_probe_device_lock. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 8 +--- drivers/iommu/iommu.c | 3 +++ drivers/iommu/virtio-iommu.c

[PATCH RFC 05/17] iommu: Make iommu_fwspec->ids a distinct allocation

2023-11-03 Thread Jason Gunthorpe
ase optimization. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 20 include/linux/iommu.h | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c9a05bb49bfa17..d5e86985f6d363 100644 --- a/drivers/io

[PATCH RFC 00/17] Solve iommu probe races around iommu_fwspec

2023-11-03 Thread Jason Gunthorpe
he dev->iommu when it calls probe. This also removes all the touches of iommu_ops from the *_iommu_configure() paths and makes that mechanism private to the iommu core. A few more lockdep assertions are added to discourage future mis-use. This is on github: https://github.com/jgunthorpe/linux/commit

[PATCH RFC 09/17] iommu: Add iommu_fwspec_append_ids()

2023-11-03 Thread Jason Gunthorpe
This is a version of iommu_fwspec_add_ids() that takes in the fwspec as an argument instead of getting it through dev->iommu. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 17 +++-- include/linux/iommu.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) d

[PATCH RFC 11/17] iommu: Hold iommu_probe_device_lock while calling ops->of_xlate

2023-11-03 Thread Jason Gunthorpe
gt;probe observing a partially initialized fwspec. Reported-by: Zhenhua Huang Closes: https://lore.kernel.org/linux-arm-kernel/20231017163337.ge282...@ziepe.ca/T/#mee0d7bdc375541934a571ae69f43b9660f8e7312 Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 12 ++-- 1 file chan

[PATCH RFC 01/17] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops()

2023-11-03 Thread Jason Gunthorpe
This is not being used to pass ops, it is just a way to tell if an iommu driver was probed. These days this can be detected directly via device_iommu_mapped(). Call device_iommu_mapped() in the two places that need to check it and remove the iommu parameter everywhere. Signed-off-by: Jason

[PATCH RFC 03/17] of: Use -ENODEV consistently in of_iommu_configure()

2023-11-03 Thread Jason Gunthorpe
led configure functions thought there was an iommu and we should try to probe it. Remove it. Signed-off-by: Jason Gunthorpe --- drivers/iommu/of_iommu.c | 42 +--- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/io

[PATCH RFC 06/17] iommu: Add iommu_fwspec_alloc/dealloc()

2023-11-03 Thread Jason Gunthorpe
Allow fwspec to exist independently from the dev->iommu by providing functions to allow allocating and freeing the raw struct iommu_fwspec. Reflow the existing paths to call the new alloc/dealloc functions. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c |

[PATCH RFC 13/17] iommu: Remove dev_iommu_fwspec_set()

2023-11-03 Thread Jason Gunthorpe
This is only used internally to iommu.c now, get rid of it to discourage things outside iommu.c from trying to manipulate dev->iommu->fwspec. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 2 +- include/linux/iommu.h | 6 -- 2 files changed, 1 insertion(+), 7 deletions(-)

[PATCH RFC 07/17] iommu: Add iommu_probe_device_fwspec()

2023-11-03 Thread Jason Gunthorpe
he bus. The lifecycle logic is a bit tortured because of how the existing driver code works. The new routine unconditionally takes ownership, even for failure. This could be simplified we can get rid of the remaining iommu_fwspec_init() callers someday. Signed-off-by: Jason Gunthorpe --- drivers

[PATCH RFC 08/17] of: Do not use dev->iommu within of_iommu_configure()

2023-11-03 Thread Jason Gunthorpe
the start of of_iommu_configure(), pass it through all functions on the stack to fill it with data, and finally pass it into iommu_probe_device_fwspec() which will load it into dev->iommu under a lock. Move the actual call to ops->of_xlate into the core code under iommu_fwspec_of_xlate(). Signe

[PATCH RFC 16/17] iommu: Mark dev_iommu_get() with lockdep

2023-11-03 Thread Jason Gunthorpe
Allocation of dev->iommu must be done under the iommu_probe_device_lock. Mark this with lockdep to discourage future mistakes. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c in

[PATCH RFC 04/17] acpi: Do not return struct iommu_ops from acpi_iommu_configure_id()

2023-11-03 Thread Jason Gunthorpe
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Signed-off-by: Jason Gunthorpe --- drivers/acpi/scan.c | 24 +++- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/acpi