From patchwork Thu Sep 14 18:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp670928vqi; Thu, 14 Sep 2023 15:49:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELyHzDYbiTs4Z917gOrxMob2QClMjWykS1Dm/Y80VeGKEm0yOCdmHT0eF3GT+pMsgzHb5g X-Received: by 2002:a05:6a20:1058:b0:14c:ca25:3b53 with SMTP id gt24-20020a056a20105800b0014cca253b53mr146792pzc.27.1694731787778; Thu, 14 Sep 2023 15:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694731787; cv=none; d=google.com; s=arc-20160816; b=TyPhwtseOI19yyMYn9W1c5he5xvvjemLgwQnmRJSHfx3L+kL1/poZes9/TB6bLimVA Ryv7+yD4kqbmDeK3ppNG8QgbQtLAqBxYJJR4r2l/4ihRJnjOLRl4HKOI/xXvrWO1H1sA lMCZk0VPCqMfvpVhvu70AEKUXCOuOB7o0NplQJ9Cfiq0iuc1v1fgNcnpBMWdAlSKJ214 539jcC+HIvv+0D2Sd1yKypStJvv5/ldWNJ8BaXHUZ5Ms+lNSNi5f+E1Ako31a5M2VqGi r6h6EYdVud7y9YVFBjfDAYWAIGLGaKqxhWpB5uprGdr/cYII9WOeEdsboPSeUutiUBbU 4gyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=0zxTlKID9c7YEvuORrPXl2fVFncXh/KVCV6b0hRF+M0=; fh=jIBv3+2u5ztppMkA20Cq2to1nHAjLiKumEJJbsvBahM=; b=usP2zAUKafpk/8x4wQx3vHmIU/Otf0kzhl5vXf1ZWUVPmLzMok/SkehvzD22P+sjMl zXqqU8K6QBz5oc+sE6PRHghSOw08KUgg1SM02W1z3k3gEbHMdg0yb+xHydvhGrCpCcBZ vgCOU1Lm2CHhzW3I2VhLoaG49i5855R5rWC5UnlsOocTFDOmx3Ne8cnZitTURgIXBxxk NBIAPcPhgnL0ieEYBM+ZrwOf69BbbqKu4QyRFiNuL3zqSypDt8ydX77Ens5R7mI5hd8B HDXvEY+fftIMKhTDhWYpNVfYCe0Y6w92nz/DY+uydeBYZixam7slBfH8zb6o7QaWXozW OEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wpI9YdYs; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u39-20020a056a0009a700b0068e2f6feab4si2407772pfg.374.2023.09.14.15.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 15:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wpI9YdYs; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 74ACB8328FD9; Thu, 14 Sep 2023 11:39:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241886AbjINSjO (ORCPT + 33 others); Thu, 14 Sep 2023 14:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241568AbjINSiw (ORCPT ); Thu, 14 Sep 2023 14:38:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52C91FFE; Thu, 14 Sep 2023 11:38:44 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716723; 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=0zxTlKID9c7YEvuORrPXl2fVFncXh/KVCV6b0hRF+M0=; b=wpI9YdYscyP7QCk0acGuia//P2qYFkbm3gJQZYYqS49wM9ejXs+pjzQLph+Uzx69MOiUXl Dzd44jCbMLmFITkggEvIkAm9kK8h3TJ3NQYg+psnX8uBb8BKhZfFkfyBh2Wdw2kgXvorv9 eN+z9CFui2CBPIgGQZOQQF36x8utOP0y0fQJb3RGGFp+NBRyRz1c5xTbr38vbYxcOwYfRv QvucfHJ04RIkd0cer+j9B5cOhisDGPDz1KoBqFmjWrEcCcdOuAoLnYILixUcoY6Ny0O5C1 STlb6yGp3sbH9XbXZlR/i1R5QsvZxuS4ujVvU8GkDtrto5lcoxGddR9baDlKIQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716723; 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=0zxTlKID9c7YEvuORrPXl2fVFncXh/KVCV6b0hRF+M0=; b=3/nKE7xyHHA/3Sq2eQiSXccT5Z8HqEfiZ5GXPISOZOKMiLIeYRqscjaIjC5bCGvNvAVBW5 tSThvy+KQFyPJZCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , Chen-Yu Tsai , Tony Lindgren , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH tty v1 11/74] serial: 8250_mtk: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:28 +0206 Message-Id: <20230914183831.587273-12-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:39:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777055078708083749 X-GMAIL-MSGID: 1777055078708083749 From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Chen-Yu Tsai --- drivers/tty/serial/8250/8250_mtk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c index 74da5676ce67..23457daae8a1 100644 --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -102,7 +102,7 @@ static void mtk8250_dma_rx_complete(void *param) if (data->rx_status == DMA_RX_SHUTDOWN) return; - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); total = dma->rx_size - state.residue; @@ -128,7 +128,7 @@ static void mtk8250_dma_rx_complete(void *param) mtk8250_rx_dma(up); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } static void mtk8250_rx_dma(struct uart_8250_port *up) @@ -368,7 +368,7 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* * Update the per-port timeout. @@ -416,7 +416,7 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, if (uart_console(port)) up->port.cons->cflag = termios->c_cflag; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); /* Don't rewrite B0 */ if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud);