From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 742BF3ACA61 for ; Tue, 14 Apr 2026 22:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776206991; cv=none; b=WvKyLWGrzYsKG/k3MdhTq4ChwrrmTZd2u/WkS7FxuOcdFFALEL275acYjg7bw3TLLgkS0wz3Jeyfelu5b8F+74CfrZyuRVZj3/Qp0aC8kUxS0VP8bIgy+RGR0mkTs2mUMDErEmcOWr/7LYqE0/7Blz7Hya3V8zDU0IVdUDMDWgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776206991; c=relaxed/simple; bh=2w8FCsUeUvgD6onjKxIhyqqgoHp1gSabAVxysWnlmzQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a4ZP2PlLTTutnzoOhgqSrarpC0QGwswLDplNr+HlLMjq6tLCoaQjryRpOnn1cOc9pPxV3whmoWfiE42dRQuZuvxit/Yfdl6TDMZ5EFaL1V9mJshiGTQlVvRxuydUNPbARSDpkjVdJVU8AIVwQRFDjbWq129VhjxAsu+xtO7YYzA= 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=rTjeqcz5; arc=none smtp.client-ip=209.85.210.202 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="rTjeqcz5" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82c7ec40f92so5630224b3a.0 for ; Tue, 14 Apr 2026 15:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776206989; x=1776811789; 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=XRasnSp3LeKygs+54FOeXokg/h9FwjkuSVLECbKoWoE=; b=rTjeqcz5+N7mwf7X1G8vnZe0S5fWNDYdSJcw2MjKf0Q9bm0UdBP6Dn4AiiixtR6FFl yyeF0JmKTKHUHEAv2tyVrHwxm9C/5c4SDbtP7Tw1TXAy/AEaBXh2768Rh5AwYKeXatyO CSQBeeOoKv1bWQYl/j1oPkxQxWUh/kg9g9LTeUGym+hL7+nkG6plQ8WJp0XJnRU7ABHK UeOtb7VSCHtfqt2C98ofAM34O3rjsQiHpSgiWnM/+JJUOusMsHJPoI6l61BOcuYWDLej uj/QqCd0L3KiiyIHIRlNEfEwXAGvUUYDi0QnBM0/gzUbZhV5tIthyK4VerSWlhD5tdjm SE0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776206989; x=1776811789; 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=XRasnSp3LeKygs+54FOeXokg/h9FwjkuSVLECbKoWoE=; b=mpAa9iB7e8SO/hHaWGhlGshKvzfGMfX44iDDZf3cfYWFzFJNi0cFug2hjpx877RGpY /U6Z0N5EfjTKYYBXGWYlmS+2auaJtXUIx6hAmxMRnUKYpgaUl1paC2RjifvfXecu+V83 EJprWs+13L1fafsEEiVO9sP3lQxCUuYDVHZ8v0kUHl//W5ZMFCS70BHKBQLYlmtdO33o KLuhdRYAuCN2BhQuWkxAiQJXIOyGAex0B97HYvFm8P/8T04Bmlq8r1IdTQKLoE5pK2Hz 4AHo7gLI99OGHOEXqEtcPyNFa1Z7qzR4PwoEVSrfRj2SyNiVHKv7bj1mA/fRY+FH5YEj tBqA== X-Forwarded-Encrypted: i=1; AFNElJ9FBIJrrooEbyhKNI9XTXW1dNcNdohkcqabYSoI7bWUSYEff9l6Jzmm9ruW+O4Hz6u8JgpoGFxUnlSHc00=@vger.kernel.org X-Gm-Message-State: AOJu0YwV8S+uSdCvFc64vg8Z2aiLBEAzN/A+lT/ijjcIPiJWFToUVGZm 1MkrU8VYyreyShJTrY5Y/Vez3Tl9vzjB4r81UkAAfN83an490rpZyXngRhaThZ4W3vAMxaUU4gX Do/drzA== X-Received: from pfbde16.prod.google.com ([2002:a05:6a00:4690:b0:82f:5aef:db75]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:9083:b0:82c:b808:4c59 with SMTP id d2e1a72fcca58-82f0c2e6c46mr19583002b3a.46.1776206988555; Tue, 14 Apr 2026 15:49:48 -0700 (PDT) Date: Tue, 14 Apr 2026 15:49:47 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260414191425.2697918-1-seanjc@google.com> <20260414191425.2697918-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused 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 Tue, Apr 14, 2026, Jim Mattson wrote: > On Tue, Apr 14, 2026 at 12:14=E2=80=AFPM Sean Christopherson wrote: > > @@ -5065,6 +5056,28 @@ static struct perf_guest_switch_msr *intel_guest= _get_msrs(int *nr, void *data) > > if (pebs_mask & ~cpuc->intel_ctrl_guest_mask) > > guest_pebs_mask =3D 0; > > > > + /* > > + * Context switch DS_AREA and PEBS_DATA_CFG if and only if PEBS= will be > > + * active in the guest; if no records will be generated while t= he guest > > + * is running, then running with host values is safe (see above= ). > > + */ > > + if (!guest_pebs_mask) > > + return arr; >=20 > I think this has an unintended side effect. If DS_AREA and > PEBS_DATA_CFG were previously listed (because pebs_guest_mask was > previously non-zero), KVM will leave the stale entries in the MSR-load > lists. >=20 > KVM only clears MSR-load list entries for enumerated MSRs with > matching guest and host values. Argh, right. This as a delta change I guess? I'd love to overhaul the int= erface, but reworking KVM to play nice with core_guest_get_msrs() would be much mor= e difficult. diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 20a153aa33cb..3244d5589981 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5059,22 +5059,20 @@ static struct perf_guest_switch_msr *intel_guest_ge= t_msrs(int *nr, void *data) /* * Context switch DS_AREA and PEBS_DATA_CFG if and only if PEBS wil= l be * active in the guest; if no records will be generated while the g= uest - * is running, then running with host values is safe (see above). + * is running, then simply keep the host values resident in hardwar= e. */ - if (!guest_pebs_mask) - return arr; - arr[(*nr)++] =3D (struct perf_guest_switch_msr){ .msr =3D MSR_IA32_DS_AREA, .host =3D (unsigned long)cpuc->ds, - .guest =3D kvm_pmu->ds_area, + .guest =3D guest_pebs_mask ? kvm_pmu->ds_area : (unsigned l= ong)cpuc->ds, }; =20 if (x86_pmu.intel_cap.pebs_baseline) { arr[(*nr)++] =3D (struct perf_guest_switch_msr){ .msr =3D MSR_PEBS_DATA_CFG, .host =3D cpuc->active_pebs_data_cfg, - .guest =3D kvm_pmu->pebs_data_cfg, + .guest =3D guest_pebs_mask ? kvm_pmu->data_cfg : + cpuc->active_pebs_data_c= fg, }; } =20