From patchwork Mon Jul 3 14:42:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 115409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp581887vqx; Mon, 3 Jul 2023 07:57:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEWabvhdoy78H3UzTuW8K6V0y0l71d6qtJvh6a+4KqhxlcxQnfNOTV2Hx357G9Os4DbcHlP X-Received: by 2002:a17:902:7c82:b0:1b8:9fc4:2733 with SMTP id y2-20020a1709027c8200b001b89fc42733mr1086374pll.3.1688396261655; Mon, 03 Jul 2023 07:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688396261; cv=none; d=google.com; s=arc-20160816; b=PBOSYWrTmHbufP1ueR+4AIfRjDSvrjABDJMWt+9+h+3dYeBYWhuVsEmqdeFymZLkvs 7HozIjFAyRaEjQhrkro48aHg73OmwjsbiRmV6vRHY2eVHsf1b8to1Vxfj5RT6AVsDumY Kb6DA953GGFOJgaD+jlpv7DEQoS44O5o9cVcWkkZgY8GA6WLF9q6p4UvN1jfvdT7HNTP 7YHY0CWZZaq5z8SpCVNo9OAmIS2rzA2YjYyYOo+3JdPPrqvTxv03Qc4KAq+M42Cqrkiz MGfPNEdsiXVLBobtxYGh6q/W4LBz/UASTaBTTobUyquzh0vJgVSznsaPhaCSCvmv/IeC +NNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=+9esspNFZECgfIJtAXuayWzH+pCWd0OfJzUtm4d/Hk8=; fh=AfCaarrJloRV9X8pgVoQkWOYp+JFhFv1/c5FQOfH+1Q=; b=B5zO+RqFlMXZYRohne4qnzu5TppIZqGvl4lcD4W87o3B9liJoIF2RjEpwTRxP2rdY5 Dvl1saykKVb6V9wBdxniYKVcIb8BhwTZu9DYYoCjMe4RUl7hDvD2Cfc/CGpY2fkz/l5Q zWnfU5oj7kdHO/h6OFRlIr1lHSYph8Yd7h/elhPpeQjotfPLwoG7M/krdkjF0pktmitO 7SZJ+X/NKo7bFs7wa0G1fe5HuQcsd3m2gVNRFG8sCCz2jOOaas+BpsyIFc9vQEi6CpTR lr+D5eAhiAWbTLBPtLVIkPJNUXt9WYwesfKt+hoJfI9iujCqHXfqnhimc6yOAdkaUT/w B6LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=hKE4LH1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a170902ce0d00b001b025aba9f2si19574394plg.22.2023.07.03.07.57.27; Mon, 03 Jul 2023 07:57:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=hKE4LH1q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nabijaczleweli.xyz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231232AbjGCOmS (ORCPT + 99 others); Mon, 3 Jul 2023 10:42:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231223AbjGCOmQ (ORCPT ); Mon, 3 Jul 2023 10:42:16 -0400 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12002B2; Mon, 3 Jul 2023 07:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1688395334; bh=xUQlRJiv0BrDJu2N4vefK4PLI4lrSt6Z70TDgeQpcYs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hKE4LH1qBJLiXXH9rih/kbNbGViPFRh7mp4kfHOm8PL48Or5SW9QTOO/HZOz0Wiqo /dV6D/T26s14gdarunqZSVTjn1AigsmFkD3jSblOg8ZLckdb7zPN5HhkOwD64aywR9 ffHZwQJBm40JW38O99WfivmMcRi+Lltc3Zwqkpami0Cxc0GnO/is19Q8qapVqPr+cl 6TLGGcvYMbWdN+vqAQqGj56hDfHCqi9BT58EARtAIm6QgOCO9QL4iQec6MTF/ZfH8K erTR/VfIhdHCiB288dTe2BY1fHtPUtWtc5MYFrypJxZ8//WHk9DvbWtufi03usHRph pgTITT+bp/m2g== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 571C71DBE; Mon, 3 Jul 2023 16:42:14 +0200 (CEST) Date: Mon, 3 Jul 2023 16:42:13 +0200 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= To: Christian Brauner Cc: Alexander Viro , Jan Kara , Amir Goldstein , Chung-Chiang Cheng , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Message-ID: <604ec704d933e0e0121d9e107ce914512e045fad.1688393619.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20230517 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,PDS_RDNS_DYNAMIC_FP, RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770411798555978180?= X-GMAIL-MSGID: =?utf-8?q?1770411798555978180?= The current behaviour caused an asymmetry where some write APIs (write, sendfile) would notify the written-to/read-from objects, but splice wouldn't. This affected userspace which uses inotify, most notably coreutils tail -f, to monitor pipes. If the pipe buffer had been filled by a splice-family function: * tail wouldn't know and thus wouldn't service the pipe, and * all writes to the pipe would block because it's full, thus service was denied. (For the particular case of tail -f this could be worked around with ---disable-inotify.) 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 Acked-by: Jan Kara --- fs/splice.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 3e06611d19ae..6ae6da52eba9 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1154,10 +1154,8 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out, if ((in->f_flags | out->f_flags) & O_NONBLOCK) flags |= SPLICE_F_NONBLOCK; - return splice_pipe_to_pipe(ipipe, opipe, len, flags); - } - - if (ipipe) { + ret = splice_pipe_to_pipe(ipipe, opipe, len, flags); + } else if (ipipe) { if (off_in) return -ESPIPE; if (off_out) { @@ -1182,18 +1180,11 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out, ret = do_splice_from(ipipe, out, &offset, len, flags); file_end_write(out); - if (ret > 0) - fsnotify_modify(out); - if (!off_out) out->f_pos = offset; else *off_out = offset; - - return ret; - } - - if (opipe) { + } else if (opipe) { if (off_out) return -ESPIPE; if (off_in) { @@ -1209,18 +1200,24 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out, ret = splice_file_to_pipe(in, opipe, &offset, len, flags); - if (ret > 0) - fsnotify_access(in); - if (!off_in) in->f_pos = offset; else *off_in = offset; + } else + return -EINVAL; - return ret; + if (ret > 0) { + /* + * Generate modify out before access in: + * do_splice_from() may've already sent modify out, + * and this ensures the events get merged. + */ + fsnotify_modify(out); + fsnotify_access(in); } - return -EINVAL; + return ret; } static long __do_splice(struct file *in, loff_t __user *off_in,