Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp4032108rdg; Wed, 18 Oct 2023 12:50:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlL2vcjeF7+zyQTGq9yfTrIyeIiNK2dTprGXF2jEAKN4hYzcHFh8AO91dzC2wNPMv5ogGf X-Received: by 2002:a05:6a00:2308:b0:690:422f:4f17 with SMTP id h8-20020a056a00230800b00690422f4f17mr115548pfh.4.1697658616302; Wed, 18 Oct 2023 12:50:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697658616; cv=none; d=google.com; s=arc-20160816; b=xjhUMcy0S9+KTlwAJe4k04mrCdvkMpdBVTpF6rJeDh3AxlgYjIuq2n6gOOpf61Q6Yq BjPrrhBhHFhtP+TKzwPCVUumWyCV0IG3MZxhP8Kv06ZeyZTTyV6UQk1colaVJovTcD5X F7ZKay8YeLB2v+EaMdFYZ5P8Oc6N4Bov/dGMscV0LhPjCk0euobCb5RgvdWAy2sOcR24 7bZDdLmVaIEMaCct33mVW8Set07q8wmYXgk//IQaUM33sIVZIuOCwqKk50Ws3dxWNU2m GLUaIr60+5u0LI7WrmCRNo8oTSsZTGi94eOMjlaxJyW8fo8kVP9FhAsMPTFdMo7bNi1u 8RDQ== 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:from :dkim-signature; bh=d70wFwXulEx1BEkYka3RH1xY2ngWeBIL+MztFYjvhlc=; fh=gmSYkz3jiLpQAS6QZLTF5lbtui7xufTlaTV/quOBDnc=; b=RQp3AwbZh8GGDPmJiTykyH2xcOrHY/+bVSr9Ip3BAyUd0gCJVwCKqM8CRw0v72+x5J o0wYwz90cu/sy2KReJE1/4dH5Dg2YJCVWz2DPEtxTkSV8sXq4spFrnJvr4o7W/bCshrT C7pJO1zFNIhujCPW2ePY9RCMhKQARXrm91gb4xQoHViOxjIW9l7DaPohhlFbvUcyVDau NrqgJrBattlysNyx5eyG9jJoXco9nabfNh6b0dICHBfndra7VQBnkmHLGCelaIVKKsGm uU9W741SsDDzFVifOM0HLuI++EMbeSDgnKXP8Wwntlvsv+wwNAUjGXeoiHp3N12LobW1 uqag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=uTajf4Lr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z5-20020a633305000000b0059b79bf220csi2758339pgz.662.2023.10.18.12.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 12:50:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=uTajf4Lr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C08198138DDC; Wed, 18 Oct 2023 12:50:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232107AbjJRTtY (ORCPT + 99 others); Wed, 18 Oct 2023 15:49:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbjJRTs6 (ORCPT ); Wed, 18 Oct 2023 15:48:58 -0400 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6931A134; Wed, 18 Oct 2023 12:48:53 -0700 (PDT) Received: from smtp.gmail.com (1.general.jsalisbury.us.vpn [10.172.66.188]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id B6A7741538; Wed, 18 Oct 2023 19:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1697658532; bh=d70wFwXulEx1BEkYka3RH1xY2ngWeBIL+MztFYjvhlc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uTajf4Lrk/Y6l0PMtoBHSezRxbtL6I+9Etz56AKlRR7JWdgBtA2AgEQV3/Rupk25Y ymMXoaB4O00xU2p3kpxyx2gU5OaaISsp8UuLCHRKhfRSD1NURNzXc6lXvCvSMrsJmn QAqHgB7jlEbrrtctV3GBhbpeyca3C/g7+TjFn/HbzMP5OcomVDbqC0OrNWOKLinqMa j5gX5NDorx+NHXgRr+k0onATTxnDpnpuyJHWX7vAewtsnEUG3UfckFGZ43VEaAwH/D 9z3KGo7fSjqHSw3K7YImQN2LOrPLrcufRaZ9wwG+Li4hqFbonl0VojHt4v5oB84EHT WTftckTLnLf5g== From: Joseph Salisbury To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Daniel Wagner , Tom Zanussi , Clark Williams , Pavel Machek , Joseph Salisbury Cc: Tetsuo Handa Subject: [PATCH RT 07/12] locking/seqlock: Do the lockdep annotation before locking in do_write_seqcount_begin_nested() Date: Wed, 18 Oct 2023 15:48:28 -0400 Message-Id: <20231018194833.651674-8-joseph.salisbury@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018194833.651674-1-joseph.salisbury@canonical.com> References: <20231018194833.651674-1-joseph.salisbury@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 18 Oct 2023 12:50:03 -0700 (PDT) From: Sebastian Andrzej Siewior v5.15.133-rt70-rc1 stable review patch. If anyone has any objections, please let me know. ----------- 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/seqlock 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 (cherry picked from commit 41b43b6c6e30a832c790b010a06772e793bca193) Signed-off-by: Joseph Salisbury --- 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 37ded6b8fee6..2c5d0102315d 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -516,8 +516,8 @@ do { \ static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subclass) { - do_raw_write_seqcount_begin(s); seqcount_acquire(&s->dep_map, subclass, 0, _RET_IP_); + do_raw_write_seqcount_begin(s); } /** -- 2.34.1