Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4547572pxj; Tue, 22 Jun 2021 02:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNScsVtMt0NnvVvlmtXANct0yJmqTr+I/FP3eJPzks9Pf/wuxzJOrGR3H0+M3haRTq/pq9 X-Received: by 2002:a17:907:20da:: with SMTP id qq26mr2992854ejb.42.1624355248241; Tue, 22 Jun 2021 02:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624355248; cv=none; d=google.com; s=arc-20160816; b=LLriRfc508pNqLJyaeS+yZHr/8Ue6lxxXS84MkIZFhTdNAbAPuHQjNZ5h54Htzj+36 4BaxoH5sGHoCzLLGcWpPtRu3QLvKklKKdb3Gghyt4WXnBrkx6/aogW7B1VWrkwcWFihX BjmOssB/IV4KnnRP7a70vhz1NYbX9AgAR2s96a+8Zfk4AKmWBaFPOdo/wMQ7/bTLcdYK Ck/uHyWEHeI6qTMcx1J2yjZp6gBS3HJjQzt2h/pIcijPSGzBHm7TTsJdU269JDrrOpMN 2tQZLbUWvJumEB7/WkYT0QmVNRWKRTLh0Ba/qrV7q/SORqpLeiAe/deLMpT13uKq55RE DR2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=iD3cgU1d1ypVKQ16WbCVbuLRGV3OUHW4LE4vF6w78s4=; b=dE0tKyO415m/7CZLP5CAb00fLYhi5AB0xOnGs6cvsgskxTInVNqh5FGr7WD+UTgC1P eM81ge42HVpQV/mfAxYbjF7j9FCFoDg+msdV1lesC2SkgoT4xmZWVv/sZFhIMu8Dopg3 IjlAJsAMrVAE91xejVUC1DWEzfdH64ji1kWhvVAdcBHS0jd+AuXKRqpYsjjNi+01BAI6 nwK+at898MSQoGjTCaxRzmjN6/pxQbxKpzAXYJjh1Xr8VFWxdszWZGEirWmzwGEEFgSk sjurttH8b5PPk8WsAWVLwvZfKvO1GBjbzpjc4oazjBiSyEtasOwvN76MsBz+kjHeiPEI NfMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd12si13595598ejb.356.2021.06.22.02.47.05; Tue, 22 Jun 2021 02:47:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbhFVJp4 (ORCPT + 99 others); Tue, 22 Jun 2021 05:45:56 -0400 Received: from mga18.intel.com ([134.134.136.126]:20222 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbhFVJpw (ORCPT ); Tue, 22 Jun 2021 05:45:52 -0400 IronPort-SDR: sk8aThFcV/eH7YagGl6a1/7KVfEK1l7of5/5uwT3+S+9Ha/kTTsLEcUQkPP5MYIhI2QHdzu6b3 4/S0XKACfYYQ== X-IronPort-AV: E=McAfee;i="6200,9189,10022"; a="194330944" X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="194330944" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:43:36 -0700 IronPort-SDR: RQb80OLk6dW+WGH5HlnboxFDdudtIOreTQGjsYxoMv3XjYhiPokSWh/rzV3pnWqc4VfCSPCPeE ZpFE8xxQ66yg== X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="641600150" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 02:43:32 -0700 From: Zhu Lingshan To: peterz@infradead.org, pbonzini@redhat.com Cc: bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, weijiang.yang@intel.com, kan.liang@linux.intel.com, ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, like.xu.linux@gmail.com, Like Xu , Zhu Lingshan Subject: [PATCH V7 04/18] perf/x86/core: Pass "struct kvm_pmu *" to determine the guest values Date: Tue, 22 Jun 2021 17:42:52 +0800 Message-Id: <20210622094306.8336-5-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210622094306.8336-1-lingshan.zhu@intel.com> References: <20210622094306.8336-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu Splitting the logic for determining the guest values is unnecessarily confusing, and potentially fragile. Perf should have full knowledge and control of what values are loaded for the guest. If we change .guest_get_msrs() to take a struct kvm_pmu pointer, then it can generate the full set of guest values by grabbing guest ds_area and pebs_data_cfg. Alternatively, .guest_get_msrs() could take the desired guest MSR values directly (ds_area and pebs_data_cfg), but kvm_pmu is vendor agnostic, so we don't see any reason to not just pass the pointer. Suggested-by: Sean Christopherson Signed-off-by: Like Xu Signed-off-by: Zhu Lingshan --- arch/x86/events/core.c | 4 ++-- arch/x86/events/intel/core.c | 4 ++-- arch/x86/events/perf_event.h | 2 +- arch/x86/include/asm/perf_event.h | 4 ++-- arch/x86/kvm/vmx/vmx.c | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 67eb5983bf80..6409f5fdd2b0 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -712,9 +712,9 @@ void x86_pmu_disable_all(void) } } -struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) +struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data) { - return static_call(x86_pmu_guest_get_msrs)(nr); + return static_call(x86_pmu_guest_get_msrs)(nr, data); } EXPORT_SYMBOL_GPL(perf_guest_get_msrs); diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index b187cb6b72fa..1d187b6d941a 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3897,7 +3897,7 @@ static int intel_pmu_hw_config(struct perf_event *event) return 0; } -static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) +static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; @@ -3930,7 +3930,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) return arr; } -static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr) +static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr, void *data) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index d0634b142376..09c20373ae09 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -876,7 +876,7 @@ struct x86_pmu { /* * Intel host/guest support (KVM) */ - struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr); + struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr, void *data); /* * Check period value for PERF_EVENT_IOC_PERIOD ioctl. diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 6a6e707905be..d5957b68906b 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -491,10 +491,10 @@ static inline void perf_check_microcode(void) { } #endif #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) -extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data); extern int x86_perf_get_lbr(struct x86_pmu_lbr *lbr); #else -struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data); static inline int x86_perf_get_lbr(struct x86_pmu_lbr *lbr) { return -1; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 50b42d7a8a11..3930e89679fc 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6595,9 +6595,10 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx) { int i, nr_msrs; struct perf_guest_switch_msr *msrs; + struct kvm_pmu *pmu = vcpu_to_pmu(&vmx->vcpu); /* Note, nr_msrs may be garbage if perf_guest_get_msrs() returns NULL. */ - msrs = perf_guest_get_msrs(&nr_msrs); + msrs = perf_guest_get_msrs(&nr_msrs, (void *)pmu); if (!msrs) return; -- 2.27.0