From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Borislav Petkov <bp@alien8.de>,
dave.hansen@linux.intel.com, decui@microsoft.com,
haiyangz@microsoft.com, "H . Peter Anvin" <hpa@zytor.com>,
kys@microsoft.com, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org, Long Li <longli@microsoft.com>,
Ingo Molnar <mingo@redhat.com>,
Mukesh Rathor <mrathor@linux.microsoft.com>,
Thomas Gleixner <tglx@kernel.org>,
Uros Bizjak <ubizjak@gmail.com>,
wei.liu@kernel.org
Subject: Re: [RFT PATCH] x86/hyperv: Use __naked attribute to fix stackless C function
Date: Thu, 26 Feb 2026 13:52:58 +0000 [thread overview]
Message-ID: <aad6d8f5-67e7-4ced-b4b3-ecea24a44acb@citrix.com> (raw)
In-Reply-To: <2ee05c7f-60cb-445b-b761-562385c4e6ba@app.fastmail.com>
On 26/02/2026 1:29 pm, Ard Biesheuvel wrote:
>
> On Thu, 26 Feb 2026, at 14:24, Andrew Cooper wrote:
>> On 26/02/2026 1:07 pm, Ard Biesheuvel wrote:
>>> On Thu, 26 Feb 2026, at 13:01, Andrew Cooper wrote:
>>>>> @@ -133,49 +150,36 @@ static noinline void hv_crash_clear_kernpt(void) * available. We restore kernel GDT, and rest of the context, and continue
>>>>> * to kexec.
>>>>> */
>>>>> -static asmlinkage void __noreturn hv_crash_c_entry(void) +static void
>>>>> __naked hv_crash_c_entry(void) {
>>>>> - struct hv_crash_ctxt *ctxt = &hv_crash_ctxt; - /* first thing, restore kernel gdt */
>>>>> - native_load_gdt(&ctxt->gdtr); + asm volatile("lgdt %0" : : "m"
>>>>> (hv_crash_ctxt.gdtr));
>>>>> - asm volatile("movw %%ax, %%ss" : : "a"(ctxt->ss)); - asm
>>>>> volatile("movq %0, %%rsp" : : "m"(ctxt->rsp)); + asm volatile("movw
>>>>> %%ax, %%ss" : : "a"(hv_crash_ctxt.ss)); + asm volatile("movq %0,
>>>>> %%rsp" : : "m"(hv_crash_ctxt.rsp));
>>>> I know this is pre-existing, but the asm here is poor.
>>>>
>>>> All segment registers loads can have a memory operand, rather than
>>>> forcing through %eax, which in turn reduces the setup logic the compiler
>>>> needs to emit.
>>>>
>>>> Something like this:
>>>>
>>>> "movl %0, %%ss" : : "m"(hv_crash_ctxt.ss)
>>>>
>>>> ought to do.
>>>>
>>> 'movw' seems to work, yes.
>> movw works, but is sub-optimal.
>>
> Can you give an asm example where movl with a segment register is accepted by the assembler? I only managed that with movw, hence my comment.
Oh lovely, that looks like a binutils bug, but I bet it comes from not
realising that `mov sreg` is different to the more general mov forms.
Using no suffix will emit the optimal instruction without a warning.
https://godbolt.org/z/GYKs31Gqn
~Andrew
next prev parent reply other threads:[~2026-02-26 13:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 9:50 [RFT PATCH] x86/hyperv: Use __naked attribute to fix stackless C function Ard Biesheuvel
2026-02-26 10:35 ` Uros Bizjak
2026-02-26 10:48 ` Ard Biesheuvel
2026-02-26 10:51 ` Uros Bizjak
2026-02-26 12:01 ` Andrew Cooper
2026-02-26 13:07 ` Ard Biesheuvel
2026-02-26 13:24 ` Andrew Cooper
2026-02-26 13:29 ` Ard Biesheuvel
2026-02-26 13:52 ` Andrew Cooper [this message]
2026-02-27 21:50 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aad6d8f5-67e7-4ced-b4b3-ecea24a44acb@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=mingo@redhat.com \
--cc=mrathor@linux.microsoft.com \
--cc=tglx@kernel.org \
--cc=ubizjak@gmail.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox