All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 1/6] KVM: x86: Extract VMX's unhandleable emulation check to common x86
Date: Tue, 28 Jul 2026 00:58:46 +0000	[thread overview]
Message-ID: <20260728005847.6EF2F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728004351.887076-2-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The mandatory `.vcpu_pre_run` hook is conditionally assigned `NULL` for VMX on non-TDX builds, causing a WARN on module load and breaking vCPU execution.
--

--- Patch [1]: [PATCH v4 1/6] KVM: x86: Extract VMX's unhandleable emulation check to common x86 ---
commit 1ae0061cc0844907be897cd2b6f318482c190f81
Author: Sean Christopherson <seanjc@google.com>

KVM: x86: Extract VMX's unhandleable emulation check to common x86

Expose VMX's check for unhandleable emulation as its own kvm_x86_ops hook,
and move the actual pre-KVM_RUN check into common x86.  This will allow
sharing the core logic with KVM's RSM emulation without needed to add a
post-RSM hook, and is a step towards removing the .vcpu_pre_run() hook
entirely.

> diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
> index 04f986e3d439a..924a629c21e2f 100644
> --- a/arch/x86/kvm/vmx/main.c
> +++ b/arch/x86/kvm/vmx/main.c
[ ... ]
> @@ -939,11 +949,12 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
>  	.flush_tlb_gva = vt_op(flush_tlb_gva),
>  	.flush_tlb_guest = vt_op(flush_tlb_guest),
>  
> -	.vcpu_pre_run = vt_op(vcpu_pre_run),
> +	.vcpu_pre_run = vt_op_tdx_only(vcpu_pre_run),

[Severity: High]
Does this conditionally assigned NULL pointer cause a module load warning on
systems without CONFIG_KVM_INTEL_TDX enabled?

Since vcpu_pre_run is declared as a mandatory hook (KVM_X86_OP(vcpu_pre_run))
in arch/x86/include/asm/kvm-x86-ops.h, setting it to NULL when TDX is
disabled will trigger a WARN in kvm_ops_update().

[ ... ]

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 960ff7fcd8dba..8c3efc1be1fa4 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8867,6 +8867,11 @@ static int kvm_x86_vcpu_pre_run(struct kvm_vcpu *vcpu)
>  	    !kvm_apic_init_sipi_allowed(vcpu))
>  		return -EINVAL;
>  
> +	if (kvm_x86_call(unhandleable_emulation_required)(vcpu)) {
> +		kvm_prepare_emulation_failure_exit(vcpu);
> +		return 0;
> +	}
> +
>  	return kvm_x86_call(vcpu_pre_run)(vcpu);

[Severity: High]
Could this break KVM_RUN by returning an uninitialized register value when TDX
is disabled?

When kvm_x86_vcpu_pre_run() calls this static call with a NULL target, the
static call machinery will patch the call site with a NOP or RET. The CPU will
execute the NOP and fall through, leaving the return value in the RAX register
unmodified.

Since the preceding call to unhandleable_emulation_required() is a boolean
function that typically returns false (setting AL=0), the uninitialized RAX
will evaluate as <= 0. This would cause kvm_arch_vcpu_ioctl_run() to
immediately exit to userspace instead of entering the guest.

>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728004351.887076-1-seanjc@google.com?part=1

  reply	other threads:[~2026-07-28  0:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  0:43 [PATCH v4 0/6] KVM: nVMX: Synthesize SHUTDOWN on RSM with bad state Sean Christopherson
2026-07-28  0:43 ` [PATCH v4 1/6] KVM: x86: Extract VMX's unhandleable emulation check to common x86 Sean Christopherson
2026-07-28  0:58   ` sashiko-bot [this message]
2026-07-28  1:01     ` Sean Christopherson
2026-07-28  0:43 ` [PATCH v4 2/6] KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation Sean Christopherson
2026-07-28  0:43 ` [PATCH v4 3/6] KVM: x86: Rework kvm_x86_ops.vcpu_pre_run() into .vcpu_needs_initialization() Sean Christopherson
2026-07-28  0:43 ` [PATCH v4 4/6] KVM: selftests: Use port 0x80 in invalid nVMX guest state test Sean Christopherson
2026-07-28  0:43 ` [PATCH v4 5/6] KVM: selftests: Refactor invalid nVMX state test to prepare for RSM testcase Sean Christopherson
2026-07-28  0:51   ` sashiko-bot
2026-07-28  0:43 ` [PATCH v4 6/6] KVM: selftests: Extend the invalid nVMX guest state test to cover RSM Sean Christopherson
2026-07-28  3:01   ` Hao Zhang

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=20260728005847.6EF2F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.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.