Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp444557pxj; Fri, 7 May 2021 12:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwBYMZMkLBILjlTbzoVS9tohx9935SJ6QRmV79yutyfwe59tmWTNR7ra7qJxkKAMqh4iks X-Received: by 2002:a17:906:d14c:: with SMTP id br12mr11503595ejb.429.1620414498227; Fri, 07 May 2021 12:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620414498; cv=none; d=google.com; s=arc-20160816; b=DA9uyAAGflCNxwGhG3R+PP83JR2wiYkwDsQAdD8zXFLCxbyK2mhC3hDJvN4OmI79fQ cE+oW+eZfWqW+/KAjPPDwb7Xax8YuK0ur5de7GFQLLT+K7p2hwspTNr3kqq53IMzec4k 03v1ysho96As9p+lgE+sPMQorDX0UzqKvRXo4K+1gqdErfCBqFZKBn9/w7yRoimDLX59 Vi+H/+yS5jqap0Os0qQngB1rCVeQDDg92db6LkHctHNwXVeSmKk3z9K6YV22uTA5Uwph JujN6wPN1dkcs6y7QS1or+uWPyBJ399KEMeLm6BgG6MY48d1AzPr3a8MSp/hRu51/VY7 banw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Gh0B3WSFNAOfleCfnt2flKLSf30MwVsP2ZwOKpp82cg=; b=FoTVsugplg/7E/Eka3/eHwVErB8OpwDSRli6cvLFQlLFXos5NgQcl2H/OThbOftbW+ 37vqLMuIEX5pL/v85qMEmEwnZolbuYMQQjh13TdKMd4w5k/MwuJ85GDTImEvgg9xHf36 LTypa8/iF9Yw7NkQc1O+i2kQKJwbOseqdVzMenytGyRRkHkgA5l5Ymc394NLv3TLl1RU QFG+gKXb6MkfjdQpDz48jr3smvKysWqEaRZztGIlqyyDhXUnEetcRBP0OdbfJaKCuuKD BOr57mmT7dVmIDaV7wTfj/qV5N1Iq0eSuvTapC7u/XJlH7SietVaep/CpLDxIJbmFj0X v3MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=L9XM6lPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si6837441eji.749.2021.05.07.12.07.52; Fri, 07 May 2021 12:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=L9XM6lPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbhEGTHx (ORCPT + 99 others); Fri, 7 May 2021 15:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbhEGTHv (ORCPT ); Fri, 7 May 2021 15:07:51 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 377DCC061574 for ; Fri, 7 May 2021 12:06:51 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id j10so14120047lfb.12 for ; Fri, 07 May 2021 12:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gh0B3WSFNAOfleCfnt2flKLSf30MwVsP2ZwOKpp82cg=; b=L9XM6lPCsR5SHe/yUVKrYoqK1Ves/gBOL1CWHPlhDT+6bNo/qx0S6DRRVt7dEXa0h1 GWWo0lgKavlZBY9zlJFVG83v3PUZHzdMPeVfe7bgYAKX+03k2WBamuthGdgpFjkORL/G xWCFEYTl+e9SaO/+8AS0mz4kTkGvCpeLoQwBI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Gh0B3WSFNAOfleCfnt2flKLSf30MwVsP2ZwOKpp82cg=; b=uRFGb2H9+IXIwXvl02oP/oWwZZKo030Dx1MceNABExcOHHxK40Fw5vkv6PKQE1BrRu GqNA0YDoXpWMtN4mvVl86WsGAiOzdQ/g4wiUlZRYOtXzrKKfnwP1ROTGdPj7hUXAEwvr g7V1h0G8kFZ8norbxKeOFddUDgAHdz9ArRrYe8EI11PwA55dNGVVNdPQOUBxpG2AVTsM va9jbYiOjUcJCX//vF0qLWUO+X9vBD19JD3QQxWRABK2uxK4IAuXgN9OI4mX6kjctAKZ iuwFozqnJX8nplY8v71lv5JCbGIcHg2gBPuzxBWIDiBtsjamVJXXdSGEWhSZSuEwNKO7 EGiw== X-Gm-Message-State: AOAM533gG03XoUT1h8qKS6M1LUS/ZlqaWGHDt2yVf3mmInEbA1knuGSA iVWUdQZacBOuIjBIAwXQB78na72P37F1ftUVgUM= X-Received: by 2002:a05:6512:3d20:: with SMTP id d32mr7194645lfv.648.1620414409498; Fri, 07 May 2021 12:06:49 -0700 (PDT) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com. [209.85.208.174]) by smtp.gmail.com with ESMTPSA id d7sm1442777lfa.48.2021.05.07.12.06.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 May 2021 12:06:48 -0700 (PDT) Received: by mail-lj1-f174.google.com with SMTP id u20so12840380lja.13 for ; Fri, 07 May 2021 12:06:48 -0700 (PDT) X-Received: by 2002:a05:651c:3de:: with SMTP id f30mr8768618ljp.251.1620414408470; Fri, 07 May 2021 12:06:48 -0700 (PDT) MIME-Version: 1.0 References: <2add1129-d42e-176d-353d-3aca21280ead@canonical.com> <202105071116.638258236E@keescook> In-Reply-To: <202105071116.638258236E@keescook> From: Linus Torvalds Date: Fri, 7 May 2021 12:06:31 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: splice() from /dev/zero to a pipe does not work (5.9+) To: Kees Cook Cc: Colin Ian King , Christoph Hellwig , Al Viro , Johannes Berg , linux-fsdevel , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 7, 2021 at 11:21 AM Kees Cook wrote: > > So the question is likely, "do we want this for /dev/zero?" Well, /dev/zero should at least be safe, and I guess it's actually interesting from a performance testing standpoint (ie useful for some kind of "what is the overhead of the splice code with no data copy"). So I'll happily take a sane patch for /dev/zero, although I think it probably only makes sense if it's made to use the zero page explicitly (ie exactly for that "no data copy testing" case). So very much *not* using generic_file_splice_read(), even if that might be the one-liner. /dev/zero should probably also use the (already existing) splice_write_null() function for the .splice_write case. Anybody willing to look into this? My gu feel is that it *should* be easy to do. That said - looking at the current 'pipe_zero()', it uses 'push_pipe()' to actually allocation regular pages, and then clear them. Which is basically what a generic_file_splice_read() would do, and it feels incredibly pointless and stupid to me. I *think* we should be able to just do something like len = size; while (len > 0) { struct pipe_buffer *buf; unsigned int tail = pipe->tail; unsigned int head = pipe->head; unsigned int mask = pipe->ring_size - 1; if (pipe_full(head, tail, pipe->max_usage)) break; buf = &pipe->bufs[iter_head & p_mask]; buf->ops = &zero_pipe_buf_ops; buf->page = ZERO_PAGE(0); buf->offset = 0; buf->len = min_t(ssize_t, len, PAGE_SIZE); len -= buf->len; pipe->head = head+1; } return size - len; but honestly, I haven't thought a lot about it. Al? This is another of those "right up your alley" things. Maybe it's not worth it, and just using generic_file_splice_read() is the way to go, but I do get the feeling that if we are splicing /dev/null, the whole _point_ of it is about benchmarking, not "make it work". Linus