From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44EEBC531CA for ; Thu, 23 Jul 2026 13:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HqzpRenBrC0k573Xz55iMUEOlsnWt7HrE0/NCI0Oux4=; b=Desb5esrJSNmCApZke8kJBghQy i0jQKM5LOcVNQuy7bCaOHAfZZWahBlSF4rCsy5inhGS2j9MNbHDpL7R2Hat6BNAg1dI6y4ZrP2X7U aJd2y0CEUTh2XhEQCoJsl2P8A/aBm5qxMnMtW0apXfa2qzAs5WpIaoVvyyG6bEGgHIfHAugtDmjIc Tfqd2q9fmoR3BEbRyjHqTiJwSP5NLw5lD+iY58qWUCGG6dGc9Cph4VAKEk4hmbprYj+plMVLZJxoU jFGVgBWS9fPLX16kx8nHVRqVKgYjsoZ8+T52Hu53WBm3l8AkH95J1lzpTrWUh6LZocV2Gfit9x5Dw 6cdbotJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wmsK3-0000000EDI3-047G; Thu, 23 Jul 2026 12:14:43 +0000 Received: from out-179.mta0.migadu.com ([91.218.175.179]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wmsJz-0000000EDGy-3qwW for linux-arm-kernel@lists.infradead.org; Thu, 23 Jul 2026 12:14:41 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784808862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HqzpRenBrC0k573Xz55iMUEOlsnWt7HrE0/NCI0Oux4=; b=wtNxnFBbvRysCrVy7Zn+LE1e5eZ/6vy0CWb31IiOnUJOAXHkpwaYeNLv6bnnw4PBachhtk 48gIzVlZ8lmhK/QQiBO0C9yhjGyP2dTFK1vdpbvj6vDcOBBoc14qAKL93H1Le88reQgaOv Fiwhz1foGDDP6K6bf5maTTfCyyy0pIc= Date: Thu, 23 Jul 2026 13:14:03 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v5 1/4] perf/core: Fix sched_task callbacks for CPU-wide branch stack events To: Puranjay Mohan , bpf@vger.kernel.org Cc: Puranjay Mohan , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Will Deacon , Mark Rutland , Catalin Marinas , Leo Yan , Rob Herring , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , James Clark , Ian Rogers , Adrian Hunter , Shuah Khan , Breno Leitao , Ravi Bangoria , Stephane Eranian , Kumar Kartikeya Dwivedi , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20260616155716.2631508-1-puranjay@kernel.org> <20260616155716.2631508-2-puranjay@kernel.org> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: <20260616155716.2631508-2-puranjay@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260723_051440_164927_CF1D6B2F X-CRM114-Status: GOOD ( 16.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 16/06/2026 16:57, Puranjay Mohan wrote: > perf_pmu_sched_task() returns early when cpuctx->task_ctx is non-NULL, > deferring to perf_ctx_sched_task_cb() in the context sched_in/out > paths. But perf_ctx_sched_task_cb() only walks the task context's > pmu_ctx_list -- PMUs that have only CPU-wide events are not on that > list and their sched_task callback is silently skipped. > > On ARM64 with CPU-wide branch recording: > > perf record -b -e cycles -a -- ls > > armv8pmu_sched_task() is skipped whenever the scheduled task has an > unrelated perf event (e.g. a software event), and branch records leak > across task boundaries. > > A second problem exists in __perf_pmu_sched_task(): it passes > cpc->task_epc directly to pmu->sched_task(), but task_epc is NULL for > PMUs with only CPU-wide events. When perf_pmu_sched_task() does reach > the loop (because cpuctx->task_ctx is NULL), this causes a NULL > pointer dereference: > > Unable to handle kernel NULL pointer dereference at virtual address 00[.] > PC is at armv8pmu_sched_task+0x14/0x50 > Call trace: > armv8pmu_sched_task+0x14/0x50 (P) > perf_pmu_sched_task+0xac/0x108 > __perf_event_task_sched_out+0x6c/0xe0 > > Fix both: > > - Remove the blanket early return in perf_pmu_sched_task() when > cpuctx->task_ctx is set. Instead, skip individual CPCs that have a > task_epc (those are handled by perf_ctx_sched_task_cb()). CPCs > without a task_epc are CPU-only and must be handled here. > > - Fall back to &cpc->epc in __perf_pmu_sched_task() when task_epc is > NULL, so the callback always gets a valid pmu_ctx. > > Fixes: bd2756811766 ("perf: Rewrite core context handling") > Signed-off-by: Puranjay Mohan > --- > kernel/events/core.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > Acked-by: Usama Arif