From nobody Sun Feb 8 11:43:13 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A5042BE64F for ; Fri, 2 Jan 2026 09:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344838; cv=none; b=SmYEfHwl8IgCIT+p0oDMtvsSoGs9S/UfRcL5ApuOhnsfGKm3/rQRAkd2ujd5bZG+QJComnQA8OVXIcaPxREIskWAlh35IKbyemKbnzMZgzSDl27dLEM8Ex+3SYm14ejiWOxSmaEuac3T4BhZWPC3/U3Gv2CQxomS12YOuHbFrm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344838; c=relaxed/simple; bh=TNOac1DJmVODH6H1Jscbp58si1kVmhqdNk259tDLcEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZW+YqolFKyEy17ZHhq4FhnNs8t5f0HILc84viH0nwMPXVkkiQhEN8v1ZQN+JDAc1DG/3NvN/rpqcpy9TXe9WOKFc0wFvTbct3APRVTfKczNidDqV8br/dHsBLcUYSkBz7QqbumXsyh/iahPe+tV1snmVjsunbXkr2KmWdYD14qI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fKWOGzNT; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fKWOGzNT" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767344834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gl52UYjuxKXySDrefeSnj8xmRj7F+GTc8QMFl3Q24hw=; b=fKWOGzNTOY0xA+Ze2bcHPPtWh0O7MKqbKQpcPbob+0n5I12ehz7unRis1+lXA9i4/suWtI 5f/VBGLnsL8tLXr6TWHhbLJUCeRrLZNWc7W6G+pIlWkFqPBnq5PyOpCYhVOMTtzGAGgfzc HMYImxXpqpITkGx8zEw3bM4VFe+iSm4= From: Leon Hwang To: stable@vger.kernel.org, greg@kroah.com Cc: Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Leon Hwang , Ingo Molnar , Sandipan Das Subject: [PATCH 6.6.y 1/4] perf/x86/amd: Ensure amd_pmu_core_disable_all() is always inlined Date: Fri, 2 Jan 2026 17:03:17 +0800 Message-ID: <20260102090320.32843-2-leon.hwang@linux.dev> In-Reply-To: <20260102090320.32843-1-leon.hwang@linux.dev> References: <20260102090320.32843-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" [ Upstream commit 0dbf66fa7e80024629f816c2ec7a9f3d39637822 ] In the following patches we will enable LBR capture on AMD CPUs at arbitrary point in time, which means that LBR recording won't be frozen by hardware automatically as part of hardware overflow event. So we need to take care to minimize amount of branches and function calls/returns on the path to freezing LBR, minimizing LBR snapshot altering as much as possible. amd_pmu_core_disable_all() is one of the functions on this path, and is already marked as __always_inline. But it calls amd_pmu_set_global_ctl() which is marked as just inline. So to guarantee no function call will be generated thoughout mark amd_pmu_set_global_ctl() as __always_inline as well. Signed-off-by: Andrii Nakryiko Signed-off-by: Ingo Molnar Reviewed-by: Sandipan Das Link: https://lore.kernel.org/r/20240402022118.1046049-2-andrii@kernel.org Signed-off-by: Leon Hwang --- arch/x86/events/amd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index aa8fc2cf1bde..3b09ec4f2b0d 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -632,7 +632,7 @@ static void amd_pmu_cpu_dead(int cpu) } } =20 -static inline void amd_pmu_set_global_ctl(u64 ctl) +static __always_inline void amd_pmu_set_global_ctl(u64 ctl) { wrmsrl(MSR_AMD64_PERF_CNTR_GLOBAL_CTL, ctl); } --=20 2.52.0 From nobody Sun Feb 8 11:43:13 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 381D72D73B2 for ; Fri, 2 Jan 2026 09:07:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344845; cv=none; b=UEHPHEtjFzsYAW0v7QyOLKxFrgbcMDEtD50ChXoX08h4XbEZXX7H7LJ7ZCDjrHpk/uorDXox8jdy42TUuHRhyU8hT2np5v5UCejUQYW55cvsdDl3YWp8aHckF3QZANeupYeiliVxmd6MpdSRIl/qCAPtqkM3OYruwvPGb1Jx974= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344845; c=relaxed/simple; bh=DbKsjsJl7UB9Kh/oEojuD1taY+UTMizooxibpWw2+bo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IEZ9MSQvgp6xoxEsbiaHhccHrZBmNcEj9cfmbJNBqS0hLvkxpo2/x90lna89SWKUem7uACJNBs8DU91P9TKYyHJpjRL5PlC6aBnDyUdR0/UqEUp7QIYtewAI/79LP0wsBWyoDZWIdiRg00QwA7CF98Jx16uV1XP7S37Niv3hUFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=u4xnv2vu; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="u4xnv2vu" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767344840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wD12dxnkK8iphtWn4IcvFyKcXErQTxG36lzru7IgNuo=; b=u4xnv2vuzQ/IXzfdzcp6c6j3H95PEoAkT+rLbwV06f58iizut9VuZ/bs96dxhHORi9lxX0 wdMXnazprXONe1iAPNIxgGJ7LD45irX/EOWTDvUwonbWuJFS7aIjq5mKlLdg/YFuKDPGin +kQuefJ4Bc0GWZg7rZbTsbgmWGnJZAY= From: Leon Hwang To: stable@vger.kernel.org, greg@kroah.com Cc: Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Leon Hwang , Ingo Molnar , Sandipan Das Subject: [PATCH 6.6.y 2/4] perf/x86/amd: Avoid taking branches before disabling LBR Date: Fri, 2 Jan 2026 17:03:18 +0800 Message-ID: <20260102090320.32843-3-leon.hwang@linux.dev> In-Reply-To: <20260102090320.32843-1-leon.hwang@linux.dev> References: <20260102090320.32843-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" [ Upstream commit 1eddf187e5d087de4560ec7c3baa2f8283920710 ] In the following patches we will enable LBR capture on AMD CPUs at arbitrary point in time, which means that LBR recording won't be frozen by hardware automatically as part of hardware overflow event. So we need to take care to minimize amount of branches and function calls/returns on the path to freezing LBR, minimizing LBR snapshot altering as much as possible. As such, split out LBR disabling logic from the sanity checking logic inside amd_pmu_lbr_disable_all(). This will ensure that no branches are taken before LBR is frozen in the functionality added in the next patch. Use __always_inline to also eliminate any possible function calls. Signed-off-by: Andrii Nakryiko Signed-off-by: Ingo Molnar Reviewed-by: Sandipan Das Link: https://lore.kernel.org/r/20240402022118.1046049-3-andrii@kernel.org Signed-off-by: Leon Hwang --- arch/x86/events/amd/lbr.c | 9 +-------- arch/x86/events/perf_event.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index 5149830c7c4f..33d0a45c0cd3 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -414,18 +414,11 @@ void amd_pmu_lbr_enable_all(void) void amd_pmu_lbr_disable_all(void) { struct cpu_hw_events *cpuc =3D this_cpu_ptr(&cpu_hw_events); - u64 dbg_ctl, dbg_extn_cfg; =20 if (!cpuc->lbr_users || !x86_pmu.lbr_nr) return; =20 - rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg); - wrmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg & ~DBG_EXTN_CFG_LBRV2EN); - - if (cpu_feature_enabled(X86_FEATURE_AMD_LBR_PMC_FREEZE)) { - rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); - wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl & ~DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); - } + __amd_pmu_lbr_disable(); } =20 __init int amd_pmu_lbr_init(void) diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index 4564521296ac..f1dda8ee0e29 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1315,6 +1315,19 @@ void amd_pmu_lbr_enable_all(void); void amd_pmu_lbr_disable_all(void); int amd_pmu_lbr_hw_config(struct perf_event *event); =20 +static __always_inline void __amd_pmu_lbr_disable(void) +{ + u64 dbg_ctl, dbg_extn_cfg; + + rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg); + wrmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg & ~DBG_EXTN_CFG_LBRV2EN); + + if (cpu_feature_enabled(X86_FEATURE_AMD_LBR_PMC_FREEZE)) { + rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl); + wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl & ~DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); + } +} + #ifdef CONFIG_PERF_EVENTS_AMD_BRS =20 #define AMD_FAM19H_BRS_EVENT 0xc4 /* RETIRED_TAKEN_BRANCH_INSTRUCTIONS */ --=20 2.52.0 From nobody Sun Feb 8 11:43:13 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA4DD279DB3 for ; Fri, 2 Jan 2026 09:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344851; cv=none; b=XaO2NLDFrq6sbwDLp/9umP22koewqtA2YNdxUVrqKKxwzU6IP+DffGlO3UGcIFamqnKmhLH9sjLHgWj1x25BddYIUdEjeUXIDjCd1gfMluqa0gbAsDREiw+RMKVvE9zacQ8cUNtMWOIsWQyoPKvTmPgTmnyJ//bEMXuFJCGR0nA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344851; c=relaxed/simple; bh=606we/nL0XRz/O/Or1i17b8MgJv23/S0vSrqiHGEFgw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aKPQie40v3yoB+lXZ/OovuKhP+vq+hgFMiwpEJIg0JdTRUIZPO2ZA9ulu9bfKEmLyDc/ElAqyIxnZbWfMf40fLA43IZbiEdfIf9mBT3g6S5n6OwuF+uImfi8syXTeYyRo7zuye0r4qucBnHoWlWkTU0K1iyzfJLpA12rCTvydD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fDbkPhFm; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fDbkPhFm" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767344847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BK7dCxL5tYSm10/iiJpGo60DW/3GXRdSeb1BZQgwomM=; b=fDbkPhFmsQv+kCEoXyWfNk8QbJ8GLl25/mPwWflzfiKaM02pU55AFadZccEx9uQj+lY2+G GF1m0pSBq6ZFihlBfH0LRaE+XfJ/BVE2ZtxoOftXsa4xny34oyi/rpndcn+Psz88u11vmh gALcq+nbcScSzs0ahgS9rYN07CPe1+A= From: Leon Hwang To: stable@vger.kernel.org, greg@kroah.com Cc: Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Leon Hwang , Ingo Molnar , Sandipan Das Subject: [PATCH 6.6.y 3/4] perf/x86/amd: Support capturing LBR from software events Date: Fri, 2 Jan 2026 17:03:19 +0800 Message-ID: <20260102090320.32843-4-leon.hwang@linux.dev> In-Reply-To: <20260102090320.32843-1-leon.hwang@linux.dev> References: <20260102090320.32843-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" [ Upstream commit a4d18112e5317c120bcadeb486fbe950f749bb5e ] Upstream commit c22ac2a3d4bd ("perf: Enable branch record for software events") added ability to capture LBR (Last Branch Records) on Intel CPUs from inside BPF program at pretty much any arbitrary point. This is extremely useful capability that allows to figure out otherwise hard to debug problems, because LBR is now available based on some application-defined conditions, not just hardware-supported events. 'retsnoop' is one such tool that takes a huge advantage of this functionality and has proved to be an extremely useful tool in practice: https://github.com/anakryiko/retsnoop Now, AMD Zen4 CPUs got support for similar LBR functionality, but necessary wiring inside the kernel is not yet setup. This patch seeks to rectify this and follows a similar approach to the original patch for Intel CPUs. We implement an AMD-specific callback set to be called through perf_snapshot_branch_stack static call. Previous preparatory patches ensured that amd_pmu_core_disable_all() and __amd_pmu_lbr_disable() will be completely inlined and will have no branches, so LBR snapshot contamination will be minimized. This was tested on AMD Bergamo CPU and worked well when utilized from the aforementioned retsnoop tool. Signed-off-by: Andrii Nakryiko Signed-off-by: Ingo Molnar Reviewed-by: Sandipan Das Link: https://lore.kernel.org/r/20240402022118.1046049-4-andrii@kernel.org Signed-off-by: Leon Hwang --- arch/x86/events/amd/core.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 3b09ec4f2b0d..002661418830 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -892,6 +892,37 @@ static int amd_pmu_handle_irq(struct pt_regs *regs) return amd_pmu_adjust_nmi_window(handled); } =20 +/* + * AMD-specific callback invoked through perf_snapshot_branch_stack static + * call, defined in include/linux/perf_event.h. See its definition for API + * details. It's up to caller to provide enough space in *entries* to fit = all + * LBR records, otherwise returned result will be truncated to *cnt* entri= es. + */ +static int amd_pmu_v2_snapshot_branch_stack(struct perf_branch_entry *entr= ies, unsigned int cnt) +{ + struct cpu_hw_events *cpuc; + unsigned long flags; + + /* + * The sequence of steps to freeze LBR should be completely inlined + * and contain no branches to minimize contamination of LBR snapshot + */ + local_irq_save(flags); + amd_pmu_core_disable_all(); + __amd_pmu_lbr_disable(); + + cpuc =3D this_cpu_ptr(&cpu_hw_events); + + amd_pmu_lbr_read(); + cnt =3D min(cnt, x86_pmu.lbr_nr); + memcpy(entries, cpuc->lbr_entries, sizeof(struct perf_branch_entry) * cnt= ); + + amd_pmu_v2_enable_all(0); + local_irq_restore(flags); + + return cnt; +} + static int amd_pmu_v2_handle_irq(struct pt_regs *regs) { struct cpu_hw_events *cpuc =3D this_cpu_ptr(&cpu_hw_events); @@ -1434,6 +1465,10 @@ static int __init amd_core_pmu_init(void) static_call_update(amd_pmu_branch_reset, amd_pmu_lbr_reset); static_call_update(amd_pmu_branch_add, amd_pmu_lbr_add); static_call_update(amd_pmu_branch_del, amd_pmu_lbr_del); + + /* Only support branch_stack snapshot on perfmon v2 */ + if (x86_pmu.handle_irq =3D=3D amd_pmu_v2_handle_irq) + static_call_update(perf_snapshot_branch_stack, amd_pmu_v2_snapshot_bran= ch_stack); } else if (!amd_brs_init()) { /* * BRS requires special event constraints and flushing on ctxsw. --=20 2.52.0 From nobody Sun Feb 8 11:43:13 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBB5A279DB3 for ; Fri, 2 Jan 2026 09:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344859; cv=none; b=kksEtrCyJwSvkEXoFRbIt8BAuVpwI2pXmBeNzg8OmhJVuFcBuypFy7xeO0fgwsDFYh0v8WkkPSbPd0/Arp57odJ3ZnJExNZKhBM4DQ6dtxLODH0qx/h7DYy1kUimq+aVMo7hD1gbT+wLtRqcM+kBLye9M0R6Oa4nr97UJtrpeh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767344859; c=relaxed/simple; bh=nIQNvWEwyYl2hWK3GcNjeOvmr0mJVipk9z6LCDGpUBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YXx6plyRaGEqm2ptcvVodN2beoLKX5RbjiOeiOv/XFsDAdGF3psm3Aqz2csTfPlA4IrQP/DBD76YaQFcsjEArKU0RUcof1Dy0ly1MqRXMd1+c7ySnFmrT4Rf6+80cpljs/7McZqfav6wQWnTHIVMCzGkM7fLZPw0jqNM/9lqJ+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tkH6fcW5; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tkH6fcW5" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1767344855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMj5TrrlMif37vw/D7M5rWgGjiFm22plFTpEXR8IQhw=; b=tkH6fcW5Xme0JrpKnovfVILgVmIT/exsoT9krDEwZCaYTEfp5m8azT+mMHma4vlzCz1iFY cOB+OHZeSj0jLCfg5RWmL+12JF3xWevk4pw5e+255psmFDuH2oOTn3reLrAatJnG6TAc6Z hOu/apt0s2SXMySPxQPd4R5tLFTmQtY= From: Leon Hwang To: stable@vger.kernel.org, greg@kroah.com Cc: Andrii Nakryiko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Leon Hwang , Ingo Molnar , Sandipan Das Subject: [PATCH 6.6.y 4/4] perf/x86/amd: Don't reject non-sampling events with configured LBR Date: Fri, 2 Jan 2026 17:03:20 +0800 Message-ID: <20260102090320.32843-5-leon.hwang@linux.dev> In-Reply-To: <20260102090320.32843-1-leon.hwang@linux.dev> References: <20260102090320.32843-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" [ Upstream commit 9794563d4d053b1b46a0cc91901f0a11d8678c19 ] Now that it's possible to capture LBR on AMD CPU from BPF at arbitrary point, there is no reason to artificially limit this feature to just sampling events. So corresponding check is removed. AFAIU, there is no correctness implications of doing this (and it was possible to bypass this check by just setting perf_event's sample_period to 1 anyways, so it doesn't guard all that much). Signed-off-by: Andrii Nakryiko Signed-off-by: Ingo Molnar Reviewed-by: Sandipan Das Link: https://lore.kernel.org/r/20240402022118.1046049-5-andrii@kernel.org Signed-off-by: Leon Hwang --- arch/x86/events/amd/lbr.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index 33d0a45c0cd3..19c7b76e21bc 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -310,10 +310,6 @@ int amd_pmu_lbr_hw_config(struct perf_event *event) { int ret =3D 0; =20 - /* LBR is not recommended in counting mode */ - if (!is_sampling_event(event)) - return -EINVAL; - ret =3D amd_pmu_lbr_setup_filter(event); if (!ret) event->attach_state |=3D PERF_ATTACH_SCHED_CB; --=20 2.52.0