From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D273BC433DB for ; Fri, 26 Mar 2021 11:13:12 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 28CDE61A14 for ; Fri, 26 Mar 2021 11:13:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28CDE61A14 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4F6K8Q2tTrz3bxG for ; Fri, 26 Mar 2021 22:13:10 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=IM/b29la; dkim=fail reason="signature verification failed" header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=4oEUatYS; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linutronix.de (client-ip=193.142.43.55; helo=galois.linutronix.de; envelope-from=john.ogness@linutronix.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=IM/b29la; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=4oEUatYS; dkim-atps=neutral Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4F6K7v6tHfz3bcw for ; Fri, 26 Mar 2021 22:12:43 +1100 (AEDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1616757158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7RxLJNwSY/A5SoVhWSfv2pmplPu4MvBBsF6rRlDKAJ0=; b=IM/b29laeEiAoFSv+02zMVKnUvwBIVAYGQtqO0mk287ab7q370BFBxTgBvdwauorRqW8ka 3OJTWc6XhWgKfbDrAHBDen1simtfKPKuZ0bI0IzpM/JJ8IQZGEj0CkfkWYeM95aI6XN7kJ rpbuADUHsCTRy9HYjgv/l5qjydPZM3lVD4xoSAEqVO4cZ9Gs3Z3RQwwTgpAXom9fvnVW6N e8JW42vfPbqQtgX88zR5Q+fSxvePgbmIl8WXh0TodTDQQhjjTPElXgbUXKhbR1mq4NdYkS rZL0cj2H+Q0xPWIg0papxzdKddU2Zi25SnLz6tG9E3HhWvd0Crn9JV9qVbUC5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1616757158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7RxLJNwSY/A5SoVhWSfv2pmplPu4MvBBsF6rRlDKAJ0=; b=4oEUatYSA7YP5RGM/INPugkii8zZ4EjltzCG2fwMvg7n0iLo1Rqh0Z4Do/UMMnpfULteXb re5uVkGdenKtW2Bg== To: Petr Mladek Subject: Re: [PATCH next v1 2/3] printk: remove safe buffers In-Reply-To: References: <20210316233326.10778-1-john.ogness@linutronix.de> <20210316233326.10778-3-john.ogness@linutronix.de> Date: Fri, 26 Mar 2021 12:12:37 +0100 Message-ID: <87pmzmi2xm.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergey Senozhatsky , Peter Zijlstra , Paul Mackerras , Tiezhu Yang , Rafael Aquini , Alexey Kardashevskiy , Yue Hu , Jordan Niethe , Kees Cook , "Paul E. McKenney" , Alistair Popple , "Guilherme G. Piccoli" , Nicholas Piggin , Steven Rostedt , Thomas Gleixner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Eric Biederman , Andrew Morton , linuxppc-dev@lists.ozlabs.org, =?utf-8?Q?C=C3=A9dric?= Le Goater Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 2021-03-23, Petr Mladek wrote: >> --- a/kernel/printk/printk.c >> +++ b/kernel/printk/printk.c >> @@ -1142,8 +1126,6 @@ void __init setup_log_buf(int early) >> new_descs, ilog2(new_descs_count), >> new_infos); >> >> - printk_safe_enter_irqsave(flags); >> - >> log_buf_len = new_log_buf_len; >> log_buf = new_log_buf; >> new_log_buf_len = 0; >> @@ -1159,8 +1141,6 @@ void __init setup_log_buf(int early) >> */ >> prb = &printk_rb_dynamic; >> >> - printk_safe_exit_irqrestore(flags); > > This will allow to add new messages from the IRQ context when we > are copying them to the new buffer. They might get lost in > the small race window. > > Also the messages from NMI might get lost because they are not > longer stored in the per-CPU buffer. > > A possible solution might be to do something like this: > > prb_for_each_record(0, &printk_rb_static, seq, &r) > free -= add_to_rb(&printk_rb_dynamic, &r); > > prb = &printk_rb_dynamic; > > /* > * Copy the remaining messages that might have appeared > * from IRQ or NMI context after we ended copying and > * before we switched the buffers. They must be finalized > * because only one CPU is up at this stage. > */ > prb_for_each_record(seq, &printk_rb_static, seq, &r) > free -= add_to_rb(&printk_rb_dynamic, &r); OK. I'll probably rework it some and combine it with the "dropped" test so that we can identify if messages were dropped during the transition (because of static ringbuffer overrun). >> - >> if (seq != prb_next_seq(&printk_rb_static)) { >> pr_err("dropped %llu messages\n", >> prb_next_seq(&printk_rb_static) - seq); >> @@ -2666,7 +2631,6 @@ void console_unlock(void) >> size_t ext_len = 0; >> size_t len; >> >> - printk_safe_enter_irqsave(flags); >> skip: >> if (!prb_read_valid(prb, console_seq, &r)) >> break; >> @@ -2711,6 +2675,8 @@ void console_unlock(void) >> printk_time); >> console_seq++; >> >> + printk_safe_enter_irqsave(flags); > > What is the purpose of the printk_safe context here, please? console_lock_spinning_enable() needs to be called with interrupts disabled. I should have just used local_irq_save(). I could add local_irq_save() to console_lock_spinning_enable() and restore them at the end of console_lock_spinning_disable_and_check(), but then I would need to add a @flags argument to both functions. I think it is simpler to just do the disable/enable from the caller, console_unlock(). BTW, I could not find any sane way of disabling interrupts via a raw_spin_lock_irqsave() of @console_owner_lock because of the how it is used with lockdep. In particular for console_lock_spinning_disable_and_check(). John Ogness