Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp906299iog; Mon, 13 Jun 2022 15:56:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s5oD1cz4s/S8iVDEQugtPgGLhRSJ1f1267eKbLWeZu8iAzSGz665Zrnk0sgOQynHBd0IGD X-Received: by 2002:a17:90b:682:b0:1e3:142:a562 with SMTP id m2-20020a17090b068200b001e30142a562mr1058216pjz.91.1655160992767; Mon, 13 Jun 2022 15:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655160992; cv=none; d=google.com; s=arc-20160816; b=IswLsa59Z7ns7NjFpwq9pefxs4MVN1REQ4DWkmUR3EH6+JCfzgkduEkSCPC7xLzgxt tWeUmYA2JQ9T+3kUj5dkrwogXLk8SCRRDEPbn9Yr80+ImZWt5QF33iZ7qesnmfcW1ucQ pvzOBl5KOpJ86eVZ1ufM602C/15t6/iykhrtAx1zxvDm6sEcQYC1qAEd0PHy3Za4h1UC u66+AvH12QFPg6SwVXDvPb1lKspKTtPiR1WuWF2PkmRkuTsn/OhRjsFE+cHIMO3x+OaW twGyLWUcwwgFXpCy1YMleNJJcWruHsNuQU8m5n+6YH5JGIirHTWjIzvUk6E1azKf1pq2 ftkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=+COkvdNrG6nWHW8DeXVNn4pSIXXVecQkufUo12vTZqM=; b=LdFeY2oJmV534yd6yMVHYgGaROFkK8nJLpnkcG/3y1Wvw9e2Va52p4Hsa8PwSLPv50 +LduQua+CWDSTPHz9R1qwakiT+KM3MOuYwdqUzraDFXrriS1OjQ8X4ZT6myqGf3N0MFF DDYz+o6HASyhC6gIhK3TkD3bN2kE96AxxQxNxb1dhs3Z5TnywLqR+qhqeBrJ42PnCPY7 0zSHBjC/5iuz0K0wDa6iJoe5c8qqhoUByks5fhARVa/TcXSWUALjznFZbMHV8xjkEmVV EN2ZI4pw8NjnB1FyOqcU+z7ZXYC99XpHI5tdC5NycMG/aaXa0clXK0heZx9Lpt821EeH vXkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=F1GaohTq; 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=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k24-20020a63ba18000000b003fcae93182bsi11621837pgf.370.2022.06.13.15.56.20; Mon, 13 Jun 2022 15:56:32 -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=@linux.org.uk header.s=zeniv-20220401 header.b=F1GaohTq; 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=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbiFMWrs (ORCPT + 99 others); Mon, 13 Jun 2022 18:47:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbiFMWrq (ORCPT ); Mon, 13 Jun 2022 18:47:46 -0400 X-Greylist: delayed 1140 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 13 Jun 2022 15:47:45 PDT Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B3130572; Mon, 13 Jun 2022 15:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+COkvdNrG6nWHW8DeXVNn4pSIXXVecQkufUo12vTZqM=; b=F1GaohTqdVyGbYtsxIq1ypUFSB P1lDuj/SfIxIUbtNOkI8o8CmCXWpPq/1+OMrMMOxMWjRQoykrHF01Bq4OG0vxR0hKM5bbwC9uWOd9 2/mdrfapr7kM/8zZ6/tsuHr3nPIYSd/WzF2XWntJS3FWWPOug6sDaEw/SFUeb0PMXbBSmi7lByhJm GA2PvhnaqVNF03pAh+K/YYGKB64ks4khKPFs48hRmwGveqm7TfpcG87sSbrydMzgtxbcH248jh/q/ d6pEaGxSHgZi/+SunJ6dUdtnr+ZWQL5awJRvRUba+eqJscSETAyFR+DCrVKsFj874VH3hJcv8Nh/L 0SgvT1OQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o0sXy-0005E5-FL; Mon, 13 Jun 2022 22:28:34 +0000 Date: Mon, 13 Jun 2022 23:28:34 +0100 From: Al Viro To: Linus Torvalds Cc: Dan Williams , Linux Kernel Mailing List , linux-fsdevel , nvdimm@lists.linux.dev, David Howells Subject: Re: [RFC][PATCH] fix short copy handling in copy_mc_pipe_to_iter() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Mon, Jun 13, 2022 at 10:54:36AM -0700, Linus Torvalds wrote: > On Sun, Jun 12, 2022 at 5:10 PM Al Viro wrote: > > > > Unlike other copying operations on ITER_PIPE, copy_mc_to_iter() can > > result in a short copy. In that case we need to trim the unused > > buffers, as well as the length of partially filled one - it's not > > enough to set ->head, ->iov_offset and ->count to reflect how > > much had we copied. Not hard to fix, fortunately... > > > > I'd put a helper (pipe_discard_from(pipe, head)) into pipe_fs_i.h, > > rather than iov_iter.c - > > Actually, since this "copy_mc_xyz()" stuff is going to be entirely > impossible to debug and replicate for any normal situation, I would > suggest we take the approach that we (long ago) used to take with > copy_from_user(): zero out the destination buffer, so that developers > that can't test the faulting behavior don't have to worry about it. > > And then the existing code is fine: it will break out of the loop, but > it won't do the odd revert games and the "randomnoise.len -= rem" > thing that I can't wrap my head around. > > Hmm? Not really - we would need to zero the rest of those pages somehow. They are already allocated and linked into pipe; leaving them there (and subsequent ones hadn't seen any stores whatsoever - they are fresh out of alloc_page(GFP_USER)) is a non-starter. We could do allocation as we go, but that's a much more intrusive change... BTW, speaking of pipes: static inline unsigned int pipe_space_for_user(unsigned int head, unsigned int tail, struct pipe_inode_info *pipe) { unsigned int p_occupancy, p_space; p_occupancy = pipe_occupancy(head, tail); if (p_occupancy >= pipe->max_usage) return 0; p_space = pipe->ring_size - p_occupancy; if (p_space > pipe->max_usage) p_space = pipe->max_usage; return p_space; } OK, if head - tail >= max_usage, we get 0. Fair enough, since pipe_full() callers will get "it's full, sod off" in that situation. But... what the hell is the rest doing? p_space is the amount of slots not in use. So we return the lesser of it and max_usage? Suppose we have 128 slots in the ring, with max_usage being below that (e.g. 64). 63 slots are in use; you can add at most one. And p_space is 65, so this sucker will return 64. Dave, could you explain what's going on there? Note that pipe_write() does *not* use that thing at all; it's only splice (i.e. ITER_PIPE stuff) that is using it. What's wrong with p_occupancy = pipe_occupancy(head, tail); if (p_occupancy >= pipe->max_usage) return 0; else return pipe->max_usage - p_occupancy; which would match the way you are using ->max_usage in pipe_write() et.al. Including the use in copy_page_to_iter_pipe(), BTW...