Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1107614rdb; Tue, 19 Sep 2023 22:46:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0xgpdsU4Jm9j66tqQNIft3edwd5jhRPGUHTMYm2tJP93cNMiVdgYmGsL7HuQJk+qn6tle X-Received: by 2002:a17:90a:bf0b:b0:263:fbe5:2125 with SMTP id c11-20020a17090abf0b00b00263fbe52125mr1637656pjs.15.1695188794497; Tue, 19 Sep 2023 22:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695188794; cv=none; d=google.com; s=arc-20160816; b=B72osyufnUc/P9Gol9Gh6UvEEjHUaOn94GlSDEUdAdpkSGHiieHZ/RYqGZPba01QMi TpZgz7U2pDP0maXdIkzCIZIFYKajoBOn1wiiBtDwmVzFoBgR+C1LxDOK9whUOLCqViyS YvQIS7QBwk70aOxBD2zE6T1t9Lw5wNFqK+uBTbjn0eBzbxznTF6QagFJ8Xuvgjx4g6GT 76eICEd6+y2MUoU4lYzBX9ReFbwUjm21S1c6t8RtteEUrizupO/gUpDM0StVwGeKcBjn PAnu6sDPq1EEESGhZbTm30eaxcD+46HDRgj0yKZiP8+5tNXfZ0n/DLAN4u0RDbaJV0dt fITw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=r1TxB3COmcZLqPqGnXik1ej1Y5Gl0niwIbew86BOZg4=; fh=9oAFUWEOUent+tT8q0bQxCb/bYsaFr9K5gI/3uV/v6s=; b=el4lWLNdUq5E5+AonVjRJ9cl3ZKoF4C36nmb3xoN+7YPWF54J/iS257eTLWFb5pLYu FsVPjeCfuW4DASqo6ggCn8Ns3xQGspKnKWJPBUhOrhF4ACT+diX12escxdqu/pbjTu93 LZlTxD6xbYn3Gc0WAYTleSqcWxePYxmloISA6mwzMVNLXrYGlmVk2ObD3nfKNpljMukJ t+joW1pTXMy/1Ez4edD19EOxfJv51B2INo0CT9dCsxIKhihRSUxDxNhWzxHFXlxkzP0X 1u6JdKpEgqN44CT1oZ2Tuj99fld1wQdxzzdD83SO3sRcLuM47gYsdKVNwcI33+Ot+Gby sogw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=reHoaaC0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id cx3-20020a17090afd8300b0027367e0c931si790738pjb.129.2023.09.19.22.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 22:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=reHoaaC0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 45EA3806A859; Tue, 19 Sep 2023 12:16:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232490AbjISTQT (ORCPT + 99 others); Tue, 19 Sep 2023 15:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbjISTQQ (ORCPT ); Tue, 19 Sep 2023 15:16:16 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 146759D; Tue, 19 Sep 2023 12:16:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D2F1C433C8; Tue, 19 Sep 2023 19:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695150970; bh=jf+VEtEVDip16BygVcd1gg6eYv9qfsttIJH+Gqr6U3Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=reHoaaC0L+T06Lbrc+bcdJAKJM4JMHS9YsU9sfplgt3Sw9jHEa1m5o3/J9G1/JL88 qaf2fDgQI31zADN7roR0GDMWqKeXyjx/WYldlsCaGDkSesVgV7TqTKOgR+cqKqSb87 kzMc7k4UR84aAGB0/4nRnB+d2k2TgBxxfHkuaKB0= Date: Tue, 19 Sep 2023 21:16:04 +0200 From: Greg Kroah-Hartman To: Petr Mladek Cc: John Ogness , Jiri Slaby , linux-serial@vger.kernel.org, Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH tty v1 01/74] serial: core: Provide port lock wrappers Message-ID: <2023091933-dollar-unwell-3ffd@gregkh> References: <20230914183831.587273-1-john.ogness@linutronix.de> <20230914183831.587273-2-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 fry.vger.email 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 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 12:16:19 -0700 (PDT) On Tue, Sep 19, 2023 at 04:24:48PM +0200, Petr Mladek wrote: > On Thu 2023-09-14 20:43:18, John Ogness wrote: > > 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 > > +/** > > + * 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); > > +} > > IMHO, it would have been better to pass the flags variable directly > via a macro as it is done in most *_lock_*_irqsafe() APIs. I mean > something like: > > /** > * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts > * @up: Pointer to UART port structure > * @flags: Interrupt flags storage > * > * Returns: True if lock was acquired, false otherwise > */ > #define uart_port_lock_irqsave(up, flags) \ > ({ \ > local_irq_save(flags); \ > uart_port_lock(lock) \ > }) > > > + > > +/** > > + * 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); > > +} > > Similar here: > > /** > * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts > * @up: Pointer to UART port structure > * @flags: Interrupt flags storage > * > * Returns: True if lock was acquired, false otherwise > */ > #define uart_port_trylock_irqsave(up, flags) \ > ({ \ > bool __ret; \ > \ > local_irq_save(flags); \ > __ret = uart_port_trylock(lock) \ > if (!__ret) \ > local_irq_restore(flags); \ > __ret; \ > }) What is the difference here of a macro vs. an inline function going to do for the resulting binary? The important thing is now we have wrapper functions, people can tweak them all they want to see if we can get better results :) thanks for the review! greg k-h