From patchwork Thu Jan 4 19:33:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 185134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5824521dyb; Thu, 4 Jan 2024 11:36:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4y9FSr1gZ5SoBTJK2zJQSVCVmJWEeulXsRx6OtzpdQDLdjhiyx6GcxQ4E4LUWEhXfR0/D X-Received: by 2002:a17:902:6841:b0:1d3:c8cb:4000 with SMTP id f1-20020a170902684100b001d3c8cb4000mr946824pln.26.1704396973669; Thu, 04 Jan 2024 11:36:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704396973; cv=none; d=google.com; s=arc-20160816; b=082gVLdSJYYAU1Wk0KmLMJbb8SJNc5Dd9BsgBhDxb1/eoW5OyWdeZ1ncg9Ka6RiOvn RIgO7bthyEI/xpKSHIhLXvX2+UxWroQJPXNmtJxiysiSZcag9nV47/6w1lS4/odXaQqM GafItXAz7tKb4zIt3wzAztVcVV9O/nv+KhT1eAOSDqVg/GMCOLIrj7UGq0ywoNE/BFJV 69eJTQ5qiDBMihrJDXAS4oUNRjGbAgTb+s7dSv2X5Zuo+i9f/BdKBkohEKsXVwRW0Dcz CZllRH0btqXqGRUsx3ua6kntWFfxGILX+2npaMokaAhFNHdUuLozWO+6PKmSF9y2hB0J bC3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=Zvs1u2UtIbd55nr7bpVl91Chzlx2v1NykCiBhL368XY=; fh=dogxdQWc7Q2U5Ekp9F18wEHwMgE3kRwQ/60KgTj3654=; b=Gx486/XNX5wlM/9wqwGA6SDo46qacKIZC8MeGOdooCxXMYSLwo5Z6R5CB/p/JVOwTk 6yB6v7W9RQZk/siDxLYXAVK64dmIEmtZmnN23RckaCoFvRXvp50p3PaV1KhnDBmqtChZ 6kUqw7DBlkffcG6aX+4X9fWU1nkD+wwB/KX1EPzZ2RAuDkE75j3moRCKc7TNKBaJTWnq Hfty8VTPmbKAEt6x8pV26wsYlS6MTyDIjMnkiaG8bmCSdZgQKROpTlSD+ukInOpX0NMd yTqb6I//N865sH5YkW40S6Vcyr1yRO8tsAWRXiHCSY14GgJ9rXmu1aAPhUWf8iZ9yqXb WqhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ix45oHyI; spf=pass (google.com: domain of linux-kernel+bounces-17167-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17167-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x1-20020a1709028ec100b001d4b1ddc8e0si7872943plo.67.2024.01.04.11.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:36:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17167-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ix45oHyI; spf=pass (google.com: domain of linux-kernel+bounces-17167-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17167-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8ECFCB23CAA for ; Thu, 4 Jan 2024 19:35:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88CAC2E40F; Thu, 4 Jan 2024 19:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ix45oHyI" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 9C5D02D792 for ; Thu, 4 Jan 2024 19:33:19 +0000 (UTC) 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 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5e9de9795dfso16767037b3.0 for ; Thu, 04 Jan 2024 11:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704396798; x=1705001598; 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=Zvs1u2UtIbd55nr7bpVl91Chzlx2v1NykCiBhL368XY=; b=ix45oHyInUXiCRhMeIXBXTxzHOn3L/gX75THjJXEKAIZ4igIMHx0LgEqqxn89OIpFV 7lKE+jewj4hKu2OvOpU6YMl/QdH38kZTwgsBypgKE0qRG+FPgzXcm+S1ro8gWaCNP5NP BVyboQxxfbXyx5QvTQGnCjMglOgQyy9lK3S6RWxC6skSWAQL7JlYnzMzHvMnZzsIdD5w ndOnoal82b5iuUfL8crO9XdY64Oyycq3F0Y5SWLNVBjuk+Xr+4+x/tlITwKe6/3YGfYe g2w4jEaUvwunJOAfO7GOQdld2yAVA9DpKFP6NebGDbkSWeOaokSbvqU7hRWCJrY3Go9T iWIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704396798; x=1705001598; 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=Zvs1u2UtIbd55nr7bpVl91Chzlx2v1NykCiBhL368XY=; b=VlqkFlsi8gWhRPsewUWw+qQE3rNZlxtjKn0V6iFLWRymMolMILeYowRgtdwzshcA/M 4HO1iBv7jUWE+NnMc+bgWopE+hy14d1FAOopM/Bys5ALnfPXab/xEVcvRtD8AauTwn3Y Qa1ci5u2LJ4/RHRIcpqkeuhjQDBr30HmHmDb8LmfhwZr5rug2xHXmgSWbu4h/1E/LqC1 xdfPvNWeTpn9SAMxZW+6bmVD8OIT5xabBwfbUvfMXAea+FNn3JCfjI3Cr3KJ08kLHEO6 P/4wgZlsfjS6/Brlks+wAKt5GraMdibFNlgis9588t4LubB40s5rlgputSdipbj+MBKt ebqA== X-Gm-Message-State: AOJu0YyXfRs7B86KbugC/K58o8bdTgoqcqZiVmjFeDIqDs7yPC8K4zJP R/ww7n2PbT1FpM3IFI25gN9UctY4vbQMOEdOUA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:6b11:0:b0:dbe:696c:1208 with SMTP id g17-20020a256b11000000b00dbe696c1208mr374709ybc.7.1704396798754; Thu, 04 Jan 2024 11:33:18 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 4 Jan 2024 11:33:01 -0800 In-Reply-To: <20240104193303.3175844-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: <20240104193303.3175844-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240104193303.3175844-7-seanjc@google.com> Subject: [GIT PULL] KVM: x86: PMU changes for 6.8 From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787189761281421140 X-GMAIL-MSGID: 1787189761281421140 PMU fixes and cleanups. The highlight is a fix for a double-overflow PMI bug when KVM manually emulates counter events, which was made mostly benign by commit a16eb25b09c0 ("KVM: x86: Mask LVTPC when handling a PMI"), but is still a bug. Note, the "Track emulated counter events instead of previous counter" fix breaks the PMU KVM-Unit-Test due to a long-standing "bug" in perf[*]. If need be, it's trivial to fudge around the shortcomings in the KUT code, I just haven't carved out time to push things along. [*] https://lore.kernel.org/all/20231107183605.409588-1-seanjc@google.com The following changes since commit e9e60c82fe391d04db55a91c733df4a017c28b2f: selftests/kvm: fix compilation on non-x86_64 platforms (2023-11-21 11:58:25 -0500) are available in the Git repository at: https://github.com/kvm-x86/linux.git tags/kvm-x86-pmu-6.8 for you to fetch changes up to fd89499a5151d197ba30f7b801f6d8f4646cf446: KVM: x86/pmu: Track emulated counter events instead of previous counter (2023-11-30 12:52:55 -0800) ---------------------------------------------------------------- KVM x86 PMU changes for 6.8: - Fix a variety of bugs where KVM fail to stop/reset counters and other state prior to refreshing the vPMU model. - Fix a double-overflow PMU bug by tracking emulated counter events using a dedicated field instead of snapshotting the "previous" counter. If the hardware PMC count triggers overflow that is recognized in the same VM-Exit that KVM manually bumps an event count, KVM would pend PMIs for both the hardware-triggered overflow and for KVM-triggered overflow. ---------------------------------------------------------------- Sean Christopherson (6): KVM: x86/pmu: Move PMU reset logic to common x86 code KVM: x86/pmu: Reset the PMU, i.e. stop counters, before refreshing KVM: x86/pmu: Stop calling kvm_pmu_reset() at RESET (it's redundant) KVM: x86/pmu: Remove manual clearing of fields in kvm_pmu_init() KVM: x86/pmu: Update sample period in pmc_write_counter() KVM: x86/pmu: Track emulated counter events instead of previous counter arch/x86/include/asm/kvm-x86-pmu-ops.h | 2 +- arch/x86/include/asm/kvm_host.h | 17 +++- arch/x86/kvm/pmu.c | 140 +++++++++++++++++++++++++++------ arch/x86/kvm/pmu.h | 47 +---------- arch/x86/kvm/svm/pmu.c | 17 ---- arch/x86/kvm/vmx/pmu_intel.c | 22 ------ arch/x86/kvm/x86.c | 1 - 7 files changed, 137 insertions(+), 109 deletions(-)