diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2014-10-16 16:54:20 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-11-05 21:53:54 -0500 |
commit | 7c8ab967e3cd1513cd79fd5edc404fb43c7f3a96 (patch) | |
tree | 2fadec4ea6f6d183b2b6e5b81453a57b8670e390 | |
parent | 2e758910832dce99761a29688b33fd77dcbf6f6c (diff) |
serial: Fix locking for uart driver set_termios() method
The low-level uart driver may modify termios settings to override
settings that are not compatible with the uart, such as CRTSCTS.
Thus, callers of the low-level uart driver's set_termios() method must
hold termios_rwsem write lock to prevent concurrent access to termios,
in case such override occurs.
The termios_rwsem lock requirement does not extend to console setup
(ie., uart_set_options), as console setup cannot race with tty
operations. Nor does this lock requirement extend to functions which
cannot be concurrent with tty ioctls (ie., uart_port_startup() and
uart_resume_port()).
Further, always claim the port mutex to protect hardware
re-reprogramming in the set_termios() uart driver method. Note this
is unnecessary for console initialization in uart_set_options()
which cannot be concurrent with other uart operations.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | Documentation/serial/driver | 6 | ||||
-rw-r--r-- | drivers/tty/serial/serial_core.c | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/Documentation/serial/driver b/Documentation/serial/driver index ba64e4b892e9..c415b0ef4493 100644 --- a/Documentation/serial/driver +++ b/Documentation/serial/driver | |||
@@ -59,7 +59,9 @@ The core driver uses the info->tmpbuf_sem lock to prevent multi-threaded | |||
59 | access to the info->tmpbuf bouncebuffer used for port writes. | 59 | access to the info->tmpbuf bouncebuffer used for port writes. |
60 | 60 | ||
61 | The port_sem semaphore is used to protect against ports being added/ | 61 | The port_sem semaphore is used to protect against ports being added/ |
62 | removed or reconfigured at inappropriate times. | 62 | removed or reconfigured at inappropriate times. Since v2.6.27, this |
63 | semaphore has been the 'mutex' member of the tty_port struct, and | ||
64 | commonly referred to as the port mutex (or port->mutex). | ||
63 | 65 | ||
64 | 66 | ||
65 | uart_ops | 67 | uart_ops |
@@ -248,7 +250,7 @@ hardware. | |||
248 | Other flags may be used (eg, xon/xoff characters) if your | 250 | Other flags may be used (eg, xon/xoff characters) if your |
249 | hardware supports hardware "soft" flow control. | 251 | hardware supports hardware "soft" flow control. |
250 | 252 | ||
251 | Locking: none. | 253 | Locking: caller holds port->mutex |
252 | Interrupts: caller dependent. | 254 | Interrupts: caller dependent. |
253 | This call must not sleep | 255 | This call must not sleep |
254 | 256 | ||
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 9d142972ee2d..e31d56159aee 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c | |||
@@ -436,7 +436,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud) | |||
436 | 436 | ||
437 | EXPORT_SYMBOL(uart_get_divisor); | 437 | EXPORT_SYMBOL(uart_get_divisor); |
438 | 438 | ||
439 | /* FIXME: Consistent locking policy */ | 439 | /* Caller holds port mutex */ |
440 | static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, | 440 | static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, |
441 | struct ktermios *old_termios) | 441 | struct ktermios *old_termios) |
442 | { | 442 | { |
@@ -1173,11 +1173,15 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, | |||
1173 | break; | 1173 | break; |
1174 | 1174 | ||
1175 | case TIOCSSERIAL: | 1175 | case TIOCSSERIAL: |
1176 | down_write(&tty->termios_rwsem); | ||
1176 | ret = uart_set_info_user(tty, state, uarg); | 1177 | ret = uart_set_info_user(tty, state, uarg); |
1178 | up_write(&tty->termios_rwsem); | ||
1177 | break; | 1179 | break; |
1178 | 1180 | ||
1179 | case TIOCSERCONFIG: | 1181 | case TIOCSERCONFIG: |
1182 | down_write(&tty->termios_rwsem); | ||
1180 | ret = uart_do_autoconfig(tty, state); | 1183 | ret = uart_do_autoconfig(tty, state); |
1184 | up_write(&tty->termios_rwsem); | ||
1181 | break; | 1185 | break; |
1182 | 1186 | ||
1183 | case TIOCSERGWILD: /* obsolete */ | 1187 | case TIOCSERGWILD: /* obsolete */ |
@@ -1278,7 +1282,9 @@ static void uart_set_termios(struct tty_struct *tty, | |||
1278 | return; | 1282 | return; |
1279 | } | 1283 | } |
1280 | 1284 | ||
1285 | mutex_lock(&state->port.mutex); | ||
1281 | uart_change_speed(tty, state, old_termios); | 1286 | uart_change_speed(tty, state, old_termios); |
1287 | mutex_unlock(&state->port.mutex); | ||
1282 | /* reload cflag from termios; port driver may have overriden flags */ | 1288 | /* reload cflag from termios; port driver may have overriden flags */ |
1283 | cflag = tty->termios.c_cflag; | 1289 | cflag = tty->termios.c_cflag; |
1284 | 1290 | ||