Message ID | 20240117065226.4166127-1-junxiao.chang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-28581-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp733480dye; Tue, 16 Jan 2024 22:53:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSSrJGIaxT4wVaIS2axnGljfyuyLWzyAexVW3lC1GLjYR3Vr7zJ2kiluZwOfBPNEliAfWO X-Received: by 2002:a05:6402:110a:b0:559:d2eb:1c15 with SMTP id u10-20020a056402110a00b00559d2eb1c15mr262086edv.24.1705474384375; Tue, 16 Jan 2024 22:53:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705474384; cv=pass; d=google.com; s=arc-20160816; b=TRU6j1FPXeiV/P9TxA6kFrvMwiDnlgFJGTxf1fMjV7xyWmGGgjkPqs5B2CCFbkf0Ur H97Kgck2gPQRA+x2Y/JZDQBxWArtx3Nl21zFkYXGJfG7n71/WhQu9yh9Y6iAmdPG+UC+ XcD4Ur2gQnHI6IxDN55jntKrfcARsWEkBaJIodncmsvtUYXyo2ecFJV7FDJZrNffAiwY LByXUKd40BT2ZqYUjdUH8RihPQf6cg1ii4SmMn8Eg8RxHJxSUcTz6+S7U899VT0QYThh gBVEUIPNdtnX5YwGEWGIL6FFCtgslHO9OLvv1vnP3+UEaFNXkA/Br8CdWl7vZ82oue/p wncA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=NFTrQOyW8egGZljdOPweqJxLPs8/r6GYiluHLpghnwY=; fh=3n9yk9H0aP61VWOkjV8qJHqEh2nN7MsL3m9A3XvFOBk=; b=r6YBuDiT9cwt6XRpkqT1LolWaloHfFA298T5Yr1MJAkXoeDJRqBzuRilgFZhdPLZsv ruoDVqHtX0Ch9qIxTP6/fgtSHhCiBMTT5esoIcaNvidzkORo7vmPBxPHkR0hoY76/ko4 P/iDu2t19g+oFr81v2DzWp9+DCIZmSRM6eaosYoA3++kF2ZjZloXFky09m5MphBB64SU 0eN8MdaFqlFlZrEdLbAejthCiinW3yrNJ89DwcjnQcCPHKsB95oRAnwMUQkS+XaRN97O D5epUmAbAuJh8kG3CGX+MqPJPcCSnR6IQqWMNl5+CorIfSIqX/xfmlOs2tKI/0Jcpn1G kqig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kpFaKOcn; 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-28581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28581-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g21-20020a056402091500b00553f946c1casi5476976edz.354.2024.01.16.22.53.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 22:53:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kpFaKOcn; 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-28581-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28581-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 002BD1F22DBB for <ouuuleilei@gmail.com>; Wed, 17 Jan 2024 06:53:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3798EBA50; Wed, 17 Jan 2024 06:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kpFaKOcn" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 A7DC78F47; Wed, 17 Jan 2024 06:52:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705474362; cv=none; b=iDDpFRmDorX2xxMwf9ED+F1Ge8FSydli2c3es2DqAxPgIuxJ9yA7E1uRhpdx+bD0ihWKvRZ5SVf2WsUIXJnc6mG3zo+Pg54mKXnNu4lMPqSYMvlQDbqHeHFK4jCcQatEgnsE6BzZpdwiKjBZupVwwmEelKWwH3R0g4NJQ/I7UaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705474362; c=relaxed/simple; bh=KtZv8F8FHVAovFoALPdwWBhpOPjZ1RcvIXZt7uUSRaE=; h=DKIM-Signature:X-IronPort-AV:X-IronPort-AV:Received:X-ExtLoop1: X-IronPort-AV:X-IronPort-AV:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; b=joyJQoN2PP7PxzTL+G2N6KvYuFbYQwSEXW8CKfGzx0zNFtlQLaK1xLPr1kT1tUj1Zr52Vnay+6Lq12XWC1F7qLSnNvzhpNIU/e8kcs/IassOLv5avFJAq4ddlQ5oKd71Lp8dBewqc8ghzMYV199njiXik/wle0tkSG+1GegUGbI= 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=kpFaKOcn; arc=none smtp.client-ip=198.175.65.12 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=1705474361; x=1737010361; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=KtZv8F8FHVAovFoALPdwWBhpOPjZ1RcvIXZt7uUSRaE=; b=kpFaKOcnyl/3gioIXLm0rWiDw4WDlpI4AoswKXQifvwnYVtyZZuDwU54 Q8JGAftIIlAmTX1OzLWHgsLosnViP6ctSeFPUZBa4pA39ekPaBUPiI2VJ 3JFWnIk1YigrvskRZmasmU3SvVai+VoMOMmFViGcBeFtUH1dhu2OBnQJm pwqg+nFy3eAB/0m218rdgRpbn+tVkyUfmbk+jDcc4/z2CrQ8t11vzDjsw sg7TEtUGa3IbP1ZNtws+PrxIGM1DKrK969p4kudlbaEBwy7DsvCQQu4u0 LidPhTOm2IHdpZw6wDtBDfoNBnN3ZMuHjHXFwyOPMjQNll4Y4Z/i2hy+T g==; X-IronPort-AV: E=McAfee;i="6600,9927,10955"; a="7467391" X-IronPort-AV: E=Sophos;i="6.05,200,1701158400"; d="scan'208";a="7467391" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 22:52:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10955"; a="733881873" X-IronPort-AV: E=Sophos;i="6.05,200,1701158400"; d="scan'208";a="733881873" Received: from junxiaochang.bj.intel.com ([10.238.157.86]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 22:52:35 -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] printk: nbcon: check uart port is nbcon or not in nbcon_release Date: Wed, 17 Jan 2024 14:52:26 +0800 Message-Id: <20240117065226.4166127-1-junxiao.chang@intel.com> X-Mailer: git-send-email 2.34.1 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: 1788319507926157549 X-GMAIL-MSGID: 1788319507926157549 |
Series |
printk: nbcon: check uart port is nbcon or not in nbcon_release
|
|
Commit Message
Chang, Junxiao
Jan. 17, 2024, 6:52 a.m. UTC
Different uart ports might have same console pointer, not all of
uart ports are nbcon. When uart port is shutdown, only release
nbcon if it is nbcon. There is same nbcon checking in API
nbcon_acquire.
Fixes: 6424f396c49e ("printk: nbcon: Implement processing in port->lock wrapper")
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
---
kernel/printk/nbcon.c | 3 +++
1 file changed, 3 insertions(+)
Comments
On 2024-01-17, Junxiao Chang <junxiao.chang@intel.com> wrote:
> Different uart ports might have same console pointer,
Please explain how this is possible. It would be a major bug.
John
There are several serial ports in one Intel ADL hardware, they are enumerated as ttyS0, ttyS1, ttyS4, and so on. Multiple console options might be appended to kernel command line. For example, "console=ttyS0,115200n8 console=ttyS4,115200n8 console=ttyS5,115200n8". In this case, several uarts "cons" pointers are same. During booting up process, login thread "agetty" might shutdown all uart. All uart ports could release nbcon lock even if they are "non nbcon" console However, in "nbcon_acquire" API, if uart is not nbcon, it returns directly didn't lock anything. This patch fixes a boot hang issue which could be reproduced every time with Intel ADL hardware/v6.6.7-rt18 kernel. BTW, this issue couldn't be reproduced with v6.6.7-rt17 kernel. Thanks, Junxiao -----Original Message----- From: John Ogness <john.ogness@linutronix.de> Sent: Wednesday, January 17, 2024 4:24 PM To: Chang, Junxiao <junxiao.chang@intel.com>; bigeasy@linutronix.de; tglx@linutronix.de; rostedt@goodmis.org; linux-kernel@vger.kernel.org Cc: Li, Hao3 <hao3.li@intel.com>; Li, Lili <lili.li@intel.com>; Gao, Jianfeng <jianfeng.gao@intel.com>; linux-rt-users@vger.kernel.org Subject: Re: [PATCH] printk: nbcon: check uart port is nbcon or not in nbcon_release On 2024-01-17, Junxiao Chang <junxiao.chang@intel.com> wrote: > Different uart ports might have same console pointer, Please explain how this is possible. It would be a major bug. John
On 2024-01-17, "Chang, Junxiao" <junxiao.chang@intel.com> wrote: > There are several serial ports in one Intel ADL hardware, they are > enumerated as ttyS0, ttyS1, ttyS4, and so on. Multiple console options > might be appended to kernel command line. For example, > "console=ttyS0,115200n8 console=ttyS4,115200n8 > console=ttyS5,115200n8". > > In this case, several uarts "cons" pointers are same. Typically a UART driver will register the console structure in the driver's initcall(), which is only called once per driver. This is why it is usually not possible to have multiple UART consoles. If a driver _does_ allow registering consoles for multiple devices, then it must allocate separate console structs for each registration. Note that register_console() will generate a warning and abort if a driver attempts to register the same console struct twice: WARN(con == newcon, "console '%s%d' already registered\n", con->name, con->index) So I ask again. Please explain how this is possible. John
On 2024-01-17 11:09:24 [+0106], John Ogness wrote: > On 2024-01-17, "Chang, Junxiao" <junxiao.chang@intel.com> wrote: > > There are several serial ports in one Intel ADL hardware, they are > > enumerated as ttyS0, ttyS1, ttyS4, and so on. Multiple console options > > might be appended to kernel command line. For example, > > "console=ttyS0,115200n8 console=ttyS4,115200n8 > > console=ttyS5,115200n8". > > > > In this case, several uarts "cons" pointers are same. > > So I ask again. Please explain how this is possible. I have here | 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A | 00:04: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A and I have | root 2315 0.0 0.0 5480 1792 ttyS0 Ss+ 11:19 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220 | root 2502 0.1 0.0 5480 1792 ttyS1 Ss+ 11:20 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220 and I can stop both of them without any trouble. Can this be reproduced on an ordinary x86 hardware given they have more than one UART (up to four). Is any of this ADL hardware upstream? > John Sebastian
Hi John, As you mentioned, same console driver is only registered once. 8250 console driver is registered once, its "struct console *newcon" parameter is address of "univ8250_console" which is defined in drivers\tty\serial\8250\8250_core.c. However, in each serial port device is registered, their cons pointer( "struct console *cons;" in "struct uart_port") will be assigned with same cons in API serial_core_add_one_port: uport->cons = drv->cons; That is, multiple similar 8250 uart_port devices have same console pointer which points to above univ8250_console. Hi Sebastain, The ADL hardware I used has two UART devices, one is lpss 8250, another is 8250_dw. Usually there is no serial port in consumer product. Maybe there is serial port in Intel ADL industrial product. With my hardware, hang issue could be reproduced every time with 6.6.7-rt18 if serial console is enabled. If you or John need me to run some test build and get debug log with my hardware, please feel free to let me know. The main problem is that there is "nbcon" checking in nbcon_acquire, but no this checking in nbcon_release. It makes nbcon lock not balance. My patch is just to add same "uart_is_nbcon" checking in nb_release. void nbcon_acquire(struct uart_port *up) { ... if (!uart_is_nbcon(up)) return; ... Thanks, Junxiao -----Original Message----- From: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Sent: Wednesday, January 17, 2024 6:25 PM To: John Ogness <john.ogness@linutronix.de> Cc: Chang, Junxiao <junxiao.chang@intel.com>; tglx@linutronix.de; rostedt@goodmis.org; linux-kernel@vger.kernel.org; Li, Hao3 <hao3.li@intel.com>; Li, Lili <lili.li@intel.com>; Gao, Jianfeng <jianfeng.gao@intel.com>; linux-rt-users@vger.kernel.org Subject: Re: RE: [PATCH] printk: nbcon: check uart port is nbcon or not in nbcon_release On 2024-01-17 11:09:24 [+0106], John Ogness wrote: > On 2024-01-17, "Chang, Junxiao" <junxiao.chang@intel.com> wrote: > > There are several serial ports in one Intel ADL hardware, they are > > enumerated as ttyS0, ttyS1, ttyS4, and so on. Multiple console > > options might be appended to kernel command line. For example, > > "console=ttyS0,115200n8 console=ttyS4,115200n8 > > console=ttyS5,115200n8". > > > > In this case, several uarts "cons" pointers are same. > > So I ask again. Please explain how this is possible. I have here | 00:03: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A | 00:04: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A and I have | root 2315 0.0 0.0 5480 1792 ttyS0 Ss+ 11:19 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220 | root 2502 0.1 0.0 5480 1792 ttyS1 Ss+ 11:20 0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220 and I can stop both of them without any trouble. Can this be reproduced on an ordinary x86 hardware given they have more than one UART (up to four). Is any of this ADL hardware upstream? > John Sebastian
On 2024-01-17, "Chang, Junxiao" <junxiao.chang@intel.com> wrote: > As you mentioned, same console driver is only registered once. 8250 > console driver is registered once, its "struct console *newcon" > parameter is address of "univ8250_console" which is defined in > drivers\tty\serial\8250\8250_core.c. > > However, in each serial port device is registered, their cons pointer( > "struct console *cons;" in "struct uart_port") will be assigned with > same cons in API serial_core_add_one_port: > > uport->cons = drv->cons; > > That is, multiple similar 8250 uart_port devices have same console > pointer which points to above univ8250_console. Ah. This explains the "(port)->cons->index == (port)->line" check in uart_console(). Thank you for clarifying. > BTW, this issue couldn't be reproduced with v6.6.7-rt17 kernel. The reason for the change is because console registration/unregistration is not related to the port lock. There is a potential race condition if nbcon unlocking is based on the UART port still being registered as a console. We could move the @locked_port flag to the struct uart_port. (Probably renaming it to @nbcon_locked_port.) I think that would be the appropriate fix. John
Your idea makes sense. We tried to implement a new patch according to your idea, it could fix our booting hang problem. We will push patch for review soon. BTW, it is better to have " uart_is_nbcon " checking in nbcon_release as well as it in nbcon_acquire. 😊 Two patches will be pushed together for review. > We could move the @locked_port flag to the struct uart_port. (Probably renaming it to @nbcon_locked_port.) I think that would be the appropriate fix. > John
On 2024-01-23, Junxiao Chang <junxiao.chang@intel.com> wrote: > There are two serial port devices in one Intel ADL hardware, one is > 8250 lpss, another is 8250 dw. Multiple uart devices are enumerated as > ttyS0, ttyS4, ttyS5,... With 6.6.10 rt18 kernel, booting hangs in > nbcon_release if console is enabled by appending > "console=ttySx,115200n8" to kernel command line. According to nbcon > author John's suggestion, lock flag is moved from console structure to > uart_port. Another patch is to add uart_is_nbcon checking in > nbcon_release. Isn't the real issue that the console pointer is copied to device that are not consoles? I am wondering why that is. Is it possible to dynamically switch the console index during runtime? If not, I think a proper fix would be to only assign @cons if it actually registered as a console. This would also simplify the uart_console() macro. It is critical that a struct console is not shared by multiple devices. I do not like the idea (or see the point) of having non-console devices store a struct console pointer that is registered with another device. I will take a closer look at that. John
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 1b1b585b1675b..e53b8bebbb57e 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1623,6 +1623,9 @@ void nbcon_release(struct uart_port *up) .prio = NBCON_PRIO_NORMAL, }; + if (!uart_is_nbcon(up)) + return; + if (!con->locked_port) return;