Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp176489imm; Thu, 31 May 2018 21:41:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJQJEJMd141szaD9ph2jJpMYx/ItSYLi0A3XHCWLjwni19fxjH9hpPo/YgwKpPszOIDc9ho X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr9686538plg.170.1527828098217; Thu, 31 May 2018 21:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527828098; cv=none; d=google.com; s=arc-20160816; b=lHtDvlHWKGmK0APTQmnwpJ7j1WHUxVD3eZluOderPrfEtckUrhRFRA52Ntnld/SjJ8 lEKSNCs5rRkMBWxD31MOwjzDyVl9N4DQ396XbjVTkIvc7O1nMKjoEIsNJoY4gvokwMW4 kvruJ/98AhJoAH/jQUCMQZS01MaEHuevrlusxRWBuZiKhihFM68a3BTfJDG9seubfTx4 hnr2nz5UshydoHCQsaUWBMPqTjX9P7e6UyfwzymRi16uAt1sxonGf4lVTHG4D/YaW0Bn xcL8MSOhaRvrZkp0yyXXQ+bMm0hWn/gWfNdnko3Pe+CJtW4VavmlMlDJRLKuLsWlP6xf M5yQ== 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:dkim-signature:arc-authentication-results; bh=e+rb/ppkFJ6qwOF1caPm+Oqo10XpgrOiBivmRd9Ndwg=; b=hqnMWoX5iCzDJdvweRLwAh6FbT1UeSyuVg1TgPg1b64N6E2FNrKtfC8810Yck0HzRw CWdecmchP6A5qDeKOH5DnwmsLJ6m9gR8NB9P9r7ol0d5QpamSrWWUdSV71qoXbArbs2L HSrOpGTkE1rgU2WRWk4uBAhLOFwR5P1G8axpjGI0snYh84n4ooUjEFimdJ4rNugFCe8O 5exrsmxrMuVmAMlUXvEb4n8RUqHmcYxqG1J80NEsAwMXCK4/mCWscrZk7H+iyGCNyJpz TGHN6Y4gclRPv3FrYbbikJdFh1A4XkfXBo8WihVCLE4dh0xlIOLzquzEEx4y/1dqLie7 NsTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hDaIYC0T; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 77-v6si38289387pfz.334.2018.05.31.21.41.23; Thu, 31 May 2018 21:41:38 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hDaIYC0T; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750983AbeFAEk5 (ORCPT + 99 others); Fri, 1 Jun 2018 00:40:57 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:39178 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750758AbeFAEk4 (ORCPT ); Fri, 1 Jun 2018 00:40:56 -0400 Received: by mail-pl0-f66.google.com with SMTP id f1-v6so14121979plt.6 for ; Thu, 31 May 2018 21:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=e+rb/ppkFJ6qwOF1caPm+Oqo10XpgrOiBivmRd9Ndwg=; b=hDaIYC0T2bodHKliT6ZmVx0fhjJzEIkhfUwlvWoF8cYS0aJFadimn7RL3du/ysgsm9 ozzNB+XGh3lreE2e6hH7d1365dlIm2b3JShFT1wc1zBfjagqShV5RI8gpugzgpq5E+3R rMrMO9Px3LeI9uPvMzuUh7jV+2nCRPXUAz6FxvnwDJa9CZRydzkOgAQMZRkytegAGp96 y3CGW2CaMKMRKJ3gV3vEGZSRwNbwnrtzQOaZqwqWRUw0ZvdYb6ObAuqqeaaZNzKwDKYX RssmKAi2RRZqkoWhdl8eIt+TTHYhKljGge1XonnDFyX5tVlYnnxJnAcF4Os4SLlAOPHI tUFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=e+rb/ppkFJ6qwOF1caPm+Oqo10XpgrOiBivmRd9Ndwg=; b=ZlnpFjMCcvnc7s2x6PPeQ2HdQca4WajL947tk68Q2gHOlWzsEhE6zEDe+9Eh/ePbgZ zxAMlQGOlQsj2OjfNDxtmlYyeAkVyDBqsubxrDrhF7L3+x4Osdj2wqmm6dybx5l+Cq5G 3IXZ1gv7EHSyEOKkDijrlaXMDfNd33hEHWow3E4TPUejcZ8q/oKCYiZ8m8W0ucWjwhHi 3XDJ1slb9q+FVOT1zDdToiKNxXrD2BV4LO3hdWnz5RncIRmdC35vt8qznS46EvNsuC5Z j5hxOO2OSrbE2oY4vzcKPywft9gYXDdAngvz4CylSKdNRYhkkJVE0IRId8+/Nbe1ZXh9 og7g== X-Gm-Message-State: ALKqPwfEyY6zDl35q952Y+eyFR7LISMqtELoHW/uuOsovc/Hidj8ipnY UdicN+oTRBev1Op6hu7VB8Q= X-Received: by 2002:a17:902:ab8d:: with SMTP id f13-v6mr9684712plr.81.1527828055594; Thu, 31 May 2018 21:40:55 -0700 (PDT) Received: from localhost ([39.7.51.205]) by smtp.gmail.com with ESMTPSA id o84-v6sm89421007pfi.27.2018.05.31.21.40.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 21:40:54 -0700 (PDT) Date: Fri, 1 Jun 2018 13:40:50 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Sergey Senozhatsky , Maninder Singh , sergey.senozhatsky@gmail.com, rostedt@goodmis.org, linux-kernel@vger.kernel.org, a.sahrawat@samsung.com, pankaj.m@samsung.com, v.narang@samsung.com Subject: Re: [PATCH 2/2] printk: make sure to print log on console. Message-ID: <20180601044050.GA5687@jagdpanzerIV> References: <20180531102246epcas5p2f1cbc6ff217172e12e2f78bb88eb4a7e~zs5h59tMh2250222502epcas5p2S@epcas5p2.samsung.com> <20180531105215.GF477@jagdpanzerIV> <20180531122112.bfeqtmwpl2qc67a5@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180531122112.bfeqtmwpl2qc67a5@pathway.suse.cz> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (05/31/18 14:21), Petr Mladek wrote: > > > > Upstream printk has no printing kthread. And we also run > > printk()->console_unlock() with disabled preemption. > > Yes, the comment was wrong Yes, that was the only thing I meant. I really didn't have any time to look at the patch yesterday, just commented on the most obvious thing. > but the problem is real. Yep, could be. But not exactly the way it is described in the commit messages and the patch does not fully address the problem. The patch assumes that all those events happen sequentially. While in reality they can happen in parallel on different CPUs. Example: CPU0 CPU1 set console verbose dump_backtrace() { // for (;;) print frames printk("%pS\n", frame0); printk("%pS\n", frame1); printk("%pS\n", frame2); printk("%pS\n", frame3); ... console_loglevel = CONSOLE_LOGLEVEL_SILENT; printk("%pS\n", frame12); printk("%pS\n", frame13); } Part of backtrace or the entire backtrace will be missed, because we read the global console_loglevel. The problem is still there. > The console handling is asynchronous even without the kthread. > The current console_lock owner is responsible for handling messages > also from other CPUs. A nitpick: that's another thing to improve in the commit message, because I don't see that console_silent() race in the upstream kernel. We even don't have any users of console_silent() function. The only thing that ever sets console_loglevel to CONSOLE_LOGLEVEL_SILENT is kernel/debug/kdb/kdb_io.c Now, there is a bunch of places that manually set console_loglevel. At a glance, __handle_sysrq() *seems* to be interesting: --- void __handle_sysrq(int key, bool check_mask) { struct sysrq_key_op *op_p; int orig_log_level; int i; rcu_sysrq_start(); rcu_read_lock(); /* ~ * Raise the apparent loglevel to maximum so that the sysrq header ~ * is shown to provide the user with positive feedback. We do not ~ * simply emit this at KERN_EMERG as that would change message ~ * routing in the consumers of /proc/kmsg. ~ */ ~ orig_log_level = console_loglevel; ~ console_loglevel = CONSOLE_LOGLEVEL_DEFAULT; pr_info("SysRq : "); op_p = __sysrq_get_key_op(key); if (op_p) { /* * Should we check for enabled operations (/proc/sysrq-trigger * should not) and is the invoked operation enabled? */ if (!check_mask || sysrq_on_mask(op_p->enable_mask)) { pr_cont("%s\n", op_p->action_msg); console_loglevel = orig_log_level; op_p->handler(key); } else { pr_cont("This sysrq operation is disabled.\n"); } } else { pr_cont("HELP : "); /* Only print the help msg once per handler */ for (i = 0; i < ARRAY_SIZE(sysrq_key_table); i++) { if (sysrq_key_table[i]) { int j; for (j = 0; sysrq_key_table[i] != sysrq_key_table[j]; j++) ; if (j != i) continue; pr_cont("%s ", sysrq_key_table[i]->help_msg); } } pr_cont("\n"); ~ console_loglevel = orig_log_level; } rcu_read_unlock(); rcu_sysrq_end(); } --- But only at a glance... In fact, it raises the loglevel to maximum only to printk() "This sysrq operation is disabled" or "HELP: " and help_msg messages. The sysrq handler itself is executed under orig_log_level loglevel. So it doesn't look like we are loosing anything super-critical, after all. This case is very interesting: static void uv_nmi_dump_state(int cpu, struct pt_regs *regs, int master) { if (master) { int tcpu; int ignored = 0; int saved_console_loglevel = console_loglevel; pr_alert("UV: tracing %s for %d CPUs from CPU %d\n", uv_nmi_action_is("ips") ? "IPs" : "processes", atomic_read(&uv_nmi_cpus_in_nmi), cpu); console_loglevel = uv_nmi_loglevel; atomic_set(&uv_nmi_slave_continue, SLAVE_EXIT); for_each_online_cpu(tcpu) { if (cpumask_test_cpu(tcpu, uv_nmi_cpu_mask)) ignored++; else if (tcpu == cpu) uv_nmi_dump_state_cpu(tcpu, regs); else uv_nmi_trigger_dump(tcpu); } if (ignored) pr_alert("UV: %d CPUs ignored NMI\n", ignored); console_loglevel = saved_console_loglevel; pr_alert("UV: process trace complete\n"); } else { while (!atomic_read(&uv_nmi_slave_continue)) cpu_relax(); while (this_cpu_read(uv_cpu_nmi.state) != UV_NMI_STATE_DUMP) cpu_relax(); uv_nmi_dump_state_cpu(cpu, regs); } uv_nmi_sync_exit(master); } And it seems to be broken anyway... uv_nmi_dump_state() relies on printk() to do a direct console_unlock() call from NMI. We don't do it. Apart from that, printk() is in printk_nmi() context when we call this function, which sometimes can use printk_deferred() directly [loglevel messages bit will be useful here], but sometimes it stores the messages in per-CPU buffers and flushes them to the logbuf later - we don't carry the must-be-printed bit with every printk_safe/printk_nmi message and as of now there is no way for to forcibly set it [because it's set automatically in log_store() after msg->level >= console_loglevel check]. So I'd say that most likely the following scenarios can suffer: - NMI comes in, sets loglevel to X, printk-s some data, restores the loglevel back to Y - IRQ comes in [like sysrq, etc] comes in and does the same thing - software exception comes in and does the same thing [e.g. bust_spinlocks() at arch/s390/mm/fault.c] IOW, the following scenario CPUA something happens set console loglevel printk 0. writes to the logbuf, e.g. printk_deferred() 1. writes to the logbuf AND calls console_unlock() 2. writes to printk_safe per-CPU buffer 3. writes to printk_nmi per-CPU buffer ... restore loglevel This is how I see the problem at the moment. May be I'm missing something. Would be great to see more real cases when it actually hits us and more analysis, please. -ss