From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 34CE2176ADE; Wed, 19 Feb 2025 09:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739957331; cv=none; b=N4IZ1s7CrGMmUPKrljYP4ETDpcvDqWG61HYtdv5aV2htRWM5dXYNM4e8mrXcHvS1/2t/AJ0NYk5FWRVcHgm1ML9frhscmoXj2VZDYjHjGK+ePgsln3efq9WRzYMGCkoHRO8xmb4LlzhMetC3UJRu90ZoYSFEPmWY+XMVxpspH6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739957331; c=relaxed/simple; bh=Hx3U8OVe6EIeBYV8OjzgVEc7q49/fMaXdMVt17EZZ44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BGDs9S9J2cugxdRWJvkWKpfR5cngrqnJD/k4Gv0IXAmIB7LuDxpxLGbOBEk/92/Yg589R7YD7Y84cVzwe5Ib3Nqg5ckdAL0wWKF+c8s1yhFo1R/aHpBUCpYq31XB7Egj1+a/E3/aRLBtsn3EDgemrAyW6WFxAgocmKMxUf6kj+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UY+5DZsf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UY+5DZsf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3BFBC4CED1; Wed, 19 Feb 2025 09:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739957331; bh=Hx3U8OVe6EIeBYV8OjzgVEc7q49/fMaXdMVt17EZZ44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UY+5DZsf6lRp2IqYNGFR6q5u6a7Uu7xMix1+xlmiLIoJnS+7q9emogog2g3z6cQPW 30Tl1Mv70cUnZ6ecporP/YMqV/yxSWeF+sO/WVpeFxiGlb6ux0HjT1/ifqtIb1CSM1 DJo8DFbhRfopmpJlcErvJRVFZegb/TUEhP9J5zEk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sean Anderson , John Ogness Subject: [PATCH 6.1 456/578] tty: xilinx_uartps: split sysrq handling Date: Wed, 19 Feb 2025 09:27:40 +0100 Message-ID: <20250219082710.932717929@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Anderson commit b06f388994500297bb91be60ffaf6825ecfd2afe upstream. 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: stable@vger.kernel.org # c980248179d: serial: xilinx_uartps: Use port lock wrappers Acked-by: John Ogness Link: https://lore.kernel.org/r/20250110213822.2107462-1-sean.anderson@linux.dev Signed-off-by: Sean Anderson Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/xilinx_uartps.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -268,7 +268,7 @@ static void cdns_uart_handle_rx(void *de continue; } - if (uart_handle_sysrq_char(port, data)) + if (uart_prepare_sysrq_char(port, data)) continue; if (is_rxbs_support) { @@ -371,7 +371,7 @@ static irqreturn_t cdns_uart_isr(int irq !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS)) cdns_uart_handle_rx(dev_id, isrstatus); - spin_unlock(&port->lock); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -1231,10 +1231,8 @@ static void cdns_uart_console_write(stru unsigned int imr, ctrl; int locked = 1; - if (port->sysrq) - locked = 0; - else if (oops_in_progress) - locked = spin_trylock_irqsave(&port->lock, flags); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); else spin_lock_irqsave(&port->lock, flags);