Skip to content

Commit ebb3c47

Browse files
committed
Merge: add bootconfig to kernel-tools package
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5642 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git JIRA: https://issues.redhat.com/browse/RHEL-65546 Omitted-fix: 0a13b6c ("docs/zh_CN: Add new translation of admin-guide/bootconfig.rst") Add the bootconfig binary to the kernel-tools package. CONFIG_BOOT_CONFIG is already enabled in RHEL and this allows having a separate file with the kernel parameters and is described at https://docs.kernel.org/admin-guide/bootconfig.html. We intend to use this for automotive for testing purposes since some embedded platforms limit the kernel command line paramters to 511 bytes. This also required bringing the bootconfig support up to the latest upstream at the time of this writing since the tools/bootconfig/ binary would not compile. This series was tested in qemu with the following procedure. Create a `/etc/kernel/bootconfig` file with the following contents that contain a kernel command line parameter that's longer than 511 bytes: ``` kernel { systemd.random-seed=EYDERk+qnhjx+WOS5zTfsSIbKGDeeZhaAXG5AaxkYr6lDgjIEZHmjjejC1INyArPQ7eNUWqzO9f/RtRaSXeLE7nac3kmVkOBlRmvMplPZS64O/vvMmQq/DZPx3pRKkuB6hGTL9LjK0eQtBFbSHI6YNhMnxSuZa/GWYpiw2rJZDU7EclaJT3xNcn3HFCL3EzPdh+fKm1s6SXF5YEqzGzSgdxj9CFGtrHuyNEoGU/bRCGRTQk11YvSrJJUPfR6zYSfBG26+oNyMwC7YJaguw/rKmXrGmCnrLMJRFuL8ytD6kHBhQJjxT2i2OIc+iSgHAYwZjCfsk3M/vbOTGxDoNiIEjljhGXPhCZofmLM8CgB0R5u/0vKNrwdxpmvKaVQzbFcVMpbGZAyt842yhXCbPDpBzfwQzqtD6bCYIxTzmz0JFE/H0McTNnMOur4u2kKbLcxoO0x8VxR6xYtGDPPJQmlxom9Zx7fIinUDcwA4Id1LCWXJuxrBtJKMK6ig7thwGtNN6qui7hUTMyjsLxgodg8eLaKIJJX393Hqid7wTZ90XQPG5ndO1M0FHfK1zBFF/R3BWlonwpKeh2avFCUcJidg+TzXsDmF+ru+//MVNA3MXRNw14qh+MYX4Xy/pWYuc4GngidF5AOzL0hIbC+PmGCHD+ae6yhj/o/5HPjqmHYNUjpvjsIhGTZaSJj9+1/9y1gCiQfypJP4zFUNPRAHBFoALMgTbQVI+Y1ZnuuIBNnRWQz/wpeRFl5YZjXwJNqxQCNMgPhKABaLd3GXi85yELrLnV5sOlPbuMvf7gR9YzDO5qeUtN23xDp+zDGLmxgCgrDdnLy4Gqbc8Pxos7RqEovBSUb+vtEpjLjub8nMGOzKsdM7ZzYzrLC2ydeh5SFHo6t3T23Kwoo5m+4VYVOsX7exbGFL8429PSnXXvUIosq0WtyBP4xVY7a274sOTnypJ4THia+dEBPaQ7mxO4qqI2+dGMpbCMOOMm4UqflvCrbypUFDrtfsCuolB8ddyV5kiwmzGjJri425QGxpoJQvvlgSAgOgZBVbP/YmPl3MQGDUtkGMxLyll1jFRGwsJQTYb35bP8oYLIpylD+9bdAM4Ev+sIDbISc0ao409aN8IOt61tpq1nzuCA9TPmDwzmP/PUDBFivVTFIuHjMJxXtu+rSp77sbSSwIJa/sXOic+m6ID6itX6lAO2cQ3gaBY+KGoF18QR50S3hU5wr5soooJv7KVmArNYMXtVOHpAWd1s0XxaQBYBF1SEhU4XgT/wZKdUeMkJQVvPk0Lzz2zF2WPkZnAdxPzfUieUo5vFWe1s7BVOMOb3CNrIKN5XfjS4JWUflEYxfDHkhhgQUJ2b+4tQUOQ== } ``` Edit `/etc/kernel/cmdline` and add `bootconfig` to the list of kernel command line arguments. You may also need to edit `/boot/loader/entries/*` as well. Run `sudo bootconfig -a /etc/kernel/bootconfig /boot/initramfs-5.14.0-*` When the system boots you will see messages like the following in the log: ``` Nov 07 01:07:38 localhost kernel: Load bootconfig: 1409 bytes 4 nodes ... Nov 07 01:07:38 localhost systemd[1]: Successfully credited entropy passed on kernel command line. Nov 07 01:07:38 localhost systemd[1]: Note that the seed provided this way is accessible to unprivileged programs. This functionality should not be used outside of testing environments. ``` `/proc/cmdline` will contain the `systemd.random-seed` variable. Signed-off-by: Brian Masney <bmasney@redhat.com> Approved-by: Eric Chanudet <echanude@redhat.com> Approved-by: Chris von Recklinghausen <crecklin@redhat.com> Approved-by: Jan Stancek <jstancek@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents f8d23cd + b65366c commit ebb3c47

