Skip to content

Commit 22c4bd9

Browse files
amlutoIngo Molnar
authored andcommitted
x86: Add a comment clarifying LDT context switching
The code is correct, but only for a rather subtle reason. This confused me for quite a while when I read switch_mm, so clarify the code to avoid confusing other people, too. TBH, I wouldn't be surprised if this code was only correct by accident. Signed-off-by: Andy Lutomirski <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Kees Cook <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Vince Weaver <[email protected]> Cc: "hillf.zj" <[email protected]> Cc: Valdis Kletnieks <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Linus Torvalds <[email protected]> Link: http://lkml.kernel.org/r/0db86397f968996fb772c443c251415b0b430ddd.1414190806.git.luto@amacapital.net Signed-off-by: Ingo Molnar <[email protected]>
1 parent 1e02ce4 commit 22c4bd9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

arch/x86/include/asm/mmu_context.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
5555
/*
5656
* Load the LDT, if the LDT is different.
5757
*
58-
* It's possible leave_mm(prev) has been called. If so,
59-
* then prev->context.ldt could be out of sync with the
60-
* LDT descriptor or the LDT register. This can only happen
61-
* if prev->context.ldt is non-null, since we never free
62-
* an LDT. But LDTs can't be shared across mms, so
63-
* prev->context.ldt won't be equal to next->context.ldt.
58+
* It's possible that prev->context.ldt doesn't match
59+
* the LDT register. This can happen if leave_mm(prev)
60+
* was called and then modify_ldt changed
61+
* prev->context.ldt but suppressed an IPI to this CPU.
62+
* In this case, prev->context.ldt != NULL, because we
63+
* never free an LDT while the mm still exists. That
64+
* means that next->context.ldt != prev->context.ldt,
65+
* because mms never share an LDT.
6466
*/
6567
if (unlikely(prev->context.ldt != next->context.ldt))
6668
load_LDT_nolock(&next->context);

0 commit comments

Comments
 (0)