Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp931598iog; Mon, 13 Jun 2022 16:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx6dtsId9cnrVUO/f3VIKaXOE+xi19k+13fc8WyfyrB+sI/knLdjtfjpa1AVvmQKgyy/xi X-Received: by 2002:a65:5207:0:b0:3fb:c00f:f6e4 with SMTP id o7-20020a655207000000b003fbc00ff6e4mr1772478pgp.415.1655163310386; Mon, 13 Jun 2022 16:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655163310; cv=none; d=google.com; s=arc-20160816; b=KdbqL5tO1K15FRGFzoyse5U94/ubE04CUqrgZ5WlWpkPdqOizZLtmBYsYlbBtwvrAj MmLQAhooaP23O057M19US4EPfn9MNlhCW6dfBaVNrwkVGz/GHWWhiMx3EsEKW9eZ4Uz7 WwoAiiewBorAocz6E77Fdt5YkLSOr4e6bp0JGgVKsmnqZMcxVAzp0UkeQe08qnxs6+GL W2PzUBrjXEIF54sh0jdSmO1gGhdszJtP+lQZbbvdBJ7Q3aVfaAvBn9NL3YUR2pBZes2S MXKiMkhT2pE+jiLHPuwAeQ4kMFd22iw4KHvX7cT/Ovii2QCt5v+MFVy1atxye1A3Yz5B qjIQ== 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=aJziV53ZNLcQpCnTSJ1xxm7rGO6TWzWG0v4urvX8NyU=; b=CXEel2uDyfiYvG33/UDUnMfm4j//GQzJ5bEZBNCLFFYYCy23s9nv6VottDeRNcgmAa /VJ38UtikHhEn6kojaT/5gNQWpSixXo3L518p4aacIv+z9pX/Z2Q70lA+6MLCl9Go5gL 0hYt/tFgPuf1exU2brSr/POLVq/at7kwAVGeiQhee5BOrSKV+prYTDoQ29QudlCmdC8s yCyz9OJZmM/YA4fW31X3Cr61uPUz0+KXiaJ3JF/3ZDx9G/thJZd2blx3TSZs75SzjFzp 3hrywSsnsDg8L4PCkiRmrBLk1Ls//6cfGu1A9+++YKc0dYkRosT6IMg+YDxUVV+jeoHP QAdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=OT0sULAj; 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 z3-20020a63e543000000b003fd4143cb9dsi10286550pgj.284.2022.06.13.16.34.58; Mon, 13 Jun 2022 16:35:10 -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=OT0sULAj; 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 S236929AbiFMXZS (ORCPT + 99 others); Mon, 13 Jun 2022 19:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239465AbiFMXZQ (ORCPT ); Mon, 13 Jun 2022 19:25:16 -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 49B1632065; Mon, 13 Jun 2022 16:25:15 -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=aJziV53ZNLcQpCnTSJ1xxm7rGO6TWzWG0v4urvX8NyU=; b=OT0sULAjLdDaLe/ufoRgRaz7h6 lrNif+4H2x52/rVv8ukb76PFqzdihC65C1EMUDEvF+Al/I3OixmZVOhwnHVxnbiuj7E2UrBJAcK3i jq5BxKMcUf79LcpEbksN/HeGbGhMS59DgwAcyqzfBHXGBAr4eL+w8z1Xhz9hgreXdCcLdwZtYOSwB ZYuHacQ5p0oL3Ji5PO+Cu6tPRFt3jXOxRhifbYIa0FpTmQz+qczlVENomVFoigy/tiAnImRolar+O VX6TvKMmZD5xYum3sDP3LaVe4eMJSNR1tv14TqHfsPe1Hd8QoCCwuRCuyn+faTB7sA1Dm1z4QhW25 kX5Ovdfg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o0tQd-0005hJ-Th; Mon, 13 Jun 2022 23:25:04 +0000 Date: Tue, 14 Jun 2022 00:25:03 +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: > 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... The more I'm looking at that thing, the more it smells like a bug; it had the same 3 callers since the time it had been introduced. 1) pipe_get_pages(). We are about to try and allocate up to that many pipe buffers. Allocation (done in push_pipe()) is done only if we have !pipe_full(pipe->head, pipe->tail, pipe->max_usage). It simply won't give you more than max_usage - occupancy. Your function returns min(ring_size - occupancy, max_usage), which is always greater than or equal to that (ring_size >= max_usage). 2) pipe_get_pages_alloc(). Same story, same push_pipe() being called, same "we'll never get that much - it'll hit the limit first". 3) iov_iter_npages() in case of ITER_PIPE. Again, the value is bogus - it should not be greater than the amount of pages we would be able to write there. AFAICS, 6718b6f855a0 "pipe: Allow pipes to have kernel-reserved slots" broke it for cases when ring_size != max_usage...