[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xen/x86: Introduce static inline wrappers for l{idt, gdt, ldt, tr}()



commit 1a8210c52a50ea518605f244fe235afbd6078122
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Oct 2 13:58:17 2017 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Dec 1 19:03:26 2017 +0000

    xen/x86: Introduce static inline wrappers for l{idt,gdt,ldt,tr}()
    
    This avoids indirection and parameter constraint issues.  Doing so relaxes 
the
    load_LDT() constraints from %ax to any general purpose register.  The 
helpers
    are upgraded to full compiler barriers, because nothing good will come of
    having these reordered with respect to other segment accesses.
    
    The triple-fault reboot method stays as is, to avoid the int3 possibly 
getting
    moved relative to the lidt.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/cpu/common.c  |  8 ++++----
 xen/arch/x86/domain.c      |  6 ++++--
 xen/common/efi/runtime.c   |  4 ++--
 xen/include/asm-x86/desc.h | 20 ++++++++++++++++++++
 xen/include/asm-x86/ldt.h  |  6 ++----
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 6cf3628..e9588b3 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -698,10 +698,10 @@ void load_system_tables(void)
                offsetof(struct tss_struct, __cacheline_filler) - 1,
                SYS_DESC_tss_busy);
 
-       asm volatile ("lgdt %0"  : : "m"  (gdtr) );
-       asm volatile ("lidt %0"  : : "m"  (idtr) );
-       asm volatile ("ltr  %w0" : : "rm" (TSS_ENTRY << 3) );
-       asm volatile ("lldt %w0" : : "rm" (0) );
+       lgdt(&gdtr);
+       lidt(&idtr);
+       ltr(TSS_ENTRY << 3);
+       lldt(0);
 
        set_ist(&idt_tables[cpu][TRAP_double_fault],  IST_DF);
        set_ist(&idt_tables[cpu][TRAP_nmi],           IST_NMI);
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 735f45c..b49a9c4 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1644,7 +1644,8 @@ static void __context_switch(void)
     {
         gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
         gdt_desc.base  = (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY);
-        asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
+
+        lgdt(&gdt_desc);
     }
 
     write_ptbase(n);
@@ -1654,7 +1655,8 @@ static void __context_switch(void)
     {
         gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
         gdt_desc.base = GDT_VIRT_START(n);
-        asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
+
+        lgdt(&gdt_desc);
     }
 
     if ( pd != nd )
diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c
index c38f00a..3dbc2e8 100644
--- a/xen/common/efi/runtime.c
+++ b/xen/common/efi/runtime.c
@@ -108,7 +108,7 @@ struct efi_rs_state efi_rs_enter(void)
                                      FIRST_RESERVED_GDT_ENTRY)
         };
 
-        asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
+        lgdt(&gdt_desc);
     }
 
     write_cr3(virt_to_maddr(efi_l4_pgtable));
@@ -128,7 +128,7 @@ void efi_rs_leave(struct efi_rs_state *state)
             .base  = GDT_VIRT_START(current)
         };
 
-        asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
+        lgdt(&gdt_desc);
     }
     irq_exit();
     efi_rs_on_cpu = NR_CPUS;
diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h
index da924bf..9778a35 100644
--- a/xen/include/asm-x86/desc.h
+++ b/xen/include/asm-x86/desc.h
@@ -197,6 +197,26 @@ DECLARE_PER_CPU(struct desc_struct *, compat_gdt_table);
 
 extern void load_TR(void);
 
+static inline void lgdt(const struct desc_ptr *gdtr)
+{
+    __asm__ __volatile__ ( "lgdt %0" :: "m" (*gdtr) : "memory" );
+}
+
+static inline void lidt(const struct desc_ptr *idtr)
+{
+    __asm__ __volatile__ ( "lidt %0" :: "m" (*idtr) : "memory" );
+}
+
+static inline void lldt(unsigned int sel)
+{
+    __asm__ __volatile__ ( "lldt %w0" :: "rm" (sel) : "memory" );
+}
+
+static inline void ltr(unsigned int sel)
+{
+    __asm__ __volatile__ ( "ltr %w0" :: "rm" (sel) : "memory" );
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ARCH_DESC_H */
diff --git a/xen/include/asm-x86/ldt.h b/xen/include/asm-x86/ldt.h
index 289ae19..589daf8 100644
--- a/xen/include/asm-x86/ldt.h
+++ b/xen/include/asm-x86/ldt.h
@@ -10,16 +10,14 @@ static inline void load_LDT(struct vcpu *v)
     unsigned long ents;
 
     if ( (ents = v->arch.pv_vcpu.ldt_ents) == 0 )
-    {
-        __asm__ __volatile__ ( "lldt %%ax" : : "a" (0) );
-    }
+        lldt(0);
     else
     {
         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);
-        __asm__ __volatile__ ( "lldt %%ax" : : "a" (LDT_ENTRY << 3) );
+        lldt(LDT_ENTRY << 3);
     }
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.