* [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save()
@ 2026-03-11 10:25 Uros Bizjak
2026-03-11 10:25 ` [PATCH -hyperv 2/3] x86/hyperv: Use current_stack_pointer to avoid asm() " Uros Bizjak
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Uros Bizjak @ 2026-03-11 10:25 UTC (permalink / raw)
To: linux-hyperv, x86, linux-kernel
Cc: Uros Bizjak, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Long Li, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Long Li <longli@microsoft.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/hyperv/hv_crash.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
index fdb277bf73d8..2c7ea7e70854 100644
--- a/arch/x86/hyperv/hv_crash.c
+++ b/arch/x86/hyperv/hv_crash.c
@@ -207,12 +207,12 @@ static void hv_hvcrash_ctxt_save(void)
asm volatile("movq %%cr2, %0" : "=a"(ctxt->cr2));
asm volatile("movq %%cr8, %0" : "=a"(ctxt->cr8));
- asm volatile("movl %%cs, %%eax" : "=a"(ctxt->cs));
- asm volatile("movl %%ss, %%eax" : "=a"(ctxt->ss));
- asm volatile("movl %%ds, %%eax" : "=a"(ctxt->ds));
- asm volatile("movl %%es, %%eax" : "=a"(ctxt->es));
- asm volatile("movl %%fs, %%eax" : "=a"(ctxt->fs));
- asm volatile("movl %%gs, %%eax" : "=a"(ctxt->gs));
+ asm volatile("movw %%cs, %0" : "=m"(ctxt->cs));
+ asm volatile("movw %%ss, %0" : "=m"(ctxt->ss));
+ asm volatile("movw %%ds, %0" : "=m"(ctxt->ds));
+ asm volatile("movw %%es, %0" : "=m"(ctxt->es));
+ asm volatile("movw %%fs, %0" : "=m"(ctxt->fs));
+ asm volatile("movw %%gs, %0" : "=m"(ctxt->gs));
native_store_gdt(&ctxt->gdtr);
store_idt(&ctxt->idtr);
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH -hyperv 2/3] x86/hyperv: Use current_stack_pointer to avoid asm() in hv_hvcrash_ctxt_save()
2026-03-11 10:25 [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Uros Bizjak
@ 2026-03-11 10:25 ` Uros Bizjak
2026-03-11 10:26 ` [PATCH -hyperv 3/3] x86/hyperv: Use any general-purpose register when saving %cr2 and %cr8 Uros Bizjak
2026-03-12 4:27 ` [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Wei Liu
2 siblings, 0 replies; 4+ messages in thread
From: Uros Bizjak @ 2026-03-11 10:25 UTC (permalink / raw)
To: linux-hyperv, x86, linux-kernel
Cc: Uros Bizjak, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Long Li, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Long Li <longli@microsoft.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/hyperv/hv_crash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
index 2c7ea7e70854..d0f95a278fdb 100644
--- a/arch/x86/hyperv/hv_crash.c
+++ b/arch/x86/hyperv/hv_crash.c
@@ -199,7 +199,7 @@ static void hv_hvcrash_ctxt_save(void)
{
struct hv_crash_ctxt *ctxt = &hv_crash_ctxt;
- asm volatile("movq %%rsp,%0" : "=m"(ctxt->rsp));
+ ctxt->rsp = current_stack_pointer;
ctxt->cr0 = native_read_cr0();
ctxt->cr4 = native_read_cr4();
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH -hyperv 3/3] x86/hyperv: Use any general-purpose register when saving %cr2 and %cr8
2026-03-11 10:25 [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Uros Bizjak
2026-03-11 10:25 ` [PATCH -hyperv 2/3] x86/hyperv: Use current_stack_pointer to avoid asm() " Uros Bizjak
@ 2026-03-11 10:26 ` Uros Bizjak
2026-03-12 4:27 ` [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Wei Liu
2 siblings, 0 replies; 4+ messages in thread
From: Uros Bizjak @ 2026-03-11 10:26 UTC (permalink / raw)
To: linux-hyperv, x86, linux-kernel
Cc: Uros Bizjak, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Long Li, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
hv_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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Long Li <longli@microsoft.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/hyperv/hv_crash.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/hyperv/hv_crash.c b/arch/x86/hyperv/hv_crash.c
index d0f95a278fdb..5ffcc23255de 100644
--- a/arch/x86/hyperv/hv_crash.c
+++ b/arch/x86/hyperv/hv_crash.c
@@ -204,8 +204,8 @@ static void hv_hvcrash_ctxt_save(void)
ctxt->cr0 = native_read_cr0();
ctxt->cr4 = native_read_cr4();
- asm volatile("movq %%cr2, %0" : "=a"(ctxt->cr2));
- asm volatile("movq %%cr8, %0" : "=a"(ctxt->cr8));
+ asm volatile("movq %%cr2, %0" : "=r"(ctxt->cr2));
+ asm volatile("movq %%cr8, %0" : "=r"(ctxt->cr8));
asm volatile("movw %%cs, %0" : "=m"(ctxt->cs));
asm volatile("movw %%ss, %0" : "=m"(ctxt->ss));
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save()
2026-03-11 10:25 [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Uros Bizjak
2026-03-11 10:25 ` [PATCH -hyperv 2/3] x86/hyperv: Use current_stack_pointer to avoid asm() " Uros Bizjak
2026-03-11 10:26 ` [PATCH -hyperv 3/3] x86/hyperv: Use any general-purpose register when saving %cr2 and %cr8 Uros Bizjak
@ 2026-03-12 4:27 ` Wei Liu
2 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2026-03-12 4:27 UTC (permalink / raw)
To: Uros Bizjak
Cc: linux-hyperv, x86, linux-kernel, K. Y. Srinivasan, Haiyang Zhang,
Wei Liu, Dexuan Cui, Long Li, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin
On Wed, Mar 11, 2026 at 11:25:58AM +0100, Uros Bizjak wrote:
> 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.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: "K. Y. Srinivasan" <kys@microsoft.com>
> Cc: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: Wei Liu <wei.liu@kernel.org>
> Cc: Dexuan Cui <decui@microsoft.com>
> Cc: Long Li <longli@microsoft.com>
> Cc: Thomas Gleixner <tglx@kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
Series applied to hyperv-fixes. Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-12 4:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 10:25 [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Uros Bizjak
2026-03-11 10:25 ` [PATCH -hyperv 2/3] x86/hyperv: Use current_stack_pointer to avoid asm() " Uros Bizjak
2026-03-11 10:26 ` [PATCH -hyperv 3/3] x86/hyperv: Use any general-purpose register when saving %cr2 and %cr8 Uros Bizjak
2026-03-12 4:27 ` [PATCH -hyperv 1/3] x86/hyperv: Save segment registers directly to memory in hv_hvcrash_ctxt_save() Wei Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox