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 tested this now, so it is something that s

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

2023-11-15 Thread Robin Murphy
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 tested this now, so it is something that should sit in linux-next for a while] What's the aim here? This is obviously

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 much for a > stable fix,

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

2023-11-15 Thread Robin Murphy
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 much for a stable fix, but then it's also not the refactoring we want for the future either, si

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

2023-11-15 Thread Jason Gunthorpe
This resolves the race around touching dev->iommu while generating the OF fwspec on the of_iommu_configure() flow: CPU0 CPU1 of_iommu_configure()iommu_device_register() .. bus_iommu_probe() iommu_fwspec_o

[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 changed, 1 inser

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

2023-11-15 Thread Jerry Snitselaar
Reviewed-by: Jerry Snitselaar ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc

[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 --- a/d

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

2023-11-15 Thread Jerry Snitselaar
Did patch 12 v2 get sent? I'm not seeing it locally, nor in lore, and b4 doesn't find it when pulling then thread. Regards, Jerry ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps

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

2023-11-15 Thread Jerry Snitselaar
Reviewed-by: Jerry Snitselaar ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc

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

2023-11-15 Thread Jerry Snitselaar
Reviewed-by: Jerry Snitselaar ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc

[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/iommu.c

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

2023-11-15 Thread Jason Gunthorpe
[Several people have tested this now, so it is something that should sit in linux-next for a while] The iommu subsystem uses dev->iommu to store bits of information about the attached iommu driver. This has been co-opted by the ACPI/OF code to also be a place to pass around the iommu_fwspec before

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

2023-11-15 Thread Jason Gunthorpe
The new callback takes in the fwspec instead of retrieving it from the dev->iommu. Provide iommu_fwspec_append_ids() to work directly on the fwspec. Convert SMMU, SMMUv3, and virtio to use iommu_fwspec_append_ids() and the new entry point. This avoids having to touch dev->iommu at all, and doesn'

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

2023-11-15 Thread Jason Gunthorpe
Instead of obtaining an iommu_fwspec from dev->iommu allow a caller allocated fwspec to be passed into the probe logic. To keep the driver ops APIs the same the fwspec is stored in dev->iommu under the iommu_probe_device_lock. If a fwspec is available use it to provide the ops instead of the bus.

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

2023-11-15 Thread Jason Gunthorpe
Instead of returning 1 and trying to handle positive error codes just stick to the convention of returning -ENODEV. Remove references to ops from of_iommu_configure(), a NULL ops will already generate an error code. There is no reason to check dev->bus, if err=0 at this point then the called confi

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

2023-11-15 Thread Jason Gunthorpe
The optimization of kreallocing the entire fwspec only works if the fwspec pointer is always stored in the dev->iommu. Since we want to change this remove the optimization and make the ids array a distinct allocation. Allow a single id to be stored inside the iommu_fwspec as a common case optimiza

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

2023-11-15 Thread Jason Gunthorpe
This call chain is using dev->iommu->fwspec to pass around the fwspec between the three parts (of_iommu_configure(), of_iommu_xlate(), iommu_probe_device()). However there is no locking around the accesses to dev->iommu, so this is all racy. Allocate a clean, local, fwspec at the start of of_iomm

[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
A perfect driver would only call dev_iommu_priv_set() from its probe callback. We've made it functionally correct to call it from the of_xlate by adding a lock around that call. lockdep assert that iommu_probe_device_lock is held to discourage misuse. Exclude PPC kernels with CONFIG_FSL_PAMU turn

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

2023-11-15 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 Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/iommu.c b/dri

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

2023-11-15 Thread Jason Gunthorpe
This call chain is using dev->iommu->fwspec to pass around the fwspec between the three parts (acpi_iommu_configure_id(), acpi_iommu_fwspec_init(), iommu_probe_device()). However there is no locking around the accesses to dev->iommu, so this is all racy. Allocate a clean, local, fwspec at the sta

[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/of/de

[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, 12 insertio

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

2023-11-15 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. Reviewed-by: Jerry Snitselaa

[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(-)

[PATCH 2/2] Hexagon: Make pfn accessors statics inlines

2023-11-15 Thread Linus Walleij
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long)

[PATCH 0/2] arch: Virt to phys to static inlines

2023-11-15 Thread Linus Walleij
/asm/page.h | 15 +-- 3 files changed, 26 insertions(+), 12 deletions(-) --- base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86 change-id: 20231115-virt-to-phy-arch-tree-137bc87046e1 Best regards, -- Linus Walleij ___ linux-snps-arc

[PATCH 1/2] ARC: mm: Make virt_to_pfn() a static inline

2023-11-15 Thread Linus Walleij
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long)