From nobody Sun Feb 8 02:41:11 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 E73452907 for ; Sat, 18 Jan 2025 05:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737179387; cv=none; b=tscZjMiO2wxRRuj8UAexpVn9khuVtNA3TbTK66RYDxT+vV3Lqsjm/F2FNysKeoZjQAD5I1YR56++McTmbqHLbslh1wlhxI2t+0yFOYylRBbHaKoTvxHT1jDUpVmscMa9At+hpXfIPV7icXgO8xq51+Wc9gxgMh+iZDMLL75uWRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737179387; c=relaxed/simple; bh=zyEyWvRj1G+ViW1k4PuGWnk2ySjl5eQKZoxoXHW//30=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=a6lLEv61n5LlADdqUVeJ6BKciMh/Uq2zDF1eIKGgiO7/ioxkDVFBRme6n0RtaogmnJbeVno0o0Azt608ayOgj75mUVWlOU8Q16z3Kwx9tnbYKQlCfddmIfEkW84t6LtfWbftsZVB3adYQKCZOvu/NVo7wWohFcaUkAumdu+oAck= 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=KnD6uufG; arc=none smtp.client-ip=209.85.214.171 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="KnD6uufG" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-216281bc30fso66593555ad.0 for ; Fri, 17 Jan 2025 21:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737179384; x=1737784184; 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=kH6ewzDAUNXsCE0JCxntis2zNVY+BVKDevpBejHbyGA=; b=KnD6uufGql8CE2TDp2isRw6sTBxSMtGunoezVSW88Z1uzl4PDNdCuk36dhExTw3FKT GorL1ErhDI6tmlq5au7komvhD0w7Dzbwt+hzI6RDdM2XRpBGrd35t9AHwBfzeD0GQR5+ q9XhF0l/T5rTdxm9q7kfbaxS+/qmvXPNN7by8E3ojxvjWye87P12SlL6JKcSR+pmebw+ RaUXjjNxXQIl6DK+IqhKuEvy6tvtuUMgTByYpTKU2ug/izXi36yAnS8alFmxwnoPMRIJ w56/QRnjOzRd1jEx3hTTNZnTiQarv7JCToM3gLV99juzD5bhmJwyh2I6VoHI5HNUabkK e3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737179384; x=1737784184; 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=kH6ewzDAUNXsCE0JCxntis2zNVY+BVKDevpBejHbyGA=; b=jJiuBlzxBAC75JizRRR9mdNVY9BsCxT+Lk2ZSfuK0bpWr1oTmoLWgzpUO8z/hHyemN 0NeNPDwyY8UooJPcMOB0fou9CzIOwbpoxIR6orFWdGjr+EZ/P89Hm3b0AHYp2tSuIGgY NUWwj+U64LbG1va9u+uecyEP3OUyikEv2YS5E8oEPpY1m9p3UqzF9SmgBKdoyk7eGXHm TuDCjSw6Dhpa6sbvoZKRtBeycRU0kC+7gDba1l1ZKrnHvKkVCc20X96SmOGM2wOTxFR+ Eanu5QERMEPf8lJVSyDA7sPNs1xe5Bu9mAHYjDda9oUBS++xm8mZaPtXfA+BRC7ut0AI WK/A== X-Gm-Message-State: AOJu0Yw6A3zhE+1ItrZRZr+V1UIl68RWNNQnnprlHOcGoUW5C5ag+m9+ GFf1KS+uGf1ZFu7HxFsYNtAfCmClxnHAduz/zQNsfqh9tAHBUrA1/tYF1Q== X-Gm-Gg: ASbGncvrXphJkwP1A9Ar6jKewL6pHtTSdTg+FE1+Epn7MG4NgAjugFFrIU9X2++WoCR s8OY2ytsXJW/8/K9rd0SI0XZZ8lm2MeOsJuyacb52FhJa8rZWoIisr/B/IHEzyaCGvklHBti6Tl VyVuFR+0P0drTlY/tIK3p2c6gGouTjEXnCu+aVW6vFlMcisvB/X1wkoXEDEF7KYpH5VzVyTEhqp G7ffBfDUTN8X+6vxVPaxmriK9blZtKfvmUO+6LO7c1inJ3WgmVrhEZO8L+3NGkVUX4WjSIWXmWg s68NCDPJvJZtBU25wJu8NiPGDFYIaHnNEsICEEt8OdK6TpEuSApwYDpXe3l9pw== X-Google-Smtp-Source: AGHT+IGD6MQnkgsF9tp0/+8LDmiwyA7mbecUaP4uUH+qo+5/u9EHCLo76fnBYJvIuGK7goiVFCM7OA== X-Received: by 2002:a17:902:d50d:b0:21a:8769:2fec with SMTP id d9443c01a7336-21c3553b336mr75890375ad.10.1737179384139; Fri, 17 Jan 2025 21:49:44 -0800 (PST) Received: from localhost.localdomain (p10213112-ipngn20001marunouchi.tokyo.ocn.ne.jp. [153.220.101.112]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2cea076esm25345345ad.6.2025.01.17.21.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 21:49:43 -0800 (PST) From: Ryo Takakura To: bigeasy@linutronix.de, boqun.feng@gmail.com, clrkwllms@kernel.org, llong@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 v3] lockdep: Fix wait context check on softirq for PREEMPT_RT Date: Sat, 18 Jan 2025 14:49:00 +0900 Message-Id: <20250118054900.18639-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! This version uses CONFIG_DEBUG_LOCK_ALLOC instead of CONFIG_LOCKDEP. Thanks Waiman for the advise! v1: https://lore.kernel.org/lkml/20241202012017.14910-1-ryotkkr98@gmail.com/ v2: https://lore.kernel.org/lkml/20241227040824.83626-1-ryotkkr98@gmail.com/ Boqun, let me know in case if I should add you as tag. (Please forgive me and ignore if not what the tag intends for...=20 I thought its appropriate reading the document[0].) Sincerely, Ryo Takakura [0] https://www.kernel.org/doc/html/v6.12/process/submitting-patches.html#u= sing-reported-by-tested-by-reviewed-by-suggested-by-and-fixes --- 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..0640a147b 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_DEBUG_LOCK_ALLOC +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 8c4524ce6..f0edb0abc 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -1012,3 +1012,15 @@ unsigned int __weak arch_dynirq_lower_bound(unsigned= int from) { return from; } + +#ifdef CONFIG_DEBUG_LOCK_ALLOC +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