From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AD8B3F166B for ; Wed, 6 May 2026 14:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778076182; cv=none; b=p4ZcRdT68/HItB9Oq0LeqRvenb0lWjiOqM8ROuo+49Iw0pM/RJkbEJQRQkuA4xuTgoeD9W0P4tsIxOkPbDAK6nVeyR8ZtiOi94X04NMkmfa6DC4yr8JcPph9DI/wEC7hJ1mBfgh489qDRB2OGsu8D1QIyMivz7mUanxUqdF77BM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778076182; c=relaxed/simple; bh=hcD0toSVOOteQihfnyNTjZWFv8+nFbgAq2DRSdobVB4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=po1ivVxa3xQUlUCzQzGkkYGgo4RoZxhQV8ZcC0Ep8kVqFMglYQ5Xsv3mIyd9DacL6GoZVj5kgJ4148YvacPO2vhXAWS1lPTgDFHXk1olH68ZDEypLhk3dhGy4MPPfA6PTAo0MbN9LLrCiZG4yvlmovsanOTNrD5u6Wt4cxTZADY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ew2VpmFP; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ew2VpmFP" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ba6ca20ceeso12349575ad.2 for ; Wed, 06 May 2026 07:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778076179; x=1778680979; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=4inufemHLYVw7e0Jw1npJcdd1uysY1TXg59beodcgGQ=; b=ew2VpmFPwYUxcWwdPoARfvhlzAn5cIe5vtO9/39ay38WU3hL5wNvrCMR6U2gvT12DI 8PgowFtXER1fpqjDKdM2CMiHAIRZCRT9dUeftX+epmwPMcNdN5KdnVIThgEdQF2NUx1H 5wsOIcCBzOdD38qIvSNGCErduUFZsz72A5VtuXK+gMhN6s6JnwLyO8eJaHTkG6lMTvCc /mKC2XdY0qnSrlxHOGvhqqV75EjgMs5abHsv8LUqBGTnzffrdklBRr1aMB34sfEPazMx PfYOdzSzT2wOCy4zHTozB0dP7ALdK1iq26ACkBLSox3kl7r2tHQ8XpACgzr0x/UES7V/ JMTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778076179; x=1778680979; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=4inufemHLYVw7e0Jw1npJcdd1uysY1TXg59beodcgGQ=; b=efToZt9ytPHTHE+7Sc+aNOoBXW3xA6fE9FtvyHs8/A8PbVUZdZPFje+FuAz+ofgrPk MkmTzZIVTDCAERredeITTYDp2qcxbeWCgpURQRv3LJC94zT8cG69Tl72yCx/iRMQNg3a bLtfk4oiVhu7MXwiiW/+lniWD8S+r0/mJfwKRtOEOtp03H9r4a4OVM1K3fW7Vo5Rt1W4 yfViaTbOsnDn56jf/5Amo7zQUJQD+EFGIX8bOigVNh+SFSIubrkrTTQbhQsdVsfBFZc0 cOzmU0Ah5eniYj/XgFCxDaoxzxI4wVHzHbA02OpIf9+GZVcdddWRv6HHoc6N4UhvysVN BOWw== X-Forwarded-Encrypted: i=1; AFNElJ+z038NljZxTcW8emqMhOwt0xeCDrSHXO3cRr9mCpLkjnlP4fpOrI2cLPECY6J1wkulH6k=@vger.kernel.org X-Gm-Message-State: AOJu0YzqmQVnG6uKWOtY7akq/aSWVlG/nHVAnvJnU/+C3nuC2CC/JlHA tiDwVp7wir4rXnuhuSuVK4DIcO4/DVGCc5SKcoRmaXHb+mfgwmhn6D+TOJYJhEwtNz+2/jbT+xa r+V9GJw== X-Received: from plqt9.prod.google.com ([2002:a17:902:a5c9:b0:2b9:a1d0:9f13]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1ad0:b0:2b2:5597:bad4 with SMTP id d9443c01a7336-2ba7a20545bmr34631745ad.30.1778076178340; Wed, 06 May 2026 07:02:58 -0700 (PDT) Date: Wed, 6 May 2026 07:02:57 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260423150340.463896-1-seanjc@google.com> <20260423150340.463896-5-seanjc@google.com> Message-ID: Subject: Re: [PATCH v2 4/4] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data From: Sean Christopherson To: Jim Mattson Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, Paolo Bonzini , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Mingwei Zhang , Stephane Eranian , Dapeng Mi Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, May 04, 2026, Jim Mattson wrote: > On Mon, May 4, 2026 at 10:19=E2=80=AFAM Sean Christopherson wrote: > > > > On Fri, May 01, 2026, Jim Mattson wrote: > > > > @@ -5052,7 +5051,7 @@ static struct perf_guest_switch_msr *intel_gu= est_get_msrs(int *nr, void *data) > > > > * wrong counter(s). Similarly, disallow PEBS in the guest= if the host > > > > * is using PEBS, to avoid bleeding host state into PEBS re= cords. > > > > */ > > > > - guest_pebs_mask &=3D kvm_pmu->pebs_enable & ~kvm_pmu->host_= cross_mapped_mask; > > > > + guest_pebs_mask &=3D guest_pebs->enable & ~guest_pebs->cros= s_mapped_mask; > > > > > > It would be helpful to save this mask somewhere, so that it can be > > > used when calculating guest_pebs_idxs in x86_pmu_handle_guest_pebs(). > > > I think that code needs a fix similar to the one in commit > > > 58f6217e5d01 ("perf/x86/intel: KVM: Mask PEBS_ENABLE loaded for guest > > > with vCPU's value."). > > > > Blech. This all feels like a losing game of whack-a-mole. Proxying th= e PMU > > through perf is a mediocre approximation for non-PEBS events, and it se= ems like > > it's downright awful for PEBS. Ideally, we'd just rip out all of the p= erf-based > > PEBS virtualization support, and only support PEBS through the mediated= PMU. :-/ > > > > Absent drastic measures though, saving the effective guest_pebs_enable = in the > > per-CPU tracking does seem like the least awful approach. Though I don= 't quite > > understand why we can't use GLOBAL_STATUS for x86_pmu_handle_guest_pebs= (). I.e. > > what happens if x86_pmu_handle_guest_pebs() only processes counters tha= t actually > > got marked as overflowing? >=20 > x86_pmu_handle_guest_pebs() is called in the path where we are > handling GLOBAL_STATUS bit 62 (GLOBAL_STATUS_BUFFER_OVF_BIT). > Individual PEBS PMCs are not configured to raise PMI on overflow. Right, but aren't the per-counter OVF bits still set in GLOBAL_STATUS? Ah,= no, at least that's not supposed to happen, per commit 8077eca079a2 ("perf/x86/= pebs: Add workaround for broken OVFL status on HSW+"). Well that's lame.