Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2136397iof; Tue, 7 Jun 2022 20:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYZzJ9BxmLNzih3Y/YyaoiY56WvXnzdNX5k3FR9jf2zhxxJvbbiI7FuD97bps5OlfTFFl/ X-Received: by 2002:a63:ea09:0:b0:3fd:3c6a:47c2 with SMTP id c9-20020a63ea09000000b003fd3c6a47c2mr20275104pgi.242.1654660715085; Tue, 07 Jun 2022 20:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654660715; cv=none; d=google.com; s=arc-20160816; b=rxH/j9ETXNtNmMJbGxNCK7ii4VjVYgyUz7ozgyqYsCHwdlfn/szQukbjCtpvpgB+fh fx/j/b9nKLds5FM6fFtfQF/gREsE9e+CYxGAD92EE8+VCI3kuliZZI0YzciwAbRZ+BZR MyE9NOwzEZ3lAi4Vrr+2Spu02JNJiIr98b4gdB9pinUqfaQYMutf2riO0TKAOqIWz4tT xjibGmtxrL3bEO+GeLYiuHNdSbLb1aDbQvzIsL1tzeq4QHKmYAwaOto6NcsQE/3QgrxG l5dIeSjQeeHWSc1f7T5+wXHe9KoY2xx0QsGSZJuBOESFv4dKBnAaCfIYuhnZRSIHwxQo as8w== 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=8dc/LmMthKH8XrB8avjzfzua23tEN1KYCF/ormtVGA0=; b=LkSrO7xIjRwib6PmgKzoj7Ss/FFu9Eh1iprNSyE1U/mxjCHIbPhPEnd/4Mn+DppwSO RM9BNMebU2NHrT15OUAz4pvtc/qWqj2LvxL3X7Ab7XHFNTI6dEM0sGatd7cgfsPZB+5Z hmQfoJ2WQfm993PLhVJ5DQVnDgVNCKjnFXz3eFk3lbNs8v+OpUvIxS+wdqbfoAv+kYW3 VRhhZYcvUtm3gvI6dqOhEoNv+2HJThNA+OuGn4s5iKy6+lQz0MH0KvjamTlAHcFUzOyK QxkM+R/5bJFIPKA47vjwCa+JwLQontp4UwSfvz3rYwvQJexqNe9bA+UbObIcjjKkukhU A8Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rc7bfRNt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b3-20020a63cf43000000b003fc9d2da651si28469642pgj.366.2022.06.07.20.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:58:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rc7bfRNt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 B00683E7DE1; Tue, 7 Jun 2022 20:21:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381517AbiFGWjA (ORCPT + 99 others); Tue, 7 Jun 2022 18:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379109AbiFGVZM (ORCPT ); Tue, 7 Jun 2022 17:25:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01942150B56; Tue, 7 Jun 2022 12:01:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8B4AC61768; Tue, 7 Jun 2022 19:01:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A7CC385A2; Tue, 7 Jun 2022 19:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628493; bh=ymx9QHg7+ScfhvFTXBKQpujaG21Mb1j9yGQhQARduI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rc7bfRNtiRXT5Sv53NOW/goPaMmEHrDcdZ1q4aEEsc0i8l1X8bOpcwMnUSDuSgMZz Uvm9c0TpfS2o44PXiHgv5XEMvnOXbJlrZnG1xQXWBbMA4GKe7sT0oZLJ4sLP+BiAbX SomHdith6wRG8bNkkG0TGmeMICoOjsyZ7hz11cS8= 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.18 349/879] fsnotify: fix wrong lockdep annotations Date: Tue, 7 Jun 2022 18:57:47 +0200 Message-Id: <20220607165012.991241561@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 4853184f7dde..c86982be2d50 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