Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm: Factor out LDT init from context init

The arch-specific mm_context_t is a great place to put
protection-key allocation state.

But, we need to initialize the allocation state because pkey 0 is
always "allocated". All of the runtime initialization of
mm_context_t is done in *_ldt() manipulation functions. This
renames the existing LDT functions like this:

init_new_context() -> init_new_context_ldt()
destroy_context() -> destroy_context_ldt()

and makes init_new_context() and destroy_context() available for
generic use.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20160212210234.DB34FCC5@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Dave Hansen and committed by
Ingo Molnar
39a0526f 66d37570

+18 -7
+16 -5
arch/x86/include/asm/mmu_context.h
··· 52 52 /* 53 53 * Used for LDT copy/destruction. 54 54 */ 55 - int init_new_context(struct task_struct *tsk, struct mm_struct *mm); 56 - void destroy_context(struct mm_struct *mm); 55 + int init_new_context_ldt(struct task_struct *tsk, struct mm_struct *mm); 56 + void destroy_context_ldt(struct mm_struct *mm); 57 57 #else /* CONFIG_MODIFY_LDT_SYSCALL */ 58 - static inline int init_new_context(struct task_struct *tsk, 59 - struct mm_struct *mm) 58 + static inline int init_new_context_ldt(struct task_struct *tsk, 59 + struct mm_struct *mm) 60 60 { 61 61 return 0; 62 62 } 63 - static inline void destroy_context(struct mm_struct *mm) {} 63 + static inline void destroy_context_ldt(struct mm_struct *mm) {} 64 64 #endif 65 65 66 66 static inline void load_mm_ldt(struct mm_struct *mm) ··· 102 102 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK) 103 103 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY); 104 104 #endif 105 + } 106 + 107 + static inline int init_new_context(struct task_struct *tsk, 108 + struct mm_struct *mm) 109 + { 110 + init_new_context_ldt(tsk, mm); 111 + return 0; 112 + } 113 + static inline void destroy_context(struct mm_struct *mm) 114 + { 115 + destroy_context_ldt(mm); 105 116 } 106 117 107 118 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
+2 -2
arch/x86/kernel/ldt.c
··· 103 103 * we do not have to muck with descriptors here, that is 104 104 * done in switch_mm() as needed. 105 105 */ 106 - int init_new_context(struct task_struct *tsk, struct mm_struct *mm) 106 + int init_new_context_ldt(struct task_struct *tsk, struct mm_struct *mm) 107 107 { 108 108 struct ldt_struct *new_ldt; 109 109 struct mm_struct *old_mm; ··· 144 144 * 145 145 * 64bit: Don't touch the LDT register - we're already in the next thread. 146 146 */ 147 - void destroy_context(struct mm_struct *mm) 147 + void destroy_context_ldt(struct mm_struct *mm) 148 148 { 149 149 free_ldt_struct(mm->context.ldt); 150 150 mm->context.ldt = NULL;