Skip to content

Commit 5ef495e

Browse files
kirylhansendc
authored andcommitted
x86: Allow atomic MM_CONTEXT flags setting
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
1 parent b19b74b commit 5ef495e

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

arch/x86/entry/vsyscall/vsyscall_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static struct vm_area_struct gate_vma __ro_after_init = {
317317
struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
318318
{
319319
#ifdef CONFIG_COMPAT
320-
if (!mm || !(mm->context.flags & MM_CONTEXT_HAS_VSYSCALL))
320+
if (!mm || !test_bit(MM_CONTEXT_HAS_VSYSCALL, &mm->context.flags))
321321
return NULL;
322322
#endif
323323
if (vsyscall_mode == NONE)

arch/x86/include/asm/mmu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <linux/bits.h>
1010

1111
/* Uprobes on this MM assume 32-bit code */
12-
#define MM_CONTEXT_UPROBE_IA32 BIT(0)
12+
#define MM_CONTEXT_UPROBE_IA32 0
1313
/* vsyscall page is accessible on this MM */
14-
#define MM_CONTEXT_HAS_VSYSCALL BIT(1)
14+
#define MM_CONTEXT_HAS_VSYSCALL 1
1515

1616
/*
1717
* x86 has arch-specific MMU state beyond what lives in mm_struct.
@@ -39,7 +39,7 @@ typedef struct {
3939
#endif
4040

4141
#ifdef CONFIG_X86_64
42-
unsigned short flags;
42+
unsigned long flags;
4343
#endif
4444

4545
struct mutex lock;

arch/x86/include/asm/mmu_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static inline void arch_exit_mmap(struct mm_struct *mm)
182182
static inline bool is_64bit_mm(struct mm_struct *mm)
183183
{
184184
return !IS_ENABLED(CONFIG_IA32_EMULATION) ||
185-
!(mm->context.flags & MM_CONTEXT_UPROBE_IA32);
185+
!test_bit(MM_CONTEXT_UPROBE_IA32, &mm->context.flags);
186186
}
187187
#else
188188
static inline bool is_64bit_mm(struct mm_struct *mm)

arch/x86/kernel/process_64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void set_personality_64bit(void)
671671
task_pt_regs(current)->orig_ax = __NR_execve;
672672
current_thread_info()->status &= ~TS_COMPAT;
673673
if (current->mm)
674-
current->mm->context.flags = MM_CONTEXT_HAS_VSYSCALL;
674+
__set_bit(MM_CONTEXT_HAS_VSYSCALL, &current->mm->context.flags);
675675

676676
/* TBD: overwrites user setup. Should have two bits.
677677
But 64bit processes have always behaved this way,
@@ -708,7 +708,7 @@ static void __set_personality_ia32(void)
708708
* uprobes applied to this MM need to know this and
709709
* cannot use user_64bit_mode() at that time.
710710
*/
711-
current->mm->context.flags = MM_CONTEXT_UPROBE_IA32;
711+
__set_bit(MM_CONTEXT_UPROBE_IA32, &current->mm->context.flags);
712712
}
713713

714714
current->personality |= force_personality32;

0 commit comments

Comments
 (0)