From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 7EC272C178D for ; Sat, 7 Feb 2026 04:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770437423; cv=none; b=hnMqRUlus6nZupe+yqoiV6AZVQ4d8CSP63CsmV4EEafQAfdQze9NhQ6w4U14G8wiVhBMH4lB7vx31NLfxq1QPpRWL8qCOZFii5IHynz8SHgfQewkLaC8JfZZmo7rYC0+z7AIkg9RdC+00Ec3BMFBFzLUGxbge5kTr9IySxxnBiw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770437423; c=relaxed/simple; bh=BTGQvs4H1Ngyfpfd4mjTDMOwEHd20pq0CRO2DNrKsqA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Mz81i4ZemU4HCH0Q31zvn4sqchqFjEALxSucETd5+6i0cCiJAciKyw/6J8wqSno5pOmLE3DY5ucaFB7qvbzcMWgEc3d+DnGnvNx7YDrhZ4g93HWbEbLGOCveP9XV1fGN1opkYG78ude/xnk40cnkeDbRUTvTCHg8sS/h/iZfOuI= 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=x0U9vHuq; arc=none smtp.client-ip=209.85.216.74 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="x0U9vHuq" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34cc8bf226cso2860802a91.3 for ; Fri, 06 Feb 2026 20:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770437423; x=1771042223; 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=H1uj9+WsCNCOqupGVMjBYAPK/R2I8MXRE7T7KcZiv/A=; b=x0U9vHuqkOdhTQMPeyrkQlhmvkYKLDZhnbisJyuEf9aBNnHP7KGG5NKu6rUg4V9+/o HxA2SsaHXGFSBtBxLK0PDtPhEBkktH9kSJ3T30TT1mi1JvkD90bzo+vkkh4PEhbYdGna 5oQi9tD3djR75Tkgq8C5JEQLxqjk+PkgGforpTCW7gtwzPK894+5DRN6SiphZxPQcLzD qvfyq31Jh1bmJ59tYJ54zlx3jThNCmTeH+pBHt/GmW4CZTlYDwmvGu1m6BdJOQNm1JIi T2pqojiYcWeJlC9JYsPAzkfTglRCpAuW7+mb0DhN4g/GpfL+mAk0r5u+L+wS72sCFWo2 RxPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770437423; x=1771042223; 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=H1uj9+WsCNCOqupGVMjBYAPK/R2I8MXRE7T7KcZiv/A=; b=AGpfZb9dgJKVMT2mfS6KA+Uf5CrQeV17XQlyNLc1xTMMnSF345+ekdR0Psp5KHSMgL PaeznGdlbhsKXh4tu4JOIbkMpFNbmIYUHZ2lQljjsaZQZgbvVJ5ngDf7oer40YOFUVez 5g8nNUK+m3Yj68xfjZ3L7Z+UkCPNjS1TB6rwFcxpG7lfXZVGGgYRH6XDoi3Grb0MGbKP fTyYQ+u/HZAzTWGHEziueVNYH0GRF7GwZ989CogOwJtoxMcVXcfdkqidHM2nKFPLnuk4 wRYbu+/FZqPLmGxgC/XbVrY4Ctr1nUcWCyI5R3MePu/elz8GSbuy/YhbFJT7caINRS4J qizw== X-Forwarded-Encrypted: i=1; AJvYcCV20GptAnWP9yM6WZV+K7WjKO25+Dx5DMKl0eG8Za2SHcZGqRquFoC4gyM29axQsaX9hcsjErnp21k+ecE=@vger.kernel.org X-Gm-Message-State: AOJu0YxVET3joGck3K7SX4DZACgirzIUjRS/GvKMQ7e1vjYa23RQ3Uvt J60qUlzt3iljPlraDSd3olPmTC80HBYBrT8fqaJ3wCZBNp4X/es+Wu880vLaC0BsAKtKEaQJLZk r5UqCBw== X-Received: from pjbgo22.prod.google.com ([2002:a17:90b:3d6:b0:354:bd11:74ae]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1650:b0:353:6373:590b with SMTP id 98e67ed59e1d1-354b3c40705mr4400845a91.7.1770437422865; Fri, 06 Feb 2026 20:10:22 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 6 Feb 2026 20:10:07 -0800 In-Reply-To: <20260207041011.913471-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: <20260207041011.913471-1-seanjc@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260207041011.913471-6-seanjc@google.com> Subject: [GIT PULL] KVM: x86: Mediated PMU for 6.20 From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson Content-Type: text/plain; charset="UTF-8" Mediated PMU support. Note, this is based on perf-core-kvm-mediated-pmu from the tip tree. If the KVM pull request is merged before the perf request, this will pull in another ~25 commits. The following changes since commit 01122b89361e565b3c88b9fbebe92dc5c7420cb7: perf: Use EXPORT_SYMBOL_FOR_KVM() for the mediated APIs (2025-12-19 08:54:59 +0100) are available in the Git repository at: https://github.com/kvm-x86/linux.git tags/kvm-x86-pmu-6.20 for you to fetch changes up to d374b89edbb9a8d552e03348f59287ff779b4c9d: KVM: VMX: Add mediated PMU support for CPUs without "save perf global ctrl" (2026-01-08 11:52:23 -0800) ---------------------------------------------------------------- KVM mediated PMU support for 6.20 Add support for mediated PMUs, where KVM gives the guest full ownership of PMU hardware (contexted switched around the fastpath run loop) and allows direct access to data MSRs and PMCs (restricted by the vPMU model), but intercepts access to control registers, e.g. to enforce event filtering and to prevent the guest from profiling sensitive host state. To keep overall complexity reasonable, mediated PMU usage is all or nothing for a given instance of KVM (controlled via module param). The Mediated PMU is disabled default, partly to maintain backwards compatilibity for existing setup, partly because there are tradeoffs when running with a mediated PMU that may be non-starters for some use cases, e.g. the host loses the ability to profile guests with mediated PMUs, the fastpath run loop is also a blind spot, entry/exit transitions are more expensive, etc. Versus the emulated PMU, where KVM is "just another perf user", the mediated PMU delivers more accurate profiling and monitoring (no risk of contention and thus dropped events), with significantly less overhead (fewer exits and faster emulation/programming of event selectors) E.g. when running Specint-2017 on a single-socket Sapphire Rapids with 56 cores and no-SMT, and using perf from within the guest: Perf command: a. basic-sampling: perf record -F 1000 -e 6-instructions -a --overwrite b. multiplex-sampling: perf record -F 1000 -e 10-instructions -a --overwrite Guest performance overhead: --------------------------------------------------------------------------- | Test case | emulated vPMU | all passthrough | passthrough with | | | | | event filters | --------------------------------------------------------------------------- | basic-sampling | 33.62% | 4.24% | 6.21% | --------------------------------------------------------------------------- | multiplex-sampling | 79.32% | 7.34% | 10.45% | --------------------------------------------------------------------------- ---------------------------------------------------------------- Dapeng Mi (11): KVM: x86/pmu: Start stubbing in mediated PMU support KVM: x86/pmu: Implement Intel mediated PMU requirements and constraints KVM: x86/pmu: Disable RDPMC interception for compatible mediated vPMU KVM: x86/pmu: Load/save GLOBAL_CTRL via entry/exit fields for mediated PMU KVM: x86/pmu: Disable interception of select PMU MSRs for mediated vPMUs KVM: x86/pmu: Bypass perf checks when emulating mediated PMU counter accesses KVM: x86/pmu: Reprogram mediated PMU event selectors on event filter updates KVM: x86/pmu: Load/put mediated PMU context when entering/exiting guest KVM: x86/pmu: Handle emulated instruction for mediated vPMU KVM: nVMX: Add macros to simplify nested MSR interception setting KVM: x86/pmu: Expose enable_mediated_pmu parameter to user space Mingwei Zhang (2): KVM: x86/pmu: Introduce eventsel_hw to prepare for pmu event filtering KVM: nVMX: Disable PMU MSR interception as appropriate while running L2 Sandipan Das (1): KVM: x86/pmu: Always stuff GuestOnly=1,HostOnly=0 for mediated PMCs on AMD Sean Christopherson (15): KVM: Add a simplified wrapper for registering perf callbacks KVM: x86/pmu: Implement AMD mediated PMU requirements KVM: x86/pmu: Disallow emulation in the fastpath if mediated PMCs are active KVM: nSVM: Disable PMU MSR interception as appropriate while running L2 KVM: x86/pmu: Elide WRMSRs when loading guest PMCs if values already match KVM: VMX: Drop intermediate "guest" field from msr_autostore KVM: nVMX: Don't update msr_autostore count when saving TSC for vmcs12 KVM: VMX: Dedup code for removing MSR from VMCS's auto-load list KVM: VMX: Drop unused @entry_only param from add_atomic_switch_msr() KVM: VMX: Bug the VM if either MSR auto-load list is full KVM: VMX: Set MSR index auto-load entry if and only if entry is "new" KVM: VMX: Compartmentalize adding MSRs to host vs. guest auto-load list KVM: VMX: Dedup code for adding MSR to VMCS's auto list KVM: VMX: Initialize vmcs01.VM_EXIT_MSR_STORE_ADDR with list address KVM: VMX: Add mediated PMU support for CPUs without "save perf global ctrl" Xiong Zhang (1): KVM: x86/pmu: Register PMI handler for mediated vPMU Documentation/admin-guide/kernel-parameters.txt | 49 ++++++++++++++++++++++ arch/arm64/kvm/arm.c | 2 +- arch/loongarch/kvm/main.c | 2 +- arch/riscv/kvm/main.c | 2 +- arch/x86/include/asm/kvm-x86-pmu-ops.h | 4 ++ arch/x86/include/asm/kvm_host.h | 3 ++ arch/x86/include/asm/msr-index.h | 1 + arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/pmu.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- arch/x86/kvm/pmu.h | 37 +++++++++++++++- arch/x86/kvm/svm/nested.c | 18 +++++++- arch/x86/kvm/svm/pmu.c | 44 +++++++++++++++++++ arch/x86/kvm/svm/svm.c | 46 ++++++++++++++++++++ arch/x86/kvm/vmx/capabilities.h | 9 +++- arch/x86/kvm/vmx/nested.c | 144 ++++++++++++++++++++++++++++++++++----------------------------- arch/x86/kvm/vmx/pmu_intel.c | 92 ++++++++++++++++++++++++++++++++++------ arch/x86/kvm/vmx/pmu_intel.h | 15 +++++++ arch/x86/kvm/vmx/vmx.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- arch/x86/kvm/vmx/vmx.h | 9 ++-- arch/x86/kvm/x86.c | 54 ++++++++++++++++++++++-- arch/x86/kvm/x86.h | 1 + include/linux/kvm_host.h | 11 ++++- virt/kvm/kvm_main.c | 5 ++- 23 files changed, 876 insertions(+), 154 deletions(-)