From nobody Tue Dec 2 00:04:08 2025 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.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 6261732572E for ; Tue, 25 Nov 2025 14:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764082472; cv=none; b=q2PA0Nf5KccNjfrkQdkS3xP/Gy2t0Rp9WOXYjs35eK3F/WpFsHwsRKP3gr9vzVDc+pfTGqIENo0ujfSl9sc/r1NH1HSkVam3lTrUffN+DpnlznUw0iJvI51hHywoijkS6RP9q57NXJnATk8zGsv6yuKEGMoSLZxsoShPxHHFmds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764082472; c=relaxed/simple; bh=SY3h2OiAfeF8gvDTCa2KyNN2joU8OiMB4qj8UaoZZOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jIKjwMBxOzigMayYxVu2f1w65PNomIrKwgjTueDnypyBTLi/GgTSY2OR1Nm8Q/qYHrOa5GxEqtaY7++HLMlnROQeGSmXQT0lxKy4iLnoEQH6coPhxp787jy/+x3y1h9NpRV23iH8PtcmveHIsjuWG/kmv2z48zbKnrGQxpcVJ28= 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=aol7RiiM; arc=none smtp.client-ip=209.85.222.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="aol7RiiM" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-8b2d7c38352so679607385a.0 for ; Tue, 25 Nov 2025 06:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764082469; x=1764687269; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=DPIrzW6iTbtfPk+JpxES9ORQpB2Xp4/r12xmpy14FPg=; b=aol7RiiM8ee4fRlhPjR6diNPdyL/MVo4kjr/jRsUYK7EilW/ruB8E7JlY9dL29Mh5l Qla3pKhlQwYIJ9cclphsvk9OalHRrX5P0K4MisL2+QjEIyy9bvXhcpoepFldi74OvhtX Uk6WwVG5RWags/bF7Qt3FmSIpSJgRZSemabb1ntshopGpcMidM6/gIkFeK+ZvWTcemzF pwQ/sjfEwR8qlQkhN2ft1OOR/HPDXKoSUBe0LysnL1n6eCjgeBqLnRWV5l1m39pHWhin qWwc22w59BmckYx85RLaVqkvPLtFjUUTAbgckRGENhIfZqmAXHv/0J7vhtr7aUmnW0ms qn2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764082469; x=1764687269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DPIrzW6iTbtfPk+JpxES9ORQpB2Xp4/r12xmpy14FPg=; b=Fmo4CuL3/UoKf5G9liuIEqzSqTDGhFIqtNBJEOFh56Zafvie9QP3G7Zptcu1/S509S RhYjRyO7vGDdIKu7SpoKAwJvCYHnXF4+8K+rv0Awg+3i5YAgCM1lMXM1YviMRyTiv4D+ X6j24BnTXKWljehsDCt1r96UGLaRlGBEvW4zS3buy/6j3tSxlzMR2gLdEgw3MmDa2kv+ NiWim/gJIpP7/UOLxdcoNt/Ba9i5uFImBmMJ+3c/zZczcSAz7Wi4Fo91C0yPj8+wCAqf 2uy4W524q3im5+Y+uskaBgNSjdkk+Q8KhMPAhYx7rjVM8pzpt9/gvOitn36GrGSNoLsk wCAg== X-Gm-Message-State: AOJu0YyjOAXeYzK7HW3Z2s/XD4b+5bOti2/4OHIl9WvH9Fv8LW/0X1YP e4Wra+3Subi+9JpaH/fpk9nB36i+0dlO2KPNpwi1NDuFgGgh4NuTjOJd X-Gm-Gg: ASbGncsKo8LluyrKJPMvBAPtmAmMvM9t8USP2fvH2qohQdlVC2FvutKOhq3mTBqmCl7 /MTCY4PbSJSX73lT7YOEUSGqzDz5kFpEjSqREoEiB43fz99O18EYTwasP+RdP1MW7J64vcPbf9c lai7a0MHZVJt0JI/6J/aKiUq8BDVi31R4QWk+Kw/gHMPhHS5ui1zW4d1Cm//328fP+lVeQS8rhi fgGjytnqAUfMwDsokqw8RftOaJbvmoILGZRkXPTXt50NeLLkY8lJTBID7S7SFzjrKWLrR4G6Sm3 4GZAR1qU6usCfmsuUS5N7+cibwZJqW168uqiVDfBuP81IMN3puNjYUwmVsI+nj2cKfjlVbOtOfI OtjC0elTiEeMGUO1oixTf9fY3LQ6roaqnE9pMwZuiXhesv5QyUX/2JmJEOFz8p1wI/v58GSElLQ V9T/z5LMxA948cGPwWUJzzoTzC6PQZSscCERRU9WiQs8w7W+uIxMzBn4Rgl32NlHg/nc2qRKm0G bQWeLgUk2BgI+c= X-Google-Smtp-Source: AGHT+IHli/HwnKXw7BqPcW2CE37T0dBCJTzUIBxElCd67FpsvIJJFlJ8tKftnDmRJhXWGNHY8/BkHA== X-Received: by 2002:a05:620a:1a07:b0:84b:7b84:4ec with SMTP id af79cd13be357-8b33bdcb246mr1906196085a.22.1764082469215; Tue, 25 Nov 2025 06:54:29 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b3295d9dc2sm1216179485a.39.2025.11.25.06.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 06:54:28 -0800 (PST) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id 4C05DF4006A; Tue, 25 Nov 2025 09:54:28 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 25 Nov 2025 09:54:28 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgedujeeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeevueehlefhiedvgeffjefgteeugfeh ieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfh gvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthho peduuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqnhgvgiht sehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrh gruggvrggurdhorhhgpdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurght ihhonhdrohhrghdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdrtghomh dprhgtphhtthhopehsfhhrsegtrghnsgdrrghuuhhgrdhorhhgrdgruhdprhgtphhtthho pehnrghthhgrnheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhonhhgmhgrnhesrh gvughhrghtrdgtohhmpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Nov 2025 09:54:27 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, linux-next@vger.kernel.org, peterz@infradead.org Cc: akpm@linux-foundation.org, Boqun Feng , Stephen Rothwell , Nathan Chancellor , Waiman Long , Ingo Molnar , Will Deacon , Sebastian Andrzej Siewior Subject: [PATCH] locking/mutex: Initialize mutex::magic even when LOCKDEP=n Date: Tue, 25 Nov 2025 06:54:21 -0800 Message-ID: <20251125145425.68319-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: References: 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" When DEBUG_MUTEXES=3Dy and LOCKDEP=3Dn, mutex_lock() still checks on ->magic, hence debug_mutex_init() should be called in mutex_init_generic() as well. While we are at it, decouple LOCKDEP logic from debug_mutex_init(), because in this way debug_mutex_init() only needs one parameter, and we now have mutex_init_lockep() for LOCKDEP=3Dy scenarios. Reported-by: Stephen Rothwell Closes: https://lore.kernel.org/lkml/20251117202214.4f710f02@canb.auug.org.= au/ Reported-by: Nathan Chancellor Closes: https://lore.kernel.org/lkml/20251121215819.GA1374726@ax162/ Fixes: 3572e2edc7b6 ("locking/mutex: Redo __mutex_init()") Reviewed-by: Waiman Long Signed-off-by: Boqun Feng --- Peter, Feel free to fold it into commit 3572e2edc7b6 ("locking/mutex: Redo __mutex_init()"), just resend it properly so it won't fall off your radar ;-) kernel/locking/mutex-debug.c | 10 +--------- kernel/locking/mutex.c | 8 +++++++- kernel/locking/mutex.h | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c index 949103fd8e9b..2c6b02d4699b 100644 --- a/kernel/locking/mutex-debug.c +++ b/kernel/locking/mutex-debug.c @@ -78,16 +78,8 @@ void debug_mutex_unlock(struct mutex *lock) } } =20 -void debug_mutex_init(struct mutex *lock, const char *name, - struct lock_class_key *key) +void debug_mutex_init(struct mutex *lock) { -#ifdef CONFIG_DEBUG_LOCK_ALLOC - /* - * Make sure we are not reinitializing a held lock: - */ - debug_check_no_locks_freed((void *)lock, sizeof(*lock)); - lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP); -#endif lock->magic =3D lock; } =20 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index f3bb352a368d..2a1d165b3167 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -51,6 +51,7 @@ static void __mutex_init_generic(struct mutex *lock) #ifdef CONFIG_MUTEX_SPIN_ON_OWNER osq_lock_init(&lock->osq); #endif + debug_mutex_init(lock); } =20 static inline struct task_struct *__owner_task(unsigned long owner) @@ -173,7 +174,12 @@ static __always_inline bool __mutex_unlock_fast(struct= mutex *lock) void mutex_init_lockep(struct mutex *lock, const char *name, struct lock_c= lass_key *key) { __mutex_init_generic(lock); - debug_mutex_init(lock, name, key); + + /* + * Make sure we are not reinitializing a held lock: + */ + debug_check_no_locks_freed((void *)lock, sizeof(*lock)); + lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP); } EXPORT_SYMBOL(mutex_init_lockep); #endif /* !CONFIG_DEBUG_LOCK_ALLOC */ diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h index 2e8080a9bee3..9ad4da8cea00 100644 --- a/kernel/locking/mutex.h +++ b/kernel/locking/mutex.h @@ -59,8 +59,7 @@ extern void debug_mutex_add_waiter(struct mutex *lock, extern void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_wai= ter *waiter, struct task_struct *task); extern void debug_mutex_unlock(struct mutex *lock); -extern void debug_mutex_init(struct mutex *lock, const char *name, - struct lock_class_key *key); +extern void debug_mutex_init(struct mutex *lock); #else /* CONFIG_DEBUG_MUTEXES */ # define debug_mutex_lock_common(lock, waiter) do { } while (0) # define debug_mutex_wake_waiter(lock, waiter) do { } while (0) @@ -68,6 +67,6 @@ extern void debug_mutex_init(struct mutex *lock, const ch= ar *name, # define debug_mutex_add_waiter(lock, waiter, ti) do { } while (0) # define debug_mutex_remove_waiter(lock, waiter, ti) do { } while (0) # define debug_mutex_unlock(lock) do { } while (0) -# define debug_mutex_init(lock, name, key) do { } while (0) +# define debug_mutex_init(lock) do { } while (0) #endif /* !CONFIG_DEBUG_MUTEXES */ #endif /* CONFIG_PREEMPT_RT */ --=20 2.50.1 (Apple Git-155)