From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B462417D1 for ; Thu, 9 Apr 2026 17:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775756891; cv=none; b=t6UptzKZL5+ccfrkWgRByXYrPt6c42bXT0HIA7MSklJzVDduCMs4MUvsPQEmzjKUYdwcMwdifXL1z59T4MQNYpYEd7yl7rxuHjS9qK8TN/yZBjmsJMSZlWE7YibQz7F/YI409hwGO3mC+dD27oPfCQ6V/jjCBX5/+Bd4hn1VlrI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775756891; c=relaxed/simple; bh=aIAfMrSA8cUJIyUiAkRbPYFZeiE3TInt/dDEE4o2+nk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Hnjp7Yus/ntDihm5nJB5LA6yXSnDefMVxP5UzYYUdJh+n1pmM+gf73Cy8TFgV+G9JUtihpd8L3RBgCEBqu1qmFYg1Nr7ed7e3eSq5Ru64HrPWm/481HiRAgaySoQiznNwZoVqOApmLU1GNQCtcc1rkbGfBHfS+MbY5u/BTPY3sI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WalItd6m; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WalItd6m" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82c646e980bso836062b3a.0 for ; Thu, 09 Apr 2026 10:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775756889; x=1776361689; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=ACR+kdrs5Iw2VxQZkb2RkoTFQ3C4xCdBdInTN5Gc/ZE=; b=WalItd6mH1nFFid5c/SA+NKPcQqok96YvavJjhZ8Sl6rXDvkqNsGm8V/5KUIZkJ5cb 33C8FuHcU2FpVzBH7g5h3rm+dRo8iasA8uF8xK4Ez3RLfX9PivmttSpIninX3NsHO1bx IP/Dc470ybE1Xw7AWsU4F/j+Ujyhvdsu+O66SPfBzgQHTJ8GKsr/7yxChkT8uTFtHdv0 AHYn4N5x5vB9eCvitLWPRp5f2Cl9ZQUpyh1L1pEI6qbEzkybD3NALLr+oujaqKqHevuF lYQWlUu1s+MNOWwasvqHwUwZi9BxeRNfTLWyk1D2Xjpzzd6RFs1twFVQBquuI0sY53kM Milw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775756889; x=1776361689; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=ACR+kdrs5Iw2VxQZkb2RkoTFQ3C4xCdBdInTN5Gc/ZE=; b=jpQl73RcSzWSYuRKShwSaZBoyEx8byoWnxEaYmTUXFvSWpTM67+wWrmUxgZXjCr2aB Y5w2qjEdV/BJLnPTMDArFezVdy+e9Swse75p1Q1k0wsqp8VJNfIgiM66PgwMDBubLu5G JrPMWbKJwq/sNcxigmf2jbCijb827z95eybjyZJ2gJeqyWrbkQhxfhdi2E0AQUZEnHto MOgDFQj1iEZxWoGHeRcqOyUajFJB0j4aNyj9AWzOcz9nOz4S8EfDIkrqXYkMktdyTyGu AJHmJOxHMtNXFfP6ONvxHPo4QPxHsnTV0sMtr9cM5gz0rJObk3M49R92V3Ult+9trjdm ZKIQ== X-Forwarded-Encrypted: i=1; AJvYcCWnGP5Ng3QOK0NEESEO8Ajtd9nDkfcl5MO13xOC2QbW4Xew86KnMcrk9PdmERQ8WUH+SurlrnszFLEnR9M=@vger.kernel.org X-Gm-Message-State: AOJu0YzW4VwD8cZsWZYCt1SHtCXR2sVyrKDlAGDCE67oWeKdgx7Qvocj rfXPpnFMr04vCKtFQeGYjHsz3YRhq87uHPUhOhK79rM8k/zaxWjN8Rk99D4qNbQABLtcfPs9u8T 44lk5IQ== X-Received: from pfbjr29.prod.google.com ([2002:a05:6a00:915d:b0:82c:63f8:59dd]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3987:b0:81f:3afe:281e with SMTP id d2e1a72fcca58-82f0c12fbd5mr185066b3a.3.1775756888433; Thu, 09 Apr 2026 10:48:08 -0700 (PDT) Date: Thu, 9 Apr 2026 10:48:05 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260326031150.3774017-1-yosry@kernel.org> <20260326031150.3774017-5-yosry@kernel.org> Message-ID: Subject: Re: [PATCH v4 4/6] KVM: x86/pmu: Re-evaluate Host-Only/Guest-Only on nested SVM transitions From: Sean Christopherson To: Jim Mattson Cc: Yosry Ahmed , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 09, 2026, Jim Mattson wrote: > On Thu, Apr 9, 2026 at 10:22=E2=80=AFAM Sean Christopherson wrote: > > > > On Wed, Apr 08, 2026, Jim Mattson wrote: > > > On Wed, Mar 25, 2026 at 8:12=E2=80=AFPM Yosry Ahmed wrote: > > > > diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h > > > > index bdbe0456049d0..fb73806d3bfa0 100644 > > > > --- a/arch/x86/kvm/pmu.h > > > > +++ b/arch/x86/kvm/pmu.h > > > > @@ -248,6 +248,19 @@ static inline bool kvm_pmu_is_fastpath_emulati= on_allowed(struct kvm_vcpu *vcpu) > > > > X86_PMC_IDX_MAX); > > > > } > > > > > > > > +static inline void kvm_pmu_handle_nested_transition(struct kvm_vcp= u *vcpu) > > > > +{ > > > > + struct kvm_pmu *pmu =3D vcpu_to_pmu(vcpu); > > > > + > > > > + if (bitmap_empty(pmu->pmc_needs_nested_reprogram, X86_PMC_I= DX_MAX)) > > > > + return; > > > > + > > > > + BUILD_BUG_ON(sizeof(pmu->pmc_needs_nested_reprogram) !=3D s= izeof(atomic64_t)); > > > > + atomic64_or(*(s64 *)pmu->pmc_needs_nested_reprogram, > > > > + &vcpu_to_pmu(vcpu)->__reprogram_pmi); > > > > + kvm_make_request(KVM_REQ_PMU, vcpu); > > > > +} > > > > > > In general, this deferral is misguided. The G/H bits should be > > > re-evaluated before we call kvm_pmu_instruction_retired() for an > > > emulated instruction. > > > > > > > ... > > > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > > > > index f1c29ac306917..966e4138308f6 100644 > > > > --- a/arch/x86/kvm/x86.h > > > > +++ b/arch/x86/kvm/x86.h > > > > @@ -9,6 +9,7 @@ > > > > #include "kvm_cache_regs.h" > > > > #include "kvm_emulate.h" > > > > #include "cpuid.h" > > > > +#include "pmu.h" > > > > > > > > #define KVM_MAX_MCE_BANKS 32 > > > > > > > > @@ -152,6 +153,8 @@ static inline void enter_guest_mode(struct kvm_= vcpu *vcpu) > > > > { > > > > vcpu->arch.hflags |=3D HF_GUEST_MASK; > > > > vcpu->stat.guest_mode =3D 1; > > > > + > > > > + kvm_pmu_handle_nested_transition(vcpu); > > > > } > > > > > > This happens too late for VMRUN, since we have already called > > > kvm_pmu_instruction_retired() via kvm_skip_emulated_instruction(), an= d > > > VMRUN counts as a *guest* instruction. > > > > It's just VMRUN that's problematic though, correct? I.e. the scheme as= a whole > > is fine, we just need to special case VMRUN due to SVM's erratum^Warchi= tecture. > > Alternatively, maybe we could get AMD to document the silly VMRUN behav= ior as an > > erratum, then we could claim KVM is architecturally superior. :-D >=20 > Here, it's just VMRUN. Above, it's WRMSR(EFER). But clearing EFER.SVME while in the guest generates architecturally undefin= ed behavior. I don't see any reason to complicate PMU virtualization for that scenario, especially now that KVM synthesizes triple fault for L1.