mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Liu <liubaolin12138@163.com>
To: linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
	Baolin Liu <liubaolin@kylinos.cn>
Subject: [PATCH v1 03/13] ntfs: snapshot resident data for direct reads
Date: Thu,  3 Dec 2026 12:03:42 +0800	[thread overview]
Message-ID: <20261203040352.1161120-4-liubaolin12138@163.com> (raw)
In-Reply-To: <20261203040352.1161120-1-liubaolin12138@163.com>

From: Baolin Liu <liubaolin@kylinos.cn>

Resident direct reads copy data to userspace while holding mrec_lock.
A user fault can acquire mmap_lock, reversing the mmap_lock ->
invalidate_lock -> mrec_lock order used by mmap and attribute operations.
Running generic/075 followed by generic/210 or generic/418 exposes this
lockdep cycle.

Copy the resident data into a temporary buffer under mrec_lock, then
release the lock before returning the direct-read mapping to iomap.
Free the snapshot in the end callback, including after failed or partial
user copies. Buffered reads retain their existing locking.

Fixes: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock")
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
 fs/ntfs/iomap.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index 8970cadcd31e..8d4dc339b436 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -280,8 +280,22 @@ static int __ntfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t le
 static int ntfs_read_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 		unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
 {
-	return __ntfs_read_iomap_begin(inode, offset, length, flags, iomap,
-			srcmap, true, true);
+	struct ntfs_inode *base_ni;
+	void *data;
+	int err;
+
+	err = __ntfs_read_iomap_begin(inode, offset, length, flags, iomap,
+				      srcmap, true, true);
+	if (err || !(flags & IOMAP_DIRECT) || iomap->type != IOMAP_INLINE)
+		return err;
+
+	/* Direct reads may fault on user memory; do not hold mrec_lock. */
+	base_ni = iomap->private;
+	data = kmemdup(iomap->inline_data, iomap->length, GFP_NOFS);
+	mutex_unlock(&base_ni->mrec_lock);
+	iomap->private = NULL;
+	iomap->inline_data = data;
+	return data ? 0 : -ENOMEM;
 }
 
 static int ntfs_read_iomap_end(struct inode *inode, loff_t pos, loff_t length,
@@ -291,6 +305,8 @@ static int ntfs_read_iomap_end(struct inode *inode, loff_t pos, loff_t length,
 
 	if (base_ni)
 		mutex_unlock(&base_ni->mrec_lock);
+	else if ((flags & IOMAP_DIRECT) && iomap->type == IOMAP_INLINE)
+		kfree(iomap->inline_data);
 	return written;
 }
 


  parent reply	other threads:[~2026-12-03  4:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  4:03 [PATCH v1 00/13] ntfs: add large folio support for ordinary files Baolin Liu
2026-12-03  4:03 ` [PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range Baolin Liu
2026-12-03  4:03 ` [PATCH v1 02/13] ntfs: read compression units without the block device page cache Baolin Liu
2026-12-03  4:03 ` Baolin Liu [this message]
2026-12-03  4:03 ` [PATCH v1 04/13] ntfs: allow vmalloc for large runlist backups Baolin Liu
2026-12-03  4:03 ` [PATCH v1 05/13] ntfs: preserve delalloc reservations when allocating holes Baolin Liu
2026-12-03  4:03 ` [PATCH v1 06/13] ntfs: serialize delalloc reservations with cluster allocation Baolin Liu
2026-12-03  4:03 ` [PATCH v1 07/13] ntfs: respect space reservations when writing compressed data Baolin Liu
2026-12-03  4:03 ` [PATCH v1 08/13] ntfs: keep space for MFT growth during delayed allocation Baolin Liu
2026-12-03  4:03 ` [PATCH v1 09/13] ntfs: serialize compression changes with file access Baolin Liu
2026-12-03  4:03 ` [PATCH v1 10/13] ntfs: complete compressed reads at folio granularity Baolin Liu
2026-12-03  4:03 ` [PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page Baolin Liu
2026-12-03  4:03 ` [PATCH v1 12/13] ntfs: preserve large folios during compressed writes Baolin Liu
2026-12-03  4:03 ` [PATCH v1 13/13] ntfs: enable large folios for ordinary files Baolin Liu
2026-12-03  4:23 ` [PATCH v1 00/13] ntfs: add large folio support " liubaolin
2026-12-03  5:30   ` Namjae Jeon
2026-12-03 10:10     ` liubaolin

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=20261203040352.1161120-4-liubaolin12138@163.com \
    --to=liubaolin12138@163.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin@kylinos.cn \
    --cc=ntfs@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®