From nobody Thu Jun 18 08:16:10 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 077F1346A1C; Wed, 15 Apr 2026 10:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250287; cv=none; b=QY9Tm62KqgW4WoOSeIw4qTkthDEQqfvc9heaG3bjYSvLpJVYVfWMeaFJz/Hanxv+BNAbjJzLv9YhT/RylzrB/S5GSyPysbO/sK7HU8HSdo0HlUDe9RNmOYi+8g9JWsTU5zE3PrqQDDqm25xoUzP4QNqJv0SMcZkDNBmSMY/IgHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250287; c=relaxed/simple; bh=D+JK71Dn+lRILKBdWtEaIvJsNkD8TO2j7urH1sFvhdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LQyg68HQBIv7AK4/9wG3cIMBlD7UBt8MaYEz5OC+UnaIWpnFktHad4VKquQlnL6ie7RIeh/D4VoPRtkr8GySNDk80hbhIn+A0MPqpjDf16GNxe9hxaHQKvvnv7hxxQEHkRtFzSPPtADBxDVF+t7azSO/ntlEYUc2VfMuXDyfJS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=W2L65QSV; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="W2L65QSV" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=+15wd/77R1WY2fKUlSl7uq+s5kLFa6U/bFrsG3puXDQ=; b=W2L65QSVuKZpQPrG3tdaGfK7eT xMAYkr91q5G9ORzdSFA+f+uZVF4lz2aRLR5VidTkycOzF/rM5GhGjAbwCaIBa5AA3BKIoFI6pBhoy 12O9QtLIzEeysHMlVAO+W+zLu2P25If3B0D4L317KPVO+xvuIo3qkMkdtDnel37e9kjRwWI7otto7 K4cYEtd6v3R2PLvjn3WTU00TbLMf5jUEOBWxsnGXPPxiUj8sBSkSM9oDHEC4AwefpTZ3gMtateZf4 /au7I7Fk9EPxdYzvP3WTHIPofPkvhw9f7Qqg3bDSqXB1O9c8MqrkZLxc3LWIf3KqPFGsdlI+9LQYV cOI7xq1A==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wCxq5-00DmiK-0b; Wed, 15 Apr 2026 10:51:21 +0000 From: Breno Leitao Date: Wed, 15 Apr 2026 03:51:10 -0700 Subject: [PATCH 1/3] bootconfig: use static buffers instead of memblock allocation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260415-bootconfig_earlier-v1-1-cf160175de5e@debian.org> References: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> In-Reply-To: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> To: Andrew Morton , Masami Hiramatsu Cc: oss@malat.biz, paulmck@kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-453a6 X-Developer-Signature: v=1; a=openpgp-sha256; l=3487; i=leitao@debian.org; h=from:subject:message-id; bh=D+JK71Dn+lRILKBdWtEaIvJsNkD8TO2j7urH1sFvhdg=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBp322hVN/fArh78LiS22R93QZ1KA6LQMcERZATX X5382rGfpuJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCad9toQAKCRA1o5Of/Hh3 bQ1AD/9SzsxsgmABDeWNGE8a4G3K7n9rMMxa4AzHGbWc2qoLR8sK7bA+Y1DqvXOyBu4cPazjcH0 t1kO+434Vhsr9PVmEu8k7m4ScnsJrMB4RsrPv8IsotxTJp4mOZljdtVI16cTAPXb9YUqYL+lzea erdoJsErR7PTD6i1BpytGCrIGEUO+630JrELpVf3XFqPIvSrGLtI9f4vgpOMUb0j5pech6FjiOe qyf0N29GnYTtYvHA5Fcgth+1yC44vDf4NeGUESgWC1s+5RIVe4S0FKUumYKyBEi5JqLpsh13VgQ +ADLfiAz44l8Z8ZG8Sb7xwR+iel38+zBwFJZF56dDSSHGRAHt+3Vzl2sNogl/dlXw+mnSkYfT4g FllgHTsIjusyLS/p1Gzn3puDTo91uQPtYJtlNqPEPHX2l+DLkIlAQ4+kZmTt53MdJu3BMLvSqgU uthcanEKE5ambq5mx5GPJPeLPdf36vzB8GFNuUZiH6y+rJ6ToP/LmsosdCrd0RpCa7XwCumUGA2 lPf7ouNY9iZpfYrYkXsVtPKQMNUBsOd8yS5GITFbreiH/zLqsavrqQB11nkdDwBV001qVXV7vFw zN4MB3Aa9yfptFAzeW+h3lMVT3dtZ0nXGlc9wORCZzWTxnl1NCdcUJBvlO7QDsnB307+svEHxS2 I4QNXLNTxXktofg== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Replace dynamic allocations in the bootconfig parser with static __initdata buffers. This removes the dependency on memblock being available when bootconfig is parsed, which is a prerequisite for moving embedded bootconfig parsing earlier in the boot sequence. The static buffers are: - xbc_data_buf[XBC_DATA_MAX + 1] (~32KB) for bootconfig text data - xbc_nodes_buf[XBC_NODE_MAX] (64KB) for the parse tree nodes Both are __initdata and freed after init in the kernel. The userspace tools path (tools/bootconfig) also uses the same static buffers, which simplifies the code by removing all #ifdef __KERNEL__ blocks from the parser. Signed-off-by: Breno Leitao --- lib/bootconfig.c | 56 ++++++++++------------------------------------------= ---- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index c470b93d5dbc2..3e529325c90ac 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -15,12 +15,11 @@ =20 #ifdef __KERNEL__ #include -#include -#include #include #include +#include +#include #include -#include #include =20 #ifdef CONFIG_BOOT_CONFIG_EMBED @@ -54,33 +53,12 @@ static const char *xbc_err_msg __initdata; static int xbc_err_pos __initdata; static int open_brace[XBC_DEPTH_MAX] __initdata; static int brace_index __initdata; - -#ifdef __KERNEL__ -static inline void * __init xbc_alloc_mem(size_t size) -{ - return memblock_alloc(size, SMP_CACHE_BYTES); -} - -static inline void __init xbc_free_mem(void *addr, size_t size, bool early) -{ - if (early) - memblock_free(addr, size); - else if (addr) - memblock_free(addr, size); -} - -#else /* !__KERNEL__ */ - -static inline void *xbc_alloc_mem(size_t size) -{ - return calloc(1, size); -} - -static inline void xbc_free_mem(void *addr, size_t size, bool early) -{ - free(addr); -} -#endif +/* + * Static buffers for bootconfig data and nodes. Avoids dynamic allocation + * so bootconfig can be parsed before memblock is available in the kernel. + */ +static char xbc_data_buf[XBC_DATA_MAX + 1] __initdata; +static struct xbc_node xbc_nodes_buf[XBC_NODE_MAX] __initdata; =20 /** * xbc_get_info() - Get the information of loaded boot config @@ -930,11 +908,9 @@ static int __init xbc_parse_tree(void) */ void __init _xbc_exit(bool early) { - xbc_free_mem(xbc_data, xbc_data_size, early); xbc_data =3D NULL; xbc_data_size =3D 0; xbc_node_num =3D 0; - xbc_free_mem(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX, early); xbc_nodes =3D NULL; brace_index =3D 0; } @@ -973,24 +949,12 @@ int __init xbc_init(const char *data, size_t size, co= nst char **emsg, int *epos) return -ERANGE; } =20 - xbc_data =3D xbc_alloc_mem(size + 1); - if (!xbc_data) { - if (emsg) - *emsg =3D "Failed to allocate bootconfig data"; - return -ENOMEM; - } + xbc_data =3D xbc_data_buf; + xbc_nodes =3D xbc_nodes_buf; memcpy(xbc_data, data, size); xbc_data[size] =3D '\0'; xbc_data_size =3D size + 1; =20 - xbc_nodes =3D xbc_alloc_mem(sizeof(struct xbc_node) * XBC_NODE_MAX); - if (!xbc_nodes) { - if (emsg) - *emsg =3D "Failed to allocate bootconfig nodes"; - _xbc_exit(true); - return -ENOMEM; - } - ret =3D xbc_parse_tree(); if (!ret) ret =3D xbc_verify_tree(); --=20 2.52.0 From nobody Thu Jun 18 08:16:10 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 799E23264D4; Wed, 15 Apr 2026 10:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250289; cv=none; b=YONtQxT1sGu5a0FRPGh5nWWyst0C7A5QXKLTFLcGqT3SWh70TvzMabu7+cOlcRdmWHfXXxnzbSCkSp5ZAIXRbQ59B3uZCbxrXIU3UH1aIy7S0r3hI8oBPfJ/MD9tN67A6gzOTXKcoCaulmPON+ypmNeIFxEziUxGZCUwKfsez7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250289; c=relaxed/simple; bh=zi24MZoteh0rhRLPTwI2OS/Ab2wiJlBSZaMNEDXiZ7Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k35ZdjHqsfngtT5Mt7QIxHkQLv+mTW+HRbfa8wYzoxtxhWnSLrIxJD7XwAZmUu+cwrgInWArHnuQE5S6TPGvNkQWkcGX2vZdr+xlIGziATXmsAC0iEACpgg9bz9wNsZKU6Vepxol6rZofZcOWvDhcpClOX4xR2WN1h4tOje1zEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=gRbPPBj3; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="gRbPPBj3" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=ILyrpCqpMl/TMd2NGrJVJqAJH7iOYKWbcki7NhdcRHQ=; b=gRbPPBj3EYyCmbKWrKjwNJSjLt xQR8mSe0UGEyYBedaAvQ1Srx/o1jMK2H1jxSOlO0rLEziwHyezhpyZ10z8F+IbkiZ62P0sPxrqUK6 upOwjLfcPH5tWT9p0MbrxIvkEpEGAYSouoqSQE0qlCWCujdcLMhf83Un3alf9QSVCguaR+Wk8Emdf VkxPF0/l8iyCrT3LQg9/ctqSFa7+W/9gPaa4Z7HDxGhjmqlR03OL6rEp+ZdBk06sf7TDu3JQAbp/+ 08eDneA0LSayuVs5ORd5oU193TcZJ7DKz5TJXL0Qs1bIgTqkOt0lmiWLAHU9atu09dDudXbdMXuQQ czZnjf5w==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wCxq8-00DmiU-2N; Wed, 15 Apr 2026 10:51:25 +0000 From: Breno Leitao Date: Wed, 15 Apr 2026 03:51:11 -0700 Subject: [PATCH 2/3] init: use static buffers for bootconfig extra command line Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260415-bootconfig_earlier-v1-2-cf160175de5e@debian.org> References: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> In-Reply-To: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> To: Andrew Morton , Masami Hiramatsu Cc: oss@malat.biz, paulmck@kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-453a6 X-Developer-Signature: v=1; a=openpgp-sha256; l=2441; i=leitao@debian.org; h=from:subject:message-id; bh=zi24MZoteh0rhRLPTwI2OS/Ab2wiJlBSZaMNEDXiZ7Y=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBp322huQaEmgvJMOssvu5k5UoUVPkweG3PLAegd 1kxIxEHXz2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCad9toQAKCRA1o5Of/Hh3 bfBkEACiIyjKxEXP/uZrxtzpo4ZmAdtu12NEeV+P+i4YVg6TzCKZ0CYDfNVdmH8WK2Onw1f4pbj 45IimlOgCQeD+XexC1dtkBWEoGq6+btQg9UdkZRghXUnvgLyvRNada41CnsyH4UcqZZYZr5cTe6 UWsx51pQCE0fgkgO8V55cx3vAPrhd1IbBHuBnDdWZSoLVkpDjLFZJOWzmPhX+784pyUA467D261 boVg+hcd1GsBjQOzrUmCK4YkymfiS33NyyNCCeRlwU5khhm9g44ACqaS7DctoZ6wvZ0MgkB1SQT oLH8flrPWjFB2mELYvR8R/tzJlwr/kZ69p88Fom3ghCevuaqKwDcJfJdkuRgISq3voT6fUTJOZz JYH84GblJQAjPao5LWkmeqtILswdeXM+3Ygjmef153K8np/+wuEcP0DXk13wUOGpRLNbhRUf1s3 SdfUMAokeIjRsJuKTzhUNpEum7rFYmL5US6Bv/K6xPujYZoFCX2Y1C0YGE990a8i+rKtDMPs6r9 Hnqbg1PcCKkgmEZ5l1j8oIlDZGKMcB9rP2bpAR7RXl8NLjtf6B6Iox2ABlltSXWj3yxHpSKUCO9 UdpIDRctohW39ZJGByuY0uXzFR+QjNgaN3qm4vuBeT8Hz99BNQodSs0/s95IGU79dZbyfnl+Lqy avVoANYklgR0cRA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Replace memblock_alloc/memblock_free in xbc_make_cmdline() with static __initdata buffers. This removes the last memblock dependency from the bootconfig loading path, completing the prerequisite for running bootconfig parsing before memblock is available. Signed-off-by: Breno Leitao --- init/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/init/main.c b/init/main.c index 96f93bb06c490..b9feca55e01f9 100644 --- a/init/main.c +++ b/init/main.c @@ -369,11 +369,18 @@ static int __init xbc_snprint_cmdline(char *buf, size= _t size, } #undef rest =20 +/* + * Static buffers for bootconfig-generated command line parameters. + * Two separate buffers are needed because both "kernel" and "init" + * parameters are stored simultaneously. + */ +static char extra_cmdline_buf[COMMAND_LINE_SIZE] __initdata; +static char extra_initargs_buf[COMMAND_LINE_SIZE] __initdata; + /* Make an extra command line under given key word */ -static char * __init xbc_make_cmdline(const char *key) +static char * __init xbc_make_cmdline(const char *key, char *new_cmdline) { struct xbc_node *root; - char *new_cmdline; int ret, len =3D 0; =20 root =3D xbc_find_node(key); @@ -382,19 +389,12 @@ static char * __init xbc_make_cmdline(const char *key) =20 /* Count required buffer size */ len =3D xbc_snprint_cmdline(NULL, 0, root); - if (len <=3D 0) + if (len <=3D 0 || len >=3D COMMAND_LINE_SIZE) return NULL; =20 - new_cmdline =3D memblock_alloc(len + 1, SMP_CACHE_BYTES); - if (!new_cmdline) { - pr_err("Failed to allocate memory for extra kernel cmdline.\n"); - return NULL; - } - ret =3D xbc_snprint_cmdline(new_cmdline, len + 1, root); if (ret < 0 || ret > len) { pr_err("Failed to print extra kernel cmdline.\n"); - memblock_free(new_cmdline, len + 1); return NULL; } =20 @@ -467,9 +467,9 @@ static void __init setup_boot_config(void) xbc_get_info(&ret, NULL); pr_info("Load bootconfig: %ld bytes %d nodes\n", (long)size, ret); /* keys starting with "kernel." are passed via cmdline */ - extra_command_line =3D xbc_make_cmdline("kernel"); + extra_command_line =3D xbc_make_cmdline("kernel", extra_cmdline_buf); /* Also, "init." keys are init arguments */ - extra_init_args =3D xbc_make_cmdline("init"); + extra_init_args =3D xbc_make_cmdline("init", extra_initargs_buf); } return; } --=20 2.52.0 From nobody Thu Jun 18 08:16:10 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58B2D345CA5; Wed, 15 Apr 2026 10:51:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250293; cv=none; b=QsOi+p5X9QsxPs0GQW8QJJsnGJWNFiwE0LhkTfLnBBCeLrmynm9jwlWUd/g0tr0nJvCFEtVgC87UzetWOXaoO4XEx1hKv8xWnxIE4fNr6aUsSYzWVYFjMjaQTXuyPA1vyfNAngGIdeqAJWSoCctbMkEsGb2w0IONF5gAvFg+kTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250293; c=relaxed/simple; bh=Vrq31nIEudZ39oK3KYS3QYZ0eIrMaHiveXBTtFLkx6Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XFoe+y0hqvPHOY09ilJpEVCcu7h5vw7hFfrhzjr9fmQ8PX6J9PL+yL0YdiXpG5TMGDo9adw+GeTBvPMD750qgOxknTPtUZrYSOyFUsGxA5EVha/VNgBj2n3+h0ClTUsfJZOOK6GsRcJtpIvHzcl7CnuYYnFvSCW5nS8bNw5GQ5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=ODD2GqHB; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="ODD2GqHB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=s3nMnmGrqEtfuwNnCgWOm2YDuOfsDx+syqU0dF2CDoM=; b=ODD2GqHBaoWuq37l1gCCu4SrGG PBn0sCQHxX/3/JnD0tprYo1dU3Q4/f9ov+vEgjg0uegcW9BPdQrwGYkGBw9ptmtmO0tlUgYubterp G0Zm4hmSeB/GeZ66+lRc5jxXz1LwsFyO9wsNGId9/tn1yM1XjayPTZSs4asq3YiBFhAoy0yTjS1Cx x2NZkLM+dfHCIWi93LJ8HEWf0es8pVw88mO33wgXXiyAdqZJmNkiGPdjSGsKHJZQycb6q+K73uzYJ Bv4jx4Zk8nSxGhdV2LjvanvNozeK9VZyv+d6lrup1HctUgVc1Xmxe91G7afQZU3j0eLyZif9Bwdze Qn3nhD1w==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wCxqC-00Dmie-10; Wed, 15 Apr 2026 10:51:28 +0000 From: Breno Leitao Date: Wed, 15 Apr 2026 03:51:12 -0700 Subject: [PATCH 3/3] init: move embedded bootconfig parsing before setup_arch() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260415-bootconfig_earlier-v1-3-cf160175de5e@debian.org> References: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> In-Reply-To: <20260415-bootconfig_earlier-v1-0-cf160175de5e@debian.org> To: Andrew Morton , Masami Hiramatsu Cc: oss@malat.biz, paulmck@kernel.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kernel-team@meta.com, Breno Leitao X-Mailer: b4 0.16-dev-453a6 X-Developer-Signature: v=1; a=openpgp-sha256; l=4290; i=leitao@debian.org; h=from:subject:message-id; bh=Vrq31nIEudZ39oK3KYS3QYZ0eIrMaHiveXBTtFLkx6Q=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBp322h5pS1HJ7mmk52ayT1x24c8M/wIrJjNZeq+ +YU2JsY0suJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCad9toQAKCRA1o5Of/Hh3 bTPYD/0T6tZbj7Fu4CyUJmtyODdU3IwlVQPcUx9Nd7woXNrL3zwVKmTgRVxMfQPDBbM2l6+NYkn Bl8B3v6vmVv9vvCwrOGMbI8sPhlo7ibB4DSEo8qeFCpHEdZ+kXLG/86Qiuf15wXfwnW5uncIgsZ 2TwajjdPlMnGRj5gEbqAeqjsUL0zATFecPy/U2v+SXVUWxjFs6ME4Jwft4IeeDgZIUu6WMN0IA0 T/ENdddGzu9VqYewDlzN7fIuybM7G6hMHJKlBgluTq9LYrebUPV0xujFGN7Vc85pXZ+awva+c0d q0eAWnoCEGN9gQmnMYkvqFbG+YLuymLgxB16W3R5fgnR9LVhe+uIjYljEnR6FHNQFXwMCKug1mv LYBCJEAF+BtyL2CMCDXaT7kwZYpsVSVEoCxCbdyHpav/5hn4lmrCYZxiPBG3iBfzOgf3s7zkZpU nQQvD5XIy6R5xOTcwL3ik2oNjoS4kKWEsigKCjNj9rf0SLWi34JVHWSgsDJhO+fkYYNzr004mWx 4Fqzi+bFGU7LHbJf7gi2Sld+juVurUyJuUIEg+6LUVxDHM61xqgtmdc9UKAFodvANxwwfPxnnON 2a/xhdYslKS37sf/dM5/nuOKuxsoJ7aZ7A9n+5/RAO56Of0CFddczDg1QNJZgMBxUsL2r/+hHsg F0wGCJHugX2zkQw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Split setup_boot_config() into setup_boot_config_from_embedded() for embedded bootconfig and setup_boot_config_from_initrd() for initrd bootconfig. The embedded bootconfig data lives in .init.rodata (compiled into the kernel via bootconfig-data.S), so it requires no memory allocation to access. Combined with the previous patches that replaced memblock allocations with static buffers, this allows embedded bootconfig to be parsed before setup_arch(), making bootconfig parameters available during architecture-specific setup. The initrd bootconfig path remains at its original position since it needs initrd_start/initrd_end set up by setup_arch(). Signed-off-by: Breno Leitao --- init/main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/init/main.c b/init/main.c index b9feca55e01f9..20fded9bfbdd0 100644 --- a/init/main.c +++ b/init/main.c @@ -416,20 +416,17 @@ static int __init warn_bootconfig(char *str) return 0; } =20 -static void __init setup_boot_config(void) +/* + * Parse bootconfig data and extract kernel/init command line parameters. + * Shared by both the early embedded path and the late initrd path. + */ +static void __init __boot_config_load(const char *data, size_t size) { static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata; - const char *msg, *data; + const char *msg; int pos, ret; - size_t size; char *err; =20 - /* Cut out the bootconfig data even if we have no bootconfig option */ - data =3D get_boot_config_from_initrd(&size); - /* If there is no bootconfig in initrd, try embedded one. */ - if (!data) - data =3D xbc_get_embedded_bootconfig(&size); - strscpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); err =3D parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL, bootconfig_params); @@ -471,7 +468,50 @@ static void __init setup_boot_config(void) /* Also, "init." keys are init arguments */ extra_init_args =3D xbc_make_cmdline("init", extra_initargs_buf); } - return; +} + +/* + * Load embedded bootconfig before setup_arch(). This runs before memblock + * is available, relying on static buffers in the bootconfig parser. + * The embedded data lives in .init.rodata so no allocation is needed + * to access it. + */ +static void __init setup_boot_config_from_embedded(void) +{ + const char *data; + size_t size; + + data =3D xbc_get_embedded_bootconfig(&size); + if (!data) + return; + + pr_info("Load embedded bootconfig early\n"); + __boot_config_load(data, size); +} + +/* + * Load bootconfig from initrd. This MUST run after setup_arch() when init= rd + * boundaries are known. If initrd bootconfig exists, it overrides any emb= edded + * bootconfig that was loaded early, preserving the original priority (ini= trd + * > embedded). + */ +static void __init setup_boot_config_from_initrd(void) +{ + const char *data; + size_t size; + + /* Cut out the bootconfig data even if we have no bootconfig option */ + data =3D get_boot_config_from_initrd(&size); + + /* No initrd bootconfig =E2=80=94 keep embedded if already loaded */ + if (!data) + return; + + /* Initrd overrides embedded =E2=80=94 tear down and re-parse */ + if (xbc_get_info(NULL, NULL) =3D=3D 0) + _xbc_exit(true); + + __boot_config_load(data, size); } =20 static void __init exit_boot_config(void) @@ -481,7 +521,9 @@ static void __init exit_boot_config(void) =20 #else /* !CONFIG_BOOT_CONFIG */ =20 -static void __init setup_boot_config(void) +static void __init setup_boot_config_from_embedded(void) { } + +static void __init setup_boot_config_from_initrd(void) { /* Remove bootconfig data from initrd */ get_boot_config_from_initrd(NULL); @@ -1036,13 +1078,14 @@ void start_kernel(void) boot_cpu_init(); page_address_init(); pr_notice("%s", linux_banner); + setup_boot_config_from_embedded(); setup_arch(&command_line); mm_core_init_early(); /* Static keys and static calls are needed by LSMs */ jump_label_init(); static_call_init(); early_security_init(); - setup_boot_config(); + setup_boot_config_from_initrd(); setup_command_line(command_line); setup_nr_cpu_ids(); setup_per_cpu_areas(); --=20 2.52.0