Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1541381pxb; Wed, 10 Feb 2021 10:39:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyH3Okc4dSGDV2y3SQ68WMnwkEFAIuO0Od/wP83FBBz/IK6h8WgB5R2Nnqmsngh2+JGLZ6q X-Received: by 2002:a17:906:b4a:: with SMTP id v10mr4184845ejg.382.1612982359706; Wed, 10 Feb 2021 10:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612982359; cv=none; d=google.com; s=arc-20160816; b=RDsfUma76BcZu0xt5Fq0G4l1EvRJFzoDv/M8egfqP7gy8dIesPQ7gNlIMwQ/xok/+h 3KKY0JckgHPXFnfuyPlxMTwIdJqFvDgmDei9Mz+jpmdMJ2i0IcBipp73bEBpLsosRq9Z wwuE0zhjyfHxZGVYoj1CLyS5OqbXNWhWINg6euz1nS2/SNO1NSexg0xQbOyRZr8kEjGg lceT2shMYhIXOAs1NN5LQ0VYndK85KKaefBaDvHRlHCUklwkoBrXGTQ9poy5gtOB7ozG 9yNfPxEiFDcMlng2DEXzcc0R8ot4NLxM/+JOZu2Rc6heOfUFUQSu4o6ACf4ZoVA5sb07 OsoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=HBuCn3mUPAVSytsaOkj6uZwzU9Wq36KTP7dWW+6MY18=; b=yxjAeXx9tuAUZzmKIbO3tMxEH9LceUJLeRtRQbpYzh57VnQN8ZASQvstGLeoiKGhVL 0UPhThNdPknbVstV/12MG2KPOBSn2clHxZ4+cfA6scauVXApncIaNEjjLCYjZ8Kf8RKW O72z0NuBgf4DAPT9wcXFAIa0CoDB4+lla+/xFlfYarj4SVPtuKTL8H3dXq0+Zus8viFe pBJ2mWVjykhGxRf9NJXpYunpSV61N1CaGAkC/y4r39A4aP2BEsu17N3JfahRyV+rnJRp jAYOBgRIx+iefvY+O22UjOGde2cfWNNjsQHFFCbjYa/QKtzIib0Fw1J1qiGYGfWM0utK M/8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xJ8HvxrR; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx11si2016504ejc.634.2021.02.10.10.38.55; Wed, 10 Feb 2021 10:39:19 -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=@linutronix.de header.s=2020 header.b=xJ8HvxrR; dkim=neutral (no key) header.i=@linutronix.de; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234292AbhBJSho (ORCPT + 99 others); Wed, 10 Feb 2021 13:37:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234108AbhBJS0x (ORCPT ); Wed, 10 Feb 2021 13:26:53 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9386AC06174A for ; Wed, 10 Feb 2021 10:26:12 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1612981571; h=from:from:reply-to:subject:subject: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=HBuCn3mUPAVSytsaOkj6uZwzU9Wq36KTP7dWW+6MY18=; b=xJ8HvxrRoGGICXuuRHzYBBmWSgerRiTthB7PcUIi/jrKMh37ht+9JZxKeji1KiKH97JP79 Xozmvn8+w8zsYhyHoeFMTJBgXWZbOv1dxA55xYsjDi//5xHzBNIjc+lB/o1+wjsx2Dk75q TIXbN3PiYbccHILLWtXAvMR/ehChTag2NEU/RSRF+jUeDAmEwt+B5SiZnhzzubly1EZGQ+ 9JbBmv+p0NC+ocjUaxalUcSEuuN+F+tTh3TiW5bY4r2FVucpiKJVBT98jc5SZm+81fqvkM BbY0NR7gdF0dI6cZBt36f4h2lUdJwdUthvXRpuyT7ux5WNWs+CfPcRA3N8lFHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1612981571; h=from:from:reply-to:subject:subject: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=HBuCn3mUPAVSytsaOkj6uZwzU9Wq36KTP7dWW+6MY18=; b=ubDoMGXMYLFlyn4V3h1tLjPO+hpq/HL25V+yo+6rEvikU8m+T+uQ1+3t7aaYgTH/XyrI5B yi8sDTevmezIjOBQ== To: Petr Mladek 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 In-Reply-To: References: <20210205141728.18117-1-john.ogness@linutronix.de> Date: Wed, 10 Feb 2021 19:32:10 +0106 Message-ID: <874kij4w59.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > It might fail when syslog_seq points to the next message > after the last valid one. In this case, we could return > immediately (after releasing the lock) because there are > zero unread messages. Yes, we could just return 0 in this case. If we are returning and not modifying @syslog_seq, then there is no need to reset @syslog_partial. At some point a reader will notice that the record is gone and reset @syslog_partial accordingly. > Anyway, syslog_partial must be zero in this case. syslog_seq > should stay when the last read was partial. And there should > always be at least one valid message in the log buffer > be design. A record can be invalidated at any time. It is a normal case that a re-read of a record (to get the rest of the partial) can lead to the record no longer being available. > IMHO, it would deserve a comment and maybe even a warning. I don't think we need a warning. It is something that can happen and it is not a problem. > What about something like? > > /* Number of chars in the log buffer */ > case SYSLOG_ACTION_SIZE_UNREAD: > logbuf_lock_irq(); > if (!prb_read_valid_info(prb, syslog_seq, &info, NULL)) { > /* No unread message */ > if (syslog_partial) { > /* This should never happen. */ > pr_err_once("Unable to read any message even when the last syslog read was partial: %zu", syslog_partial); > syslog_partial = 0; > } > logbuf_unlock_irq(); > return 0; > } 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. > */ > 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