From patchwork Tue Jun 27 20:50:52 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: 113602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8464350vqr; Tue, 27 Jun 2023 13:54:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hdztkp1btpE9K5dhXQjH9h8Gkp/1/gbEiIcr6T29Kep/uWtDYej6NerWFn+AVtdTlwQDJ X-Received: by 2002:a05:6a20:7d96:b0:12b:f44f:bc98 with SMTP id v22-20020a056a207d9600b0012bf44fbc98mr1196855pzj.21.1687899253398; Tue, 27 Jun 2023 13:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687899253; cv=none; d=google.com; s=arc-20160816; b=FGAoeN7EUQF43Bl9aPlgzqMMARzIvoglqtl+mB9hysJIXRRdn3YyPy+0Ium90xaYIf im3X3hh9AgdmtflwJs5fEuxn62Csk6ndxGFydJXNoy/fifmUtqlrNVaLvQBFHlYRchfu Ef59VxDOe7Mgr+Ajf/Qx91ES38PHudoFeuQ+EYLoRkhzijPc7yb1+OcmXM2aKO9L0vG5 HAPBzSgIBbNOxhalqugqx10rJCkPZ88WtteeXdcuFEpzzKnUINmF79cCtYtQOdAmNO2J MZ1LVpJSmm4CwKinq3SixB9R7985vQldDO6E1IPFnX9QYcvFTrsFJIjNifCXWhjOgvLW 3M5w== 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=P8ekdkgBH92tA9Ly0VzKRksCfLz4wsaYbX9MRQxlGKk=; fh=EwHFucLs4bwDakTQKl/ndDudi5N9htFCanErUntz+qw=; b=CDyiRGW8tCm/G7/TG/LHwDPDTxz0wTspTumbTawvB61e7VmzCjjbOrRGnj9+SN8Tm4 AXgH+jGpdgmQ3US2E+l0mASlwoCAhWNwOJCMErJjBuRem4k9VujXpL/c9Z4n4kvVERH7 +alqL6ntOEcy8IUIoHNZ0/tdM3Q4fCDNpI03VLleMpqiwhzKNpCkAnvEE8OoBw1/ea/p RQunHsV0AnBSGjZCIDEGPoYIV0suUXnqbRnyzgJ9jpPBBvBZvAQ35FpdTcpw2BvSe4B9 dWt+M5R7JukrfnLPDr8QU3GmIQm5GNevSyslm4CLhrfhmzQHe6+tcJ8gI5MpE5ep2+g4 BVAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nabijaczleweli.xyz header.s=202305 header.b=c0yE1oTL; 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 201-20020a6301d2000000b005347d133470si8101233pgb.385.2023.06.27.13.54.01; Tue, 27 Jun 2023 13:54:13 -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=c0yE1oTL; 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 S230420AbjF0UvB (ORCPT + 99 others); Tue, 27 Jun 2023 16:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbjF0Uuz (ORCPT ); Tue, 27 Jun 2023 16:50:55 -0400 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92EA9ED; Tue, 27 Jun 2023 13:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202305; t=1687899053; bh=qCdQpza0vGDqNSdxaU8DpurpP2cGaeH8ooUq+QibGG8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=c0yE1oTLMDmySbdvOBrMfwjecFrriPS22m25V4FrQ9pdR/RLc0J93Q3wNpU+YwTMx 5eegks9sgfjtmCD4RzXALcaMHBXL6L+zmZ7YgPOofSKJYravKbeg/2UnKxmzuTfxAK K16wd4fd9eIAoXfm+ZW35dh6NI3E14NjI0yz3y/WS7sb2wVDUIUaHgjMMNGhfveWw1 3vNqt0CseE0IcRJWEdHxiY0IQGuIAe0KahxXq+csSiAvUr9OTWq1TCckCCdxRCqyRA 8v5XvojpVaDT2nn9XR9eybkbzh2+MqZ5sEYH+wOjf4mrVCx31aFDxTGbh51yaZwS+F Rdl6dG4WDtWSw== Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id E0BCA12C6; Tue, 27 Jun 2023 22:50:53 +0200 (CEST) Date: Tue, 27 Jun 2023 22:50:52 +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@lists.linux.it Subject: [PATCH v4 1/3] splice: always fsnotify_access(in), fsnotify_modify(out) on success Message-ID: 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,URIBL_BLOCKED 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?1769890647510803660?= X-GMAIL-MSGID: =?utf-8?q?1769890647510803660?= 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.) Generate modify out before access in to let inotify merge the modify out events in thr ipipe case. 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 | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 3e06611d19ae..b5c7a5ae0e94 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,19 @@ 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) { + fsnotify_modify(out); + fsnotify_access(in); } - return -EINVAL; + return ret; } static long __do_splice(struct file *in, loff_t __user *off_in,