* (RESEND) [PATCH] ovl: stacked file operation for mmap
@ 2020-10-16 15:57 Chengguang Xu
2020-10-18 7:53 ` Amir Goldstein
0 siblings, 1 reply; 3+ messages in thread
From: Chengguang Xu @ 2020-10-16 15:57 UTC (permalink / raw)
To: miklos; +Cc: linux-unionfs, Chengguang Xu
Currently only mmap does not behave as stacked file operation,
although in practice there is less change to open a file in
RDONLY mode and take long time to do mmap but the fix looks
reasonable.
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
Hi Miklos,
I'm sorry that I did a mistake about signed-off-by tag in previous
email, so I resend this patch.
fs/overlayfs/file.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 3582c3ae819c..f98b1c0c975b 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -461,6 +461,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
{
struct file *realfile = file->private_data;
const struct cred *old_cred;
+ struct fd real;
int ret;
if (!realfile->f_op->mmap)
@@ -469,7 +470,11 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
if (WARN_ON(file != vma->vm_file))
return -EIO;
- vma->vm_file = get_file(realfile);
+ ret = ovl_real_fdget(file, &real);
+ if (ret)
+ return ret;
+
+ vma->vm_file = get_file(real.file);
old_cred = ovl_override_creds(file_inode(file)->i_sb);
ret = call_mmap(vma->vm_file, vma);
@@ -477,13 +482,14 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
if (ret) {
/* Drop reference count from new vm_file value */
- fput(realfile);
+ fput(real.file);
} else {
/* Drop reference count from previous vm_file value */
fput(file);
}
ovl_file_accessed(file);
+ fdput(real);
return ret;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: (RESEND) [PATCH] ovl: stacked file operation for mmap
2020-10-16 15:57 (RESEND) [PATCH] ovl: stacked file operation for mmap Chengguang Xu
@ 2020-10-18 7:53 ` Amir Goldstein
2020-10-19 6:23 ` Chengguang Xu
0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-10-18 7:53 UTC (permalink / raw)
To: Chengguang Xu; +Cc: Miklos Szeredi, overlayfs
On Fri, Oct 16, 2020 at 7:38 PM Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> Currently only mmap does not behave as stacked file operation,
> although in practice there is less change to open a file in
> RDONLY mode and take long time to do mmap but the fix looks
> reasonable.
I suppose you do not have a real life use case where this fix
is relevant?
The thing is that this change is not without consequence.
It could result in 2 overlapping mmaps on the same RDONLY fd
mapping a different file and it can be even more confusing
than different fd mapping different files.
It is not clear which non-standard behavior is preferred, so without
any evidence that one strange behavior is preferred over the other
I don't think we should change anything.
Thanks,
Amir.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
> Hi Miklos,
>
> I'm sorry that I did a mistake about signed-off-by tag in previous
> email, so I resend this patch.
>
> fs/overlayfs/file.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 3582c3ae819c..f98b1c0c975b 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -461,6 +461,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
> {
> struct file *realfile = file->private_data;
> const struct cred *old_cred;
> + struct fd real;
> int ret;
>
> if (!realfile->f_op->mmap)
> @@ -469,7 +470,11 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
> if (WARN_ON(file != vma->vm_file))
> return -EIO;
>
> - vma->vm_file = get_file(realfile);
> + ret = ovl_real_fdget(file, &real);
> + if (ret)
> + return ret;
> +
> + vma->vm_file = get_file(real.file);
>
> old_cred = ovl_override_creds(file_inode(file)->i_sb);
> ret = call_mmap(vma->vm_file, vma);
> @@ -477,13 +482,14 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
>
> if (ret) {
> /* Drop reference count from new vm_file value */
> - fput(realfile);
> + fput(real.file);
> } else {
> /* Drop reference count from previous vm_file value */
> fput(file);
> }
>
> ovl_file_accessed(file);
> + fdput(real);
>
> return ret;
> }
> --
> 2.26.2
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: (RESEND) [PATCH] ovl: stacked file operation for mmap
2020-10-18 7:53 ` Amir Goldstein
@ 2020-10-19 6:23 ` Chengguang Xu
0 siblings, 0 replies; 3+ messages in thread
From: Chengguang Xu @ 2020-10-19 6:23 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Miklos Szeredi, overlayfs
---- 在 星期日, 2020-10-18 15:53:23 Amir Goldstein <amir73il@gmail.com> 撰写 ----
> On Fri, Oct 16, 2020 at 7:38 PM Chengguang Xu <cgxu519@mykernel.net> wrote:
> >
> > Currently only mmap does not behave as stacked file operation,
> > although in practice there is less change to open a file in
> > RDONLY mode and take long time to do mmap but the fix looks
> > reasonable.
>
> I suppose you do not have a real life use case where this fix
> is relevant?
Detected by some unexpectedly running test scripts.
>
> The thing is that this change is not without consequence.
> It could result in 2 overlapping mmaps on the same RDONLY fd
> mapping a different file and it can be even more confusing
> than different fd mapping different files.
>
> It is not clear which non-standard behavior is preferred, so without
> any evidence that one strange behavior is preferred over the other
> I don't think we should change anything.
>
Makes sense.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-19 6:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 15:57 (RESEND) [PATCH] ovl: stacked file operation for mmap Chengguang Xu
2020-10-18 7:53 ` Amir Goldstein
2020-10-19 6:23 ` Chengguang Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).