x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save()
Subsystems (3)
PATCH 1/3 x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save()
hv_hvcrash_ctxt_save() in arch/x86/hyperv/hv_crash.c currently saves segment registers via a general-purpose register (%eax). Update the code to save segment registers (cs, ss, ds, es, fs, gs) directly to the crash context memory using movw. This avoids unnecessary use of a general-purpose register, making the code simpler and more efficient.
The size of the corresponding object file improves as follows:
text data bss dec hex filename 4167 176 200 4543 11bf hv_crash-old.o 4151 176 200 4527 11af hv_crash-new.o
No functional change occurs to the saved context contents; this is purely a code-quality improvement.
--- arch/x86/hyperv/hv_crash.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/hyperv/hv_crash.c +6 -6
@@ -207,12 +207,12 @@ static void hv_hvcrash_ctxt_save(void) asmvolatile ("movq %%cr2, %0" :"=a" (ctxt->cr2)); asmvolatile ("movq %%cr8, %0" :"=a" (ctxt->cr8)); - asmvolatile ("movl %%cs, %%eax" :"=a" (ctxt->cs)); - asmvolatile ("movl %%ss, %%eax" :"=a" (ctxt->ss)); - asmvolatile ("movl %%ds, %%eax" :"=a" (ctxt->ds)); - asmvolatile ("movl %%es, %%eax" :"=a" (ctxt->es)); - asmvolatile ("movl %%fs, %%eax" :"=a" (ctxt->fs)); - asmvolatile ("movl %%gs, %%eax" :"=a" (ctxt->gs)); + asmvolatile ("movw %%cs, %0" :"=m" (ctxt->cs)); + asmvolatile ("movw %%ss, %0" :"=m" (ctxt->ss)); + asmvolatile ("movw %%ds, %0" :"=m" (ctxt->ds)); + asmvolatile ("movw %%es, %0" :"=m" (ctxt->es)); + asmvolatile ("movw %%fs, %0" :"=m" (ctxt->fs)); + asmvolatile ("movw %%gs, %0" :"=m" (ctxt->gs));native_store_gdt (&ctxt->gdtr);store_idt (&ctxt->idtr);
Signature · 1 line
2.53.0
PATCH 2/3 x86/hyperv: Use current_stack_pointer to avoid asm() in hv_hvcrash_ctxt_save()
Use current_stack_pointer to avoid asm() when saving %rsp to the crash context memory in hv_hvcrash_ctxt_save(). The new code is more readable and results in exactly the same object file.
--- arch/x86/hyperv/hv_crash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_crash.c +1 -1
@@ -199,7 +199,7 @@ static void hv_hvcrash_ctxt_save(void) {struct hv_crash_ctxt *ctxt = &hv_crash_ctxt; - asmvolatile ("movq %%rsp,%0" :"=m" (ctxt->rsp)); + ctxt->rsp = current_stack_pointer; ctxt->cr0 =native_read_cr0 (); ctxt->cr4 =native_read_cr4 ();
Signature · 1 line
2.53.0
PATCH 3/3 x86/hyperv: Use any general-purpose register when saving %cr2 and %cr8
In reply to Uros Bizjakhv_hvcrash_ctxt_save() in arch/x86/hyperv/hv_crash.c currently saves %cr2 and %cr8 using %eax ("=a"). This unnecessarily forces a specific register. Update the inline assembly to use a general-purpose register ("=r") for both %cr2 and %cr8. This makes the code more flexible for the compiler while producing the same saved context contents.
No functional changes.
--- arch/x86/hyperv/hv_crash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/hyperv/hv_crash.c +2 -2
@@ -204,8 +204,8 @@ static void hv_hvcrash_ctxt_save(void) ctxt->cr0 =native_read_cr0 (); ctxt->cr4 =native_read_cr4 (); - asmvolatile ("movq %%cr2, %0" :"=a" (ctxt->cr2)); - asmvolatile ("movq %%cr8, %0" :"=a" (ctxt->cr8)); + asmvolatile ("movq %%cr2, %0" :"=r" (ctxt->cr2)); + asmvolatile ("movq %%cr8, %0" :"=r" (ctxt->cr8)); asmvolatile ("movw %%cs, %0" :"=m" (ctxt->cs)); asmvolatile ("movw %%ss, %0" :"=m" (ctxt->ss));
Signature · 1 line
2.53.0
Wei Liu
maintainerQuoted 15 lines · Uros Bizjak
hv_hvcrash_ctxt_save()inarch/x86/hyperv/hv_crash.ccurrently saves segment registers via a general-purpose register (%eax). Update the code to save segment registers (cs, ss, ds, es, fs, gs) directly to the crash context memory using movw. This avoids unnecessary use of a general-purpose register, making the code simpler and more efficient.The size of the corresponding object file improves as follows:
text data bss dec hex filename 4167 176 200 4543 11bf hv_crash-old.o 4151 176 200 4527 11af hv_crash-new.oNo functional change occurs to the saved context contents; this is purely a code-quality improvement.
Quoted 11 lines
Signed-off-by Uros Bizjak <[email protected]>Cc "K. Y. Srinivasan" <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Wei Liu <[email protected]>Cc Dexuan Cui <[email protected]>Cc Long Li <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Cc "H. Peter Anvin" <[email protected]>
Series applied to hyperv-fixes. Thanks.