Commit 3ef5abd
tty: serial: kgdboc: fix mutex locking order for configure_kgdboc()
Several mutexes are taken while setting up console serial ports. In
particular, the tty_port->mutex and @console_mutex are taken:
serial_pnp_probe
serial8250_register_8250_port
uart_add_one_port (locks tty_port->mutex)
uart_configure_port
register_console (locks @console_mutex)
In order to synchronize kgdb's tty_find_polling_driver() with
register_console(), commit 6193bc9 ("tty: serial: kgdboc:
synchronize tty_find_polling_driver() and register_console()") takes
the @console_mutex. However, this leads to the following call chain
(with locking):
platform_probe
kgdboc_probe
configure_kgdboc (locks @console_mutex)
tty_find_polling_driver
uart_poll_init (locks tty_port->mutex)
uart_set_options
This is clearly deadlock potential due to the reverse lock ordering.
Since uart_set_options() requires holding @console_mutex in order to
serialize early initialization of the serial-console lock, take the
@console_mutex in uart_poll_init() instead of configure_kgdboc().
Since configure_kgdboc() was using @console_mutex for safe traversal
of the console list, change it to use the SRCU iterator instead.
Add comments to uart_set_options() kerneldoc mentioning that it
requires holding @console_mutex (aka the console_list_lock).
Fixes: 6193bc9 ("tty: serial: kgdboc: synchronize tty_find_polling_driver() and register_console()")
Signed-off-by: John Ogness <[email protected]>
Reviewed-by: Sergey Senozhatsky <[email protected]>
Reviewed-by: Petr Mladek <[email protected]>
[[email protected]: Export console_srcu_read_lock_is_held() to fix build kgdboc as a module.]
Signed-off-by: Petr Mladek <[email protected]>
Link: https://lore.kernel.org/r/[email protected]1 parent 5074ffb commit 3ef5abd
File tree
3 files changed
+11
-15
lines changed- drivers/tty/serial
- kernel/printk
3 files changed
+11
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | 193 | | |
202 | | - | |
203 | | - | |
| 194 | + | |
204 | 195 | | |
205 | | - | |
206 | 196 | | |
207 | 197 | | |
208 | 198 | | |
| |||
211 | 201 | | |
212 | 202 | | |
213 | 203 | | |
214 | | - | |
| 204 | + | |
| 205 | + | |
215 | 206 | | |
216 | 207 | | |
217 | 208 | | |
218 | 209 | | |
219 | 210 | | |
220 | 211 | | |
221 | 212 | | |
| 213 | + | |
222 | 214 | | |
223 | 215 | | |
224 | 216 | | |
225 | | - | |
226 | | - | |
227 | 217 | | |
228 | 218 | | |
229 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2212 | 2212 | | |
2213 | 2213 | | |
2214 | 2214 | | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
2215 | 2218 | | |
2216 | 2219 | | |
2217 | 2220 | | |
| |||
2619 | 2622 | | |
2620 | 2623 | | |
2621 | 2624 | | |
| 2625 | + | |
2622 | 2626 | | |
| 2627 | + | |
2623 | 2628 | | |
2624 | 2629 | | |
2625 | 2630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
0 commit comments