From: Sean Christopherson <seanjc@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, jmattson@google.com
Subject: Re: [kvm-unit-tests PATCH 2/3] x86: Align L2's stacks
Date: Thu, 9 Dec 2021 20:06:54 +0000 [thread overview]
Message-ID: <YbJh3mBZ0c86E7TU@google.com> (raw)
In-Reply-To: <20211209182624.2316453-3-aaronlewis@google.com>
On Thu, Dec 09, 2021, Aaron Lewis wrote:
> Setting the stack to PAGE_SIZE - 1 sets the stack to being 1-byte
LOL, nice. It's also pointless because any access larger than a byte that occurs
without first adjusting the stack will explode.
> aligned, which fails in usermode with alignment checks enabled (ie: with
> flags cr0.am set and eflags.ac set). This was causing an #AC in
> usermode.c when preparing to call the callback in run_in_user().
> Aligning the stack fixes the issue.
>
> For the purposes of fixing the #AC in usermode.c the stack has to be
> aligned to at least an 8-byte boundary. Setting it to a page aligned
> boundary ensures any stack alignment requirements are met as x86_64
> stacks generally want to be 16-byte aligned.
>
> Signed-off-by: Aaron Lewis <aaronlewis@google.com>
> ---
> x86/vmx.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/x86/vmx.c b/x86/vmx.c
> index 6dc9a55..44f4861 100644
> --- a/x86/vmx.c
> +++ b/x86/vmx.c
> @@ -1242,7 +1242,7 @@ static void init_vmcs_guest(void)
> vmcs_write(GUEST_CR4, guest_cr4);
> vmcs_write(GUEST_SYSENTER_CS, KERNEL_CS);
> vmcs_write(GUEST_SYSENTER_ESP,
> - (u64)(guest_syscall_stack + PAGE_SIZE - 1));
> + (u64)(guest_syscall_stack + PAGE_SIZE));
> vmcs_write(GUEST_SYSENTER_EIP, (u64)(&entry_sysenter));
> vmcs_write(GUEST_DR7, 0);
> vmcs_write(GUEST_EFER, rdmsr(MSR_EFER));
> @@ -1292,7 +1292,7 @@ static void init_vmcs_guest(void)
>
> /* 26.3.1.4 */
> vmcs_write(GUEST_RIP, (u64)(&guest_entry));
> - vmcs_write(GUEST_RSP, (u64)(guest_stack + PAGE_SIZE - 1));
> + vmcs_write(GUEST_RSP, (u64)(guest_stack + PAGE_SIZE));
Rather than do the math here, which looks arbitrary at first blance, what about
adjusting on allocation and renaming the variables accordingly? E.g.
diff --git a/x86/vmx.c b/x86/vmx.c
index 6dc9a55..bc8be77 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -1388,8 +1388,8 @@ void init_vmx(u64 *vmxon_region)
static void alloc_bsp_vmx_pages(void)
{
bsp_vmxon_region = alloc_page();
- guest_stack = alloc_page();
- guest_syscall_stack = alloc_page();
+ guest_stack_top = alloc_page() + PAGE_SIZE;
+ guest_syscall_stack_top = alloc_page() + PAGE_SIZE;
vmcs_root = alloc_page();
}
> vmcs_write(GUEST_RFLAGS, X86_EFLAGS_FIXED);
>
> /* 26.3.1.5 */
> --
> 2.34.1.173.g76aa8bc2d0-goog
>
next prev parent reply other threads:[~2021-12-09 20:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-09 18:26 [kvm-unit-tests PATCH 0/3] Add additional testing for routing L2 exceptions Aaron Lewis
2021-12-09 18:26 ` [kvm-unit-tests PATCH 1/3] x86: Fix a #GP from occurring in usermode's exception handlers Aaron Lewis
2021-12-09 20:04 ` Sean Christopherson
2021-12-09 18:26 ` [kvm-unit-tests PATCH 2/3] x86: Align L2's stacks Aaron Lewis
2021-12-09 20:06 ` Sean Christopherson [this message]
2021-12-09 18:26 ` [kvm-unit-tests PATCH 3/3] x86: Add test coverage for the routing logic when exceptions occur in L2 Aaron Lewis
2021-12-09 21:15 ` Sean Christopherson
2021-12-14 1:19 ` Aaron Lewis
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=YbJh3mBZ0c86E7TU@google.com \
--to=seanjc@google.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/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