From patchwork Fri Jan 10 21:38:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 13935499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77615E77188 for ; Fri, 10 Jan 2025 21:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=iC3k1SZlNlarqOZELintr0r8/tkyMFglXXS2+edHzKk=; b=hTJIuwCuOY0xMP6ySZMJI3bllm JYqAzvpFVjh8u1dDk5+Xdad+/CkT/2+2hcSedHEOnYYgZjVlRUam7ZFhmZRgxwC/cWHXWjFCB/fmg VWNqshQeKxHVT6+g7Z5IeMXFJjoFALJYAijtdOJUjT0zn4peOYWr+hV4OeKY5hEMTunL+esu3vGLY n6Kdi97U3yGs/kwMPzWVFAV+GfKSY4fTaKHEBHXBdXpsRW0cVSBazii6gARJPG4yw904I5MbVMFyi cMedsZT/MnXns0B0/HTAgF4daKfp6IzS/HSmda7Gn45nijSyDxKQ26Oz8JeXR0vOTvbAygzNmNB0i gUbC/FDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tWMjR-0000000H2v8-3Fnc; Fri, 10 Jan 2025 21:39:53 +0000 Received: from out-187.mta0.migadu.com ([91.218.175.187]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tWMiD-0000000H2l6-0oIf for linux-arm-kernel@lists.infradead.org; Fri, 10 Jan 2025 21:38:38 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1736545109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=iC3k1SZlNlarqOZELintr0r8/tkyMFglXXS2+edHzKk=; b=Wva81Awwv8ENbIE/bgyPENEqbHTNL7iwNmGOtP50PP3xoef58qXCG690ciwFORmKWOkdrA FNQQVJ3dEzFR5l/R2SluGnP4Br//1R/g2BpGUpQFhiM0+NiikXAjGI5g6lNrvm9Vedt/b/ wGU6ue67daWJX2W5IWpOviA0bntRhrY= From: Sean Anderson To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Cc: Manikanta Guntupalli , linux-arm-kernel@lists.infradead.org, John Ogness , linux-kernel@vger.kernel.org, Michal Simek , Thomas Gleixner , Sean Anderson , stable@vger.kernel.org Subject: [PATCH] tty: xilinx_uartps: split sysrq handling Date: Fri, 10 Jan 2025 16:38:22 -0500 Message-Id: <20250110213822.2107462-1-sean.anderson@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250110_133837_560438_DF8BA0C6 X-CRM114-Status: GOOD ( 12.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org lockdep detects the following circular locking dependency: CPU 0 CPU 1 ========================== ============================ cdns_uart_isr() printk() uart_port_lock(port) console_lock() cdns_uart_console_write() if (!port->sysrq) uart_port_lock(port) uart_handle_break() port->sysrq = ... uart_handle_sysrq_char() printk() console_lock() The fixed commit attempts to avoid this situation by only taking the port lock in cdns_uart_console_write if port->sysrq unset. However, if (as shown above) cdns_uart_console_write runs before port->sysrq is set, then it will try to take the port lock anyway. This may result in a deadlock. Fix this by splitting sysrq handling into two parts. We use the prepare helper under the port lock and defer handling until we release the lock. Fixes: 74ea66d4ca06 ("tty: xuartps: Improve sysrq handling") Signed-off-by: Sean Anderson Cc: # c980248179d: serial: xilinx_uartps: Use port lock wrappers --- drivers/tty/serial/xilinx_uartps.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index beb151be4d32..92ec51870d1d 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -287,7 +287,7 @@ static void cdns_uart_handle_rx(void *dev_id, unsigned int isrstatus) continue; } - if (uart_handle_sysrq_char(port, data)) + if (uart_prepare_sysrq_char(port, data)) continue; if (is_rxbs_support) { @@ -495,7 +495,7 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id) !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS)) cdns_uart_handle_rx(dev_id, isrstatus); - uart_port_unlock(port); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -1380,9 +1380,7 @@ static void cdns_uart_console_write(struct console *co, const char *s, unsigned int imr, ctrl; int locked = 1; - if (port->sysrq) - locked = 0; - else if (oops_in_progress) + if (oops_in_progress) locked = uart_port_trylock_irqsave(port, &flags); else uart_port_lock_irqsave(port, &flags);