Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2730960pxb; Sun, 15 Nov 2020 16:01:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyF7Q8ihZFwjw6nRkyRZNc/LYNBDtqmbTGq0pRAa3oSaNkye4Y6rkzlfzu65/1LuoFh7/iq X-Received: by 2002:a50:99c3:: with SMTP id n3mr13704058edb.213.1605484857221; Sun, 15 Nov 2020 16:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605484857; cv=none; d=google.com; s=arc-20160816; b=cpCkA3oqCpl9BZvnhMxVFZ7ZrTYeudURryS0BsPM0yDIhD4IbjsiF2WQ8ZOWxN+WVR II9X6KwL013dzmCakbjSMrnW4Y0x1lQJgnLn91AzrXOX0b+ljqb3rrABBiQhkQWh6atL BliyWjQy0IZMgGtsHSOVf6cNbGFbbTY85X1qrGbFkk5FuK4YsXBCxuw4GJHg1eFG4DVd zcv6ysw0Gw8FWLd24u0AOwWRr5Fy16hQm/UU6eAiTQKZfD3flNbJj5nieMs0Pf59IE66 i0lhxQEa1bMQgORmKRMu3zc2S90k/jZ/dNbx0JVsn1vuClZcNBpC01Ej2GzEDfIzNmno o2HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=01m0cOcFI71mVs+9lBinrDWRRm8biXQ0bPXJ4x3qNNc=; b=Vnq03ODchjLKQM4jdnED9FmPTXq09j4bYT4zg/av8UoWRWLge3a3AYRnl0xM1vo1U3 NxYsHGBpaNct5CJctNBLOyNRVZCkyUBYOheb9Fp8TAdCYIboZ2lD5DN6gCp96ZKapV+E AvmRw+4in6yYrAYnZlXFDBbUr54FdiTF/pwURyhj2OWaYGBBIWAMLonwmmiTCcFGX6a9 SIwrCwITQMYDYU8obWR31yR03jPO3LIFkwzofbakawkLmkNeMuQuVguYZzBL+Ps7esBq Z2/9/9G8vMvZ4CXhInV+t4kGx69GYjnZkCD4MMB82NIFLjDPjvbPsr9Ko3C8Moy6sKNo KqbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Mp9zLGQi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s12si10079382ejd.753.2020.11.15.16.00.33; Sun, 15 Nov 2020 16:00:57 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=Mp9zLGQi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728119AbgKOXv4 (ORCPT + 99 others); Sun, 15 Nov 2020 18:51:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728086AbgKOXvz (ORCPT ); Sun, 15 Nov 2020 18:51:55 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B8CC0613CF; Sun, 15 Nov 2020 15:51:55 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id p68so824018pga.6; Sun, 15 Nov 2020 15:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=01m0cOcFI71mVs+9lBinrDWRRm8biXQ0bPXJ4x3qNNc=; b=Mp9zLGQiX5AE3ACYtNkAKEnscwvdI9V81xyEQzS9jB7EZIHJqccHj/Zz4lJWC/zhDr O4652kVtn/5HAGomJsX0Qroot6FHA4ohPo8gzDA4nXg1BsU5dCF0S4i6rZPUL1cvzNzu Hflh7W0RCthNfrYxWOfHt0jdwyafgSHyu26zYWTegFtT22/KXMlPyGjVLdsDeN172s/X EvsE2GRnJcfeSDpkfyhYoEw1VWx/gIvJfeReB0RxJqMtMqRl1tCrev2sikdacYHyhUar rDkYbRm20HyzOrMM29aSOciGKbCKPkU/nxQiQKUVgPxya0zIAuRJUSNslinwWn1BZ83j VJ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=01m0cOcFI71mVs+9lBinrDWRRm8biXQ0bPXJ4x3qNNc=; b=jCx4mxrNNQIuWSNke4X4ZORxmmgH2tBSIknUnqABbz7DaZDk0ixqS6fZeLpfMq+geO KXgQOmCXNxCGfhnHCt3XsCq7fYv6s4nP5eHB9uxgGoYXfknAePFNYbbSPLO/ri50xPfe 9WGqPfl/OOFystlkM9fAOfOcQRYJLkybNawxMcwWi17GBHNSS8764fXFGOWcie/zVyrc joOSzpYWu5NkANAly7yeltzAQ+szvCBfJIS1easGkeukC8QIQxQoOrUFTBx2YG1+CUYM crHnMGizz01P/eFjSsyL40CW7F5bg/0PdTOORIHXoU06GTnwUDKN7tJqxJmSEv0ktpzh 0L0g== X-Gm-Message-State: AOAM530inmkK9ekmc9CW3j4TWq6LwutOmfBIvrq/XrsHu7YVICfGKVTY LonzuBxTL23E9BoQlOJRtKo= X-Received: by 2002:a63:7847:: with SMTP id t68mr11010094pgc.422.1605484314830; Sun, 15 Nov 2020 15:51:54 -0800 (PST) Received: from Ryzen-9-3900X.localdomain (ip68-98-75-144.ph.ph.cox.net. [68.98.75.144]) by smtp.gmail.com with ESMTPSA id r4sm15667311pgs.54.2020.11.15.15.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 15:51:52 -0800 (PST) Date: Sun, 15 Nov 2020 16:51:49 -0700 From: Nathan Chancellor To: Al Viro Cc: Linus Torvalds , Christoph Hellwig , Greg KH , Alexey Dobriyan , linux-fsdevel , Linux Kernel Mailing List , kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, linux-hyperv@vger.kernel.org Subject: Re: [PATCH 1/6] seq_file: add seq_read_iter Message-ID: <20201115235149.GA252@Ryzen-9-3900X.localdomain> References: <20201114030124.GA236@Ryzen-9-3900X.localdomain> <20201114035453.GM3576660@ZenIV.linux.org.uk> <20201114041420.GA231@Ryzen-9-3900X.localdomain> <20201114055048.GN3576660@ZenIV.linux.org.uk> <20201114061934.GA658@Ryzen-9-3900X.localdomain> <20201114070025.GO3576660@ZenIV.linux.org.uk> <20201114205000.GP3576660@ZenIV.linux.org.uk> <20201115155355.GR3576660@ZenIV.linux.org.uk> <20201115214125.GA317@Ryzen-9-3900X.localdomain> <20201115233814.GT3576660@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201115233814.GT3576660@ZenIV.linux.org.uk> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 15, 2020 at 11:38:14PM +0000, Al Viro wrote: > On Sun, Nov 15, 2020 at 02:41:25PM -0700, Nathan Chancellor wrote: > > Hi Al, > > > > Apologies for the delay. > > > > On Sun, Nov 15, 2020 at 03:53:55PM +0000, Al Viro wrote: > > > On Sat, Nov 14, 2020 at 08:50:00PM +0000, Al Viro wrote: > > > > > > OK, I think I understand what's going on. Could you check if > > > reverting the variant in -next and applying the following instead > > > fixes what you are seeing? > > > > The below diff on top of d4d50710a8b46082224376ef119a4dbb75b25c56 does > > not fix my issue unfortunately. > > OK... Now that I have a reproducer[1], I think I've sorted it out. > And yes, it had been too subtle for its own good ;-/ > > [1] I still wonder what the hell in the userland has come up with the > idea of reading through a file with readv(), each time with 2-element > iovec array, the first element covering 0 bytes and the second one - 1024. > AFAICS, nothing is systemd git appears to be _that_ weird... Makes for > a useful testcase, though... > > Anyway, could you test this replacement? Looks good to me on top of d4d50710a8b46082224376ef119a4dbb75b25c56, thanks for quickly looking into this! Tested-by: Nathan Chancellor > diff --git a/fs/seq_file.c b/fs/seq_file.c > index 3b20e21604e7..c0dfe2861b35 100644 > --- a/fs/seq_file.c > +++ b/fs/seq_file.c > @@ -168,12 +168,14 @@ EXPORT_SYMBOL(seq_read); > ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > { > struct seq_file *m = iocb->ki_filp->private_data; > - size_t size = iov_iter_count(iter); > size_t copied = 0; > size_t n; > void *p; > int err = 0; > > + if (!iov_iter_count(iter)) > + return 0; > + > mutex_lock(&m->lock); > > /* > @@ -208,34 +210,32 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > } > /* if not empty - flush it first */ > if (m->count) { > - n = min(m->count, size); > - if (copy_to_iter(m->buf + m->from, n, iter) != n) > - goto Efault; > + n = copy_to_iter(m->buf + m->from, m->count, iter); > m->count -= n; > m->from += n; > - size -= n; > copied += n; > - if (!size) > + if (m->count) // hadn't managed to copy everything > goto Done; > } > - /* we need at least one record in buffer */ > + /* we need at least one non-empty record in the buffer */ > m->from = 0; > p = m->op->start(m, &m->index); > while (1) { > err = PTR_ERR(p); > - if (!p || IS_ERR(p)) > + if (!p || IS_ERR(p)) // EOF or an error > break; > err = m->op->show(m, p); > - if (err < 0) > + if (err < 0) // hard error > break; > - if (unlikely(err)) > + if (unlikely(err)) // ->show() says "skip it" > m->count = 0; > - if (unlikely(!m->count)) { > + if (unlikely(!m->count)) { // empty record > p = m->op->next(m, p, &m->index); > continue; > } > - if (m->count < m->size) > + if (!seq_has_overflowed(m)) // got it > goto Fill; > + // need a bigger buffer > m->op->stop(m, p); > kvfree(m->buf); > m->count = 0; > @@ -244,11 +244,14 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > goto Enomem; > p = m->op->start(m, &m->index); > } > + // EOF or an error > m->op->stop(m, p); > m->count = 0; > goto Done; > Fill: > - /* they want more? let's try to get some more */ > + // one non-empty record is in the buffer; if they want more, > + // try to fit more in, but in any case we need to advance > + // the iterator at least once. > while (1) { > size_t offs = m->count; > loff_t pos = m->index; > @@ -259,11 +262,9 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > m->op->next); > m->index++; > } > - if (!p || IS_ERR(p)) { > - err = PTR_ERR(p); > + if (!p || IS_ERR(p)) // no next record for us > break; > - } > - if (m->count >= size) > + if (m->count >= iov_iter_count(iter)) > break; > err = m->op->show(m, p); > if (seq_has_overflowed(m) || err) { > @@ -273,16 +274,14 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > } > } > m->op->stop(m, p); > - n = min(m->count, size); > - if (copy_to_iter(m->buf, n, iter) != n) > - goto Efault; > + n = copy_to_iter(m->buf, m->count, iter); > copied += n; > m->count -= n; > m->from = n; > Done: > - if (!copied) > - copied = err; > - else { > + if (unlikely(!copied)) { > + copied = m->count ? -EFAULT : err; > + } else { > iocb->ki_pos += copied; > m->read_pos += copied; > } > @@ -291,9 +290,6 @@ ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter) > Enomem: > err = -ENOMEM; > goto Done; > -Efault: > - err = -EFAULT; > - goto Done; > } > EXPORT_SYMBOL(seq_read_iter); >