Is it possible to remove an active port (without shutdown)?
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)?
Greg KH
maintainerQuoted 11 lines · Saubhik Mukherjee
Consider the following events involving
drivers/tty/serial/owl-uart.c:Suppose the driver is registered, and the
owl_uart_probe()was called. Thenuart_startup()can be called in serial core. This callsowl_uart_startup()which registers the interrupt handlerowl_uart_irq.Now suppose
uart_remove_one_port()in serial core is called. This detaches port from the core. This callsowl_uart_release_port(port). This writes NULL toport->membaseafter iounmap ofport->membasefromport->dev.
Quoted 6 lines
During this point, an interrupt is triggered and the interrupt callback
owl_uart_irq()is called (parallel withuart_remove_one_port()). This tries to readport->membaseto send or receive chars (with spinlock onport->lock). This introduces a race condition onport->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
Quoted 17 lines · Greg KH
Quoted 16 lines · Saubhik Mukherjee
Consider the following events involving
drivers/tty/serial/owl-uart.c:Suppose the driver is registered, and the
owl_uart_probe()was called. Thenuart_startup()can be called in serial core. This callsowl_uart_startup()which registers the interrupt handlerowl_uart_irq.Now suppose
uart_remove_one_port()in serial core is called. This detaches port from the core. This callsowl_uart_release_port(port). This writes NULL toport->membaseafter iounmap ofport->membasefromport->dev.During this point, an interrupt is triggered and the interrupt callback
owl_uart_irq()is called (parallel withuart_remove_one_port()). This tries to readport->membaseto send or receive chars (with spinlock onport->lock). This introduces a race condition onport->membase.
Quoted 6 lines
Quoted 1 line
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.
Greg KH
maintainerQuoted 23 lines · Saubhik Mukherjee
Quoted 22 lines · Greg KH
Quoted 11 lines · Saubhik Mukherjee
Consider the following events involving
drivers/tty/serial/owl-uart.c:Suppose the driver is registered, and the
owl_uart_probe()was called. Thenuart_startup()can be called in serial core. This callsowl_uart_startup()which registers the interrupt handlerowl_uart_irq.Now suppose
uart_remove_one_port()in serial core is called. This detaches port from the core. This callsowl_uart_release_port(port). This writes NULL toport->membaseafter iounmap ofport->membasefromport->dev.Quoted 6 lines
During this point, an interrupt is triggered and the interrupt callback
owl_uart_irq()is called (parallel withuart_remove_one_port()). This tries to readport->membaseto send or receive chars (with spinlock onport->lock). This introduces a race condition onport->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.
Quoted 8 lines
Quoted 1 line
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