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 253BD3DA7D8 for ; Mon, 27 Apr 2026 17:34:40 +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=1777311281; cv=none; b=Zw789N3tblphIkofWW32Q3c+7QBNWUZUHpk/s0FLtC3XVWq94FOEB3uJxe04ws5o7tr6C5+F8aZo1CBz/3HJkk/vLcxFOtCKu5o17Dp4VkbZYdjrhJNvXOD7lk/DQJ9/pL95aBITYrg91pvpYLdEuPKXEKdcilMZULMkRGxj/eY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777311281; c=relaxed/simple; bh=zXsxEj1uV1jT6g8uPy7vpdf7iKBLusxzqQTDXrMZoXE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hVKJ6dS8u8fidInVExiS9FwuC1RurdUbeqocxwamcIt0KkvTqIYOjAXBy7b/FwJPfz0YoQkC+PJqmc6s4FZeMjnxsYBWSqjaJpfrJvRzptpLG2zTodEupXVR8bZ67RbpLiniBAw+mlkO6yTHORfFS05MKOtkBPJvqdy215MvZOk= 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=warKmD6n; 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="warKmD6n" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82fa5ecd760so5240818b3a.0 for ; Mon, 27 Apr 2026 10:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777311279; x=1777916079; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YdEnpzDIOCEcXBvG6SCSAkx4aELVLebcgUGVQXndMA8=; b=warKmD6n2W02WagiH3IGv9uPEFHrJJo6RKaw4EAdfd7iKERgqHAufUN1XPMC+QrsVB aVMYBV9+WX1dYV7c2GKOoeDbm7RSgLO49o6sN2ZheU4QmjqWR56tR91zkIOVvxEJ+us8 rbL0ZlOKAxl42VSQmvpUHjgBiDOPmiLMyt9rlY9S2azb6EKegfIfhhDzqGdq25Ty2z8h 4lidO2nTyObGtwUggF9ddec9JMv332p07hqUuHYf9D01ikmW5oBtB3yR56i/kquvz5P/ VjYJ7jAC5/MKtGS2GRvoyOLphlLdefpEqD6kgDH42PT4Viqu3VW3HVipiD+1Z+vHVu14 sEZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777311279; x=1777916079; h=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=YdEnpzDIOCEcXBvG6SCSAkx4aELVLebcgUGVQXndMA8=; b=PKcbNkZ33TOSWNL4NZaX/rAmsLSUN7qfvAHX9fawCUYNjyDNm5NyCzUB3njRdcFJqQ yc+R3lRCsCpdrw1Pj8cBFozG8tS2wZb9XD+x7IMv0OMTWZLdIBke0NIeUNSK5YIYI+GK V8JbRseCmpkVnfMjFr6ymML4Ypmi5yRKnIAOiY+Nte+J8aMUDqTwmoXcVjhjBfQym9sd v8KakYv9cOn1Qsc+ZdnatBqTIWntVGj/jEq8g5p9bFfy51v4KbhPT16LBS6dyyoYAafw zl+VtuZYplNdaS8M+lja5GfDkgmlVJBmqIgrGmbq85U/qDPJHuw1/m6Ld8msZyB6Skej UO9A== X-Forwarded-Encrypted: i=1; AFNElJ8DPnFIbq2MpwJkZehDrbcOtg18CtG3nVoqQgXno9Cd45et5byeV9iaMPdNwZNvgMdlcMI=@vger.kernel.org X-Gm-Message-State: AOJu0YxHQ4mzRKrzOSbfPH5QDS1XRuC5GZc9ph3mP+HxFVtm7RehYWEC tncBvDH/4rcsD9gQc0Il9h6mpgmDdOEt0O0eyC3E48PwU2fycN7tDFLmSmkycRubgqirPEGA4NW 0mTKgYg== X-Received: from pfblh2.prod.google.com ([2002:a05:6a00:7102:b0:82f:ad57:40bb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3498:b0:82f:85c8:fc19 with SMTP id d2e1a72fcca58-82f8c8502d9mr43552491b3a.11.1777311279289; Mon, 27 Apr 2026 10:34:39 -0700 (PDT) Date: Mon, 27 Apr 2026 10:34:38 -0700 In-Reply-To: <9d318656-3faf-479c-817f-f32f7d5caaae@linux.intel.com> 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-3-seanjc@google.com> <9d318656-3faf-479c-817f-f32f7d5caaae@linux.intel.com> Message-ID: Subject: Re: [PATCH v2 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused From: Sean Christopherson To: Dapeng Mi 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, Jim Mattson , Mingwei Zhang , Stephane Eranian Content-Type: text/plain; charset="us-ascii" On Mon, Apr 27, 2026, Dapeng Mi wrote: > > @@ -5065,6 +5056,26 @@ 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 = 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 the guest > > + * is running, then simply keep the host values resident in hardware. > > + */ > > + arr[(*nr)++] = (struct perf_guest_switch_msr){ > > + .msr = MSR_IA32_DS_AREA, > > + .host = (unsigned long)cpuc->ds, > > + .guest = guest_pebs_mask ? kvm_pmu->ds_area : (unsigned long)cpuc->ds, > > + }; > > The code looks good to me. > > one nit: people may be curious on why set same host value for guest if they > don't notice that the same value on host and guest would lead to the MSRs > would be removed from MSR load-list. Maybe add comments to further explain it. +1. In the same comment (maybe on the function?), I'll also call out that the inclusion/exclusion of MSRs must only ever be based on constant host state, specifically because of the need to _remove_ MSRs from the list when KVM doesn't need to load a guest value on entry.