Received: by 10.223.176.46 with SMTP id f43csp159688wra; Tue, 23 Jan 2018 18:12:42 -0800 (PST) X-Google-Smtp-Source: AH8x224Wy9oE/zZF2sEQ88h+9/2AfDeDzGpdvBP6FwZyAATaKLL9YYXcRPKQeWUElKdHMpcdixP9 X-Received: by 10.98.105.199 with SMTP id e190mr11369756pfc.233.1516759962511; Tue, 23 Jan 2018 18:12:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516759962; cv=none; d=google.com; s=arc-20160816; b=XNKPAsXKf64qg78rDzkr4dxt1on3zPaljpkfBUCl6NBlz5pokgOgFGS8cK00aDSUKY KsSEr/JX5ZL2s6tHUdT0amMA9HdNpVLe9F6IvvKzX0OaPqJ5JkfmiSZoM10UBijAZiUv aS3YrDZzzNhVmbT8ttXQHNyQtPLK6WeWcujkqGUUW44y1bt9uDIyJ9iUwKGmNfv1GsXC X1/a1PW1rJNWzpSXmAwBi+a2yJ+QMXoMWjRqCqm2bB9pi0BZEO36y5Un5wpjj45nRpms 5KndAxhjCnXjcjCjZAd6K53CQDpqpDlotnkKtFLMMyNM+f/7qSgnE+M8QM4m3efCZ8ev FcOg== 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=nhgDnPndrfJ5XRrkBEGdLc+lmZt51zGBz9HVif8Pug8=; b=nsgy6OKpYN/KOQ7C4EH6jIkJURQ3ixt7x6hNL21d6HTfd1EY+FN0x54tQ4x6rCWqJH MV4RV50aAKz1gG60mBTaiWCemztlaUrBUyRzOXx0YEAVoJyI5/+eaSIVn1Y8MQJKemFD PEjlsZN07lXZz05gRlXBb1utEz5HKxtzaDKNca2+drme3Tp70TBFC6ab5vbcFXTajxZ8 ZIODzqYh9ryVVZoM60I8jvQn2xzkyjgZX0Bc8oBYrByBtW5BdK3o5gcn8q54AaSfmmFo YP02u3wJ2TcDqEK9My3xDGjgr5oKwhGmGG4+7skY842O/HcKAwdToyBEccKidZ4moSpQ /g+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NjCvwiTc; 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=NONE 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 d2-v6si2652910plh.27.2018.01.23.18.12.29; Tue, 23 Jan 2018 18:12:42 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NjCvwiTc; 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=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752283AbeAXCLn (ORCPT + 99 others); Tue, 23 Jan 2018 21:11:43 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:42888 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186AbeAXCLk (ORCPT ); Tue, 23 Jan 2018 21:11:40 -0500 Received: by mail-pf0-f173.google.com with SMTP id b25so1850371pfd.9 for ; Tue, 23 Jan 2018 18:11:39 -0800 (PST) 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=nhgDnPndrfJ5XRrkBEGdLc+lmZt51zGBz9HVif8Pug8=; b=NjCvwiTclvDOrR9LCLqU7gEbmkqtELHdWWYVTEOphttYuKnhLyl9MNhckI2ctpIefD tUkI4hgd8uMqaZ4tdhR8QzrikdXZK7mf3hpYt2q6CT3QXnBVXg0hjoVAXkfyGEz6r8/B dL7JjhEn+eRCPoZ1htXmKxrbP5ecffhM5LA3gIWM4NjS1cyVvBSBwTKXtT/dWcQiEkBc qB9aRI2uCLJ5AucrQg2Y5RC96YfxVhBhZwo5e9XwdtQP+LLPVoI3vPPqHOrgziIX5gJc xArBiy72eD48Iek9sOn63X9Qbwcy0HjUeGbPYrm9JpXwV32Spvrt0BRF+K2AK+laF/27 0SAg== 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=nhgDnPndrfJ5XRrkBEGdLc+lmZt51zGBz9HVif8Pug8=; b=snfK0wn/GzR3wrVHOt+pwFMqcG+nmuMIIzSy6LCLfPq8Csa6vcwexFqkqggpl2Eruo 7j3t2VWrRAZsbKHn508YbyZN/RF3G3s44eRPUtOEbyanC59JLrofUiKsQqhrw0DcVn4p eyATtbFSC5X0+ugy5FE4wsP4maTlbUa9vj5MPQ/TIzBnfqO5FngjfBUwoG7MJXl76qGW /PBAxRP0Q9vRRtVw3VBOD3RdtKUbqR1QgV7A1JWegI0W3nF6lgZlXIRXUKtp2qlOpFoQ 8/A52Aix7xVYJgNpS0yucJDr6oYaOjmQIMmpMcO4YLJ/QAV8URLFGlt0jndmj2hSztkN DlHA== X-Gm-Message-State: AKwxytciMMWscRBLwHhwNCenFtImLWDRjR5irB6mVHvt2vJ5XpNgZTLi vJm4fbOO/ayX+znIicV/ogY= X-Received: by 2002:a17:902:d217:: with SMTP id t23-v6mr6876815ply.303.1516759899444; Tue, 23 Jan 2018 18:11:39 -0800 (PST) Received: from localhost ([175.223.3.173]) by smtp.gmail.com with ESMTPSA id k90sm6895944pfk.171.2018.01.23.18.11.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 18:11:37 -0800 (PST) Date: Wed, 24 Jan 2018 11:11:33 +0900 From: Sergey Senozhatsky To: Steven Rostedt Cc: Sergey Senozhatsky , Sergey Senozhatsky , Petr Mladek , Tejun Heo , akpm@linux-foundation.org, linux-mm@kvack.org, Cong Wang , Dave Hansen , Johannes Weiner , Mel Gorman , Michal Hocko , Vlastimil Babka , Peter Zijlstra , Linus Torvalds , Jan Kara , Mathieu Desnoyers , Tetsuo Handa , rostedt@home.goodmis.org, Byungchul Park , Pavel Machek , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 0/2] printk: Console owner and waiter logic cleanup Message-ID: <20180124021034.GA651@jagdpanzerIV> References: <20180119132052.02b89626@gandalf.local.home> <20180120071402.GB8371@jagdpanzerIV> <20180120104931.1942483e@gandalf.local.home> <20180121141521.GA429@tigerII.localdomain> <20180123064023.GA492@jagdpanzerIV> <20180123095652.5e14da85@gandalf.local.home> <20180123152130.GB429@tigerII.localdomain> <20180123104121.2ef96d81@gandalf.local.home> <20180123160153.GC429@tigerII.localdomain> <20180123112436.0c94bc2e@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180123112436.0c94bc2e@gandalf.local.home> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On (01/23/18 11:24), Steven Rostedt wrote: [..] > > With WQ we don't lockup the kernel, because we flush printk_safe in > > preemptible context. And people are very much expected to fix the > > misbehaving consoles. But that should not be printk_safe problem. > > Right, but now you just made printk safe unreliable to get information > out, because you need to wait for a schedule to occur, and if there's > issues, like a deadlock, that thread will never run. And you just lost > you lockdep splat. Yes and No. printk_safe and printk_nmi are unreliable - both need irq_work. That's why we forcibly flush those buffers in panic(). At least for printk_safe case, and I'm pretty sure the same stands for printk_nmi, we never said that we will store all the messages that were printed from unsafe context (recursion or NMI). The only thing we said - we will try not to deadlock the system. Now we are adding one more thing to printk_safe - we will also try not to lockup the system. Default printk_safe buffer size might not be enough to store a very large lockdep splat. And we will report that the buffer is too small and that we lost some of the lines: "here is what we have, we lost N lines, but at least we didn't deadlock the system". See f975237b76827956fe13ecfe993a319158e2c303 for more details, it contains a list of recursive-printk deadlock scenarios that printk_safe was meant to handle. It is possible and OK to lose messages in printk_safe/printk_nmi printk_safe_enter_irqsave() printk printk ... ... printk printk printk_safe_exit_irqrestore() No flush will take place as long as there is no IRQ on that CPU. But printk_safe and printk_nmi are solving different problem in the first place. > > I'll re-read this one tomorrow. Not quite following it. > > I'll add more capitals next time ;-) Ha-ha-ha ;) [..] > > pintk_safe was designed to be recursive. It was never designed to be > > used to troubleshoot or debug consoles. But it was designed to be > > recursive - because that's the sort of the problems it was meant to > > handle: recursive printks that would otherwise deadlock us. That's why > > we have it in the first place. > > So printk safe is only triggered when at the same context? If we can > guarantee that printk safe is triggered only when its because a printk > is happening at the same context (not because of an interrupt, but > really at the same context, using my context check), then I'm fine with > delaying them to a work queue. printk_safe is for printk recursion only. It happens in the same context only. When we switch to printk_safe we disable local IRQs, NMIs have their own printk_nmi thing. And the way we flush printk_safe is mostly recursive. Because we flush when we know that we will not deadlock [as much as we can; we can't control any 3rd party locks which might be involved; thus printk_deferred() usage]. Usually it's something like printk spin_lock_irqsave(logbuf_lock) printk spin_lock_irqsave(logbuf_lock) << deadlock What we have with printk_safe is printk local_irq_save printk_safe_enter spin_lock(logbuf_lock) printk vprintk_safe queue irq work spin_unlock(logbuf_lock) printk_safe_exit local_irq_restore >>> IRQ work printk_safe_flush printk spin_lock_irqsave(logbuf_lock) log_store() spin_unlock_irqrestore(logbuf_lock) So we flush printk_safe ASAP, which usually (unless originally we were not in IRQ) means that the flush is recursive, but safe - we don't deadlock. > That is, if we have this: > > printk() > console_lock() > > printk() > add to log buffer > > console_unlock(); Right. This is what we have right now. Every time we enable local IRQs in the console_unlock() printing loop - we flush printk_safe. And that's the problem. > printk() > console_lock() > > put in printk safe buffer > trigger work queue > console_unlock() > > flush safe buffer > printk() Right. This is what we will have with WQ. We don't flush printk_safe until we return from console_unlock(). Because printk() disables preemption for the duration of console_unlock(), we can't schedule WQ on that CPU. And we schedule flushing work only on the CPU that has triggered the recursion. Another thing: console_lock() blah blah console_unlock() In this case we will flush printk_safe withing the printing loop. Immediately. But we don't care - the CPU is preemptible, we don't lock up the kernel. > Then I'm fine with that. > > I have to look at the latest code. If this is indeed what we have, then > I admit I misunderstood the problem you want to solve. > > I only want recursive printks (those that are actually triggered by > doing a printk) to be allowed to be delayed. > > Make sense? Please take a look. -ss