From patchwork Wed May 18 17:01:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Like Xu X-Patchwork-Id: 12853888 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 9DBF0C433EF for ; Wed, 18 May 2022 17:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240605AbiERRB0 (ORCPT ); Wed, 18 May 2022 13:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240578AbiERRBZ (ORCPT ); Wed, 18 May 2022 13:01:25 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 284CE3151F; Wed, 18 May 2022 10:01:24 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id v11so2705586pff.6; Wed, 18 May 2022 10:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H6B54qfKCxnxSHyEfUNX3YrSNC1uK+oUERUpX17h73k=; b=PKnYJIwTCogXke3WtxPoGPZGLj9YYbN0qFiRuMIC0YahXtBUy/XGcy9hTDkKgwYvir WbtRdZhB35Tx8CbMYgTxE9UTwlej9AURpMNOfBgiRKTGbgjafX/frnR2wGKu96kzkop0 qAyTmuKyQWM0hOJcuQf5f7MRRULJYs+wYBZD4TnTahRaK/PwvfT1sfuxmNrcLE/JXj4n qJWHF2bOPkZhTVUSII1vH8FCmCOFqQa0uFGHnPJ7GWgAY2GWFPg+8vFCjqJhXktTrSr0 pkPTpPQWz3DOfuIlZOnOgt1FZu60kgGXEKNliMk8BPtpzRTyyhXzlk8QGBerLdUITlmC 4qbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H6B54qfKCxnxSHyEfUNX3YrSNC1uK+oUERUpX17h73k=; b=WYJgVMPhFI5xG72iGpxB1xxUpGK6XSYtIElVBv4bmFkcYlhvJ1An/MxwArVZqZGuRp iKympo+faXPx86SdJ/g2qvcArLJbLVgizQEMGg2R/9jGOROuroUJga/k96HoXZ9KruGd X3zd66RPejw/5MCbDJDmG3FjAvEJ+tByGivODp9OvfhkgQwgEvdscCLCrrAHkV+2BOmu OSEmZuozWfxZ4mwn7nuvxwembmQhPExDb9i8SNU2NFesLA0GeFuouCpM06RvQUTlSTmD J8jR2PhU3cjutUF9eY/E7nC6i8ApVd8tWjM2XFc5GsO5I/l9aWdMYZzvz6hlp0qHvOZT P64g== X-Gm-Message-State: AOAM533hHR8BN3jPgCO3HmtFmKKXI8+WmAZHky5N/8zeuXl6QEoqKrp4 mGzpSYH/kI3u/2TZctOoGco= X-Google-Smtp-Source: ABdhPJxuCvanawtwr+FNXTDXWGpcC9yYYw57LRkbaVIQBC8sFwXm27u7kfda4Tw4uzBQj7EPfF7Bvg== X-Received: by 2002:a63:f1e:0:b0:3c1:d54f:fc47 with SMTP id e30-20020a630f1e000000b003c1d54ffc47mr343979pgl.51.1652893283621; Wed, 18 May 2022 10:01:23 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.117]) by smtp.gmail.com with ESMTPSA id p42-20020a056a0026ea00b0050dc762818dsm2283240pfw.103.2022.05.18.10.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 10:01:23 -0700 (PDT) From: Like Xu X-Google-Original-From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] KVM: x86/pmu: Move the vmx_icl_pebs_cpu[] definition out of the header file Date: Thu, 19 May 2022 01:01:16 +0800 Message-Id: <20220518170118.66263-1-likexu@tencent.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Like Xu Defining a static const array in a header file would introduce redundant definitions to the point of confusing semantics, and such a use case would only bring complaints from the compiler: arch/x86/kvm/pmu.h:20:32: warning: ‘vmx_icl_pebs_cpu’ defined but not used [-Wunused-const-variable=] 20 | static const struct x86_cpu_id vmx_icl_pebs_cpu[] = { | ^~~~~~~~~~~~~~~~ Fixes: a095df2c5f48 ("KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter") Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 7 +++++++ arch/x86/kvm/pmu.h | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index b5d0c36b869b..a2eaae85d97b 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "x86.h" #include "cpuid.h" #include "lapic.h" @@ -27,6 +28,12 @@ struct x86_pmu_capability __read_mostly kvm_pmu_cap; EXPORT_SYMBOL_GPL(kvm_pmu_cap); +static const struct x86_cpu_id vmx_icl_pebs_cpu[] = { + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL), + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL), + {} +}; + /* NOTE: * - Each perf counter is defined as "struct kvm_pmc"; * - There are two types of perf counters: general purpose (gp) and fixed. diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index dbf4c83519a4..ecf2962510e4 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -4,8 +4,6 @@ #include -#include - #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu) #define pmu_to_vcpu(pmu) (container_of((pmu), struct kvm_vcpu, arch.pmu)) #define pmc_to_pmu(pmc) (&(pmc)->vcpu->arch.pmu) @@ -17,12 +15,6 @@ #define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001 #define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002 -static const struct x86_cpu_id vmx_icl_pebs_cpu[] = { - X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL), - X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL), - {} -}; - struct kvm_event_hw_type_mapping { u8 eventsel; u8 unit_mask; From patchwork Wed May 18 17:01:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Like Xu X-Patchwork-Id: 12853889 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 8D43DC433F5 for ; Wed, 18 May 2022 17:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240661AbiERRBd (ORCPT ); Wed, 18 May 2022 13:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240651AbiERRB3 (ORCPT ); Wed, 18 May 2022 13:01:29 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 738FD326CF; Wed, 18 May 2022 10:01:27 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id c14so2720734pfn.2; Wed, 18 May 2022 10:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N88H0czoo1fdiyjAEuf4MZG6526sP958mco2gNiBpws=; b=HorzJBxEjlmcTT8opaMMa6B9CFCM1p1mgQhAA/QOj4RsVWMnEQIu2tqhPCV0qp7QtE +EgyA/i5YNeWWN1kpWeXBMvrjyEP3EzePzf7XoXTNwzqYpafsIcbMqprbxNXNL04ehRx 7qImA7dOqNikh10nmUIj498rfLrOHpSRqUv7QmDzevuwPO9u2GBwRSbA8kWgTIHhpMQc 6/eghuZx9u65eBgOnbPG53+ZN/BU/bGm8+KtvLMgRVPEiFOs3gVh1+R4+UjKpWaChpIr w19qGDdnHpVoioJlE3oYyoQPYKTF+cYfkTnMH6sf7N81REFV200JZDpZZ+brMuLz4m70 jVGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N88H0czoo1fdiyjAEuf4MZG6526sP958mco2gNiBpws=; b=rimseVAOnPnsMTPjXi/c3q/Bsp/uMzwcOafF9p+MP/mObnqTBgo7FjQSggE0K8lVzz F6k9C06yRPauUXPlChwYtpsGQoryKgTgI4d7vY67dbZ90EOwd887IW7C1UjEkA6lSUbK 0/jz0afsXzVbyC/T3RTW0i1FbUjKLZBvSimuAu7Z6Mo5mwcBPZY0AFtzeVJ0hSngushC Sb57YJr9JrHNiwdfKZXT1PVA3HFjIsTxn/LXuCukBoWOa7NmZmrpCSElnNqt3CSF7F2M v+GYTv1/FqYO4iFMzhHO2VKXdWMfisMdkFox4oxoTyA4oXIXxkSGpJpiSD4nk3yN/krK sG9Q== X-Gm-Message-State: AOAM533iKydVKsJ2absGXI7G9f3ICBRz9zedwuul6gdUoeEob8s38aFb UohDOjZS7GMSLMwHe3dyBSk= X-Google-Smtp-Source: ABdhPJx9SOEYrUMpZbFRADRHuw5lj2iLwsIlelmGmuXigva8cECOeeuQN8FE3PitM9BxagRsBFRA0g== X-Received: by 2002:a63:28c:0:b0:3c1:6f72:7288 with SMTP id 134-20020a63028c000000b003c16f727288mr350389pgc.564.1652893286076; Wed, 18 May 2022 10:01:26 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.117]) by smtp.gmail.com with ESMTPSA id p42-20020a056a0026ea00b0050dc762818dsm2283240pfw.103.2022.05.18.10.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 10:01:25 -0700 (PDT) From: Like Xu X-Google-Original-From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] KVM: selftests: x86: Sync the new name of the test case to the .gitignore Date: Thu, 19 May 2022 01:01:17 +0800 Message-Id: <20220518170118.66263-2-likexu@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518170118.66263-1-likexu@tencent.com> References: <20220518170118.66263-1-likexu@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Like Xu Fixing side effect of the so-called opportunistic change in the commit. Fixes: dc8a9febbab0 ("KVM: selftests: x86: Fix test failure on arch lbr capable platforms") Signed-off-by: Like Xu --- tools/testing/selftests/kvm/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index 4f48f9c2411d..f18ae306c916 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -55,7 +55,7 @@ /x86_64/xen_shinfo_test /x86_64/xen_vmcall_test /x86_64/xss_msr_test -/x86_64/vmx_pmu_msrs_test +/x86_64/vmx_pmu_caps_test /access_tracking_perf_test /demand_paging_test /dirty_log_test From patchwork Wed May 18 17:01:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Like Xu X-Patchwork-Id: 12853890 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 04641C433F5 for ; Wed, 18 May 2022 17:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240673AbiERRBg (ORCPT ); Wed, 18 May 2022 13:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240653AbiERRBc (ORCPT ); Wed, 18 May 2022 13:01:32 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F354333E1E; Wed, 18 May 2022 10:01:29 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id i1so2349627plg.7; Wed, 18 May 2022 10:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RcLHuOHV+RcpwGuZbYj1dwn0uVanHpALeVRluvJ4g1I=; b=K04yJM6DTJUgL8ulQk9SeqQC4aMUlA0X9pcm/57phnuJEd8CJpCNkJ53QfDFtTCd29 1z4efV2UH/LoajUWyy9G98L46LR0FKlvEA3JC/fC9f0fGvu84OcftYWXlfNTowf5VFOT GzlVf8UhUQSW9CtN4neQwhArRRFr2C7oZiGsL0FnruJF0tkpJMSr71FIwFk27Qpk2zsm vQwoSZm2vgRaMuyqYsEaFVFJ7ea+XatN1hnmzpGBstBCq16R8txpKOlzHtKDvRoJZQpC TqeOrnGnQHDGypzLstsrySlutf/CBsGfqEOslSTa6b0GsBiMFBQP1atedfF7w7tjb4YH 47VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RcLHuOHV+RcpwGuZbYj1dwn0uVanHpALeVRluvJ4g1I=; b=bN4Kl9WEyiETuVgM64Z6V7qb6CIooimgLKwJv3ALXFjUIPap2sKw/Hc5SX0xHQzgdV 2jer88HyuG5aP2zQMkU/uNolXo/8qq13iLkt4xhjZKxIjiktEajoxbftS9QRElt0+jOg zlrwKEtkYcTclhJOfJ0pWxokztlaUH9/pHmo01Kw8//Z0KifxWxXA0GxVcAXSVXesxYx CU1dYSIXJhxD7RJ5PRcRTZNiq1NppHNQfrJhDk4F/+LVIAafPDVC+Y7OFAWZG8MVKz1Z DqL1B1fnEf714vMflp7BHYh1mvpE/8xn9V4SiE4fMRfhS2wFbwl5uXBP6CjjkSH1oOfa w3PA== X-Gm-Message-State: AOAM532uBtvD6pZwJmGnO6eDpE3gQEHNzuc3hiijlYuR0KVFoXUPOEvx R8ADIC7ldzX7PXgr7e2aqSE= X-Google-Smtp-Source: ABdhPJx0XLUuLwYHCSHly5djoS/xd+ihCGXyWkcmfhvIY5k20ccuv0i5oQYvMkcbWEEftuSU5Zlbog== X-Received: by 2002:a17:902:f64c:b0:156:7ceb:b579 with SMTP id m12-20020a170902f64c00b001567cebb579mr496428plg.73.1652893288645; Wed, 18 May 2022 10:01:28 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.117]) by smtp.gmail.com with ESMTPSA id p42-20020a056a0026ea00b0050dc762818dsm2283240pfw.103.2022.05.18.10.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 10:01:28 -0700 (PDT) From: Like Xu X-Google-Original-From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] KVM: x86/pmu: Update global enable_pmu when PMU is undetected Date: Thu, 19 May 2022 01:01:18 +0800 Message-Id: <20220518170118.66263-3-likexu@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220518170118.66263-1-likexu@tencent.com> References: <20220518170118.66263-1-likexu@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Like Xu On some virt platforms (L1 guest w/o PMU), the value of module parameter 'enable_pmu' for nested L2 guests should be updated at initialisation. Considering that there is no concept of "architecture pmu" in AMD or Hygon and that the versions (prior to Zen 4) are all 0, but that the theoretical available counters are at least AMD64_NUM_COUNTERS, the utility check_hw_exists() is reused in the initialisation call path. Opportunistically update Intel specific comments. Fixes: 8eeac7e999e8 ("KVM: x86/pmu: Add kvm_pmu_cap to optimize perf_get_x86_pmu_capability") Signed-off-by: Like Xu --- arch/x86/events/core.c | 6 ++++++ arch/x86/kvm/pmu.h | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 7f1d10dbabc0..865eeb500a71 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2982,6 +2982,12 @@ unsigned long perf_misc_flags(struct pt_regs *regs) void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) { + if (!check_hw_exists(&pmu, x86_pmu.num_counters, + x86_pmu.num_counters_fixed)) { + memset(cap, 0, sizeof(*cap)); + return; + } + cap->version = x86_pmu.version; /* * KVM doesn't support the hybrid PMU yet. diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h index ecf2962510e4..b200d080a8a3 100644 --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -150,14 +150,19 @@ extern struct x86_pmu_capability kvm_pmu_cap; static inline void kvm_init_pmu_capability(void) { + bool is_intel = boot_cpu_data.x86_vendor == X86_VENDOR_INTEL; + perf_get_x86_pmu_capability(&kvm_pmu_cap); - /* - * Only support guest architectural pmu on - * a host with architectural pmu. - */ - if (!kvm_pmu_cap.version) + /* + * For Intel, only support guest architectural pmu + * on a host with architectural pmu. + */ + if ((is_intel && !kvm_pmu_cap.version) || !kvm_pmu_cap.num_counters_gp) { memset(&kvm_pmu_cap, 0, sizeof(kvm_pmu_cap)); + enable_pmu = false; + return; + } kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2); kvm_pmu_cap.num_counters_fixed = min(kvm_pmu_cap.num_counters_fixed,