From patchwork Fri Mar 1 21:45:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777626 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0BAE122098 for ; Fri, 1 Mar 2024 21:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329973; cv=none; b=F5uXah8EfedmjyWamTj0v32RfmVtzduuARDbrfj7uMdxtZccEa5ezwEifZF2WoOSAwhPlu3RkzKie0PSB4Xa4Ws0j/BJsZ+RJwe0hDVryNl66j+vFOELIJusIozZOeVuOWp7kJ/WZP9tsiXonfZSzr6nQhltF8+ez2SG2Jmk3XE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329973; c=relaxed/simple; bh=y5xpoIyunCZo8pZWw66B7Bmm7D6Ggt2M2grbviX3iKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n5GZvA5XJI0ieL93Qd1C8dSErRSe2ASUga8msO0i82c5AtkDctHPeI3sfXE/44fA7SoDvttNEj8btZa5iHVOUV/RdE67cb05hEESfBDBOMekXRIJ8A8J4d1EG4URQVzbsp7zZRhjpKI0oObGL4ndFnu3HOZP4uIRunMcVvXUAgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OuM36w8/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1GF65Qo8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OuM36w8/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1GF65Qo8" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=uU/09Z2yXckVBdWhsFvdpwmXoXppERpLDZbklHxaGSY=; b=OuM36w8//gkcAhmojG/EfnkCSaY1NFYmUiYENAS28cc0ptuD+0hhwdY2a3tSEnFxwfkQiB 6RUBdGiufq6wTCL7DmMMLhSCSo6ue6W8ef12wznrHV6GXj4As1+WdX5fC9NZ3NdYtZ5Gpl nz7EUZ5zgYzLS3inOqSdUg0+t/P8ERGORawSWDBidoRlYhpSyitLhL0tivAvHzXB8+2Aiq 7zIOaD5zaGy3xKM5Md6mbmA85hePlAgHzYJ3PVt4HLNyH23+MAC5Iwf+cH8ofOaAQS3q3Y rUJrBfA9MgFXxAk85btf58BaeOl6KNfw1oiyaMVf/aXaIM9tcTq8EzH+EU6cFQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=uU/09Z2yXckVBdWhsFvdpwmXoXppERpLDZbklHxaGSY=; b=1GF65Qo8mo4mV/D68HUFJ/RZLwfPAj9ndnJW4tFgRtzWcNEZqjoFVm1awscLVMb/QJUE85 sW4psdEEbW6dUQAg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Russell King Subject: [PATCH 01/18] serial: amba-pl011: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:14 +0100 Message-ID: <20240301215246.891055-2-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Russell King Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/amba-pl011.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index cf2c890a560f0..2fa3fb30dc6c7 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -348,10 +348,7 @@ static int pl011_fifo_to_tty(struct uart_amba_port *uap) flag = TTY_FRAME; } - uart_port_unlock(&uap->port); - sysrq = uart_handle_sysrq_char(&uap->port, ch & 255); - uart_port_lock(&uap->port); - + sysrq = uart_prepare_sysrq_char(&uap->port, ch & 255); if (!sysrq) uart_insert_char(&uap->port, ch, UART011_DR_OE, ch, flag); } @@ -1017,7 +1014,7 @@ static void pl011_dma_rx_callback(void *data) ret = pl011_dma_rx_trigger_dma(uap); pl011_dma_rx_chars(uap, pending, lastbuf, false); - uart_port_unlock_irq(&uap->port); + uart_unlock_and_check_sysrq(&uap->port); /* * Do this check after we picked the DMA chars so we don't * get some IRQ immediately from RX. @@ -1540,11 +1537,10 @@ static void check_apply_cts_event_workaround(struct uart_amba_port *uap) static irqreturn_t pl011_int(int irq, void *dev_id) { struct uart_amba_port *uap = dev_id; - unsigned long flags; unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; int handled = 0; - uart_port_lock_irqsave(&uap->port, &flags); + uart_port_lock(&uap->port); status = pl011_read(uap, REG_RIS) & uap->im; if (status) { do { @@ -1573,7 +1569,7 @@ static irqreturn_t pl011_int(int irq, void *dev_id) handled = 1; } - uart_port_unlock_irqrestore(&uap->port, flags); + uart_unlock_and_check_sysrq(&uap->port); return IRQ_RETVAL(handled); } @@ -2322,13 +2318,10 @@ pl011_console_write(struct console *co, const char *s, unsigned int count) clk_enable(uap->clk); - local_irq_save(flags); - if (uap->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&uap->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&uap->port, &flags); else - uart_port_lock(&uap->port); + uart_port_lock_irqsave(&uap->port, &flags); /* * First save the CR then disable the interrupts @@ -2354,8 +2347,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count) pl011_write(old_cr, uap, REG_CR); if (locked) - uart_port_unlock(&uap->port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(&uap->port, flags); clk_disable(uap->clk); } From patchwork Fri Mar 1 21:45:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777339 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4EBEF57873 for ; Fri, 1 Mar 2024 21:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; cv=none; b=njE4XDmXzoNifH+sjETCAonmObSkoTRMB0aamv1b3lj62ft225QF1ctLqLqvjv8k2fLSgwUW3QGFgMp93kjnWN4TuNA0El2mUSuu8bcENUH2CE9wSGXWprJdkfFtg0PlHhmHGrDmpJlxpe1hC60CygAcjg9vbpVJOrWz0rxKIKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; c=relaxed/simple; bh=vt9PBEtGbohZDGrGc4PLnmYjZUk1n9QtGVrTPVAxhyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ai5+/eww/pkCYErGrpcleZx9RM1LqJZZRdudblMClLD04SFsKrcjpW0ZeL2U+bKrK2Iw2ZGaEtYHDYMhXEpfowMH1RTQtjLr/TKC8ZqnOIHHaGvA/MkJpO8GW2kGzttSXTCjmrctdrelDAH+C2bhw+50J2TzfxCbWLKCLsGHWNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gsXiTTmu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GfLsnBuT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gsXiTTmu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GfLsnBuT" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=r0wQNW0zEI8swe9n40nxYYuKvTQNfbOQZBPRnKtnIEk=; b=gsXiTTmuxhZpmQOghewy9Y617Dl1pm1ASBlUnSBMW1bJ2hxAUG8LlcsBiT41dYGR0gwk+g zR2+rxmmUAOJ64baRHrlo6BVpBcH0yPxBcHyIQT+xoXJCQaH8cnLRPT5WAFFaPR+wv7QU9 vn1WQ0zt8RlRkHoXLIgrdM1Tqz2VHfG9v6U/zZL6uLz0OmiX8csNVij9ydDn8KHkBQ6Nr7 sNplJ3mn6hXB2V6IQeeGOc1BIGwYVBj+g57xr2egoX+vNW60l2yepn2RIfVhQG7OLzYqJo GJgRgEZNvhSYSzlBTRR8rQvMJfSeHZ/2Mh3ygzqgfC+YDXsz41ehDbsjdOCRkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=r0wQNW0zEI8swe9n40nxYYuKvTQNfbOQZBPRnKtnIEk=; b=GfLsnBuT4TCymPLvf91/y2bIaxkF68ngJeoYhNqf67Blhgmp6GohAhSi7d+eA1AI6h2GWr P+C1ylMMh2QKbhDg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 02/18] serial: ar933x: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:15 +0100 Message-ID: <20240301215246.891055-3-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/ar933x_uart.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_uart.c index 8d09ace062e59..7790cbc57391a 100644 --- a/drivers/tty/serial/ar933x_uart.c +++ b/drivers/tty/serial/ar933x_uart.c @@ -378,7 +378,7 @@ static void ar933x_uart_rx_chars(struct ar933x_uart_port *up) up->port.icount.rx++; ch = rdata & AR933X_UART_DATA_TX_RX_MASK; - if (uart_handle_sysrq_char(&up->port, ch)) + if (uart_prepare_sysrq_char(&up->port, ch)) continue; if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0) @@ -468,7 +468,7 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id) ar933x_uart_tx_chars(up); } - uart_port_unlock(&up->port); + uart_unlock_and_check_sysrq(&up->port); return IRQ_HANDLED; } @@ -627,14 +627,10 @@ static void ar933x_uart_console_write(struct console *co, const char *s, unsigned int int_en; int locked = 1; - local_irq_save(flags); - - if (up->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&up->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&up->port, &flags); else - uart_port_lock(&up->port); + uart_port_lock_irqsave(&up->port, &flags); /* * First save the IER then disable the interrupts @@ -654,9 +650,7 @@ static void ar933x_uart_console_write(struct console *co, const char *s, ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS); if (locked) - uart_port_unlock(&up->port); - - local_irq_restore(flags); + uart_port_unlock_irqrestore(&up->port, flags); } static int ar933x_uart_console_setup(struct console *co, char *options) From patchwork Fri Mar 1 21:45:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777340 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 8EC9958ABA for ; Fri, 1 Mar 2024 21:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; cv=none; b=oKkoKvZW8LtvkVxjRI5lIo8QuWAWaNoEvUE/YfX6gTyw0By5btWCDcGbrMNPzv8WY1Ur9q+10bcTlX7xbnsYB0B/MHJ8uoQCRIYdhgYMYBDLmvmUCQ3dqrJCup1vHrcmsJasr0xfLPXOBQozafFMIyW56LsF0LYjmVAN+auUuP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; c=relaxed/simple; bh=A0Sl0tlJDQ4HRDzIJ/leO1z/5F4WjWEu3jha+E8ggsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NViKvsB8mZNK5/fRFD3dgGFihp7TkFvwpXbuWIqP+mGw+U4+fsbjmRQIK79SYbUnbAxqlXvyw3+01ThxUrtPjng0jdjckG9lZ44Lh3mIJTs6sbZha078bZ2Dm5w9zm/QNCQj3hCMSilTai5DdfQq1umVT4DrzdgLAXdlrJlPT1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LJkVeVlz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/IvfRVUa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LJkVeVlz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/IvfRVUa" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=YIqFu/AADtWHsa2rj/FvPzDKlVU7ecbiMypUuA2TtPA=; b=LJkVeVlz6WczQ2ZtyWamJTorAMNcNKrme/ofxnWL7OhIZCYQCGVnzELmHZKFOxF8la5mIn 3Zbw53AEx6atAj223AulIn6zF6H+qS+tAQ9dX/UXx6Mw+Mqe+ihoMKDA/WMOy9lXyonVWL eLfbCD3bPW/Qmx1y2abAYvriF3QXHIDJQNhyG+kLvAOONxNmSZtodpa9SWv9rxUQ5DzZnw 1S45MU9pfXSr6/xFaiBMRsX2vxht7bLxQVOPCyVxtBtbVaOOvG2xMTHoyQU6kfY4OWmo+L PLC6ZBKoI2LrIgMbspKM8CtVU5y5MmCnxYA8WrpUNRnu8xj9QWfd5K+QiSHhLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329970; 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: in-reply-to:in-reply-to:references:references; bh=YIqFu/AADtWHsa2rj/FvPzDKlVU7ecbiMypUuA2TtPA=; b=/IvfRVUa7UMPx9bEPcu7lqfzoDyoFpIjZL+j/rfBa8vduINCAKBi7F60JxkqJ2md9X50UL oe+1fU4c5yfLRODw== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 03/18] serial: bcm63xx: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:16 +0100 Message-ID: <20240301215246.891055-4-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/bcm63xx_uart.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c index a3cefa153456d..34801a6f300b6 100644 --- a/drivers/tty/serial/bcm63xx_uart.c +++ b/drivers/tty/serial/bcm63xx_uart.c @@ -285,10 +285,9 @@ static void bcm_uart_do_rx(struct uart_port *port) flag = TTY_PARITY; } - if (uart_handle_sysrq_char(port, c)) + if (uart_prepare_sysrq_char(port, c)) continue; - if ((cstat & port->ignore_status_mask) == 0) tty_insert_flip_char(tty_port, c, flag); @@ -353,7 +352,7 @@ static irqreturn_t bcm_uart_interrupt(int irq, void *dev_id) estat & UART_EXTINP_DCD_MASK); } - uart_port_unlock(port); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -703,20 +702,14 @@ static void bcm_console_write(struct console *co, const char *s, { struct uart_port *port; unsigned long flags; - int locked; + int locked = 1; port = &ports[co->index]; - local_irq_save(flags); - if (port->sysrq) { - /* bcm_uart_interrupt() already took the lock */ - locked = 0; - } else if (oops_in_progress) { - locked = uart_port_trylock(port); - } else { - uart_port_lock(port); - locked = 1; - } + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); /* call helper to deal with \r\n */ uart_console_write(port, s, count, bcm_console_putchar); @@ -725,8 +718,7 @@ static void bcm_console_write(struct console *co, const char *s, wait_for_xmitr(port); if (locked) - uart_port_unlock(port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(port, flags); } /* From patchwork Fri Mar 1 21:45:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777625 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 8EC3258AA5 for ; Fri, 1 Mar 2024 21:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; cv=none; b=LvbemLDUYrOGzlGCD+lCxbn06PCOP17bU8gJO6HN4D37RnVm711raok9w8yg7/n/ZnOSE1lrObs1NzuNNwDNx81pguqFChqw5Mmj6YTyso58q+8m0HEtBY1xILC1Oro/5b2JDlZPYYyB937C8JJ4Ucb4+BKuNSAR+gPZFY/rJr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329974; c=relaxed/simple; bh=1BfFvTW+7SYkzGkk18cHNE5iV+AG5gRxV2fSbGLrLko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=juZRKtV0028bWpe5kIosgAQobrtYElJ5Ty48H2wsixkbcp2onhn2xSbB/WtXo1JvK74dqm54PMH71BYx3XO6ATRs2fyI8LNnFWJdOEIdzofP4DrZC/3ovkt5qm4heCx1l8noUKCXi9R7643diQ6T/m17O0JnzNoiwb2TTct5NXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w/6JWsip; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=U6vXNia4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w/6JWsip"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="U6vXNia4" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=H7r1ch2QCFOhprkBXp7qfcKOLIETYbzIerJUqrI061g=; b=w/6JWsipW/VNMSxnbJX8VayPbqNtoFevsHC0HxJHEM28w+pOSJYMStG5tGBURutPNa4Uv0 /Cdk7vy072Gsb8Ga/umkx9aOc0YCPdGtWI1uVIW4fHv+cuPTX57Fn0qo5FHPOagxmzEG9H wzlTGQ7okWDu7DSN+rXSTJxBaKZOqMEj34b9ZSeN1/2Ya5YReELIZ0xNy+wJyqWYK/osTF SKdHBUN0LXR8q46lK6ct0VxQoC8yzA2yVsnvoKAz1ciiQ20MrQdB7ECNOY+ANq+hSsB1Pz yKTTBP7wIDSBkwlrFUr/veUFOkNIpEHSiXAXYsBDnZMqq4NtZIqfB495vBRhsQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=H7r1ch2QCFOhprkBXp7qfcKOLIETYbzIerJUqrI061g=; b=U6vXNia4v+kROl9sdz8uXe84USxD/w5gbTSFDQcdI6uy01AQNDumm3pKag2zc2pDX3elqF pAsAVrjwYp95xZDA== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Kevin Hilman , Jerome Brunet , linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH 04/18] serial: meson: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:17 +0100 Message-ID: <20240301215246.891055-5-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Kevin Hilman Cc: Jerome Brunet Cc: linux-arm-kernel@lists.infradead.org Cc: linux-amlogic@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/meson_uart.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index 8395688f5ee92..6feac459c0cf4 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -220,7 +220,7 @@ static void meson_receive_chars(struct uart_port *port) continue; } - if (uart_handle_sysrq_char(port, ch)) + if (uart_prepare_sysrq_char(port, ch)) continue; if ((status & port->ignore_status_mask) == 0) @@ -248,7 +248,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *dev_id) meson_uart_start_tx(port); } - uart_port_unlock(port); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -556,18 +556,13 @@ static void meson_serial_port_write(struct uart_port *port, const char *s, u_int count) { unsigned long flags; - int locked; + int locked = 1; u32 val, tmp; - local_irq_save(flags); - if (port->sysrq) { - locked = 0; - } else if (oops_in_progress) { - locked = uart_port_trylock(port); - } else { - uart_port_lock(port); - locked = 1; - } + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); val = readl(port->membase + AML_UART_CONTROL); tmp = val & ~(AML_UART_TX_INT_EN | AML_UART_RX_INT_EN); @@ -577,8 +572,7 @@ static void meson_serial_port_write(struct uart_port *port, const char *s, writel(val, port->membase + AML_UART_CONTROL); if (locked) - uart_port_unlock(port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(port, flags); } static void meson_serial_console_write(struct console *co, const char *s, From patchwork Fri Mar 1 21:45:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777337 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2A3AA57873; Fri, 1 Mar 2024 21:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=fkky0ttq57w3oJDRlganBj2UrtzlIzd1eS3dJWeh4aRD8kPfKjTP6ZvAM4hTL0m9LWIacZf0EVEEypwVBRBfJrAiOXLfcVimqwUBOINhHE5rdph+c5TJLIcDaOOvsKTVLWL8pDHZBCn7l2LJeMutDjI7qUXJzKNt8IfWhn4vSV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=ZSHo7yW56q/OlHOuR8ZSf19ghp6NekGXo4YcajF/HdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fqMsUW3/K5+3re97vCiS/ETufMD3bq2cMpqqKg2wAc1pbnwS+/pOrjQApdNLNxxpUj5Sp9KYVeFv7pdo7gnR3nmME15ZDs0zE4aYD6pDa3ZNYw8Ayh09tPT3lfhgxWooTbdTl6T8JUF0qqjU73OXsn3TfUNhd1sPfQSzR2U/vdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hPVorvr4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/KYP3h6W; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hPVorvr4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/KYP3h6W" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=XmPH4B4axTpKo5FxjSK3NcariRNbGHfCM6HFELDE+lQ=; b=hPVorvr4HEx95TVYMIAgH+mUMaPHgAkQKpg/1R+JW9QNsO6/wzm/AaCImUQAhvuv1GSowQ x4qCesKySc7anz3pLghuyOr5uePiwGPQOS4HuMO0+XrVDsUHnWBWHIvBzMehjHTvVut95B 4JeGs5GZWq1BDTjx57BgEetqBGJIpJvmLpeyPUHC1uLa+JvmodKSVl5QyUgvm+bzgOsy/8 TaAryy8aCFxeiiG3jcRJ+DJXGuuFDn47XXW466vBH3zj7E/GTO9psU3VehjYE7f0hbZ6f/ E0266TCHeosRsZUPRsunaI0Nw6DXVpDKnXIQustsXLyZSZ8ZOArEfxiQ/IdlBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=XmPH4B4axTpKo5FxjSK3NcariRNbGHfCM6HFELDE+lQ=; b=/KYP3h6W869OPAT3O4R56gPNrKlXFktxAb3iKcn1GjGPj1waQH6kBcx/CIFWeKlTQWB06/ X9pH9Nj4rJbfmNBw== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Bjorn Andersson , Konrad Dybcio , linux-arm-msm@vger.kernel.org Subject: [PATCH 05/18] serial: msm: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:18 +0100 Message-ID: <20240301215246.891055-6-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Bjorn Andersson Cc: Konrad Dybcio Cc: linux-arm-msm@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/msm_serial.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index e24204ad35def..d27c4c8c84e13 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -588,16 +588,14 @@ static void msm_complete_rx_dma(void *args) if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) flag = TTY_NORMAL; - uart_port_unlock_irqrestore(port, flags); - sysrq = uart_handle_sysrq_char(port, dma->virt[i]); - uart_port_lock_irqsave(port, &flags); + sysrq = uart_prepare_sysrq_char(port, dma->virt[i]); if (!sysrq) tty_insert_flip_char(tport, dma->virt[i], flag); } msm_start_rx_dma(msm_port); done: - uart_port_unlock_irqrestore(port, flags); + uart_unlock_and_check_sysrq_irqrestore(port, flags); if (count) tty_flip_buffer_push(tport); @@ -763,9 +761,7 @@ static void msm_handle_rx_dm(struct uart_port *port, unsigned int misr) if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) flag = TTY_NORMAL; - uart_port_unlock(port); - sysrq = uart_handle_sysrq_char(port, buf[i]); - uart_port_lock(port); + sysrq = uart_prepare_sysrq_char(port, buf[i]); if (!sysrq) tty_insert_flip_char(tport, buf[i], flag); } @@ -825,9 +821,7 @@ static void msm_handle_rx(struct uart_port *port) else if (sr & MSM_UART_SR_PAR_FRAME_ERR) flag = TTY_FRAME; - uart_port_unlock(port); - sysrq = uart_handle_sysrq_char(port, c); - uart_port_lock(port); + sysrq = uart_prepare_sysrq_char(port, c); if (!sysrq) tty_insert_flip_char(tport, c, flag); } @@ -948,11 +942,10 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) struct uart_port *port = dev_id; struct msm_port *msm_port = to_msm_port(port); struct msm_dma *dma = &msm_port->rx_dma; - unsigned long flags; unsigned int misr; u32 val; - uart_port_lock_irqsave(port, &flags); + uart_port_lock(port); misr = msm_read(port, MSM_UART_MISR); msm_write(port, 0, MSM_UART_IMR); /* disable interrupt */ @@ -984,7 +977,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) msm_handle_delta_cts(port); msm_write(port, msm_port->imr, MSM_UART_IMR); /* restore interrupt */ - uart_port_unlock_irqrestore(port, flags); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -1621,14 +1614,10 @@ static void __msm_console_write(struct uart_port *port, const char *s, num_newlines++; count += num_newlines; - local_irq_save(flags); - - if (port->sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); else - uart_port_lock(port); + uart_port_lock_irqsave(port, &flags); if (is_uartdm) msm_reset_dm_count(port, count); @@ -1667,9 +1656,7 @@ static void __msm_console_write(struct uart_port *port, const char *s, } if (locked) - uart_port_unlock(port); - - local_irq_restore(flags); + uart_port_unlock_irqrestore(port, flags); } static void msm_console_write(struct console *co, const char *s, From patchwork Fri Mar 1 21:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777624 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2A3E758AD1 for ; Fri, 1 Mar 2024 21:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; cv=none; b=S0nVjkn7e+0SlYcuK0w+Q8wgtKzTL+s92nHZiLQx2f2T4sej8IGPlqBNUDiPffTV2wFnQl04I3orTql5UmUTlvbxLQ0DynY1XZcz7KiXYF3/Hd8VCZcXTunonffWCjyaI44ZVbfFTMRliiaP4ejHd0grEB8SoN2eXQMuacux8YU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; c=relaxed/simple; bh=d0+vsfDJBJUqS2Fkhl3INsvp+GpH/URMcC4GhMT1Fgc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KB+UrLuUbsKejkR/JeA/IXzvec3xLl4dTL2IYLnBH3zikqBNMlD3BUllkIxI44laVJe9Iag0ClnBRpDRtNdJeZbK0cQ6dpLwKLlWCBFZRZuU1+AQSy+tOvigyeNHdRWYz0r+HBDltfugA7TsfZrPxxxxTmy8sU15yEjndkOTP28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=btylfPwW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5S1ziX4Z; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="btylfPwW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5S1ziX4Z" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=neIqKSHS/D/i5nWAr8RrJwghx1+ApKIn7UCJC7a4zDI=; b=btylfPwWS9W4OhA7XC7wc2BZuaBJ7KjLDHmIDK9/iQlLfh8DtSq8ZJnxWWSs50h/nmjqaG VeYJoS+++sbC4Jxc0NNKxTRC0Hqg1WBJmxOni05IPfsO+2a8pv1qU3v4cFz3/yfLAvmLqH NMdOrjHmMdhlQ+JdiFBCLhsQ0zCIwUpOCdBwoFfx/5SVIsWg2gK4b2mvmx6ekaxWNQ8pf1 L2lxxxt9JaLtLKK40PJUd/LbX0TuMIZoqfBuw5aVcc/IgxhtSY4L3J7phaqlUUAMojUcZZ e/gXEaeS9s0o4W8TtVQg7K3lGew4qZimwvlSrdOxvLKgiZs5lrnEITB+W5jw7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=neIqKSHS/D/i5nWAr8RrJwghx1+ApKIn7UCJC7a4zDI=; b=5S1ziX4ZKs4Y/mf1jyZJiT7B2ElYQ1p2EVaXdPDGya0A/BwtKZZhUsxdxjNgxkeJ3Siymg uY/BeBEDnSZszoCQ== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 06/18] serial: omap: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:19 +0100 Message-ID: <20240301215246.891055-7-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/omap-serial.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index f5a0b401af63b..9be1c871cf116 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -508,7 +508,7 @@ static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr) up->port.icount.rx++; - if (uart_handle_sysrq_char(&up->port, ch)) + if (uart_prepare_sysrq_char(&up->port, ch)) return; uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, TTY_NORMAL); @@ -563,7 +563,7 @@ static irqreturn_t serial_omap_irq(int irq, void *dev_id) } } while (max_count--); - uart_port_unlock(&up->port); + uart_unlock_and_check_sysrq(&up->port); tty_flip_buffer_push(&up->port.state->port); @@ -1212,13 +1212,10 @@ serial_omap_console_write(struct console *co, const char *s, unsigned int ier; int locked = 1; - local_irq_save(flags); - if (up->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&up->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&up->port, &flags); else - uart_port_lock(&up->port); + uart_port_lock_irqsave(&up->port, &flags); /* * First save the IER then disable the interrupts @@ -1245,8 +1242,7 @@ serial_omap_console_write(struct console *co, const char *s, check_modem_status(up); if (locked) - uart_port_unlock(&up->port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(&up->port, flags); } static int __init From patchwork Fri Mar 1 21:45:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777623 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4105958AD4 for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; cv=none; b=bXsF0LN2mHHHWcnFpb0VMPyUjgWZj9zlBt5rW0gCnPF8z+0eqy8ZioutNd45Hv2u/kOeUJ7ngmrAo0Mch8y8mjFx3wA9xa5FjiInLLa/qu9y0uJTT1nQUqtPZp+v2RbbSHXEsqLTVmqq05C6Lm/a+bXvJLUhjF61OYrPTQ0kmG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; c=relaxed/simple; bh=Duj6Luz9qImDdou3gmsCC4s4kjyfZoeFPrWjuFz0b+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PiUdNTwlgya01ngWNL835kR9WJevuMKmQb7lHY39VuSZJDcR9vJ5qqDWoV7Ey0R7dj2E+JFrCKtkTgYQkufq/kMZpozfXZ4nzLjqWZTY1uhtV1wGC4rISgK9FcjdDW0b+N8YasauBye4/qoex/cUYS6e4KCsm02YjLtbgcIBXYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mcB7Yyax; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bogcD9kt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mcB7Yyax"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bogcD9kt" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=gTkKclahS1ExJZZt5oqxL5Ekjnu0SVXe0SPP0GVKmbk=; b=mcB7YyaxVUtCyFzFBd/GhDnjelnRqTpIs8hg0Gb3VA3PWtd21e8fFG8ne8u/L1nIJvlJaM UxVBab17CXO/BmikROOpRH9O0cQMtMHxHa00QUfvmYEWZ2WMyIG/6+it2AwpshyoUGcU48 Ci0mFLioKgBqCwKzc5Tyauta+J1Ev7xw0UURc9eVwqP38Cs1zbHBCcQRXuOS6JBlH5WLAI oKLar+MjnPHnXK2gzI+HWkhLGQCMMWFfBmFuktYIBI1zJfMwnIhJhkIOrSCu9j8qVZEmn6 2KyKq6LlW149ZBjOiskmZXzMz9yZahQHl4Y+OQv3E2Reb3SYU6dux6ygqut17Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=gTkKclahS1ExJZZt5oqxL5Ekjnu0SVXe0SPP0GVKmbk=; b=bogcD9ktH+t2AfDh7+fFHbWHIi+KV6nnU2eDs6c9BMfhRki33Mjz4wwgVIBXd5wnM3frsY iJJxNTphhwSgWCBA== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 07/18] serial: pxa: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:20 +0100 Message-ID: <20240301215246.891055-8-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pxa.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c index 46e70e155aab2..e395ff29c1a2c 100644 --- a/drivers/tty/serial/pxa.c +++ b/drivers/tty/serial/pxa.c @@ -151,7 +151,7 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status) flag = TTY_FRAME; } - if (uart_handle_sysrq_char(&up->port, ch)) + if (uart_prepare_sysrq_char(&up->port, ch)) goto ignore_char; uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); @@ -232,7 +232,7 @@ static inline irqreturn_t serial_pxa_irq(int irq, void *dev_id) check_modem_status(up); if (lsr & UART_LSR_THRE) transmit_chars(up); - uart_port_unlock(&up->port); + uart_unlock_and_check_sysrq(&up->port); return IRQ_HANDLED; } @@ -604,13 +604,10 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count) int locked = 1; clk_enable(up->clk); - local_irq_save(flags); - if (up->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&up->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&up->port, &flags); else - uart_port_lock(&up->port); + uart_port_lock_irqsave(&up->port, &flags); /* * First save the IER then disable the interrupts @@ -628,10 +625,8 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count) serial_out(up, UART_IER, ier); if (locked) - uart_port_unlock(&up->port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(&up->port, flags); clk_disable(up->clk); - } #ifdef CONFIG_CONSOLE_POLL From patchwork Fri Mar 1 21:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777338 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 410AB58AD7 for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; cv=none; b=UCbGvVPNvSXizEPxqVdAs90EM1KT1KgUxX46LYjoCwwWENJ+O0B4U8KyfyhigcxgA1lTkz+nzGtMFKKux+g12ipfY90fsEH+ww7Jjr0sbdDF51Zhin+LV8Y4H6UIyZA+LhnLARUraTC8WjWXi9TRbYSuaviLKJCtGwH8oJDtm0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329976; c=relaxed/simple; bh=PV8zmysWU6NKef6+WG93PWkFDYIEgZyYBwnADe5OGvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R4PchC9r8tToCvatV1uZxCu7+L9iOO2Cv+51Y2WoGgWOUkv41C9yJ+SrO9lCcWbOBNVfWVi5M4CGu5HugwVCuZTjM5lAcUlcrvnGw1V/aCmp9N3vBDGYteE4poOlpOck3iSfEV8hCuhnolno+jD8d3IpXeBuchFjtCU5isrAkTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=l8BPYWC+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3SuRw3NY; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="l8BPYWC+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3SuRw3NY" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=zfrtyH8jEy/aviKS2/H/q8f4mQwnYfUS4DMZuSDZ9aI=; b=l8BPYWC+G0hKGAoMf9J8gp8c1QtpaO+6hGYFV1EQOp8xpqJI6Lhegfm3GPzNlGecjKzKqX Kx/Lo14Gi7k6Fi4rJiGWQTZgfMER8UcDB4K2JFa4kqNmenLX1lWLKhgqqSlFgceSQDG28H fq+Wqm0DJHhw2fmLq7oBfmM721WXZYJ5u2FYmDSjbcgiIJEOltTPtZ5v2UjC0RhxFdjgND KI+aMjU5j5efVOIppxH8O4zjosJSGRwtW+LSOUKSGYcJMbO81MzhL00bq+UTdudKWFGcjy RFvt5d/aNc3Cf2pR2K5SvKXK/okl7k9TixKR9uyie99itYKoo5ZnFXdgtIvv4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329971; 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: in-reply-to:in-reply-to:references:references; bh=zfrtyH8jEy/aviKS2/H/q8f4mQwnYfUS4DMZuSDZ9aI=; b=3SuRw3NYo0NvklGJxJe4pkkM6/pEPDPQ0CZoiUhwL1uIhAs43/hJtBQHqfKnt1O3bB0uX/ 3kld/OzridmeFMBw== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Hammer Hsieh Subject: [PATCH 08/18] serial: sunplus: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:21 +0100 Message-ID: <20240301215246.891055-9-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Hammer Hsieh Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/sunplus-uart.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/sunplus-uart.c b/drivers/tty/serial/sunplus-uart.c index 99f5285819d4b..f5e29eb4a4ce4 100644 --- a/drivers/tty/serial/sunplus-uart.c +++ b/drivers/tty/serial/sunplus-uart.c @@ -260,7 +260,7 @@ static void receive_chars(struct uart_port *port) if (port->ignore_status_mask & SUP_DUMMY_READ) goto ignore_char; - if (uart_handle_sysrq_char(port, ch)) + if (uart_prepare_sysrq_char(port, ch)) goto ignore_char; uart_insert_char(port, lsr, SUP_UART_LSR_OE, ch, flag); @@ -287,7 +287,7 @@ static irqreturn_t sunplus_uart_irq(int irq, void *args) if (isc & SUP_UART_ISC_TX) transmit_chars(port); - uart_port_unlock(port); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -512,22 +512,16 @@ static void sunplus_console_write(struct console *co, unsigned long flags; int locked = 1; - local_irq_save(flags); - - if (sunplus_console_ports[co->index]->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&sunplus_console_ports[co->index]->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&sunplus_console_ports[co->index]->port, &flags); else - uart_port_lock(&sunplus_console_ports[co->index]->port); + uart_port_lock_irqsave(&sunplus_console_ports[co->index]->port, &flags); uart_console_write(&sunplus_console_ports[co->index]->port, s, count, sunplus_uart_console_putchar); if (locked) - uart_port_unlock(&sunplus_console_ports[co->index]->port); - - local_irq_restore(flags); + uart_port_unlock_irqrestore(&sunplus_console_ports[co->index]->port, flags); } static int __init sunplus_console_setup(struct console *co, char *options) From patchwork Fri Mar 1 21:45:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777621 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9134358ADD for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=scxXc6FsZOCWF+UKCdZQnUz0hL96JA1VNNR94bbOb2YcxM/vmBZJ7M3DKDr54OgRXs/beElumSrEyJNzdOlEheZHUyAshY4Zqq764gSFTJ7LhgXoLylSkMZagKCIj5xH5rK/0TwF4XLhHYbrESPIgfB/DD7xBZ4Krh9/Y8/tpRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=Z26sQXqoRz5d7FR7ubORTC35ekQGKh6UTTKavUvCI04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BIRaFirKi8Rg+2mB7RdZNoDd4z3+kh4XV8qeDxOmyfTkhFN9x3QmaB1Fb94cT+g59Z6Lth+LibcF8XFa2+E2AQy4i+lEY/tp0kM3fgLvfGxcOg8hkMfcTn1ybK7AIeQxygo0EoPq+3A0FdTVRKUdWiEXzTVL1h0Wox6S2pnoVkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JQE6hsuD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=naHLAMDr; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JQE6hsuD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="naHLAMDr" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329972; 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: in-reply-to:in-reply-to:references:references; bh=wNzlMgcB7Ml8SwiiDSy2k2m2CzXu6bUYS/NmyaqyVvY=; b=JQE6hsuD4GBq+eQWc1quSwSjrpKc+JJK9sl7nxnUK6YtebPrz+us/3ItDp3nCY+aXVJaKU J5MJhR1O4NE02wDDBMTp7Frme1R84yw2W/iDfnKVd0MMqpvy3BdFsr3vqgqqPDn4es10kC TOyr48sCvlSD/pFbbyFXjnDnK91V3ChT+Q9fVrelgUUXtnbE4HEGPq8OYEochRaUceNK+v dFcJq5HzvYjikpjiLO8Iuo6JjnQupfD/xM54Wyl6XVOYVpWn9SpxG6HCJNtcjUKc4XtldN ywzBmmqbm2xjS7QDlKCdwR1ANQEyAP4aUuWRQZeEvB2Umk1tlH/w91kfT28eZg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329972; 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: in-reply-to:in-reply-to:references:references; bh=wNzlMgcB7Ml8SwiiDSy2k2m2CzXu6bUYS/NmyaqyVvY=; b=naHLAMDrbDn1VJoY3UrOJIMmXbzlyfLeNOfYuiezN0L9NJsU7IConNvIk0CYZk/r2oE0cR sOmLRPGu8VdeuICw== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Vladimir Zapolskiy , linux-arm-kernel@lists.infradead.org Subject: [PATCH 09/18] serial: lpc32xx_hs: Use uart_prepare_sysrq_char() to handle sysrq. Date: Fri, 1 Mar 2024 22:45:22 +0100 Message-ID: <20240301215246.891055-10-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Handle sysrq requests sysrq once the port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Vladimir Zapolskiy Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/lpc32xx_hs.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/lpc32xx_hs.c b/drivers/tty/serial/lpc32xx_hs.c index ec20329f06036..e70fa59dbcc3b 100644 --- a/drivers/tty/serial/lpc32xx_hs.c +++ b/drivers/tty/serial/lpc32xx_hs.c @@ -136,20 +136,16 @@ static void lpc32xx_hsuart_console_write(struct console *co, const char *s, int locked = 1; touch_nmi_watchdog(); - local_irq_save(flags); - if (up->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&up->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&up->port, &flags); else - uart_port_lock(&up->port); + uart_port_lock_irqsave(&up->port, &flags); uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar); wait_for_xmit_empty(&up->port); if (locked) - uart_port_unlock(&up->port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(&up->port, flags); } static int __init lpc32xx_hsuart_console_setup(struct console *co, @@ -268,7 +264,8 @@ static void __serial_lpc32xx_rx(struct uart_port *port) tty_insert_flip_char(tport, 0, TTY_FRAME); } - tty_insert_flip_char(tport, (tmp & 0xFF), flag); + if (!uart_prepare_sysrq_char(port, tmp & 0xff)) + tty_insert_flip_char(tport, (tmp & 0xFF), flag); tmp = readl(LPC32XX_HSUART_FIFO(port->membase)); } @@ -333,7 +330,7 @@ static irqreturn_t serial_lpc32xx_interrupt(int irq, void *dev_id) __serial_lpc32xx_tx(port); } - uart_port_unlock(port); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } From patchwork Fri Mar 1 21:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777620 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 913D759141 for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=Y9z42Zp30QpTZxrIy75fHmpaMYNoutPNEuGaW4r4+Lg+x1pjOD5kPUp8U2yYyxzPcUu4s5Y6uKZqvQtRYqfXprqTQRAnobwajO6f7KxuS5k9Ni0TZv4t823YUmXVYL/JMpP1GlrsynSYmHtZbb45e6F0g60kZueOskTdsf2OHwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=uymOQEaGyz5PP5tvxdnNv2kYIFvbiI3h6jTV0u0UjkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IxbEl0epiIlgQtTgsAY66lV4VDPW98AiJz5R+wOf9uFE4WljGtmrhaSSx3vKCV5Hu23wWEKqI4cxvCAiV1aI8Vpsn766P777ACIwcxav19xmM/zKEcQI7Fz/OHAyMzgH1QE0wQDWsUL/fBnfeYPej08tynIurvX5T8da5ZfodTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=32PpjUGO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SsMk5Jrp; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="32PpjUGO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SsMk5Jrp" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9WNSSuDhcj1L0hdKTmzZHOjjPZHLEmPBI6eyJikJAxs=; b=32PpjUGOijguemtgK5OGL/uEcf+Ed5E32JT6lbtR3GdeCV/eo5rXQWWEWRbAFi8twtwK+Z DpCoTwloeyPP3686UB83pPO1uTmvR/F89B3IpF7mms7xnOvECB6bQuCtL94tOj84OMiFZ+ zzdm3c4XGpuplfAOzcvELdBKzvPp2nWjC/dxcOGVNJno8zju2BTyiz2fcCRBpRpAF8yY9z da3gu/2i764YDfyrXFaXdfx176v+rJ+rBI0h+vHTNQRHJwyX7sxc+viQLOTIZ4CN0wbHWs aHTHl9HXan2ME0xdmsyxgcwR9DhvF/kj6ox19EMx1oecaTh1wVMO/mKJGoc3Hw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9WNSSuDhcj1L0hdKTmzZHOjjPZHLEmPBI6eyJikJAxs=; b=SsMk5Jrp930Xb5w5e046HrQjoh1Hx9Ojuzkx+xUxFIuhu7kwcDYIMuFG26sXao5zaumeRr pvOTdEiB48/6juBg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , =?utf-8?q?Andreas_F?= =?utf-8?q?=C3=A4rber?= , Manivannan Sadhasivam , linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org Subject: [PATCH 10/18] serial: owl: Use uart_prepare_sysrq_char() to handle sysrq. Date: Fri, 1 Mar 2024 22:45:23 +0100 Message-ID: <20240301215246.891055-11-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Handle sysrq requests sysrq once the port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: "Andreas Färber" Cc: Manivannan Sadhasivam Cc: linux-arm-kernel@lists.infradead.org Cc: linux-actions@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/owl-uart.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c index d9fe85397741d..8b60ac0ad7cd3 100644 --- a/drivers/tty/serial/owl-uart.c +++ b/drivers/tty/serial/owl-uart.c @@ -199,6 +199,7 @@ static void owl_uart_receive_chars(struct uart_port *port) stat = owl_uart_read(port, OWL_UART_STAT); while (!(stat & OWL_UART_STAT_RFEM)) { char flag = TTY_NORMAL; + bool sysrq; if (stat & OWL_UART_STAT_RXER) port->icount.overrun++; @@ -217,7 +218,9 @@ static void owl_uart_receive_chars(struct uart_port *port) val = owl_uart_read(port, OWL_UART_RXDAT); val &= 0xff; - if ((stat & port->ignore_status_mask) == 0) + sysrq = uart_prepare_sysrq_char(port, val); + + if (!sysrq && (stat & port->ignore_status_mask) == 0) tty_insert_flip_char(&port->state->port, val, flag); stat = owl_uart_read(port, OWL_UART_STAT); @@ -229,10 +232,9 @@ static void owl_uart_receive_chars(struct uart_port *port) static irqreturn_t owl_uart_irq(int irq, void *dev_id) { struct uart_port *port = dev_id; - unsigned long flags; u32 stat; - uart_port_lock_irqsave(port, &flags); + uart_port_lock(port); stat = owl_uart_read(port, OWL_UART_STAT); @@ -246,7 +248,7 @@ static irqreturn_t owl_uart_irq(int irq, void *dev_id) stat |= OWL_UART_STAT_RIP | OWL_UART_STAT_TIP; owl_uart_write(port, stat, OWL_UART_STAT); - uart_port_unlock_irqrestore(port, flags); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -508,18 +510,12 @@ static void owl_uart_port_write(struct uart_port *port, const char *s, { u32 old_ctl, val; unsigned long flags; - int locked; + int locked = 1; - local_irq_save(flags); - - if (port->sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(port); - else { - uart_port_lock(port); - locked = 1; - } + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); old_ctl = owl_uart_read(port, OWL_UART_CTL); val = old_ctl | OWL_UART_CTL_TRFS_TX; @@ -541,9 +537,7 @@ static void owl_uart_port_write(struct uart_port *port, const char *s, owl_uart_write(port, old_ctl, OWL_UART_CTL); if (locked) - uart_port_unlock(port); - - local_irq_restore(flags); + uart_port_unlock_irqrestore(port, flags); } static void owl_uart_console_write(struct console *co, const char *s, From patchwork Fri Mar 1 21:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777622 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 912FE58ADB for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=aum0c3dbwOBJ1mAQnOFdRhj9/Y28pBRUDuTRpZnqnKFsiHzCyb84PZPrmrZdZ435rywHp84UIYEay2MidYzOfTwcIftciJP99MIHAq3O2by++lTafC0hXKM+byyvxtTtTRRvmbe2yAEKBsdRy+Q20ISbKip0XEBJj8y9i0HWdHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=VMH61/tHRAbj2Ekc0mQyrj2xuDBqI7ViaojJrJByZW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y9Q+ZNCas9x8plw6OedHJOnZAQfaRF4qznYkXESohucvqxaq7ejrTGiqo+LEI7uPaxEdowc8JA40CLXjNYFEERmY5nIm8qIf07zAMxdlWwlIjHUbIWv/GqhMTuMCcFYY26evmylYa8Zrbo9lY8/kdBrhgZJICeLwMyLwH8VoXoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DYeW/M1O; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VXU5xXqD; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DYeW/M1O"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VXU5xXqD" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329972; 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: in-reply-to:in-reply-to:references:references; bh=tledTIFDDr1sldln/W0Iqtq8p3bbY99HUvZ3jjp5lks=; b=DYeW/M1ORa4YklCaqL330/U85u/jJ+vZdIf5XzcCr1ZY8J/qa4tkUvBtBUyrosws1Hp3ox fGCNR3vwyXJH7mvvWemhuptLbwbDMIpZNfXelPUl85mEdRWx1JZ6P/9Wws6Fk/Hfg0cbMw gfHmTsKbtOCui97hgqP+kSTDOdz40MB+Ygiql02qRl61ZregVOlBI3Uo5/Rl0d98bjlV9S i2AiEKCIeGaop0mWb1xOTnHdNeCXSPavl4SdFCES7EmT++cWQjoA8JyNAGaFt1p+GHwIXk FNCI8PqstTDTWvZEdrC4uIG6lrukcv50FKN4Ygl8Tez7tdf3V3VTZ5qT0bUZXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329972; 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: in-reply-to:in-reply-to:references:references; bh=tledTIFDDr1sldln/W0Iqtq8p3bbY99HUvZ3jjp5lks=; b=VXU5xXqD7rHLIprKYFCb/dOHvMV74MKNJXd1UQwUXThVIFJHiP3eKZA1Gmxa9738uXpO2Y 8jYRQNUskQ+VH8CA== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Manivannan Sadhasivam , linux-arm-kernel@lists.infradead.org, linux-unisoc@lists.infradead.org Subject: [PATCH 11/18] serial: rda: Use uart_prepare_sysrq_char() to handle sysrq. Date: Fri, 1 Mar 2024 22:45:24 +0100 Message-ID: <20240301215246.891055-12-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Handle sysrq requests sysrq once the port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Manivannan Sadhasivam Cc: linux-arm-kernel@lists.infradead.org Cc: linux-unisoc@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/rda-uart.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c index 13deb355cf1bc..82def9b8632a5 100644 --- a/drivers/tty/serial/rda-uart.c +++ b/drivers/tty/serial/rda-uart.c @@ -394,7 +394,8 @@ static void rda_uart_receive_chars(struct uart_port *port) val &= 0xff; port->icount.rx++; - tty_insert_flip_char(&port->state->port, val, flag); + if (!uart_prepare_sysrq_char(port, val)) + tty_insert_flip_char(&port->state->port, val, flag); status = rda_uart_read(port, RDA_UART_STATUS); } @@ -405,10 +406,9 @@ static void rda_uart_receive_chars(struct uart_port *port) static irqreturn_t rda_interrupt(int irq, void *dev_id) { struct uart_port *port = dev_id; - unsigned long flags; u32 val, irq_mask; - uart_port_lock_irqsave(port, &flags); + uart_port_lock(port); /* Clear IRQ cause */ val = rda_uart_read(port, RDA_UART_IRQ_CAUSE); @@ -425,7 +425,7 @@ static irqreturn_t rda_interrupt(int irq, void *dev_id) rda_uart_send_chars(port); } - uart_port_unlock_irqrestore(port, flags); + uart_unlock_and_check_sysrq(port); return IRQ_HANDLED; } @@ -590,18 +590,12 @@ static void rda_uart_port_write(struct uart_port *port, const char *s, { u32 old_irq_mask; unsigned long flags; - int locked; + int locked = 1; - local_irq_save(flags); - - if (port->sysrq) { - locked = 0; - } else if (oops_in_progress) { - locked = uart_port_trylock(port); - } else { - uart_port_lock(port); - locked = 1; - } + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); old_irq_mask = rda_uart_read(port, RDA_UART_IRQ_MASK); rda_uart_write(port, 0, RDA_UART_IRQ_MASK); @@ -615,9 +609,7 @@ static void rda_uart_port_write(struct uart_port *port, const char *s, rda_uart_write(port, old_irq_mask, RDA_UART_IRQ_MASK); if (locked) - uart_port_unlock(port); - - local_irq_restore(flags); + uart_port_unlock_irqrestore(port, flags); } static void rda_uart_console_write(struct console *co, const char *s, From patchwork Fri Mar 1 21:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777334 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9139F58ADE for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329978; cv=none; b=AKxrKhOWxDbIXKBgNkOrfBmX/X6A+RRfJNs3dxwnmsBUV7UVDagkcGIFowJt75oEmMmmdGHACB7RbGhpgnm/pC3gSWMIoUJRi8VkQ95fujEVQGjDaiSgC9AWXd/QBcm0jiOFCkwQElwAOhmiZh1kGXKeRc5l7W8CQ4rmNnuTh6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329978; c=relaxed/simple; bh=hqclxZ7fQ/fIk6kCqEFEfBDFCnJcwa8pzL6FMEtMsRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GLsmlMHVL1x5/wcTkTkJLYFm9HS+4QTs1DJo5g1NIRSE6HAy7rXuL8/4SEOLQkA+UonU/j7KaeRHp8O5DSP7G+qXEN5XOTgOUIbkXeDvqjqBFGr8yKV8omfBh2LTEtTDHgFckx58rFOUVTNb0x5CRu8sqDSfYus9pi/OZjHwN4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kXkNRzW5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cfVr8DqJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kXkNRzW5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cfVr8DqJ" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=Q3rJ+VIa9zH6PXhEPo5PwUUJJVp/71Z7DvgBQX7HX44=; b=kXkNRzW5SN42CuG3j4/V7kKEiVAOe873xyPaCkeIungLWwGlx26c1O7Gte0RgDGuR9gXGX 8qOyauCNcFgAhVPEwLDbj0sUHQIJOone7Vc7ygZklYUTCxaNrNrcR+EgO50IlRSv6DoVWL Iq0zLDH1hqr+y2QZEPDjqCZ+O0s9y4C2qpZpZA/dFeB6nolEQOUpuoiOh9bgRwplT6NCX8 oA0Y7W/Lw76wap0jfYm4aSz3PDbld83b4N39aV6AEnJTr1oMcS8dJISzYm0DWGscBsl4X3 bixYSHMbKe8hKAZw94bAlb502yitVjeBmw15J9VnGzQlkFf13dO3PYZifpvDJQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=Q3rJ+VIa9zH6PXhEPo5PwUUJJVp/71Z7DvgBQX7HX44=; b=cfVr8DqJ/HJJ86+hlhTql0ysW451KIZ/tbZ1sIj2K94z5XE31vEEP5vJ92oRjVlR7a/uz+ 3byohSZL5uh0qbAQ== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org Subject: [PATCH 12/18] serial: sifive: Use uart_prepare_sysrq_char() to handle sysrq. Date: Fri, 1 Mar 2024 22:45:25 +0100 Message-ID: <20240301215246.891055-13-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Handle sysrq requests sysrq once the port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: linux-riscv@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior Acked-by: Samuel Holland Tested-by: Samuel Holland --- drivers/tty/serial/sifive.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c index a4cc569a78a25..0670fd9f84967 100644 --- a/drivers/tty/serial/sifive.c +++ b/drivers/tty/serial/sifive.c @@ -412,7 +412,8 @@ static void __ssp_receive_chars(struct sifive_serial_port *ssp) break; ssp->port.icount.rx++; - uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL); + if (!uart_prepare_sysrq_char(&ssp->port, ch)) + uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL); } tty_flip_buffer_push(&ssp->port.state->port); @@ -534,7 +535,7 @@ static irqreturn_t sifive_serial_irq(int irq, void *dev_id) if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) __ssp_transmit_chars(ssp); - uart_port_unlock(&ssp->port); + uart_unlock_and_check_sysrq(&ssp->port); return IRQ_HANDLED; } @@ -791,13 +792,10 @@ static void sifive_serial_console_write(struct console *co, const char *s, if (!ssp) return; - local_irq_save(flags); - if (ssp->port.sysrq) - locked = 0; - else if (oops_in_progress) - locked = uart_port_trylock(&ssp->port); + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&ssp->port, &flags); else - uart_port_lock(&ssp->port); + uart_port_lock_irqsave(&ssp->port, &flags); ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); @@ -807,8 +805,7 @@ static void sifive_serial_console_write(struct console *co, const char *s, __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); if (locked) - uart_port_unlock(&ssp->port); - local_irq_restore(flags); + uart_port_unlock_irqrestore(&ssp->port, flags); } static int sifive_serial_console_setup(struct console *co, char *options) From patchwork Fri Mar 1 21:45:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777336 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0575159144 for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=KtMsmrhmygmBq7WKKgLFim1oQUpo9xHBwWqLYGpHvTBaioUOI51kdqPK4OCUqV1miUgpvcV0hbngtoNen5pzfEpbGAKhTOBbWbUaMArJOBKZ/GEKgs4wBivg2EHOOiovAGamCPzjLntfL8x8C8+BPJ5/i3FMJFmApXd9Hjn/3G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=P+hCeeWTiwQ956ZhzC5IWqeVkfRNJPOR3rmG6/WGOPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IRv0Z5I6AWRPecwuZa0WvCZq7mWVHiyw7tq/UXRr1e0EnfmyeDCnGyd3DBrXdeb4G8WPuylRP5SBtC5hmzl4o6o8J4le0pK7ArxvSw2xFfAwKDjtVLwmcvtrnLKuba3l9JZmdUxpB4g8RR8qizEb5cywtYYzIuuqtlJ3B9uIZOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0/QBNf4I; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ebzA5Hmm; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0/QBNf4I"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ebzA5Hmm" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=h7R39kvA5nWx/SHLkwt/oBPRXP7RjZNc6ixojjlPi0s=; b=0/QBNf4IgMRfw2pMIvLY/+ufqDgbJ+mJ0y7/Y1Fj1j9vPByFNLCcRss+KyMSASwuMvMVEV gxNzsvj09422np2aQm9l8Flk2xyq0w2IfLb5VVMtFk1gxOVy94DPUEHST5Oe0NI5H+hYc0 238QlnwCHRy/x/BST3gCKMnKu74tYZ4NJiAAd02w6v5to1plt38nhtkECyt71U4VvMDqzk 1i95o816KeNqBQ8ZMd6Yxkf3HW8ji/Y1C46QaHkBDa1Kg0U40/owVsWjaBPq+hgBntJh2d 02SKurrcCnbvCyG7b2IBuu1HZfDcFOSwLNdgXcRWFpWskf+r5wn4pk4+mzzzzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=h7R39kvA5nWx/SHLkwt/oBPRXP7RjZNc6ixojjlPi0s=; b=ebzA5Hmm7uP1CoOmJvVGUtbjuTQGElZMrsxO9J/5ipZpXhiW0gRj8/p1wyP2CheMBUqMF6 QnWiUexhhbnpMxBg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 13/18] serial: pch: Invoke handle_rx_to() directly. Date: Fri, 1 Mar 2024 22:45:26 +0100 Message-ID: <20240301215246.891055-14-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 handle_rx() is only a wrapper around handle_rx_to() without any additional functionality. Invoke handle_rx_to() directly and remove handle_rx(). Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 436cc6d52a11b..29ed6f8621d7d 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -778,11 +778,6 @@ static int handle_rx_to(struct eg20t_port *priv) return PCH_UART_HANDLED_RX_INT; } -static int handle_rx(struct eg20t_port *priv) -{ - return handle_rx_to(priv); -} - static int dma_handle_rx(struct eg20t_port *priv) { struct uart_port *port = &priv->port; @@ -1051,7 +1046,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) PCH_UART_HAL_RX_INT | PCH_UART_HAL_RX_ERR_INT); } else { - ret = handle_rx(priv); + ret = handle_rx_to(priv); } break; case PCH_UART_IID_RDR_TO: /* Received Data Ready From patchwork Fri Mar 1 21:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777335 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 07FC459146 for ; Fri, 1 Mar 2024 21:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; cv=none; b=OHTlUo69Z8+bYKmkuel55Yl0uQOezs8e57K3kbUTpIZEZSFeaFvb1SMJQ0jPYVejwT6DAZ37l28TSXwbZp1Lni6sQ9yRa6phXX43gjH+NoA1FHgBIq96Y9sstZsufAk5dHVv2/FWgwTeE3RISWyyA99KhhKThyrlVor8V5qaPmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329977; c=relaxed/simple; bh=95CvMzwLEYvN0YPdFgnvtB83kTTr7qCy0v8blcJOJG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UldQlj86LX8Izq6YUh3lEeq+UbJHviYMo6Ubt+Z807ltOW1HvHvCM0Trde8zKFg7Ty067r1EJxkKtIfX2Y9gRRVIGdjYWFmOpC9B0H2WEaofnvofXK3EbX/wBXFDG6Eiu31zz3+qolHB15DF9mqGGATgJP21VOnpSYg7y753eC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fpkk8WdB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oSX8W81+; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fpkk8WdB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oSX8W81+" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=gr2ZxEwFtSX4/4G1RgLzPTzSQg478W3tlH7lcsXH0mc=; b=fpkk8WdB0bre+7rLpCRoW15tSHtAa/O4wATJbIud9rMy0nRIbnXFi3dS1unLyTMbYBRXUF HiVK4tXA4/FMISi949igIbIJM7AODSe/QgrqD8MJzd70YgJzfcf+AAPvJuMvRuQquy/2eC NhU2t12++7gk4neMB+c/qd3LmGfe25SyN21X8+/oL/cNdYL3rlqtaSZwZQXiceuQbGqVZb h1S6OXd5s/A12s5mbYH6exS6ejDmIpI3OTq9luwoUcljx2Bt/mub0vGKat6p4ldroN8FkJ nFO5KchHg67GHcBKJ6M4BJnvpOP7H1qV9q6LAIjv5KUfDqgTo7lNk0aeJ+vUDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=gr2ZxEwFtSX4/4G1RgLzPTzSQg478W3tlH7lcsXH0mc=; b=oSX8W81+15FcseS/E4G2apZY2qxtBj1NzB//CfXTjM9toOs5x8V/lBQoRnqSTwhOfW17Yl u7GtZvLyQt2gKzCg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 14/18] serial: pch: Make push_rx() return void. Date: Fri, 1 Mar 2024 22:45:27 +0100 Message-ID: <20240301215246.891055-15-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 push_rx() returns always 0. Make push_rx() return void. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 29ed6f8621d7d..124eb816fca7e 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -599,16 +599,14 @@ static void pch_uart_hal_set_break(struct eg20t_port *priv, int on) iowrite8(lcr, priv->membase + UART_LCR); } -static int push_rx(struct eg20t_port *priv, const unsigned char *buf, - int size) +static void push_rx(struct eg20t_port *priv, const unsigned char *buf, + int size) { struct uart_port *port = &priv->port; struct tty_port *tport = &port->state->port; tty_insert_flip_string(tport, buf, size); tty_flip_buffer_push(tport); - - return 0; } static int dma_push_rx(struct eg20t_port *priv, int size) @@ -761,7 +759,7 @@ static int handle_rx_to(struct eg20t_port *priv) { struct pch_uart_buffer *buf; int rx_size; - int ret; + if (!priv->start_rx) { pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | PCH_UART_HAL_RX_ERR_INT); @@ -770,9 +768,7 @@ static int handle_rx_to(struct eg20t_port *priv) buf = &priv->rxbuf; do { rx_size = pch_uart_hal_read(priv, buf->buf, buf->size); - ret = push_rx(priv, buf->buf, rx_size); - if (ret) - return 0; + push_rx(priv, buf->buf, rx_size); } while (rx_size == buf->size); return PCH_UART_HANDLED_RX_INT; From patchwork Fri Mar 1 21:45:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777333 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4B3585916C for ; Fri, 1 Mar 2024 21:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; cv=none; b=ZB5D7rwyXuKoCNEYGBHZD+uxef8kMBLZDYXB1Qwvy3z0T3Ktvy0ssVJawvYGUA+DIIa6pzv3Vmp+xVWRf3mFxSisammKDk0aHdvIqAcqm/hmLsUTPfnTeRaK4si2TC8NcfMViDW784IkwHjtT7PzV6K9R2vyNL979q2N61ky408= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; c=relaxed/simple; bh=/03FG9FF13NAdHycAZCWAZFqqx2USc4J/DxFaLppJ5E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JOWeP3KIDYpEdPccLCYInpgtk9kdHDKKaqBKnI2QMQvQeqs0DFt7si9pJsrmeD7mtxF/kFENnluHCB6VL1BQp51KWDw38jGGHy3gmB736zrsJR4NjDrR4X/i7A6wTsKc0IQs3Z0JgwOsQpN6d3DfucaH2TwNRKrnQ+xOxthTGCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XLCULnuv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HZZ0rg7T; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XLCULnuv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HZZ0rg7T" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=8lXM/uFYefXXbiK1CgREiM4AYl7rnjz2Bx/xobHfCzg=; b=XLCULnuvVEZwwEC7AqxENYf+76zxma9AZAK3fSdcy0haYMwvlCe1o+XCcAqtMVEErF3C2W o7lcXOdbzTtkOjwcAPYqywHG7vL7oTA6O5lp9kABLiZiGrlztuA0RAPSfygyqqmkt+EuHc 242I3OFDt1k32V9f8ZPMPq3vue+93UWrzekwLKf1kywNY+4a8+Jm1oBWPjrgrOFssiUiJ4 OBPDALVe3wHwHzBz4wTEgalpQqKuV4hjHOWpW4dHEXB2q0m0kn1Jk+G0Ptb7LAcnp1wDIZ droRykQnmPaHHWoNkBGUqBAqMseVTZyfhCmZ284lIHuGexKvJNYpJIjRKfZHOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=8lXM/uFYefXXbiK1CgREiM4AYl7rnjz2Bx/xobHfCzg=; b=HZZ0rg7TpVyhq8LlAAOu/CBuIf00NhCzbXrH+CBdAjxZxFMsAnmkA1OKKEXDMCXss+ZebH ZXOP/cIOQtF5uSAQ== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 15/18] serial: pch: Don't disable interrupts while acquiring lock in ISR. Date: Fri, 1 Mar 2024 22:45:28 +0100 Message-ID: <20240301215246.891055-16-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The interrupt service routine is always invoked with disabled interrupts. Remove the _irqsave() from the locking functions in the interrupts service routine/ pch_uart_interrupt(). Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 124eb816fca7e..6e259f4139153 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -1010,11 +1010,10 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) u8 lsr; int ret = 0; unsigned char iid; - unsigned long flags; int next = 1; u8 msr; - spin_lock_irqsave(&priv->lock, flags); + spin_lock(&priv->lock); handled = 0; while (next) { iid = pch_uart_hal_get_iid(priv); @@ -1074,7 +1073,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) handled |= (unsigned int)ret; } - spin_unlock_irqrestore(&priv->lock, flags); + spin_unlock(&priv->lock); return IRQ_RETVAL(handled); } From patchwork Fri Mar 1 21:45:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777619 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 EBBE358AC0 for ; Fri, 1 Mar 2024 21:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; cv=none; b=ZGBs8gZezvIkqAIiT99jr4bKzHHlGiALcDCtr2IuXijg+LrNHJGUTzYXV8emf4Qf42AX2HdiYwfst5T/q2PVM3+6TCUQsjAnN5rJobn3PyLzMchblQuEO024dvwTvcSG6YFfJP94kU112sApdvpp0ZUUyL1E0WGg5hCB8zMDpNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; c=relaxed/simple; bh=6S3rT8ew5SW4ooRI3s2dS7P0BAIVcBK43n3pP2nVPVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g48jAJaJsnzPArWQ7cK+S/L8D/s5pvbz15774C+jYgzWVJHqNafwDltFA1EsB9WBOnUxjvhbFF8hjOpjFSyQJjrBp+uKgGLi0UahhjrmKjwCCL3e8nS7FNJ9iagMTQkg1JqBWfo0dActq6KOLzPo/cKvdNgSkErEdod7PemDDpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K+FjPxZ8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kXpUL8nw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K+FjPxZ8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kXpUL8nw" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=K0g8itF+ExlpYzEJYeSCnD2J1K8E/AB5H3Ar0pbseLU=; b=K+FjPxZ8Rtk1jizL2MM1FuvCxEyiWV/8Nk3pn1RjQVbRtxAMzIohciVlPyJJIAJ1eN7Rbe Erb3AfTpPr9TPQEPzme6rOHfsKKOo/+W2raT2XzQNkJKbBULMdZTQhRVXIYh8/PGNKJ/Gq F1fw6X2ZzF2p53XjvEw2ovUJhmrrlneVXkBrweJXx8z3ZDGLmPjEfe2/DnAkwes5gengrb zvTZbqSUOaq6ACvbaxT6D+TmMazs0A7zkDogpYmI6pelKBKY93ALQFsXjctAsS0NA9SasO W9OH7miXOIk1zayA+ZZujrhEEhQs64xnQBvDPyj0oTeeUa0SzES8tmFgqcdZ0A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329973; 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: in-reply-to:in-reply-to:references:references; bh=K0g8itF+ExlpYzEJYeSCnD2J1K8E/AB5H3Ar0pbseLU=; b=kXpUL8nw3U+vuu4eRO/NLXoNlmdO4pUAyCDjw2UKJtx1k4VgfR7W8d2rz5pKISrZeB8pOx IxSSoLbJbbq6rzAQ== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 16/18] serial: pch: Don't initialize uart_port's spin_lock. Date: Fri, 1 Mar 2024 22:45:29 +0100 Message-ID: <20240301215246.891055-17-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is no need to directly initialize the spinlock_t in struct uart_port. The structure is later passed to uart_add_one_port() which initialize the complete struct including the lock member. Remove spin_lock_init() on uart_port's internal lock. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 6e259f4139153..3911703918764 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -1725,8 +1725,6 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, KBUILD_MODNAME ":" PCH_UART_DRIVER_DEVICE "%d", priv->port.line); - spin_lock_init(&priv->port.lock); - pci_set_drvdata(pdev, priv); priv->trigger_level = 1; priv->fcr = 0; From patchwork Fri Mar 1 21:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777332 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2E3C159169 for ; Fri, 1 Mar 2024 21:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; cv=none; b=BKBRZ25LQmjNtEBTLVI1jRbNYlXuUpUvKR+0CWlWucS0wnZcafeltMc2GAE6imi8v4siWMdSv/8jhzg+CFNAMtqeIdbGqImEyPsuhcgpV9vCcRig+ggGRsnZ56zU8gGvH+0c0Qru/ONqwVJN6Yt1Ky/YY9AQCnzu4qRCU2Y9Q3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; c=relaxed/simple; bh=W1bZAcSWaD2tgfhQ6Fbubqq01v5jgI1caf8l+t9Rw+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XXdzZ49i0bOXKlEb1lpFChgoQ7se1NUH+cmrDPmZ7yYLvfhyXTJSYvV8pJ4IaMYTidIeH99d9Mf+Du08gsnoBsz2dQHNStV/lsgiOBCm8RqZs7LD9R6KZIpkMsUijJyw5vBT2KBIBz2Rnfs5oKHt3K/ictJAxlJsyMhvX35rd70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ml/Yf7C9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZDy191eZ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ml/Yf7C9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZDy191eZ" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329974; 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: in-reply-to:in-reply-to:references:references; bh=WdLQfv7Xl2ik4I8lDwt6i1/NivYpaQJh5MZ/FKTlv14=; b=Ml/Yf7C9nbauHydI1iQZRS0OZ6eKh3M24hYsVUcsdj7L6yCVw+HGhUmm/GssBJhtm7Ka7T hC7LGrhyf2K8azqUvTFvbvu870yUrpfOE1Fn1zGHbc7kuticSIegX5cBNMwddXXinRxBrX EbEXtAVlOZ729Rtkk4Je++uDlwhthRN8WLUQ1N9uJELXai36qMOffha6y2yR3WIzHBZqZP uQUzT78hE8A/2gvP2lCo9LfwdWNYfbf47Uiterv3IY8SSyDVtbkVHrK17kz0cBzwuZEKnJ y1tOkkjKBXc0GptgIiHvjZ/mx05PiQn3rktY0yP8TS3aIPI3kJ3UXMf2H4avYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329974; 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: in-reply-to:in-reply-to:references:references; bh=WdLQfv7Xl2ik4I8lDwt6i1/NivYpaQJh5MZ/FKTlv14=; b=ZDy191eZ5/JmGBfVDX6KxFvPQQE3xQvZmuLH5xSwFRzxl1IDXRPeoklI0XTXS7Crt14VAL QUEfy9e4mGnCYpDA== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 17/18] serial: pch: Remove eg20t_port::lock. Date: Fri, 1 Mar 2024 22:45:30 +0100 Message-ID: <20240301215246.891055-18-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The struct eg20t_port has a spinlock_t which is used for locking while access I/O of the device. Then there is the uart_portlock which is sometimes and nests within eg20t_port's lock. The uart_port lock is not used while using the struct in pch_uart_hal_read() which might be okay. Then both locks are used in pch_console_write() which looks odd especially the double try_lock part. All in all it looks like the uart_port's lock could replace eg20t_port's lock and simplify the code. Remove eg20t_port::lock and use uart_port's lock for the lock scope. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 3911703918764..92cb3c623cc31 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -237,9 +237,6 @@ struct eg20t_port { #define IRQ_NAME_SIZE 17 char irq_name[IRQ_NAME_SIZE]; - - /* protect the eg20t_port private structure and io access to membase */ - spinlock_t lock; }; /** @@ -1013,7 +1010,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) int next = 1; u8 msr; - spin_lock(&priv->lock); + uart_port_lock(&priv->port); handled = 0; while (next) { iid = pch_uart_hal_get_iid(priv); @@ -1073,7 +1070,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) handled |= (unsigned int)ret; } - spin_unlock(&priv->lock); + uart_port_unlock(&priv->port); return IRQ_RETVAL(handled); } @@ -1184,9 +1181,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl) unsigned long flags; priv = container_of(port, struct eg20t_port, port); - spin_lock_irqsave(&priv->lock, flags); + uart_port_lock_irqsave(&priv->port, &flags); pch_uart_hal_set_break(priv, ctl); - spin_unlock_irqrestore(&priv->lock, flags); + uart_port_unlock_irqrestore(&priv->port, flags); } /* Grab any interrupt resources and initialise any low level driver state. */ @@ -1336,8 +1333,7 @@ static void pch_uart_set_termios(struct uart_port *port, baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); - spin_lock_irqsave(&priv->lock, flags); - uart_port_lock(port); + uart_port_lock_irqsave(port, &flags); uart_update_timeout(port, termios->c_cflag, baud); rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); @@ -1350,8 +1346,7 @@ static void pch_uart_set_termios(struct uart_port *port, tty_termios_encode_baud_rate(termios, baud, baud); out: - uart_port_unlock(port); - spin_unlock_irqrestore(&priv->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static const char *pch_uart_type(struct uart_port *port) @@ -1555,7 +1550,6 @@ pch_console_write(struct console *co, const char *s, unsigned int count) { struct eg20t_port *priv; unsigned long flags; - int priv_locked = 1; int port_locked = 1; u8 ier; @@ -1565,15 +1559,11 @@ pch_console_write(struct console *co, const char *s, unsigned int count) local_irq_save(flags); if (priv->port.sysrq) { - /* call to uart_handle_sysrq_char already took the priv lock */ - priv_locked = 0; /* serial8250_handle_port() already took the port lock */ port_locked = 0; } else if (oops_in_progress) { - priv_locked = spin_trylock(&priv->lock); port_locked = uart_port_trylock(&priv->port); } else { - spin_lock(&priv->lock); uart_port_lock(&priv->port); } @@ -1595,8 +1585,6 @@ pch_console_write(struct console *co, const char *s, unsigned int count) if (port_locked) uart_port_unlock(&priv->port); - if (priv_locked) - spin_unlock(&priv->lock); local_irq_restore(flags); } @@ -1694,8 +1682,6 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, pci_enable_msi(pdev); pci_set_master(pdev); - spin_lock_init(&priv->lock); - iobase = pci_resource_start(pdev, 0); mapbase = pci_resource_start(pdev, 1); priv->mapbase = mapbase; From patchwork Fri Mar 1 21:45:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 777618 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4B31B5916A for ; Fri, 1 Mar 2024 21:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; cv=none; b=Gf9opYLh+LO15eKp0hN9OrfrNpdbY7HTs0goRLrSqxYAAdJHOkFRBwp2a572qd5rsDOQ95XBwMRVptgQA2pHbJvVsODjoHpquMuRPEfyEsNULVLf9nIaF65GyONI5oeqgny92qSrOjllKwRJMWvfrZjkeU+XbNGxSOwTKYIj5RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709329979; c=relaxed/simple; bh=TRua4hwsyKAOaNTpok6CuR9EPO46jceuHAEu7jLMil4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LT+U1jxj3/U6+EIdkN6QlQl++Y4BhhhD8xsaGAsvmGEXMiYsw3t/pF2CBgfohi3a6+l4JQPTrBrzCn74i4SNmmmBy4vfK0cYXTwTIvPKmXPH5CcWnR48kUws8foi7x/Y7zA7+ouTsHMK1W4n0keAeyqiB+IwB4/jeJowO8tsETA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=G8lnie70; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mZROY3e1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="G8lnie70"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mZROY3e1" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709329974; 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: in-reply-to:in-reply-to:references:references; bh=pOJuLzQLDJioNQIKELQPhw/86A1haCxeVutu0Df82AU=; b=G8lnie70jQEUnLtjpojJCSXjo08zJjviSEhHVTVWT8sMxU5r4IQIA1ptxiinYX6d7vfsdx ZqX7mQx43oA/p/1BC1gbL956aZia0ivyQl8+uml52WHcy0llKXwMtNLlEA5KdrHDZEvDWR lopfxrx504rG9MM/RRocACW7hx+DdpLydw7mrtv+Y8Hb4Pmp4cwQ95JZuvLFkX+qr6D648 P5ZcBUxGLC3WO2/6C3jYPvs9P1FjzfaqQL3aDg4o5o1xvpRVjNTn6zCdeLq26RZk8Zl9IY YZiBAKNng2xcCeINYvdNwosUcsThSX4cgRQwTpTcj7v5HpEzHgyif11t19L84g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709329974; 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: in-reply-to:in-reply-to:references:references; bh=pOJuLzQLDJioNQIKELQPhw/86A1haCxeVutu0Df82AU=; b=mZROY3e137rCOKQ5IsrCs8L9+EHN5vF1W0d0ODo7/spCVMdV2Ta6KWCwO1nv/9+supikBv jKaOTWhCaljADGDg== To: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 18/18] serial: pch: Use uart_prepare_sysrq_char(). Date: Fri, 1 Mar 2024 22:45:31 +0100 Message-ID: <20240301215246.891055-19-bigeasy@linutronix.de> In-Reply-To: <20240301215246.891055-1-bigeasy@linutronix.de> References: <20240301215246.891055-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The port lock is a spinlock_t which is becomes a sleeping lock on PREEMPT_RT. The driver splits the locking function into two parts: local_irq_save() and uart_port_lock() and this breaks PREEMPT_RT. Delay handling sysrq until port lock is dropped. Remove the special case in the console write routine an always use the complete locking function. Signed-off-by: Sebastian Andrzej Siewior --- drivers/tty/serial/pch_uart.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index 92cb3c623cc31..89257cddf5405 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -564,7 +564,7 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf, if (uart_handle_break(port)) continue; } - if (uart_handle_sysrq_char(port, rbr)) + if (uart_prepare_sysrq_char(port, rbr)) continue; buf[i++] = rbr; @@ -1070,7 +1070,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id) handled |= (unsigned int)ret; } - uart_port_unlock(&priv->port); + uart_unlock_and_check_sysrq(&priv->port); return IRQ_RETVAL(handled); } @@ -1550,22 +1550,17 @@ pch_console_write(struct console *co, const char *s, unsigned int count) { struct eg20t_port *priv; unsigned long flags; - int port_locked = 1; + int locked = 1; u8 ier; priv = pch_uart_ports[co->index]; touch_nmi_watchdog(); - local_irq_save(flags); - if (priv->port.sysrq) { - /* serial8250_handle_port() already took the port lock */ - port_locked = 0; - } else if (oops_in_progress) { - port_locked = uart_port_trylock(&priv->port); - } else { - uart_port_lock(&priv->port); - } + if (oops_in_progress) + locked = uart_port_trylock_irqsave(&priv->port, &flags); + else + uart_port_lock_irqsave(&priv->port, &flags); /* * First save the IER then disable the interrupts @@ -1583,9 +1578,8 @@ pch_console_write(struct console *co, const char *s, unsigned int count) wait_for_xmitr(priv, UART_LSR_BOTH_EMPTY); iowrite8(ier, priv->membase + UART_IER); - if (port_locked) - uart_port_unlock(&priv->port); - local_irq_restore(flags); + if (locked) + uart_port_unlock_irqrestore(&priv->port, flags); } static int __init pch_console_setup(struct console *co, char *options)