Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1547702rda; Mon, 23 Oct 2023 16:40:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGowoJ57slK18Vec8JlnX7MkQCrCgmpSuk+NyngDGqwqy3HszJl/TF6IdOpIOjjYGe1hWWE X-Received: by 2002:a17:902:c1c5:b0:1c9:bfdb:aad5 with SMTP id c5-20020a170902c1c500b001c9bfdbaad5mr10512730plc.24.1698104448056; Mon, 23 Oct 2023 16:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698104448; cv=none; d=google.com; s=arc-20160816; b=WRAJW02YehZgyPg6Pz2Nbs6mwMcVU3wuk0u62DBrOf6VKYzpJX2j8z3uGBIqKHq/Lx GbFfjnGTnmAkB9w536fWmYY8+vW7nQ1yXEz+Vk3yUoJLJnT3ltDz4V8hcu33Qiwnt/tB F7mfO4In4M7fe0gghT+YUuetkBsFeaqks07Mg8Jersz33q8dYH9PPErF/+YqC/e1z4nT zSQlia/IHEKqKP9A3WjZF1VgmrtHopL6w+dLB7Mm5TGfnrjHlwz+avyvnaIm17XVHzBj 9ToLyAOPcPGGleHn/zSEgJ8B1r8KJeSLgaY+DFsgPToqBdkX7nW7W4rwE5Lr3D0zJtFW BfUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=6neP5ivK010SBRb0ibXYexUf8ZRbqIGhikwLVX47+yQ=; fh=t7gFcWLRyAqmyldGbr6d3KgIXGxOYU/i61iCoIU6S88=; b=09pvniu/ijxEbNUFNl0SEph+MfTvE1OJoRpUm6p4sOGoKsu607mrseG4MX/jOhvBnC mI1/TFYZhASdSUruog4TaWkMxPTpkzWkkTWGGRn5J8carMk5w+2q+NaGzxn9xWciRf0O KPytVpWKPL3KvEpdmJjGhc0YZzOKYGPAB/MWvHDOYeVwOy5MBPQ5QDxBgJYmrelqHIWb dF9r+YqslB3dyaPgSjLLJ9ndT/QuvO2v2O+pKYnsoHW+17M6gxc8dBTc/FY+542VYif7 /Kw6XYfKAodsbd/0WKCNPTLKSpdjCddq4oR+egvOCSRZYPBS7SGOdyrsBsxYVuP6u47N tsaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xbElmHYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m1-20020a170902db0100b001cbd8dd09e8si1756240plx.537.2023.10.23.16.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 16:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xbElmHYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9DD3D8065EC4; Mon, 23 Oct 2023 16:40:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjJWXkI (ORCPT + 99 others); Mon, 23 Oct 2023 19:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjJWXkG (ORCPT ); Mon, 23 Oct 2023 19:40:06 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7797DDE for ; Mon, 23 Oct 2023 16:40:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7ac9c1522so55065837b3.0 for ; Mon, 23 Oct 2023 16:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698104403; x=1698709203; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=6neP5ivK010SBRb0ibXYexUf8ZRbqIGhikwLVX47+yQ=; b=xbElmHYFUhnIKBFb6so2aaj7in7ozZtHvbYUpgx1aq3YoHjpTd8sG3hqvzY+bwCcNC 4zRIToRxvLzRG0ZRm6wTGa2fN9onLLWvJQOq12rq30fLGyulz46Lff4YJPLQ597aGPVP IrV9BY0JrNe0CPMTMTFkLtB1impi99Xz7gZRQSWTgNKRPEDUQUL9dCaA6zrWzrqrIC4A 2mYNECP2cXguTNKmCde19jxMVo96p7CY5mbjxlgq3Oyan3zUduTUH85NxJCJMQqUhAQ+ 0mBE98r2YCX61pK9Y1LIHj2TaNadJ5rnL15/Fdy/0YfIbuQ2TLfHyekF0W7gdcCj+z+P eB1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698104403; x=1698709203; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6neP5ivK010SBRb0ibXYexUf8ZRbqIGhikwLVX47+yQ=; b=aCT2gRjRzTjFy+Gb7nfqANdG0hPmzudRkgUUccf+Oc3xJLb2kh4WkcqN9HlmVi1/6g 2xeZVxFq1v9Ty8NM9Kg8zy8DuuSz+5resCUMZp0ablmafMrSgNIBBqKbQwPxgUdcpLZZ dcP/eK2SPhceDhTiKaRBx3TQ6pcPsUbLXU/+CpNpa4CAbb9tZopctOYQlMXoN9C6vQsj E0PGVFVTS0W9dbvV2vnXBcPvlUvA81UBn0ireftk6JNbwip4sK/WloI+ITadETC0Mjjx RF1S5/Y/j6HN1FOXBxldmNn88dPh4grxvN6GR42clznlfb/Z+9uGJyyOUm7t4Wc0MFpM HJAQ== X-Gm-Message-State: AOJu0YxOS9RtBrpsXmK2iV1whZuTDZd/0SrO8Nfm6y/MHnN+BtdltADg +cJTR+4v2QEijIx39OlrBrCQwkb/pBc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:d50f:0:b0:59b:c811:a702 with SMTP id x15-20020a0dd50f000000b0059bc811a702mr237963ywd.6.1698104403721; Mon, 23 Oct 2023 16:40:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 23 Oct 2023 16:39:54 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231023234000.2499267-1-seanjc@google.com> Subject: [PATCH 0/6] KVM: x86/pmu: Clean up emulated PMC event handling From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , Roman Kagan , Jim Mattson , Dapeng Mi , Like Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 16:40:38 -0700 (PDT) The ultimate goal of this series is to track emulated counter events using a dedicated variable instead of trying to track the previous counter value. Tracking the previous counter value is flawed as it takes a snapshot at every emulated event, but only checks for overflow prior to VM-Enter, i.e. KVM could miss an overflow if KVM ever supports emulating event types that can occur multiple times in a single VM-Exit. Patches 1-5 are (some loosely, some tightly) related fixes and cleanups to simplify the emulated counter approach implementation. The fixes are tagged for stable as usersepace could cause some weirdness around perf events, but I doubt any real world VMM is actually affected. 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 | 128 +++++++++++++++++++++---- 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, 127 insertions(+), 107 deletions(-) base-commit: ec2f1daad460c6201338dae606466220ccaa96d5 -- 2.42.0.758.gaed0368e0e-goog