From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3DA3C433F5 for ; Thu, 16 Sep 2021 06:23:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 61381611EE for ; Thu, 16 Sep 2021 06:23:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 61381611EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F3E5094000A; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEE546B0072; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDCB194000A; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id D0DDC6B0071 for ; Thu, 16 Sep 2021 02:23:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7278F2D4B5 for ; Thu, 16 Sep 2021 06:23:32 +0000 (UTC) X-FDA: 78592445064.08.2C25198 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf17.hostedemail.com (Postfix) with ESMTP id 2A875F00039C for ; Thu, 16 Sep 2021 06:23:32 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CF8760E76; Thu, 16 Sep 2021 06:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631773411; bh=HDO3TKu02v6+e848DWht3XEAfdCaWsoKu5YHLC4JMMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYocb8eZ7/3/FZNxFtfy4rmfts/5jPeYqyzVudGgOhlnWeo6URPWpIH3jWe52h5RX umQmP3i1EXTTYgHvUaL9k017EwR/ZfRY+XVrkZjs2A2K9wvrTQ82e6tt3R8MKirRh0 VJq9joDDkXgjpSz91ti03fq2lxmNdoi79vrlsBhZYHryLqKdDog1c2PMnevdET7go6 aC1673yP/ACsgylD1rXW0dNbCpjgyqGBX4/c1g8lW0T+75YMN0K8mcQxYeRhOpr4R6 gdV2GL1pARj4BYvFZEIkuB86pPUsttzpJUWx6SAdVLK+y9I5z5+A5OSu+fKW7zrnXE PheReHNkSBAkA== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v4 3/4] bootconfig: Add xbc_get_info() for the node information Date: Thu, 16 Sep 2021 15:23:29 +0900 Message-Id: <163177340877.682366.4360676589783197627.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163177338366.682366.5998343833719057348.stgit@devnote2> References: <163177338366.682366.5998343833719057348.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SYocb8eZ; spf=pass (imf17.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: ajyognk37w19xsawrs4qr74bbs1e54kz X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2A875F00039C X-HE-Tag: 1631773412-164607 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add xbc_get_info() API which allows user to get the number of used xbc_nodes and the size of bootconfig data. This is also useful for checking the bootconfig is initialized or not. Signed-off-by: Masami Hiramatsu --- include/linux/bootconfig.h | 2 ++ init/main.c | 1 + lib/bootconfig.c | 21 +++++++++++++++++++++ tools/bootconfig/main.c | 1 + 4 files changed, 25 insertions(+) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index 62e09b788172..f955bb7eabbb 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -273,6 +273,8 @@ static inline int __init xbc_node_compose_key(struct = xbc_node *node, /* XBC node initializer */ int __init xbc_init(const char *buf, size_t size, const char **emsg, int= *epos); =20 +/* XBC node and size information */ +int __init xbc_get_info(int *node_size, size_t *data_size); =20 /* XBC cleanup data structures */ void __init xbc_destroy_all(void); diff --git a/init/main.c b/init/main.c index 77c309ed9f17..747b4fd38a1a 100644 --- a/init/main.c +++ b/init/main.c @@ -451,6 +451,7 @@ static void __init setup_boot_config(void) pr_err("Failed to parse bootconfig: %s at %d.\n", msg, pos); } else { + xbc_get_info(&ret, NULL); pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); /* keys starting with "kernel." are passed via cmdline */ extra_command_line =3D xbc_make_cmdline("kernel"); diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 66b02fddfea8..b088fe5c0001 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -34,6 +34,27 @@ static int xbc_err_pos __initdata; static int open_brace[XBC_DEPTH_MAX] __initdata; static int brace_index __initdata; =20 +/** + * xbc_get_info() - Get the information of loaded boot config + * node_size: A pointer to store the number of nodes. + * data_size: A pointer to store the size of bootconfig data. + * + * Get the number of used nodes in @node_size if it is not NULL, + * and the size of bootconfig data in @data_size if it is not NULL. + * Return 0 if the boot config is initialized, or return -ENODEV. + */ +int __init xbc_get_info(int *node_size, size_t *data_size) +{ + if (!xbc_data) + return -ENODEV; + + if (node_size) + *node_size =3D xbc_node_num; + if (data_size) + *data_size =3D xbc_data_size; + return 0; +} + static int __init xbc_parse_error(const char *msg, const char *p) { xbc_err_msg =3D msg; diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 7269c9e35335..4f2a8d884745 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -391,6 +391,7 @@ static int apply_xbc(const char *path, const char *xb= c_path) return ret; } printf("Apply %s to %s\n", xbc_path, path); + xbc_get_info(&ret, NULL); printf("\tNumber of nodes: %d\n", ret); printf("\tSize: %u bytes\n", (unsigned int)size); printf("\tChecksum: %d\n", (unsigned int)csum);