Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3877091rdg; Wed, 18 Oct 2023 08:27:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAhFocDSAYAsV9EX//n8ea/VagJMVU8Q+z3o2IqXgEpTf56/jL9Qt7GUHA5mhgHfTq/S+b X-Received: by 2002:a05:6359:2d85:b0:166:e153:db13 with SMTP id rn5-20020a0563592d8500b00166e153db13mr4783042rwb.16.1697642863178; Wed, 18 Oct 2023 08:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697642863; cv=none; d=google.com; s=arc-20160816; b=L3AyCp38RcwG6rsOtcp3T52QPfgzo89s+OYXNvFBvm3HagmimCk2O8nXgW/KdJ4fgd D/KfPYlZY0dcARp8ITNoTJAjSPcXLQvLHbZC1x9ZeLobS9Vzx7cMhmghaD9HQIAkSyZf Nk6b+iGG+7v8T1sJCX3KRhRatNHwXqBWNvDUqVh+h9eK07ZzxDwxBIK3+s3X5h60IUgr TvWD3UtlW+w4kOR0JJ+HEYEcRQMMyFT0U/vh2CnKcnuR6FM2V1kx1O4OR72c9ua9oDhA P+SXv4aopikM1tb3wRqyDP6xoEngkIoSh2BmjwD1xtiEHF1TRC86+HUoDxJaZCBiNOBN eAGQ== 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; bh=r/9m6h3MqD09l+fnjM/zg4dZexc4ErmfKAJrk8yM0GQ=; fh=3oUSWWYQ0rMHaNqDlm8j09K7pkfJE062n+5jIRWafQ4=; b=EfgAqOty7w5qbWCGCG9fCA/W33soTlO/SdgjJJDH3A7KXNj+oYSZyV3bzKFHp/CkNJ D31hiyO5U3m9mAQgZF/ee1DkSeFY1ZbD+6Ksv3J2h7Hzph5ruqIDNDewKYspLlvHsCeo BnQWBWY93/wFIbAKeVvg43SYUplHEB1hNS0gip4myLC8ZduYrqUgfLYOx6h6vyLtXYXB EBRc3DpaLkQDmsgBzA6PymZR6erprABd0fUDH0Lhij1q3uhDlNWzu4x0HgwSZBIjS6/t 7QIz5kL0qmh+oQmFi0dIlnmCybZmQUTaJnB4z7jhSArYxETZIim/qqEhM/6HHT9i30EG w/VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id m21-20020a656a15000000b005b7e3ee1820si2573704pgu.157.2023.10.18.08.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:27:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4ED2380F66BF; Wed, 18 Oct 2023 08:27:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbjJRP1a (ORCPT + 99 others); Wed, 18 Oct 2023 11:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbjJRP13 (ORCPT ); Wed, 18 Oct 2023 11:27:29 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 742EAF7 for ; Wed, 18 Oct 2023 08:27:27 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 199AC1FD7C; Wed, 18 Oct 2023 15:27:26 +0000 (UTC) Received: from suse.cz (pmladek.tcp.ovpn2.prg.suse.de [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id AF8FE2C23A; Wed, 18 Oct 2023 15:27:25 +0000 (UTC) Date: Wed, 18 Oct 2023 17:27:25 +0200 From: Petr Mladek To: John Ogness 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 Message-ID: References: <20231013204340.1112036-1-john.ogness@linutronix.de> <20231013204340.1112036-4-john.ogness@linutronix.de> <87mswh6iwq.fsf@jogness.linutronix.de> <874jio6o2y.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874jio6o2y.fsf@jogness.linutronix.de> X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 199AC1FD7C X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 08:27:40 -0700 (PDT) On Wed 2023-10-18 15:51:57, John Ogness wrote: > 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); I see. And this this set in static void desc_make_final(struct prb_desc_ring *desc_ring, unsigned long id) { [...] /* Best effort to remember the last finalized @id. */ atomic_long_set(&desc_ring->last_finalized_id, id); } So it is the _last_ finalized id from the timing POV. If there are more CPUs storing and finalizing the messages in parallel then it might change forth and back. There might be earlier non-finalized records and newer finalized ones. It means that prb_next_seq() really is the best effort and the description is not valid: /** * prb_next_seq() - Get the sequence number after the last available record. * * @rb: The ringbuffer to get the sequence number from. * * This is the public function available to readers to see what the next * newest sequence number available to readers will be. * * This provides readers a sequence number to jump to if all currently * available records should be skipped. It is not guaranteed that it will be the last available record because there might be newer already finalized records with some non-finalized records in between. Also it is not guaranteed that it will be the next record available to readers because readers should stop on the 1st non-yet-finalized record and prb_next_seq() might be behind. It would be great to document these subtle details especially when we are going to depend on them. > 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. It is not guaranteed. It might be lower when some still running CPU manages to finalize an earlier record and there are later non-finalized records. But you are right, there is a very high chance that it will point behind the last message from panic() context sooner or later, especially after CPUs get stopped. Well, note that only NMI guarantees that CPUs get stopped. There are still architectures which stop CPUs using normal interrupts. > 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". You are right. Well, it is really hard to put all the pieces together just by reading the code. And the unclear comments make it even worse. Best Regards, Petr