linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [question] Is it possible to remove an active port (without shutdown)?
@ 2021-06-11  9:33 Saubhik Mukherjee
  2021-06-11  9:47 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Saubhik Mukherjee @ 2021-06-11  9:33 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-serial, ldv-project, andrianov

Consider the following events involving drivers/tty/serial/owl-uart.c:

Suppose the driver is registered, and the owl_uart_probe() was called.
Then uart_startup() can be called in serial core. This calls
owl_uart_startup() which registers the interrupt handler owl_uart_irq.

Now suppose uart_remove_one_port() in serial core is called. This
detaches port from the core. This calls owl_uart_release_port(port).
This writes NULL to port->membase after iounmap of port->membase from
port->dev.

During this point, an interrupt is triggered and the interrupt callback
owl_uart_irq() is called (parallel with uart_remove_one_port()). This
tries to read port->membase to send or receive chars (with spinlock on
port->lock). This introduces a race condition on port->membase.

QUESTION: Is it possible to remove an active port (without shutdown)?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [question] Is it possible to remove an active port (without shutdown)?
  2021-06-11  9:33 [question] Is it possible to remove an active port (without shutdown)? Saubhik Mukherjee
@ 2021-06-11  9:47 ` Greg KH
  2021-06-14  9:57   ` Saubhik Mukherjee
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2021-06-11  9:47 UTC (permalink / raw)
  To: Saubhik Mukherjee; +Cc: jirislaby, linux-serial, ldv-project, andrianov

On Fri, Jun 11, 2021 at 03:03:42PM +0530, Saubhik Mukherjee wrote:
> Consider the following events involving drivers/tty/serial/owl-uart.c:
> 
> Suppose the driver is registered, and the owl_uart_probe() was called.
> Then uart_startup() can be called in serial core. This calls
> owl_uart_startup() which registers the interrupt handler owl_uart_irq.
> 
> Now suppose uart_remove_one_port() in serial core is called. This
> detaches port from the core. This calls owl_uart_release_port(port).
> This writes NULL to port->membase after iounmap of port->membase from
> port->dev.
> 
> During this point, an interrupt is triggered and the interrupt callback
> owl_uart_irq() is called (parallel with uart_remove_one_port()). This
> tries to read port->membase to send or receive chars (with spinlock on
> port->lock). This introduces a race condition on port->membase.
> 
> QUESTION: Is it possible to remove an active port (without shutdown)?

You can remove it, if the driver is set up to do so properly.  Odds are
the owl-uart code is not written to expect that to ever happen.

How are you "removing" an active port?  What triggers this action?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [question] Is it possible to remove an active port (without shutdown)?
  2021-06-11  9:47 ` Greg KH
@ 2021-06-14  9:57   ` Saubhik Mukherjee
  2021-06-14 10:01     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Saubhik Mukherjee @ 2021-06-14  9:57 UTC (permalink / raw)
  To: Greg KH; +Cc: jirislaby, linux-serial, ldv-project, andrianov

On 6/11/21 3:17 PM, Greg KH wrote:
> On Fri, Jun 11, 2021 at 03:03:42PM +0530, Saubhik Mukherjee wrote:
>> Consider the following events involving drivers/tty/serial/owl-uart.c:
>>
>> Suppose the driver is registered, and the owl_uart_probe() was called.
>> Then uart_startup() can be called in serial core. This calls
>> owl_uart_startup() which registers the interrupt handler owl_uart_irq.
>>
>> Now suppose uart_remove_one_port() in serial core is called. This
>> detaches port from the core. This calls owl_uart_release_port(port).
>> This writes NULL to port->membase after iounmap of port->membase from
>> port->dev.
>>
>> During this point, an interrupt is triggered and the interrupt callback
>> owl_uart_irq() is called (parallel with uart_remove_one_port()). This
>> tries to read port->membase to send or receive chars (with spinlock on
>> port->lock). This introduces a race condition on port->membase.
>>
>> QUESTION: Is it possible to remove an active port (without shutdown)?
> 
> You can remove it, if the driver is set up to do so properly.  Odds are
> the owl-uart code is not written to expect that to ever happen.
> 
> How are you "removing" an active port?  What triggers this action?

Thank you for the reply.

The active port is removed (without shutdown) due to the platform 
callback owl_uart_remove() during de-registration of the platform 
driver. The race condition described is due to the interrupt handler, 
owl_uart_irq(), executing in parallel.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [question] Is it possible to remove an active port (without shutdown)?
  2021-06-14  9:57   ` Saubhik Mukherjee
@ 2021-06-14 10:01     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-06-14 10:01 UTC (permalink / raw)
  To: Saubhik Mukherjee; +Cc: jirislaby, linux-serial, ldv-project, andrianov

On Mon, Jun 14, 2021 at 03:27:43PM +0530, Saubhik Mukherjee wrote:
> On 6/11/21 3:17 PM, Greg KH wrote:
> > On Fri, Jun 11, 2021 at 03:03:42PM +0530, Saubhik Mukherjee wrote:
> > > Consider the following events involving drivers/tty/serial/owl-uart.c:
> > > 
> > > Suppose the driver is registered, and the owl_uart_probe() was called.
> > > Then uart_startup() can be called in serial core. This calls
> > > owl_uart_startup() which registers the interrupt handler owl_uart_irq.
> > > 
> > > Now suppose uart_remove_one_port() in serial core is called. This
> > > detaches port from the core. This calls owl_uart_release_port(port).
> > > This writes NULL to port->membase after iounmap of port->membase from
> > > port->dev.
> > > 
> > > During this point, an interrupt is triggered and the interrupt callback
> > > owl_uart_irq() is called (parallel with uart_remove_one_port()). This
> > > tries to read port->membase to send or receive chars (with spinlock on
> > > port->lock). This introduces a race condition on port->membase.
> > > 
> > > QUESTION: Is it possible to remove an active port (without shutdown)?
> > 
> > You can remove it, if the driver is set up to do so properly.  Odds are
> > the owl-uart code is not written to expect that to ever happen.
> > 
> > How are you "removing" an active port?  What triggers this action?
> 
> Thank you for the reply.
> 
> The active port is removed (without shutdown) due to the platform callback
> owl_uart_remove() during de-registration of the platform driver. The race
> condition described is due to the interrupt handler, owl_uart_irq(),
> executing in parallel.

Then the remove function needs to disable the irq and make sure the
handler is finished in order to properly be able to remove the platform
driver.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-14 10:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11  9:33 [question] Is it possible to remove an active port (without shutdown)? Saubhik Mukherjee
2021-06-11  9:47 ` Greg KH
2021-06-14  9:57   ` Saubhik Mukherjee
2021-06-14 10:01     ` Greg KH

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).