From nobody Fri Dec 19 16:06:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB201E7D0AD for ; Thu, 21 Sep 2023 21:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbjIUVNL (ORCPT ); Thu, 21 Sep 2023 17:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231717AbjIUVMZ (ORCPT ); Thu, 21 Sep 2023 17:12:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5898B98A45; Thu, 21 Sep 2023 10:56:48 -0700 (PDT) Date: Thu, 21 Sep 2023 06:41:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695278467; 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=g44M9hKvXEDwyXwCGx4cA7u2mkZTmo3YlGxVozqTY0Q=; b=sv+cMhSArTF4tfQ+u7e+XFTDJWvDXKk8BR7Q3LRxuVePUFrxoxIEXlE9E+8nDDpvvda83T c3VsXlOHmtrDHLyp1PxZFp72OCwQMS2rgpwyMIwAPba1Fry80RllcKCaNFAxsfjUXITymC G2uNzFQFdc2UjKOC74ljSjr/VTUVDV7GAiVaOJhXfdcaaW4lhdD/6pbJd99v6VGTQyVsOC cBMMAknGmwNcZQUA9NQ8Lxj7pPR9DdmpZv0j5IsDtNH4/K+7wNGJJDNfkITG6yQYqDfRtV Y+LaIpREC4f7jZK6I9Za1aMVtnKCxkqYYie+YGGINQLYJL+Fvnr8lfPeG5rbpQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695278467; 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=g44M9hKvXEDwyXwCGx4cA7u2mkZTmo3YlGxVozqTY0Q=; b=B3sACAN4d9PwM+tihDtaf6VrEDYJN+PxevT78CKXLLDD93MpKoRlwIs+UIUvKOz1vkBHsq hl22DDYJpiHABJAA== From: "tip-bot2 for Sebastian Andrzej Siewior" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] locking/seqlock: Do the lockdep annotation before locking in do_write_seqcount_begin_nested() Cc: Tetsuo Handa , Sebastian Andrzej Siewior , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230920104627._DTHgPyA@linutronix.de> References: <20230920104627._DTHgPyA@linutronix.de> MIME-Version: 1.0 Message-ID: <169527846710.27769.2808849894554476760.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/urgent branch of tip: Commit-ID: 41b43b6c6e30a832c790b010a06772e793bca193 Gitweb: https://git.kernel.org/tip/41b43b6c6e30a832c790b010a06772e79= 3bca193 Author: Sebastian Andrzej Siewior AuthorDate: Wed, 20 Sep 2023 12:46:27 +02:00 Committer: Ingo Molnar CommitterDate: Thu, 21 Sep 2023 08:37:44 +02:00 locking/seqlock: Do the lockdep annotation before locking in do_write_seqco= unt_begin_nested() It was brought up by Tetsuo that the following sequence: write_seqlock_irqsave() printk_deferred_enter() could lead to a deadlock if the lockdep annotation within write_seqlock_irqsave() triggers. The problem is that the sequence counter is incremented before the lockdep annotation is performed. The lockdep splat would then attempt to invoke printk() but the reader side, of the same seqcount, could have a tty_port::lock acquired waiting for the sequence number to become even agai= n. The other lockdep annotations come before the actual locking because "we want to see the locking error before it happens". There is no reason why seqcount should be different here. Do the lockdep annotation first then perform the locking operation (the sequence increment). Fixes: 1ca7d67cf5d5a ("seqcount: Add lockdep functionality to seqcount/seql= ock structures") Reported-by: Tetsuo Handa Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230920104627._DTHgPyA@linutronix.de Closes: https://lore.kernel.org/20230621130641.-5iueY1I@linutronix.de --- include/linux/seqlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 987a59d..e9bd2f6 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -512,8 +512,8 @@ do { \ =20 static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subcl= ass) { - do_raw_write_seqcount_begin(s); seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_); + do_raw_write_seqcount_begin(s); } =20 /**