From patchwork Wed Sep 20 07:36:09 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: 142538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4315088vqi; Wed, 20 Sep 2023 10:47:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQeWu8ljOGt4RxtqktJ/TBw2pjvrVwUgA/6VLUWYBB4S+tNqZDzU6ildX1s3BNnxEB7u+O X-Received: by 2002:a05:6a20:5494:b0:153:b245:50ff with SMTP id i20-20020a056a20549400b00153b24550ffmr3450491pzk.40.1695232027013; Wed, 20 Sep 2023 10:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695232026; cv=none; d=google.com; s=arc-20160816; b=gepvUhEfYpiveTqFfq1RjOQmb4OuVaBIsmNtvhDANQaWCkgUwX4nJoboeCuqggAJCt bactqa4dWXqBIbJ9bHJbcwc3ME1PHdgTWs75iI4Eqde2TJjNrNGt2Cch/14CYyK4B3pw ZufhNKCQ7ITpQQdZVUPOpJGb90KGCnlPIyuf1OMtFzID84vtKWFxGauiw9hVQjHsag8P x7DTos6IgZbrxBI0BFQSzDiJrhJClra0YRs8AIGGUCmvUDNfVJsBEtF7mij34fSFhdpf 1Zf5hJ3/I9OP18X3o0axcwLhShiMLyJ67u3PAXlnDvqJluQ+eYhjUSyaRXvszNtvxW0x UrzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=v+JgXwP57sgUiUMevhm4cL25gu1CKeVHdhZhw9WaQac=; fh=NiEo874cXEplhhZulBsc+QY1CQhg/8TgW+n4WB3OYOk=; b=jAzdOLS54oKx2nZBq1Vz9P9cJWRBikafrTAmqwXol/mkK/yPQCS3tpOcUpeuW3CnML qbIIgin6rEaPjQPPwW9jcpu/waunDBHX8cd6zYT2Qhy9NIeWkd+QjG00IFrc0Cplj12a YzDi1lStcp7IC530hEhn/4qFuMNTSvs85YcCQkZoa3mpzEBnKBVJ1gU12dW9cklJ7cjT BF6NGyABqBl1A7PuaEvn6ra1X6LzCidv7v7XAZr8l0zimh/vZS5AXIcfG5sW1pLNCELD Ym3glkacYOtVIl9OrKrjEDwFLOUM5Ou40kJn7ouibGA1Eb6LYOcXWJvFZJDA1XXbOr0H oCEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3Ow5R83q; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TR2tqJI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z17-20020a631911000000b0057790a5a8e7si12065379pgl.190.2023.09.20.10.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 10:47:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3Ow5R83q; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=TR2tqJI+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 30B038092CA1; Wed, 20 Sep 2023 00:37:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233784AbjITHgS (ORCPT + 26 others); Wed, 20 Sep 2023 03:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbjITHgR (ORCPT ); Wed, 20 Sep 2023 03:36:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DAFECA; Wed, 20 Sep 2023 00:36:11 -0700 (PDT) Date: Wed, 20 Sep 2023 07:36:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695195370; 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=v+JgXwP57sgUiUMevhm4cL25gu1CKeVHdhZhw9WaQac=; b=3Ow5R83qQtQi7n8EtEk+ltH7aqOKx9XV5njBhCjROmjLL31cPfqQYZAlNpHHOxGQ6Ab0Jr CNLfUqc28U5iR79jNAqTlqJ8mmm7uhuTnbJcRfl1o+RIYQLG2s+Fz4iAOwjI/L/tppfXmm ThS5wRzyRG6oIoCijZM53osmw2xCHwS2C0jnR2WcdR4HA4+hBOeBZHCfHC5NyIxIE2xdTu at7XAtlW3fIOqp7ftbxHR6jFU7lbW3qwpPNq4DILAJlhGtm3wpnZH3qS/r+w9/x7SHUwsX XQ4KJfcNrLB0+UYaFU+Ypd9+NUGJPOpQAp8mrJ72le1i0C2sgm+8ODEgjGg41Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695195370; 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=v+JgXwP57sgUiUMevhm4cL25gu1CKeVHdhZhw9WaQac=; b=TR2tqJI+dE0HLy1YvHzEarAjsMfpgixABJJi2Qpd04kzhkz47yL9HaOOpDKCGojHw0zkwt JADFyVlCSf14qtDw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/rtmutex: Add a lockdep assert to catch potential nested blocking Cc: Crystal Wood , Thomas Gleixner , "Peter Zijlstra (Intel)" , Sebastian Andrzej Siewior , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230908162254.999499-7-bigeasy@linutronix.de> References: <20230908162254.999499-7-bigeasy@linutronix.de> MIME-Version: 1.0 Message-ID: <169519536955.27769.443350425283875935.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 20 Sep 2023 00:37:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777579617726947631 X-GMAIL-MSGID: 1777579617726947631 The following commit has been merged into the locking/core branch of tip: Commit-ID: 45f67f30a22f264bc7a0a61255c2ee1a838e9403 Gitweb: https://git.kernel.org/tip/45f67f30a22f264bc7a0a61255c2ee1a838e9403 Author: Thomas Gleixner AuthorDate: Fri, 08 Sep 2023 18:22:53 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 20 Sep 2023 09:31:14 +02:00 locking/rtmutex: Add a lockdep assert to catch potential nested blocking There used to be a BUG_ON(current->pi_blocked_on) in the lock acquisition functions, but that vanished in one of the rtmutex overhauls. Bring it back in form of a lockdep assert to catch code paths which take rtmutex based locks with current::pi_blocked_on != NULL. Reported-by: Crystal Wood Signed-off-by: Thomas Gleixner Signed-off-by: "Peter Zijlstra (Intel)" Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230908162254.999499-7-bigeasy@linutronix.de --- kernel/locking/rtmutex.c | 2 ++ kernel/locking/rwbase_rt.c | 2 ++ kernel/locking/spinlock_rt.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index a3fe05d..4a10e8c 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1784,6 +1784,8 @@ static int __sched rt_mutex_slowlock(struct rt_mutex_base *lock, static __always_inline int __rt_mutex_lock(struct rt_mutex_base *lock, unsigned int state) { + lockdep_assert(!current->pi_blocked_on); + if (likely(rt_mutex_try_acquire(lock))) return 0; diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c index c7258cb..34a5956 100644 --- a/kernel/locking/rwbase_rt.c +++ b/kernel/locking/rwbase_rt.c @@ -133,6 +133,8 @@ static int __sched __rwbase_read_lock(struct rwbase_rt *rwb, static __always_inline int rwbase_read_lock(struct rwbase_rt *rwb, unsigned int state) { + lockdep_assert(!current->pi_blocked_on); + if (rwbase_read_trylock(rwb)) return 0; diff --git a/kernel/locking/spinlock_rt.c b/kernel/locking/spinlock_rt.c index 842037b..38e2924 100644 --- a/kernel/locking/spinlock_rt.c +++ b/kernel/locking/spinlock_rt.c @@ -37,6 +37,8 @@ static __always_inline void rtlock_lock(struct rt_mutex_base *rtm) { + lockdep_assert(!current->pi_blocked_on); + if (unlikely(!rt_mutex_cmpxchg_acquire(rtm, NULL, current))) rtlock_slowlock(rtm); }