* [PATCH v2 1/3] x86: Use MOVL when reading segment registers @ 2025-11-21 14:14 Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 2/3] x86/hyperv: Use savesegment() instead of inline asm() to save " Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn Uros Bizjak 0 siblings, 2 replies; 5+ messages in thread From: Uros Bizjak @ 2025-11-21 14:14 UTC (permalink / raw) To: linux-hyperv, x86, linux-kernel Cc: Uros Bizjak, Michael Kelley, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin Use MOVL when reading segment registers to avoid 0x66 operand-size override insn prefix. The segment value is always 16-bit and gets zero-extended to the full 32-bit size. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Tested-by: Michael Kelley <mhklinux@outlook.com> Cc: Thomas Gleixner <tglx@linutronix.de> 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/include/asm/segment.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index f59ae7186940..9f5be2bbd291 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -348,7 +348,7 @@ static inline void __loadsegment_fs(unsigned short value) * Save a segment register away: */ #define savesegment(seg, value) \ - asm("mov %%" #seg ",%0":"=r" (value) : : "memory") + asm("movl %%" #seg ",%k0" : "=r" (value) : : "memory") #endif /* !__ASSEMBLER__ */ #endif /* __KERNEL__ */ -- 2.51.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] x86/hyperv: Use savesegment() instead of inline asm() to save segment registers 2025-11-21 14:14 [PATCH v2 1/3] x86: Use MOVL when reading segment registers Uros Bizjak @ 2025-11-21 14:14 ` Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn Uros Bizjak 1 sibling, 0 replies; 5+ messages in thread From: Uros Bizjak @ 2025-11-21 14:14 UTC (permalink / raw) To: linux-hyperv, x86, linux-kernel Cc: Uros Bizjak, Wei Liu, Michael Kelley, K. Y. Srinivasan, Haiyang Zhang, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin Use standard savesegment() utility macro to save segment registers. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Acked-by: Wei Liu <wei.liu@kernel.org> Tested-by: Michael Kelley <mhklinux@outlook.com> Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Dexuan Cui <decui@microsoft.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> --- arch/x86/hyperv/ivm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 651771534cae..7365d8f43181 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -25,6 +25,7 @@ #include <asm/e820/api.h> #include <asm/desc.h> #include <asm/msr.h> +#include <asm/segment.h> #include <uapi/asm/vmx.h> #ifdef CONFIG_AMD_MEM_ENCRYPT @@ -315,16 +316,16 @@ int hv_snp_boot_ap(u32 apic_id, unsigned long start_ip, unsigned int cpu) vmsa->gdtr.base = gdtr.address; vmsa->gdtr.limit = gdtr.size; - asm volatile("movl %%es, %%eax;" : "=a" (vmsa->es.selector)); + savesegment(es, vmsa->es.selector); hv_populate_vmcb_seg(vmsa->es, vmsa->gdtr.base); - asm volatile("movl %%cs, %%eax;" : "=a" (vmsa->cs.selector)); + savesegment(cs, vmsa->cs.selector); hv_populate_vmcb_seg(vmsa->cs, vmsa->gdtr.base); - asm volatile("movl %%ss, %%eax;" : "=a" (vmsa->ss.selector)); + savesegment(ss, vmsa->ss.selector); hv_populate_vmcb_seg(vmsa->ss, vmsa->gdtr.base); - asm volatile("movl %%ds, %%eax;" : "=a" (vmsa->ds.selector)); + savesegment(ds, vmsa->ds.selector); hv_populate_vmcb_seg(vmsa->ds, vmsa->gdtr.base); vmsa->efer = native_read_msr(MSR_EFER); -- 2.51.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn 2025-11-21 14:14 [PATCH v2 1/3] x86: Use MOVL when reading segment registers Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 2/3] x86/hyperv: Use savesegment() instead of inline asm() to save " Uros Bizjak @ 2025-11-21 14:14 ` Uros Bizjak 2025-11-22 0:06 ` H. Peter Anvin 1 sibling, 1 reply; 5+ messages in thread From: Uros Bizjak @ 2025-11-21 14:14 UTC (permalink / raw) To: linux-hyperv, x86, linux-kernel Cc: Uros Bizjak, Michael Kelley, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin Unlike CALL instruction, VMMCALL does not push to the stack, so it's OK to allow the compiler to insert it before the frame pointer gets set up by the containing function. ASM_CALL_CONSTRAINT is for CALLs that must be inserted after the frame pointer is set up, so it is over-constraining here and can be removed. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Tested-by: Michael Kelley <mhklinux@outlook.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: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> --- v2: Expand commit message and include ASM_CALL_CONSTRAINT explanation --- arch/x86/hyperv/ivm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 7365d8f43181..be7fad43a88d 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -392,7 +392,7 @@ u64 hv_snp_hypercall(u64 control, u64 param1, u64 param2) register u64 __r8 asm("r8") = param2; asm volatile("vmmcall" - : "=a" (hv_status), ASM_CALL_CONSTRAINT, + : "=a" (hv_status), "+c" (control), "+d" (param1), "+r" (__r8) : : "cc", "memory", "r9", "r10", "r11"); -- 2.51.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn 2025-11-21 14:14 ` [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn Uros Bizjak @ 2025-11-22 0:06 ` H. Peter Anvin 2025-11-22 9:33 ` Uros Bizjak 0 siblings, 1 reply; 5+ messages in thread From: H. Peter Anvin @ 2025-11-22 0:06 UTC (permalink / raw) To: Uros Bizjak, linux-hyperv, x86, linux-kernel Cc: Michael Kelley, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen On November 21, 2025 6:14:11 AM PST, Uros Bizjak <ubizjak@gmail.com> wrote: >Unlike CALL instruction, VMMCALL does not push to the stack, so it's >OK to allow the compiler to insert it before the frame pointer gets >set up by the containing function. ASM_CALL_CONSTRAINT is for CALLs >that must be inserted after the frame pointer is set up, so it is >over-constraining here and can be removed. > >Signed-off-by: Uros Bizjak <ubizjak@gmail.com> >Tested-by: Michael Kelley <mhklinux@outlook.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: Thomas Gleixner <tglx@linutronix.de> >Cc: Ingo Molnar <mingo@redhat.com> >Cc: Borislav Petkov <bp@alien8.de> >Cc: Dave Hansen <dave.hansen@linux.intel.com> >Cc: "H. Peter Anvin" <hpa@zytor.com> >--- >v2: Expand commit message and include ASM_CALL_CONSTRAINT explanation >--- > arch/x86/hyperv/ivm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c >index 7365d8f43181..be7fad43a88d 100644 >--- a/arch/x86/hyperv/ivm.c >+++ b/arch/x86/hyperv/ivm.c >@@ -392,7 +392,7 @@ u64 hv_snp_hypercall(u64 control, u64 param1, u64 param2) > > register u64 __r8 asm("r8") = param2; > asm volatile("vmmcall" >- : "=a" (hv_status), ASM_CALL_CONSTRAINT, >+ : "=a" (hv_status), > "+c" (control), "+d" (param1), "+r" (__r8) > : : "cc", "memory", "r9", "r10", "r11"); > I think it would be good to have a comment at the point where ASM_CALL_CONSTRAINT is defined explaining its proper use. Specifically, instructions like syscall, vmcall, vmfunc, vmmcall, int xx and VM-specific escape instructions are not "calls" because they either don't modify the stack or create an exception frame (kernel) or signal frame (user space) which is completely special. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn 2025-11-22 0:06 ` H. Peter Anvin @ 2025-11-22 9:33 ` Uros Bizjak 0 siblings, 0 replies; 5+ messages in thread From: Uros Bizjak @ 2025-11-22 9:33 UTC (permalink / raw) To: H. Peter Anvin Cc: linux-hyperv, x86, linux-kernel, Michael Kelley, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen On Sat, Nov 22, 2025 at 1:06 AM H. Peter Anvin <hpa@zytor.com> wrote: > > On November 21, 2025 6:14:11 AM PST, Uros Bizjak <ubizjak@gmail.com> wrote: > >Unlike CALL instruction, VMMCALL does not push to the stack, so it's > >OK to allow the compiler to insert it before the frame pointer gets > >set up by the containing function. ASM_CALL_CONSTRAINT is for CALLs > >that must be inserted after the frame pointer is set up, so it is > >over-constraining here and can be removed. > > > >Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > >Tested-by: Michael Kelley <mhklinux@outlook.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: Thomas Gleixner <tglx@linutronix.de> > >Cc: Ingo Molnar <mingo@redhat.com> > >Cc: Borislav Petkov <bp@alien8.de> > >Cc: Dave Hansen <dave.hansen@linux.intel.com> > >Cc: "H. Peter Anvin" <hpa@zytor.com> > >--- > >v2: Expand commit message and include ASM_CALL_CONSTRAINT explanation > >--- > > arch/x86/hyperv/ivm.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > >diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c > >index 7365d8f43181..be7fad43a88d 100644 > >--- a/arch/x86/hyperv/ivm.c > >+++ b/arch/x86/hyperv/ivm.c > >@@ -392,7 +392,7 @@ u64 hv_snp_hypercall(u64 control, u64 param1, u64 param2) > > > > register u64 __r8 asm("r8") = param2; > > asm volatile("vmmcall" > >- : "=a" (hv_status), ASM_CALL_CONSTRAINT, > >+ : "=a" (hv_status), > > "+c" (control), "+d" (param1), "+r" (__r8) > > : : "cc", "memory", "r9", "r10", "r11"); > > > > I think it would be good to have a comment at the point where ASM_CALL_CONSTRAINT is defined explaining its proper use. > > Specifically, instructions like syscall, vmcall, vmfunc, vmmcall, int xx and VM-specific escape instructions are not "calls" because they either don't modify the stack or create an exception frame (kernel) or signal frame (user space) which is completely special. The existing comment already mentions CALL instruction only: /* * This output constraint should be used for any inline asm which has a "call" * instruction. Otherwise the asm may be inserted before the frame pointer * gets set up by the containing function. If you forget to do this, objtool * may print a "call without frame pointer save/setup" warning. */ Uros. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-22 9:33 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-21 14:14 [PATCH v2 1/3] x86: Use MOVL when reading segment registers Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 2/3] x86/hyperv: Use savesegment() instead of inline asm() to save " Uros Bizjak 2025-11-21 14:14 ` [PATCH v2 3/3] x86/hyperv: Remove ASM_CALL_CONSTRAINT with VMMCALL insn Uros Bizjak 2025-11-22 0:06 ` H. Peter Anvin 2025-11-22 9:33 ` Uros Bizjak
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).