Skip to content

Commit

Permalink
Merge tag 'tty-4.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/gregkh/tty

Pull tty fixes from Greg KH:
 "Here are three small HVC tty driver fixes to resolve a reported
  regression from 4.19-rc1.

  All of these have been in linux-next for a while with no reported
  issues"

* tag 'tty-4.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty:
  tty: hvc: hvc_write() fix break condition
  tty: hvc: hvc_poll() fix read loop batching
  tty: hvc: hvc_poll() fix read loop hang
  • Loading branch information
torvalds committed Sep 14, 2018
2 parents 45d9ab8 + 7f2bf78 commit c284cf0
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions drivers/tty/hvc/hvc_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
return -EIO;

while (count > 0) {
int ret = 0;

spin_lock_irqsave(&hp->lock, flags);

rsize = hp->outbuf_size - hp->n_outbuf;
Expand All @@ -537,10 +539,13 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
}

if (hp->n_outbuf > 0)
hvc_push(hp);
ret = hvc_push(hp);

spin_unlock_irqrestore(&hp->lock, flags);

if (!ret)
break;

if (count) {
if (hp->n_outbuf > 0)
hvc_flush(hp);
Expand Down Expand Up @@ -623,6 +628,15 @@ static int hvc_chars_in_buffer(struct tty_struct *tty)
#define MAX_TIMEOUT (2000)
static u32 timeout = MIN_TIMEOUT;

/*
* Maximum number of bytes to get from the console driver if hvc_poll is
* called from driver (and can't sleep). Any more than this and we break
* and start polling with khvcd. This value was derived from from an OpenBMC
* console with the OPAL driver that results in about 0.25ms interrupts off
* latency.
*/
#define HVC_ATOMIC_READ_MAX 128

#define HVC_POLL_READ 0x00000001
#define HVC_POLL_WRITE 0x00000002

Expand Down Expand Up @@ -669,8 +683,8 @@ static int __hvc_poll(struct hvc_struct *hp, bool may_sleep)
if (!hp->irq_requested)
poll_mask |= HVC_POLL_READ;

read_again:
/* Read data if any */

count = tty_buffer_request_room(&hp->port, N_INBUF);

/* If flip is full, just reschedule a later read */
Expand Down Expand Up @@ -717,9 +731,23 @@ static int __hvc_poll(struct hvc_struct *hp, bool may_sleep)
#endif /* CONFIG_MAGIC_SYSRQ */
tty_insert_flip_char(&hp->port, buf[i], 0);
}
if (n == count)
poll_mask |= HVC_POLL_READ;
read_total = n;
read_total += n;

if (may_sleep) {
/* Keep going until the flip is full */
spin_unlock_irqrestore(&hp->lock, flags);
cond_resched();
spin_lock_irqsave(&hp->lock, flags);
goto read_again;
} else if (read_total < HVC_ATOMIC_READ_MAX) {
/* Break and defer if it's a large read in atomic */
goto read_again;
}

/*
* Latency break, schedule another poll immediately.
*/
poll_mask |= HVC_POLL_READ;

out:
/* Wakeup write queue if necessary */
Expand Down

0 comments on commit c284cf0

Please sign in to comment.