From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28AC7C4338F for ; Thu, 5 Aug 2021 07:47:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0532A60E52 for ; Thu, 5 Aug 2021 07:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238768AbhHEHrg (ORCPT ); Thu, 5 Aug 2021 03:47:36 -0400 Received: from mail-wm1-f43.google.com ([209.85.128.43]:43544 "EHLO mail-wm1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238826AbhHEHr3 (ORCPT ); Thu, 5 Aug 2021 03:47:29 -0400 Received: by mail-wm1-f43.google.com with SMTP id l8-20020a05600c1d08b02902b5acf7d8b5so2296589wms.2; Thu, 05 Aug 2021 00:47:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=I526ijbe8/74kjOA75IwkOyaPcqEXfx0YMdi/ub5h0M=; b=CNUVuwoD+bs9BID+JkSaLIZ2GUCNFulvqOo+Hu9aoGFY3i2YrDFagG5Bftny8vQ+I0 TZyQfhn/+RnJt+5wbKum24h8ePCDokT8c8zQ6aXD1T3GnHGGK8vocsLWhvqp6PHC8L6Z 72Ws3qvrBkFp9B2PYh0e4AtBRUXDyTJPAWQUXNPX/PiffiiKewZXgOOuX6rVPsCaERQU GpB+i6a+nz+dZOQTJ+dAQ6D1Majpkzqfw1+biIj7llVZk5hBuakG8MVfRQff6Vw5jg4F ZttSaDJLBeoYYUVvR0FdcJs8n5C6swpOBBxRyrlQII6zMJWoDx4ikRRyoAaA2xuK0r1q b83g== X-Gm-Message-State: AOAM531WbBYnjSR7/aw9jd7zADyRepkD//levFYY+JEvWPXy0adItB2i jnhWmYJh01eRWNsxD396FI8= X-Google-Smtp-Source: ABdhPJwvOwnv09InkfauY/5dCjERsBYo1U1VQMOeA1IMI5PuQsUW4j8b79rm41Lbc7bMwllLsM9EwQ== X-Received: by 2002:a05:600c:290:: with SMTP id 16mr13385731wmk.71.1628149634054; Thu, 05 Aug 2021 00:47:14 -0700 (PDT) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id t1sm4985968wrm.42.2021.08.05.00.47.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Aug 2021 00:47:13 -0700 (PDT) Subject: Re: [PATCH printk v1 10/10] serial: 8250: implement write_atomic To: Andy Shevchenko , John Ogness Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Paul Cercueil , Matthias Brugger , Andrew Jeffery , Christophe JAILLET , kuldip dwivedi , Wang Qing , Andrij Abyzov , Johan Hovold , Eddie Huang , Claire Chang , Hsin-Yi Wang , Zhang Qilong , "Maciej W. Rozycki" , Guenter Roeck , Sergey Senozhatsky , Serge Semin , "Gustavo A. R. Silva" , Al Cooper , linux-serial@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20210803131301.5588-1-john.ogness@linutronix.de> <20210803131301.5588-11-john.ogness@linutronix.de> From: Jiri Slaby Message-ID: <931ebc1a-3cc9-677c-44c3-7cbd645eb4f4@kernel.org> Date: Thu, 5 Aug 2021 09:47:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 03. 08. 21, 16:07, Andy Shevchenko wrote: > On Tue, Aug 03, 2021 at 03:19:01PM +0206, John Ogness wrote: >> Implement an NMI-safe write_atomic() console function in order to >> support synchronous console printing. >> >> Since interrupts need to be disabled during transmit, all usage of >> the IER register is wrapped with access functions that use the >> printk cpulock to synchronize register access while tracking the >> state of the interrupts. This is necessary because write_atomic() >> can be called from an NMI context that has preempted write_atomic(). > > ... > >> +static inline void serial8250_set_IER(struct uart_8250_port *up, >> + unsigned char ier) >> +{ >> + struct uart_port *port = &up->port; >> + unsigned long flags; >> + bool is_console; > >> + is_console = uart_console(port); >> + >> + if (is_console) >> + console_atomic_cpu_lock(flags); >> + >> + serial_out(up, UART_IER, ier); >> + >> + if (is_console) >> + console_atomic_cpu_unlock(flags); > > I would rewrite it as > > if (uart_console()) { > console_atomic_cpu_lock(flags); > serial_out(up, UART_IER, ier); > console_atomic_cpu_unlock(flags); > } else { > serial_out(up, UART_IER, ier); > } > > No additional variable, easier to get the algorithm on the first glance, less > error prone. Yes, the original is terrible. Another option: bool locked = console_atomic_cpu_lock(flags, uart_console()); serial_out(up, UART_IER, ier); console_atomic_cpu_unlock(flags, locked); Which makes console_atomic_cpu_lock to lock only if second parameter is true and return its value too. BTW I actually don't know what console_atomic_cpu_lock does to think about it more as I was not CCed, and neither lore sees the other patches: https://lore.kernel.org/linux-mips/20210803131301.5588-1-john.ogness@linutronix.de/ thanks, -- js suse labs