From: "Ahelenia Ziemiańska" <nabijaczleweli@nabijaczleweli.xyz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Jan Kara <jack@suse.cz>,
Chung-Chiang Cheng <cccheng@synology.com>,
ltp@vger.kernel.org
Subject: [PATCH v3 0/3+1] fanotify accounting for fs/splice.c
Date: Tue, 27 Jun 2023 18:55:22 +0200 [thread overview]
Message-ID: <cover.1687884029.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <CAOQ4uxh7i_s4R9pFJPENALdWGG5-dDhqPLEUXuJqSoHraktFiA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3694 bytes --]
In 1/3 I've applied if/else if/else tree like you said,
and expounded a bit in the message.
This is less pretty now, however, since it turns out that
iter_file_splice_write() already marks the out fd as written because it
writes to it via vfs_iter_write(), and that sent a double notification.
$ git grep -F .splice_write | grep -v iter_file_splice_write
drivers/char/mem.c: .splice_write = splice_write_null,
drivers/char/virtio_console.c: .splice_write = port_fops_splice_write,
fs/fuse/dev.c: .splice_write = fuse_dev_splice_write,
fs/gfs2/file.c: .splice_write = gfs2_file_splice_write,
fs/gfs2/file.c: .splice_write = gfs2_file_splice_write,
fs/overlayfs/file.c: .splice_write = ovl_splice_write,
net/socket.c: .splice_write = generic_splice_sendpage,
scripts/coccinelle/api/stream_open.cocci: .splice_write = splice_write_f,
Of these, splice_write_null() doesn't mark out as written
(but it's for /dev/null so I think this is expected),
and I haven't been able to visually confirm whether
port_fops_splice_write() and generic_splice_sendpage() do.
All the others delegate to iter_file_splice_write().
In 2/3 I fixed the vmsplice notification placement
(access from pipe, modify to pipe).
I'm following this up with an LTP patch, where only sendfile_file_to_pipe
passes on 6.1.27-1 and all tests pass on v6.4 + this patchset.
Ahelenia Ziemiańska (3):
splice: always fsnotify_access(in), fsnotify_modify(out) on success
splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice
splice: fsnotify_access(in), fsnotify_modify(out) on success in tee
fs/splice.c | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
Interdiff against v2:
diff --git a/fs/splice.c b/fs/splice.c
index 3234aaa6e957..0427f0a91c7d 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1155,10 +1155,7 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
flags |= SPLICE_F_NONBLOCK;
ret = splice_pipe_to_pipe(ipipe, opipe, len, flags);
- goto notify;
- }
-
- if (ipipe) {
+ } else if (ipipe) {
if (off_in)
return -ESPIPE;
if (off_out) {
@@ -1188,10 +1185,10 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
else
*off_out = offset;
- goto notify;
- }
-
- if (opipe) {
+ // ->splice_write already marked out
+ // as modified via vfs_iter_write()
+ goto noaccessout;
+ } else if (opipe) {
if (off_out)
return -ESPIPE;
if (off_in) {
@@ -1211,17 +1208,14 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
in->f_pos = offset;
else
*off_in = offset;
+ } else
+ return -EINVAL;
- goto notify;
- }
-
- return -EINVAL;
-
-notify:
- if (ret > 0) {
- fsnotify_access(in);
+ if (ret > 0)
fsnotify_modify(out);
- }
+noaccessout:
+ if (ret > 0)
+ fsnotify_access(in);
return ret;
}
@@ -1352,6 +1346,9 @@ static long vmsplice_to_user(struct file *file, struct iov_iter *iter,
pipe_unlock(pipe);
}
+ if (ret > 0)
+ fsnotify_access(file);
+
return ret;
}
@@ -1381,8 +1378,10 @@ static long vmsplice_to_pipe(struct file *file, struct iov_iter *iter,
if (!ret)
ret = iter_to_pipe(iter, pipe, buf_flag);
pipe_unlock(pipe);
- if (ret > 0)
+ if (ret > 0) {
wakeup_pipe_readers(pipe);
+ fsnotify_modify(file);
+ }
return ret;
}
@@ -1447,9 +1446,6 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov,
else
error = vmsplice_to_user(f.file, &iter, flags);
- if (error > 0)
- fsnotify_modify(f.file);
-
kfree(iov);
out_fdput:
fdput(f);
--
2.39.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-06-27 16:55 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 3:04 splice(-> FIFO) never wakes up inotify IN_MODIFY? Ahelenia Ziemiańska
2023-06-26 6:11 ` Amir Goldstein
2023-06-26 12:19 ` Ahelenia Ziemiańska
2023-06-26 12:57 ` Ahelenia Ziemiańska
2023-06-26 13:51 ` Jan Kara
2023-06-26 14:25 ` Ahelenia Ziemiańska
2023-06-26 15:00 ` Jan Kara
2023-06-26 15:15 ` Ahelenia Ziemiańska
2023-06-26 16:52 ` Jan Kara
2023-06-26 14:53 ` Amir Goldstein
2023-06-26 15:12 ` Ahelenia Ziemiańska
2023-06-26 16:21 ` Amir Goldstein
2023-06-26 17:14 ` Ahelenia Ziemiańska
2023-06-26 18:57 ` Amir Goldstein
2023-06-26 23:08 ` [PATCH v2 0/3] fanotify accounting for fs/splice.c наб
2023-06-27 6:14 ` Amir Goldstein
2023-06-27 16:55 ` Ahelenia Ziemiańska [this message]
2023-06-27 16:55 ` [PATCH v3 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-27 18:10 ` Amir Goldstein
2023-06-27 20:13 ` Ahelenia Ziemiańska
2023-06-27 16:55 ` [PATCH v3 2/3] splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27 18:11 ` Amir Goldstein
2023-06-27 16:55 ` [PATCH v3 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-27 16:57 ` [LTP PATCH] inotify13: new test for fs/splice.c functions vs pipes vs inotify Ahelenia Ziemiańska
2023-06-27 18:31 ` Amir Goldstein
2023-06-27 20:59 ` [LTP RFC PATCH v2] " Ahelenia Ziemiańska
2023-06-28 0:21 ` [LTP RFC PATCH v3] " Ahelenia Ziemiańska
2023-06-28 5:30 ` Amir Goldstein
2023-06-28 16:03 ` Ahelenia Ziemiańska
2023-06-27 22:57 ` [LTP PATCH] " Petr Vorel
2023-06-27 18:03 ` [PATCH v3 0/3+1] fanotify accounting for fs/splice.c Amir Goldstein
2023-06-27 20:34 ` Ahelenia Ziemiańska
2023-06-27 20:50 ` [PATCH v4 0/3] " Ahelenia Ziemiańska
2023-06-27 20:50 ` [PATCH v4 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-28 6:33 ` Amir Goldstein
2023-06-28 10:11 ` Jan Kara
2023-06-28 17:09 ` Ahelenia Ziemiańska
2023-06-28 18:38 ` Amir Goldstein
2023-06-28 20:18 ` Ahelenia Ziemiańska
2023-06-30 11:03 ` Amir Goldstein
2023-06-27 20:50 ` [PATCH v4 2/3] splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27 20:51 ` [PATCH v4 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-28 6:02 ` [PATCH v4 0/3] fanotify accounting for fs/splice.c Amir Goldstein
2023-06-28 11:38 ` Jan Kara
2023-06-28 13:41 ` Amir Goldstein
2023-06-28 18:54 ` Ahelenia Ziemiańska
2023-06-29 8:45 ` Jan Kara
2023-06-28 4:51 ` [PATCH v3 0/3+1] " Christoph Hellwig
2023-06-28 10:38 ` Jan Kara
2023-06-26 23:09 ` [PATCH v2 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Ahelenia Ziemiańska
2023-06-27 6:02 ` Amir Goldstein
2023-06-26 23:09 ` [PATCH v2 2/3] splice: fsnotify_modify(fd) in vmsplice Ahelenia Ziemiańska
2023-06-27 6:27 ` Amir Goldstein
2023-06-26 23:09 ` [PATCH v2 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Ahelenia Ziemiańska
2023-06-27 6:20 ` Amir Goldstein
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=cover.1687884029.git.nabijaczleweli@nabijaczleweli.xyz \
--to=nabijaczleweli@nabijaczleweli.xyz \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cccheng@synology.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ltp@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).