From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Jinjiang Tu <tujinjiang@huawei.com>, <miklos@szeredi.hu>,
<akpm@linux-foundation.org>, <vbabka@suse.cz>, <jannh@google.com>,
<linux-mm@kvack.org>, <linux-unionfs@vger.kernel.org>,
<sunnanyong@huawei.com>, <yi.zhang@huawei.com>,
Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH -next] ovl: respect underlying filesystem's get_unmapped_area()
Date: Wed, 11 Dec 2024 23:01:49 +0800 [thread overview]
Message-ID: <88a1f4e4-8c3a-447c-a207-df754f1ab67d@huawei.com> (raw)
In-Reply-To: <CAOQ4uxjBB7EUOnHB2n9BUGJ_TrHqvqJLksVyxcnpOUCR+7Tfyg@mail.gmail.com>
On 2024/12/11 17:43, Amir Goldstein wrote:
> On Tue, Dec 10, 2024 at 8:19 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>>
>>
>>
>> On 2024/12/6 20:58, Amir Goldstein wrote:
>>> On Fri, Dec 6, 2024 at 11:45 AM Kefeng Wang <wangkefeng.wang@huawei.com> wrote:
>>>>
>> ...
>>>>
>>>> So maybe use mm_get_unmapped_area() instead of __get_unmapped_area(),
>>>> something like below,
>>>>
>>>> +static unsigned long ovl_get_unmapped_area(struct file *file,
>>>> + unsigned long addr, unsigned long len, unsigned long pgoff,
>>>> + unsigned long flags)
>>>> +{
>>>> + struct file *realfile;
>>>> + const struct cred *old_cred;
>>>> +
>>>> + realfile = ovl_real_file(file);
>>>> + if (IS_ERR(realfile))
>>>> + return PTR_ERR(realfile);
>>>> +
>>>> + if (realfile->f_op->get_unmapped_area) {
>>>> + unsigned long ret;
>>>> +
>>>> + old_cred = ovl_override_creds(file_inode(file)->i_sb);
>>>> + ret = realfile->f_op->get_unmapped_area(realfile, addr, len,
>>>> + pgoff, flags);
>>>> + ovl_revert_creds(old_cred);
>>>> +
>>>> + if (ret)
>>>> + return ret;
>>>> + }
>>>> +
>>>> + return mm_get_unmapped_area(current->mm, file, addr, len, pgoff,
>>>> flags);
>>>> +}
>>>>
>>>> Correct me If I'm wrong.
>>>>
>>>
>>> You just need to be aware of the fact that between ovl_get_unmapped_area()
>>> and ovl_mmap(), ovl_real_file(file) could change from the lower file, to the
>>> upper file due to another operation that initiated copy-up.
>>
>> Not sure about this part(I have very little knowledge of ovl), do you
>> mean that we could not use ovl_real_file()? The ovl_mmap() using
>> realfile = file->private_data, we may use similar way in
>> ovl_get_unmapped_area(). but I may have misunderstood.
>>
>
> First of all, you may add to your patch:
> Acked-by: Amir Goldstein <amir73il@gmail.com>
Thanks,
>
> I think this patch is fine as is.
> w.r.t. question about ovl_override_creds(), I think it is good practice to
> user mounter credentials when calling into real fs methods, regardless
> of the fact that in most cases known today the ->get_unmapped_area()
> methods do not check credentials.
>
> My comment was referring to the fact that ovl_real_file(file), when called
> two subsequent times in a row (once from ovl_get_unmapped_area() and
> then again from ovl_mmap()) may not return the same realfile.
>
> This is because during the lifetime of an overlayfs file/inode, its realinode/
> realfile can change once, in the event known as "copy-up", so you may
> start by calling ovl_get_unmapped_area() on a lower ext4 realfile and then end
> up actually mapping an upper tmpfs realfile, because someone has opened
> the overlayfs file for write in the meanwhile.
Got it, thanks for your detail explanation.
>
> I guess in this corner case, the alignment may be wrong, or just too strict for
> the actual mapping, but it is not critical, so just FYI.
Yes, not critical, at least not too much worse.
Ovl is always lack of vma THP alignment or some other VMA allocation
requirements.
> There are worse issues with mmap of overlayfs file documented in:
> https://docs.kernel.org/filesystems/overlayfs.html#non-standard-behavior
> "If a file residing on a lower layer is opened for read-only and then
> memory mapped
> with MAP_SHARED, then subsequent changes to the file are not reflected in the
> memory mapping."
I think we could ignore above issue in this fixup and if there is a need
to check vm_flags in ->get_unmapped_area(), we could deal with it later.
And Jinjiang, please send a v2 according to all the discussion.
Thanks.
>
> Thanks,
> Amir.
next prev parent reply other threads:[~2024-12-11 15:02 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 14:30 Jinjiang Tu
2024-12-05 15:04 ` Lorenzo Stoakes
2024-12-05 15:12 ` Amir Goldstein
2024-12-05 15:24 ` Lorenzo Stoakes
2024-12-06 3:35 ` Jinjiang Tu
2024-12-06 13:52 ` Matthew Wilcox
2024-12-10 17:36 ` Jann Horn
2024-12-06 3:35 ` Jinjiang Tu
2024-12-06 9:25 ` Lorenzo Stoakes
2024-12-06 10:45 ` Kefeng Wang
2024-12-06 11:53 ` Lorenzo Stoakes
2024-12-10 7:09 ` Kefeng Wang
2024-12-06 12:58 ` Amir Goldstein
2024-12-10 7:19 ` Kefeng Wang
2024-12-11 9:43 ` Amir Goldstein
2024-12-11 15:01 ` Kefeng Wang [this message]
2024-12-13 1:51 ` Jinjiang Tu
2024-12-13 4:25 ` Matthew Wilcox
2024-12-13 7:49 ` Kefeng Wang
2024-12-13 14:00 ` Matthew Wilcox
2024-12-14 7:58 ` Kefeng Wang
2024-12-05 21:21 ` kernel test robot
2024-12-06 13:58 ` Matthew Wilcox
2024-12-09 6:43 ` Jinjiang Tu
2024-12-09 13:33 ` Matthew Wilcox
2024-12-10 7:13 ` Jinjiang Tu
2024-12-10 17:58 ` Matthew Wilcox
2024-12-11 2:21 ` Zhang Yi
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=88a1f4e4-8c3a-447c-a207-df754f1ab67d@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=jannh@google.com \
--cc=linux-mm@kvack.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=miklos@szeredi.hu \
--cc=sunnanyong@huawei.com \
--cc=tujinjiang@huawei.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=yi.zhang@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