Merge tag 'wberr-v4.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton...
[sfrench/cifs-2.6.git] / arch / x86 / kernel / ldt.c
index a870910c85658af0379d5dea041d687547078663..f0e64db18ac83db5f45e6bb7f531e1536d11522a 100644 (file)
 #include <asm/mmu_context.h>
 #include <asm/syscalls.h>
 
+static void refresh_ldt_segments(void)
+{
+#ifdef CONFIG_X86_64
+       unsigned short sel;
+
+       /*
+        * Make sure that the cached DS and ES descriptors match the updated
+        * LDT.
+        */
+       savesegment(ds, sel);
+       if ((sel & SEGMENT_TI_MASK) == SEGMENT_LDT)
+               loadsegment(ds, sel);
+
+       savesegment(es, sel);
+       if ((sel & SEGMENT_TI_MASK) == SEGMENT_LDT)
+               loadsegment(es, sel);
+#endif
+}
+
 /* context.lock is held for us, so we don't need any locking. */
 static void flush_ldt(void *__mm)
 {
@@ -32,6 +51,8 @@ static void flush_ldt(void *__mm)
 
        pc = &mm->context;
        set_ldt(pc->ldt->entries, pc->ldt->nr_entries);
+
+       refresh_ldt_segments();
 }
 
 /* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */