From: Jan Kara <jack@suse.cz>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Jan Kara <jack@suse.com>,
tytso@mit.edu, Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/3] quota: Prevent memory allocation recursion while holding dq_lock
Date: Mon, 6 Jun 2022 10:03:34 +0200 [thread overview]
Message-ID: <20220606080334.tv5r7kljang55fat@quack3.lan> (raw)
In-Reply-To: <20220605143815.2330891-2-willy@infradead.org>
On Sun 05-06-22 15:38:13, Matthew Wilcox (Oracle) wrote:
> As described in commit 02117b8ae9c0 ("f2fs: Set GF_NOFS in
> read_cache_page_gfp while doing f2fs_quota_read"), we must not enter
> filesystem reclaim while holding the dq_lock. Prevent this more generally
> by using memalloc_nofs_save() while holding the lock.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
This is definitely a good cleanup to have and seems mostly unrelated to the
rest. I'll take it rightaway into my tree. Thanks for the patch!
Honza
> ---
> fs/quota/dquot.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
> index a74aef99bd3d..cdb22d6d7488 100644
> --- a/fs/quota/dquot.c
> +++ b/fs/quota/dquot.c
> @@ -425,9 +425,11 @@ EXPORT_SYMBOL(mark_info_dirty);
> int dquot_acquire(struct dquot *dquot)
> {
> int ret = 0, ret2 = 0;
> + unsigned int memalloc;
> struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
>
> mutex_lock(&dquot->dq_lock);
> + memalloc = memalloc_nofs_save();
> if (!test_bit(DQ_READ_B, &dquot->dq_flags)) {
> ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot);
> if (ret < 0)
> @@ -458,6 +460,7 @@ int dquot_acquire(struct dquot *dquot)
> smp_mb__before_atomic();
> set_bit(DQ_ACTIVE_B, &dquot->dq_flags);
> out_iolock:
> + memalloc_nofs_restore(memalloc);
> mutex_unlock(&dquot->dq_lock);
> return ret;
> }
> @@ -469,9 +472,11 @@ EXPORT_SYMBOL(dquot_acquire);
> int dquot_commit(struct dquot *dquot)
> {
> int ret = 0;
> + unsigned int memalloc;
> struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
>
> mutex_lock(&dquot->dq_lock);
> + memalloc = memalloc_nofs_save();
> if (!clear_dquot_dirty(dquot))
> goto out_lock;
> /* Inactive dquot can be only if there was error during read/init
> @@ -481,6 +486,7 @@ int dquot_commit(struct dquot *dquot)
> else
> ret = -EIO;
> out_lock:
> + memalloc_nofs_restore(memalloc);
> mutex_unlock(&dquot->dq_lock);
> return ret;
> }
> @@ -492,9 +498,11 @@ EXPORT_SYMBOL(dquot_commit);
> int dquot_release(struct dquot *dquot)
> {
> int ret = 0, ret2 = 0;
> + unsigned int memalloc;
> struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
>
> mutex_lock(&dquot->dq_lock);
> + memalloc = memalloc_nofs_save();
> /* Check whether we are not racing with some other dqget() */
> if (dquot_is_busy(dquot))
> goto out_dqlock;
> @@ -510,6 +518,7 @@ int dquot_release(struct dquot *dquot)
> }
> clear_bit(DQ_ACTIVE_B, &dquot->dq_flags);
> out_dqlock:
> + memalloc_nofs_restore(memalloc);
> mutex_unlock(&dquot->dq_lock);
> return ret;
> }
> --
> 2.35.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2022-06-06 8:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-05 14:38 [PATCH 0/3] Cache quota files in the page cache Matthew Wilcox (Oracle)
2022-06-05 14:38 ` [PATCH 1/3] quota: Prevent memory allocation recursion while holding dq_lock Matthew Wilcox (Oracle)
2022-06-06 8:03 ` Jan Kara [this message]
2022-06-06 12:42 ` Matthew Wilcox
2022-06-06 13:08 ` Jan Kara
2022-06-05 14:38 ` [PATCH 2/3] quota: Support using the page cache for quota files Matthew Wilcox (Oracle)
2022-06-06 2:53 ` kernel test robot
2022-06-06 4:05 ` kernel test robot
2022-06-06 4:36 ` kernel test robot
2022-06-05 14:38 ` [PATCH 3/3] ext4: Use generic_quota_read() Matthew Wilcox (Oracle)
2022-06-06 8:38 ` Jan Kara
2022-06-08 1:42 ` Matthew Wilcox
2022-06-08 14:21 ` Jan Kara
2022-06-13 7:59 ` [ext4] fa96490369: WARNING:at_fs/ext4/inode.c:#ext4_invalidate_folio kernel test robot
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=20220606080334.tv5r7kljang55fat@quack3.lan \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=willy@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).