From nobody Sun Feb 8 13:39:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DAA5EB64DA for ; Mon, 10 Jul 2023 08:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232686AbjGJINy (ORCPT ); Mon, 10 Jul 2023 04:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbjGJINZ (ORCPT ); Mon, 10 Jul 2023 04:13:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E36CE7; Mon, 10 Jul 2023 01:13:24 -0700 (PDT) Date: Mon, 10 Jul 2023 08:13:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1688976802; h=from:from:sender:sender:reply-to: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=QmxEJkHfTKInkH+veC+TMsvNnEkLPnoWkAzHDAyTGxE=; b=46UHh6y3XrPRrKJ3SjGN0YUZY/84V1itqZ5EnhjPTfpHvW70onGukErJ7ewIKM5+w+a2WO z5YN1tKYAT7qWqoehvLfaZxAyQMrualGzO8cUK3QLkN23TMXFrSUFtc+OT8Cu1ocMg1EsR 3nHn7w3EvLG7c6yB+5L/0VBlwFo5LK4/9YDCRgkHCfXmpLDmozJ7JuwZpWoVb2p/SD6GBI m7BoqpGv1cMiwjFmdK8LUv1YZhqMXV3xFAHUhfwJnkcipaKevJoE9Yym6pLbml8O62UZNl DmmAF/x0NKHRj4wjKGvYRH6UnAVajYiNEesR8i5SKig4Uz0IyWH9rJtffzyy6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1688976802; h=from:from:sender:sender:reply-to: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=QmxEJkHfTKInkH+veC+TMsvNnEkLPnoWkAzHDAyTGxE=; b=0elY/nPtYviK9iAC+zRpm07pnu1+pEsxn8qE+5ZGzxFuFPjHqmPIeC9RgdbFntCMETSL+/ JJJMQfO4iuaX+RBg== From: "tip-bot2 for Namhyung Kim" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf/x86: Fix lockdep warning in for_each_sibling_event() on SPR Cc: Greg Thelen , Namhyung Kim , "Peter Zijlstra (Intel)" , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230704181516.3293665-1-namhyung@kernel.org> References: <20230704181516.3293665-1-namhyung@kernel.org> MIME-Version: 1.0 Message-ID: <168897680188.404.3122821140126581927.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 27c68c216ee1f1b086e789a64486e6511e380b8a Gitweb: https://git.kernel.org/tip/27c68c216ee1f1b086e789a64486e6511= e380b8a Author: Namhyung Kim AuthorDate: Tue, 04 Jul 2023 11:15:15 -07:00 Committer: Peter Zijlstra CommitterDate: Mon, 10 Jul 2023 09:52:20 +02:00 perf/x86: Fix lockdep warning in for_each_sibling_event() on SPR On SPR, the load latency event needs an auxiliary event in the same group to work properly. There's a check in intel_pmu_hw_config() for this to iterate sibling events and find a mem-loads-aux event. The for_each_sibling_event() has a lockdep assert to make sure if it disabled hardirq or hold leader->ctx->mutex. This works well if the given event has a separate leader event since perf_try_init_event() grabs the leader->ctx->mutex to protect the sibling list. But it can cause a problem when the event itself is a leader since the event is not initialized yet and there's no ctx for the event. Actually I got a lockdep warning when I run the below command on SPR, but I guess it could be a NULL pointer dereference. $ perf record -d -e cpu/mem-loads/uP true The code path to the warning is: sys_perf_event_open() perf_event_alloc() perf_init_event() perf_try_init_event() x86_pmu_event_init() hsw_hw_config() intel_pmu_hw_config() for_each_sibling_event() lockdep_assert_event_ctx() We don't need for_each_sibling_event() when it's a standalone event. Let's return the error code directly. Fixes: f3c0eba28704 ("perf: Add a few assertions") Reported-by: Greg Thelen Signed-off-by: Namhyung Kim Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20230704181516.3293665-1-namhyung@kernel.org --- arch/x86/events/intel/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index a149faf..2a284ba 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3993,6 +3993,13 @@ static int intel_pmu_hw_config(struct perf_event *ev= ent) struct perf_event *leader =3D event->group_leader; struct perf_event *sibling =3D NULL; =20 + /* + * When this memload event is also the first event (no group + * exists yet), then there is no aux event before it. + */ + if (leader =3D=3D event) + return -ENODATA; + if (!is_mem_loads_aux_event(leader)) { for_each_sibling_event(sibling, leader) { if (is_mem_loads_aux_event(sibling))