Re: [PATCH] x86/apic/msi: check interupt context before reporting warning
From: Greg KH
Date: Tue Jul 13 2021 - 03:00:00 EST
On Tue, Jul 13, 2021 at 02:46:09PM +0800, Yongxin Liu wrote:
> Affinity change can happen in both interrupt context and non-interrupt
> context. The paranoia check for interrupt target cpu is not always true
> in non-interrupt context.
>
> For example:
> Set affinity for irq to CPU#7
> $ echo 80 > /proc/irq/default_smp_affinity
>
> Open serial port on different CPU.
> $taskset -c 4 agetty -L 115200 ttyS1
>
> Will triger the following warning.
>
> WARNING: CPU: 4 PID: 765 at arch/x86/kernel/apic/msi.c:75 msi_set_affinity+0x16f/0x190
> Call Trace:
> irq_do_set_affinity+0x57/0x1b0
> irq_setup_affinity+0x136/0x190
> irq_startup+0xaf/0xf0
> __setup_irq+0x745/0x7e0
> ? kmem_cache_alloc_trace+0x2b5/0x450
> request_threaded_irq+0x110/0x180
> univ8250_setup_irq+0x1e2/0x220
> serial8250_do_startup+0x481/0x760
> serial8250_startup+0x1e/0x20
> uart_startup.part.22+0xf8/0x260
> uart_port_activate+0x41/0x60
> tty_port_open+0x82/0xd0
> ? _raw_spin_unlock+0x16/0x30
> uart_open+0x1e/0x30
> tty_open+0x100/0x4d0
> ? cdev_purge+0x60/0x60
> chrdev_open+0xa3/0x1c0
> ? cdev_put.part.3+0x20/0x20
> do_dentry_open+0x21f/0x380
> vfs_open+0x2f/0x40
> path_openat+0xd67/0xf60
> ? page_add_file_rmap+0xad/0x140
> ? do_set_pte+0xd7/0x210
> do_filp_open+0xc5/0x140
> do_sys_openat2+0x239/0x300
> ? do_sys_openat2+0x239/0x300
> do_sys_open+0x59/0x80
> __x64_sys_openat+0x20/0x30
> do_syscall_64+0x3f/0x90
> entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> With this patch, the warning is only reported in interrupt context and when
> the target CPU is not local CPU.
>
> Signed-off-by: Yongxin Liu <yongxin.liu@xxxxxxxxxxxxx>
> ---
> arch/x86/kernel/apic/msi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/apic/msi.c b/arch/x86/kernel/apic/msi.c
> index 44ebe25e7703..c4c73f227eeb 100644
> --- a/arch/x86/kernel/apic/msi.c
> +++ b/arch/x86/kernel/apic/msi.c
> @@ -72,7 +72,7 @@ msi_set_affinity(struct irq_data *irqd, const struct cpumask *mask, bool force)
> * Paranoia: Validate that the interrupt target is the local
> * CPU.
> */
> - if (WARN_ON_ONCE(cpu != smp_processor_id())) {
> + if (in_interrupt() && WARN_ON_ONCE(cpu != smp_processor_id())) {
> irq_msi_update_msg(irqd, cfg);
> return ret;
> }
> --
> 2.14.5
>
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>