From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 5A5E6238C03 for ; Sat, 7 Feb 2026 01:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770427434; cv=none; b=tu2yDGMPEYbs8OFCSd1afB0gK3gqHoZdVrruslzenCLcYOcxos4UmH0VkGNqADC55ZUOgA60xle1tQxHW1oflRGAMh/hy0t+OnJoSjc+M3KILRMh34mAVe3ZQ8fGjqJlPeYqHrLWZP7QS47NhjiFbFG6BWxBZwbiI4du6wXPC7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770427434; c=relaxed/simple; bh=dbXNLQnXNLyXQ9CT/B6ZGUFhbJ3b6yLRqpkwxAjNO5g=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=CJ3+clnqpYlM486KnTTKwsN9rVVSEVL35bmqJcz3+xdY/XKtejkkyag/GBD9WP91U7k2wWNchceUigg6qpvG3eUuGcRTjICYqvKcM/55byEBNPhyCXzM2lTikMPD8WT6+viSOXrwV2VnCx/HnqcYLQOGowJsgJMy1Cytb/UFNts= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jmattson.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SLGclmpL; arc=none smtp.client-ip=209.85.215.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--jmattson.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SLGclmpL" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c6b1b22b134so1598061a12.2 for ; Fri, 06 Feb 2026 17:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770427434; x=1771032234; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zx9cflBOvMN2Fre5G6WHM7bbDYv06YwaCyO7rWPF26U=; b=SLGclmpLSC5f+b2lHOUddrZVZntDo3NmvP7g8ZpcA99lvnk2/5gz252p8Cui8qb0RV GfEYuAgo0K8EwxLGbYja5FywWyGgA04Ghim2Nb66RhtkxQqmIib57ppl5GWglEzd3BSd GIQc7Lg5fnzfaJRd3uVjCiICz8UJjbXfnRGocVWrqfb/DYV+lYF0bcsqW9pg2zeeGUn1 +iqNnpMbeO5kRWPr9fBb3yJF0grnkksUgBaU4DsLPWlkmGaU4znahdlMhxYB/nu8QYkv DHiwGnaOr/6YApP1yBoI5+5F9++SBnGbC71YwgSPM4qeBe4eNZUJup863BWlb9vNp0z1 StQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770427434; x=1771032234; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zx9cflBOvMN2Fre5G6WHM7bbDYv06YwaCyO7rWPF26U=; b=kwyvi7O+88S6xp3b7tG+hbDO3oZz09M3G6Z9LbLcYSUE25vqy4yxo20jLTPAXHjmOM 0gtUvQPp3QCULos99PyI35ONJZZBDrP0+Xr1sNAyT2ShmKoGQCbO31LoGekzR/NWRnlO MAXlrTqgW0qt4reGguaKnk8QDSEN4XZ3S1krBTF30rlmySJR1+BRfTfz9SZw+lmDRMRa cldOoNw/BEwJM8hWf9Smc1Us8WNPccJBBRPYbgP43/N18DoX79iJ8/vWmycpLTwq8x5T O9nI886Z/c5RzG2OQf1yzc081MyYMhBUfC1GZh3i688vPeIQYJ74KYbF2MMOJ1Fcb3YN Mq9g== X-Forwarded-Encrypted: i=1; AJvYcCVZ2R7Dr7+CECTaLcJ/9IOIgLjmfaKbahQvOw/6xCKVlq5BrnaF3GlVpHsRRLp+LPe1skR7Wl2kOHdpcvqdAEQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8JcVHxPZzUSDPR1g56evy8EmnZw2/dbN8i6qf6Yz0UzaFaEdT 3lF1ni7G86fIYtx1Z3puNcm/8k+OvnGUSIo8ePVf0zX7CpfSeDF9IgmejoyhXwv89UWo/0ZBoAB TXogNV/uLoNFtdw== X-Received: from pgbdo14.prod.google.com ([2002:a05:6a02:e8e:b0:c62:b045:9c6]) (user=jmattson job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:681:b0:38e:c1c3:b1ed with SMTP id adf61e73a8af0-393ad33ab08mr4698774637.44.1770427433658; Fri, 06 Feb 2026 17:23:53 -0800 (PST) Date: Fri, 6 Feb 2026 17:23:26 -0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260207012339.2646196-1-jmattson@google.com> Subject: [PATCH v3 0/5] KVM: x86/pmu: Add support for AMD Host-Only/Guest-Only bits From: Jim Mattson To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Yosry Ahmed , Mingwei Zhang , Sandipan Das Cc: Jim Mattson Content-Type: text/plain; charset="UTF-8" This series adds support for AMD's Host-Only and Guest-Only performance counter eventsel bits in KVM's mediated PMU passthrough implementation. These bits allow an nSVM-enabled guest to configure performance counters that count only during L1 execution (Host-Only) or only during L2 execution (Guest-Only). KVM updates the hardware event selector ENABLE bit at the following state transitions to ensure counters only count in the appropriate mode: - EFER.SVME changes: Enable/disable Guest-Only counters - Nested VMRUN: Disable Host-Only, enable Guest-Only counters - Nested VMEXIT: Enable Host-Only, disable Guest-Only counters v1: https://lore.kernel.org/kvm/20260121225438.3908422-1-jmattson@google.com/ v2: https://lore.kernel.org/kvm/20260129232835.3710773-1-jmattson@google.com/ v2 -> v3: * Dropped the svm_enter_guest_mode() and svm_leave_guest_mode() wrappers introduced in v2 [Yosry] * Introduced a generic nested_transition callback in kvm_x86_ops to avoid confusing SVM-specific wrappers and unnecessary code replication * Fixed a latent bug with L2 stack alignment, which was triggered by a movdqa instruction in l2_guest_code() that referenced the L2 stack. Note that l2_guest_code() expects the stack to be 16-byte misaligned at function entry. It was not. Jim Mattson (5): KVM: x86/pmu: Introduce amd_pmu_set_eventsel_hw() KVM: x86/pmu: Disable Host-Only/Guest-Only events as appropriate for vCPU state KVM: x86/pmu: Refresh Host-Only/Guest-Only eventsel at nested transitions KVM: x86/pmu: Allow Host-Only/Guest-Only bits with nSVM and mediated PMU KVM: selftests: x86: Add svm_pmu_host_guest_test for Host-Only/Guest-Only bits arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 2 + arch/x86/include/asm/perf_event.h | 2 + arch/x86/kvm/kvm_cache_regs.h | 2 + arch/x86/kvm/svm/pmu.c | 42 +++- arch/x86/kvm/svm/svm.c | 3 + arch/x86/kvm/svm/svm.h | 5 + arch/x86/kvm/x86.c | 1 + tools/testing/selftests/kvm/Makefile.kvm | 1 + tools/testing/selftests/kvm/include/x86/pmu.h | 6 + .../selftests/kvm/include/x86/processor.h | 2 + .../kvm/x86/svm_pmu_host_guest_test.c | 199 ++++++++++++++++++ 12 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86/svm_pmu_host_guest_test.c -- 2.53.0.rc2.204.g2597b5adb4-goog