Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp482315pxt; Thu, 5 Aug 2021 04:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLK1s7jCstVFkNyuSB9cmJqs/6AtV6dRyv1OhAuecU5tfAVg+q6qHujOE9EhIV4t5FIRvg X-Received: by 2002:a05:6402:498:: with SMTP id k24mr6102186edv.25.1628163576077; Thu, 05 Aug 2021 04:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628163576; cv=none; d=google.com; s=arc-20160816; b=VO88YJkano4SadnO5j4yN8k6ugd5IOu8XV7eIAn063RCr7xNCtFNf04XYCz6oynOCk sce12Z72HgTE3ajO4kN5gMKY90vssvovGN7jsSIPP6Uvth9r1gFuFNzVEv9PLIvWZafK RN9m5Zwn1T0eMADjtWNsa+v52Gp0nSZNwDAFUKDsz3zIkmzcGQmGrfGZ7RjUt6x8X8SI P8YfuGciFToZkSRbwhUy0P/XYdNWWFMtutF/59H+cm+ludsNiKtzAlVDup+Ka7m1o2Sm ipmmL/FX+xkfdj/Q70mTK0yBaylDCadwrN/wp6sSA39+BINNNGa6Id/TQ+8ISw/VNrre 0hKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=I526ijbe8/74kjOA75IwkOyaPcqEXfx0YMdi/ub5h0M=; b=gs9w4VRLp69nM25t9AAQU05StREUirOyDsviCejWi8V5FI8e2pwla63iNG5rok8fIp IxxjsfGT+CIatF+8UwtU+4MhPMuZXGRIFsvMeOf0FGQCb4KnlIeKpSSOu/3bTrdn5u2U aXlu/ph1CpM8Oe77sYzXzVdSbbnJV93ihti/tKl1iWBRjtJ2mS9Ld9U3eg1xwE9dz3Ls z4umz6TagVtFmw9SJnZxApRdMQDq7bKJoECow7xLaPlkZNMZGIdTPm3pqP2hi5tTIWZW yceIA/VrVJhhuCX1yRlmjwr6pooNHOJtxltiIfnMMk5VVMW4cyOFaDtYAHQdC8dfQ0LT wmLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si5300980edy.570.2021.08.05.04.39.12; Thu, 05 Aug 2021 04:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238961AbhHEHsF (ORCPT + 99 others); Thu, 5 Aug 2021 03:48:05 -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-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-kernel@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