All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Mathias Krause <minipli@grsecurity.net>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Chao Gao <chao.gao@intel.com>,
	kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v2 13/13] x86: Avoid top-most page for vmalloc on x86-64
Date: Fri, 12 Sep 2025 07:37:54 -0700	[thread overview]
Message-ID: <aMQwQnGpNzutdr-q@google.com> (raw)
In-Reply-To: <20250626073459.12990-14-minipli@grsecurity.net>

On Thu, Jun 26, 2025, Mathias Krause wrote:
> The x86-64 implementation if setup_mmu() doesn't initialize 'vfree_top'
> and leaves it at its zero-value. This isn't wrong per se, however, it
> leads to odd configurations when the first vmalloc/vmap page gets
> allocated. It'll be the very last page in the virtual address space --
> which is an interesting corner case -- but its boundary will probably
> wrap. It does so, for CET's shadow stack, at least, which loads the
> shadow stack pointer with the base address of the mapped page plus its
> size, i.e. 0xffffffff_fffff000 + 4096, which wraps to 0x0.
> 
> The CPU seems to handle such configurations just fine. However, it feels
> odd to set the shadow stack pointer to "NULL".
> 
> To avoid the wrapping, ignore the top most page by initializing
> 'vfree_top' to just one page below.
> 
> Reviewed-by: Chao Gao <chao.gao@intel.com>
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> ---
> v2:
> - change comment in x86/lam.c too
> 
>  lib/x86/vm.c |  2 ++
>  x86/lam.c    | 10 +++++-----
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/x86/vm.c b/lib/x86/vm.c
> index 90f73fbb2dfd..27e7bb4004ef 100644
> --- a/lib/x86/vm.c
> +++ b/lib/x86/vm.c
> @@ -191,6 +191,8 @@ void *setup_mmu(phys_addr_t end_of_memory, void *opt_mask)
>          end_of_memory = (1ul << 32);  /* map mmio 1:1 */
>  
>      setup_mmu_range(cr3, 0, end_of_memory);
> +    /* skip the last page for out-of-bound and wrap-around reasons */
> +    init_alloc_vpage((void *)(~(PAGE_SIZE - 1)));

This breaks the eventinj test (leads to SHUTDOWN).  I haven't spent any time
trying to figure out why.

  reply	other threads:[~2025-09-12 14:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-26  7:34 [kvm-unit-tests PATCH v2 00/13] Improve CET tests Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 01/13] x86: cet: Pass virtual addresses to invlpg Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 02/13] x86: cet: Remove unnecessary memory zeroing for shadow stack Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 03/13] x86: cet: Directly check for #CP exception in run_in_user() Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 04/13] x86: cet: Validate #CP error code Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 05/13] x86: cet: Use report_skip() Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 06/13] x86: cet: Drop unnecessary casting Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 07/13] x86: cet: Validate writing unaligned values to SSP MSR causes #GP Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 08/13] x86: cet: Validate CET states during VMX transitions Mathias Krause
2025-07-11  8:51   ` Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 09/13] x86: cet: Make shadow stack less fragile Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 10/13] x86: cet: Simplify IBT test Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 11/13] x86: cet: Use symbolic values for the #CP error codes Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 12/13] x86: cet: Test far returns too Mathias Krause
2025-06-26  7:34 ` [kvm-unit-tests PATCH v2 13/13] x86: Avoid top-most page for vmalloc on x86-64 Mathias Krause
2025-09-12 14:37   ` Sean Christopherson [this message]
2025-09-14 11:05     ` Chao Gao

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=aMQwQnGpNzutdr-q@google.com \
    --to=seanjc@google.com \
    --cc=chao.gao@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=minipli@grsecurity.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.