From nobody Tue Dec 16 14:38:29 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 9DAD72F7AC5 for ; Sat, 6 Dec 2025 00:18:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764980313; cv=none; b=YtwnxOjWdqrwdRwIkbeenp/NLABbi8SikPBvaUYggxn+dWyOogaxVGTg2dgTz4/OYTR/ViIcwoDLs/47DK8R7AJSsCEB+MRwLg78v+KqDEVoKp30/KbBJ+I9/yluS+o+yY1yqb14rtEaxEac0JrhgkZMc9X7SxmLneLe3tQ2aEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764980313; c=relaxed/simple; bh=3Wr9JMWcB5q7jiwxMn5RBJWwtBvMspvu6SXJNEXPG6Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g1IM/yWhxQV1826br6KrB10eRrFiQBLRpE1PKmWZxesxzqZJJI0qBSzwQZLYoKXj3TYsn3u+ZCjGD4LMdgHZcoG/wCx3G9MdQqE5LclfxtxNNJ+o/b9cqWhMIsaRbJ0I/yQoehiZPTmnR+cAFLmBosz8gHo/rWhcGvDFfT8U5d4= 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=fail (0-bit key) header.d=google.com header.i=@google.com header.b=I+tov7Gi reason="key not found in DNS"; arc=none smtp.client-ip=209.85.214.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=fail reason="key not found in DNS" (0-bit key) header.d=google.com header.i=@google.com header.b="I+tov7Gi" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-297df52c960so55490145ad.1 for ; Fri, 05 Dec 2025 16:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764980310; x=1765585110; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=EW7FbaDPVd5t9h4ibnQZUOMw78F2xoAgB/he+4U2Bes=; b=I+tov7GiRtyiO58uXMws04H+CWBqQ/SiP98FOW9vQr8LzoPTX18XuRpDFBQf8Vwaqt FJLCo7cfwx/L3aDPUSuFlVEOhCM2Kl+juxNmm+hnU7OoBHv+F815d+euqz3p6BBPOjsf ZMAh7qvBtYCV2Gcw2colazmYI0HG5jK5TnnHABxR5OaHP0pMRZY69zS5JUXfUfo1+ujM Oz3SknGz4Ijyg8ItMgeEqK/8t1ulGarPso71HqSQ35dzMa8vJ/L5aCeNoCo2acMIaL3t tjvpyks8NJQNWkrMS7UzmXk+AOVwPvqa9NYhxvLVC5ThjqjW6XXGJgY+iJA3Acm02KHq Sq+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764980310; x=1765585110; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EW7FbaDPVd5t9h4ibnQZUOMw78F2xoAgB/he+4U2Bes=; b=sBFPJPbnnm0tkCvaKiXSK2+ZH4CXsJssjiNfhCwYCCR2x5XTpJZZu/06Hg9/Xfir6Z q38Cdx6nqxb0MCEX3/83osHMM9KVmjBNhuOjAEUjZlwmps8B6zNNsr+dwMrPBpDzLkF1 y/DXaa+/NSO8LS5AHvlk5uWs2oE5VVCx2vYozbEIQQK40Eeik0bsUC6FQdEs3Mb5tWRP SQotnp0QBuPCXd/7tiyQKbaGaUZ3AkJ8LHeq7ogqLdOnzoOrdxXVsMtcK3ld0bKbjYhg Kolo7ISqf0zKOaACuW+rWYBWJN1g6BuEXc4z8kdkNQ8aAXEqH4iJGL4xz6eMq1OAP3KH 5foA== X-Forwarded-Encrypted: i=1; AJvYcCWvmtSCg36D2TBbOSiiyvXufDXiw/hx8FGTyf35POzvASfRQrl8XKwsO52CwC6jnfi/Ip2xAfezjU/zekg=@vger.kernel.org X-Gm-Message-State: AOJu0YygRutu7PkEnOe+GZsEQ21P2+dG3tud2jNXeRe6sYJU5vZvD4EY TToScTQ4DNbAoMVu3/qA34Jy6T30m5dfVA2UqPed6HlsMZtxCYWH2xJITD+XhyirbLwVb/8HSmK D14lPAA== X-Google-Smtp-Source: AGHT+IEzWFttnZLEQAsOaxYvtzWLuPcRq6QltY73DikVd5gmywMn7Yi+CzZHr3S07fvHdxIzVSJyvXKfRes= X-Received: from plrc6.prod.google.com ([2002:a17:902:aa46:b0:29d:5afa:2de]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:32d0:b0:294:f310:5218 with SMTP id d9443c01a7336-29df4cb6bfamr6615315ad.0.1764980310360; Fri, 05 Dec 2025 16:18:30 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 5 Dec 2025 16:17:08 -0800 In-Reply-To: <20251206001720.468579-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251206001720.468579-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251206001720.468579-33-seanjc@google.com> Subject: [PATCH v6 32/44] KVM: nSVM: Disable PMU MSR interception as appropriate while running L2 From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Xin Li , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Mingwei Zhang , Xudong Hao , Sandipan Das , Dapeng Mi , Xiong Zhang , Manali Shukla , Jim Mattson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add MSRs that might be passed through to L1 when running with a mediated PMU to the nested SVM's set of to-be-merged MSR indices, i.e. disable interception of PMU MSRs when running L2 if both KVM (L0) and L1 disable interception. There is no need for KVM to interpose on such MSR accesses, e.g. if L1 exposes a mediated PMU (or equivalent) to L2. Tested-by: Xudong Hao Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/nested.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index ba0f11c68372..93140ccec95d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -194,7 +194,7 @@ void recalc_intercepts(struct vcpu_svm *svm) * Hardcode the capacity of the array based on the maximum number of _offs= ets_. * MSRs are batched together, so there are fewer offsets than MSRs. */ -static int nested_svm_msrpm_merge_offsets[7] __ro_after_init; +static int nested_svm_msrpm_merge_offsets[10] __ro_after_init; static int nested_svm_nr_msrpm_merge_offsets __ro_after_init; typedef unsigned long nsvm_msrpm_merge_t; =20 @@ -222,6 +222,22 @@ int __init nested_svm_init_msrpm_merge_offsets(void) MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP, MSR_IA32_LASTINTTOIP, + + MSR_K7_PERFCTR0, + MSR_K7_PERFCTR1, + MSR_K7_PERFCTR2, + MSR_K7_PERFCTR3, + MSR_F15H_PERF_CTR0, + MSR_F15H_PERF_CTR1, + MSR_F15H_PERF_CTR2, + MSR_F15H_PERF_CTR3, + MSR_F15H_PERF_CTR4, + MSR_F15H_PERF_CTR5, + + MSR_AMD64_PERF_CNTR_GLOBAL_CTL, + MSR_AMD64_PERF_CNTR_GLOBAL_STATUS, + MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_CLR, + MSR_AMD64_PERF_CNTR_GLOBAL_STATUS_SET, }; int i, j; =20 --=20 2.52.0.223.gf5cc29aaa4-goog