Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp409296ybl; Wed, 4 Dec 2019 04:55:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzUE1aEW4P1Jr+kJLcvdnXQDANS0b+hdM8IBUc1VyNbgc1q5OHHnRx9ooiPegMNqBUW3Yvz X-Received: by 2002:a05:6830:579:: with SMTP id f25mr2400332otc.248.1575464140577; Wed, 04 Dec 2019 04:55:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575464140; cv=none; d=google.com; s=arc-20160816; b=gi0WHm9Uw16qwNLHMrZCCQR1KbDIYcAbhtwPjRl8I8++WWiqAbtAnaXAS6q0usN9/k VUHSrM6MvUhboi9vZmwsHIPSUoEeAlGi1LFRPR/yX6X3+GuPHRS2pgfU1hOGbcxeLZsP d05POkvJDDijYAfACDWTu1otKK92Hwcf18tN9Dofs3zlkIdE1GvfM44jEjuUE4bh4glF OLbPYafJOCXcqX8LzY/E5iG5BbZkqY2lhUAQvgXZg9GxkHYByaINCWDepUq8CYyNXefb 9mH4kUvnv17a+Dtk10JnmJDGTovnP/Z3SO+pxE7gj0Bq/Zt93ScAJN5UyPM8YjxyhiEg XpJg== 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=w+wr/a8mrlvxG65uzLJ/OrTLp3K4A/xj0JBXNk7LIqg=; b=lvH5G16ID0lb7rhkJwgDzvIUKcPv73jO+5jhKwLOy/MfTKYJUmAe9sYyCpOkJOPsFZ kwmNZzOP6v1dGw1Xmph/FV16cT6BExLWYWVExHMI073Jqni1QaHTNItC2FOnxRwQ0FIX Wv4H24APVDEg7UI0LjxloYMq5ad/nHAmaZ3p+20lcgwiA3rGGkwTsIGQQL7w+PXichw3 kZ6okLl9TNwGZnQTsrreHXEwcYEkG/uDnwF6GLnOaPl6VYLmx6EMY8B2ldvnSesgnMv3 oKx5hIswmgEgZFlkGFif+kXg9QNpHU4kc+zV6iZEWXyYisUj9XGjSiiGGP72mzeARTz8 LbfQ== 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 a26si3115100oto.199.2019.12.04.04.55.27; Wed, 04 Dec 2019 04:55:40 -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; 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 S1727649AbfLDMyz (ORCPT + 99 others); Wed, 4 Dec 2019 07:54:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:36264 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726010AbfLDMyy (ORCPT ); Wed, 4 Dec 2019 07:54:54 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 29F11B202; Wed, 4 Dec 2019 12:54:52 +0000 (UTC) Date: Wed, 4 Dec 2019 13:54:50 +0100 From: Petr Mladek To: John Ogness Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky , Brendan Higgins , kexec@lists.infradead.org Subject: Re: [RFC PATCH v5 2/3] printk-rb: new printk ringbuffer implementation (reader) Message-ID: <20191204125450.ob5b7xi3gevor4qz@pathway.suse.cz> References: <20191128015235.12940-1-john.ogness@linutronix.de> <20191128015235.12940-3-john.ogness@linutronix.de> <20191203120622.zux33do54rmjafns@pathway.suse.cz> <87pnh5bjz4.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pnh5bjz4.fsf@linutronix.de> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2019-12-03 14:46:07, John Ogness wrote: > On 2019-12-03, Petr Mladek wrote: > >> Add the reader implementation for the new ringbuffer. > >> > >> Signed-off-by: John Ogness > >> --- > >> kernel/printk/printk_ringbuffer.c | 234 ++++++++++++++++++++++++++++++ > >> kernel/printk/printk_ringbuffer.h | 12 +- > >> 2 files changed, 245 insertions(+), 1 deletion(-) > >> > >> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c > >> index 09c32e52fd40..f85762713583 100644 > >> --- a/kernel/printk/printk_ringbuffer.c > >> +++ b/kernel/printk/printk_ringbuffer.c > >> @@ -674,3 +674,237 @@ void prb_commit(struct prb_reserved_entry *e) > >> local_irq_restore(e->irqflags); > >> } > >> EXPORT_SYMBOL(prb_commit); > >> + > >> +/* > >> + * Given @blk_lpos, return a pointer to the raw data from the data block > >> + * and calculate the size of the data part. A NULL pointer is returned > >> + * if @blk_lpos specifies values that could never be legal. > >> + * > >> + * This function (used by readers) performs strict validation on the lpos > >> + * values to possibly detect bugs in the writer code. A WARN_ON_ONCE() is > >> + * triggered if an internal error is detected. > >> + */ > >> +static char *get_data(struct prb_data_ring *data_ring, > >> + struct prb_data_blk_lpos *blk_lpos, > >> + unsigned long *data_size) > >> +{ > >> + struct prb_data_block *db; > >> + > >> + if (blk_lpos->begin == INVALID_LPOS && > >> + blk_lpos->next == INVALID_LPOS) { > >> + /* descriptor without a data block */ > >> + return NULL; > >> + } else if (DATA_WRAPS(data_ring, blk_lpos->begin) == > >> + DATA_WRAPS(data_ring, blk_lpos->next)) { > >> + /* regular data block */ > >> + if (WARN_ON_ONCE(blk_lpos->next <= blk_lpos->begin)) > >> + return NULL; > >> + db = to_block(data_ring, blk_lpos->begin); > >> + *data_size = blk_lpos->next - blk_lpos->begin; > >> + > >> + } else if ((DATA_WRAPS(data_ring, blk_lpos->begin) + 1 == > >> + DATA_WRAPS(data_ring, blk_lpos->next)) || > >> + ((DATA_WRAPS(data_ring, blk_lpos->begin) == > >> + DATA_WRAPS(data_ring, -1UL)) && > >> + (DATA_WRAPS(data_ring, blk_lpos->next) == 0))) { > > > > I am a bit confused. I would expect that (-1UL + 1) = 0. So the second > > condition after || looks just like a special variant of the first > > valid condition. > > > > Or do I miss anything? Is there a problems with type casting? > > Sorry, this code deserves a comment. > > Here we are only comparing the number of wraps. For a wrapping data > block, @begin will be 1 wrap less than @next. The first part of the > check is checking the typical case, making sure that: > > 1 + WRAPS(@begin) == WRAPS(@next) > > There is also the case when the lpos overflows. In that case the number > of wraps starts over at zero (without having overflowed). (Note: The > lpos overflows, _not_ the number of wraps. This is why the first check > is not enough.) In this case, the number of wraps of the highest > possible lpos value (-1UL) should be the same as the number of wraps of > @begin. And the number of wraps of @next should be 0. The simplified > pseudo-code check is: > > WRAPS(@begin) == WRAPS(-1UL) > && > WRAPS(@next) == 0 Got it. I knew that it must have been something like this but I did not see it. I wonder if the following might be easier to understand even for people like me ;-) } else if (DATA_WRAPS(data_ring, blk_lpos->begin + DATA_SIZE(data_ring)) == DATA_WRAPS(data_ring, blk_lpos->next)) { Best Regards, Petr