[SRU][Groovy][PATCH 1/2] UBUNTU: SAUCE: Revert "tty: implement read_iter"

Kleber Sacilotto de Souza kleber.souza at canonical.com
Wed Apr 21 17:16:59 UTC 2021


BugLink: https://bugs.launchpad.net/bugs/1925290

This reverts commit b7bfa1af145a6aa3868894a4be82f7b2034c564a (Upstream
commit dd78b0c483e33225e0e0782b0ed887129b00f956).

This commit introduced a regression on the tty code caught by hangup01
testcase from ltp pty tests, so revert it until a follow-up fix is not
found.

Signed-off-by: Kleber Sacilotto de Souza <kleber.souza at canonical.com>
---
 drivers/tty/tty_io.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 895763337afc..c2b19e10423b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -142,7 +142,7 @@ LIST_HEAD(tty_drivers);			/* linked list of tty drivers */
 /* Mutex to protect creating and releasing a tty */
 DEFINE_MUTEX(tty_mutex);
 
-static ssize_t tty_read(struct kiocb *, struct iov_iter *);
+static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
 static ssize_t tty_write(struct kiocb *, struct iov_iter *);
 static __poll_t tty_poll(struct file *, poll_table *);
 static int tty_open(struct inode *, struct file *);
@@ -473,9 +473,8 @@ static void tty_show_fdinfo(struct seq_file *m, struct file *file)
 
 static const struct file_operations tty_fops = {
 	.llseek		= no_llseek,
-	.read_iter	= tty_read,
+	.read		= tty_read,
 	.write_iter	= tty_write,
-	.splice_read	= generic_file_splice_read,
 	.splice_write	= iter_file_splice_write,
 	.poll		= tty_poll,
 	.unlocked_ioctl	= tty_ioctl,
@@ -488,9 +487,8 @@ static const struct file_operations tty_fops = {
 
 static const struct file_operations console_fops = {
 	.llseek		= no_llseek,
-	.read_iter	= tty_read,
+	.read		= tty_read,
 	.write_iter	= redirected_tty_write,
-	.splice_read	= generic_file_splice_read,
 	.splice_write	= iter_file_splice_write,
 	.poll		= tty_poll,
 	.unlocked_ioctl	= tty_ioctl,
@@ -843,17 +841,16 @@ static void tty_update_time(struct timespec64 *time)
  * data or clears the cookie. The cookie may be something that the
  * ldisc maintains state for and needs to free.
  */
-static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
-		struct file *file, struct iov_iter *to)
+static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, struct file *file,
+		char __user *buf, size_t count)
 {
 	int retval = 0;
 	void *cookie = NULL;
 	unsigned long offset = 0;
 	char kernel_buf[64];
-	size_t count = iov_iter_count(to);
 
 	do {
-		int size, copied;
+		int size, uncopied;
 
 		size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count;
 		size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset);
@@ -869,9 +866,10 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
 			return size;
 		}
 
-		copied = copy_to_iter(kernel_buf, size, to);
-		offset += copied;
-		count -= copied;
+		uncopied = copy_to_user(buf+offset, kernel_buf, size);
+		size -= uncopied;
+		offset += size;
+		count -= size;
 
 		/*
 		 * If the user copy failed, we still need to do another ->read()
@@ -879,7 +877,7 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
 		 *
 		 * But make sure size is zeroed.
 		 */
-		if (unlikely(copied != size)) {
+		if (unlikely(uncopied)) {
 			count = 0;
 			retval = -EFAULT;
 		}
@@ -906,10 +904,10 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
  *	read calls may be outstanding in parallel.
  */
 
-static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to)
+static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
+			loff_t *ppos)
 {
 	int i;
-	struct file *file = iocb->ki_filp;
 	struct inode *inode = file_inode(file);
 	struct tty_struct *tty = file_tty(file);
 	struct tty_ldisc *ld;
@@ -922,9 +920,11 @@ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to)
 	/* We want to wait for the line discipline to sort out in this
 	   situation */
 	ld = tty_ldisc_ref_wait(tty);
+	if (!ld)
+		return hung_up_tty_read(file, buf, count, ppos);
 	i = -EIO;
-	if (ld && ld->ops->read)
-		i = iterate_tty_read(ld, tty, file, to);
+	if (ld->ops->read)
+		i = iterate_tty_read(ld, tty, file, buf, count);
 	tty_ldisc_deref(ld);
 
 	if (i > 0)
@@ -2945,7 +2945,7 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
 
 static int this_tty(const void *t, struct file *file, unsigned fd)
 {
-	if (likely(file->f_op->read_iter != tty_read))
+	if (likely(file->f_op->read != tty_read))
 		return 0;
 	return file_tty(file) != t ? 0 : fd + 1;
 }
-- 
2.27.0




More information about the kernel-team mailing list