Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3000301pxk; Sun, 6 Sep 2020 23:23:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+EvOPJjCG/kKSERUDoj4iwypLtZJwWoU6I4Huh3kovweMS07n6pa3JcMbP5FomKrbMdCT X-Received: by 2002:a17:906:328d:: with SMTP id 13mr20349369ejw.71.1599459833280; Sun, 06 Sep 2020 23:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599459833; cv=none; d=google.com; s=arc-20160816; b=mwTxNyMqj6qCkPYJgnnq5SlVzv2oS/RH8WS3HtMf7Api05P/+HWFUCsK4ne85XiP0o OweVmUJYN2Xtn7ak412XT4Dbij2pX9bI10GHBEYhAOHVslcujTrsYlsxA8N4rYnbb/W4 h9gNdUt6IbMvEF3hMJry+8fkyIKi26rmLxR4fSvO3RMrnJ8JfK+J0tUFNLOlrKXVIk9Q HkcJez4yKdC1S9eBdLpasNurVUzMPPQsMCk+EVv6E81ZWFmT0vJpBgT/MderiMhByVGm YutfxMNRSXf9O+6GXss62QWMQTog+zHrOTBkEoGtZXlY1nwTgzVL8TOeRuoXB0YMNVDo FsrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0MDFsZzBUisqi18M1sChO7KQ88O//Yi2LanhfOtwsGY=; b=Bp33MQ/z3ohRj8+560lMiEsW8JgX+Ui9Kf3kZqL5nUtaFcCu5q6+buZAG3G/01mvfQ 1txdd8ytpiOSL4oHLbgDnUYjzwys1S/kQnrtFlNbsqgM+dK0WgatgpNQ22YlJ5mL4Qg8 Pt9kgExhWQtqwKX8SCKOnf6i/DcZp62joou8+JvDer1QdOn4tSLCtfSTCWRp2NnhTQYZ QsXcauI1NmT2uWBiMHgoV8UZo8TTZDNvwiIkcmNn+YozoG8wVunsG4h4pdJjXqsMA2Ox dkqChQmidi++CFDCamLJP9yyFNRhKJZ+k4ayP630TiBWVIi6TzBdOf8JUgsApQGNkfwt cFWA== ARC-Authentication-Results: i=1; mx.google.com; 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 u16si9311702ejr.4.2020.09.06.23.23.30; Sun, 06 Sep 2020 23:23:53 -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; 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 S1726410AbgIGGUa (ORCPT + 99 others); Mon, 7 Sep 2020 02:20:30 -0400 Received: from verein.lst.de ([213.95.11.211]:47767 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbgIGGU3 (ORCPT ); Mon, 7 Sep 2020 02:20:29 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id EE1C56736F; Mon, 7 Sep 2020 08:20:26 +0200 (CEST) Date: Mon, 7 Sep 2020 08:20:26 +0200 From: Christoph Hellwig To: Rasmus Villemoes Cc: Christoph Hellwig , arnd@arndb.de, gregkh@linuxfoundation.org, christophe.leroy@csgroup.eu, linux-kernel@vger.kernel.org Subject: Re: [PATCH] /dev/zero: also implement ->read Message-ID: <20200907062026.GA19076@lst.de> References: <20200903155922.1111551-1-hch@lst.de> <8d430999-b155-dbfa-e7db-f414b48014b1@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8d430999-b155-dbfa-e7db-f414b48014b1@rasmusvillemoes.dk> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 07, 2020 at 12:34:37AM +0200, Rasmus Villemoes wrote: > On 03/09/2020 17.59, Christoph Hellwig wrote: > > Christophe reported a major speedup due to avoiding the iov_iter > > overhead, so just add this trivial function. Note that /dev/zero > > already implements both an iter and non-iter writes so this just > > makes it more symmetric. > > > > Christophe Leroy > > ?-by ? Suggested-by, > > +static ssize_t read_zero(struct file *file, char __user *buf, > > + size_t count, loff_t *ppos) > > +{ > > + size_t cleared = 0; > > + > > + while (count) { > > + size_t chunk = min_t(size_t, count, PAGE_SIZE); > > + > > + if (clear_user(buf + cleared, chunk)) > > + return cleared ? cleared : -EFAULT; > > Probably nobody really cares, but currently doing > > read(fd, &unmapped_page - 5, 123); > > returns 5, and those five bytes do get cleared; if I'm reading the above > right you'd return -EFAULT for that case. > > > > + cleared += chunk; > > + count -= chunk; > > + > > + if (signal_pending(current)) > > + return cleared ? cleared : -ERESTARTSYS; > > I can't see how we can get here without 'cleared' being positive, so > this can just be 'return cleared' (and if you fix the above EFAULT case > to more accurately track how much got cleared, there's probably no > longer any code to be symmetric with anyway). Yeah, I'll fix these up and resend.