Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2165930iof; Tue, 7 Jun 2022 21:56:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7/h2Uw2luchplrc3nCV7H8m50lupt2PSeWNESsGjhR4LT/d2c+Yy2ZVodDNQ5WCwgS/lo X-Received: by 2002:a17:90b:3b4b:b0:1e8:434c:5ab1 with SMTP id ot11-20020a17090b3b4b00b001e8434c5ab1mr25993613pjb.129.1654664203710; Tue, 07 Jun 2022 21:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654664203; cv=none; d=google.com; s=arc-20160816; b=0GidhKjAie1sPF+RbA+/2BxA2H2BzWivJauijpuX3vQKbqkWsd++AqX0C2Xc3Xj/Bt cQJF+CjtXxGA97hpLAXb6GIlAD9fs5A81kwp1JDG5w1WLrn3kFGwV5ROSss6IaijHq9i XE6djzLEq43Z8phl3S+j3ZPINziFMb6DKIOKatNxYf+bNM3OqViYEfVGaW9qy4qTC/rR sQwg4TFh+DtRRMx5vK6LkEUqnJ89tVOte+45vetFbB/R2uxbd2yaXH+oZ3lrQGjq8Qs4 U2/fHJ0FrFYliADUMlmdZ1RmlfyTkTciVp9B3vvOxP03nq70PwIewRCG+qKZSmNHyRxV rWgA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6Fmvzjk1PUBdfsTpvE+xD+rQcNOIfnC43mELWAfmJHE=; b=Qo4I6BNyiZhnpy4FCpwD3mqJsJmdebeT20eK1Bv1EKpEQxK93F2catZqUbL/93rPGd OkobC6O/0NmPl/87R8fkrCNiwk20t/scoxQhq331x+ILh79f2X+63Kbin7LnuGmkZJbj qXqIjYLfoF3tGmclt2xcN+rXpY5Ie26dD7Xhg7G6xtUrPNwGE2rHYs+DR9zZwwyaGmvA jsCCYtUg7VSsCS/WPZlLpml6pgBVZ1V5Rb2/yLwmWQBWyHM916XHQpJNtuTGHJ9V2bSV +j79PjlRMDu0L70zuCpadOdH3x7Lr4l5bTHREXyw5jSQp5atkiQ1QtOjr0N2F5cri01b YMdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rrm5v4ue; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a7-20020a63e847000000b003fa34f038afsi27271585pgk.159.2022.06.07.21.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:56:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rrm5v4ue; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6290462250; Tue, 7 Jun 2022 21:32:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377628AbiFGU74 (ORCPT + 99 others); Tue, 7 Jun 2022 16:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357022AbiFGTyh (ORCPT ); Tue, 7 Jun 2022 15:54:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC95814BE; Tue, 7 Jun 2022 11:23:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DDB18B8237C; Tue, 7 Jun 2022 18:23:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4370CC36B00; Tue, 7 Jun 2022 18:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654626207; bh=bf3A8Tav4GLThsLGs2hokuDRjuGzvnUBNsYxG+5a7Bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rrm5v4uekxasBgxEA//cehPKcI9fYVNp0334doGa02pTEWRcc7kGrJY+l90PRfa6I mCFD+/HUCfe2KfecsPMUKDcIS8Qi8sstRcaA8TMizCmEEsX8Rwn2YVuo9XYq4EDbRQ vBchGOBSBcK4W9txXrNbXUoMqLKssVeF0X6W3IUI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Khazhismel Kumykov , Amir Goldstein , Jan Kara , Sasha Levin Subject: [PATCH 5.17 293/772] fsnotify: fix wrong lockdep annotations Date: Tue, 7 Jun 2022 18:58:05 +0200 Message-Id: <20220607164957.657625529@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Amir Goldstein [ Upstream commit 623af4f538b5df9b416e1b82f720af7371b4c771 ] Commit 6960b0d909cd ("fsnotify: change locking order") changed some of the mark_mutex locks in direct reclaim path to use: mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); This change is explained: "...It uses nested locking to avoid deadlock in case we do the final iput() on an inode which still holds marks and thus would take the mutex again when calling fsnotify_inode_delete() in destroy_inode()." The problem is that the mutex_lock_nested() is not a nested lock at all. In fact, it has the opposite effect of preventing lockdep from warning about a very possible deadlock. Due to these wrong annotations, a deadlock that was introduced with nfsd filecache in kernel v5.4 went unnoticed in v5.4.y for over two years until it was reported recently by Khazhismel Kumykov, only to find out that the deadlock was already fixed in kernel v5.5. Fix the wrong lockdep annotations. Cc: Khazhismel Kumykov Fixes: 6960b0d909cd ("fsnotify: change locking order") Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Link: https://lore.kernel.org/r/20220422120327.3459282-4-amir73il@gmail.com Signed-off-by: Amir Goldstein Signed-off-by: Jan Kara Signed-off-by: Sasha Levin --- fs/notify/mark.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 9007d6affff3..b42629d2fc1c 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -452,7 +452,7 @@ void fsnotify_free_mark(struct fsnotify_mark *mark) void fsnotify_destroy_mark(struct fsnotify_mark *mark, struct fsnotify_group *group) { - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); fsnotify_detach_mark(mark); mutex_unlock(&group->mark_mutex); fsnotify_free_mark(mark); @@ -770,7 +770,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, * move marks to free to to_free list in one go and then free marks in * to_free list one by one. */ - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { if (mark->connector->type == obj_type) list_move(&mark->g_list, &to_free); @@ -779,7 +779,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, clear: while (1) { - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); if (list_empty(head)) { mutex_unlock(&group->mark_mutex); break; -- 2.35.1