From patchwork Thu Sep 21 06:41:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 143190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5336555vqi; Thu, 21 Sep 2023 22:28:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxp3fnjDK5X5akGv8ZYfBg1LzJZfY5RVYCZiNZzeB0vn7nIGVvAMYwLTnpCSv//e9Q0MMX X-Received: by 2002:a17:902:e811:b0:1b5:1467:c4e8 with SMTP id u17-20020a170902e81100b001b51467c4e8mr8829923plg.15.1695360511811; Thu, 21 Sep 2023 22:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695360511; cv=none; d=google.com; s=arc-20160816; b=NVP03rh2uKmctaYC+iYz6AYXQZeGmIlhRvqkspjjYRDpBq+q/N7GptoA3UxzNqXJVo y+U46RwKuMu3L08eRX7BgXeHm5FgLmshS6nftg9SFejKwxwXHSvvNLle6daO9zTBv4yb FF6tgvhHeIw9JvSVHL6xzt9iSAgF3ooiA0lrtezvzW3orXUajaN6O36ehrsay2UWQ75/ B6K8WbdZxfLzsPvnDtCTKq1PA9D0h8tLgZVi3+TeaaiNZuWgqZJJubd7cb8eZPkBsStR F2pC3q22htvDMjLN6WJvzsKs7ctuB/KtXbezIr/biz8OBWyHPkB5TB3hCGidl1j4Q9RH O7+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=g44M9hKvXEDwyXwCGx4cA7u2mkZTmo3YlGxVozqTY0Q=; fh=8d0CgdjnLLdc0nzDjuslE2DV2fp2Mvl2OxqAHCuI/e8=; b=rZCj9Jtj4HHKoEzV1fg4OdTV8rkbrcCi1rXcMFmwl+tLngGt602WLKwpWAxMDCUuyH hZDDqI3JO9vJMAJDgWQyYRwmTs0BoecB64nVoYA1e/h+qM4aMg2eKFx3CEi5pEu+685W 4YC3rejya3wqvTgXQ8Eeytl8w8+Vh1hD7yYaLap5UY0YbQQGK/SVkjMJrmNld1AbLfib OdElRrDat3CV2imXjn29MyomQ1XyHksCnK0rsC57jWl1RFBlenCx9bQtgxoMu4onnNlE 8Ouuqpkjuu/ntfoMDHZW61snLNy64JHEfC4ReGDuvQxz2ebTNJG24ajaHr+TD417Hr/S BSOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sv+cMhSA; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id n9-20020a170902e54900b001c45e1f034esi3264990plf.141.2023.09.21.22.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 22:28:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=sv+cMhSA; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 621CB8392312; Thu, 21 Sep 2023 14:13:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229708AbjIUVNK (ORCPT + 29 others); Thu, 21 Sep 2023 17:13:10 -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 X-Spam-Status: No, score=0.3 required=5.0 tests=DATE_IN_PAST_06_12,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:13:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777714343862299778 X-GMAIL-MSGID: 1777714343862299778 The following commit has been merged into the locking/urgent branch of tip: Commit-ID: 41b43b6c6e30a832c790b010a06772e793bca193 Gitweb: https://git.kernel.org/tip/41b43b6c6e30a832c790b010a06772e793bca193 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_seqcount_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 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 --- 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 { \ 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); } /**