Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: sashiko-reviews@lists.linux.dev,
	Paolo Bonzini <pbonzini@redhat.com>,
	 kvm@vger.kernel.org
Subject: Re: [PATCH 4/4] KVM: selftests: Check VMPTRLD with active eVMCS
Date: Mon, 17 Aug 2026 10:06:12 -0700	[thread overview]
Message-ID: <aoM_hK4Vn-xr7NvO@google.com> (raw)
In-Reply-To: <87lda5kmye.fsf@redhat.com>

On Mon, Aug 17, 2026, Vitaly Kuznetsov wrote:
> sashiko-bot@kernel.org writes:
> 
> > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> > - [Medium] The hardcoded `VMPTRLD_INSN_SIZE` of 5 bytes is brittle
> > because `vmptrld` is executed using an inline assembly memory operand
> > constraint (`"m"`), which results in a variable-sized instruction
> > depending on compiler optimizations and register allocation.
> 
> True that, but afair we don't currently have an instruction decoder in
> selftests. I see three ways to move forward:
> 
> - Calculate the size of the instruction with two labels, something like
>   (untested):
> 
>     static inline int __vmptrld(u64 vmcs_pa, int *insn_size)
>     {
>             u8 ret;
> 
>             __asm__ __volatile__ ("movl $(2f-1f), %[size];"
>                                   "1: vmptrld %[pa]; 2:"
>                                   "setna %[ret]"
>                     : [ret]"=rm"(ret), [size]"=m"(*insn_size)
>                     : [pa]"m"(vmcs_pa)
>                     : "cc", "memory");
> 
>             return ret;
>     }
> 
>   and use insn_size in the tests.
> 
> - Stuf __vmptrld() with NOPs after vmptrld and keep the constant jump,
>   just make it loner (e.g. 10 bytes should realistically be enough).
> 
> - Make peace with the fragility (it's just a selftest after all) and
>   leave a comment in vmptrld() that changing the asm there make break
>   the assumption.

Option D: use KVM_ASM_SAFE() to do the heavy lifting.  Completely untested, but
something like so:

static inline int vmptrst_safe(u64 *value)
{
	u64 error_code;
	u8 vector;
	int ret;

	asm volatile(KVM_ASM_SAFE("vmptrst %[value]")
		     "\n\tsetna %[ret]"
		     : KVM_ASM_SAFE_OUTPUTS(vector, error_code),
		       [value]"=m"(*value), [ret]"=rm"(ret)
		     :
		     : "cc", "memory");

	return vector ? vector : ret ? -EINVAL : 0;
}

> Any preferences? Personally, I'm feeling adventurous and can go with the
> first one - calculating the exact size with labels.

      reply	other threads:[~2026-08-17 17:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 16:22 [PATCH 0/4] KVM: nVMX: Adjust VMPTRLD/VMPTRST behavior with active eVMCS Vitaly Kuznetsov
2026-08-14 16:22 ` [PATCH 1/4] KVM: nVMX: Make VMPTRLD result in #UD when eVMCS is used Vitaly Kuznetsov
2026-08-14 16:31   ` sashiko-bot
2026-08-14 16:43     ` Sean Christopherson
2026-08-14 16:22 ` [PATCH 2/4] KVM: nVMX: Make VMPTRST return eVMCS GPA when it " Vitaly Kuznetsov
2026-08-14 16:32   ` sashiko-bot
2026-08-14 16:44     ` Sean Christopherson
2026-08-14 16:22 ` [PATCH 3/4] KVM: selftests: Adapt to the updated VMPTRST behavior when eVMCS " Vitaly Kuznetsov
2026-08-14 16:31   ` sashiko-bot
2026-08-14 16:22 ` [PATCH 4/4] KVM: selftests: Check VMPTRLD with active eVMCS Vitaly Kuznetsov
2026-08-14 16:31   ` sashiko-bot
2026-08-17 11:26     ` Vitaly Kuznetsov
2026-08-17 17:06       ` Sean Christopherson [this message]

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=aoM_hK4Vn-xr7NvO@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkuznets@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