Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5797657imb; Fri, 8 Mar 2019 02:32:25 -0800 (PST) X-Google-Smtp-Source: APXvYqyLPuYB1CGhaeYJyfd+ehzTnw72zafHOGaQgHJiSbp5YtFdcufEpDZLj0umWsbuXOfX7/J9 X-Received: by 2002:a17:902:ab8f:: with SMTP id f15mr18037676plr.218.1552041145475; Fri, 08 Mar 2019 02:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552041145; cv=none; d=google.com; s=arc-20160816; b=MdUDFxSQJBgBvsfWWKSX5C6OZAuwp5eAYCcVqio6jWMaGY5f/jkdFeHpMUFa1GzPq3 iIAxVFbh4ui2jTAsc0MSzlvHkLt1+8vTvBwVIqXsVpT7LtKMpPyY9QkVAImuDUGe5Tg0 3nb8CFDPm4AbmAQeBZZbBbOLA92Ml/vJuL0QZbbvLEBgpV03uqurM30oFyfP7g2oOhHm MajSyt7bHjUU2oiw3tWIoIKQdh9mCNoqsqIPTObfyyEVASbynV4z6kGDhOSDLJRZ0+od Gx9IjRJR+XbOBi69T7PjFjheX3wUPW2cT8WJbX4G/NXypZxIHrLCdDyIpY0A/p9RRUen fFvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=aaHFQZpJKaHCd2rHzLAgGxiJ5bWZ9dOXuJP/OPeltYI=; b=kkQmWXb0pCF2pUbijyQ6NXRtFqXL35ShuVByl0cZzH3inSCZivMQVgVMczpflnqpl1 sjvFMULu9jyCv6Je+FLm+5HmD09VKGsStSdwl4QCJwaqlCS/67U52p2MAa9DFcOTaw0s yDfOGxjf0Ddx/I32IFbENdb0iKIeqauMmedLsXsx/4x6kOB6YP4U70lo7a+Wr+Wv3315 p0febCOM5I0RkMe8eh/tq+H/MAimeZPUrFOo39PorM36id08njnlJ9/wj1xsRLRLV2FU myvodzcm6dDV5lSPMvxTmnWwvDpsKkVOL6lrukqlHy0/67WDGccDgjjxAqnSZDQUWGR1 ZPOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si6376174pfb.189.2019.03.08.02.32.09; Fri, 08 Mar 2019 02:32:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726441AbfCHKb3 (ORCPT + 99 others); Fri, 8 Mar 2019 05:31:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:59196 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725975AbfCHKb3 (ORCPT ); Fri, 8 Mar 2019 05:31:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C968DAF7B; Fri, 8 Mar 2019 10:31:27 +0000 (UTC) Date: Fri, 8 Mar 2019 11:31:27 +0100 From: Petr Mladek To: Sergey Senozhatsky Cc: John Ogness , linux-kernel@vger.kernel.org, Peter Zijlstra , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC PATCH v1 19/25] printk: introduce emergency messages Message-ID: <20190308103127.txsgv3d6lqlf6pad@pathway.suse.cz> References: <20190212143003.48446-1-john.ogness@linutronix.de> <20190212143003.48446-20-john.ogness@linutronix.de> <20190307073029.GA489@jagdpanzerIV> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190307073029.GA489@jagdpanzerIV> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2019-03-07 16:30:29, Sergey Senozhatsky wrote: > On (02/12/19 15:29), John Ogness wrote: > [..] > > +static bool console_can_emergency(int level) > > +{ > > + struct console *con; > > + > > + for_each_console(con) { > > + if (!(con->flags & CON_ENABLED)) > > + continue; > > + if (con->write_atomic && level < emergency_console_loglevel) > > + return true; > > + if (con->write && (con->flags & CON_BOOT)) > > + return true; > > + } > > + return false; > > +} > > + > > +static void call_emergency_console_drivers(int level, const char *text, > > + size_t text_len) > > +{ > > + struct console *con; > > + > > + for_each_console(con) { > > + if (!(con->flags & CON_ENABLED)) > > + continue; > > + if (con->write_atomic && level < emergency_console_loglevel) { > > + con->write_atomic(con, text, text_len); > > + continue; > > + } > > + if (con->write && (con->flags & CON_BOOT)) { > > + con->write(con, text, text_len); > > + continue; > > + } > > + } > > +} > > + > > +static void printk_emergency(char *buffer, int level, u64 ts_nsec, u16 cpu, > > + char *text, u16 text_len) > > +{ > > + struct printk_log msg; > > + size_t prefix_len; > > + > > + if (!console_can_emergency(level)) > > + return; > > + > > + msg.level = level; > > + msg.ts_nsec = ts_nsec; > > + msg.cpu = cpu; > > + msg.facility = 0; > > + > > + /* "text" must have PREFIX_MAX preceding bytes available */ > > + > > + prefix_len = print_prefix(&msg, > > + console_msg_format & MSG_FORMAT_SYSLOG, > > + printk_time, buffer); > > + /* move the prefix forward to the beginning of the message text */ > > + text -= prefix_len; > > + memmove(text, buffer, prefix_len); > > + text_len += prefix_len; > > + > > + text[text_len++] = '\n'; > > + > > + call_emergency_console_drivers(level, text, text_len); > > So this iterates the console list and calls consoles' callbacks, but what > prevents console driver to be rmmod-ed under us? > > CPU0 CPU1 > > printk_emergency() rmmod netcon > call_emergency_console_drivers() > con_foo->flags & CON_ENABLED == 1 > unregister_console(con_foo) > con_foo->flags &= ~CON_ENABLED > __exit // con_foo gone ? > con_foo->write() > > We use console_lock()/console_trylock() in order to protect the list and > console drivers; but this brings scheduler to the picture, with all its > locks. Great catch! I think that it is doable to guard the list using RCU. Best Regards, Petr