Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3397940ybd; Tue, 25 Jun 2019 01:45:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwV2VJYZga8oOLkJUxISfhYngWPvPBOJBrlBc46UcxtShJbFno2nYqArvlP5oTeC6xJEl1r X-Received: by 2002:a63:570c:: with SMTP id l12mr10653717pgb.25.1561452348977; Tue, 25 Jun 2019 01:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561452348; cv=none; d=google.com; s=arc-20160816; b=Z58+JRIjw/+kNeewbPZuiyO8BTi0dg5mqmdiqDhkZsc2WfYufO9R6a/AFztw4F2ViB NL5t9/qpLYJy0z3gWOq/N0DTOipHbc6BAwsnFmsh8Y7QCAncR+JPrFbtm/DwgkOo1Dye 5VbdSebI6TAKwtcHiEpGIwYnOznTQ+dTT0bC77rv3/wP3NG9+RvlNiZI2CBKdLcesDO4 ws4KuGDAnBoKYTJzOPCHbGxI2Q8SBX25OrXcDyLBM8yHZwP6NnPc64wrPChIGFA6WaCZ 8EI+DY4oyYMOyd9FgUOmpD2Aa+k0+5eQSQuCEPGN8pamOtZS3arw+OQ3UKJVONWKBATI FU2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=1DlhqXHwaMq373XYWU20HkM82M3EH4yI8mqfQnTbU0s=; b=PRdCyi3ZOhFu4CzceoaPFx2KiUpWZj/SLFdhzKXa/cEvKrOlFdf9np+Zy18fLwEdh8 o+0dZcTFhZtwdg71P4N+14SlBiOvFIy+zJgO7ZhQw+3SF7YKeQ1rB4QuJGL5ORJDq7y/ MrRLWycsdQhLONZP7EJm41+7yvD9Z3KM5KG/IjlRzRkaWmT3mzU0xn4noYy1dkj+Icty LTdzK4KtBsGi2uJJxklZyEqBLGpARDSPOtblwRSXBNoTTCEAQKn7djk94QMNHKqlW+XO tE/iHxYslX+hb6ltkjy5XYecpyVlYokwenAmlnjqqe7XFB2GeRIbNb97ujvdLP8l1z6a TxlQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c139si42690pfb.140.2019.06.25.01.45.33; Tue, 25 Jun 2019 01:45:48 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730796AbfFYIo6 (ORCPT + 99 others); Tue, 25 Jun 2019 04:44:58 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:41309 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726587AbfFYIo6 (ORCPT ); Tue, 25 Jun 2019 04:44:58 -0400 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1hfh3t-0000XF-62; Tue, 25 Jun 2019 10:44:21 +0200 From: John Ogness To: Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Petr Mladek , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation References: <20190607162349.18199-1-john.ogness@linutronix.de> <20190607162349.18199-2-john.ogness@linutronix.de> <20190618045117.GA7419@jagdpanzerIV> <87imt2bl0k.fsf@linutronix.de> <20190625064543.GA19050@jagdpanzerIV> <20190625071500.GB19050@jagdpanzerIV> Date: Tue, 25 Jun 2019 10:44:19 +0200 In-Reply-To: <20190625071500.GB19050@jagdpanzerIV> (Sergey Senozhatsky's message of "Tue, 25 Jun 2019 16:15:00 +0900") Message-ID: <875zoujbq4.fsf@linutronix.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-06-25, Sergey Senozhatsky wrote: >>>> + struct prb_reserved_entry e; >>>> + char *s; >>>> + >>>> + s = prb_reserve(&e, &rb, 32); >>>> + if (s) { >>>> + sprintf(s, "Hello, world!"); >>>> + prb_commit(&e); >>>> + } >>> >>> A nit: snprintf(). >>> >>> sprintf() is tricky, it may write "slightly more than was >>> anticipated" bytes - all those string_nocheck(" disabled"), >>> error_string("pK-error"), etc. >> >> Agreed. Documentation should show good examples. > > In vprintk_emit(), are we going to always reserve 1024-byte > records, since we don't know the size in advance, e.g. > > printk("%pS %s\n", regs->ip, current->name) > prb_reserve(&e, &rb, ????); > > or are we going to run vscnprintf() on a NULL buffer first, > then reserve the exactly required number of bytes and afterwards > vscnprintf(s) -> prb_commit(&e)? (As suggested by Petr) I want to use vscnprintf() on a NULL buffer. However, a NULL buffer is not sufficient because things like the loglevel are sometimes added via %s (for example, in /dev/kmsg). So rather than a NULL buffer, I would use a small buffer on the stack (large enough to store loglevel/cont information). This way we can use vscnprintf() to get the exact size _and_ printk_get_level() will see enough of the formatted string to parse what it needs. > I'm asking this because, well, if the most common usage > pattern (printk->prb_reserve) will always reserve fixed > size records (aka data blocks), then you _probably_ (??) > can drop the 'variable size records' requirement from prb > design and start looking at records (aka data blocks) as > fixed sized chunks of bytes, which are always located at > fixed offsets. The average printk message size is well under 128 bytes. It would be quite wasteful to always reserve 1K blocks. John Ogness