@@ -539,6 +539,9 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put);
539
539
*/
540
540
static int serial8250_em485_init (struct uart_8250_port * p )
541
541
{
542
+ /* Port locked to synchronize UART_IER access against the console. */
543
+ lockdep_assert_held_once (& p -> port .lock );
544
+
542
545
if (p -> em485 )
543
546
goto deassert_rts ;
544
547
@@ -677,6 +680,8 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
677
680
serial8250_rpm_get (p );
678
681
679
682
if (p -> capabilities & UART_CAP_SLEEP ) {
683
+ /* Synchronize UART_IER access against the console. */
684
+ spin_lock_irq (& p -> port .lock );
680
685
if (p -> capabilities & UART_CAP_EFR ) {
681
686
lcr = serial_in (p , UART_LCR );
682
687
efr = serial_in (p , UART_EFR );
@@ -690,13 +695,17 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
690
695
serial_out (p , UART_EFR , efr );
691
696
serial_out (p , UART_LCR , lcr );
692
697
}
698
+ spin_unlock_irq (& p -> port .lock );
693
699
}
694
700
695
701
serial8250_rpm_put (p );
696
702
}
697
703
698
704
static void serial8250_clear_IER (struct uart_8250_port * up )
699
705
{
706
+ /* Port locked to synchronize UART_IER access against the console. */
707
+ lockdep_assert_held_once (& up -> port .lock );
708
+
700
709
if (up -> capabilities & UART_CAP_UUE )
701
710
serial_out (up , UART_IER , UART_IER_UUE );
702
711
else
@@ -969,6 +978,9 @@ static void autoconfig_16550a(struct uart_8250_port *up)
969
978
unsigned char status1 , status2 ;
970
979
unsigned int iersave ;
971
980
981
+ /* Port locked to synchronize UART_IER access against the console. */
982
+ lockdep_assert_held_once (& up -> port .lock );
983
+
972
984
up -> port .type = PORT_16550A ;
973
985
up -> capabilities |= UART_CAP_FIFO ;
974
986
@@ -1152,6 +1164,8 @@ static void autoconfig(struct uart_8250_port *up)
1152
1164
/*
1153
1165
* We really do need global IRQs disabled here - we're going to
1154
1166
* be frobbing the chips IRQ enable register to see if it exists.
1167
+ *
1168
+ * Synchronize UART_IER access against the console.
1155
1169
*/
1156
1170
spin_lock_irqsave (& port -> lock , flags );
1157
1171
@@ -1324,7 +1338,10 @@ static void autoconfig_irq(struct uart_8250_port *up)
1324
1338
/* forget possible initially masked and pending IRQ */
1325
1339
probe_irq_off (probe_irq_on ());
1326
1340
save_mcr = serial8250_in_MCR (up );
1341
+ /* Synchronize UART_IER access against the console. */
1342
+ spin_lock_irq (& port -> lock );
1327
1343
save_ier = serial_in (up , UART_IER );
1344
+ spin_unlock_irq (& port -> lock );
1328
1345
serial8250_out_MCR (up , UART_MCR_OUT1 | UART_MCR_OUT2 );
1329
1346
1330
1347
irqs = probe_irq_on ();
@@ -1336,7 +1353,10 @@ static void autoconfig_irq(struct uart_8250_port *up)
1336
1353
serial8250_out_MCR (up ,
1337
1354
UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2 );
1338
1355
}
1356
+ /* Synchronize UART_IER access against the console. */
1357
+ spin_lock_irq (& port -> lock );
1339
1358
serial_out (up , UART_IER , UART_IER_ALL_INTR );
1359
+ spin_unlock_irq (& port -> lock );
1340
1360
serial_in (up , UART_LSR );
1341
1361
serial_in (up , UART_RX );
1342
1362
serial_in (up , UART_IIR );
@@ -1346,7 +1366,10 @@ static void autoconfig_irq(struct uart_8250_port *up)
1346
1366
irq = probe_irq_off (irqs );
1347
1367
1348
1368
serial8250_out_MCR (up , save_mcr );
1369
+ /* Synchronize UART_IER access against the console. */
1370
+ spin_lock_irq (& port -> lock );
1349
1371
serial_out (up , UART_IER , save_ier );
1372
+ spin_unlock_irq (& port -> lock );
1350
1373
1351
1374
if (port -> flags & UPF_FOURPORT )
1352
1375
outb_p (save_ICP , ICP );
@@ -1361,6 +1384,9 @@ static void serial8250_stop_rx(struct uart_port *port)
1361
1384
{
1362
1385
struct uart_8250_port * up = up_to_u8250p (port );
1363
1386
1387
+ /* Port locked to synchronize UART_IER access against the console. */
1388
+ lockdep_assert_held_once (& port -> lock );
1389
+
1364
1390
serial8250_rpm_get (up );
1365
1391
1366
1392
up -> ier &= ~(UART_IER_RLSI | UART_IER_RDI );
@@ -1380,6 +1406,9 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p)
1380
1406
{
1381
1407
unsigned char mcr = serial8250_in_MCR (p );
1382
1408
1409
+ /* Port locked to synchronize UART_IER access against the console. */
1410
+ lockdep_assert_held_once (& p -> port .lock );
1411
+
1383
1412
if (p -> port .rs485 .flags & SER_RS485_RTS_AFTER_SEND )
1384
1413
mcr |= UART_MCR_RTS ;
1385
1414
else
@@ -1429,6 +1458,9 @@ static void __stop_tx_rs485(struct uart_8250_port *p, u64 stop_delay)
1429
1458
{
1430
1459
struct uart_8250_em485 * em485 = p -> em485 ;
1431
1460
1461
+ /* Port locked to synchronize UART_IER access against the console. */
1462
+ lockdep_assert_held_once (& p -> port .lock );
1463
+
1432
1464
stop_delay += (u64 )p -> port .rs485 .delay_rts_after_send * NSEC_PER_MSEC ;
1433
1465
1434
1466
/*
@@ -1608,6 +1640,9 @@ static void serial8250_start_tx(struct uart_port *port)
1608
1640
struct uart_8250_port * up = up_to_u8250p (port );
1609
1641
struct uart_8250_em485 * em485 = up -> em485 ;
1610
1642
1643
+ /* Port locked to synchronize UART_IER access against the console. */
1644
+ lockdep_assert_held_once (& port -> lock );
1645
+
1611
1646
if (!port -> x_char && uart_circ_empty (& port -> state -> xmit ))
1612
1647
return ;
1613
1648
@@ -1635,6 +1670,9 @@ static void serial8250_disable_ms(struct uart_port *port)
1635
1670
{
1636
1671
struct uart_8250_port * up = up_to_u8250p (port );
1637
1672
1673
+ /* Port locked to synchronize UART_IER access against the console. */
1674
+ lockdep_assert_held_once (& port -> lock );
1675
+
1638
1676
/* no MSR capabilities */
1639
1677
if (up -> bugs & UART_BUG_NOMSR )
1640
1678
return ;
@@ -1649,6 +1687,9 @@ static void serial8250_enable_ms(struct uart_port *port)
1649
1687
{
1650
1688
struct uart_8250_port * up = up_to_u8250p (port );
1651
1689
1690
+ /* Port locked to synchronize UART_IER access against the console. */
1691
+ lockdep_assert_held_once (& port -> lock );
1692
+
1652
1693
/* no MSR capabilities */
1653
1694
if (up -> bugs & UART_BUG_NOMSR )
1654
1695
return ;
@@ -2105,6 +2146,14 @@ static void serial8250_put_poll_char(struct uart_port *port,
2105
2146
unsigned int ier ;
2106
2147
struct uart_8250_port * up = up_to_u8250p (port );
2107
2148
2149
+ /*
2150
+ * Normally the port is locked to synchronize UART_IER access
2151
+ * against the console. However, this function is only used by
2152
+ * KDB/KGDB, where it may not be possible to acquire the port
2153
+ * lock because all other CPUs are quiesced. The quiescence
2154
+ * should allow safe lockless usage here.
2155
+ */
2156
+
2108
2157
serial8250_rpm_get (up );
2109
2158
/*
2110
2159
* First save the IER then disable the interrupts
@@ -2440,6 +2489,8 @@ void serial8250_do_shutdown(struct uart_port *port)
2440
2489
serial8250_rpm_get (up );
2441
2490
/*
2442
2491
* Disable interrupts from this port
2492
+ *
2493
+ * Synchronize UART_IER access against the console.
2443
2494
*/
2444
2495
spin_lock_irqsave (& port -> lock , flags );
2445
2496
up -> ier = 0 ;
@@ -2739,6 +2790,8 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2739
2790
/*
2740
2791
* Ok, we're now changing the port state. Do it with
2741
2792
* interrupts disabled.
2793
+ *
2794
+ * Synchronize UART_IER access against the console.
2742
2795
*/
2743
2796
serial8250_rpm_get (up );
2744
2797
spin_lock_irqsave (& port -> lock , flags );
0 commit comments