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 254533E51C5 for ; Mon, 27 Apr 2026 17:34:39 +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=1777311282; cv=none; b=AuQQ3U10Mtclb1ruvY/SQApjQokh/bdBWBAdrnzKc5HTWcLtb5yvQuUqVkAWqMIrfYtjgODDGq6Ym1cbj+HorBT9x/pY0PztNBEVZPInxf0jP/KaKT8DfJgcO54iRJWHaS1/YidVNSGybd9GahKubhxiXLyRdl+ngLkmythvFkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777311282; c=relaxed/simple; bh=zXsxEj1uV1jT6g8uPy7vpdf7iKBLusxzqQTDXrMZoXE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bWYOrGIQRS2sKiAkeNpna6qJh3Mqc04KDDdvDBSBbO65+ExkrEMX+uja5ikBQssTrHJ9dccH82YUav9uYRGvWzIz8rhvxJM5bv2GWQeKhptpP9l2Gth7CFTj1L2bN2lUGpvtWPOWa8K5pUH7wthWJzBOSb7LfNMZHlRjKx8+S60= 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-82fa5ecd760so5240816b3a.0 for ; Mon, 27 Apr 2026 10:34:39 -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=jRIk0hT8qGFsbsJrLHOPDFJRpIfm3Mjx3pXla33FbhRHbv8lSEEbe2u6iik0LxrdT5 qo4t106PBtPqc13ezTvm664Np+K500yaae+6NMs97825Y20JBTPKpUI5Xvt1R2KA006L ndejdJ5A5XqsvyGQnjmpZmqkPtD/8wUHdiqzRcIeYbQ2+CK6HD0nbb78Dy8qLxKlULs+ 7AVkcoVb4xi2BHqtyliOA/G61YMfS6emIxmi753mLp3aNB8EyBc0W3hIZLOk9x3GGduX 7hvUYZO0Cw3PBXRz2/gI8bpOxw0t9AqPMqbgj/n6dG9ztTNGnIs1YkYUeuc10pZseT12 Fi+g== X-Forwarded-Encrypted: i=1; AFNElJ+QTpAIorT9z+XzvkpQprLacDdHMdROOQckmt2224o4mxjs1SvmgiqfTl6VtEHyQDu8amzmUYQ8MDQzs/o=@vger.kernel.org X-Gm-Message-State: AOJu0YwmdwKJfKMrR2yzY30062bIXjWzqtKn7o5iyz4qCfQHVE2KH/5U /4pEIKvMFOocRlFmMhSI6YQofaNcDR2YXYEtVKZvDRK94x50zbhjECDG7sEncuBzwOijwhuhE5j /NUEF2Q== 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: linux-kernel@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.