linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jianfeng Gao <jianfeng.gao@intel.com>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH] perf/x86: KVM: Disable vPMU support on hybrid CPUs (host PMUs)
Date: Fri, 20 Jan 2023 09:39:41 -0500	[thread overview]
Message-ID: <1dec071d-c010-cd89-9e58-d643e71e775c@linux.intel.com> (raw)
In-Reply-To: <20230120004051.2043777-1-seanjc@google.com>



On 2023-01-19 7:40 p.m., Sean Christopherson wrote:
> Disable KVM support for virtualizing PMUs on hosts with hybrid PMUs until
> KVM gains a sane way to enumeration the hybrid vPMU to userspace and/or
> gains a mechanism to let userspace opt-in to the dangers of exposing a
> hybrid vPMU to KVM guests.
> 
> Virtualizing a hybrid PMU, or at least part of a hybrid PMU, is possible,
> but it requires userspace to pin vCPUs to pCPUs to prevent migrating a
> vCPU between a big core and a little core, requires the VMM to accurately
> enumerate the topology to the guest (if exposing a hybrid CPU to the
> guest), and also requires the VMM to accurately enumerate the vPMU
> capabilities to the guest.

Current kernel only return the common counters to KVM, which is
available on both e-core and p-core. In theory, there should be no
problem with the migration between cores. You don't have to pin vCPU.
The only problem is that you probably can only use the architecture events.

There is nothing wrong for the information provided by the kernel. I
think it should be a KVM issue (my guess is the CPUID enumeration.) we
should fix rather than simply disable the PMU for entire hybrid machines.

Thanks,
Kan
> 
> The last point is especially problematic, as KVM doesn't control which
> pCPU it runs on when enumerating KVM's vPMU capabilities to userspace.
> For now, simply disable vPMU support on hybrid CPUs to avoid inducing
> seemingly random #GPs in guests.
> 
> Reported-by: Jianfeng Gao <jianfeng.gao@intel.com>
> Cc: stable@vger.kernel.org
> Cc: Andrew Cooper <Andrew.Cooper3@citrix.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Cc: Andi Kleen <ak@linux.intel.com>
> Link: https://lore.kernel.org/all/20220818181530.2355034-1-kan.liang@linux.intel.com
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> 
> Lightly tested as I don't have hybrid hardware.  For the record, I'm not
> against supporting hybrid vPMUs in KVM, but it needs to be a dedicated
> effort and not implicitly rely on userspace to do the right thing (or get
> lucky).
> 
>  arch/x86/events/core.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> index 85a63a41c471..a67667c41cc8 100644
> --- a/arch/x86/events/core.c
> +++ b/arch/x86/events/core.c
> @@ -2974,17 +2974,18 @@ unsigned long perf_misc_flags(struct pt_regs *regs)
>  
>  void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
>  {
> -	if (!x86_pmu_initialized()) {
> +	/*
> +	 * Hybrid PMUs don't play nice with virtualization unless userspace
> +	 * pins vCPUs _and_ can enumerate accurate information to the guest.
> +	 * Disable vPMU support for hybrid PMUs until KVM gains a way to let
> +	 * userspace opt into the dangers of hybrid vPMUs.
> +	 */
> +	if (!x86_pmu_initialized() || is_hybrid()) {
>  		memset(cap, 0, sizeof(*cap));
>  		return;
>  	}
>  
>  	cap->version		= x86_pmu.version;
> -	/*
> -	 * KVM doesn't support the hybrid PMU yet.
> -	 * Return the common value in global x86_pmu,
> -	 * which available for all cores.
> -	 */
>  	cap->num_counters_gp	= x86_pmu.num_counters;
>  	cap->num_counters_fixed	= x86_pmu.num_counters_fixed;
>  	cap->bit_width_gp	= x86_pmu.cntval_bits;
> 
> base-commit: de60733246ff4545a0483140c1f21426b8d7cb7f

  reply	other threads:[~2023-01-20 14:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20  0:40 [PATCH] perf/x86: KVM: Disable vPMU support on hybrid CPUs (host PMUs) Sean Christopherson
2023-01-20 14:39 ` Liang, Kan [this message]
2023-01-20 17:32   ` Sean Christopherson
2023-01-20 19:55     ` Liang, Kan
2023-01-20 20:34       ` Sean Christopherson
2023-01-20 22:00         ` Liang, Kan
2023-01-24  1:04           ` Andi Kleen
2023-01-24 15:31             ` Liang, Kan
2023-01-31 10:59               ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1dec071d-c010-cd89-9e58-d643e71e775c@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jianfeng.gao@intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).