From patchwork Fri Dec 15 11:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 179203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9207797dys; Fri, 15 Dec 2023 03:43:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IErKZKXu6br2fUfbvkaGZOKPIjylcxdMRYgnPf7giK3KrtoEzxc6j1KEeM3V3jPfOmjsySQ X-Received: by 2002:a05:6871:7389:b0:1fb:75c:3fe6 with SMTP id na9-20020a056871738900b001fb075c3fe6mr14465304oac.70.1702640620717; Fri, 15 Dec 2023 03:43:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702640620; cv=none; d=google.com; s=arc-20160816; b=ODxR1HHM2bShU1VpuTi6KRfZ6F9AWKgpr06Y2PoFpJIVvLUdO19li0s8pjWDoevnjS fHYOSxyS1A82lyIB7dkuowicnTeh+7iCgBkIUxr5DgakLmJ7Wn+KaYvtiGAOwspg7QMY 6+RMa2dmWbAEF5Rv1F8/5bZ1Xeh54hUJg85is7HjvifZ5TOoCr/I5Yp0SgiNztuseTGc FkdzMYLeo44n15zVrl+ttrsPGBgJDSnzYqc57ZvA5JrxFQ08mg3VR6DHWekgBO3flXD5 2/zYiobDnHt5QNEGm3Wr68KB4SZfnFnhaYxlFCd+PPoi6czxif4oiMWJV0HZ2DZJekmP w07w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=7Q7Ku4Lhyrtkwj5E1dLtuUeOMVelgb0yIL0BU0v4KUc=; fh=Rp093gBuFecc+gJIojw7p34tyneHqzxuhP2VRb9j92I=; b=iGOOYBqW85Tg7/d7mzdCDD0ZyynAQM6675IdE9Umc9JS9Ra3vVi5EUsWWUI+Xcfcdh ZaV0o5rRMz3iTbb1oeR06rfENcfvBExpX0F24NHfEPFNk/Z38gXnmG5GgHjq6XoFvzEP knGdvwPRnrMP77hD5I6ySIBMNMZZAck2B/PeoMxQElKuK4P3Cc0qr1MGYfRZhtMZGYKq 0I4B+0IRrKjZfBhPH49vJV50fOd3WV6pyzfJPFSLUMgIA9f7GzYsZMAlIMCXS4vayW1v wg6k/852NEowCMo0jlqYlPJJZ+VVuUnTqK9yOS9i50GUrcydxowhlzUDpDIe/Nwutrzk XMxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CdOV0a28; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-859-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-859-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h12-20020a65638c000000b005acb88d8c15si12969784pgv.386.2023.12.15.03.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:43:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-859-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CdOV0a28; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-859-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-859-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 45B07B2265A for ; Fri, 15 Dec 2023 11:43:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A862925564; Fri, 15 Dec 2023 11:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CdOV0a28"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fWyK3Ky9" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A6267250E8; Fri, 15 Dec 2023 11:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 15 Dec 2023 11:42:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702640579; 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=7Q7Ku4Lhyrtkwj5E1dLtuUeOMVelgb0yIL0BU0v4KUc=; b=CdOV0a28viDk9VATTd62WT9HF2p1DzMob50NQ6ItVNh57vobFjy7g6lxQdgwCDqgyYXjgO tlKJYgGboJyTBNTx3XejE1PXkC5KUIE78VEWif1JNDKceNNFwIMxReWuIILKGAq/BxQbQQ HUMvitqHDjIGwtWVdG5LfXPzl8TQ2v3sttz9sJ6c9iVLkx5V42KzBVlu3fIRzi7HmoTGGe aqscEBPkaZCdcdklW02CSwPZ9w8BqgoFouB2NZ3rwcWZ53HY6171tOyJS6NGreskWA8LUS KzCQDvLa8g1pWa0IPGSfGRXHSdtsULbahKeIiqs2mDnY+uHmk1Jrb4xz1okqXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702640579; 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=7Q7Ku4Lhyrtkwj5E1dLtuUeOMVelgb0yIL0BU0v4KUc=; b=fWyK3Ky9g6ice3/RP91y/y22o+Qnjm+gu2WNu+xCTtbFS0Tyg2s9UAKJuVv6epdmte7Q3G fPA5fttZJdogOBDw== From: "tip-bot2 for Mark Rutland" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf: Fix perf_event_validate_size() lockdep splat Cc: Lucas De Marchi , Pengfei Xu , Mark Rutland , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231215112450.3972309-1-mark.rutland@arm.com> References: <20231215112450.3972309-1-mark.rutland@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170264057897.398.420625380438569608.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785347003489170319 X-GMAIL-MSGID: 1785348091612016348 The following commit has been merged into the perf/urgent branch of tip: Commit-ID: 7e2c1e4b34f07d9aa8937fab88359d4a0fce468e Gitweb: https://git.kernel.org/tip/7e2c1e4b34f07d9aa8937fab88359d4a0fce468e Author: Mark Rutland AuthorDate: Fri, 15 Dec 2023 11:24:50 Committer: Peter Zijlstra CommitterDate: Fri, 15 Dec 2023 12:33:23 +01:00 perf: Fix perf_event_validate_size() lockdep splat When lockdep is enabled, the for_each_sibling_event(sibling, event) macro checks that event->ctx->mutex is held. When creating a new group leader event, we call perf_event_validate_size() on a partially initialized event where event->ctx is NULL, and so when for_each_sibling_event() attempts to check event->ctx->mutex, we get a splat, as reported by Lucas De Marchi: WARNING: CPU: 8 PID: 1471 at kernel/events/core.c:1950 __do_sys_perf_event_open+0xf37/0x1080 This only happens for a new event which is its own group_leader, and in this case there cannot be any sibling events. Thus it's safe to skip the check for siblings, which avoids having to make invasive and ugly changes to for_each_sibling_event(). Avoid the splat by bailing out early when the new event is its own group_leader. Fixes: 382c27f4ed28f803 ("perf: Fix perf_event_validate_size()") Closes: https://lore.kernel.org/lkml/20231214000620.3081018-1-lucas.demarchi@intel.com/ Closes: https://lore.kernel.org/lkml/ZXpm6gQ%2Fd59jGsuW@xpf.sh.intel.com/ Reported-by: Lucas De Marchi Reported-by: Pengfei Xu Signed-off-by: Mark Rutland Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20231215112450.3972309-1-mark.rutland@arm.com Tested-by: Pengfei Xu --- kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index c9d123e..9efd0d7 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1947,6 +1947,16 @@ static bool perf_event_validate_size(struct perf_event *event) group_leader->nr_siblings + 1) > 16*1024) return false; + /* + * When creating a new group leader, group_leader->ctx is initialized + * after the size has been validated, but we cannot safely use + * for_each_sibling_event() until group_leader->ctx is set. A new group + * leader cannot have any siblings yet, so we can safely skip checking + * the non-existent siblings. + */ + if (event == group_leader) + return true; + for_each_sibling_event(sibling, group_leader) { if (__perf_event_read_size(sibling->attr.read_format, group_leader->nr_siblings + 1) > 16*1024)