From nobody Mon Feb 9 00:20:27 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DD1170802 for ; Fri, 27 Dec 2024 04:08:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735272519; cv=none; b=gadygfGjUboPDqumO/I0G9AAA7w4orGKmyAu+byLCBu/shUvTGj9qD6h7mvNVNoIS/yBTuIqk+cOxMJob1d/VuMBhuCBR0jaQmpEH1gMjlm0UiLkRl0+HwJT7vZnxbnLaPt0b5dLZIeaXhH5ib0qgYoj5EyZIXU2EQlhmcwh7oU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735272519; c=relaxed/simple; bh=wqML3VQ0gwMYDsw/3NqJIoNvhc9bs6GaEiQJSKeRzU0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=p0dL2V5zh98v6CXZofikj7YsQsKvMWJ5ykg/tDi82XfOOcsOreYGcT/0LMqk8AcCPdS0lvjwKgGjCSJvzSPsfUPjt3GP/yMck9dlSVv/18IKrz7+6ix0MhQw/O+Fds9P9TFGh/gvxb4OtgNm/ZmVQ5IqXhjoYK706iKYI42K9S0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l/GTsCtx; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l/GTsCtx" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21634338cfdso118469565ad.2 for ; Thu, 26 Dec 2024 20:08:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735272517; x=1735877317; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AGBPKZkVSwZ246MMQ8j/Faxxrn44L8Wku9zAKTR/iqM=; b=l/GTsCtxyDCxRXvv5MZkovw3zvS1KG5eJHj3Nll4CoWFu063YXknLwdMdtwLFKRAyd DHwz6KvUPiMliU7DtPifcfPuLECeRE4AbJerueEw4nTsPfgXaRbQkCOTCNlPovUwSoFQ FOb16oV2pxj9QFnotsPMoXu9xP538P+A9wOHHwedJvTzscRw7Bsf6BGfR8vSaucIWndO IHEhWUJ1oAZbeelCsv8qiKNeHJbnSi5h1r34s06255gUqqghyyHpE1Oe9LVsUvgvo/lg stAzGWn0Xz3MXp+kwPMnTWUMTtLl6Wj/h6TqLSzhwtqua4cKOyj0pS3wrHJuknnKej4C x7eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735272517; x=1735877317; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AGBPKZkVSwZ246MMQ8j/Faxxrn44L8Wku9zAKTR/iqM=; b=cOsB8neRIb6Lcf2z7ki1oSTzlkfaTfhAkrdHAhf3PGBAEiqrExeHCqWikcsykrzchW 63MAJDkOelirhSnOn1jDeeK0gJUT0at38V6ASFXRkjs9m11pONq9+UoAERtN7N8Phm4f BJSTwjVNeolgAVM9Is68vCKD1csmGfQSOU3BVX+tJIpnYptP1po+OHSYmpXMUc9/U6VJ NZaOdgOQ5/9hKQsMc6sOxTuNI8USUzN47jNNSIfKQo8zU+k3vLmUVe10sgTfP7mG/VBH dRpp5iNhooCWuICkNJLu7JHuJNCl7A7c5sY9JabvuwUSOXuzMAWGY+D7r1vCRc8UnAYb w3MQ== X-Gm-Message-State: AOJu0Yzi21GMfVh1VLgeSy4SOt+Y8IHMz429bYNsn4s74ntb1aPNBAWP AEoRcbQhJGZohkkU8hBfZrjpaLl9E/zoeD/42VOx9inQTzdUhHKMu+SevQ== X-Gm-Gg: ASbGncvMh5rp9nNOTaPoF081RhK6wu2gTY1TblM/JDhVQYgEjIMBJfqbTIofO3qV/mr vfD4bpAMLD7ID2c1c2t2OThbEZ/slbX2c6YBb0fMQS8dB/QwZtTtOHUyUekVQ5Url0BOeRDRxe7 tAwcyTpjGYqo6n6sRquH+Qbekl2i3XcBYlgO8F2r4a4KYNt20uPH6UfLz6914hQWVLObHAk+Bfs zUEeT5+Ib7m47V1Qbw0KNE47oKC4z0f7NEC71/tswdZSuIvTZl5LRGVFjDVWUyBH4EuhhScsnT3 u/ujrgDnG5FvCiUn3xeLbpyfxzA= X-Google-Smtp-Source: AGHT+IGA91NZFQkp1zy0ot+57/lIY9AOTCKrgqdQ2t2BaMtyQmLjkBd7jza1FARcO2PmZ/7oc0yrfw== X-Received: by 2002:a17:902:c411:b0:215:2f00:67b1 with SMTP id d9443c01a7336-219e6e8c79emr361222545ad.6.1735272516882; Thu, 26 Dec 2024 20:08:36 -0800 (PST) Received: from DESKTOP-NBGHJ1C.local.valinux.co.jp (vagw.valinux.co.jp. [210.128.90.14]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc96e585sm127368035ad.70.2024.12.26.20.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 20:08:36 -0800 (PST) From: Ryo Takakura To: bigeasy@linutronix.de, boqun.feng@gmail.com, clrkwllms@kernel.org, longman@redhat.com, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, tglx@linutronix.de, will@kernel.org Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Ryo Takakura Subject: [PATCH v2] lockdep: Fix wait context check on softirq for PREEMPT_RT Date: Fri, 27 Dec 2024 13:08:24 +0900 Message-Id: <20241227040824.83626-1-ryotkkr98@gmail.com> X-Mailer: git-send-email 2.34.1 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 Content-Type: text/plain; charset="utf-8" Since commit 0c1d7a2c2d32 ("lockdep: Remove softirq accounting on PREEMPT_RT."), the wait context test for mutex usage within "in softirq context" fails as it references @softirq_context. [ 0.184549] | wait context tests | [ 0.184549] ----------------------------------------------------------= ---------------- [ 0.184549] | rcu | raw | spin |mutex= | [ 0.184549] ----------------------------------------------------------= ---------------- [ 0.184550] in hardirq context: ok | ok | ok | ok = | [ 0.185083] in hardirq context (not threaded): ok | ok | ok | ok = | [ 0.185606] in softirq context: ok | ok | ok |FAILE= D| As a fix, add lockdep map for BH disabled section. This fixes the issue by letting us catch cases when local_bh_disable() gets called with preemption disabled where local_lock doesn't get acquired. In the case of "in softirq context" selftest, local_bh_disable() was being called with preemption disable as it's early in the boot. Signed-off-by: Ryo Takakura --- Hi!=20 This version fixes the issue by adding lockdep map for BH disabled section. Thanks Boqun for the suggestion! Changes since v1: https://lore.kernel.org/lkml/20241202012017.14910-1-ryotkkr98@gmail.com/ - Fix the issue by adding lockdep map for BH disabled section.=20 This let us catch mutex usage within "in softirq context" selftest as it disables BH section. Also, may I add Boqun as tag? --- include/linux/bottom_half.h | 8 ++++++++ kernel/softirq.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/linux/bottom_half.h b/include/linux/bottom_half.h index fc53e0ad5..f77dc746c 100644 --- a/include/linux/bottom_half.h +++ b/include/linux/bottom_half.h @@ -4,6 +4,7 @@ =20 #include #include +#include =20 #if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_TRACE_IRQFLAGS) extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt); @@ -15,8 +16,13 @@ static __always_inline void __local_bh_disable_ip(unsign= ed long ip, unsigned int } #endif =20 +#ifdef CONFIG_LOCKDEP +extern struct lockdep_map bh_lock_map; +#endif + static inline void local_bh_disable(void) { + lock_map_acquire_read(&bh_lock_map); __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET); } =20 @@ -25,11 +31,13 @@ extern void __local_bh_enable_ip(unsigned long ip, unsi= gned int cnt); =20 static inline void local_bh_enable_ip(unsigned long ip) { + lock_map_release(&bh_lock_map); __local_bh_enable_ip(ip, SOFTIRQ_DISABLE_OFFSET); } =20 static inline void local_bh_enable(void) { + lock_map_release(&bh_lock_map); __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET); } =20 diff --git a/kernel/softirq.c b/kernel/softirq.c index 4dae6ac2e..a8211ba9a 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -1073,3 +1073,15 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned= int from) { return from; } + +#ifdef CONFIG_LOCKDEP +static struct lock_class_key bh_lock_key; +struct lockdep_map bh_lock_map =3D { + .name =3D "local_bh", + .key =3D &bh_lock_key, + .wait_type_outer =3D LD_WAIT_FREE, + .wait_type_inner =3D LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. = */ + .lock_type =3D LD_LOCK_PERCPU, +}; +EXPORT_SYMBOL_GPL(bh_lock_map); +#endif --=20 2.34.1