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

[xen staging] x86: introduce read_sregs() to allow storing to memory directly



commit 32a9ecca23b87db659c19fa5fc23c40309ba68ed
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Sep 29 10:50:27 2020 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Sep 29 10:50:27 2020 +0200

    x86: introduce read_sregs() to allow storing to memory directly
    
    When storing all (data) segment registers in one go, prefer writing the
    selector values directly to memory (as opposed to read_sreg()).
    
    Also move the single register variant into the regs.h, dropping the
    unecessary "volatile" from the asm() (there are no hidden side effects).
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/domain.c        |  5 +----
 xen/arch/x86/x86_64/traps.c  |  5 +----
 xen/include/asm-x86/regs.h   | 14 ++++++++++++++
 xen/include/asm-x86/system.h |  6 ------
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index e8e91cf080..4273d272e7 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -1703,10 +1703,7 @@ static void save_segments(struct vcpu *v)
 {
     struct cpu_user_regs *regs = &v->arch.user_regs;
 
-    regs->ds = read_sreg(ds);
-    regs->es = read_sreg(es);
-    regs->fs = read_sreg(fs);
-    regs->gs = read_sreg(gs);
+    read_sregs(regs);
 
     if ( !is_pv_32bit_vcpu(v) )
     {
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index 93af0c5e87..fd049c5e14 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -43,10 +43,7 @@ static void read_registers(struct cpu_user_regs *regs, 
unsigned long crs[8])
     crs[2] = read_cr2();
     crs[3] = read_cr3();
     crs[4] = read_cr4();
-    regs->ds = read_sreg(ds);
-    regs->es = read_sreg(es);
-    regs->fs = read_sreg(fs);
-    regs->gs = read_sreg(gs);
+    read_sregs(regs);
     crs[5] = rdfsbase();
     crs[6] = rdgsbase();
     crs[7] = rdgsshadow();
diff --git a/xen/include/asm-x86/regs.h b/xen/include/asm-x86/regs.h
index dc00b854e3..8d984ea388 100644
--- a/xen/include/asm-x86/regs.h
+++ b/xen/include/asm-x86/regs.h
@@ -15,4 +15,18 @@
     (diff == 0);                                                              \
 })
 
+#define read_sreg(name) ({                           \
+    unsigned int __sel;                              \
+    asm ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \
+    __sel;                                           \
+})
+
+static inline void read_sregs(struct cpu_user_regs *regs)
+{
+    asm ( "mov %%ds, %0" : "=m" (regs->ds) );
+    asm ( "mov %%es, %0" : "=m" (regs->es) );
+    asm ( "mov %%fs, %0" : "=m" (regs->fs) );
+    asm ( "mov %%gs, %0" : "=m" (regs->gs) );
+}
+
 #endif /* __X86_REGS_H__ */
diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h
index 7e5891f3df..45c183bd10 100644
--- a/xen/include/asm-x86/system.h
+++ b/xen/include/asm-x86/system.h
@@ -5,12 +5,6 @@
 #include <xen/bitops.h>
 #include <asm/processor.h>
 
-#define read_sreg(name)                                         \
-({  unsigned int __sel;                                         \
-    asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) );   \
-    __sel;                                                      \
-})
-
 static inline void wbinvd(void)
 {
     asm volatile ( "wbinvd" ::: "memory" );
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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