mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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:24:47 +0000	[thread overview]
Message-ID: <ccc4f915-3623-406e-8df6-f468427264f4@citrix.com> (raw)
In-Reply-To: <a7e1b5c1-f933-44e5-99ec-a83b27fcf81e@app.fastmail.com>

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.

The segment register instructions are somewhat weird even by x86 standards.

They should always be written as 32-bit operations (movl, and %eax),
removing the operand size prefix which is not necessary for these
instructions to function correctly.

It's absolutely marginal, but it does always pain me to read asm like
this and see the myth of how to access segment selectors being repeated
time and time again.

~Andrew

  reply	other threads:[~2026-02-26 13:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26  9:50 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 [this message]
2026-02-26 13:29       ` Ard Biesheuvel
2026-02-26 13:52         ` Andrew Cooper
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=ccc4f915-3623-406e-8df6-f468427264f4@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

all inboxes | Powered by JetHome®