From patchwork Tue Jun 27 16:55:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13294814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23AA8EB64D9 for ; Tue, 27 Jun 2023 16:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbjF0Qzb (ORCPT ); Tue, 27 Jun 2023 12:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjF0Qza (ORCPT ); Tue, 27 Jun 2023 12:55:30 -0400 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA06397; Tue, 27 Jun 2023 09:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1687884923; bh=JbdHKDIIKTI2/zLdYwnwsm7aGJ9yF1yJAJVd+rjxLKE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MUO1vDXxXz65himZ9pbtz3C9L+ROPw+Lh6PGBVcZpo2R1LG+J2X1rMfA/P6bk2MfA YQl769QrR2gOTNNjJVLEtY57Bump4i0jvV+oeG+LqKpHnKJwazU0tFN+hd+04G02Wu Cm5UXQV1MOuBm3uGdJ7jU6o+smeBu4rKzXq24aWfyQcvd/QEWEgjYSHauXmT9JgxPb cy+UC6Vf7gGot7CszkTcPhxdu1y+Jb7mfxqz9UbYoHzb8odyQyiklbM3F4fWPGCRbw rwU+/Gi1+yaQrcovrHIti/GZCG6/yqUN41/TjUlSV3hMyqKSOkxCa+hXcHwP7KVC68 lsPejDrYmTyqw== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 914181A88; Tue, 27 Jun 2023 18:55:23 +0200 (CEST) Date: Tue, 27 Jun 2023 18:55:22 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: Amir Goldstein Cc: Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Chung-Chiang Cheng , ltp@vger.kernel.org Subject: [PATCH v3 0/3+1] fanotify accounting for fs/splice.c Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20230517 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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); From patchwork Tue Jun 27 16:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13294816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 562CFC001B0 for ; Tue, 27 Jun 2023 16:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjF0Qzy (ORCPT ); Tue, 27 Jun 2023 12:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjF0Qzx (ORCPT ); Tue, 27 Jun 2023 12:55:53 -0400 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C6ED10F; Tue, 27 Jun 2023 09:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1687884951; bh=zaiiTIQm+Ka+TX+0vYl9PnxvGYZU7w8NqATlroNC6p0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WdMG1sm5NRYxvt8I5gq00DBkYKI3Q4MObBBsJbYbOqARD5a59yVLVqXWjEAMyxcRD Rh8oa93FQxAJBISz7ANoEICJf6GgApt42SYAZPxqLvX7dzSI0+rcZm7OdjR7dl6idW cc0RqjU+ghJV/0ITRG/Xfc8uh1cIQq4G4HDf7d0t1VOtaTkZErVTo5lnP8oJ/lhn8w /q57QcwV8wqexSrRO0lN212HReZZ771YSxo9FQie1eJ2AzDE2uwiugXgQRHVt+Y9KU 8l+5Qln1fSGx4g5ZAeCjHVZRrmSjCjVt5JwaXiqLt/xOtT678NxnQ5lohqkeh/2P5C MeKiMorEgQZGQ== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 6E44B1A8E; Tue, 27 Jun 2023 18:55:51 +0200 (CEST) Date: Tue, 27 Jun 2023 18:55:50 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: Amir Goldstein Cc: Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Chung-Chiang Cheng , ltp@vger.kernel.org Subject: [PATCH v3 2/3] splice: fsnotify_access(fd)/fsnotify_modify(fd) in vmsplice Message-ID: <4206d7388fdbee87053c9655919096225a461423.1687884031.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20230517 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Same logic applies here: this can fill up the pipe and pollers that rely on getting IN_MODIFY notifications never wake up. Fixes: 983652c69199 ("splice: report related fsnotify events") Link: https://lore.kernel.org/linux-fsdevel/jbyihkyk5dtaohdwjyivambb2gffyjs3dodpofafnkkunxq7bu@jngkdxx65pux/t/#u Link: https://bugs.debian.org/1039488 Signed-off-by: Ahelenia Ziemiańska Reviewed-by: Amir Goldstein --- fs/splice.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/splice.c b/fs/splice.c index e16f4f032d2f..0eb36e93c030 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1346,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; } @@ -1375,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; } From patchwork Tue Jun 27 16:55:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13294817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8FDCEB64D9 for ; Tue, 27 Jun 2023 16:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbjF0Q4F (ORCPT ); Tue, 27 Jun 2023 12:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbjF0Q4C (ORCPT ); Tue, 27 Jun 2023 12:56:02 -0400 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC27018C; Tue, 27 Jun 2023 09:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1687884956; bh=izqD3jT+ADWBX3rn8DQFe67pMsMvDJNKvE2GgEtMe7s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CfHLC6O0JAaN2qNDtJDzq4Gz/M5XN6XtFNQmfupTu66xUWMV5oPWGWAbtwX3Py7yu 1tOOCa4UaHEOzQptUN1dJeoxRQ8XT5HAOjbFS+/GRntcepqlX0tKIDgk9MsgZwEQsr IUxgNj7FFFPN7CBFpJwWDjL0EATSvlyg93KRax6n+ftB0MzQG4uc54WyWdmbvomfma U9Y8N+63Obc3b1YUQsxzT/EiHxN6b6U2CDDcHITQEc2ZSCV44JNwByM42BuxSDP803 K1QsxMTi2Z4+pbozxfaUr8yKAT/iGz4Ajtih/7wiyniZurlp82qwHxOkuuMtZum3o9 XeJ7DT8gi6REA== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 375471A90; Tue, 27 Jun 2023 18:55:56 +0200 (CEST) Date: Tue, 27 Jun 2023 18:55:55 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: Amir Goldstein Cc: Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Chung-Chiang Cheng , ltp@vger.kernel.org Subject: [PATCH v3 3/3] splice: fsnotify_access(in), fsnotify_modify(out) on success in tee Message-ID: <080710f0a1a5c0f124bfa6cc2569b976e0365a91.1687884031.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20230517 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Same logic applies here: this can fill up the pipe, and pollers that rely on getting IN_MODIFY notifications never wake up. Fixes: 983652c69199 ("splice: report related fsnotify events") Link: https://lore.kernel.org/linux-fsdevel/jbyihkyk5dtaohdwjyivambb2gffyjs3dodpofafnkkunxq7bu@jngkdxx65pux/t/#u Link: https://bugs.debian.org/1039488 Signed-off-by: Ahelenia Ziemiańska Reviewed-by: Amir Goldstein --- fs/splice.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/splice.c b/fs/splice.c index 0eb36e93c030..2ecfccbda956 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1815,6 +1815,11 @@ long do_tee(struct file *in, struct file *out, size_t len, unsigned int flags) } } + if (ret > 0) { + fsnotify_access(in); + fsnotify_modify(out); + } + return ret; }