Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AF52C64EC4 for ; Fri, 10 Mar 2023 10:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbjCJKyq (ORCPT ); Fri, 10 Mar 2023 05:54:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbjCJKyU (ORCPT ); Fri, 10 Mar 2023 05:54:20 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DF7FFBFC; Fri, 10 Mar 2023 02:54:10 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so9418799pjh.0; Fri, 10 Mar 2023 02:54:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678445650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TuKuJgCQ/AJK9oB9PxBqMc3IiOj3CxcIYL84H7LCcFk=; b=oP2GQg1nQ2BC5qEovXCSrIuixk9M7JDz47vXnzO3GPvIt/PREYhrbwHZCJ159gplWm kEf/MdQ3U22f/dV6QhsCCc0EuVvtozsi7kbHXuvfiWGNmPyATelxwtqwMZJMrq6MT3UJ GtdLfOIEgrN9KkGfxVcGdyejvlpt2hAflfSLMiq9gU1mKZI+hcdQ35yynxHOArhHU6qp EkA0Jurpw/RCy9c/Zc2oBFd3iKhI4mwtVBR26tFmD+P9Vo0oaeUGCgZxueZ1UftfC/by W0J//ZAqhJutipIEK14pe7Z47BcgtKZH+mauOXI9hx7rx8+hofP9JaM1WnKtJYvMoz/l c9ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678445650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TuKuJgCQ/AJK9oB9PxBqMc3IiOj3CxcIYL84H7LCcFk=; b=n44JgvwJ+jj2gigOA2zASK8UWi8DzF2mBaAmc+ZLSvx8ta//YHQf6kY9pi8D8QazJd weaFTykVpFG5QTlAg0Hl4d/FPVKpqnXs6xiAqEoup2N/i4PduBJkolCDRC5mZpLXcV0D IX9tCiIFNVk9Mt+NhGRlthckNfxdseFw2tR7joUp2edlSGLq1w1F3BC6Qqzq7/s7p3g3 sPhDw7talQ88qPIRIzsBVzjPam3732jquLFKaksIBSvwMijyFOJYApnCLjOYztZRgq48 US6Jjk8ujTvlwr4wFAWOaQywAZf7ggve+FffMdXsqzBYtnefP4ZIXL43Fq33uzXLoLmx Uk/g== X-Gm-Message-State: AO0yUKX7V8SkcuiURzDFN6erLk1IH5lBHbWTZ3yfLLEu9CXcW5iArwQI d64FAx2sZfzWjFaSp63+7fM= X-Google-Smtp-Source: AK7set/VjVe4W4LYtwsKIqP++zAYM/v5WZ9XyQuK7AIwmM8cr0CRfRQajdyvCsTc57DzdvK2sdEHuQ== X-Received: by 2002:a17:902:e842:b0:19a:b4a9:9ddb with SMTP id t2-20020a170902e84200b0019ab4a99ddbmr31045713plg.49.1678445649976; Fri, 10 Mar 2023 02:54:09 -0800 (PST) Received: from localhost.localdomain ([103.7.29.32]) by smtp.gmail.com with ESMTPSA id ks3-20020a170903084300b0019cbabf127dsm1174167plb.182.2023.03.10.02.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:54:09 -0800 (PST) From: Like Xu X-Google-Original-From: Like Xu To: Sean Christopherson Cc: Paolo Bonzini , Ravi Bangoria , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] KVM: x86/pmu: Move the overflow of a normal counter out of PMI context Date: Fri, 10 Mar 2023 18:53:44 +0800 Message-Id: <20230310105346.12302-4-likexu@tencent.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310105346.12302-1-likexu@tencent.com> References: <20230310105346.12302-1-likexu@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu From the guest's point of view, vPMU's global_status bit update following a counter overflow is completely independent of whether it is emulated in the host PMI context. The guest counter overflow emulation only depends on whether pmc->counter has an overflow or not. Plus the counter overflow generated by the emulation instruction has been delayed and not been handled in the PMI context. This part of the logic can be unified by reusing pmc->prev_counter for a normal counter. However for a PEBS counter, its buffer overflow irq still requires hardware to trigger PMI. Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 01a6b7ffa9b1..81c7cc4ceadf 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -160,7 +160,10 @@ static void kvm_perf_overflow(struct perf_event *perf_event, if (test_and_set_bit(pmc->idx, pmc_to_pmu(pmc)->reprogram_pmi)) return; - __kvm_perf_overflow(pmc, true); + if (pebs_is_enabled(pmc)) + __kvm_perf_overflow(pmc, true); + else + pmc->prev_counter = pmc->counter; kvm_make_request(KVM_REQ_PMU, pmc->vcpu); } -- 2.39.2