Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3808072rdg; Wed, 18 Oct 2023 06:46:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETdZZ2OwALPueMyHTfv8G+7qAZpvzuxtvo1HXD8y/38MjLOA68bEMR64OsJ7pSpL5FeIah X-Received: by 2002:a05:6a21:185:b0:17b:40:ccc6 with SMTP id le5-20020a056a21018500b0017b0040ccc6mr6416976pzb.4.1697636783436; Wed, 18 Oct 2023 06:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697636783; cv=none; d=google.com; s=arc-20160816; b=i3K3z0+VVbccZlwryaSPTAp2kjuhgQrS3BFNisW6Xd1+NXUGWCEyWFeYf+1DXyRS+H 4yiSxlEweYwE/PhOAU8ggtmejPyCS35pPslT7PJ/UqaJQ3F2EJE1Po9uV0/G83FsIJpe CeJSphvhKkWJl9pOqObMhvfsLvhrW3U//lWOtSZhyeJRBBJekAVQ4ffOIPl9uzQ6ht9X z/AI7NiZlLY8qnK6lxZrkzpLeA8LensogVNN6q7mmORhE9MjkYEONbgQ/PDT7Eu0MsFX 9IhIJUkqIg6IYHLjMlY9dADWeWRURxkSYOublKjGstt5rYj5qaL5+WXux1E1vXgmXw9/ 30Cg== 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=aHr2BzWnALAi96WZOeBFoa+QlTGYS/bQ5Th8GJp4Cvw=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=shTHCtrMvfo5HxLANYtOFl/trRzxLLUe1rf7irblf5kSL+IQb8MX2hEBJAvWo51SQC 0pEoyYWqwYqR3/J2aQ3b2YorOJdKMDvOwaYcvC4GJue8KEuUXtcm0ID4iaLfyETLGHPr t6HMIH+QvUk8zgiuLue5D511R9fbA8uHY++4XG9bP5fPHhNvlDKNAkJp/ZhITjy9zuK0 1puxvlsrBR/GSE/AzA6uIeESFqA4g9bR78R7cUmONVGpqtYoLCAMYOHyfq9WOgnuxvjH Krtx20Iakx4yYpwW4lwILdod8slri6nWbwg+4i7s6uLXOwymdtsrf/sErRrmk+cUOKXG ZYyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IkIC4l9t; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id s26-20020a63925a000000b005b7ce261d0dsi367007pgn.402.2023.10.18.06.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 06:46:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IkIC4l9t; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id AC76680295FD; Wed, 18 Oct 2023 06:46:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbjJRNqM (ORCPT + 99 others); Wed, 18 Oct 2023 09:46:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbjJRNqK (ORCPT ); Wed, 18 Oct 2023 09:46:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D59B6BA for ; Wed, 18 Oct 2023 06:46:08 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697636767; 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=aHr2BzWnALAi96WZOeBFoa+QlTGYS/bQ5Th8GJp4Cvw=; b=IkIC4l9tDueXa/vIQ6w1HOjpVc7cavmCmA09ULqPoZ67IB+G8M7Z+mOKODAw+RilPpA6Fx FU+6xM6xhwzRx8ZxsH7kBBQe7Y2qpQfxy7fP1Ufzbp+ZSOP9rMrNlICaqeU//zG31FYxus xZ9AseBkqQ5gJGfI1cH9tKfxFoG3qm4rJQfEBfn+nYEDvdjT2qVI/ohQkIqpg0QwEIfWFe NmpowxB7Zs4G6mQ6i3H4yac5P31WKfCIcrseBzTkOR6QyMuF1Xr+pK6a1x9xReGsnmc/7V 5+e3HOPfOSBe3oHNSMs2Q8zR7HCZMb+iW6dkj+7qcrV161BZooE4jwtaN688Mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697636767; 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=aHr2BzWnALAi96WZOeBFoa+QlTGYS/bQ5Th8GJp4Cvw=; b=jM4nkKOYrwc7jyJLweY/UbG98J/e7hHLogrsdQpsH3AHytELs7DPAb34+y7y1ep7EQm4La Fca0pALyeAEUucDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v2 3/4] printk: Skip unfinalized records in panic In-Reply-To: References: <20231013204340.1112036-1-john.ogness@linutronix.de> <20231013204340.1112036-4-john.ogness@linutronix.de> <87mswh6iwq.fsf@jogness.linutronix.de> Date: Wed, 18 Oct 2023 15:51:57 +0206 Message-ID: <874jio6o2y.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 06:46:20 -0700 (PDT) On 2023-10-18, Petr Mladek wrote: > Wait! This means that your patch actually does not work. Here is the diff: > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -2815,8 +2815,19 @@ static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, > else > prb_rec_init_rd(&r, &info, outbuf, outbuf_sz); > > - if (!prb_read_valid(prb, seq, &r)) > - return false; > + while (!prb_read_valid(prb, seq, &r)) { > + if (this_cpu_in_panic() && seq < prb_next_seq(prb)) { > + /* > + * The record @seq is not finalized and there may be > + * more records in the ringbuffer. Since this is the > + * panic CPU, skip over the unfinalized record and > + * try to read a finalized record that may follow. > + */ > + seq++; > + } else { > + return false; > + } > + } > > pmsg->seq = r.info->seq; > pmsg->dropped = r.info->seq - seq; > > It skips the invalid reads only when seq < prb_next_seq(). But > prb_next_seq(prb) points to the 1st non-finalized record. And > all records with seq < prb_next_seq() must be finalized! Please take a look at prb_next_seq(). It _starts_ its search from: id = atomic_long_read(&desc_ring->last_finalized_id); For console_flush_on_panic(), @last_finalized_id will _always_ be set to the last finalized message of the panic messages, being higher than any non-finalized records that may exist. There are no other CPUs running except the panic CPU. > And it is even wrong. I still believe that dataless records are > quietly skipped. Here is the code: > > static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq, > struct printk_record *r, unsigned int *line_count) > { > while ((err = prb_read(rb, *seq, r, line_count))) { > [...] > } else if (err == -ENOENT) { > /* Record exists, but no data available. Skip. */ > (*seq)++; > > } else { > } > [...] > } Yes, this is the code. But prb_read() returns _true_ for data-less records. You are confusing data-less records (which are valid records containing the empty string) with "no data available" (which are records that have lost their data). Your confusion shows that we should improve the language. I am working on a patch that does this. > Note that "seq" is incremented and the cycle continues. It means > that it tries to read the next record. It does _not_ return > "true" when seeing dataless record, definitely. I showed you where to look: get_data() has an extra check for data-less records. It returns a valid string "", not NULL. >> that it is just a brief internal comment. It also says: >> >> * See the description of prb_read_valid() and prb_read_valid_info() >> * for details. > > This does not help because these two functions do not describe > how the seq is modified. And there are clearly three possibilities > when it returns false: > > 1. The record for the given seq number has not been finalized > yet. In this case, it keeps "seq" as it was. > > 2. The record for the given seq has been dataless. In this case > it would try to advance seq until it finds a record with > the data or not-yet-finalized one. "dataless" is the wrong word. It should be "lost data". It is skipped because there is no data available (because it was lost) for the reader to read. This is _not_ the case where it is a finalized fully intakt record containing an empty string. > > 3. The given seq number has been invalid, above the head. > In this case, it keeps "seq" intact. So same as 1st case. > > Note that "seq" was not updated in the 1st and 3rd case. But the > current comment suggests that it is updated. > > Well, it might be updated in all situations when then given > seq pointed to an already overwritten record (below tail). You are making this all sound much more complicated than it is. Really. I suppose this is testimony for the horrible documentation. >> _prb_read_valid() returns true > > This is not true if I read the code correctly. Unfortunately you are not reading the code correctly. (Or rather, you are being misled by comments because you incorrectly associate "not available to reader" to mean "valid record with an empty string". > PS: Sigh, I know that my comments looked like nitpicking. I had big inner > fight whether it was worth it or I was just burning my and others > time. But it seems that it helped for find many subtle problems > in the end. Indeed. The subtle problem is: unclear comments/documentation. John