Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1125980pxa; Thu, 20 Aug 2020 03:17:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlpJfxcsetkUi7bVkLX0khKTiBoTSr2IKmdEWy0zeXyMQTR1gUhxJtLlI1PfqfGjj+cxsR X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr2085465edb.98.1597918662790; Thu, 20 Aug 2020 03:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597918662; cv=none; d=google.com; s=arc-20160816; b=f+HpFEOn7VHjbU5eI8qfG/weMTazfp6pYP3NQA6RjtJ9ndUcVCbmEdICD24gZwqizv ihuSSjPId1+upAzPpCvVOCv4ILes1+mg4N1EVKRTEC0fboNVkNzf4l11L60x0Cb/nrHg 5lPkU6gY5vb8vLeGG1ptp+NIJR/DaKIop0VSLisLWVb0kAMSEaXlNjyzwmt3IaJut0DY t6gp/BGBd+VzXRcKjqyk6fKQ7El9bGYWJB0wQGQLbiAOcvT/yip9DIoo8tIZQyS0uZiK 6F1+in/ChuVZjFhF7kF0iPRPA8h/+YY2PmGf0dEEDKHqkpVm2jg3gweGujzAP8rU1LHY a3Xw== 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; bh=FuE026ij9n119ovxhQYCu4EnlIoUzx1jBJoZ6Nzo078=; b=WlgWIrQJB8/Eq/72OaRUzXruG3nO6gNFYO4LAkZcWzCgxGHrTwKA+xlyIAfLozJPFQ RAXq+pWXOz5Vc1V4P4GH+BuNJ76D+V2XNHRyNUpZqp0u/15wXajfDzibIrgN32WpzyoW Y0GZdjufzIbHs0jxks+ZY++gv61fqFiJY/W0Bb4/AzMqNgrKJ5nZGzXWVkM/hBQbsVtz dt0G0zq1Wyw8dGcRy4EFIaHkPQiZF4IP4dxVzRca6n9gMkR+l1rcEAI0UYyEesfhaCBd crDhjjrcULNcsSZR5Bv02ccVKppUuXxl/gRGaokDgNFkE3vaKdwNuL1r9HXGEddLdCCP W3lQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 39si1105877edq.552.2020.08.20.03.17.19; Thu, 20 Aug 2020 03:17:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731291AbgHTKQo (ORCPT + 99 others); Thu, 20 Aug 2020 06:16:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:36728 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgHTKQ2 (ORCPT ); Thu, 20 Aug 2020 06:16:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0BCDCAD19; Thu, 20 Aug 2020 10:16:53 +0000 (UTC) Date: Thu, 20 Aug 2020 12:16:25 +0200 From: Petr Mladek To: John Ogness Cc: Linus Torvalds , Sergey Senozhatsky , Steven Rostedt , Greg Kroah-Hartman , Thomas Gleixner , Sergey Senozhatsky , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/5] printk: implement pr_cont_t Message-ID: <20200820101625.GE4353@alley> References: <20200819232632.13418-1-john.ogness@linutronix.de> <20200819232632.13418-2-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200819232632.13418-2-john.ogness@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2020-08-20 01:32:28, John Ogness wrote: > Implement a new buffering mechanism for pr_cont messages. > > Old mechanism syntax: > > printk(KERN_INFO "text"); > printk(KERN_CONT " continued"); > printk(KERN_CONT "\n"); > > New mechanism syntax: > > pr_cont_t c; > > pr_cont_begin(&c, KERN_INFO "text"); > pr_cont_append(&c, " continued"); > pr_cont_end(&c); > > Signed-off-by: John Ogness > --- > include/linux/printk.h | 19 ++++++ > kernel/printk/printk.c | 137 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 156 insertions(+) > > diff --git a/include/linux/printk.h b/include/linux/printk.h > index 34c1a7be3e01..4d9ce18e4afa 100644 > --- a/include/linux/printk.h > +++ b/include/linux/printk.h > @@ -380,6 +380,25 @@ extern int kptr_restrict; > #define pr_cont(fmt, ...) \ > printk(KERN_CONT fmt, ##__VA_ARGS__) > > +/* opaque handle for continuous printk messages */ > +typedef struct { > + u8 index; > + u8 loglevel; > + u16 text_len; > +} pr_cont_t; > + > +/* initialize handle, provide loglevel and initial message text */ > +int pr_cont_begin(pr_cont_t *c, const char *fmt, ...); > + > +/* append message text */ > +int pr_cont_append(pr_cont_t *c, const char *fmt, ...); > + > +/* flush message to kernel buffer */ > +void pr_cont_flush(pr_cont_t *c); > + > +/* flush message to kernel buffer, cleanup handle */ > +void pr_cont_end(pr_cont_t *c); > + > /** > * pr_devel - Print a debug-level message conditionally > * @fmt: format string > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index ad8d1dfe5fbe..10113e7ea350 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -3495,3 +3495,140 @@ void kmsg_dump_rewind(struct kmsg_dumper *dumper) > EXPORT_SYMBOL_GPL(kmsg_dump_rewind); > > #endif > + > +#define CONT_LINE_MAX LOG_LINE_MAX > +#define CONT_BUF_COUNT 10 > +static char cont_buf[CONT_BUF_COUNT][CONT_LINE_MAX]; > +static DECLARE_BITMAP(cont_buf_map, CONT_BUF_COUNT); > + > +static int get_cont_buf(void) > +{ > + int bit; > + > + do { > + bit = find_first_zero_bit(cont_buf_map, CONT_BUF_COUNT); > + if (bit == CONT_BUF_COUNT) > + break; > + } while (test_and_set_bit(bit, cont_buf_map)); > + > + return bit; > +} My big problem with this solution is a forgotten pr_cont_end(). It will cause: + the message will never get printed + several calls into such a broken code will exhaust the pool of cont buffers and it will stop working for the entire system The above might be solved with some fallback mechanism (timer, watchdog) but then it needs some synchronization. Why is it so bad? + it will happen like other bugs + it is hard to notice; it is easier to notice hard-lockup than a missing message Now that I think about it. This is the biggest problem with any temporary buffer for pr_cont() lines. I am more and more convinced that we should just _keep the current behavior_. It is not ideal. But sometimes mixed messages are always better than lost ones. That said, some printk() API using local buffer would be still valuable for pieces of code where people really want to avoid mixed lines. But it should be optional and people should be aware of the risks. Best Regards, Petr