Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4268531rdb; Thu, 14 Sep 2023 18:05:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBanR32ALzGZl0PBMJGKp0glTTsjTk68abnhyP90X4+63o6KztddOuyif7Jy4N62M53wuD X-Received: by 2002:a05:6a20:1442:b0:13d:5b8e:db83 with SMTP id a2-20020a056a20144200b0013d5b8edb83mr541106pzi.9.1694739945077; Thu, 14 Sep 2023 18:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694739945; cv=none; d=google.com; s=arc-20160816; b=ZLATlTceOI1kkQmtZz1whzID+Efl5kuOyHOq2ntw4so6mV4YE7nfUDx1fHrJsfS/OF fRVwewcAhdm/l4Z6ShyQQIn0VlhMZxgXO+mpAVxYoUM357MBrpyCperhhMilpFietL5S giF3A4+ulUIHhNHlj3nnk17mSDeTh+Kjd9y8rk2ox16LudDaS0Tx48KzilDJaaMPeCBI k76Q0QY/AnUcAxMcjxBdEgFtvRpoZ0MeQ6Jz9v54ITNoK7nWsd1SwJWVV1cbt4BZCvmv nRQxwNtyK3w+xDkThwfp6m1aZ1pWVIRS466ET7LMXDgQiXBbki3DSzUn2jfOJ9VrwTll S1Cw== 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=IRoapPsp3k8C9+cAJncEIUfgF6L1OgYHKNIWMNQArN8=; fh=qmZFnekuDs4T9icLmieAH3NNHXuS0/kWBnXi7iQsZPY=; b=mzN7G21TSMc/nDBkXvPYvGdxcol1oeWpijH9fukDbDhDeI+bEBpgC80zI2DyqGTKkd gYByb3tXXI5NpVZ9pmIHPjyoAn/JUDKlacjNVZnNJCZ7sADwaXoNtVPBOJuURSceoCLL ACx5Qd//LQu2cFjxcTu4/J1VgxCGByneuazJL+0TJkZAK67m7kISfspznocWOfPCuKRA XvKWJRPhtLAXKaCNLF7zA63nEu/QcN2XLD21aMFJwnsIwuRHu7wkO9BQR2Boc6qEB3k5 BguwRrxMJoDDdZ1Q5dpqoB5RravCTila+4fHbkCiRDqWHGzPHX2YY0ZCGTPwyVuOOr3A zbvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VAjKIhOb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wGLW0CPq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id j3-20020a170903028300b001c4329b77bfsi222864plr.123.2023.09.14.18.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:05:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VAjKIhOb; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wGLW0CPq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 90FDB81DF25C; Thu, 14 Sep 2023 11:39:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241440AbjINSit (ORCPT + 99 others); Thu, 14 Sep 2023 14:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234957AbjINSiq (ORCPT ); Thu, 14 Sep 2023 14:38:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A781FF9; Thu, 14 Sep 2023 11:38:41 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716719; 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=IRoapPsp3k8C9+cAJncEIUfgF6L1OgYHKNIWMNQArN8=; b=VAjKIhObU4Ecwzj1Ft23hUIFCg5wNU+ACZXfHOo/+M6G3rDdjIutIP/3dgKZphFycD7k0s l1K/shKjUF1xNDyqSV4Dkv1WCexNBS4t69JIncUEixls1YhZ/pLnSCgDpEory16tlJ3aaK cTsL9IOd8JYrt8dYej3n1jevYWZHoDYTaJtVMpwp/BHiRAyRsFxkoewey2tW8f/zXlHHoj eGxIhZNWggKOIC77flgOvFXuitF29LOz6qsVQG5nx2unbIXnsGYvp0nQHU7vFHpswVtoGd qFrRpKlOyVTIQm/uj3/xhPNHlPXIYSjTqnj+ukPYGxr4V79XY9RgkxxGqm6CVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716719; 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=IRoapPsp3k8C9+cAJncEIUfgF6L1OgYHKNIWMNQArN8=; b=wGLW0CPqtjKXdq32BWOBlskt8IKEQHA9vLWBa4IeEQiBvGjl9GrE1AxJD/0KbuJjMJhKKB l4R6nV8mtg7pUYBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 01/74] serial: core: Provide port lock wrappers Date: Thu, 14 Sep 2023 20:43:18 +0206 Message-Id: <20230914183831.587273-2-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 Content-Transfer-Encoding: 8bit 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 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:39:03 -0700 (PDT) X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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. Provide wrapper functions for spin_[un]lock*(port->lock) invocations so that the console mechanics can be applied later on at a single place and does not require to copy the same logic all over the drivers. Signed-off-by: Thomas Gleixner --- include/linux/serial_core.h | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index bb6f073bc159..f1d5c0d1568c 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -588,6 +588,85 @@ struct uart_port { void *private_data; /* generic platform data pointer */ }; +/** + * uart_port_lock - Lock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock(struct uart_port *up) +{ + spin_lock(&up->lock); +} + +/** + * uart_port_lock_irq - Lock the UART port and disable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock_irq(struct uart_port *up) +{ + spin_lock_irq(&up->lock); +} + +/** + * uart_port_lock_irqsave - Lock the UART port, save and disable interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + */ +static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) +{ + spin_lock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_trylock - Try to lock the UART port + * @up: Pointer to UART port structure + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock(struct uart_port *up) +{ + return spin_trylock(&up->lock); +} + +/** + * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags) +{ + return spin_trylock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_unlock - Unlock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock(struct uart_port *up) +{ + spin_unlock(&up->lock); +} + +/** + * uart_port_unlock_irq - Unlock the UART port and re-enable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock_irq(struct uart_port *up) +{ + spin_unlock_irq(&up->lock); +} + +/** + * uart_port_lock_irqrestore - Unlock the UART port, restore interrupts + * @up: Pointer to UART port structure + * @flags: The saved interrupt flags for restore + */ +static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) +{ + spin_unlock_irqrestore(&up->lock, flags); +} + static inline int serial_port_in(struct uart_port *up, int offset) { return up->serial_in(up, offset); -- 2.39.2