From: Baokun Li <libaokun1@huawei.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: <linux-ext4@vger.kernel.org>, <adilger.kernel@dilger.ca>,
<jack@suse.cz>, <ritesh.list@gmail.com>,
<linux-kernel@vger.kernel.org>, <jun.nie@linaro.org>,
<ebiggers@kernel.org>, <yi.zhang@huawei.com>,
<yangerkun@huawei.com>, <yukuai3@huawei.com>,
<syzbot+a158d886ca08a3fecca4@syzkaller.appspotmail.com>,
<stable@vger.kernel.org>, Baokun Li <libaokun1@huawei.com>
Subject: Re: [PATCH v2] ext4: fix race condition between buffer write and page_mkwrite
Date: Mon, 5 Jun 2023 10:17:29 +0800 [thread overview]
Message-ID: <c20befb7-cd2e-019a-57d4-35da70e0f534@huawei.com> (raw)
In-Reply-To: <20230604030445.GF1128744@mit.edu>
On 2023/6/4 11:04, Theodore Ts'o wrote:
> I tried testing to see if this fixed [1], and it appears to be
> triggering a lockdep warning[2] at this line in the patch:
>
> [1] https://syzkaller.appspot.com/bug?extid=f4582777a19ec422b517
> [2] https://syzkaller.appspot.com/x/report.txt?x=17260843280000
>
>> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
>> index d101b3b0c7da..9df82d72eb90 100644
>> --- a/fs/ext4/file.c
>> +++ b/fs/ext4/file.c
>> @@ -808,6 +809,27 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
>> if (!daxdev_mapping_supported(vma, dax_dev))
>> return -EOPNOTSUPP;
>>
>> + /*
>> + * Writing via mmap has no logic to handle inline data, so we
>> + * need to call ext4_convert_inline_data() to convert the inode
>> + * to normal format before doing so, otherwise a BUG_ON will be
>> + * triggered in ext4_writepages() due to the
>> + * EXT4_STATE_MAY_INLINE_DATA flag. Moreover, we need to grab
>> + * i_rwsem during conversion, since clearing and setting the
>> + * inline data flag may race with ext4_buffered_write_iter()
>> + * to trigger a BUG_ON.
>> + */
>> + if (ext4_has_feature_inline_data(sb) &&
>> + vma->vm_flags & VM_SHARED && vma->vm_flags & VM_MAYWRITE) {
>> + int err;
>> +
>> + inode_lock(inode); <=================== LOCKDEP warning
>> + err = ext4_convert_inline_data(inode);
>> + inode_unlock(inode);
>> + if (err)
>> + return err;
>> + }
>
> The details of the lockdep warning from [2], which appears to be a
> mmap(2) racing with a buffered write(2) are below. Could you take a
> look?
>
> Thanks!
>
> - Ted
Sorry for the late reply!
Had a look at this question which is similar to the one Honza mentioned
earlier.
Concurrency between write and mmap as follows can lead to ABBA deadlocks:
CPU0 CPU1
write(2) mmap(2)
ext4_file_write_iter
ext4_buffered_write_iter
inode_lock(inode) ---> LOCK A
generic_perform_write
ksys_mmap_pgoff
vm_mmap_pgoff
mmap_write_lock_killable(mm) ---> LOCK B
do_mmap
mmap_region
call_mmap
ext4_file_mmap
inode_lock(inode) ---> try LOCK A again
fault_in_iov_iter_readable |
fault_in_readable |
asm_exc_page_fault ABBA deadlock
handle_page_fault |
do_user_addr_fault |
mmap_read_lock(mm) ---> try LOCK B again
Thanks!
--
With Best Regards,
Baokun Li
.
prev parent reply other threads:[~2023-06-05 2:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 13:44 [PATCH v2] ext4: fix race condition between buffer write and page_mkwrite Baokun Li
2023-05-31 13:15 ` Jan Kara
2023-06-04 3:04 ` Theodore Ts'o
2023-06-04 21:08 ` Theodore Ts'o
2023-06-05 1:58 ` Matthew Wilcox
2023-06-05 9:16 ` Jan Kara
2023-06-05 12:21 ` Jan Kara
2023-06-05 14:55 ` Matthew Wilcox
2023-06-05 15:08 ` Jan Kara
2023-06-06 12:19 ` Baokun Li
2024-04-15 4:28 ` Baokun Li
2024-04-15 12:34 ` Jan Kara
2024-04-15 14:07 ` Baokun Li
2023-06-05 2:17 ` Baokun Li [this message]
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=c20befb7-cd2e-019a-57d4-35da70e0f534@huawei.com \
--to=libaokun1@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=ebiggers@kernel.org \
--cc=jack@suse.cz \
--cc=jun.nie@linaro.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ritesh.list@gmail.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+a158d886ca08a3fecca4@syzkaller.appspotmail.com \
--cc=tytso@mit.edu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.com \
/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