Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12799100rwd; Fri, 23 Jun 2023 10:47:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77TA2/WmOJbrw8ysxJNnriRDhcCew1/3FL/ZROajBl46NncadrZg8szphX1c5CUNyTf/9y X-Received: by 2002:a17:902:ea01:b0:1ad:f407:37d1 with SMTP id s1-20020a170902ea0100b001adf40737d1mr11419652plg.52.1687542444585; Fri, 23 Jun 2023 10:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687542444; cv=none; d=google.com; s=arc-20160816; b=uq/90rLisIa/uD/mPf9Ts9Ltk1LoOODHZeZRrq9px2jyScZoi6fnTQYYwQRwd6lvj6 GVsfxnBBppOAEQ0uBLWNSIKDoDS7VSTMhVX+P/OO9rhFk1lexGPM+3/M7m48xLhQPxhb zCDgoqKzT/FKmiOzZBE8UMvvFIYvJqDueqftNlBLaoS3rsACEI+S9Jak30wIPLrzJYeF cc+0Hsr3E0XTJvcREeIY3dal2QsF9T989Uzo9Z6Q4ZCfkCryvBzjX6PwX9kL1/VpQP6c Px3ZQ3FMBBPscrZJjD0AyN6eVMfsM/4JxIo0mldhGbU3mxi6D7L5Iep/Oopk4x7Yyi7J 44/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=d174zlUL/lhF0vBTL/OICvsXlNACFuiYhQ7ttHm3uTo=; b=eXY3QuHyG5ITau5hEM0tjgoP5QmrdC7uMc+nBrnm30bf5PNIJUDR14trqCN9E6tkNW k264nZdK++tnUA7LF53ukeRHKOrewDxBSirDnpBRYeE6pfi006NLO6s4Y/GzbitWgCDU Heu4HxsWd9ErUT4nsIi6HZEc5MPMC62vMPw194Zw+uRoeDr57/4CmV2a1u9mGetSKBqu SOVmiZEznWwmHSVmKEugG3BdZhUF0hPyB/TNXDBcMlyPI2u61muSMA+/yd0dqYRzsaK3 v65PQ53jrG2imCkPFH1ErWtnS9TCHTg4mDCnTmgTfzeFj2rqQwLih6gnYTtgQJ/VUiB7 ytNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wUEukFRu; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020a170903234100b001b674055d72si5270199plh.621.2023.06.23.10.47.12; Fri, 23 Jun 2023 10:47:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wUEukFRu; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232095AbjFWRNB (ORCPT + 99 others); Fri, 23 Jun 2023 13:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230506AbjFWRMq (ORCPT ); Fri, 23 Jun 2023 13:12:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DBA19A1 for ; Fri, 23 Jun 2023 10:12:43 -0700 (PDT) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1687540361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d174zlUL/lhF0vBTL/OICvsXlNACFuiYhQ7ttHm3uTo=; b=wUEukFRuQtWtID4ZOeOhNXoXQ773U6bquwTxJC7s8rOqzIlrm+gZSF7ZYmg1UhYmzJz4qm oD5Ysr/0zLXb9jT8ovdKF0Bpnlu+ruuv5VQLGVR9IpQu1tCXNMfKYOdKKjWpQ6kyj38jjk A3H8UVBPOl/2QXtQf3GaYd928rVYkoeof+erMEKQc7QMrkdtrWBK1pJnKT5YTlzAhx4C64 eK4rIHSgqMfZyHITIAvcGigQjrydcs2bQNIuo3JhRnlq9qSlzz3y5lPmbLHw+cWmTyNiTQ YRAqhj5dYBPvaNyVjqV0onfE/WhUArwF1Be/lz2+WhLL5yHn/M6an9SWQOwFHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1687540361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d174zlUL/lhF0vBTL/OICvsXlNACFuiYhQ7ttHm3uTo=; b=crRCrHYhVULMoIjeuCQU0yIWeH3xxFHKwaD5PsqTuAc+qRz2en09xW9R2TKMpVhjpwL/DE JSx8UERIkzfTFABA== To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Luis Claudio R. Goncalves" , Andrew Morton , Boqun Feng , Ingo Molnar , John Ogness , Mel Gorman , Michal Hocko , Peter Zijlstra , Petr Mladek , Tetsuo Handa , Thomas Gleixner , Waiman Long , Will Deacon , Sebastian Andrzej Siewior , Tetsuo Handa Subject: [PATCH v2 1/2] seqlock: Do the lockdep annotation before locking in do_write_seqcount_begin_nested() Date: Fri, 23 Jun 2023 19:12:31 +0200 Message-Id: <20230623171232.892937-2-bigeasy@linutronix.de> In-Reply-To: <20230623171232.892937-1-bigeasy@linutronix.de> References: <20230623171232.892937-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 again. 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 Link: https://lore.kernel.org/20230621130641.-5iueY1I@linutronix.de Signed-off-by: Sebastian Andrzej Siewior --- 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 3926e90279477..d778af83c8f36 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 /** --=20 2.40.1