Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp986860iog; Mon, 13 Jun 2022 18:07:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyshGDYOJSXBVvtkJs6xgtjpBhCrNHcyu5/DmVv5Ued2vSPPfFsFlkHruRbzubcKC0L3SBW X-Received: by 2002:a17:907:868f:b0:702:f865:55de with SMTP id qa15-20020a170907868f00b00702f86555demr2147191ejc.24.1655168831468; Mon, 13 Jun 2022 18:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655168831; cv=none; d=google.com; s=arc-20160816; b=hdB8LAs3yQ48rjokLi29CKuz28UNcEOgTbczd1tCF2WkKcPRc33yUB6bO1iegqUJ/N qzhsEkICqFC150jtHMgu9YO3WbDFv239aDs49Ad1RjYt7JpdqQlswSDrvXvDLRi5vZ1o eLlyR2/wXDvVkFV+EibaHCSJ4abzrVaiFIu5l7knM2/gO2Qx+jicnffCiFccGOidYz00 +5CLpQLvGeIodhILum+PlcgH70pV11Nl5ak2Mg3CEXLd5CLNPwtCYPYrecKk8aIvAdzi H3jQYSo6/Z8swUliEcROWndlGikVw9V+Ckh3r3d7XnxSdGU3tTnvZmxssSoYnjejshzC Dpxg== 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=gb5E1ldq5OJFZfWUbl/fw8bH7nSwLZwzG19ZDpeNBtQ=; b=j7s4EVH1k7A8qai9IGAedKw3QvUR9+VGhHJuGdrJTsb8Z9FADN8ZJrDZDukAyg0Mhe u89hB679Htj7msDCmZeFUxnnU9+9eGs1o2rXGltdeMkYR/IiPp1yEYBQZZ5YgzuIPVkb P7E8KfO14J/vrwGkKjk1CnnPbCSbozoVXAqZvkb3EXWce727auEAdfBggvg9mZOL9+G2 Pj+L7bKE9RH05dLPivFyKwjL8H97sv2t2iReAQ+8lwkLS5n7oBT68ayXbBub+ybrEdYu 5qgDF1BXGDVaO/c4Shu6la1cNxkrCTxTGuuVyXZ7/jrihWIfz8prhy9elAjl/zUoa0KT IVbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=KvBo6xh0; 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 v17-20020aa7d651000000b0042ddac25209si8969151edr.92.2022.06.13.18.06.46; Mon, 13 Jun 2022 18:07:11 -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=KvBo6xh0; 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 S241377AbiFNAx6 (ORCPT + 99 others); Mon, 13 Jun 2022 20:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiFNAx4 (ORCPT ); Mon, 13 Jun 2022 20:53:56 -0400 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 7CBFC2FFF5; Mon, 13 Jun 2022 17:53:55 -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=gb5E1ldq5OJFZfWUbl/fw8bH7nSwLZwzG19ZDpeNBtQ=; b=KvBo6xh0HK0GydjEAQjoC1HVyL AV1IOkIMCtraKad7QJkyct7tjm3FtoFtF2qsWzNdFshheB1Dk7YxDdq1JR4bHoJP8J5ZliaDkZ3GM ZY3NtJq9VqYTIY2fgfAyniULF7Id+UNImGHTGgZKl1dcX0j3keZqdlOqs4RZad+O1PQwYjgJ9v62X UTMn1R72uDrIhvpdOSP7Oiuaz6mfSpYlRQyelvj64pvv0LK3Rn1ZQDmUCvejv4CAGbOwpk4Z6rJN+ tVE3g7LWbJFVwGmfy8H1X5iJUYWi7SiUzaVLrof+c1oHLKlVOKZbTG7iABZjNXqQNab5x4UxluGCX GCizf9Fw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o0uoY-0006Pc-QR; Tue, 14 Jun 2022 00:53:50 +0000 Date: Tue, 14 Jun 2022 01:53:50 +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 11:28:34PM +0100, Al Viro wrote: > 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... FWIW, I've got quite a bit of cleanups in the local tree; reordering and cleaning that queue up at the moment, will post tonight or tomorrow. I've looked into doing allocations page-by-page (instead of single push_pipe(), followed by copying into those). Doable, but it ends up being much messier. IMO this "truncate on failure" approach is saner.