qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Ard Biesheuvel <ardb@kernel.org>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Eduardo Habkost <eduardo@habkost.net>
Subject: Re: [RFC PATCH] target/i386: Truncate ESP when exiting from long mode
Date: Wed, 26 Jul 2023 08:01:42 -0700	[thread overview]
Message-ID: <67a8967e-338a-fbd1-1c06-d5a35f2db509@linaro.org> (raw)
In-Reply-To: <20230726081710.1051126-1-ardb@kernel.org>

On 7/26/23 01:17, Ard Biesheuvel wrote:
> While working on some EFI boot changes for Linux/x86, I noticed that TCG deviates from
> bare metal when it comes to how it handles the value of the stack pointer register RSP
> when dropping out of long mode.
> 
> On bare metal, RSP is truncated to 32 bits, even if the code that runs in 32-bit
> protected mode never uses the stack at all (and uses a long jump rather than long
> return to switch back to long mode). This means 64-bit code cannot rely on RSP
> surviving any excursions into 32-bit protected mode (with paging disabled).
> 
> Let's align TCG with this behavior, so that code that relies on RSP retaining its value
> does not inadvertently work while bare metal does not.
> 
> Observed on Intel Ice Lake cores.
> 
> Cc: Paolo Bonzini<pbonzini@redhat.com> Cc: Richard
> Henderson<richard.henderson@linaro.org> Cc: Eduardo Habkost<eduardo@habkost.net> 
> Link:https://lore.kernel.org/all/20230711091453.2543622-11-ardb@kernel.org/ 
> Signed-off-by: Ard Biesheuvel<ardb@kernel.org> --- I used this patch locally to
> reproduce an issue that was reported on Ice Lake but didn't trigger in my QEMU
> testing.
> 
> Hints welcome on where the architectural behavior is specified, and in particular,
> whether or not other 64-bit GPRs can be relied upon to preserve their full 64-bit
> length values.

No idea about chapter and verse, but it has the feel of being part and parcel with the
truncation of eip.  While esp is always special, I suspect that none of the GPRs can be 
relied on carrying all bits.

I'm happy with the change though, since similar behaviour can be observed on hw.

Acked-by: Richard Henderson <richard.henderson@linaro.org>


r~


  reply	other threads:[~2023-07-26 15:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26  8:17 [RFC PATCH] target/i386: Truncate ESP when exiting from long mode Ard Biesheuvel
2023-07-26 15:01 ` Richard Henderson [this message]
2023-07-27 17:56   ` Richard Henderson
2023-07-27 21:36     ` Ard Biesheuvel
2023-07-28  0:17       ` Richard Henderson
2023-07-28 16:47         ` Ard Biesheuvel
2023-07-31  8:35   ` Ard Biesheuvel

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=67a8967e-338a-fbd1-1c06-d5a35f2db509@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=ardb@kernel.org \
    --cc=eduardo@habkost.net \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).