2024-04-11 13:50:55

by li.hao40

[permalink] [raw]
Subject: [PATCH] tty: hvc: wakeup hvc console immediately when needed

From: Li Hao <[email protected]>

Cancel the do_wakeup flag in hvc_struct, and change it to immediately
wake up tty when hp->n_outbuf is 0 in hvc_push().

When we receive a key input character, the interrupt handling function
hvc_handle_interrupt() will be executed, and the echo thread
flush_to_ldisc() will be added to the queue.

If the user is currently using tcsetattr(), a hang may occur. tcsetattr()
enters kernel and waits for hp->n_outbuf to become 0 via
tty_wait_until_sent(). If the echo thread finishes executing before
reaching tty_wait_until_sent (for example, put_chars() takes too long),
it will cause while meeting the wakeup condition (hp->do_wakeup = 1),
tty_wait_until_sent() cannot be woken up (missed the tty_wakeup() of
this round&apos;s tty_poll). Unless the next key input character comes,
hvc_poll will be executed, and tty_wakeup() will be performed through
the do_wakeup flag.

Signed-off-by: Li Hao
---
drivers/tty/hvc/hvc_console.c | 12 +++++-------
drivers/tty/hvc/hvc_console.h | 1 -
2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index cdcc64ea2554..4f06aead690a 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -476,11 +476,13 @@ static void hvc_hangup(struct tty_struct *tty)
static int hvc_push(struct hvc_struct *hp)
{
int n;
+ struct tty_struct *tty;

n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
+ tty = tty_port_tty_get(&hp->port);
if (n <= 0) {
if (n == 0 || n == -EAGAIN) {
- hp->do_wakeup = 1;
+ tty_wakeup(tty);
return 0;
}
/* throw away output on error; this happens when
@@ -491,7 +493,7 @@ static int hvc_push(struct hvc_struct *hp)
if (hp->n_outbuf > 0)
memmove(hp->outbuf, hp->outbuf + n, hp->n_outbuf);
else
- hp->do_wakeup = 1;
+ tty_wakeup(tty);

return n;
}
@@ -739,11 +741,7 @@ static int __hvc_poll(struct hvc_struct *hp, bool may_sleep)
poll_mask |= HVC_POLL_READ;

out:
- /* Wakeup write queue if necessary */
- if (hp->do_wakeup) {
- hp->do_wakeup = 0;
- tty_wakeup(tty);
- }
+ /* Wakeup in hvc_push */
bail:
spin_unlock_irqrestore(&hp->lock, flags);

diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index 18d005814e4b..164ae2c82b98 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -36,7 +36,6 @@ struct hvc_struct {
struct tty_port port;
spinlock_t lock;
int index;
- int do_wakeup;
char *outbuf;
int outbuf_size;
int n_outbuf;
--
2.25.1


2024-04-11 14:14:58

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] tty: hvc: wakeup hvc console immediately when needed

On Thu, Apr 11, 2024 at 09:50:17PM +0800, [email protected] wrote:
> From: Li Hao <[email protected]>
>
> Cancel the do_wakeup flag in hvc_struct, and change it to immediately
> wake up tty when hp->n_outbuf is 0 in hvc_push().
>
> When we receive a key input character, the interrupt handling function
> hvc_handle_interrupt() will be executed, and the echo thread
> flush_to_ldisc() will be added to the queue.
>
> If the user is currently using tcsetattr(), a hang may occur. tcsetattr()
> enters kernel and waits for hp->n_outbuf to become 0 via
> tty_wait_until_sent(). If the echo thread finishes executing before
> reaching tty_wait_until_sent (for example, put_chars() takes too long),
> it will cause while meeting the wakeup condition (hp->do_wakeup = 1),
> tty_wait_until_sent() cannot be woken up (missed the tty_wakeup() of
> this round&apos;s tty_poll). Unless the next key input character comes,
> hvc_poll will be executed, and tty_wakeup() will be performed through
> the do_wakeup flag.
>
> Signed-off-by: Li Hao

Did checkpatch say this was ok?


2024-04-12 03:29:00

by li.hao40

[permalink] [raw]
Subject: Re: [PATCH] tty: hvc: wakeup hvc console immediately when needed

sorry,the patch seems to be corrupt,I will resubmit the patch





------------------Original------------------
From: gregkh <[email protected]>
To: li hao10307857;
Cc: jirislaby <[email protected]>;linuxppc-dev <[email protected]>;linux-kernel <[email protected]>;
Date: 2024/04/11 22:03
Subject: Re: [PATCH] tty: hvc: wakeup hvc console immediately when needed
On Thu, Apr 11, 2024 at 09:50:17PM +0800, [email protected] wrote:
> From: Li Hao <[email protected]>
>
> Cancel the do_wakeup flag in hvc_struct, and change it to immediately
> wake up tty when hp->n_outbuf is 0 in hvc_push().
>
> When we receive a key input character, the interrupt handling function
> hvc_handle_interrupt() will be executed, and the echo thread
> flush_to_ldisc() will be added to the queue.
>
> If the user is currently using tcsetattr(), a hang may occur. tcsetattr()
> enters kernel and waits for hp->n_outbuf to become 0 via
> tty_wait_until_sent(). If the echo thread finishes executing before
> reaching tty_wait_until_sent (for example, put_chars() takes too long),
> it will cause while meeting the wakeup condition (hp->do_wakeup = 1),
> tty_wait_until_sent() cannot be woken up (missed the tty_wakeup() of
> this round&apos;s tty_poll). Unless the next key input character comes,
> hvc_poll will be executed, and tty_wakeup() will be performed through
> the do_wakeup flag.
>
> Signed-off-by: Li Hao
Did checkpatch say this was ok?