From: Sean Christopherson <seanjc@google.com>
To: Vishal Annapurve <vannapurve@google.com>
Cc: pbonzini@redhat.com, dave.hansen@linux.intel.com,
rick.p.edgecombe@intel.com, dapeng1.mi@linux.intel.com,
mizhang@google.com, kai.huang@intel.com, jmattson@google.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/1] KVM: x86: Introduce has_protected_pmu state for TDX VMs
Date: Tue, 12 May 2026 15:47:02 -0700 [thread overview]
Message-ID: <agOt5nzP6pm5yyOZ@google.com> (raw)
In-Reply-To: <20260507212957.2629561-1-vannapurve@google.com>
On Thu, May 07, 2026, Vishal Annapurve wrote:
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0a1b63c63d1a..c248abb0e2ab 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6909,6 +6909,13 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
> if (!enable_pmu || (cap->args[0] & ~KVM_CAP_PMU_VALID_MASK))
> break;
>
> + if (kvm->arch.has_protected_pmu) {
> + WARN_ON_ONCE(kvm->arch.enable_pmu);
> + if (cap->args[0] == KVM_PMU_CAP_DISABLE)
> + r = 0;
> + break;
Sashiko: 3, Sean: 0
: Does this code bypass standard lifecycle validation?
:
: For standard VMs, KVM strictly enforces that PMU capabilities can only be
: configured before any vCPUs are created, returning -EINVAL otherwise. The newly
: added block for TDX VMs short-circuits this logic, returning 0 unconditionally
: when disabling the PMU, regardless of whether vCPUs have been created.
: Could this introduce a UAPI inconsistency where the same userspace sequence
: could fail on standard VMs but silently succeed on TDX VMs, potentially
: hiding VMM initialization order bugs?
That potential issue crossed my mind when first trying to figure out how to allow
KVM_PMU_CAP_DISABLE for protected PMUs, but then SQUIRREL!!!
I think my original reaction is the way to go: add extra validation for protected
PMUs (reject everything except CAP_DISABLE), but otherwise let the normal flow do
it's thing.
Completely untested, but I think this would do what we want?
case KVM_CAP_PMU_CAPABILITY:
r = -EINVAL;
if (!enable_pmu || (cap->args[0] & ~KVM_CAP_PMU_VALID_MASK))
break;
if (kvm->arch.has_protected_pmu &&
cap->args[0] != KVM_PMU_CAP_DISABLE)
break;
mutex_lock(&kvm->lock);
if (!kvm->created_vcpus && !kvm->arch.created_mediated_pmu) {
kvm->arch.enable_pmu = !(cap->args[0] & KVM_PMU_CAP_DISABLE);
r = 0;
}
mutex_unlock(&kvm->lock);
break;
next prev parent reply other threads:[~2026-05-12 22:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 21:29 [PATCH v4 1/1] KVM: x86: Introduce has_protected_pmu state for TDX VMs Vishal Annapurve
2026-05-12 22:47 ` Sean Christopherson [this message]
2026-05-13 0:15 ` Vishal Annapurve
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=agOt5nzP6pm5yyOZ@google.com \
--to=seanjc@google.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=jmattson@google.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mizhang@google.com \
--cc=pbonzini@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=vannapurve@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox