From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 1C8E5311956 for ; Thu, 9 Apr 2026 18:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775759918; cv=none; b=J5LG6x7ACLUhS8gTSYTTgiIMAGZadzbCVba7ibV1ynVjSX5Jqu++23DkId8kWcDM6kIG4n0wyo+Pv07xgqiOrir3g6Y2PYCh5xWmUk2m/50YKlZ7bXqn7YlnLhc4amcRhac+FS7qpBFd/QNEh48xvC2n8sGKeT8ZAtWuNykGEfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775759918; c=relaxed/simple; bh=Gqq0qPDhRj1ViS0hdYCDLoJ6C0DL5yAvzqkfva9cQRc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XoO5ujYiI5zZ32VZJRNRcRbI29LxrIDCNeWbHPv5DxVB9MwD2GXj1w54LWQ/QLbQHGeT+QrWvadaLnriMui/CAxWSVFUf6LFoUTiKBECxwtYd2Jtu9nGtkKqhJNge55hvawN4y2tMquN/XIHrj1N7d/13YzyjrKB/yxvjs96q2s= 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=IFYjINoW; arc=none smtp.client-ip=209.85.210.202 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="IFYjINoW" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82c714cb672so654031b3a.0 for ; Thu, 09 Apr 2026 11:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775759915; x=1776364715; 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=vVTgkJjg/Y8v5u56Zdlg/Uwr9pfljLNL1gOzjVlRH7A=; b=IFYjINoW1hbHrATaTp/0Xg1A+VjtSSd5sEgS+yWqJHtCXjYCLun3hEaZeZRD04ltI0 3NbWaVGpG1Kom+ZCDjqyGjMd4C4rxh9Ce6Q8nTlLgm75PYbKBY4rj1YdCLIFSgMiixRZ Hm+jSiEdA3P8t4QQvqa5XIq+fsYrYsrupsnM475aVsESqZnjm9ESrz1SZp443f0MyQ/i jgMucJJnAZPvJ5KVtLJLaI/WDa8mynGBHcmnsrtwBNadoW7b3c4GVRjuti68dQBqi+O6 KdNf5yl55ryxtKP3KtYtcL56Y+exu5ndNs9OMv+c4Z0NtyTbofQuFyOHgAGQF7bQDIHh KWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775759915; x=1776364715; 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=vVTgkJjg/Y8v5u56Zdlg/Uwr9pfljLNL1gOzjVlRH7A=; b=GISO3Em62OguKV3h3JJJHAXdkOwYm79YP9G3SpmTUb0yrGhTwHzfbyOyL1SQHCTlf/ +nXckw/zM7FIBruZMzyNzo9xq2H3Vlr2fnW5phD5dh0tdZ4PtV26PJT0PbHWj/pSs1d0 lPA4OjJC5CPhEcLTAdqXH5KIY03mnPrsARnXCiA/V4IW33s0AchmI/wKWIIN+ojCpApX 0Zv+OZVIQdsCtfq59Pt4yhfLTi0M5oBwEvOj6Iu+79kV2NL2p8I6cl7iiWttDH0gEBAc CgETSOprRKrzwMb78A/35pA1ihNHb9nw0mJs3EHWD60U4skKZ2VGX5gZRVMyZE5skIHH XlvQ== X-Forwarded-Encrypted: i=1; AJvYcCVfoMExwx1cuIiseFAnxxJjjqQ2IVrrSZ6rc4SqW4WYr1mRsSRB1XBu2TLNxvbzmnCTitv97dwr+HfU628=@vger.kernel.org X-Gm-Message-State: AOJu0YzGWTLRpvYhgdRA+Psw7GmfbzGIjgzGHx3Mx7XKNR27sUPTY3Qa 8S/VPttKF5wcKfu+LZcM/dmriglb3vvM8ThUofRVvlG2eNHzWAeXylqpiJtqBM2VAvVMRBuu1K0 rZHUJVw== X-Received: from pfbjf13.prod.google.com ([2002:a05:6a00:6e4d:b0:827:4734:567]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a241:b0:82c:2480:4e95 with SMTP id d2e1a72fcca58-82f0c302aa3mr266790b3a.33.1775759915130; Thu, 09 Apr 2026 11:38:35 -0700 (PDT) Date: Thu, 9 Apr 2026 11:38:33 -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:48=E2=80=AFAM Sean Christopherson wrote: > > On Thu, Apr 09, 2026, Jim Mattson wrote: > > > > > 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()= , and > > > > > VMRUN counts as a *guest* instruction. > > > > > > > > It's just VMRUN that's problematic though, correct? I.e. the schem= e as a whole > > > > is fine, we just need to special case VMRUN due to SVM's erratum^Wa= rchitecture. > > > > Alternatively, maybe we could get AMD to document the silly VMRUN b= ehavior as an > > > > erratum, then we could claim KVM is architecturally superior. :-D > > > > > > Here, it's just VMRUN. Above, it's WRMSR(EFER). > > > > But clearing EFER.SVME while in the guest generates architecturally und= efined > > behavior. I don't see any reason to complicate PMU virtualization for = that > > scenario, especially now that KVM synthesizes triple fault for L1. >=20 > L1 can clear the virtual EFER.SVME. That is well-defined. Gah, I forgot that the H/G bits are ignored when EFER.SVME=3D0. That's rea= lly annoying.