From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF2C7C388F9 for ; Wed, 11 Nov 2020 21:52:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67F3D20825 for ; Wed, 11 Nov 2020 21:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbgKKVwe (ORCPT ); Wed, 11 Nov 2020 16:52:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgKKVwc (ORCPT ); Wed, 11 Nov 2020 16:52:32 -0500 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A362C0613D4; Wed, 11 Nov 2020 13:52:32 -0800 (PST) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcy2O-003qBZ-LL; Wed, 11 Nov 2020 21:52:20 +0000 Date: Wed, 11 Nov 2020 21:52:20 +0000 From: Al Viro To: Linus Torvalds Cc: Christoph Hellwig , Greg KH , Alexey Dobriyan , linux-fsdevel , Linux Kernel Mailing List Subject: Re: [PATCH 1/6] seq_file: add seq_read_iter Message-ID: <20201111215220.GA3576660@ZenIV.linux.org.uk> References: <20201104082738.1054792-1-hch@lst.de> <20201104082738.1054792-2-hch@lst.de> <20201110213253.GV3576660@ZenIV.linux.org.uk> <20201110213511.GW3576660@ZenIV.linux.org.uk> <20201110232028.GX3576660@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 11, 2020 at 09:54:12AM -0800, Linus Torvalds wrote: > On Tue, Nov 10, 2020 at 3:20 PM Al Viro wrote: > > > > Any objections to the following? > > Well, I don't _object_, but I find it ugly. > > And I think both the old and the "fixed" code is wrong when an EFAULT > happens in the middle. > > Yes, we can just return EFAULT. But for read() and write() we really > try to do the proper partial returns in other places, why not here? > > IOW, why isn't the proper fix just something like this: > > diff --git a/fs/seq_file.c b/fs/seq_file.c > index 3b20e21604e7..ecc6909b71f5 100644 > --- a/fs/seq_file.c > +++ b/fs/seq_file.c > @@ -209,7 +209,8 @@ 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) > + n = copy_to_iter(m->buf + m->from, n, iter); > + if (!n) > goto Efault; > m->count -= n; > m->from += n; > > which should get the "efault in the middle" case roughly right (ie the > usual "exact byte alignment and page crosser" caveats apply). Look at the loop after that one, specifically the "it doesn't fit, allocate a bigger one" part: kvfree(m->buf); m->count = 0; m->buf = seq_buf_alloc(m->size <<= 1); It really depends upon having m->buf empty at the beginning of the loop. Your variant will lose the data, unless we copy the "old" part of buffer (from before the ->show()) into the larger one. That can be done, but I would rather go with n = copy_to_iter(m->buf + m->from, m->count, iter); m->count -= n; m->from += n; copied += n; if (!size) goto Done; if (m->count) goto Efault; if we do it that way. Let me see if I can cook something reasonable along those lines...