Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Like Xu <like.xu.linux@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Oliver Upton <oupton@google.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Don't patch L2's hypercall if L1 intercepts #UD
Date: Thu, 12 Nov 2026 08:39:07 -0800	[thread overview]
Message-ID: <avXrdHhup76EoDQ8@google.com> (raw)
In-Reply-To: <20261112132512.68348-1-likexu@tencent.com>

On Thu, Nov 12, 2026, Like Xu wrote:
> From: Like Xu <likexu@tencent.com>
> 
> The fix_hypercall_test selftest fails when run in an L1 VM on an AMD host:
> 
>   ret == (u64)-EFAULT
> 
> On SVM, L0 always intercepts #UD in vmcb01, so nested_svm_exit_special()
> claims every #UD from L2 for L0, before L1's intercepts are consulted.
> L0 then emulates L2's VMCALL and, based on the quirk that L0 userspace
> configured for L1, patches it to VMMCALL. This ignores L1's decision to
> disable KVM_X86_QUIRK_FIX_HYPERCALL_INSN for L2.
> 
> Synthesize #UD instead if the vCPU is in L2 and L1 intercepts #UD, so
> the nested exception machinery reflects it to L1.  Keep patching L2's
> instruction when L1 doesn't intercept #UD, as existing userspace relies
> on it, e.g. nested SVM selftests execute VMCALL in L2 and expect L1 to
> see SVM_EXIT_VMMCALL.
> 
> Fixes: f1a9761fbb00 ("KVM: x86: Allow userspace to opt out of hypercall patching")
> Signed-off-by: Like Xu <likexu@tencent.com>

I think I'd rather fix this by skipping the selftest, e.g.

diff --git a/tools/testing/selftests/kvm/x86/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86/fix_hypercall_test.c
index f11fcc520f24..bb2fdd622538 100644
--- a/tools/testing/selftests/kvm/x86/fix_hypercall_test.c
+++ b/tools/testing/selftests/kvm/x86/fix_hypercall_test.c
@@ -135,6 +135,7 @@ KVM_ONE_VCPU_TEST(fix_hypercall, disable_quirk, guest_main)
 
 int main(int argc, char *argv[])
 {
+	TEST_REQUIRE(!this_cpu_has(X86_FEATURE_HYPERVISOR));
 	TEST_REQUIRE(kvm_check_cap(KVM_CAP_DISABLE_QUIRKS2) & KVM_X86_QUIRK_FIX_HYPERCALL_INSN);
 
 	return test_harness_run(argc, argv);

I doubt there's a deployment that would actually break if L0 stopped patching L2,
but the right solution here really is to disable the quirk in L0.  Any risk of
breaking existing setups, however small, just isn't worth it IMO.

      reply	other threads:[~2026-11-12 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 13:25 [PATCH] KVM: x86: Don't patch L2's hypercall if L1 intercepts #UD Like Xu
2026-11-12 16:39 ` 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=avXrdHhup76EoDQ8@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=like.xu.linux@gmail.com \
    --cc=oupton@google.com \
    --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