Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2070510pxb; Thu, 11 Feb 2021 03:41:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEVFG24r6os/pO9qGqwk7afR2dW0uKL5YvXpuNUKrREUAtDdpDIVimvKJfXfVgvY22MGtN X-Received: by 2002:aa7:d818:: with SMTP id v24mr8186236edq.259.1613043683073; Thu, 11 Feb 2021 03:41:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613043683; cv=none; d=google.com; s=arc-20160816; b=hOYkf0mg0grPnyRXwV4uTrxPVAjgQxosQC/0L3nsiY2rPTHxRs/zwntTaOdj5HdGwu W3/1WAh4tgqpKOq7n03JmIekH5aTQVLYrwgUTAAzHBJom5dv+KSysRMiRa5VtVZfQG8O +hvcicN3HyV1lIltU1q8uN4cjIHG9ygwfpURCfQgLbclKzm/6aXa/t03eOAbJtHZfxzB +J81bxfpLJWgaH/SuumKhjRF+U/CTBISGDkr8OwGdwFp2gswoR9S6a3a3rxTEDr3F0Ey 2o0o+PX6yoPW8qhYbQKcRAxtf1APcvi3T7uveNt5+Sr3/kxWfP3yg8yX5H83gXnNt7eB eQUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pMJzRr/L4i/Dq4M8UHSKGZOZ6wJPLPyiWgD0VYdU+Bk=; b=qABXULEVhRAckouM755+ti4P9NcZMdtFIJRTAMO5nhV3w10uDmwnuK6LFHfaHJYEBW l6bM8Tp690+CvgPKMCo/pJO0J1s7EUZ8FScybEIdyD/MCzELebAONeXsDfTilvaZ3m5i /X/7TK+muKtJE6xRIC6EX0sqbAoIcxfikLwvWX0n6GASK/hl3MMBcJjIPhHVM0w1Za1C QrCwJXlSEGqfqC1F/aX1rj+dQ/Yqx3h47RcKnbZUG6T8hrHf6bijNMVfrvwjLXi19ULC CR0p3crDSl8STNRF85GFCVrA9O5BPGCzu5qvSDR5SZgDZCtx/731mvn7v8en9ehOM66T 4c5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=YqY7bmv9; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k8si3605370edn.92.2021.02.11.03.40.59; Thu, 11 Feb 2021 03:41:23 -0800 (PST) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b=YqY7bmv9; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbhBKLhU (ORCPT + 99 others); Thu, 11 Feb 2021 06:37:20 -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