File tree

29 files changed

+982
-297
lines changed

29 files changed

+982
-297
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ Each key-value pair is shown in each line with following style::
158158
Boot Kernel With a Boot Config
159159
==============================
160160

161-
Since the boot configuration file is loaded with initrd, it will be added
162-
to the end of the initrd (initramfs) image file with padding, size,
163-
checksum and 12-byte magic word as below.
161+
There are two options to boot the kernel with bootconfig: attaching the
162+
bootconfig to the initrd image or embedding it in the kernel itself.
163+
164+
Attaching a Boot Config to Initrd
165+
---------------------------------
166+
167+
Since the boot configuration file is loaded with initrd by default,
168+
it will be added to the end of the initrd (initramfs) image file with
169+
padding, size, checksum and 12-byte magic word as below.
164170

165171
[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]
166172

@@ -178,7 +184,7 @@ update the boot loader and the kernel image itself as long as the boot
178184
loader passes the correct initrd file size. If by any chance, the boot
179185
loader passes a longer size, the kernel fails to find the bootconfig data.
180186

181-
To do this operation, Linux kernel provides "bootconfig" command under
187+
To do this operation, Linux kernel provides ``bootconfig`` command under
182188
tools/bootconfig, which allows admin to apply or delete the config file
183189
to/from initrd image. You can build it by the following command::
184190

@@ -195,6 +201,66 @@ To remove the config from the image, you can use -d option as below::
195201

