x86: Allow atomic MM_CONTEXT flags setting
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Sun, 12 Mar 2023 11:25:57 +0000 (14:25 +0300)
committerDave Hansen <dave.hansen@linux.intel.com>
Thu, 16 Mar 2023 20:08:39 +0000 (13:08 -0700)
So far there's no need in atomic setting of MM context flags in
mm_context_t::flags. The flags set early in exec and never change
after that.

LAM enabling requires atomic flag setting. The upcoming flag
MM_CONTEXT_FORCE_TAGGED_SVA can be set much later in the process
lifetime where multiple threads exist.

Convert the field to unsigned long and do MM_CONTEXT_* accesses with
__set_bit() and test_bit().

No functional changes.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Alexander Potapenko <glider@google.com>
Link: https://lore.kernel.org/all/20230312112612.31869-3-kirill.shutemov%40linux.intel.com
arch/x86/entry/vsyscall/vsyscall_64.c
arch/x86/include/asm/mmu.h
arch/x86/include/asm/mmu_context.h
arch/x86/kernel/process_64.c

index d234ca7..e0ca812 100644 (file)
@@ -317,7 +317,7 @@ static struct vm_area_struct gate_vma __ro_after_init = {
 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
 {
 #ifdef CONFIG_COMPAT
-       if (!mm || !(mm->context.flags & MM_CONTEXT_HAS_VSYSCALL))
+       if (!mm || !test_bit(MM_CONTEXT_HAS_VSYSCALL, &mm->context.flags))
                return NULL;
 #endif
        if (vsyscall_mode == NONE)
index 5d74946..efa3eae 100644 (file)
@@ -9,9 +9,9 @@
 #include <linux/bits.h>
 
 /* Uprobes on this MM assume 32-bit code */
-#define MM_CONTEXT_UPROBE_IA32 BIT(0)
+#define MM_CONTEXT_UPROBE_IA32         0
 /* vsyscall page is accessible on this MM */
-#define MM_CONTEXT_HAS_VSYSCALL        BIT(1)
+#define MM_CONTEXT_HAS_VSYSCALL                1
 
 /*
  * x86 has arch-specific MMU state beyond what lives in mm_struct.
@@ -39,7 +39,7 @@ typedef struct {
 #endif
 
 #ifdef CONFIG_X86_64
-       unsigned short flags;
+       unsigned long flags;
 #endif
 
        struct mutex lock;
index e01aa74..b4e4a0c 100644 (file)
@@ -182,7 +182,7 @@ static inline void arch_exit_mmap(struct mm_struct *mm)
 static inline bool is_64bit_mm(struct mm_struct *mm)
 {
        return  !IS_ENABLED(CONFIG_IA32_EMULATION) ||
-               !(mm->context.flags & MM_CONTEXT_UPROBE_IA32);
+               !test_bit(MM_CONTEXT_UPROBE_IA32, &mm->context.flags);
 }
 #else
 static inline bool is_64bit_mm(struct mm_struct *mm)
index bb65a68..cd34bcf 100644 (file)
@@ -671,7 +671,7 @@ void set_personality_64bit(void)
        task_pt_regs(current)->orig_ax = __NR_execve;
        current_thread_info()->status &= ~TS_COMPAT;
        if (current->mm)
-               current->mm->context.flags = MM_CONTEXT_HAS_VSYSCALL;
+               __set_bit(MM_CONTEXT_HAS_VSYSCALL, &current->mm->context.flags);
 
        /* TBD: overwrites user setup. Should have two bits.
           But 64bit processes have always behaved this way,
@@ -708,7 +708,7 @@ static void __set_personality_ia32(void)
                 * uprobes applied to this MM need to know this and
                 * cannot use user_64bit_mode() at that time.
                 */
-               current->mm->context.flags = MM_CONTEXT_UPROBE_IA32;
+               __set_bit(MM_CONTEXT_UPROBE_IA32, &current->mm->context.flags);
        }
 
        current->personality |= force_personality32;