Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp433110pxb; Wed, 14 Apr 2021 20:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmJa77+/1W9pD5Yl+IXj26sV1gbRxWBqH3mib7+YXTy0yqtHEJNBmPBJzqEPUiTlalxUHH X-Received: by 2002:a17:90b:682:: with SMTP id m2mr1487468pjz.70.1618456972135; Wed, 14 Apr 2021 20:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618456972; cv=none; d=google.com; s=arc-20160816; b=DPpWMboumRKCTp6ZhB91y0Mi/urbjAedG26FuOckKXxKhhLKYS96DNpw4DEnCzAuD4 f8vC68h5eWOqx4kfQDL4MwPkfPkY9jjPqstjcIp9NLStN2lU3rdQsueBeiZq09Fbncr+ OBOVFEa6/VM+5CfBQn5XZniEurQ8jRz00pBKPEFGA/oxoCE0iIVJl38uMDEScM+qL7Qb WfWTdSvYBNiMeNMtGWK/jl29hjzMJNWyNEPQPo64LB9GQhHm6nPwhSkKdLvWi7wb8jMc ZYnAh4A23ZGv52WBO0d69CcsJMYWBqool3lJfL35k626ycKNBteC8kuS5tZu4xJfW6Dv EiCg== 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=YxaENcPYV560NxBf7gUkho+VcdXkSvEg7fzVFHbkKho=; b=s48maCCGYa4Cwd4el64NURcNl0EGvgMJpPGtajnsNNeHCggrBwoD6VFYET7DxrrGg1 EM7P4Mu0wWI6ySajmM+NqPiOwZxMy0b5nnza7u4IK46MB6YH6tSve/KKRE5fY2tttyKC 3t6cmY7+IzVBOt2RcTkqqsyHnbyKU5lpnEBX02jk9gBW5g6hMqE9e6AreZL8pdfRkal0 9k2VJw2mL9ywn5O+zzKRxmuWgtAqqPM5VT14ULkDLT6AaMyUF44JEttzpvARlWuVLOaG MIT+cvAxVTOvHcXeGGo3rq87nVnKpFSEJj4u98FAvpLR11AKpOk5NV+x9m0km2Spmouc vuaA== 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 pi15si1748012pjb.31.2021.04.14.20.22.39; Wed, 14 Apr 2021 20:22:52 -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 S229832AbhDODVC (ORCPT + 99 others); Wed, 14 Apr 2021 23:21:02 -0400 Received: from mga11.intel.com ([192.55.52.93]:1119 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbhDODU4 (ORCPT ); Wed, 14 Apr 2021 23:20:56 -0400 IronPort-SDR: rpX3W4XHABwzbfX9UgR2mKvd0bn+/9ZeijwWx+jG9P08jO+bPdYdkjz7c/C2CqRKM7XcXu9k6f j1v7uD2KsGog== X-IronPort-AV: E=McAfee;i="6200,9189,9954"; a="191592825" X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="191592825" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 20:20:34 -0700 IronPort-SDR: rVFPZ7YgA4Y4zqgCCco6jebL1WDghaIUFLByyJuHwBdcevE4TxKoefXomnNLyKxQpY4qd7bh/C Eh4528Qx/yfA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="425013896" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 14 Apr 2021 20:20:30 -0700 From: Like Xu To: peterz@infradead.org, Paolo Bonzini , Sean Christopherson Cc: andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v5 03/16] perf/x86/core: Pass "struct kvm_pmu *" to determine the guest values Date: Thu, 15 Apr 2021 11:20:03 +0800 Message-Id: <20210415032016.166201-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210415032016.166201-1-like.xu@linux.intel.com> References: <20210415032016.166201-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 06bef6ba8a9b..7e2264a8c3f7 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -673,9 +673,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 021658df1feb..2f8ac53fe594 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3834,7 +3834,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; @@ -3866,7 +3866,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 85dc4e1d4514..e52b35333e1f 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -809,7 +809,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 c05e6e2854b5..58673351c475 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6537,9 +6537,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.30.2