From: "Huang, Kai" <kai.huang@intel.com>
To: "maz@kernel.org" <maz@kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"oupton@kernel.org" <oupton@kernel.org>,
"seanjc@google.com" <seanjc@google.com>
Cc: "yuzenghui@huawei.com" <yuzenghui@huawei.com>,
"suzuki.poulose@arm.com" <suzuki.poulose@arm.com>,
"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"joey.gouly@arm.com" <joey.gouly@arm.com>,
"seiden@linux.ibm.com" <seiden@linux.ibm.com>
Subject: Re: [PATCH] KVM: Never clear KVM_REQ_VM_DEAD from a vCPU's requests
Date: Mon, 10 Aug 2026 01:29:43 +0000 [thread overview]
Message-ID: <4122846f2c7a9b8025aa9915162ae605d5853ed4.camel@intel.com> (raw)
In-Reply-To: <20260806214618.82180-1-seanjc@google.com>
On Thu, 2026-08-06 at 14:46 -0700, Sean Christopherson wrote:
> Use kvm_test_request() instead of kvm_check_request() when querying
> KVM_REQ_VM_DEAD, i.e. don't clear KVM_REQ_VM_DEAD, as the entire purpose
> of KVM_REQ_VM_DEAD is to prevent the vCPU from enterring the guest ever
> again, even if userspace insists on redoing KVM_RUN.
>
> Ensuring KVM_REQ_VM_DEAD is never cleared will allow relaxing KVM's rule
> that ioctls can't be invoked on dead VMs, to only disallow ioctls if the
> VM is bugged, i.e. if KVM hit a KVM_BUG_ON().
>
> Opportunistically add compile-time assertions to guard against clearing
> KVM_REQ_VM_DEAD through the standard APIs.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
FWIW, I build tested that both gcc and clang could build successfully (both -O2
and -Os).
[...]
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2324,13 +2324,18 @@ static inline bool kvm_test_request(int req, struct kvm_vcpu *vcpu)
> return test_bit(req & KVM_REQUEST_MASK, (void *)&vcpu->requests);
> }
>
> -static inline void kvm_clear_request(int req, struct kvm_vcpu *vcpu)
> +static __always_inline void kvm_clear_request(int req, struct kvm_vcpu *vcpu)
> {
> + BUILD_BUG_ON(req == KVM_REQ_VM_DEAD);
> +
> clear_bit(req & KVM_REQUEST_MASK, (void *)&vcpu->requests);
> }
>
> -static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
> +static __always_inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu)
> {
> + /* Once a VM is dead, it needs to stay dead. */
> + BUILD_BUG_ON(req == KVM_REQ_VM_DEAD);
> +
> if (kvm_test_request(req, vcpu)) {
> kvm_clear_request(req, vcpu);
>
Nit: AFAICT the change to __always_inline is to avoid build failure. Perhaps
explicitly mention this in changelog?
Btw, I also tried building the kernel after reverting __always_inline to plain
inline, but indeed got build error when using clang (clang failed with both -O2
and -Os, but gcc was fine for both, though).
prev parent reply other threads:[~2026-08-10 1:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 21:46 [PATCH] KVM: Never clear KVM_REQ_VM_DEAD from a vCPU's requests Sean Christopherson
2026-08-07 8:20 ` Marc Zyngier
2026-08-10 1:29 ` Huang, Kai [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=4122846f2c7a9b8025aa9915162ae605d5853ed4.camel@intel.com \
--to=kai.huang@intel.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.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