From patchwork Tue May 6 11:23:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 888481 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 E5A6827AC5B for ; Tue, 6 May 2025 11:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530613; cv=none; b=QkE93wwMWbF1AXELhKB1lMlqqTTG291VKtgGWGepfG10IOfton+GueIJSrpR57epYqPkClixxiU5NoNikFeSoO8xk9t9ggz54u5SpeQFJ5sfaTHxx8iEt8XT7ZYlyg3HrfL7YT4CHxOlQPromImJS57bNK9g5E+c6HSjB6BLCUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530613; c=relaxed/simple; bh=xjL65vzHaYnd2+Zu9zg+UVvkfoWrRNrqH2KTKvwr7nk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RVDKO6WH/GKHkMHik4leuITQFFnyey9M4MbrH2/edMYcgVY119A5eIi8CKMirpUMqX425IGMabj3f7FveX6seoB93rbjRvqtrcOBWDvAMqj19iOkQp6BdEgTWgFqyUeqguQLsEDLlgnvMjznvZh3GFwsCVh6+ZEEnMpeQRE/lDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=eRXQ5XhT; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="eRXQ5XhT" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-b07d607dc83so4617885a12.1 for ; Tue, 06 May 2025 04:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1746530611; x=1747135411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=lj+Ua/fxMyjIfoIv2F4j22EXalsnM7wsPJwCRLC9/bk=; b=eRXQ5XhT6sobBVK6SdyeCkzoJBQY+Uj9EA8VYsyVTDRZ2E6zgvPcYkMdkcbIqipQuF RktkxhUk+zROq9iv+XmdDDxaqWZS3bjVcS8wRH1fr2InH1XyXJECwWNQvF6ytCtUz0zu zFyO5J6sppKI7XThFy5Fj+A1plCuyhMyJC6aUUEPBY7ReH/O8U/bi/fjE2ROGaLn12wj RZLXHXLWKHY9SSsr+q+oBnXLF5YFvCirU9d6rD1ESqmMHCl1OoSMd+OJFisG4q6i2f9e o3vgeGI1SyACrluZ/+z/Za4ZxZxi6Ia9N2+vc41t6hn5NpGIFjRd9FcY8FdnxkYMYlE6 WPcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746530611; x=1747135411; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lj+Ua/fxMyjIfoIv2F4j22EXalsnM7wsPJwCRLC9/bk=; b=mpV2AObD3deYfJHTYGP2glLNvD64/Jg01kVyIoeQ25YacB0AEeL+ENMur9bzVNNBYV 5UbXX2DkZ65G8jVtYxggWEkdRU1RCJUgZ6HD+BQ6nUWv/xZbIsJw4+XEPk7S7hQ9nXox 7O8nTvw/VMWtVJU0w55S9DgeJE1KxbqOePkiUYl9v5mjVYsqzmOllceoj/8JABOBlhJz jFAxAx9SEu/nEeBdhDsmOizuzuA5EExZ63B54gxK3bPBEphQgxdZEfv8QoXxrEAmFMvr WSL+Vxvy1VEOE5gd+rqJGWP5j0B3SbpJCszZU03JDfNsflPEiZWRucYIks8CGqUAyS6p yWdw== X-Forwarded-Encrypted: i=1; AJvYcCWiWdl88WBMzNY3f9WKP2CFcmlDny05cqoQgbrK8yjss18jcRAmOb3vC+Lh8J71023/cV8nRmqXazAK+W4=@vger.kernel.org X-Gm-Message-State: AOJu0YztpwHckj+i/yQNoxB9QxVjVexIHa5NAp6LTTK9KHiNFD717SLK PhakPHToeqpDVhXKBns0mF05JeyRMVwI/6BySJp5RQampK8DkBawxUEMCYlHNm4= X-Gm-Gg: ASbGncto4donvRZ0Z+vVUFs1qVJAgPiUIZPi9UDtggQv55fAMxW//FbgyhlOgb8oPEy LKMlXWZuSLqmLy4OQyLVsKyAk7ziMql0bXmfDyapcH342k4wtAlK5MvgSRh81bjKyt6oR1HaaXr aXQrZvLeT8zQYUbGQpc6EAFwbK3XmOCzb8igz9Ksgzm/GmvTfG2Yq9pUKhxTwnUMUr9U5ymnEr6 RcYPOYG9cbO04FRfHg22TKGUs4co7Hx8uom/jKeobiUAu6gHdFaTPTrWjXn+BS4K0Ga/6+PYHrB qAlHrBxSJnToqz0DqvcFs0WBFpBG5kkf6JHmV8LRteSDh7cT4/dU4xJ4OmM8VMfHzP8Jd5Gx X-Google-Smtp-Source: AGHT+IEOXeQAPiRigAJRM+ag8kVULH/CPzkxnG0tEFjbXvabNNYE6kFbgeM+fhK2lrsDJD43flM35w== X-Received: by 2002:a17:90b:2703:b0:308:6d7a:5d30 with SMTP id 98e67ed59e1d1-30a619ab240mr19584577a91.18.1746530611028; Tue, 06 May 2025 04:23:31 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480ea0dsm13630303a91.37.2025.05.06.04.23.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 May 2025 04:23:30 -0700 (PDT) From: Yunhui Cui To: arnd@arndb.de, andriy.shevchenko@linux.intel.com, benjamin.larsson@genexis.eu, cuiyunhui@bytedance.com, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, ilpo.jarvinen@linux.intel.com, jirislaby@kernel.org, jkeeping@inmusicbrands.com, john.ogness@linutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, markus.mayer@linaro.org, matt.porter@linaro.org, namcao@linutronix.de, paulmck@kernel.org, pmladek@suse.com, schnelle@linux.ibm.com, sunilvl@ventanamicro.com, tim.kryger@linaro.org Subject: [PATCH v5 1/4] serial: 8250: fix panic due to PSLVERR Date: Tue, 6 May 2025 19:23:18 +0800 Message-Id: <20250506112321.61710-1-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the PSLVERR_RESP_EN parameter is set to 1, the device generates an error response if an attempt is made to read an empty RBR (Receive Buffer Register) while the FIFO is enabled. In serial8250_do_startup(), calling serial_port_out(port, UART_LCR, UART_LCR_WLEN8) triggers dw8250_check_lcr(), which invokes dw8250_force_idle() and serial8250_clear_and_reinit_fifos(). The latter function enables the FIFO via serial_out(p, UART_FCR, p->fcr). Execution proceeds to the dont_test_tx_en label: ... serial_port_in(port, UART_RX); This satisfies the PSLVERR trigger condition. Because another CPU(e.g., using printk()) is accessing the UART (UART is busy), the current CPU fails the check (value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR), causing it to enter dw8250_force_idle(). Put serial_port_out(port, UART_LCR, UART_LCR_WLEN8) under the port->lock to fix this issue. Panic backtrace: [ 0.442336] Oops - unknown exception [#1] [ 0.442343] epc : dw8250_serial_in32+0x1e/0x4a [ 0.442351] ra : serial8250_do_startup+0x2c8/0x88e ... [ 0.442416] console_on_rootfs+0x26/0x70 Fixes: c49436b657d0 ("serial: 8250_dw: Improve unwritable LCR workaround") Link: https://lore.kernel.org/all/84cydt5peu.fsf@jogness.linutronix.de/T/ Signed-off-by: Yunhui Cui --- drivers/tty/serial/8250/8250_port.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 3f256e96c722..a913135d5217 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2380,9 +2380,10 @@ int serial8250_do_startup(struct uart_port *port) /* * Now, initialize the UART */ - serial_port_out(port, UART_LCR, UART_LCR_WLEN8); uart_port_lock_irqsave(port, &flags); + serial_port_out(port, UART_LCR, UART_LCR_WLEN8); + if (up->port.flags & UPF_FOURPORT) { if (!up->port.irq) up->port.mctrl |= TIOCM_OUT1; From patchwork Tue May 6 11:23:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 888043 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 6AD83277817 for ; Tue, 6 May 2025 11:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530619; cv=none; b=XqV5XcDXv1uI777d9LznFos2+L0OTgkV92lRwbof674KiniaiTF9naYDs6RlAKCP49UzdiukunZMc5NBvMgR4M9FK+U8o3bWbeM2gnQrmep4zKmWvnbFw9Q+8gDeGGejBaHPkA2fWULViAY62imn+7Bl6aWKWcZlrvq7tQhTRMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530619; c=relaxed/simple; bh=H3l282jI5Layhto6Pmynhm3ddZElvS+Gd+StASMFlFc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nBHEA5thyUU8FRJlmlnLilKka1cY+1iXu9/JtVbODpTu45x9ioigmFG8BF4nlA94vqeJOJrhiZvd9xvNBYC4p336xNzkw1jIvDrJsEXSs6KuG67bSwRpGmW9fzV0sMztzhNgYfmEu7Yb4UPxF6njvHn3nSdktABlXcOK6Mwg5Z8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ihvYTMsb; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ihvYTMsb" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-309f3bf23b8so7238356a91.3 for ; Tue, 06 May 2025 04:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1746530617; x=1747135417; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1iSa5DYMN+92PEYo5yJGBYTHY1dFKEUc+Tn0/1DSVH4=; b=ihvYTMsbbGDAe1YiME3im0853yv4UUXCEtvl/G4FYtDpiW8Ys/nDhSkxOj8DEj7Iqf 8lHJSr9PWCmQ3NarlKQS9rlgI5zlFY00d1KUwskX7vMiPxqBHBEu+wkbuQjNgCja4T2l k9FGvaGD5R1zge6XG/PMot2uR/9Gm7eSKJflk6lFZRLpyIV7L0iJhJ/2eeqzGVvuzR6W hswBVuiehvvMHRIxy2eetTjCpnQGrK921/xViSxW9B8XPHk3/4NMGbg0cw1S9SHlyKPW Tp4dqvA4HwfWt0/hIuMFQB/JcOas4C21Qx278uDCn6mLvOq22YOHJayz2Aq5SahQJEYr SvZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746530617; x=1747135417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1iSa5DYMN+92PEYo5yJGBYTHY1dFKEUc+Tn0/1DSVH4=; b=KNk9ny52jLWTsGMpQbOWhxcSsqon5DNP4GJuRsm9UUFvIWuHq3SO1ncClwDb4+90OR D+qbPI2vs2SJS7p2amuPVDNovhB5sadB8e03VhNSz7Jslq+RixpptF3ZM+9zzVkrFu3k 78DQF3hMNmGlKT7aK0HNpyfizyGfinMB8R/ZEtSLz9AxRQpxO3xGmkDhpPSXGvU6Mkf0 smHgZAexk49LcwMuhv5XNixTvkgOl+uTt+Rjc1oSiG/IRLSkzeowO2uiG/68EtiGRToO H5/PcquJiYSC8AXukC+xghCi6DxDWTx9JU+10ekb0sfxcUCKYwcEdg/xrH9I1yBbxrfE FjYA== X-Forwarded-Encrypted: i=1; AJvYcCU6+t+soXfx/q0ktZaTbrwANQXo8JCWtgQZmPeqQEoUYAthnK4J5GURknHlK4mZwvVYsq3mZzeKEL1AN0I=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+BDIKfa69Cxfbekg6EBzUvib45Z6IHuNLq1JUOfb+pmgCwKDG UybkDbcef+oslihrrDwnR3b/wrJX3NOVGdxXsPDdDY47I4i9QnXEayb7n+IOow4= X-Gm-Gg: ASbGncuu+tvQKbnfOXzOKyRw3Y7Ew4cLoTTjc3gnLQy4EFE+fjoqxbhWMjjUa8KJ0DE 9ExE80cw4u7i6vF9VpYONaufNns0wn3A+wONkw9P3W2oifHGgSzwvpb1WJjhUYxMIuBD6bl7xir wSHDmbt2YQ186tFQ0QHebUX5kr823z+1ymrFIAPRFGPcc8vIZCzRR7QGl+fQpMYV+Dp/YibkIfU x7fVHI1begxdO3u6eIVm/36mePa2JFMVrJN7274nGnMn8So1U8nRSfUuPLBOCHbYauqQswRacEM PrhfQZm9tnI0MUyaINzIw2UkeoEpAt+LJk+C7o5YGf3TcwkRatBsZRFXP0dUs1kk64HA+dP/ X-Google-Smtp-Source: AGHT+IFZHmt25dELEMwZQhUshisxGn6bjEwlTvzFcbNJLIa3RfN+PGPZSE1vLKGtcV12XFgGyQr6kA== X-Received: by 2002:a17:90b:1f82:b0:2fe:baa3:b8bc with SMTP id 98e67ed59e1d1-30a7c0c8b8emr3223643a91.23.1746530616613; Tue, 06 May 2025 04:23:36 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480ea0dsm13630303a91.37.2025.05.06.04.23.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 May 2025 04:23:36 -0700 (PDT) From: Yunhui Cui To: arnd@arndb.de, andriy.shevchenko@linux.intel.com, benjamin.larsson@genexis.eu, cuiyunhui@bytedance.com, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, ilpo.jarvinen@linux.intel.com, jirislaby@kernel.org, jkeeping@inmusicbrands.com, john.ogness@linutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, markus.mayer@linaro.org, matt.porter@linaro.org, namcao@linutronix.de, paulmck@kernel.org, pmladek@suse.com, schnelle@linux.ibm.com, sunilvl@ventanamicro.com, tim.kryger@linaro.org Subject: [PATCH v5 2/4] serial: 8250: avoid potential PSLVERR issue Date: Tue, 6 May 2025 19:23:19 +0800 Message-Id: <20250506112321.61710-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250506112321.61710-1-cuiyunhui@bytedance.com> References: <20250506112321.61710-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Failure to check the UART_LSR_DR before reading UART_RX, or the non-atomic nature of clearing the FIFO and reading UART_RX, poses potential risks that could lead to PSLVERR. Signed-off-by: Yunhui Cui --- drivers/tty/serial/8250/8250.h | 13 +++++++++ drivers/tty/serial/8250/8250_port.c | 43 +++++++++++++++-------------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h index b861585ca02a..6f97ff3a197d 100644 --- a/drivers/tty/serial/8250/8250.h +++ b/drivers/tty/serial/8250/8250.h @@ -162,6 +162,19 @@ static inline u16 serial_lsr_in(struct uart_8250_port *up) return lsr; } +/* + * To avoid PSLVERR, check UART_LSR_DR in UART_LSR before + * reading UART_RX. + */ +static inline void serial8250_discard_data(struct uart_8250_port *up) +{ + u16 lsr; + + lsr = serial_in(up, UART_LSR); + if (lsr & UART_LSR_DR) + serial_in(up, UART_RX); +} + /* * For the 16C950 */ diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index a913135d5217..1666b965f6a0 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1357,9 +1357,8 @@ static void autoconfig_irq(struct uart_8250_port *up) /* Synchronize UART_IER access against the console. */ uart_port_lock_irq(port); serial_out(up, UART_IER, UART_IER_ALL_INTR); + serial8250_discard_data(up); uart_port_unlock_irq(port); - serial_in(up, UART_LSR); - serial_in(up, UART_RX); serial_in(up, UART_IIR); serial_in(up, UART_MSR); serial_out(up, UART_TX, 0xFF); @@ -2137,25 +2136,22 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits) static int serial8250_get_poll_char(struct uart_port *port) { struct uart_8250_port *up = up_to_u8250p(port); - int status; + int status = NO_POLL_CHAR; u16 lsr; + unsigned long flags; serial8250_rpm_get(up); + uart_port_lock_irqsave(port, &flags); lsr = serial_port_in(port, UART_LSR); + if (lsr & UART_LSR_DR) + status = serial_port_in(port, UART_RX); + uart_port_unlock_irqrestore(port, flags); - if (!(lsr & UART_LSR_DR)) { - status = NO_POLL_CHAR; - goto out; - } - - status = serial_port_in(port, UART_RX); -out: serial8250_rpm_put(up); return status; } - static void serial8250_put_poll_char(struct uart_port *port, unsigned char c) { @@ -2264,13 +2260,17 @@ int serial8250_do_startup(struct uart_port *port) * Clear the FIFO buffers and disable them. * (they will be reenabled in set_termios()) */ + uart_port_lock_irqsave(port, &flags); serial8250_clear_fifos(up); /* - * Clear the interrupt registers. + * Read UART_RX to clear interrupts (e.g., Character Timeout). + * No data on UART_IIR_RX_TIMEOUT, UART_LSR_DR won't set. + * FIFO disabled, read UART_RX without LSR check, no PSLVERR. */ serial_port_in(port, UART_LSR); serial_port_in(port, UART_RX); + uart_port_unlock_irqrestore(port, flags); serial_port_in(port, UART_IIR); serial_port_in(port, UART_MSR); @@ -2429,15 +2429,14 @@ int serial8250_do_startup(struct uart_port *port) } dont_test_tx_en: - uart_port_unlock_irqrestore(port, flags); /* * Clear the interrupt registers again for luck, and clear the * saved flags to avoid getting false values from polling * routines or the previous session. */ - serial_port_in(port, UART_LSR); - serial_port_in(port, UART_RX); + serial8250_discard_data(up); + uart_port_unlock_irqrestore(port, flags); serial_port_in(port, UART_IIR); serial_port_in(port, UART_MSR); up->lsr_saved_flags = 0; @@ -2519,7 +2518,6 @@ void serial8250_do_shutdown(struct uart_port *port) port->mctrl &= ~TIOCM_OUT2; serial8250_set_mctrl(port, port->mctrl); - uart_port_unlock_irqrestore(port, flags); /* * Disable break condition and FIFOs @@ -2527,6 +2525,14 @@ void serial8250_do_shutdown(struct uart_port *port) serial_port_out(port, UART_LCR, serial_port_in(port, UART_LCR) & ~UART_LCR_SBC); serial8250_clear_fifos(up); + /* + * Read data port to reset things, and then unlink from + * the IRQ chain. + * Since reading UART_RX clears interrupts, doing so with + * FIFO disabled won't trigger PSLVERR. + */ + serial_port_in(port, UART_RX); + uart_port_unlock_irqrestore(port, flags); #ifdef CONFIG_SERIAL_8250_RSA /* @@ -2535,11 +2541,6 @@ void serial8250_do_shutdown(struct uart_port *port) disable_rsa(up); #endif - /* - * Read data port to reset things, and then unlink from - * the IRQ chain. - */ - serial_port_in(port, UART_RX); serial8250_rpm_put(up); up->ops->release_irq(up); From patchwork Tue May 6 11:23:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 888480 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 0786D27A939 for ; Tue, 6 May 2025 11:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530624; cv=none; b=ivR0NsuNuO7rpkU8pLfyNwB+Y9NepeEIPWnj+yXL6PfDTZCkPxhYLq+iPE6WGHxDH5XGBTN7/YErswbDt5gpmVGfcVQ23xugVjykmsOfImYk9hhQy3QLzPVSj03jPV3rUR6DR2fAo7V1ZpYKiBE8hgaQk3c3uiM1PNeeIQ+Jv6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530624; c=relaxed/simple; bh=Av1uBZ0UiDSTag4cG1ZoMvZ8Yr00ipFA4jvwEErTnds=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EfAoqxZLYmDDw4UYbF65f5mFwWH9I1RXBKyj7cGASAmO8jV3MvGLDw7pjgVMuceNI3nYo+sxCQgOfw070Ph/QzgRHODs4kSOr2hdCal88RSX2b+OpktY3ElcrgYRmuhq73mjV3Xm1cUhqKh3astdK56Mgj39D9XCgpBlw0C9uag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=fEq9TJii; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="fEq9TJii" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-3035858c687so4108944a91.2 for ; Tue, 06 May 2025 04:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1746530622; x=1747135422; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=gsFEelJoZFPGjqC5CS/HFrDUtUzRaRFJEqe02AReKwc=; b=fEq9TJiiO2Hu9aA0SLDWlxxe6EUhGygcZil5Du97iWC1VaUcRs2/y1Jldli9J3VNIt NnNtW0c7dHiRFjMaYzb4ifqjXMj70M7k4ysI75RqPUQEIacIxTjh4ZW85UbE+/wOeEJC 2c9rPiQRz7iFK1PjlKYG5SkRJNz/ODkta6M4nqn/ws5rOHJfACTXsh1TdBOZztINjxYr HSy9/v1oy7FWPSONNt8+Kk7+Gx2UDyv8uLMwCwvKIY6V5OEA2Z1x/EGOj+/ZopFUOID+ ebFzPJfLvvKEmEkovo3hEyOAo190DSrgdvpVu0nksYtqShpLSrMVzSkjuCZQElzZ8RxL CaFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746530622; x=1747135422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gsFEelJoZFPGjqC5CS/HFrDUtUzRaRFJEqe02AReKwc=; b=QdcIR0/2VXPLIon9SVE2TTtEmDMxaqyi8w2ehoaBpUCESHCktsxVEsUVm8Bkmf1UeR gxf/Ty37bXnN5QW1TkeM9TFpxztVM/jzkRPt80CcP+LVpBJTge5l5qyMvN7/NZJLGWFc iFAfmnrgIE/L4bgSEx8Sd2t+5afn34zrRJrATRyKEubGXZO+38z3rdlLhWvlxWDWtIFs ZjNrrbmianS1x2T3tTS8CsdA3WGWlOi22xprBbNR71C9GxnMqrTnfYhMOvH/EwyCzfaS wuvdJ1Cv1StxNw4/R+Pkok8x4oVmeZKUn6nT812z19EQiecAxhkdDjSM2mhpHTEGrNgi baEw== X-Forwarded-Encrypted: i=1; AJvYcCUoHgrye2uffEPYO6ODmRi756gCtV9RjbiGjKFVOYnfKaG6ZSAlZxnizWPLoJvGaXkAUHuuX2+0CbMWU+A=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1+s9oMEVRdhQHsKirbFnjGgSWU5xHLuoqRu6GbxTjutm8b7rU F9NantCT2eYHxNlWdX01Ru1SOXniRqhGWD+A4DDJvPCGGj8t3yuVXCUSNHaxlaQ= X-Gm-Gg: ASbGncs7FclW/GoQb1W2DD6fgKEOCzSb+P6NHGQXHMk3Kvae4fJpbFGPo0czFkyq1Mf COk4x29/o4Miu+zhqwcI/G65puIDXIGQOSvBpYjTUAe8khGtXp0JR7aJYnYJTze9hiTcGQdOKK5 pF774uCjW7Z/1YmznBtWe0fMMenD7qGfUCerooR3MBa38MN/KybRMRW1z3jrZshCB85nwMgFOO3 PbLh4HKneYqMTbyn2JzcRiDKTVB7sLYYMNweQgfypnIBTJtOohVaFQ8uLOAExyR4I464HdQuYsg bCyq3Bi4CzmIRMyjB5/E2M57aLotd/+xA1IQa7gpsA6obP5PRdIqFj6eAZccp/uBvHZYsi5K X-Google-Smtp-Source: AGHT+IGD8/c2V6FEHQXVuQcalLttyvnSCx1zvvLwGRwurqvvghvKHkpqr9RcWbomLqdZzObfVoBOpw== X-Received: by 2002:a17:90a:e188:b0:2fe:a545:4c84 with SMTP id 98e67ed59e1d1-30a61a7473bmr14100272a91.34.1746530622190; Tue, 06 May 2025 04:23:42 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480ea0dsm13630303a91.37.2025.05.06.04.23.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 May 2025 04:23:41 -0700 (PDT) From: Yunhui Cui To: arnd@arndb.de, andriy.shevchenko@linux.intel.com, benjamin.larsson@genexis.eu, cuiyunhui@bytedance.com, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, ilpo.jarvinen@linux.intel.com, jirislaby@kernel.org, jkeeping@inmusicbrands.com, john.ogness@linutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, markus.mayer@linaro.org, matt.porter@linaro.org, namcao@linutronix.de, paulmck@kernel.org, pmladek@suse.com, schnelle@linux.ibm.com, sunilvl@ventanamicro.com, tim.kryger@linaro.org Subject: [PATCH v5 3/4] serial: 8250_dw: warning on entering dw8250_force_idle unlocked Date: Tue, 6 May 2025 19:23:20 +0800 Message-Id: <20250506112321.61710-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250506112321.61710-1-cuiyunhui@bytedance.com> References: <20250506112321.61710-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Read UART_RX and check UART_LSR_DR in critical section. Unsure if caller of dw8250_force_idle() holds port->lock. Don't acquire it directly to avoid deadlock. Use lockdep_assert_held_once for warning. Signed-off-by: Yunhui Cui --- drivers/tty/serial/8250/8250_dw.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index af24ec25d976..f41c4a9ed58b 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -112,6 +113,13 @@ static void dw8250_force_idle(struct uart_port *p) struct uart_8250_port *up = up_to_u8250p(p); unsigned int lsr; + /* + * The serial_in(p, UART_RX) should be under port->lock, but we can't add + * it to avoid AA deadlock as we're unsure if serial_out*(...UART_LCR) + * is under port->lock. + */ + lockdep_assert_held_once(&p->lock); + serial8250_clear_and_reinit_fifos(up); /* From patchwork Tue May 6 11:23:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 888042 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.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 ABB4A279787 for ; Tue, 6 May 2025 11:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530630; cv=none; b=jKNeP8Z4zv5XP93ZQpx9P28FS6QTZ/Ya+yIokjNb2EbIBWUGvMZNavhk+DBbpLXZzaf5nHsCx9Hstl3Z8yFQbkccb5aCuEezHSCJr17AYTgCan3CIN9OprRhDDmFFS/TXte2y0Iu/j7awwPUDhnAd0dsEMM0kLlpKZMBWK7q5Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746530630; c=relaxed/simple; bh=tqLDKDef5O6cJ4keWnJtbG4x/2kNRBP1ukrtog92iYs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AxBGUcW2FjyN1wtOhmlzveLYHBLHB6xI73f0AxSdjKkIlkMzzmWaWd3zkg0kLzEs4Tf4fgS7jWoZSwLH15qBCUfX2p6sWh8ubZB48a1N54ZKPNgi233Ooe6xosODbPymCUZEfTk6eH/41L/1ds6szRdbMGZeRxbWsSK7/SFKw48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=XISo3Ikk; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="XISo3Ikk" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-30332dfc820so6424284a91.2 for ; Tue, 06 May 2025 04:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1746530628; x=1747135428; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BUMYg6viYOA1qi+ywdeJSO+n/kzbTJsKc7vLbt7F+/g=; b=XISo3IkkncqT0Uwe++4YFrS11kFHbkEmw6ZHlWyLtGrlKUGQwQk9XMK/2Vzxt981TU ULsVTRjifUjpp5bXTUjHtXOlIwH5Gav42hk8ENmisRxg/J5GHDx6qKQ3pj/zBFwEED/z gTOcZJL8zI83N+I2D5n29Wi7P6x/TOXVzeXaaMUeNR5DrhQzURUELZ6IQAKSuaVEo2kY 6kzTYmXMyxatPiEHwJQvqE/zzTxVOk90kr3JXrdKVhWn1QlOCUX7jfOIIfUIODqed4Vb MO0RCClJEEhOVL7ROJ7GuZdS5BH1Fc72pzHe/1iM01/QIg5UV81OpgGuNzNjmgohkX/S DobA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746530628; x=1747135428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BUMYg6viYOA1qi+ywdeJSO+n/kzbTJsKc7vLbt7F+/g=; b=gGpbHZ+/glqgrZ9OCFLQUyNeL6icRvAD5EZpkk3kgki5IWb3MIXb5sx8yT26B0Dw2h OgJ4z++Og38EXqO5rPXTKcQUhwUkMTUPbCZ2P7O68bHGlYneUif+ObtoBTzpX/BrJf8n V9PcMbJ2q/pG0qbTunXohLHFW4LUQXL4GcZdJL0Wn9MGGlVgltuZFt3i7YpGhBBprjx0 I7NoF82LtxKq5R1UVR7JiyOXv2OG4Ec2NxVQfLL6DSsscjebd+6h0DQKrAS1VrCXKcwL j4H4fNfc28JVwot44dwKtoPXk3HTUp0x7Lrdl6Cdtjq2UQAIexK1C5nZVvY1zivn5Rgs Zkqg== X-Forwarded-Encrypted: i=1; AJvYcCUxTHjZ7m/UTDd6MWkNm8RtY236TSVoNALaqBQYQv11IeLPIGd7WxaNnFQcTb2dT6Axt8alC4QwYrhnfJM=@vger.kernel.org X-Gm-Message-State: AOJu0YycSCV4IGr2EgsIhta37rs/0XGePkpzaxuMKJs/by/o2WNlhNsv RBuOzkRhBqrqYlR3EMQigguK+camXWI48afvodW1P0FK032pp3bPIz7ioIpDkiE= X-Gm-Gg: ASbGncsdMvYeyQmFhq7jvRSvmJ86ZZLEP4lIRMOIYkz7doJd93Tm/Lv03e+pLl7NXYW 16WxLmeCmuyYk5gdMM5qlK04jCsjNTq3+Z6utwLpWpr0ELn0/WquuKbudp3PlBDneoZL/CjN2dx WfWeclDQLZ5qU4ONbkegwYx4AHr48TDBxuBVl/kDYE6HrzTXDfwYNNC5atqFhh/4iANpcRw6OdA 2GdnGkxfQzgbVKPIMBw/AbapkjFiEi7ASKG3ifWysDIPtwtpYvP7ZECexOCe9FczhL2GobmzNSx +cQYqrgmGg6jSmqxV8oyv5XVBcFBM+iRqvKR0gc/PTgtVKzyeO7KR+wo9vNYFgcY8Geca7tBdjb 8LTNm1rQ= X-Google-Smtp-Source: AGHT+IFIpS3jKbFdovjmPaz6TQujDc77vnxGWRHeMmuNuGEMYq/uCxYu8Y3tDR8UjdI1Raunfojh2w== X-Received: by 2002:a17:90b:3909:b0:309:eb54:9ea2 with SMTP id 98e67ed59e1d1-30a7e1af162mr3039230a91.20.1746530627764; Tue, 06 May 2025 04:23:47 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.14]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30a3480ea0dsm13630303a91.37.2025.05.06.04.23.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 06 May 2025 04:23:47 -0700 (PDT) From: Yunhui Cui To: arnd@arndb.de, andriy.shevchenko@linux.intel.com, benjamin.larsson@genexis.eu, cuiyunhui@bytedance.com, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, ilpo.jarvinen@linux.intel.com, jirislaby@kernel.org, jkeeping@inmusicbrands.com, john.ogness@linutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, markus.mayer@linaro.org, matt.porter@linaro.org, namcao@linutronix.de, paulmck@kernel.org, pmladek@suse.com, schnelle@linux.ibm.com, sunilvl@ventanamicro.com, tim.kryger@linaro.org Subject: [PATCH v5 4/4] serial: 8250_dw: fix PSLVERR on RX_TIMEOUT Date: Tue, 6 May 2025 19:23:21 +0800 Message-Id: <20250506112321.61710-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250506112321.61710-1-cuiyunhui@bytedance.com> References: <20250506112321.61710-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the case of RX_TIMEOUT, to avoid PSLVERR, disable the FIFO before reading UART_RX when UART_LSR_DR is not set. Fixes: 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt") Signed-off-by: Yunhui Cui --- drivers/tty/serial/8250/8250_dw.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index f41c4a9ed58b..ffa8cb10b39c 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -288,9 +288,17 @@ static int dw8250_handle_irq(struct uart_port *p) uart_port_lock_irqsave(p, &flags); status = serial_lsr_in(up); - if (!(status & (UART_LSR_DR | UART_LSR_BI))) + if (!(status & (UART_LSR_DR | UART_LSR_BI))) { + /* To avoid PSLVERR, disable the FIFO first. */ + if (up->fcr & UART_FCR_ENABLE_FIFO) + serial_out(up, UART_FCR, 0); + (void) p->serial_in(p, UART_RX); + if (up->fcr & UART_FCR_ENABLE_FIFO) + serial_out(up, UART_FCR, up->fcr); + } + uart_port_unlock_irqrestore(p, flags); }