Skip to content

Commit a91a3c2

Browse files
ij-intelgregkh
authored andcommitted
serial: 8250: Toggle IER bits on only after irq has been set up
[ Upstream commit 039d492 ] Invoking TIOCVHANGUP on 8250_mid port on Ice Lake-D and then reopening the port triggers these faults during serial8250_do_startup(): DMAR: DRHD: handling fault status reg 3 DMAR: [DMA Write NO_PASID] Request device [00:1a.0] fault addr 0x0 [fault reason 0x05] PTE Write access is not set If the IRQ hasn't been set up yet, the UART will have zeroes in its MSI address/data registers. Disabling the IRQ at the interrupt controller won't stop the UART from performing a DMA write to the address programmed in its MSI address register (zero) when it wants to signal an interrupt. The UARTs (in Ice Lake-D) implement PCI 2.1 style MSI without masking capability, so there is no way to mask the interrupt at the source PCI function level, except disabling the MSI capability entirely, but that would cause it to fall back to INTx# assertion, and the PCI specification prohibits disabling the MSI capability as a way to mask a function's interrupt service request. The MSI address register is zeroed by the hangup as the irq is freed. The interrupt is signalled during serial8250_do_startup() performing a THRE test that temporarily toggles THRI in IER. The THRE test currently occurs before UART's irq (and MSI address) is properly set up. Refactor serial8250_do_startup() such that irq is set up before the THRE test. The current irq setup code is intermixed with the timer setup code. As THRE test must be performed prior to the timer setup, extract it into own function and call it only after the THRE test. The ->setup_timer() needs to be part of the struct uart_8250_ops in order to not create circular dependency between 8250 and 8250_base modules. Fixes: 40b36da ("[PATCH] 8250 UART backup timer") Reported-by: Lennert Buytenhek <[email protected]> Tested-by: Lennert Buytenhek <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 6be8e56 commit a91a3c2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

drivers/tty/serial/8250/8250_core.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,9 @@ static void serial8250_backup_timeout(struct timer_list *t)
300300
jiffies + uart_poll_timeout(&up->port) + HZ / 5);
301301
}
302302

303-
static int univ8250_setup_irq(struct uart_8250_port *up)
303+
static void univ8250_setup_timer(struct uart_8250_port *up)
304304
{
305305
struct uart_port *port = &up->port;
306-
int retval = 0;
307306

308307
/*
309308
* The above check will only give an accurate result the first time
@@ -324,10 +323,16 @@ static int univ8250_setup_irq(struct uart_8250_port *up)
324323
*/
325324
if (!port->irq)
326325
mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
327-
else
328-
retval = serial_link_irq_chain(up);
326+
}
329327

330-
return retval;
328+
static int univ8250_setup_irq(struct uart_8250_port *up)
329+
{
330+
struct uart_port *port = &up->port;
331+
332+
if (port->irq)
333+
return serial_link_irq_chain(up);
334+
335+
return 0;
331336
}
332337

333338
static void univ8250_release_irq(struct uart_8250_port *up)
@@ -383,6 +388,7 @@ static struct uart_ops univ8250_port_ops;
383388
static const struct uart_8250_ops univ8250_driver_ops = {
384389
.setup_irq = univ8250_setup_irq,
385390
.release_irq = univ8250_release_irq,
391+
.setup_timer = univ8250_setup_timer,
386392
};
387393

388394
static struct uart_8250_port serial8250_ports[UART_NR];

drivers/tty/serial/8250/8250_port.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,10 @@ int serial8250_do_startup(struct uart_port *port)
22802280
if (port->irq && (up->port.flags & UPF_SHARE_IRQ))
22812281
up->port.irqflags |= IRQF_SHARED;
22822282

2283+
retval = up->ops->setup_irq(up);
2284+
if (retval)
2285+
goto out;
2286+
22832287
if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) {
22842288
unsigned char iir1;
22852289

@@ -2322,9 +2326,7 @@ int serial8250_do_startup(struct uart_port *port)
23222326
}
23232327
}
23242328

2325-
retval = up->ops->setup_irq(up);
2326-
if (retval)
2327-
goto out;
2329+
up->ops->setup_timer(up);
23282330

23292331
/*
23302332
* Now, initialize the UART

include/linux/serial_8250.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct uart_8250_port;
7474
struct uart_8250_ops {
7575
int (*setup_irq)(struct uart_8250_port *);
7676
void (*release_irq)(struct uart_8250_port *);
77+
void (*setup_timer)(struct uart_8250_port *);
7778
};
7879

7980
struct uart_8250_em485 {

0 commit comments

Comments
 (0)