Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: "Jiri Slaby" <jirislaby@kernel.org>,
	"Łukasz Bartosik" <ukaszb@chromium.org>,
	"Mathias Nyman" <mathias.nyman@intel.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] xhci: dbgtty: fix device unregister
Date: Mon, 24 Nov 2025 09:48:52 +0200	[thread overview]
Message-ID: <6171754f-1b84-47e0-a4da-0d045ea7546e@linux.intel.com> (raw)
In-Reply-To: <2f05eedd-f152-4a4a-bf6c-09ca1ab7da40@kernel.org>

On 11/24/25 08:42, Jiri Slaby wrote:
> Hmm, CCing TTY MAINTAINERS entry would not hurt.
> 
> On 19. 11. 25, 22:29, Łukasz Bartosik wrote:
>> From: Łukasz Bartosik <ukaszb@chromium.org>
>>
>> When DbC is disconnected then xhci_dbc_tty_unregister_device()
>> is called. However if there is any user space process blocked
>> on write to DbC terminal device then it will never be signalled
>> and thus stay blocked indifinitely.
> 
> indefinitely
> 
>> This fix adds a tty_vhangup() call in xhci_dbc_tty_unregister_device().
>> The tty_vhangup() wakes up any blocked writers and causes subsequent
>> write attempts to DbC terminal device to fail.
>>
>> Cc: stable@vger.kernel.org
>> Fixes: dfba2174dc42 ("usb: xhci: Add DbC support in xHCI driver")
>> Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
>> ---
>> Changes in v2:
>> - Replaced tty_hangup() with tty_vhangup()
> 
> Why exactly?

I recommended using tty_vhangup(), well actually tty_port_tty_vhangup() to solve
issue '2' you pointed out.
To me it looks like tty_vhangup() is synchronous so it won't schedule hangup work
and should be safe to call right before we destroy the port.

> 
>> --- a/drivers/usb/host/xhci-dbgtty.c
>> +++ b/drivers/usb/host/xhci-dbgtty.c
>> @@ -535,6 +535,12 @@ static void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
>>       if (!port->registered)
>>           return;
>> +    /*
>> +     * Hang up the TTY. This wakes up any blocked
>> +     * writers and causes subsequent writes to fail.
>> +     */
>> +    tty_vhangup(port->port.tty);
> 
> This is wrong IMO:
> 1) what if there is no tty currently open? Ie. tty is NULL.

v1 had the NULL check, I stated that tty_port_tty_vhangup() does the check for us
so no need for it here.

https://lore.kernel.org/linux-usb/d25feb0d-2ede-4722-a499-095139870c96@linux.intel.com/

looks like v2 removed the check but used tty_vhangup() instead of
tty_port_tty_vhangup()

> 2) you schedule a tty hangup work and destroy the port right after:
>>       tty_unregister_device(dbc_tty_driver, port->minor);
>>       xhci_dbc_tty_exit_port(port);
>>       port->registered = false;
> You should to elaborate how this is supposed to work?

Does tty_port_tty_vhangup() work here? it
1. checks if tty is NULL
2. is synchronous and should be safe to call before tty_unregister_device()

tty internals are still a bit of mystery to me

Thanks
Mathias


  reply	other threads:[~2025-11-24  7:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-19 21:29 [PATCH v2] xhci: dbgtty: fix device unregister Łukasz Bartosik
2025-11-24  6:42 ` Jiri Slaby
2025-11-24  7:48   ` Mathias Nyman [this message]
2025-11-24  9:11     ` Jiri Slaby
2025-11-25  7:53       ` Łukasz Bartosik
2025-11-25  8:00         ` Greg Kroah-Hartman
2025-11-25 14:39           ` Łukasz Bartosik
2025-11-26  5:39             ` Jiri Slaby
2025-11-26  9:53               ` Łukasz Bartosik

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=6171754f-1b84-47e0-a4da-0d045ea7546e@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=ukaszb@chromium.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