linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] seq_file: add seq_read_iter
Date: Tue, 10 Nov 2020 23:20:28 +0000	[thread overview]
Message-ID: <20201110232028.GX3576660@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20201110213511.GW3576660@ZenIV.linux.org.uk>

On Tue, Nov 10, 2020 at 09:35:11PM +0000, Al Viro wrote:
> On Tue, Nov 10, 2020 at 09:32:53PM +0000, Al Viro wrote:
> 
> > AFAICS, not all callers want that semantics, but I think it's worth
> > a new primitive.  I'm not saying it should be a prereq for your
> > series, but either that or an explicit iov_iter_revert() is needed.
> 
> Seeing that it already went into mainline, it needs a followup fix.
> And since it's not -stable fodder (AFAICS), I'd rather go with
> adding a new primitive...

Any objections to the following?

Fix seq_read_iter() behaviour on full pipe

generic_file_splice_read() will purge what we'd left in pipe in case
of error; it will *not* do so in case of short write, so we must make
sure that reported amount of data stored by ->read_iter() matches the
reality.

It's not a rare situation (and we already have it open-coded in at least
one place), so let's introduce a new primitive - copy_to_iter_full().
Similar to copy_from_iter_full(), it returns true if we had been able
to copy everything we'd been asked to and false otherwise.  Iterator
is advanced only on success.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3b20e21604e7..233d790ea301 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -209,7 +209,7 @@ 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)
+		if (!copy_to_iter_full(m->buf + m->from, n, iter))
 			goto Efault;
 		m->count -= n;
 		m->from += n;
@@ -274,7 +274,7 @@ 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)
+	if (!copy_to_iter_full(m->buf, n, iter))
 		goto Efault;
 	copied += n;
 	m->count -= n;
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 72d88566694e..388c05e371ad 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -138,6 +138,18 @@ size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i)
 }
 
 static __always_inline __must_check
+bool copy_to_iter_full(const void *addr, size_t bytes, struct iov_iter *i)
+{
+	if (likely(check_copy_size(addr, bytes, true))) {
+		size_t n = _copy_to_iter(addr, bytes, i);
+		if (likely(n == bytes))
+			return true;
+		iov_iter_revert(i, n);
+	}
+	return false;
+}
+
+static __always_inline __must_check
 size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)
 {
 	if (unlikely(!check_copy_size(addr, bytes, false)))
diff --git a/include/net/udp.h b/include/net/udp.h
index 295d52a73598..91d1a2998a2d 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -390,14 +390,7 @@ static inline bool udp_skb_is_linear(struct sk_buff *skb)
 static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
 				  struct iov_iter *to)
 {
-	int n;
-
-	n = copy_to_iter(skb->data + off, len, to);
-	if (n == len)
-		return 0;
-
-	iov_iter_revert(to, n);
-	return -EFAULT;
+	return copy_to_iter_full(skb->data + off, len, to) ? 0 : -EFAULT;
 }
 
 /*

  reply	other threads:[~2020-11-10 23:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04  8:27 support splice reads on seq_file based procfs files v2 Christoph Hellwig
2020-11-04  8:27 ` [PATCH 1/6] seq_file: add seq_read_iter Christoph Hellwig
2020-11-10 21:32   ` Al Viro
2020-11-10 21:35     ` Al Viro
2020-11-10 23:20       ` Al Viro [this message]
2020-11-11  7:55         ` Christoph Hellwig
2020-11-11 17:54         ` Linus Torvalds
2020-11-11 21:52           ` Al Viro
2020-11-11 22:21             ` Al Viro
2020-11-11 22:27               ` Linus Torvalds
2020-11-11 23:00                 ` Al Viro
2020-11-13 23:54               ` Nathan Chancellor
2020-11-14  1:17                 ` Al Viro
2020-11-14  3:01                   ` Nathan Chancellor
2020-11-14  3:54                     ` Al Viro
2020-11-14  4:14                       ` Nathan Chancellor
2020-11-14  5:50                         ` Al Viro
2020-11-14  6:19                           ` Nathan Chancellor
2020-11-14  7:00                             ` Al Viro
2020-11-14 20:50                               ` Al Viro
2020-11-15 15:53                                 ` Al Viro
2020-11-15 16:56                                   ` Linus Torvalds
2020-11-15 21:41                                   ` Nathan Chancellor
2020-11-15 23:38                                     ` Al Viro
2020-11-15 23:51                                       ` Nathan Chancellor
2020-11-16  0:25                                         ` Al Viro
2020-11-16  0:34                                           ` Nathan Chancellor
2020-11-16  3:29                                             ` Al Viro
2020-11-27 16:29                                               ` Christoph Hellwig
2020-12-08 16:35                                                 ` Christoph Hellwig
2020-12-08 18:34                                                   ` Linus Torvalds
2020-12-08 19:49                                                     ` Al Viro
2020-12-08 20:25                                                       ` Linus Torvalds
2020-12-08 20:53                                                         ` Al Viro
2020-12-08 21:01                                                           ` Linus Torvalds
2020-12-08 19:49                                                     ` Greg KH
2020-11-14 21:44                 ` Al Viro
2020-11-04  8:27 ` [PATCH 2/6] proc: wire up generic_file_splice_read for iter ops Christoph Hellwig
2020-11-04  8:27 ` [PATCH 3/6] proc/cpuinfo: switch to ->read_iter Christoph Hellwig
2020-11-04  8:27 ` [PATCH 4/6] proc/stat: " Christoph Hellwig
2020-11-04  8:27 ` [PATCH 5/6] proc "single files": " Christoph Hellwig
2020-11-04  8:27 ` [PATCH 6/6] proc "seq " Christoph Hellwig
2020-11-04 17:53 ` support splice reads on seq_file based procfs files v2 Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201110232028.GX3576660@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=adobriyan@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).