Message ID | 20240123054033.183114-2-junxiao.chang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp136780dyi; Mon, 22 Jan 2024 21:43:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyuTVdFdNuJFKUK9KZZs0bU37uIFCmwVXbvzTPrLIjbbSthAQwVBeOLfLVPBbLbohuk8+G X-Received: by 2002:aca:210d:0:b0:3bd:6929:d826 with SMTP id 13-20020aca210d000000b003bd6929d826mr5179915oiz.84.1705988595069; Mon, 22 Jan 2024 21:43:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705988595; cv=pass; d=google.com; s=arc-20160816; b=LgI8dXUIwZhiyhj5e7bue2Q4fUOlkqjLoKgTQVg81kelktRywoLRzYZdT6SJcTVR25 19cag0oTOzzae9XD29VspmNMFNpt0Mr4CXmm7QPR2xflhVk2l3iOnRF7QbHN/bzFbhCF whcWlUuuOs4dK2+ilndVdY+/WoO6eq2UqOOoWstFYo3gr6lUAUPNDdUqSYe9C+hsGumN zIBO1fJzmDTE1KfjhTH9YLCbYgF8LiBaaQ9Uo3UqYtqgFYINpUbTsGb8uaaSWqoY1lUi M9XoIQ2U1fcwsal4/c6Hfq50IHqJvpu7sz7Uhy9nwwQbz8W7mNcl79qdbRoPQ1psnqru ibTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zdYKrlDzUSCR+k1c6htQmOpzX7HqoD22HE6w5MctqLo=; fh=3n9yk9H0aP61VWOkjV8qJHqEh2nN7MsL3m9A3XvFOBk=; b=oZGDt0MSBO2ME3OH9b7ynEKAWnWVcug4lqvW709JLy9563ZbmyB30Fr+NdHpZGQ1Us wkM3zXX+4IgBCiic5msyT6P8zOuz+YWrqwDn9h4Z55OPwkX3LC69Sp8jGCQSK//kcZFj vrb67+HIDrXMvxMhju0tIV6yVZHPuusfesJW0wg5+578tQC9lmgvAyNbtPrpd3rI3nRy Muh1q8OpbKRfQ6GsxxRl2GT/bfK4O54pkF8G8QlhMfdeUBDNbNY9KxyEiAfA4vf04p1i s9bCpByrup03tt7xKNsDjo3vDV3qzk2CwzVpZGtP5+wzZu28GsrkILIIaxck6chSBQil mzZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iOHK/kbF"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w7-20020a63b747000000b005cdf801a27dsi9324698pgt.198.2024.01.22.21.43.14 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 21:43:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="iOHK/kbF"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34729-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 84074282144 for <ouuuleilei@gmail.com>; Tue, 23 Jan 2024 05:41:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79337DF5D; Tue, 23 Jan 2024 05:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iOHK/kbF" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D86AE4400; Tue, 23 Jan 2024 05:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705988462; cv=none; b=JFN5115qd4ZIHMnpo2A1H6YDJ5JQxeruZ7JQeYdGUyif+08vTFv9+MS9qISLHMvoAuuDlv7GTL1V6QSwcHhdK+I5KW+X1gXLB7DLSZf+PoJpJaDNF6axPEmYxDX3SKTMDQ0192ATgH7DWmeA+sZ25QFWBSQXRBfoG8i+2R1wG4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705988462; c=relaxed/simple; bh=45JX5R3MtKe14ZwW9pBMEaHbWJ2PGWM2phoKEB3As6Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=irYRVAb8xpU2MUr6V6wcGtdP/XKgWpA/AVws5UcE39F9KsgFqOnw87VPJ9wuHNARk1brqcXNUsS6ru+bZxPr2DCkQJ2gNuItj+/GYxB/fkdFl2UjRzFO4vzTHvHjHgC7IdtICkCKTUoGDqbJmyBqdn7yawvfK4j9bbvBctq4fc8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iOHK/kbF; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705988462; x=1737524462; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=45JX5R3MtKe14ZwW9pBMEaHbWJ2PGWM2phoKEB3As6Y=; b=iOHK/kbF1RCIy31w4f2T8ABgitPlIUoG8S/2RI3TqQ4xRBpi3irxI57G MNCQZI+S/BYsDoVMGLE2QG2S5cn/B8BmnPCgjD7kIMuBnHxXznL66TgLT +dE3Rtl3ddXd/2Lkmj/gjFHvp3YqCNpvJbQQvqAHD4DQhrmCkoEcn2+iE 2jK38+KKwLWSpZgIO/J4SnZ+Sqwgek61ZomUSOJKcCMzkits634MUWWXU Ueu9Rz2D4wzbN3qW+UUwXuf60g13gTZMyvEwdyniCAh2lnFdb+KYI2YYc 9UIl82PBlrYYlqYtkqBmNn+BJbbq6Q3L0M+r29/zf8sUvZIK7aBLX7di8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="14770148" X-IronPort-AV: E=Sophos;i="6.05,213,1701158400"; d="scan'208";a="14770148" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 21:40:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,213,1701158400"; d="scan'208";a="1471996" Received: from junxiaochang.bj.intel.com ([10.238.157.86]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 21:40:44 -0800 From: Junxiao Chang <junxiao.chang@intel.com> To: bigeasy@linutronix.de, tglx@linutronix.de, rostedt@goodmis.org, linux-kernel@vger.kernel.org Cc: john.ogness@linutronix.de, hao3.li@intel.com, lili.li@intel.com, jianfeng.gao@intel.com, linux-rt-users@vger.kernel.org Subject: [PATCH 1/2] printk: nbcon: move locked_port flag to struct uart_port Date: Tue, 23 Jan 2024 13:40:32 +0800 Message-Id: <20240123054033.183114-2-junxiao.chang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240123054033.183114-1-junxiao.chang@intel.com> References: <BN9PR11MB5370AED9C562F9DA75093557EC742@BN9PR11MB5370.namprd11.prod.outlook.com> <20240123054033.183114-1-junxiao.chang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788858696907930473 X-GMAIL-MSGID: 1788858696907930473 |
Series |
nbcon locking issue with v6.6.10-rt18 kernel
|
|
Commit Message
Chang, Junxiao
Jan. 23, 2024, 5:40 a.m. UTC
Console pointer in uart_port might be shared among multiple uart
ports. Flag port locked by nbcon should be saved in uart_port
structure instead of in console structure.
Fixes: 6424f396c49e ("printk: nbcon: Implement processing in port->lock wrapper")
Suggested-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
---
include/linux/console.h | 2 --
include/linux/serial_core.h | 1 +
kernel/printk/nbcon.c | 8 ++++----
3 files changed, 5 insertions(+), 6 deletions(-)
Comments
On 2024-01-23, Junxiao Chang <junxiao.chang@intel.com> wrote: > Console pointer in uart_port might be shared among multiple uart > ports. I still want to investigate why the pointer is shared. This sounds sloppy or dangerous. > Flag port locked by nbcon should be saved in uart_port > structure instead of in console structure. If it turns out that the pointer sharing is necessary, this patch will fix the reported problem. Reviewed-by: John Ogness <john.ogness@linutronix.de>
On 2024-01-24 10:53:10 [+0106], John Ogness wrote: > On 2024-01-23, Junxiao Chang <junxiao.chang@intel.com> wrote: > > Console pointer in uart_port might be shared among multiple uart > > ports. > > I still want to investigate why the pointer is shared. This sounds > sloppy or dangerous. I have x86 a server box and PNP enumerates two UARTs (8250). Only one is wired up but both can be specified as console=. What do I need to do to reproduce this here? Using console= twice does not do the trick. Sebastian
> > > Console pointer in uart_port might be shared among multiple uart > > > ports. > > > > I still want to investigate why the pointer is shared. This sounds > > sloppy or dangerous. > I have x86 a server box and PNP enumerates two UARTs (8250). Only one is wired up but both can be specified as console=. > What do I need to do to reproduce this here? Using console= twice does not do the trick. Issue could be reproduced with our hardware every time. My cmdline is: BOOT_IMAGE=(hd0,gpt2)/boot/bzImage-linux-intel-iot-lts-rt-6.6-kernel root=PARTLABEL=primary rootwait console=ttyS0,115200 console=tty0 init=/sbin/preinit-env console=ttyS4,115200n8 console=ttyS5,115200n8 If you would like to try any debug patch with my ADL hardware, please feel free to let me know. For console pointer sharing issue, from code logic point of view, the call chain looks like: serial8250_register_8250_port -> uart_add_one_port -> serial_ctrl_register_port -> serial_core_register_port -> serial_core_add_one_port In API serial_core_add_one_port, uart_port's console pointer is assigned with driver's console pointer: uport->cons = drv->cons; Driver's console pointer points to static structure "univ8250_console" which is defined in 8250_core.c That is, all 8250 serial devices' console pointer are same, they point to univ8250_console. Below is debug log output: sh-5.1# dmesg | grep @@@@ [ 1.687121] @@@@ univ8250_console_init univ8250_console address:ffffffff935df1e0 [ 3.419880] @@@@ serial8250_register_8250_port: name:ttyS4, cons pointer:ffffffff935df1e0 [ 3.534954] @@@@ serial8250_register_8250_port: name:ttyS5, cons pointer:ffffffff935df1e0 [ 11.971345] @@@@ serial8250_do_shutdown, curr thread:(agetty), name:ttyS0, line 0, cons pointer:ffffffff935df1e0 [ 11.971506] @@@@ serial8250_do_shutdown, curr thread:(agetty), name:ttyS4, line 4, cons pointer:ffffffff935df1e0 [ 11.971849] @@@@ serial8250_do_shutdown, curr thread:(agetty), name:ttyS4, line 4, cons pointer:ffffffff935df1e0 [ 11.983072] @@@@ serial8250_do_shutdown, curr thread:agetty, name:ttyS4, line 4, cons pointer:ffffffff935df1e0 [ 11.983595] @@@@ serial8250_do_shutdown, curr thread:(agetty), name:ttyS5, line 5, cons pointer:ffffffff935df1e0 [ 11.983895] @@@@ serial8250_do_shutdown, curr thread:(agetty), name:ttyS5, line 5, cons pointer:ffffffff935df1e0 [ 12.009632] @@@@ serial8250_do_shutdown, curr thread:agetty, name:ttyS5, line 5, cons pointer:ffffffff935df1e0 sh-5.1# All cons pointers address are same "ffffffff935df1e0". Debug patch: diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 30434718fad80..740fd7e133a28 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -755,6 +755,7 @@ static int __init univ8250_console_init(void) serial8250_isa_init_ports(); register_console(&univ8250_console); + printk("@@@@ %s univ8250_console address:%lx\n", __func__, (unsigned long)(&univ8250_console)); return 0; } console_initcall(univ8250_console_init); @@ -1181,6 +1182,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) if (ret) goto err; + printk("@@@@ %s: name:%s, cons pointer:%lx\n", __func__, uart->port.name, (unsigned long)uart->port.cons); ret = uart->port.line; } else { dev_info(uart->port.dev, diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 437a7d3d34cde..93f1e548d1301 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2510,6 +2510,7 @@ void serial8250_do_shutdown(struct uart_port *port) struct uart_8250_port *up = up_to_u8250p(port); unsigned long flags; + printk("@@@@ %s, curr thread:%s, name:%s, line %d, cons pointer:%lx\n", __func__, current->comm, port->name, port->line, (unsigned long)port->cons); serial8250_rpm_get(up); /* * Disable interrupts from this port Thanks, Junxiao
On 2024-01-25 01:08:24 [+0000], Chang, Junxiao wrote: > > Issue could be reproduced with our hardware every time. My cmdline is: > BOOT_IMAGE=(hd0,gpt2)/boot/bzImage-linux-intel-iot-lts-rt-6.6-kernel > root=PARTLABEL=primary rootwait console=ttyS0,115200 console=tty0 > init=/sbin/preinit-env console=ttyS4,115200n8 console=ttyS5,115200n8 > > If you would like to try any debug patch with my ADL hardware, please feel free to let me know. > > For console pointer sharing issue, from code logic point of view, the call chain looks like: > serial8250_register_8250_port -> uart_add_one_port -> serial_ctrl_register_port -> serial_core_register_port -> serial_core_add_one_port > > In API serial_core_add_one_port, uart_port's console pointer is assigned with driver's console pointer: > uport->cons = drv->cons; > Driver's console pointer points to static structure "univ8250_console" which is defined in 8250_core.c > > That is, all 8250 serial devices' console pointer are same, they point to univ8250_console. Okay, So that I see this and the unbalanced acquire/ release part with the attached patch. I leave it to John… Btw. You don't see kernel log output on ttyS4 + ttyS5, right? Just a login prompt. … > Thanks, > Junxiao Sebastian
> > That is, all 8250 serial devices' console pointer are same, they point to univ8250_console. > Okay, So that I see this and the unbalanced acquire/ release part with the attached patch. I leave it to John… Btw. You don't see kernel log output on ttyS4 + ttyS5, right? Just a login prompt. > > Sebastian Right. At that time, only ttyS0 is console and nbcon. Thanks, Junxiao
Hi Sebastian, On 2024-01-25, Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote: > Okay, So that I see this and the unbalanced acquire/ release part with > the attached patch. I leave it to John... Please add this one patch to the 6.6-rt and later queues. The 2nd patch in this series is not needed. For 6.8 the fix may end up looking different, i.e. by eliminating the struct console pointer sharing instead. But for now this patch is fully sufficient. Thanks. John
On 2024-01-26 09:04:34 [+0106], John Ogness wrote: > Hi Sebastian, Hi, > Please add this one patch to the 6.6-rt and later queues. The 2nd patch > in this series is not needed. Okay. I just dropped a v6.8-RT with this included and I am going to poke Clark regarding v6.6 next week. > Thanks. > > John Sebastian
diff --git a/include/linux/console.h b/include/linux/console.h index f8a0628678886..1eb9580e9b18a 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -304,7 +304,6 @@ struct nbcon_write_context { * @nbcon_state: State for nbcon consoles * @nbcon_seq: Sequence number of the next record for nbcon to print * @pbufs: Pointer to nbcon private buffer - * @locked_port: True, if the port lock is locked by nbcon * @kthread: Printer kthread for this console * @rcuwait: RCU-safe wait object for @kthread waking * @irq_work: Defer @kthread waking to IRQ work context @@ -338,7 +337,6 @@ struct console { atomic_t __private nbcon_state; atomic_long_t __private nbcon_seq; struct printk_buffers *pbufs; - bool locked_port; struct task_struct *kthread; struct rcuwait rcuwait; struct irq_work irq_work; diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 245c11753effd..b2221a50fcb29 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -488,6 +488,7 @@ struct uart_port { struct uart_icount icount; /* statistics */ struct console *cons; /* struct console, if any */ + bool nbcon_locked_port; /* True, if the port is locked by nbcon */ /* flags must be updated while holding port mutex */ upf_t flags; diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 1b1b585b1675b..b53d93585ee71 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1586,7 +1586,7 @@ void nbcon_acquire(struct uart_port *up) if (!uart_is_nbcon(up)) return; - WARN_ON_ONCE(con->locked_port); + WARN_ON_ONCE(up->nbcon_locked_port); do { do { @@ -1597,7 +1597,7 @@ void nbcon_acquire(struct uart_port *up) } while (!nbcon_context_enter_unsafe(&ctxt)); - con->locked_port = true; + up->nbcon_locked_port = true; } EXPORT_SYMBOL_GPL(nbcon_acquire); @@ -1623,13 +1623,13 @@ void nbcon_release(struct uart_port *up) .prio = NBCON_PRIO_NORMAL, }; - if (!con->locked_port) + if (!up->nbcon_locked_port) return; if (nbcon_context_exit_unsafe(&ctxt)) nbcon_context_release(&ctxt); - con->locked_port = false; + up->nbcon_locked_port = false; } EXPORT_SYMBOL_GPL(nbcon_release);