From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933944AbcLABIq (ORCPT ); Wed, 30 Nov 2016 20:08:46 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33678 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932200AbcLABIo (ORCPT ); Wed, 30 Nov 2016 20:08:44 -0500 Date: Thu, 1 Dec 2016 10:08:48 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Sergey Senozhatsky , Andrew Morton , Jan Kara , Tejun Heo , Calvin Owens , Thomas Gleixner , Mel Gorman , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Laura Abbott , Andy Lutomirski , Linus Torvalds , Kees Cook , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC][PATCHv4 3/6] printk: introduce per-cpu safe_print seq buffer Message-ID: <20161201010848.GD12039@jagdpanzerIV> References: <20161027154933.1211-1-sergey.senozhatsky@gmail.com> <20161027154933.1211-4-sergey.senozhatsky@gmail.com> <20161124165821.GG24103@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161124165821.GG24103@pathway.suse.cz> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (11/24/16 17:58), Petr Mladek wrote: [..] > > +#ifdef CONFIG_PRINTK > > + > > +#define PRINTK_SAFE_CONTEXT_MASK 0x7fffffff > > +#define PRINTK_SAFE_NMI_CONTEXT_MASK 0x80000000 > > What about shorter name PRINTK_NMI_CONTEXT_MASK? ok. > > diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c > > index 1f66163..af74d9c 100644 > > --- a/kernel/printk/printk_safe.c > > +++ b/kernel/printk/printk_safe.c > > @@ -50,27 +49,26 @@ struct printk_safe_seq_buf { > > struct irq_work work; /* IRQ work that flushes the buffer */ > > unsigned char buffer[SAFE_LOG_BUF_LEN]; > > }; > > + > > +static DEFINE_PER_CPU(struct printk_safe_seq_buf, safe_print_seq); > > +static DEFINE_PER_CPU(int, printk_safe_context); > > I would personally use the short name "printk_context". It is a generic > value. Zero value means that it is a normal context. Also there is > an idea to add KDB context that would use its own vprintk_kdb() > implementation and will not use the printk_safe buffer. ok. > > - if (len >= sizeof(s->buffer)) { > > - atomic_inc(&nmi_message_lost); > > - return 0; > > - } > > + if (len >= sizeof(s->buffer)) > > + return -E2BIG; > > E2BIG means "argument list too long" and does not fit much here. > I would suggest to use -ENOSPC. It is not ideal either but it fits > slightly better. ok. > > +/* > > + * Lockless printk(), to avoid deadlocks should the printk() recurse > > + * into itself. It uses a per-CPU buffer to store the message, just like > > + * NMI. > > + */ > > +static int vprintk_safe(const char *fmt, va_list args) > > +{ > > + struct printk_safe_seq_buf *s = this_cpu_ptr(&safe_print_seq); > > + > > + return printk_safe_log_store(s, fmt, args); > > We should return zero if printk_safe_log_store() returns an error. > I know that it will get fixed in the next patch. But we should do > some minimum sanity check here because of bisection. ok. -ss