x86: introduce read_sregs() and elf_core_save_regs() adjustments
cover x86: introduce read_sregs() and elf_core_save_regs() adjustments
1: introduce read_sregs() to allow storing to memory directly 2: ELF: don't open-code read_sreg()
3: ELF: don't store function pointer in elf_core_save_regs() 4: ELF: also record FS/GS bases in elf_core_save_regs() 5: ELF: eliminate pointless local variable from elf_core_save_regs()
Jan
PATCH 1/5 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.
xen/arch/x86/domain.c +1 -4
@@ -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) ) {
xen/arch/x86/x86_64/traps.c +1 -4
@@ -43,10 +43,7 @@ static void read_registers(struct cpu_us 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 ();
xen/include/asm-x86/regs.h +14 -0
@@ -15,4 +15,18 @@ (diff ==0 ); \ }) +#define read_sreg (name) ({ \ + unsigned int __sel; \ + asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \ + __sel; \ +}) + +static inline void read_sregs (struct cpu_user_regs *regs) +{ + asmvolatile ("mov %%ds, %0" :"=m" (regs->ds) ); + asmvolatile ("mov %%es, %0" :"=m" (regs->es) ); + asmvolatile ("mov %%fs, %0" :"=m" (regs->fs) ); + asmvolatile ("mov %%gs, %0" :"=m" (regs->gs) ); +} +#endif /* __X86_REGS_H__ */
xen/include/asm-x86/system.h +0 -6
@@ -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 ) { asmvolatile ("wbinvd" :::"memory" );
Re: [PATCH 1/5] x86: introduce read_sregs() to allow storing to memory directly
Quoted 8 lines · Jan Beulich
xen/include/asm-x86/regs.h +2
-0@@ -15,4 +15,18 @@ (diff ==0 ); \ }) +#define read_sreg (name) ({ \ + unsigned int __sel; \
xen/include/asm-x86/regs.h line 29
Quoted 10 lines
xen/include/asm-x86/regs.h +10
-0+ asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \ + __sel; \ +}) + +static inline void read_sregs(struct cpu_user_regs *regs) +{ + asmvolatile ("mov %%ds, %0" :"=m" (regs->ds) ); + asmvolatile ("mov %%es, %0" :"=m" (regs->es) ); + asmvolatile ("mov %%fs, %0" :"=m" (regs->fs) ); + asmvolatile ("mov %%gs, %0" :"=m" (regs->gs) );
It occurs to me that reads don't need to be volatile. There are no side effects.
With that fixed, Reviewed-by: Andrew Cooper <[email protected]>
Re: [PATCH 1/5] x86: introduce read_sregs() to allow storing to memory directly
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
xen/include/asm-x86/regs.h +0
-0@@ -15,4 +15,18 @@ (diff ==0 ); \ })
Quoted 15 lines
xen/include/asm-x86/regs.h line 29
Quoted 12 lines
xen/include/asm-x86/regs.h +12
-0+#define read_sreg (name) ({ \ + unsigned int __sel; \ + asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \ + __sel; \ +}) + +static inline void read_sregs (struct cpu_user_regs *regs) +{ + asmvolatile ("mov %%ds, %0" :"=m" (regs->ds) ); + asmvolatile ("mov %%es, %0" :"=m" (regs->es) ); + asmvolatile ("mov %%fs, %0" :"=m" (regs->fs) ); + asmvolatile ("mov %%gs, %0" :"=m" (regs->gs) );It occurs to me that reads don't need to be volatile. There are no side effects.
Oh yes, of course. Too mechanical moving / copying ...
Quoted 1 line
With that fixed, Reviewed-by: Andrew Cooper <[email protected]>
Thanks, Jan
Re: [PATCH 1/5] x86: introduce read_sregs() to allow storing to memory directly
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
xen/include/asm-x86/regs.h +0
-0@@ -15,4 +15,18 @@ (diff ==0 ); \ })
Quoted 15 lines
xen/include/asm-x86/regs.h line 29
Quoted 12 lines
xen/include/asm-x86/regs.h +12
-0+#define read_sreg (name) ({ \ + unsigned int __sel; \ + asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \ + __sel; \ +}) + +static inline void read_sregs (struct cpu_user_regs *regs) +{ + asmvolatile ("mov %%ds, %0" :"=m" (regs->ds) ); + asmvolatile ("mov %%es, %0" :"=m" (regs->es) ); + asmvolatile ("mov %%fs, %0" :"=m" (regs->fs) ); + asmvolatile ("mov %%gs, %0" :"=m" (regs->gs) );It occurs to me that reads don't need to be volatile. There are no side effects.
I'll do the same for what patches 3 and 5 alter anyway, assuming this won't invalidate your R-b there.
Jan
Re: [PATCH 1/5] x86: introduce read_sregs() to allow storing to memory directly
Quoted 22 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Jan Beulich
xen/include/asm-x86/regs.h +0
-0@@ -15,4 +15,18 @@ (diff ==0 ); \ })Quoted 14 lines
xen/include/asm-x86/regs.h line 29
Quoted 12 lines
xen/include/asm-x86/regs.h +12
-0+#define read_sreg (name) ({ \ + unsigned int __sel; \ + asm volatile ( "mov %%" STR(name) ",%0" : "=r" (__sel) ); \ + __sel; \ +}) + +static inline void read_sregs (struct cpu_user_regs *regs) +{ + asmvolatile ("mov %%ds, %0" :"=m" (regs->ds) ); + asmvolatile ("mov %%es, %0" :"=m" (regs->es) ); + asmvolatile ("mov %%fs, %0" :"=m" (regs->fs) ); + asmvolatile ("mov %%gs, %0" :"=m" (regs->gs) );It occurs to me that reads don't need to be volatile. There are no side effects.
Quoted 2 lines
I'll do the same for what patches 3 and 5 alter anyway, assuming this won't invalidate your R-b there.
3 is fine. 5 is a little more problematic, because there are serialising side effects, but I suppose we really don't care here.
~Andrew
PATCH 2/5 x86/ELF: don't open-code read_sreg()
In reply to Jan Beulichxen/include/asm-x86/x86_64/elf.h +7 -5
@@ -1,6 +1,8 @@ #ifndef __X86_64_ELF_H__ #define __X86_64_ELF_H__ +#include <asm/regs.h> + typedef struct { unsigned long r15; unsigned long r14;
@@ -53,16 +55,16 @@ static inline void elf_core_save_regs(EL asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi));/* orig_rax not filled in for now */ core_regs->rip = (unsigned long )elf_core_save_regs; - asmvolatile ("movl %%cs, %%eax;" :"=a" (core_regs->cs)); + core_regs->cs =read_sreg (cs); asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); asmvolatile ("movl %%ss, %%eax;" :"=a" (core_regs->ss));/* thread_fs not filled in for now */ /* thread_gs not filled in for now */ - asmvolatile ("movl %%ds, %%eax;" :"=a" (core_regs->ds)); - asmvolatile ("movl %%es, %%eax;" :"=a" (core_regs->es)); - asmvolatile ("movl %%fs, %%eax;" :"=a" (core_regs->fs)); - asmvolatile ("movl %%gs, %%eax;" :"=a" (core_regs->gs)); + core_regs->ds =read_sreg (ds); + core_regs->es =read_sreg (es); + core_regs->fs =read_sreg (fs); + core_regs->gs =read_sreg (gs); asmvolatile ("mov %%cr0, %0" :"=r" (tmp) : ); xen_core_regs->cr0 = tmp;
Re: [PATCH 2/5] x86/ELF: don't open-code read_sreg()
Quoted 14 lines · Jan Beulich
Signed-off-by Jan Beulich <[email protected]>xen/include/asm-x86/x86_64/elf.h +2
-0@@ -1,6 +1,8 @@ #ifndef __X86_64_ELF_H__ #define __X86_64_ELF_H__ +#include <asm/regs.h> + typedef struct { unsigned long r15; unsigned long r14;
xen/include/asm-x86/x86_64/elf.h static inline void elf_core_save_regs(EL · line 61
Quoted 8 lines
xen/include/asm-x86/x86_64/elf.h +1
-1@@ -53,16 +55,16 @@ static inline void elf_core_save_regs(EL asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi));/* orig_rax not filled in for now */ core_regs->rip = (unsigned long )elf_core_save_regs; - asmvolatile ("movl %%cs, %%eax;" :"=a" (core_regs->cs)); + core_regs->cs =read_sreg (cs); asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); asmvolatile ("movl %%ss, %%eax;" :"=a" (core_regs->ss));
Another one here.
With that fixed, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 13 lines
xen/include/asm-x86/x86_64/elf.h +4
-4/* thread_fs not filled in for now */ /* thread_gs not filled in for now */ - asmvolatile ("movl %%ds, %%eax;" :"=a" (core_regs->ds)); - asmvolatile ("movl %%es, %%eax;" :"=a" (core_regs->es)); - asmvolatile ("movl %%fs, %%eax;" :"=a" (core_regs->fs)); - asmvolatile ("movl %%gs, %%eax;" :"=a" (core_regs->gs)); + core_regs->ds =read_sreg (ds); + core_regs->es =read_sreg (es); + core_regs->fs =read_sreg (fs); + core_regs->gs =read_sreg (gs); asmvolatile ("mov %%cr0, %0" :"=r" (tmp) : ); xen_core_regs->cr0 = tmp;
PATCH 3/5 x86/ELF: don't store function pointer in elf_core_save_regs()
In reply to Jan BeulichThis keeps at least gcc 10 from generating a separate function instance in common/kexec.o alongside the inlining of the function in its sole caller. I also think putting the address of the actual code storing the registers is a better indication to consumers than that of an otherwise unreferenced function.
xen/include/asm-x86/x86_64/elf.h +1 -1
@@ -54,7 +54,7 @@ static inline void elf_core_save_regs(EL asmvolatile ("movq %%rsi,%0" :"=m" (core_regs->rsi)); asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi));/* orig_rax not filled in for now */ - core_regs->rip = (unsigned long )elf_core_save_regs; + asmvolatile ("call 0f; 0: popq %0" :"=m" (core_regs->rip)); core_regs->cs =read_sreg (cs); asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp));
Re: [PATCH 3/5] x86/ELF: don't store function pointer in elf_core_save_regs()
Quoted 5 lines · Jan Beulich
This keeps at least gcc 10 from generating a separate function instance in
common/kexec.oalongside the inlining of the function in its sole caller. I also think putting the address of the actual code storing the registers is a better indication to consumers than that of an otherwise unreferenced function.
Hmm - that's unfortunate.
elf_core_save_regs is certainly a useful name to spot in a backtrace.
xen/include/asm-x86/x86_64/elf.h static inline void elf_core_save_regs(EL · line 57
Quoted 10 lines
Signed-off-by Jan Beulich <[email protected]>xen/include/asm-x86/x86_64/elf.h +1
-1@@ -54,7 +54,7 @@ static inline void elf_core_save_regs(EL asmvolatile ("movq %%rsi,%0" :"=m" (core_regs->rsi)); asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi));/* orig_rax not filled in for now */ - core_regs->rip = (unsigned long )elf_core_save_regs; + asmvolatile ("call 0f; 0: popq %0" :"=m" (core_regs->rip));
lea 0(%rip) will be faster to execute, and this is 64bit code specifically.
Either way, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 4 lines
xen/include/asm-x86/x86_64/elf.h +0
-0core_regs->cs =read_sreg (cs); asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp));
PATCH 4/5 x86/ELF: also record FS/GS bases in elf_core_save_regs()
In reply to Jan Beulichxen/include/asm-x86/x86_64/elf.h +3 -2
@@ -1,6 +1,7 @@ #ifndef __X86_64_ELF_H__ #define __X86_64_ELF_H__ +#include <asm/msr.h> #include <asm/regs.h> typedef struct {
@@ -59,8 +60,8 @@ static inline void elf_core_save_regs(EL asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); asmvolatile ("movl %%ss, %%eax;" :"=a" (core_regs->ss)); -/* thread_fs not filled in for now */ -/* thread_gs not filled in for now */ +rdmsrl (MSR_FS_BASE , core_regs->thread_fs); +rdmsrl (MSR_GS_BASE , core_regs->thread_gs); core_regs->ds =read_sreg (ds); core_regs->es =read_sreg (es); core_regs->fs =read_sreg (fs);
Re: [PATCH 4/5] x86/ELF: also record FS/GS bases in elf_core_save_regs()
Quoted 1 line · Jan Beulich
Signed-off-by Jan Beulich <[email protected]>
Any idea why this wasn't done before? At a minimum, I'd be tempted to put a sentence in the commit message saying "no idea why this wasn't done before".
Quoted 23 lines
xen/include/asm-x86/x86_64/elf.h +3
-2@@ -1,6 +1,7 @@ #ifndef __X86_64_ELF_H__ #define __X86_64_ELF_H__ +#include <asm/msr.h> #include <asm/regs.h> typedef struct {@@ -59,8 +60,8 @@ static inline void elf_core_save_regs(EL asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); asmvolatile ("movl %%ss, %%eax;" :"=a" (core_regs->ss)); -/* thread_fs not filled in for now */ -/* thread_gs not filled in for now */ +rdmsrl (MSR_FS_BASE , core_regs->thread_fs); +rdmsrl (MSR_GS_BASE , core_regs->thread_gs); core_regs->ds =read_sreg (ds); core_regs->es =read_sreg (es); core_regs->fs =read_sreg (fs);
Re: [PATCH 4/5] x86/ELF: also record FS/GS bases in elf_core_save_regs()
Quoted 4 lines · Andrew Cooper
Quoted 1 line · Jan Beulich
Signed-off-by Jan Beulich <[email protected]>Any idea why this wasn't done before?
No. My only guess is laziness, in the sense of "I'll do it later" and then forgetting.
Quoted 3 lines
At a minimum, I'd be tempted to
put a sentence in the commit message saying "no idea why this wasn't done before".
Sure, done.
Quoted 1 line
Reviewed-by Andrew Cooper <[email protected]>
Thanks.
Jan
PATCH 5/5 x86/ELF: eliminate pointless local variable from elf_core_save_regs()
In reply to Jan BeulichWe can just as well specify the CRn structure fields directly in the asm()s, just like done for all other ones.
xen/include/asm-x86/x86_64/elf.h +4 -13
@@ -37,8 +37,6 @@ typedef struct {static inline void elf_core_save_regs (ELF_Gregset *core_regs,crash_xen_core_t *xen_core_regs) { -unsigned long tmp; - asmvolatile ("movq %%r15,%0" :"=m" (core_regs->r15)); asmvolatile ("movq %%r14,%0" :"=m" (core_regs->r14)); asmvolatile ("movq %%r13,%0" :"=m" (core_regs->r13));
@@ -67,17 +65,10 @@ static inline void elf_core_save_regs(EL core_regs->fs =read_sreg (fs); core_regs->gs =read_sreg (gs); - asmvolatile ("mov %%cr0, %0" :"=r" (tmp) : ); - xen_core_regs->cr0 = tmp; - - asmvolatile ("mov %%cr2, %0" :"=r" (tmp) : ); - xen_core_regs->cr2 = tmp; - - asmvolatile ("mov %%cr3, %0" :"=r" (tmp) : ); - xen_core_regs->cr3 = tmp; - - asmvolatile ("mov %%cr4, %0" :"=r" (tmp) : ); - xen_core_regs->cr4 = tmp; + asmvolatile ("mov %%cr0, %0" :"=r" (xen_core_regs->cr0)); + asmvolatile ("mov %%cr2, %0" :"=r" (xen_core_regs->cr2)); + asmvolatile ("mov %%cr3, %0" :"=r" (xen_core_regs->cr3)); + asm volatile("mov %%cr4, %0" : "=r" (xen_core_regs->cr4)); }#endif /* __X86_64_ELF_H__ */
Re: [PATCH 5/5] x86/ELF: eliminate pointless local variable from elf_core_save_regs()
Quoted 4 lines · Jan Beulich
We can just as well specify the CRn structure fields directly in the asm()s, just like done for all other ones.
Signed-off-by Jan Beulich <[email protected]>
[PATCH 6/5] x86/ELF: drop unnecessary volatile from asm()-s in elf_core_save_regs()
In reply to Jan BeulichThere are no hidden side effects here.
---
v2: New.
xen/include/asm-x86/x86_64/elf.h +17 -17
@@ -37,26 +37,26 @@ typedef struct {static inline void elf_core_save_regs (ELF_Gregset *core_regs,crash_xen_core_t *xen_core_regs) { - asmvolatile ("movq %%r15,%0" :"=m" (core_regs->r15)); - asmvolatile ("movq %%r14,%0" :"=m" (core_regs->r14)); - asmvolatile ("movq %%r13,%0" :"=m" (core_regs->r13)); - asmvolatile ("movq %%r12,%0" :"=m" (core_regs->r12)); - asmvolatile ("movq %%rbp,%0" :"=m" (core_regs->rbp)); - asmvolatile ("movq %%rbx,%0" :"=m" (core_regs->rbx)); - asmvolatile ("movq %%r11,%0" :"=m" (core_regs->r11)); - asmvolatile ("movq %%r10,%0" :"=m" (core_regs->r10)); - asmvolatile ("movq %%r9,%0" :"=m" (core_regs->r9)); - asmvolatile ("movq %%r8,%0" :"=m" (core_regs->r8)); - asmvolatile ("movq %%rax,%0" :"=m" (core_regs->rax)); - asmvolatile ("movq %%rcx,%0" :"=m" (core_regs->rcx)); - asmvolatile ("movq %%rdx,%0" :"=m" (core_regs->rdx)); - asmvolatile ("movq %%rsi,%0" :"=m" (core_regs->rsi)); - asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi)); + asm ("movq %%r15,%0" :"=m" (core_regs->r15) ); + asm ("movq %%r14,%0" :"=m" (core_regs->r14) ); + asm ("movq %%r13,%0" :"=m" (core_regs->r13) ); + asm ("movq %%r12,%0" :"=m" (core_regs->r12) ); + asm ("movq %%rbp,%0" :"=m" (core_regs->rbp) ); + asm ("movq %%rbx,%0" :"=m" (core_regs->rbx) ); + asm ("movq %%r11,%0" :"=m" (core_regs->r11) ); + asm ("movq %%r10,%0" :"=m" (core_regs->r10) ); + asm ("movq %%r9,%0" :"=m" (core_regs->r9) ); + asm ("movq %%r8,%0" :"=m" (core_regs->r8) ); + asm ("movq %%rax,%0" :"=m" (core_regs->rax) ); + asm ("movq %%rcx,%0" :"=m" (core_regs->rcx) ); + asm ("movq %%rdx,%0" :"=m" (core_regs->rdx) ); + asm ("movq %%rsi,%0" :"=m" (core_regs->rsi) ); + asm ("movq %%rdi,%0" :"=m" (core_regs->rdi) );/* orig_rax not filled in for now */ asm ("call 0f; 0: popq %0" :"=m" (core_regs->rip) ); core_regs->cs =read_sreg (cs); - asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); - asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); + asm ("pushfq; popq %0" :"=m" (core_regs->rflags) ); + asm ("movq %%rsp,%0" :"=m" (core_regs->rsp) ); core_regs->ss =read_sreg (ss);rdmsrl (MSR_FS_BASE , core_regs->thread_fs);rdmsrl (MSR_GS_BASE , core_regs->thread_gs);
Re: [PATCH 6/5] x86/ELF: drop unnecessary volatile from asm()-s in elf_core_save_regs()
Quoted 27 lines · Jan Beulich
There are no hidden side effects here.
Signed-off-by Jan Beulich <[email protected]>---
v2: New.xen/include/asm-x86/x86_64/elf.h +0
-15@@ -37,26 +37,26 @@ typedef struct {static inline void elf_core_save_regs (ELF_Gregset *core_regs,crash_xen_core_t *xen_core_regs) { - asmvolatile ("movq %%r15,%0" :"=m" (core_regs->r15)); - asmvolatile ("movq %%r14,%0" :"=m" (core_regs->r14)); - asmvolatile ("movq %%r13,%0" :"=m" (core_regs->r13)); - asmvolatile ("movq %%r12,%0" :"=m" (core_regs->r12)); - asmvolatile ("movq %%rbp,%0" :"=m" (core_regs->rbp)); - asmvolatile ("movq %%rbx,%0" :"=m" (core_regs->rbx)); - asmvolatile ("movq %%r11,%0" :"=m" (core_regs->r11)); - asmvolatile ("movq %%r10,%0" :"=m" (core_regs->r10)); - asmvolatile ("movq %%r9,%0" :"=m" (core_regs->r9)); - asmvolatile ("movq %%r8,%0" :"=m" (core_regs->r8)); - asmvolatile ("movq %%rax,%0" :"=m" (core_regs->rax)); - asmvolatile ("movq %%rcx,%0" :"=m" (core_regs->rcx)); - asmvolatile ("movq %%rdx,%0" :"=m" (core_regs->rdx)); - asmvolatile ("movq %%rsi,%0" :"=m" (core_regs->rsi)); - asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi));
xen/include/asm-x86/x86_64/elf.h typedef struct { · line 49
Quoted 10 lines
xen/include/asm-x86/x86_64/elf.h +10
-0+ asm ("movq %%r15,%0" :"=m" (core_regs->r15) ); + asm ("movq %%r14,%0" :"=m" (core_regs->r14) ); + asm ("movq %%r13,%0" :"=m" (core_regs->r13) ); + asm ("movq %%r12,%0" :"=m" (core_regs->r12) ); + asm ("movq %%rbp,%0" :"=m" (core_regs->rbp) ); + asm ("movq %%rbx,%0" :"=m" (core_regs->rbx) ); + asm ("movq %%r11,%0" :"=m" (core_regs->r11) ); + asm ("movq %%r10,%0" :"=m" (core_regs->r10) ); + asm ("movq %%r9,%0" :"=m" (core_regs->r9) ); + asm ("movq %%r8,%0" :"=m" (core_regs->r8) );
Any chance we can align these seeing as they're changing?
What about spaces before %0 ?
Either way, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 16 lines
xen/include/asm-x86/x86_64/elf.h +7
-2+ asm ("movq %%rax,%0" :"=m" (core_regs->rax) ); + asm ("movq %%rcx,%0" :"=m" (core_regs->rcx) ); + asm ("movq %%rdx,%0" :"=m" (core_regs->rdx) ); + asm ("movq %%rsi,%0" :"=m" (core_regs->rsi) ); + asm ("movq %%rdi,%0" :"=m" (core_regs->rdi) );/* orig_rax not filled in for now */ asm ("call 0f; 0: popq %0" :"=m" (core_regs->rip) ); core_regs->cs =read_sreg (cs); - asmvolatile ("pushfq; popq %0" :"=m" (core_regs->rflags)); - asmvolatile ("movq %%rsp,%0" :"=m" (core_regs->rsp)); + asm ("pushfq; popq %0" :"=m" (core_regs->rflags) ); + asm ("movq %%rsp,%0" :"=m" (core_regs->rsp) ); core_regs->ss =read_sreg (ss);rdmsrl (MSR_FS_BASE , core_regs->thread_fs);rdmsrl (MSR_GS_BASE , core_regs->thread_gs);
Re: [PATCH 6/5] x86/ELF: drop unnecessary volatile from asm()-s in elf_core_save_regs()
Quoted 32 lines · Andrew Cooper
Quoted 31 lines · Jan Beulich
There are no hidden side effects here.
Signed-off-by Jan Beulich <[email protected]>---
v2: New.xen/include/asm-x86/x86_64/elf.h +4
-15@@ -37,26 +37,26 @@ typedef struct {static inline void elf_core_save_regs (ELF_Gregset *core_regs,crash_xen_core_t *xen_core_regs) { - asmvolatile ("movq %%r15,%0" :"=m" (core_regs->r15)); - asmvolatile ("movq %%r14,%0" :"=m" (core_regs->r14)); - asmvolatile ("movq %%r13,%0" :"=m" (core_regs->r13)); - asmvolatile ("movq %%r12,%0" :"=m" (core_regs->r12)); - asmvolatile ("movq %%rbp,%0" :"=m" (core_regs->rbp)); - asmvolatile ("movq %%rbx,%0" :"=m" (core_regs->rbx)); - asmvolatile ("movq %%r11,%0" :"=m" (core_regs->r11)); - asmvolatile ("movq %%r10,%0" :"=m" (core_regs->r10)); - asmvolatile ("movq %%r9,%0" :"=m" (core_regs->r9)); - asmvolatile ("movq %%r8,%0" :"=m" (core_regs->r8)); - asmvolatile ("movq %%rax,%0" :"=m" (core_regs->rax)); - asmvolatile ("movq %%rcx,%0" :"=m" (core_regs->rcx)); - asmvolatile ("movq %%rdx,%0" :"=m" (core_regs->rdx)); - asmvolatile ("movq %%rsi,%0" :"=m" (core_regs->rsi)); - asmvolatile ("movq %%rdi,%0" :"=m" (core_regs->rdi)); + asm ("movq %%r15,%0" :"=m" (core_regs->r15) ); + asm ("movq %%r14,%0" :"=m" (core_regs->r14) ); + asm ("movq %%r13,%0" :"=m" (core_regs->r13) ); + asm ("movq %%r12,%0" :"=m" (core_regs->r12) );
Quoted 8 lines
xen/include/asm-x86/x86_64/elf.h typedef struct { · line 49
Quoted 6 lines
xen/include/asm-x86/x86_64/elf.h +6
-0+ asm ("movq %%rbp,%0" :"=m" (core_regs->rbp) ); + asm ("movq %%rbx,%0" :"=m" (core_regs->rbx) ); + asm ("movq %%r11,%0" :"=m" (core_regs->r11) ); + asm ("movq %%r10,%0" :"=m" (core_regs->r10) ); + asm ("movq %%r9,%0" :"=m" (core_regs->r9) ); + asm ("movq %%r8,%0" :"=m" (core_regs->r8) );Any chance we can align these seeing as they're changing?
I wasn't really sure about this - alignment to cover for the difference between r8 and r9 vs r10-r15 never comes out nicely, as the padding should really be in the number part of the names. I'd prefer to leave it as is, while ...
Quoted 1 line
What about spaces before %0 ?
... I certainly will add these (as I should have noticed their lack myself).
Quoted 1 line
Either way, Reviewed-by: Andrew Cooper <[email protected]>
Thanks.
Jan