From: <wang.yaxin@zte.com.cn>
To: <willy@infradead.org>
Cc: <akpm@linux-foundation.org>, <liam.howlett@oracle.com>,
<lorenzo.stoakes@oracle.com>, <david@kernel.org>,
<vbabka@suse.cz>, <jannh@google.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <xu.xin16@zte.com.cn>,
<yang.yang29@zte.com.cn>, <fan.yu9@zte.com.cn>,
<he.peilin@zte.com.cn>, <tu.qiang35@zte.com.cn>,
<qiu.yutan@zte.com.cn>, <jiang.kun2@zte.com.cn>,
<lu.zhongjun@zte.com.cn>
Subject: Re: [PATCH linux-next] mm/madvise: prefer VMA lock for MADV_REMOVE
Date: Wed, 14 Jan 2026 15:00:29 +0800 (CST) [thread overview]
Message-ID: <202601141500292511NYBdWwzTilw10jiTcGlN@zte.com.cn> (raw)
In-Reply-To: <aWcZCwz__qwwKbxw@casper.infradead.org>
>> - mark_mmap_lock_dropped(madv_behavior);
>> + /*
>> + * Prefer VMA read lock path: when operating under VMA lock, we avoid
>> + * dropping/reacquiring the mmap lock and directly perform the filesystem
>> + * operation while the VMA is read-locked. We still take and drop a file
>> + * reference to protect against concurrent file changes.
>
>How does taking a reference prevent file changes? What do you mean by
"file changes" anyway?
Thanks for the review.
Taking a reference with get_file(f) does not prevent file content or
metadata changes; it pins the struct file so the pointer remains valid
while we temporarily drop mmap_lock. The VMA can be split, unmapped, or
otherwise changed during that window, and without a ref the vma->vm_file
could be freed.
By “file changes” I meant lifetime changes to the VMA → file association
(e.g. concurrent munmap/mremap or VMA splits) while mmap_lock is dropped,
not changes to the file’s data or inode state. Those are serialized by
the filesystem (e.g. inode locks) and are unrelated to the refcount.
>> + * When operating under mmap read lock (fallback), preserve existing
>> + * behaviour: mark lock dropped, coordinate with userfaultfd_remove(),
>> + * temporarily drop mmap_read_lock around vfs_fallocate(), and then
>> + * reacquire it.
>
>This is not the way to write an inline comment; that's how you describe
>what you've done in the changelog.
>
>> @@ -1033,12 +1045,19 @@ static long madvise_remove(struct madvise_behavior *madv_behavior)
>> + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
>>
>> /*
>> - * Filesystem's fallocate may need to take i_rwsem. We need to
>> - * explicitly grab a reference because the vma (and hence the
>> - * vma's reference to the file) can go away as soon as we drop
>> - * mmap_lock.
>> + * Execute filesystem punch-hole under appropriate locking.
>> + * - VMA lock path: no mmap lock held; call vfs_fallocate() directly.
>> + * - mmap lock path: follow existing protocol including UFFD coordination
>> + * and temporary mmap_read_unlock/lock around the filesystem call.
>
>Again, I don't like what you've done here with the comments.
I’ll fix the inline comment to say: “Pin struct file across potential
mmap_lock drop so the file pointer remains valid even if the VMA is
modified or freed,” and remove the changelog-style prose.
Thanks,
Jiang Kun
next prev parent reply other threads:[~2026-01-14 7:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 3:24 wang.yaxin
2026-01-14 4:18 ` Matthew Wilcox
2026-01-14 7:00 ` wang.yaxin [this message]
2026-01-14 4:19 ` Matthew Wilcox
2026-01-14 8:03 ` [syzbot ci] " syzbot ci
2026-01-14 9:04 ` [PATCH linux-next] " Lorenzo Stoakes
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=202601141500292511NYBdWwzTilw10jiTcGlN@zte.com.cn \
--to=wang.yaxin@zte.com.cn \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=fan.yu9@zte.com.cn \
--cc=he.peilin@zte.com.cn \
--cc=jannh@google.com \
--cc=jiang.kun2@zte.com.cn \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lu.zhongjun@zte.com.cn \
--cc=qiu.yutan@zte.com.cn \
--cc=tu.qiang35@zte.com.cn \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
/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