From: Yu Zhao <yuzhao@google.com>
To: "Theodore Y . Ts'o" <tytso@mit.edu>,
Jaegeuk Kim <jaegeuk@kernel.org>,
Eric Biggers <ebiggers@kernel.org>
Cc: linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org,
Yu Zhao <yuzhao@google.com>
Subject: [PATCH] fscrypt: fix lockdep warning
Date: Tue, 4 Oct 2022 18:13:26 -0600 [thread overview]
Message-ID: <20221005001326.157644-1-yuzhao@google.com> (raw)
fscrypt_initialize() shouldn't allocate memory without GFP_NOFS.
The problem seems to go back to 2015
commit 57e5055b0a5e ("f2fs crypto: add f2fs encryption facilities")
but I have never heard of any complaints, hence not CC'ing stable.
======================================================
WARNING: possible circular locking dependency detected
6.0.0-lockdep #1 Not tainted
------------------------------------------------------
kswapd0/77 is trying to acquire lock:
71ffff808b254a18 (jbd2_handle){++++}-{0:0}, at: start_this_handle+0x76c/0x8dc
but task is already holding lock:
ffffffea26533310 (fs_reclaim){+.+.}-{0:0}, at: 0x1
which lock already depends on the new lock.
<snipped>
other info that might help us debug this:
Chain exists of:
jbd2_handle --> fscrypt_init_mutex --> fs_reclaim
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(fs_reclaim);
lock(fscrypt_init_mutex);
lock(fs_reclaim);
lock(jbd2_handle);
*** DEADLOCK ***
3 locks held by kswapd0/77:
#0: ffffffea26533310 (fs_reclaim){+.+.}-{0:0}, at: 0x1
#1: ffffffea26529220 (shrinker_rwsem){++++}-{3:3}, at: shrink_slab+0x54/0x464
#2: 6dffff808abe90e8 (&type->s_umount_key#47){++++}-{3:3}, at: trylock_super+0x2c/0x8c
<snipped>
Signed-off-by: Yu Zhao <yuzhao@google.com>
---
fs/crypto/crypto.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index e78be66bbf01..e10fc30142a6 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -316,6 +316,7 @@ EXPORT_SYMBOL(fscrypt_decrypt_block_inplace);
int fscrypt_initialize(unsigned int cop_flags)
{
int err = 0;
+ unsigned int flags;
/* No need to allocate a bounce page pool if this FS won't use it. */
if (cop_flags & FS_CFLG_OWN_PAGES)
@@ -326,8 +327,10 @@ int fscrypt_initialize(unsigned int cop_flags)
goto out_unlock;
err = -ENOMEM;
+ flags = memalloc_nofs_save();
fscrypt_bounce_page_pool =
mempool_create_page_pool(num_prealloc_crypto_pages, 0);
+ memalloc_nofs_restore(flags);
if (!fscrypt_bounce_page_pool)
goto out_unlock;
--
2.38.0.rc1.362.ged0d419d3c-goog
next reply other threads:[~2022-10-05 0:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 0:13 Yu Zhao [this message]
2022-10-05 1:39 ` [PATCH] fscrypt: fix lockdep warning Eric Biggers
2022-10-05 1:57 ` Yu Zhao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221005001326.157644-1-yuzhao@google.com \
--to=yuzhao@google.com \
--cc=ebiggers@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox