From nobody Sun Dec 14 14:14:50 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 813572361DB for ; Thu, 16 Jan 2025 18:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051793; cv=none; b=FmhG6jqiaDC5fkp/Jcqwt1T/OezcPtQtKFSngm78h+za+uKBEM2vphuvUw0BnlzyOXvWaBhclN4k0wYLeXYjeVVAw4I0cGK7GmWms1//i22hmluo5I5OVad8sm2R655+TyX7MmHa1v9b8bQG28E/dA/bZJOwg/o3rBr+y5ie7JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737051793; c=relaxed/simple; bh=+JZn/ww1FY/kTAFer89gJaTpDgTvbKcrRyepTGJVP18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eu2pqKBvWnKcFzceqKhyUez4jIzxyLz4r0FZOp4QWtd6o46qsn44LCwsSxqXSJmrVt/lXe9AN9VTkmdHbzabJ4hECgeDj5uhpGWYurkyi4noXSgmq5TRlq28QdJN0JI3czMCJXC1s5ymdHz62rnnStJN43bevdY7hw8kTbIurbk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=YeUU7cNt; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="YeUU7cNt" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-385e1fcb0e1so685981f8f.2 for ; Thu, 16 Jan 2025 10:23:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1737051790; x=1737656590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jmtKKaWRtLl2vifGgcWTXPqXE2lcLz7qOiG2GbtoKk4=; b=YeUU7cNtxyYGjobOoDN8dw1YAkZTfwMsyPu+JSlpT4eS5qcxDlxUymNWWDfZNwD+7U CmZR2k0Y6pColT9i8J5vUsNobVwqxCzUgd+8aARt6VeH6R7tPNfiHvX2Lr/vnxV6lVPk +nPrWIWQJApJqPMsLtymLbeTFbIjjfp6jllbGHshBwEK56cRVOyxtmHMZBty4ZgFWVK6 XNhdWJgem5+EC4EbeFgx0Vos6SLMpBf0xcMMy2tsFatfb/5BKxyg0isCBbYSM3TzVglB f3kSNGav4gDWgEdBmBim4CtPvAzWLeGq/CvxdW7+MGOqGb6hY1AfqwIJ5UeqIwgeF3AQ yg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737051790; x=1737656590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jmtKKaWRtLl2vifGgcWTXPqXE2lcLz7qOiG2GbtoKk4=; b=VMtEpXQF+uRxRs+B8bbg60tFeKl1umXqxCIK6F5LMTHdiPFngJNQDMe2BdyfqvqVDO JyXM05bbKEF2uBlpRUigkxXAhWD6eNn65dZAkdrGVOoLnwCsagNLzr+54SiuMPWM4/yH hHnUZMQpm2JGd5PgumNraotsvhivxKw3UEO3F7SgESzgwqYbEdjexBqH1HSXmoxjV1Tw 3RLx4l7c8eIKyATetV2hDDK6xRU9vbcgeSHdcdpudHbTUFS/rYGvKtNPOr5ZOA4eVbFP lLagMc3dQ82nv7jYhytsb54hcwDukl6nuy7Ta9QiZeJmJgWUVsR7qW2wLmpbCBqnJvol csFg== X-Forwarded-Encrypted: i=1; AJvYcCW/PK1bkCKPqdCHo70mM7ZjXca9QIjp+5Wh7/w5qiTC9qbe1SdL3xYEOuRRyqnSu0drDGBA0izTsyPTEEI=@vger.kernel.org X-Gm-Message-State: AOJu0YydE+WY6pbZ9JQeiR++FXzs6wOoSDR8Pnji4AwPByRX2XY1VVYI C4ygh8CW9D5xxmEVGbkG5SL62Jueu1IyT28D49rvut21fNPJEoqZiAAxjeOns+U= X-Gm-Gg: ASbGnctoCCkDPinrOUqShzITwrsAfKORUGmJtmxjqhAuGaP4IPZtI+qgcOYOQ3vYg1J 4VOVsuQQAvubyWWPuIoNEdbJrbcd718kQETGjbX20G9V501kWXXPJ7kCT1B0W3fOEREJ/qmKjAz fiDELHfGtTjr4L6JNNJoBCFqaPd0LfUMIzo+lLtoIHlliOQM3ISUBGF0hm7GAl7338AiSvMeWeA r3Fg8oQFeek4U8pQaROCDq2P8RvMz0xHMZJtjBb31MOkECvT0Ve2WSdqwq1VhD4KcQyLj1Pnoxr dSrxtMxjFVw= X-Google-Smtp-Source: AGHT+IHTCLzWRVHhlR7lW8GYQyylUAfvSBIe2YvKqor2RF/6OYe8hunZYeSsvJPm4KC/0CLZzX9ROQ== X-Received: by 2002:a05:6000:184d:b0:38b:ef22:d8ba with SMTP id ffacd0b85a97d-38bef22da4emr3656439f8f.44.1737051789820; Thu, 16 Jan 2025 10:23:09 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.165]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf322a838sm495942f8f.48.2025.01.16.10.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 10:23:08 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, geert+renesas@glider.be, wsa+renesas@sang-engineering.com, prabhakar.mahadev-lad.rj@bp.renesas.com, ysato@users.sourceforge.jp, ulrich.hecht+renesas@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH 5/5] serial: sh-sci: Increment the runtime usage counter for the earlycon device Date: Thu, 16 Jan 2025 20:22:49 +0200 Message-ID: <20250116182249.3828577-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> References: <20250116182249.3828577-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea In the sh-sci driver, serial ports are mapped to the sci_ports[] array, with earlycon mapped at index zero. The uart_add_one_port() function eventually calls __device_attach(), which, in turn, calls pm_request_idle(). The identified code path is as follows: uart_add_one_port() -> serial_ctrl_register_port() -> serial_core_register_port() -> serial_core_port_device_add() -> serial_base_port_add() -> device_add() -> bus_probe_device() -> device_initial_probe() -> __device_attach() -> // ... if (dev->p->dead) { // ... } else if (dev->driver) { // ... } else { // ... pm_request_idle(dev); // ... } The earlycon device clocks are enabled by the bootloader. However, the pm_request_idle() call in __device_attach() disables the SCI port clocks while earlycon is still active. The earlycon write function, serial_console_write(), calls sci_poll_put_char() via serial_console_putchar(). If the SCI port clocks are disabled, writing to earlycon may sometimes cause the SR.TDFE bit to remain unset indefinitely, causing the while loop in sci_poll_put_char() to never exit. On single-core SoCs, this can result in the system being blocked during boot when this issue occurs. To resolve this, increment the runtime PM usage counter for the earlycon SCI device before registering the UART port. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes since RFT: - used spaced instead of tabs in the call trace from patch description - moved the comment in the code block started by if (sci_uart_earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->start) - still kept the sci_ports[0].port.mapbase =3D=3D sci_res->start check as I haven't manage to find a better way drivers/tty/serial/sh-sci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index e64d59888ecd..b1ea48f38248 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3436,6 +3436,22 @@ static int sci_probe_single(struct platform_device *= dev, } =20 if (sci_uart_earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->start)= { + /* + * In case: + * - this is the earlycon port (mapped on index 0 in sci_ports[]) and + * - it now maps to an alias other than zero and + * - the earlycon is still alive (e.g., "earlycon keep_bootcon" is + * available in bootargs) + * + * we need to avoid disabling clocks and PM domains through the runtime + * PM APIs called in __device_attach(). For this, increment the runtime + * PM reference counter (the clocks and PM domains were already enabled + * by the bootloader). Otherwise the earlycon may access the HW when it + * has no clocks enabled leading to failures (infinite loop in + * sci_poll_put_char()). + */ + pm_runtime_get_noresume(&dev->dev); + /* * Skip cleanup the sci_port[0] in early_console_exit(), this * port is the same as the earlycon one. --=20 2.43.0