Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2463294pxy; Tue, 3 Aug 2021 07:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK+DAJTtR6L+ElzsbFUutvlFcb7pKL244mR4wdsayokPUiJWEe6aWn8KEM2nr79W0KNTjV X-Received: by 2002:a5e:8e02:: with SMTP id a2mr210432ion.205.1627999765088; Tue, 03 Aug 2021 07:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627999765; cv=none; d=google.com; s=arc-20160816; b=JrJkehUodpb4r5MN8eg+P0GythF/+is77gaPUu9JcuoYt0DvxWQPudC7zBhBWilltz gnJOjE3z12hbtDMEmASE/9+WzGXjFDg7d2xjVQM48xinu8Ct2AatU80hhIGRUHfp/pqv +YiVt9lhFmi79GatMQwZ2f4WUXLKzt8TgkKZeAVHuF+cdRy8syjt/N3wZOrVNgTvrbuq lKwL/8c9bVYhruhDj9lUUhpnzWnoUoBp/fIKxEQhwkme/6z4Wne/8JBb6S0jnjwbDfmw u0utxyc6so2tQMPfQSJIUFPUGkzHVUqPhinypty5cFMfPLLMMmWZpH2tx35K90lCYUlu boLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=R/i4YE2W8trk1AqyYhC38fKgeV1wIVnbtttYwA8CzqE=; b=R7hCcSJKwXd8jegmLDcLRYaAnDpM5XPU+PRKEA4hKEyMgDAUrU4ArBBZoumtcGH5ZI bvWYHTe+9dRY5ejSYJhWssfeQ1h0Y3pAOtfEyXCjOzd8BKdrEek4r+K/p/rDn8ikBtpl xPwqdQiNoRjXM6sE+cg+GxIj1CDM/tscsGO6SRY+mVVSmUQKqNGG/K9DK+pr01ZTZFXB Tt7FzsRDbFA3goU3v270cwkySHmbxRDnFJusF3Lei88/gNTX/VB7Y58IEMsOSZmUR+Zv nK1ms5naHmKP13Nl15W3g6ixB63vACw+xxYLWUAK0b7lqZJ8Yzik5ik/+ucSrj6oHaQR icxw== 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si12090496ilq.19.2021.08.03.07.09.05; Tue, 03 Aug 2021 07:09:25 -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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236485AbhHCOIR (ORCPT + 99 others); Tue, 3 Aug 2021 10:08:17 -0400 Received: from mga18.intel.com ([134.134.136.126]:12751 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236469AbhHCOIQ (ORCPT ); Tue, 3 Aug 2021 10:08:16 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10064"; a="200888330" X-IronPort-AV: E=Sophos;i="5.84,291,1620716400"; d="scan'208";a="200888330" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2021 07:08:05 -0700 X-IronPort-AV: E=Sophos;i="5.84,291,1620716400"; d="scan'208";a="568680226" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2021 07:07:58 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1mAv5C-004kW7-El; Tue, 03 Aug 2021 17:07:50 +0300 Date: Tue, 3 Aug 2021 17:07:50 +0300 From: Andy Shevchenko To: John Ogness Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , 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 Subject: Re: [PATCH printk v1 10/10] serial: 8250: implement write_atomic Message-ID: References: <20210803131301.5588-1-john.ogness@linutronix.de> <20210803131301.5588-11-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210803131301.5588-11-john.ogness@linutronix.de> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > +} > +static inline unsigned char serial8250_clear_IER(struct uart_8250_port *up) > +{ > + struct uart_port *port = &up->port; > + unsigned int clearval = 0; > + unsigned long flags; > + unsigned int prior; > + bool is_console; > + > + is_console = uart_console(port); > + > + if (up->capabilities & UART_CAP_UUE) > + clearval = UART_IER_UUE; > + > + if (is_console) > + console_atomic_cpu_lock(flags); > + > + prior = serial_port_in(port, UART_IER); > + serial_port_out(port, UART_IER, clearval); > + > + if (is_console) > + console_atomic_cpu_unlock(flags); Ditto. > + return prior; > +} ... > + is_console = uart_console(port); > + > + if (is_console) > + console_atomic_cpu_lock(flags); > up->ier = port->serial_in(port, UART_IER); > + if (is_console) > + console_atomic_cpu_unlock(flags); > + I'm wondering why you can't call above function here? ... > + is_console = uart_console(p); > + if (is_console) > + console_atomic_cpu_lock(flags); > ier = p->serial_in(p, UART_IER); > + if (is_console) > + console_atomic_cpu_unlock(flags); Ditto. ... > + is_console = uart_console(port); > + > + if (is_console) > + console_atomic_cpu_lock(flags); > + > + ier = serial_in(up, UART_IER); > + serial_out(up, UART_IER, ier & (~mask)); > + > + if (is_console) > + console_atomic_cpu_unlock(flags); Ditto. ... > + if (uart_console(port)) > + console_atomic_cpu_lock(flags); > + > + ier = serial_in(up, UART_IER); > + serial_out(up, UART_IER, ier | mask); > + > + if (uart_console(port)) > + console_atomic_cpu_unlock(flags); Ditto. Looking into above note, that uart_console(port) can give different results here, AFAIR. -- With Best Regards, Andy Shevchenko