196202
Then add "bootconfig" on the normal kernel command line to tell the
197203
kernel to look for the bootconfig at the end of the initrd file.
204+
Alternatively, build your kernel with the ``CONFIG_BOOT_CONFIG_FORCE``
205+
Kconfig option selected.
206+
207+
Embedding a Boot Config into Kernel
208+
-----------------------------------
209+
210+
If you can not use initrd, you can also embed the bootconfig file in the
211+
kernel by Kconfig options. In this case, you need to recompile the kernel
212+
with the following configs::
213+
214+
CONFIG_BOOT_CONFIG_EMBED=y
215+
CONFIG_BOOT_CONFIG_EMBED_FILE="/PATH/TO/BOOTCONFIG/FILE"
216+
217+
``CONFIG_BOOT_CONFIG_EMBED_FILE`` requires an absolute path or a relative
218+
path to the bootconfig file from source tree or object tree.
219+
The kernel will embed it as the default bootconfig.
220+
221+
Just as when attaching the bootconfig to the initrd, you need ``bootconfig``
222+
option on the kernel command line to enable the embedded bootconfig, or,
223+
alternatively, build your kernel with the ``CONFIG_BOOT_CONFIG_FORCE``
224+
Kconfig option selected.
225+
226+
Note that even if you set this option, you can override the embedded
227+
bootconfig by another bootconfig which attached to the initrd.
228+
229+
Kernel parameters via Boot Config
230+
=================================
231+
232+
In addition to the kernel command line, the boot config can be used for
233+
passing the kernel parameters. All the key-value pairs under ``kernel``
234+
key will be passed to kernel cmdline directly. Moreover, the key-value
235+
pairs under ``init`` will be passed to init process via the cmdline.
236+
The parameters are concatenated with user-given kernel cmdline string
237+
as the following order, so that the command line parameter can override
238+
bootconfig parameters (this depends on how the subsystem handles parameters
239+
but in general, earlier parameter will be overwritten by later one.)::
240+
241+
[bootconfig params][cmdline params] -- [bootconfig init params][cmdline init params]
242+
243+
Here is an example of the bootconfig file for kernel/init parameters.::
244+
245+
kernel {
246+
root = 01234567-89ab-cdef-0123-456789abcd
247+
}
248+
init {
249+
splash
250+
}
251+
252+
This will be copied into the kernel cmdline string as the following::
253+
254+
root="01234567-89ab-cdef-0123-456789abcd" -- splash
255+
256+
If user gives some other command line like,::
257+
258+
ro bootconfig -- quiet
259+
260+
The final kernel cmdline will be the following::
261+
262+
root="01234567-89ab-cdef-0123-456789abcd" ro bootconfig -- splash quiet
263+
198264

199265
Config File Limitation
200266
======================

Documentation/trace/boottime-trace.rst

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,69 @@ Note that kprobe and synthetic event definitions can be written under
125125
instance node, but those are also visible from other instances. So please
126126
take care for event name conflict.
127127

128+
Ftrace Histogram Options
129+
------------------------
130+
131+
Since it is too long to write a histogram action as a string for per-event
132+
action option, there are tree-style options under per-event 'hist' subkey
133+
for the histogram actions. For the detail of the each parameter,
134+
please read the event histogram document (Documentation/trace/histogram.rst)
135+
136+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]keys = KEY1[, KEY2[...]]
137+
Set histogram key parameters. (Mandatory)
138+
The 'N' is a digit string for the multiple histogram. You can omit it
139+
if there is one histogram on the event.
140+
141+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]values = VAL1[, VAL2[...]]
142+
Set histogram value parameters.
143+
144+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]sort = SORT1[, SORT2[...]]
145+
Set histogram sort parameter options.
146+
147+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]size = NR_ENTRIES
148+
Set histogram size (number of entries).
149+
150+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]name = NAME
151+
Set histogram name.
152+
153+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]var.VARIABLE = EXPR
154+
Define a new VARIABLE by EXPR expression.
155+
156+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<pause|continue|clear>
157+
Set histogram control parameter. You can set one of them.
158+
159+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]event = GROUP.EVENT
160+
Set histogram 'onmatch' handler matching event parameter.
161+
The 'M' is a digit string for the multiple 'onmatch' handler. You can omit it
162+
if there is one 'onmatch' handler on this histogram.
163+
164+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmatch.[M.]trace = EVENT[, ARG1[...]]
165+
Set histogram 'trace' action for 'onmatch'.
166+
EVENT must be a synthetic event name, and ARG1... are parameters
167+
for that event. Mandatory if 'onmatch.event' option is set.
168+
169+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onmax.[M.]var = VAR
170+
Set histogram 'onmax' handler variable parameter.
171+
172+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]onchange.[M.]var = VAR
173+
Set histogram 'onchange' handler variable parameter.
174+
175+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]save = ARG1[, ARG2[...]]
176+
Set histogram 'save' action parameters for 'onmax' or 'onchange' handler.
177+
This option or below 'snapshot' option is mandatory if 'onmax.var' or
178+
'onchange.var' option is set.
179+
180+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.[N.]<onmax|onchange>.[M.]snapshot
181+
Set histogram 'snapshot' action for 'onmax' or 'onchange' handler.
182+
This option or above 'save' option is mandatory if 'onmax.var' or
183+
'onchange.var' option is set.
184+
185+
ftrace.[instance.INSTANCE.]event.GROUP.EVENT.hist.filter = FILTER_EXPR
186+
Set histogram filter expression. You don't need 'if' in the FILTER_EXPR.
187+
188+
Note that this 'hist' option can conflict with the per-event 'actions'
189+
option if the 'actions' option has a histogram action.
190+
128191

