Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2402095rdf; Mon, 6 Nov 2023 13:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2Yy5Cu72UDmDZvMRtBEq8YKLM2wGyzfb9l8XTsLTLaYp5RIEllCBpSPLgeeD3Ncvlp6W/ X-Received: by 2002:a05:6a00:15ca:b0:6bd:66ce:21d4 with SMTP id o10-20020a056a0015ca00b006bd66ce21d4mr28278566pfu.23.1699304894230; Mon, 06 Nov 2023 13:08:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699304894; cv=none; d=google.com; s=arc-20160816; b=IPj/5jXKrGBoXh1Ax41OhpPVf2SeNrQl13aTvWPBCQk6mVHgGnhw+WoR90+Q9c1j4O rs2Tk5o+fNEpdwaQmZGmUJdcuIBQKGmyMBGXA5iPCXtynh0jsO2dRFKZfLf/D60WaVGR isbXOUn6mJiE34TTdph+y9Xfm4DWDSCcy76UhxJPsBKnB2WA/IcByXBbzb67EMa9BtIA reh0B24Wgwds3xeXLj2xoOSL9zVIscz1aTJth4NqrfTXgInTYa1tQ2UdTYoQUUdo+T2n NvGCAtEXIQKo4ufXSNiKd3d1fY8/tNLGkYoIfVh/dAU0nJR+1EGhxnZ8Q5GsTDoduuW1 qQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=zy0aCNS0BNbBR2t/Vy2pLfxqa358VYw0pvvR05rDg/o=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=vNy5FGAOT/opGaV8d+A9PNx+0Qzdo4Q7yxOzWBbnVQfMOww8LiZhRlMIufozX8LYQs kdXs1nRsidcEHIYI5vKW90rLmTk5yXrPovMt+gZg+kJpsJWSpe5eKJgkQnkiF0kp4Ey7 bhgqlnnBoK7n3qQihlA+4teyyd/eTvYyOv8K1Z2z+Jk97AK7VtjBF8Ofs5krBGZEbjaU 0vXSYM7rVSbi3o+ycavKxdkWY635Hw7qobrxpu0XvBFtRVlVEOLPVUC1Vg2TGHygfeyY rGxwa+yt6BL5trLJVh0qiTyABF1gpbayIyDzmYrtlfws6boTNnlezHqSvxByhqZsnG4V C6SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fB6LLMeP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id f8-20020a656288000000b005b938759695si450984pgv.886.2023.11.06.13.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:08:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fB6LLMeP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 75A0D8031138; Mon, 6 Nov 2023 13:08:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233136AbjKFVHp (ORCPT + 99 others); Mon, 6 Nov 2023 16:07:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbjKFVHi (ORCPT ); Mon, 6 Nov 2023 16:07:38 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379CDD75 for ; Mon, 6 Nov 2023 13:07:35 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1699304853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zy0aCNS0BNbBR2t/Vy2pLfxqa358VYw0pvvR05rDg/o=; b=fB6LLMePAfBS6UsMHNPaGN1Jp491bueVhdT9MO5Poa+tLrJXPOEbHESi9XjdXfPX/nq8zj Fy5eumkd+lH2QB7p1YFdETnX/II5LCSnAhWuUVcUYv7/qIdiCOtb7HjraMrTj8Onso/pFF 8V6YPGa9VHUK4pQ7Z8bTiw/rrkZDsDboZE5aHm9OAHBj6hEONNlfwJmLTQOEuO5tHZ4Ibd 2s7hOSONf4fJKU6NKS/5aKD3l74gjI7t+EO4KqcJGlM4vno/UySNkR8p03mQiQU+G++tBt Jp5KQMn8Zh5hLvxc83e7nKW1IBu9K1liHOM3+eSpb8DCl6UIFszPphqlTi8Z8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1699304853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zy0aCNS0BNbBR2t/Vy2pLfxqa358VYw0pvvR05rDg/o=; b=HbiGHTBfFOaOEt2JUlfzI0MJAMvgqI0KgYMKg369AG+/tYwBccrxc0M4/aXxi7/3czo/64 Krv9JHZCFJytrADA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 2/9] printk: ringbuffer: Clarify special lpos values Date: Mon, 6 Nov 2023 22:13:23 +0106 Message-Id: <20231106210730.115192-3-john.ogness@linutronix.de> In-Reply-To: <20231106210730.115192-1-john.ogness@linutronix.de> References: <20231106210730.115192-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 13:08:05 -0800 (PST) For empty line records, no data blocks are created. Instead, these valid records are identified by special logical position values (in fields of @prb_desc.text_blk_lpos). Currently the macro NO_LPOS is used for empty line records. This name is confusing because it does not imply _why_ there is no data block. Rename NO_LPOS to EMPTY_LINE_LPOS so that it is clear why there is no data block. Also add comments explaining the use of EMPTY_LINE_LPOS as well as clarification to the values used to represent data-less blocks. Signed-off-by: John Ogness --- kernel/printk/printk_ringbuffer.c | 20 ++++++++++++++++---- kernel/printk/printk_ringbuffer.h | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c index 94eede5356ac..43d77db435c5 100644 --- a/kernel/printk/printk_ringbuffer.c +++ b/kernel/printk/printk_ringbuffer.c @@ -1034,9 +1034,13 @@ static char *data_alloc(struct printk_ringbuffer *rb, unsigned int size, unsigned long next_lpos; if (size == 0) { - /* Specify a data-less block. */ - blk_lpos->begin = NO_LPOS; - blk_lpos->next = NO_LPOS; + /* + * Data blocks are not created for empty lines. Instead, the + * reader will recognize these special lpos values and handle + * it appropriately. + */ + blk_lpos->begin = EMPTY_LINE_LPOS; + blk_lpos->next = EMPTY_LINE_LPOS; return NULL; } @@ -1214,10 +1218,18 @@ static const char *get_data(struct prb_data_ring *data_ring, /* Data-less data block description. */ if (BLK_DATALESS(blk_lpos)) { - if (blk_lpos->begin == NO_LPOS && blk_lpos->next == NO_LPOS) { + /* + * Records that are just empty lines are also valid, even + * though they do not have a data block. For such records + * explicitly return empty string data to signify success. + */ + if (blk_lpos->begin == EMPTY_LINE_LPOS && + blk_lpos->next == EMPTY_LINE_LPOS) { *data_size = 0; return ""; } + + /* Data lost, invalid, or otherwise unavailable. */ return NULL; } diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h index 3374a5a3303e..5c09061433f3 100644 --- a/kernel/printk/printk_ringbuffer.h +++ b/kernel/printk/printk_ringbuffer.h @@ -127,8 +127,22 @@ enum desc_state { #define DESC_SV(id, state) (((unsigned long)state << DESC_FLAGS_SHIFT) | id) #define DESC_ID_MASK (~DESC_FLAGS_MASK) #define DESC_ID(sv) ((sv) & DESC_ID_MASK) + +/* + * Special data block logical position values (for fields of + * @prb_desc.text_blk_lpos). + * + * - Bit0 is used to identify if the record has no data block. (Implemented in + * the LPOS_DATALESS() macro.) + * + * - Bit1 specifies the reason for not having a data block. + * + * These special values could never be real lpos values because of the + * meta data and alignment padding of data blocks. (See to_blk_size() for + * details.) + */ #define FAILED_LPOS 0x1 -#define NO_LPOS 0x3 +#define EMPTY_LINE_LPOS 0x3 #define FAILED_BLK_LPOS \ { \ -- 2.39.2