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=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 2C3E9C433DB for ; Thu, 11 Feb 2021 11:37:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F11BD64DB1 for ; Thu, 11 Feb 2021 11:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbhBKLha (ORCPT ); Thu, 11 Feb 2021 06:37:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:41968 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231461AbhBKLGj (ORCPT ); Thu, 11 Feb 2021 06:06:39 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613041552; h=from:from:reply-to: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=pMJzRr/L4i/Dq4M8UHSKGZOZ6wJPLPyiWgD0VYdU+Bk=; b=YqY7bmv95n/xGzpd+Q/ZohZU1eDHEHg1lAbKJHPKWusDvnnVZx0TwMvx8zXwdleIGN4raH zciHp1cgtkvgn4WTAsLQm+JfhqrsehAyv/EqbYoqWeWqDqWwuX1RvQC2WjJsv0TdOqQNZC 3B2cQkV4gGfFHWQ0lFU8s9wKi4jz2VE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 43CD7AD2B; Thu, 11 Feb 2021 11:05:52 +0000 (UTC) Date: Thu, 11 Feb 2021 12:05:51 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, "J. Avila" Subject: Re: [PATCH] printk: avoid prb_first_valid_seq() where possible Message-ID: References: <20210205141728.18117-1-john.ogness@linutronix.de> <874kij4w59.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874kij4w59.fsf@jogness.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2021-02-10 19:32:10, John Ogness wrote: > On 2021-02-09, Petr Mladek wrote: > >> @@ -1629,9 +1631,13 @@ int do_syslog(int type, char __user *buf, int len, int source) > >> /* Number of chars in the log buffer */ > >> case SYSLOG_ACTION_SIZE_UNREAD: > >> logbuf_lock_irq(); > >> - if (syslog_seq < prb_first_valid_seq(prb)) { > >> - /* messages are gone, move to first one */ > >> - syslog_seq = prb_first_valid_seq(prb); > >> + if (prb_read_valid_info(prb, syslog_seq, &info, NULL)) { > >> + if (info.seq != syslog_seq) { > >> + /* messages are gone, move to first one */ > >> + syslog_seq = info.seq; > >> + syslog_partial = 0; > >> + } > >> + } else { > >> syslog_partial = 0; > > > > I am scratching my head when prb_read_valid_info(prb, > > syslog_seq, &info, NULL)) might fail. > > It can fail because the descriptor has been invalidated/recycled by > writers and perhaps there is no valid record that has yet come after it. I see. From some reasons I though that there should always be at least one message in the commited state. But it is enough when it is in reusable state. I should have double checked it. > I recommend changing your suggestion to: > > > if (!prb_read_valid_info(prb, syslog_seq, &info, NULL)) { > > /* > > * No unread messages. No need to check/reset > > * syslog_partial. When a reader does read a new > > * message it will notice and appropriately update > > * syslog_seq and reset syslog_partial. > > */ The following comment might be enough after all. /* No unread messages. */ My main concern was that we cleared syslog_partial and continued. I thought that we might miss a bug this way. But it seems to be perfectly fine. I just have to update my mental picture. Otherwise. the fact that syslog_partial will be fixed by the next successful call is more or less obvious if we change the code as you propose. Please, send an updated patch. Best Regards, Petr > > logbuf_unlock_irq(); > > return 0; > > } > > if (info.seq != syslog_seq) { > > /* messages are gone, move to first one */ > > syslog_seq = info.seq; > > syslog_partial = 0; > > } > > John Ogness