Re: [PATCH] serial: 8250_mid fix calltrace when hotplug 8250 serial controller

From: Andy Shevchenko
Date: Wed Nov 30 2016 - 11:15:08 EST


On Wed, 2016-11-30 at 01:25 -0500, Song liwei wrote:
> From: Liwei Song <liwei.song@xxxxxxxxxxxxx>
>
> Fix the following Calltrace:
> [ÂÂÂ77.768221] WARNING: CPU: 5 PID: 645 at
> drivers/dma/dmaengine.c:1069 dma_async_device_unregister+0xe2/0xf0
> [ÂÂÂ77.775058] dma_async_device_unregister called while 1 clients hold
> a reference
> [ÂÂÂ77.825048] CPU: 5 PID: 645 Comm: sh Not tainted 4.8.8-
> WR9.0.0.0_standard+ #3
> [ÂÂÂ77.832550] Hardware name: Intel Corp. Aspen Cove/Server, BIOS
> HAVLCRB1.X64.0012.D58.1604140405 04/14/2016
> [ÂÂÂ77.840396]ÂÂ0000000000000000 ffffc90008adbc80 ffffffff81403456
> ffffc90008adbcd0
> [ÂÂÂ77.848245]ÂÂ0000000000000000 ffffc90008adbcc0 ffffffff8105e2e1
> 0000042d08adbf20
> [ÂÂÂ77.855934]ÂÂffff88046a861c18 ffff88046a85c420 ffffffff820d4200
> ffff88046ae92318
> [ÂÂÂ77.863601] Call Trace:
> [ÂÂÂ77.871113]ÂÂ[<ffffffff81403456>] dump_stack+0x4f/0x69
> [ÂÂÂ77.878655]ÂÂ[<ffffffff8105e2e1>] __warn+0xd1/0xf0
> [ÂÂÂ77.886102]ÂÂ[<ffffffff8105e34f>] warn_slowpath_fmt+0x4f/0x60
> [ÂÂÂ77.893508]ÂÂ[<ffffffff814187a9>] ? find_next_bit+0x19/0x20
> [ÂÂÂ77.900730]ÂÂ[<ffffffff814bf83e>] ?
> dma_channel_rebalance+0x23e/0x270
> [ÂÂÂ77.907814]ÂÂ[<ffffffff814bfee2>]
> dma_async_device_unregister+0xe2/0xf0
> [ÂÂÂ77.914992]ÂÂ[<ffffffff814c53aa>] hsu_dma_remove+0x1a/0x60
> [ÂÂÂ77.921977]ÂÂ[<ffffffff814ee14c>] dnv_exit+0x1c/0x20
> [ÂÂÂ77.928752]ÂÂ[<ffffffff814edff6>] mid8250_remove+0x26/0x40
> [ÂÂÂ77.935607]ÂÂ[<ffffffff8144f1b9>] pci_device_remove+0x39/0xc0
> [ÂÂÂ77.942292]ÂÂ[<ffffffff8160cfea>]
> __device_release_driver+0x9a/0x140
> [ÂÂÂ77.948836]ÂÂ[<ffffffff8160d0b3>] device_release_driver+0x23/0x30
> [ÂÂÂ77.955364]ÂÂ[<ffffffff81447dcc>] pci_stop_bus_device+0x8c/0xa0
> [ÂÂÂ77.961769]ÂÂ[<ffffffff81447f0a>]
> pci_stop_and_remove_bus_device_locked+0x1a/0x30
> [ÂÂÂ77.968113]ÂÂ[<ffffffff81450d4e>] remove_store+0x5e/0x70
> [ÂÂÂ77.974267]ÂÂ[<ffffffff81607ed8>] dev_attr_store+0x18/0x30
> [ÂÂÂ77.980243]ÂÂ[<ffffffff8123006a>] sysfs_kf_write+0x3a/0x50
> [ÂÂÂ77.986180]ÂÂ[<ffffffff8122f5ab>] kernfs_fop_write+0x10b/0x190
> [ÂÂÂ77.992118]ÂÂ[<ffffffff811bf1c8>] __vfs_write+0x18/0x40
> [ÂÂÂ77.998032]ÂÂ[<ffffffff811bfdee>] vfs_write+0xae/0x190
> [ÂÂÂ78.003747]ÂÂ[<ffffffff811c1016>] SyS_write+0x46/0xb0
> [ÂÂÂ78.009234]ÂÂ[<ffffffff81a4c31b>]
> entry_SYSCALL_64_fastpath+0x13/0x8f
> [ÂÂÂ78.014809] ---[ end trace 0c36dd73b7408eb2 ]---
>
> This happens when the 8250 serial controller is hotplugged as follows:
> echo 1 > /sys/bus/pci/devices/0000:00:1a.0/remove
>
> This trace happens due to the serial port still holding a reference
> when
> the dma device is unregistered.
> The dma unregister routine will check if there is still a reference
> exist,
> if so it will give the WARNING(here serial port still was not
> unregister).
>
> To fix this, We need to unregister the serial port first, then do DMA
> device unregister to make sure there is no reference when to DMA
> routine.
>

Good catch, thanks!

Acked-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

> Signed-off-by: Liwei Song <liwei.song@xxxxxxxxxxxxx>
> ---
> Âdrivers/tty/serial/8250/8250_mid.c | 4 ++--
> Â1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_mid.c
> b/drivers/tty/serial/8250/8250_mid.c
> index 39c2324..ac013edf 100644
> --- a/drivers/tty/serial/8250/8250_mid.c
> +++ b/drivers/tty/serial/8250/8250_mid.c
> @@ -303,10 +303,10 @@ static void mid8250_remove(struct pci_dev *pdev)
> Â{
> Â struct mid8250 *mid = pci_get_drvdata(pdev);
> Â
> + serial8250_unregister_port(mid->line);
> +
> Â if (mid->board->exit)
> Â mid->board->exit(mid);
> -
> - serial8250_unregister_port(mid->line);
> Â}
> Â
> Âstatic const struct mid8250_board pnw_board = {

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy