Received: by 10.223.176.46 with SMTP id f43csp2653033wra; Mon, 22 Jan 2018 00:57:51 -0800 (PST) X-Google-Smtp-Source: AH8x227tWC7d0GpT5CQrL6Xg32I/ffA+wlh+/jylCzV/3RP5iRqx/DyXKc2dt7tzGSByIPJf4IUX X-Received: by 10.99.138.75 with SMTP id y72mr6670110pgd.90.1516611471634; Mon, 22 Jan 2018 00:57:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516611471; cv=none; d=google.com; s=arc-20160816; b=WH4H1QIECvbi+A0hhwonykduBQaOeDv4ULRHCifCzsqpqtpQHNhM5Cv2MYGBT/V419 o4m2JwzUDoyaFaI0Qs03rNeEUKgT3MObYceLVvtoCUXuLNMpi+k7Z/jF85ai4P1TKYLW tPguOpjn+DJeu5punut0I+Jku2Bq5f2PGjaS4cTrd2Of3kdWzx3/Zx4YAVgciGC+0NyU ixOVuC7CrQAYTUIetz3zlNEgI1EI9RZuxa0iBcxu48YiMPNszf6N4QcSu6Id37eF25Bq 1gWvUpc7Y4jXZSKyeLTQAb10iK+PQWsW/6ySN3zgMDJZubssmZspqPySmeK8/C8+2MOW l2JQ== 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=lEU56i5ZIcpLo1uosZrdVbSX0Qkb2FZBowDGtMcYU+o=; b=f55fID+xIc8B8awo1aWQ3UjbvCwB7IacTUXOdERCCSlxiZiCLlqWDfrzI9B+4/3KRK K5Pi02tke1BFrsWumC5LF6Ba0j8LfH8QVwKayn52p5tzBozj1TpbcN+9bTX1NYG6hfIO L4f8nFzjNtiJ8hWu0hRB9n8ps4ByARAUAlFO5aOjp9+OhhHSxP8k7TPm17/SozNA3XJE WZPUGdZg82dS3lRBdjl5nbhs0UtN4nBYh9ZxePP59Ms9gz8ldFXkjR4QIZ4SL+/Gus6c JWNKwiK3T+nMDiQE9DA0gWq5qW44Ihn0dl8ZQD/DVbNRGn7kQWgkb+IYhGP3DJSRpOVs 7aEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JF06iW5p; 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 f64-v6si1502186plb.817.2018.01.22.00.57.37; Mon, 22 Jan 2018 00:57:51 -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=JF06iW5p; 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 S1752811AbeAVI4k (ORCPT + 99 others); Mon, 22 Jan 2018 03:56:40 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:45305 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752530AbeAVI4h (ORCPT ); Mon, 22 Jan 2018 03:56:37 -0500 Received: by mail-pg0-f50.google.com with SMTP id c194so6576449pga.12 for ; Mon, 22 Jan 2018 00:56:37 -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=lEU56i5ZIcpLo1uosZrdVbSX0Qkb2FZBowDGtMcYU+o=; b=JF06iW5pDGpOfCjeu+Zbt6PlF8Udtyg2w/3tSoGyQMtR09nOotY+UyTvLYxQ3HqPaW 3C4F2hvsfAwCcgVliaCng9UE2Yt6lIYA+ON32pibVrDsJnEd1xRNvJCPGhMTrfpj+9+e iwiV4qqgaeALTNL+wOAfs6qmpH/asypkAFacpB1bnlZyf4gn9kNwvgkaARpPNcitzXm+ /i1mk3d5a0iz2YYNjXrh/VyRhBDCicchHUyhfweTK7e4D0Ckbjq9Onc2exFIdqeGi6E4 qIYgKVEcm9WkD5DMZnbdl91mGXi11LAehtu3Qh3BpIgRBBxKZbTaU21oAEiKBuP2eOsQ 7edQ== 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=lEU56i5ZIcpLo1uosZrdVbSX0Qkb2FZBowDGtMcYU+o=; b=cRKfd/P6/NOZjEO1HOTscUrcrY/xqFU+YrMB+F+qOlShh14tMh5w9ULpfWTSdMnIp+ 9qcqdBujJbB3oEdk7h2OsqMSTA1KFCYFWyis+II4zyMdjMpevJXT0RNd2yNg0XkPmkfo Yu+kGzh2L5e51oztmysdb0EYxDqZQj/93u8hLTV64uLD6lPfBwIDLQreorwCVvlqd4Fp NDdujY1kRI6e7gQqiAN6R7YzF5UqGgYv76wwTcVpNOuNxzBXKG4Erz+scuV4z/OrhOr5 r0d4hnSt92KaKlcHmCbewifWsge4FwuzRC2YGEx47anGP/z2NsbWs9G84RwNZAWFHsrN jBPw== X-Gm-Message-State: AKwxyteiLtnuXnqOTq796tHAbHoYoyDFpXM52uTOZg3UNlflF5JxHj14 yv2DmRKlyFxTdplXLKhV/1M= X-Received: by 2002:a17:902:6b0b:: with SMTP id o11-v6mr3006226plk.109.1516611397203; Mon, 22 Jan 2018 00:56:37 -0800 (PST) Received: from localhost ([175.223.10.178]) by smtp.gmail.com with ESMTPSA id 14sm31077813pfn.125.2018.01.22.00.56.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jan 2018 00:56:35 -0800 (PST) Date: Mon, 22 Jan 2018 17:56:32 +0900 From: Sergey Senozhatsky To: Steven Rostedt Cc: Sergey Senozhatsky , Sergey Senozhatsky , Tejun Heo , Petr Mladek , 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: <20180122085632.GA403@jagdpanzerIV> References: <20180116194456.GS3460072@devbig577.frc2.facebook.com> <20180117091208.ezvuhumnsarz5thh@pathway.suse.cz> <20180117151509.GT3460072@devbig577.frc2.facebook.com> <20180117121251.7283a56e@gandalf.local.home> <20180117134201.0a9cbbbf@gandalf.local.home> <20180119132052.02b89626@gandalf.local.home> <20180120071402.GB8371@jagdpanzerIV> <20180120104931.1942483e@gandalf.local.home> <20180121141521.GA429@tigerII.localdomain> <20180121160441.7ea4b6d9@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180121160441.7ea4b6d9@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 On (01/21/18 16:04), Steven Rostedt wrote: [..] > > The problem is that we flush printk_safe right when console_unlock() printing > > loop enables local IRQs via printk_safe_exit_irqrestore() [given that IRQs > > were enabled in the first place when the CPU went to console_unlock()]. > > This forces that CPU to loop in console_unlock() as long as we have > > printk-s coming from call_console_drivers(). But we probably can postpone > > printk_safe flush. Basically, we can declare a new rule - we don't flush > > printk_safe buffer as long as console_sem is locked. Because this is how > > that printing CPU stuck in the console_unlock() printing loop. printk_safe > > buffer is very important when it comes to storing a non-repetitive stuff, like > > a lockdep splat, which is a single shot event. But the more repetitive the > > message is, like millions of similar kmalloc() dump_stack()-s over and over > > again, the less value in it. We should have printk_safe buffer big enough for > > important info, like a lockdep splat, but millions of similar kmalloc() > > messages are pretty invaluable - one is already enough, we can drop the rest. > > And we should not flush new messages while there is a CPU looping in > > console_unlock(), because it already has messages to print, which were > > log_store()-ed the normal way. > > The above is really hard to read without any capitalization. Everything > seems to be a run-on sentence and gives me a head ache. So you lost me > there. Apologies. Will improve. > > This is where the "postpone thing" jumps in. so how do we postpone printk_safe > > flush. > > > > We can't console_trylock()/console_unlock() in printk_safe flush code. > > But there is a `console_locked' flag and is_console_locked() function which > > tell us if the console_sem is locked. As long as we are in console_unlock() > > printing loop that flag is set, even if we enabled local IRQs and printk_safe > > flush work arrived. So now printk_safe flush does extra check and does > > not flush printk_safe buffer content as long as someone is currently > > printing or soon will start printing. But we need to take extra step and > > to re-queue flush on CPUs that did postpone it [console_unlock() can > > reschedule]. So now we flush only when printing CPU printed all pending > > logbuf messages, hit the "console_seq == log_next_seq" and up() > > console_sem. This sets a boundary -- no matter how many times during the > > current printing loop we called console drivers and how many times those > > drivers caused printk recursion, we will flush only SAFE_LOG_BUF_LEN chars. > > Another big paragraph with no capitals (besides macros and CPU ;-) I walked through it and mostly "fixed" your head ache :) > I guess this is what it is like when people listen to me talk too fast. Absolutely!!! > > IOW, what we have now, looks like this: > > > > a) printk_safe is for important stuff, we don't guarantee that a flood > > of messages will be preserved. > > > > b) we extend the previously existing "will flush messages later on from > > a safer context" and now we also consider console_unlock() printing loop > > as unsafe context. so the unsafe context it's not only the one that can > > deadlock, but also the one that can lockup CPU in a printing loop because > > of recursive printk messages. > > Sure. > > > > > > > so this > > > > printk > > console_unlock > > { > > for (;;) { > > call_console_drivers > > net_console > > printk > > printk_save -> irq_work queue > > > > IRQ work > > prink_safe_flush > > printk_deferred -> log_store() > > iret > > } > > up(); > > } > > > > > > // which can never break out, because we can always append new messages > > // from prink_safe_flush. > > > > becomes this > > > > printk > > console_unlock > > { > > for (;;) { > > call_console_drivers > > net_console > > printk > > printk_save -> irq_work queue > > > > } > > up(); > > > > IRQ work > > prink_safe_flush > > printk_deferred -> log_store() > > iret > > } > > But we do eventually send this data out to the consoles, and if the > consoles cause more printks, wouldn't this still never end? Right. But not immediately. We wait for all pending messages to be evicted first (and up()) and we limit the amount of data that we flush. So at least it's not exponential anymore: every line that we print does not log_store() a whole new dump_stack() of lines. Which is still miles away from "a perfect solution", tho. But limiting the number of lines we print recursive is not much better. First, we don't know how many lines we want to flush from printk_safe. And having a knob indicates that no one ever will do it right. Second, hand off can play games with it. Assume the following, - I set `recursion_max' to 200. Which looks reasonable to me. Then I have the following ping-pong: CPU0 CPU1 printk() recursion_check_start() call_console_drivers() printk() recursion_check_start() dump_stack() console_trylock_spinning() flush_printk_safe() spinning_disable_and_check() //handoff recursion_check_finish() // reset call_console_drivers() dump_stack() flush_printk_safe() printk() recursion_check_start() console_trylock_spinning() spinning_disable_and_check() // handoff recursion_check_finish() // reset call_console_drivers() printk dump_stack() recursion_check_start() flush_printk_safe() console_trylock_spinning() spinning_disable_and_check() recursion_check_finish() // reset call_console_drivers() ... And so on. So it's - take the lock, call console drivers, fill up the printk_safe buffer, flush it completely, hand off printing to another CPU, reset this CPU's recursion counter, repeat everything again. Every line of dump_stack() which we print adds another dump_stack() lines. Sergey "no-time-for-capitals" Senozhatsky