iommu: Change kconfig around IOMMU_SVA
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 27 Oct 2023 00:05:20 +0000 (08:05 +0800)
committerJoerg Roedel <jroedel@suse.de>
Tue, 12 Dec 2023 09:11:27 +0000 (10:11 +0100)
Linus suggested that the kconfig here is confusing:

https://lore.kernel.org/all/CAHk-=wgUiAtiszwseM1p2fCJ+sC4XWQ+YN4TanFhUgvUqjr9Xw@mail.gmail.com/

Let's break it into three kconfigs controlling distinct things:

 - CONFIG_IOMMU_MM_DATA controls if the mm_struct has the additional
   fields for the IOMMU. Currently only PASID, but later patches store
   a struct iommu_mm_data *

 - CONFIG_ARCH_HAS_CPU_PASID controls if the arch needs the scheduling bit
   for keeping track of the ENQCMD instruction. x86 will select this if
   IOMMU_SVA is enabled

 - IOMMU_SVA controls if the IOMMU core compiles in the SVA support code
   for iommu driver use and the IOMMU exported API

This way ARM will not enable CONFIG_ARCH_HAS_CPU_PASID

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20231027000525.1278806-2-tina.zhang@intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
arch/Kconfig
arch/x86/Kconfig
arch/x86/kernel/traps.c
drivers/iommu/Kconfig
include/linux/iommu.h
include/linux/mm_types.h
include/linux/sched.h
kernel/fork.c
mm/Kconfig
mm/init-mm.c

index f4b210ab06129120bdddd0e937960c4c507db30d..3e49f862670e38463f1dc44496855bb0d8753479 100644 (file)
@@ -301,6 +301,11 @@ config ARCH_HAS_DMA_CLEAR_UNCACHED
 config ARCH_HAS_CPU_FINALIZE_INIT
        bool
 
+# The architecture has a per-task state that includes the mm's PASID
+config ARCH_HAS_CPU_PASID
+       bool
+       select IOMMU_MM_DATA
+
 # Select if arch init_task must go in the __init_task_data section
 config ARCH_TASK_STRUCT_ON_STACK
        bool
index 3762f41bb092971e3f6180f057b49742014e5f11..68a2ec36a46ec6b91fa072bc83e75e48c044a89c 100644 (file)
@@ -71,6 +71,7 @@ config X86
        select ARCH_HAS_CACHE_LINE_SIZE
        select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
        select ARCH_HAS_CPU_FINALIZE_INIT
+       select ARCH_HAS_CPU_PASID               if IOMMU_SVA
        select ARCH_HAS_CURRENT_STACK_POINTER
        select ARCH_HAS_DEBUG_VIRTUAL
        select ARCH_HAS_DEBUG_VM_PGTABLE        if !X86_PAE
index c876f1d36a81a7518214c3215ae08830d47e55f5..2b62dbb3396add5eb1ba1b6cab15121d870e96a1 100644 (file)
@@ -565,7 +565,7 @@ static bool fixup_iopl_exception(struct pt_regs *regs)
  */
 static bool try_fixup_enqcmd_gp(void)
 {
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_ARCH_HAS_CPU_PASID
        u32 pasid;
 
        /*
index 7673bb82945b6cbf08ee1d4d44c196dc46875c5a..9a29d742617e3d34e3c9a28d25857230b06d2a68 100644 (file)
@@ -160,6 +160,7 @@ config IOMMU_DMA
 
 # Shared Virtual Addressing
 config IOMMU_SVA
+       select IOMMU_MM_DATA
        bool
 
 config FSL_PAMU
index c7394b39599c8482de4ef07c49a4c184303da869..cd3f398095bf3d1412d13e0eadc33305663edeb2 100644 (file)
@@ -1337,7 +1337,7 @@ static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream
        return false;
 }
 
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_IOMMU_MM_DATA
 static inline void mm_pasid_init(struct mm_struct *mm)
 {
        mm->pasid = IOMMU_PASID_INVALID;
index 957ce38768b2a88d754112e72f923f7947ab0854..41f248608dd98b7e82275492a1af77be467f9110 100644 (file)
@@ -938,7 +938,7 @@ struct mm_struct {
 #endif
                struct work_struct async_put_work;
 
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_IOMMU_MM_DATA
                u32 pasid;
 #endif
 #ifdef CONFIG_KSM
index 292c316972485dae579a2518b4a2b847d35b961c..70888a36677b60ce7205e877d68076d65c14b183 100644 (file)
@@ -954,7 +954,7 @@ struct task_struct {
        /* Recursion prevention for eventfd_signal() */
        unsigned                        in_eventfd:1;
 #endif
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_ARCH_HAS_CPU_PASID
        unsigned                        pasid_activated:1;
 #endif
 #ifdef CONFIG_CPU_SUP_INTEL
index 10917c3e1f0366b5fbf60d98c2042c636cd74c87..43fd9bc1a5224794ea8b0d7f45d3eab12480fffc 100644 (file)
@@ -1179,7 +1179,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
        tsk->use_memdelay = 0;
 #endif
 
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_ARCH_HAS_CPU_PASID
        tsk->pasid_activated = 0;
 #endif
 
index 89971a894b6058fd7b908c0e8ffa216cbdc887dd..0143f4d905c9656c627537ec7755fe170cf9337b 100644 (file)
@@ -1270,6 +1270,9 @@ config LOCK_MM_AND_FIND_VMA
        bool
        depends on !STACK_GROWSUP
 
+config IOMMU_MM_DATA
+       bool
+
 source "mm/damon/Kconfig"
 
 endmenu
index cfd367822cdd2ebe94181c118c1d14b73cc4b5e8..c52dc2740a3de2e52a65328484864f04f11da407 100644 (file)
@@ -44,7 +44,7 @@ struct mm_struct init_mm = {
 #endif
        .user_ns        = &init_user_ns,
        .cpu_bitmap     = CPU_BITS_NONE,
-#ifdef CONFIG_IOMMU_SVA
+#ifdef CONFIG_IOMMU_MM_DATA
        .pasid          = IOMMU_PASID_INVALID,
 #endif
        INIT_MM_CONTEXT(init_mm)