_set_tssldt_desc() is used to set LDT or TSS descriptors in the GDT.
As LDT descriptors might be shared across cpus care is taken to not
create a temporary invalid descriptor.

Split _set_tssldt_desc() into dedicated functions for setting either
a LDT or a TSS descriptor. For LDT descriptors this is basically the
same as today, while TSS descriptors can be written without using
barriers as those are written for the local cpu only.

Signed-off-by: Juergen Gross <jgr...@suse.com>
---
V3:
- new patch
---
 xen/arch/x86/cpu/common.c  |  4 ++--
 xen/arch/x86/traps.c       |  4 ++--
 xen/include/asm-x86/desc.h | 14 +++++++++++++-
 xen/include/asm-x86/ldt.h  |  2 +-
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 4306e59650..e0ae8120a6 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -755,12 +755,12 @@ void load_system_tables(void)
                .bitmap = IOBMP_INVALID_OFFSET,
        };
 
-       _set_tssldt_desc(
+       _set_tss_desc(
                gdt + TSS_ENTRY,
                (unsigned long)tss,
                offsetof(struct tss_struct, __cacheline_filler) - 1,
                SYS_DESC_tss_avail);
-       _set_tssldt_desc(
+       _set_tss_desc(
                compat_gdt + TSS_ENTRY,
                (unsigned long)tss,
                offsetof(struct tss_struct, __cacheline_filler) - 1,
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 13a852ca4e..9b29014e2c 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -1845,12 +1845,12 @@ void load_TR(void)
         .limit = LAST_RESERVED_GDT_BYTE
     };
 
-    _set_tssldt_desc(
+    _set_tss_desc(
         this_cpu(gdt_table) + TSS_ENTRY - FIRST_RESERVED_GDT_ENTRY,
         (unsigned long)tss,
         offsetof(struct tss_struct, __cacheline_filler) - 1,
         SYS_DESC_tss_avail);
-    _set_tssldt_desc(
+    _set_tss_desc(
         this_cpu(compat_gdt_table) + TSS_ENTRY - FIRST_RESERVED_GDT_ENTRY,
         (unsigned long)tss,
         offsetof(struct tss_struct, __cacheline_filler) - 1,
diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h
index 4093c65faa..6ec515582d 100644
--- a/xen/include/asm-x86/desc.h
+++ b/xen/include/asm-x86/desc.h
@@ -171,7 +171,7 @@ static inline void _update_gate_addr_lower(idt_entry_t 
*gate, void *addr)
     _write_gate_lower(gate, &idte);
 }
 
-#define _set_tssldt_desc(desc,addr,limit,type)           \
+#define _set_ldt_desc(desc,addr,limit,type)              \
 do {                                                     \
     (desc)[0].b = (desc)[1].b = 0;                       \
     smp_wmb(); /* disable entry /then/ rewrite */        \
@@ -185,6 +185,18 @@ do {                                                     \
         (((u32)(addr) & 0x00FF0000U) >> 16);             \
 } while (0)
 
+#define _set_tss_desc(desc,addr,limit,type)              \
+do {                                                     \
+    (desc)[0].a =                                        \
+        ((u32)(addr) << 16) | ((u32)(limit) & 0xFFFF);   \
+    (desc)[0].b =                                        \
+        ((u32)(addr) & 0xFF000000U) |                    \
+        ((u32)(type) << 8) | 0x8000U |                   \
+        (((u32)(addr) & 0x00FF0000U) >> 16);             \
+    (desc)[1].a = (u32)(((unsigned long)(addr)) >> 32);  \
+    (desc)[1].b = 0;                                     \
+} while (0)
+
 struct __packed desc_ptr {
        unsigned short limit;
        unsigned long base;
diff --git a/xen/include/asm-x86/ldt.h b/xen/include/asm-x86/ldt.h
index 589daf83c6..6179cef9e9 100644
--- a/xen/include/asm-x86/ldt.h
+++ b/xen/include/asm-x86/ldt.h
@@ -16,7 +16,7 @@ static inline void load_LDT(struct vcpu *v)
         desc = (!is_pv_32bit_vcpu(v)
                 ? this_cpu(gdt_table) : this_cpu(compat_gdt_table))
                + LDT_ENTRY - FIRST_RESERVED_GDT_ENTRY;
-        _set_tssldt_desc(desc, LDT_VIRT_START(v), ents*8-1, SYS_DESC_ldt);
+        _set_ldt_desc(desc, LDT_VIRT_START(v), ents*8-1, SYS_DESC_ldt);
         lldt(LDT_ENTRY << 3);
     }
 }
-- 
2.13.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to