linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Jinjiang Tu <tujinjiang@huawei.com>,
	miklos@szeredi.hu, amir73il@gmail.com, 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: Fri, 6 Dec 2024 11:53:47 +0000	[thread overview]
Message-ID: <a101ce9b-9789-4883-a232-056330642fd8@lucifer.local> (raw)
In-Reply-To: <f2668332-78ac-4dc1-abcc-440e38964ccc@huawei.com>

On Fri, Dec 06, 2024 at 06:45:11PM +0800, Kefeng Wang 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);

Credentials stuff necessary now you're not having security_mmap_addr()
called etc.?

> +
> +               if (ret)
> +                       return ret;

Surely you'd unconditionally return in this case? I don't think there's any case
where you'd want to fall through.

> +       }
> +
> +       return mm_get_unmapped_area(current->mm, file, addr, len, pgoff,
> flags);
> +}
>
> Correct me If I'm wrong.
>
> Thanks.
>

I mean this doesn't export anything we don't want exported so this is fine
from that perspective :)

And I guess in principle this is OK in that __get_unmapped_area() would be
invoked on the overlay file, will do the required arch_mmap_check(), then
will invoke your overlay handler.

I did think of suggesting invoking the f_op directly, but it feels icky
vs. just supporting large folios.

But actually... hm I realise I overlooked the fact that underlying _files_
will always provide a large folio-aware handler.

I'm guessing you can't use overlayfs somehow with a MAP_ANON | MAP_SHARED
mapping or similar, thinking of:

	if (file) {
		...
	} else if (flags & MAP_SHARED) {
		/*
		 * mmap_region() will call shmem_zero_setup() to create a file,
		 * so use shmem's get_unmapped_area in case it can be huge.
		 */
		get_area = shmem_get_unmapped_area;
	}

But surely actually any case that works with overlayfs will have a file and
so... yeah.

Hm, I actually think this should work.

Can you make sure to do some pretty thorough testing on this just to make
sure you're not hitting on any weirdness?


  reply	other threads:[~2024-12-06 11:54 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 [this message]
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
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=a101ce9b-9789-4883-a232-056330642fd8@lucifer.local \
    --to=lorenzo.stoakes@oracle.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=miklos@szeredi.hu \
    --cc=sunnanyong@huawei.com \
    --cc=tujinjiang@huawei.com \
    --cc=vbabka@suse.cz \
    --cc=wangkefeng.wang@huawei.com \
    --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