Re: linux-next: manual merge of the tip tree with the iommu tree

From: Stephen Rothwell
Date: Mon Apr 03 2023 - 01:12:01 EST


Hi all,

On Mon, 3 Apr 2023 14:36:42 +1000 Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx> wrote:
>
> Today's linux-next merge of the tip tree got conflicts in:
>
> drivers/iommu/iommu-sva.c
> include/linux/sched/mm.h
> include/linux/ioasid.h
>
> between commits:
>
> cd3891158a77 ("iommu/sva: Move PASID helpers to sva code")
> 4e14176ab13f ("iommu/sva: Stop using ioasid_set for SVA")
> 1a14bf0fc7ed ("iommu/sva: Use GFP_KERNEL for pasid allocation")
>
> from the iommu tree and commit:
>
> 400b9b93441c ("iommu/sva: Replace pasid_valid() helper with mm_valid_pasid()")
>
> from the tip tree.
>
> I fixed it up (I used the former version of include/linux/sched/mm.h,
> removed include/linux/ioasid.h, updated drivers/iommu/iommu-sva.c
> as below and applied the following patch) and can carry the fix as
> necessary. This is now fixed as far as linux-next is concerned, but any
> non trivial conflicts should be mentioned to your upstream maintainer
> when your tree is submitted for merging. You may also want to consider
> cooperating with the maintainer of the conflicting tree to minimise any
> particularly complex conflicts.
>
> From: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
> Date: Mon, 3 Apr 2023 14:32:58 +1000
> Subject: [PATCH] fixup for "iommu/sva: Replace pasid_valid() helper with mm_valid_pasid()"
>
> interacting with "iommu/sva: Replace pasid_valid() helper with
> mm_valid_pasid()" and "iommu: Remove ioasid infrastructure"
>
> Signed-off-by: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
> ---
> include/linux/iommu.h | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 54f535ff9868..0c5d4c3b59cd 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -1172,16 +1172,15 @@ static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream
> return false;
> }
>
> -static inline bool pasid_valid(ioasid_t ioasid)
> -{
> - return ioasid != IOMMU_PASID_INVALID;
> -}
> -
> #ifdef CONFIG_IOMMU_SVA
> static inline void mm_pasid_init(struct mm_struct *mm)
> {
> mm->pasid = IOMMU_PASID_INVALID;
> }
> +static inline bool mm_valid_pasid(struct mm_struct *mm)
> +{
> + return mm->pasid != IOMMU_PASID_INVALID;
> +}
> void mm_pasid_drop(struct mm_struct *mm);
> struct iommu_sva *iommu_sva_bind_device(struct device *dev,
> struct mm_struct *mm);
> @@ -1203,6 +1202,7 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle)
> return IOMMU_PASID_INVALID;
> }
> static inline void mm_pasid_init(struct mm_struct *mm) {}
> +static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; }
> static inline void mm_pasid_drop(struct mm_struct *mm) {}
> #endif /* CONFIG_IOMMU_SVA */
>
> --
> 2.39.2
>
> --
> Cheers,
> Stephen Rothwell
>
> diff --cc drivers/iommu/iommu-sva.c
> index c434b95dc8eb,dd76a1a09cf7..000000000000
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c
> @@@ -9,14 -10,26 +10,14 @@@
> #include "iommu-sva.h"
>
> static DEFINE_MUTEX(iommu_sva_lock);
> -static DECLARE_IOASID_SET(iommu_sva_pasid);
> +static DEFINE_IDA(iommu_global_pasid_ida);
>
> -/**
> - * iommu_sva_alloc_pasid - Allocate a PASID for the mm
> - * @mm: the mm
> - * @min: minimum PASID value (inclusive)
> - * @max: maximum PASID value (inclusive)
> - *
> - * Try to allocate a PASID for this mm, or take a reference to the existing one
> - * provided it fits within the [@min, @max] range. On success the PASID is
> - * available in mm->pasid and will be available for the lifetime of the mm.
> - *
> - * Returns 0 on success and < 0 on error.
> - */
> -int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
> +/* Allocate a PASID for the mm within range (inclusive) */
> +static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max)
> {
> int ret = 0;
> - ioasid_t pasid;
>
> - if (!pasid_valid(min) || !pasid_valid(max) ||
> - if (min == INVALID_IOASID || max == INVALID_IOASID ||
> ++ if (min == IOMMU_PASID_INVALID || max == IOMMU_PASID_INVALID ||
> min == 0 || max < min)
> return -EINVAL;
>
> @@@ -205,11 -242,3 +209,11 @@@ out_put_mm
>
> return status;
> }
> +
> +void mm_pasid_drop(struct mm_struct *mm)
> +{
> - if (likely(!pasid_valid(mm->pasid)))
> ++ if (likely(!mm_valid_pasid(mm)))
> + return;
> +
> + ida_free(&iommu_global_pasid_ida, mm->pasid);
> +}

It also needs this:

From: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
Date: Mon, 3 Apr 2023 14:58:05 +1000
Subject: [PATCH] extra fixup for "iommu/sva: Replace pasid_valid() helper with mm_valid_pasid()"

interacting with "iommu/sva: Replace pasid_valid() helper with
mm_valid_pasid()" and "iommu: Remove ioasid infrastructure"

Signed-off-by: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
---
arch/x86/kernel/process_64.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 74c7e84a94d8..3bcbc165c5bb 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -39,6 +39,7 @@
#include <linux/io.h>
#include <linux/ftrace.h>
#include <linux/syscalls.h>
+#include <linux/iommu.h>

#include <asm/processor.h>
#include <asm/pkru.h>
--
2.39.2

--
Cheers,
Stephen Rothwell

Attachment: pgpg2AuzjrHnI.pgp
Description: OpenPGP digital signature