129192
When to Start
130193
=============
@@ -159,13 +222,23 @@ below::
159222
}
160223
synthetic.initcall_latency {
161224
fields = "unsigned long func", "u64 lat"
162-
actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
225+
hist {
226+
keys = func.sym, lat
227+
values = lat
228+
sort = lat
229+
}
163230
}
164-
initcall.initcall_start {
165-
actions = "hist:keys=func:ts0=common_timestamp.usecs"
231+
initcall.initcall_start.hist {
232+
keys = func
233+
var.ts0 = common_timestamp.usecs
166234
}
167-
initcall.initcall_finish {
168-
actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)"
235+
initcall.initcall_finish.hist {
236+
keys = func
237+
var.lat = common_timestamp.usecs - $ts0
238+
onmatch {
239+
event = initcall.initcall_start
240+
trace = initcall_latency, func, $lat
241+
}
169242
}
170243
}
171244

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7238,6 +7238,7 @@ S: Maintained
72387238
F: Documentation/admin-guide/bootconfig.rst
72397239
F: fs/proc/bootconfig.c
72407240
F: include/linux/bootconfig.h
7241+
F: lib/bootconfig-data.S
72417242
F: lib/bootconfig.c
72427243
F: tools/bootconfig/*
72437244
F: tools/bootconfig/scripts/*

include/linux/bootconfig.h

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
* Author: Masami Hiramatsu <mhiramat@kernel.org>
88
*/
99

10+
#ifdef __KERNEL__
1011
#include <linux/kernel.h>
1112
#include <linux/types.h>
13+
#else /* !__KERNEL__ */
14+
/*
15+
* NOTE: This is only for tools/bootconfig, because tools/bootconfig will
16+
* run the parser sanity test.
17+
* This does NOT mean linux/bootconfig.h is available in the user space.
18+
* However, if you change this file, please make sure the tools/bootconfig
19+
* has no issue on building and running.
20+
*/
21+
#endif
1222

1323
#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
1424
#define BOOTCONFIG_MAGIC_LEN 12
@@ -25,10 +35,10 @@
2535
* The checksum will be used with the BOOTCONFIG_MAGIC and the size for
2636
* embedding the bootconfig in the initrd image.
2737
*/
28-
static inline __init u32 xbc_calc_checksum(void *data, u32 size)
38+
static inline __init uint32_t xbc_calc_checksum(void *data, uint32_t size)
2939
{
3040
unsigned char *p = data;
31-
u32 ret = 0;
41+
uint32_t ret = 0;
3242

3343
while (size--)
3444
ret += *p++;
@@ -38,18 +48,18 @@ static inline __init u32 xbc_calc_checksum(void *data, u32 size)
3848

3949
/* XBC tree node */
4050
struct xbc_node {
41-
u16 next;
42-
u16 child;
43-
u16 parent;
44-
u16 data;
51+
uint16_t next;
52+
uint16_t child;
53+
uint16_t parent;
54+
uint16_t data;
4555
} __attribute__ ((__packed__));
4656

4757
#define XBC_KEY 0
4858
#define XBC_VALUE (1 << 15)
4959
/* Maximum size of boot config is 32KB - 1 */
5060
#define XBC_DATA_MAX (XBC_VALUE - 1)
5161

52-
#define XBC_NODE_MAX 1024
62+
#define XBC_NODE_MAX 8192
5363
#define XBC_KEYLEN_MAX 256
5464
#define XBC_DEPTH_MAX 16
5565

@@ -110,7 +120,7 @@ static inline __init bool xbc_node_is_leaf(struct xbc_node *node)
110120
}
111121

112122
/* Tree-based key-value access APIs */
113-
struct xbc_node * __init xbc_node_find_child(struct xbc_node *parent,
123+
struct xbc_node * __init xbc_node_find_subkey(struct xbc_node *parent,
114124
const char *key);
115125

116126
const char * __init xbc_node_find_value(struct xbc_node *parent,
@@ -148,7 +158,7 @@ xbc_find_value(const char *key, struct xbc_node **vnode)
148158
*/
149159
static inline struct xbc_node * __init xbc_find_node(const char *key)
150160
{
151-
return xbc_node_find_child(NULL, key);
161+
return xbc_node_find_subkey(NULL, key);
152162
}
153163

154164
/**
@@ -271,13 +281,27 @@ static inline int __init xbc_node_compose_key(struct xbc_node *node,
271281
}
272282

273283
/* XBC node initializer */
274-
int __init xbc_init(char *buf, const char **emsg, int *epos);
284+
int __init xbc_init(const char *buf, size_t size, const char **emsg, int *epos);
275285

286+
/* XBC node and size information */
287+
int __init xbc_get_info(int *node_size, size_t *data_size);
276288

277289
/* XBC cleanup data structures */
278-
void __init xbc_destroy_all(void);
290+
void __init _xbc_exit(bool early);
279291

280-
/* Debug dump functions */
281-
void __init xbc_debug_dump(void);
292+
static inline void xbc_exit(void)
293+
{
294+
_xbc_exit(false);
295+
}
296+
297+
/* XBC embedded bootconfig data in kernel */
298+
#ifdef CONFIG_BOOT_CONFIG_EMBED
299+
const char * __init xbc_get_embedded_bootconfig(size_t *size);
300+
#else
301+
static inline const char *xbc_get_embedded_bootconfig(size_t *size)
302+
{
303+
return NULL;
304+
}
305+
#endif
282306

283307
#endif

init/Kconfig

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ endif
13231323

13241324
config BOOT_CONFIG
13251325
bool "Boot config support"
1326-
select BLK_DEV_INITRD
1326+
select BLK_DEV_INITRD if !BOOT_CONFIG_EMBED
13271327
help
13281328
Extra boot config allows system admin to pass a config file as
13291329
complemental extension of kernel cmdline when booting.
@@ -1333,6 +1333,38 @@ config BOOT_CONFIG
13331333

13341334
If unsure, say Y.
13351335

1336+
config BOOT_CONFIG_FORCE
1337+
bool "Force unconditional bootconfig processing"
1338+
depends on BOOT_CONFIG
1339+
default y if BOOT_CONFIG_EMBED
1340+
help
1341+
With this Kconfig option set, BOOT_CONFIG processing is carried
1342+
out even when the "bootconfig" kernel-boot parameter is omitted.
1343+
In fact, with this Kconfig option set, there is no way to
1344+
make the kernel ignore the BOOT_CONFIG-supplied kernel-boot
1345+
parameters.
1346+
1347+
If unsure, say N.
1348+
1349+
config BOOT_CONFIG_EMBED
1350+
bool "Embed bootconfig file in the kernel"
1351+
depends on BOOT_CONFIG
1352+
help
1353+
Embed a bootconfig file given by BOOT_CONFIG_EMBED_FILE in the
1354+
kernel. Usually, the bootconfig file is loaded with the initrd
1355+
image. But if the system doesn't support initrd, this option will
1356+
help you by embedding a bootconfig file while building the kernel.
1357+
1358+
If unsure, say N.
1359+
1360+
config BOOT_CONFIG_EMBED_FILE
1361+
string "Embedded bootconfig file path"
1362+
depends on BOOT_CONFIG_EMBED
1363+
help
1364+
Specify a bootconfig file which will be embedded to the kernel.
1365+
This bootconfig will be used if there is no initrd or no other
1366+
bootconfig in the initrd.
1367+
13361368
choice
13371369
prompt "Compiler optimization level"
13381370
default CC_OPTIMIZE_FOR_PERFORMANCE

0 commit comments

Comments
 (0)