Skip to content

Commit db594c2

Browse files
committed
Add support to rh_waived cmdline boot parameter
JIRA: https://issues.redhat.com/browse/RHEL-122981 Conflicts: Minor context difference due to RHEL-only commit c7db2ac ("kernel: Add redhat code") This patch is a backport of the following RHEL-only commit: commit 13d53ad70d726bfd8ffcea9c4891c5eaa6254dfb Author: Ricardo Robaina <rrobaina@redhat.com> Date: Wed May 22 10:20:47 2024 -0300 Add support to rh_waived cmdline boot parameter JIRA: https://issues.redhat.com/browse/RHEL-26170 Upstream Status: RHEL only This commit adds support to a standard mechanism to hide waived features behind a common cmdline parameter in RHEL, called rh_waived. Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
1 parent 36001ff commit db594c2

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,6 +5734,17 @@
57345734
rhash_entries= [KNL,NET]
57355735
Set number of hash buckets for route cache
57365736

5737+
rh_waived=
5738+
Enable waived features in RHEL.
5739+
5740+
Waived features are disabled by default in RHEL, this parameter
5741+
provides support to enable such features, as needed.
5742+
5743+
Format: <feat-1>,<feat-2>...<feat-n>
5744+
5745+
Use 'rh_waived' to enable all waived features listed at
5746+
Documentation/admin-guide/rh-waived-features.rst
5747+
57375748
ring3mwait=disable
57385749
[KNL] Disable ring 3 MONITOR/MWAIT feature on supported
57395750
CPUs.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _rh_waived_features:
2+
3+
=======================
4+
Red Hat Waived Features
5+
=======================
6+
7+
Red Hat waived features are features considered unmaintained, insecure, rudimentary, or
8+
deprecated and are shipped in RHEL only for customer convenience. These features are disabled
9+
by default but can be enabled on demand via the ``rh_waived`` kernel boot parameter. To allow
10+
a set of waived features, append ``rh_waived=<feature name>,...,<feature name>`` to the kernel
11+
cmdline. Appending only ``rh_waived`` (with no arguments) will enable all waived features
12+
listed below.
13+
14+
The waived features listed in the next session follow the pattern below:
15+
16+
- feature name
17+
feature description
18+
19+
List of Red Hat Waived Features
20+
===============================
21+

include/linux/rh_waived.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* include/linux/rh_waived.h
4+
*
5+
* rh_waived cmdline parameter interface.
6+
*
7+
* Copyright (C) 2024, Red Hat, Inc. Ricardo Robaina <rrobaina@redhat.com>
8+
*/
9+
#ifndef _RH_WAIVED_H
10+
#define _RH_WAIVED_H
11+
12+
enum rh_waived_feat {
13+
/* RH_WAIVED_FEAT_ITEMS must always be the last item in the enum */
14+
RH_WAIVED_FEAT_ITEMS,
15+
};
16+
17+
bool is_rh_waived(enum rh_waived_feat feat);
18+
19+
#endif /* _RH_WAIVED_H */

kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ obj-y = fork.o exec_domain.o panic.o \
1212
notifier.o ksysfs.o cred.o reboot.o \
1313
async.o range.o smpboot.o ucount.o regset.o ksyms_common.o
1414

15-
obj-$(CONFIG_RHEL_DIFFERENCES) += rh_messages.o rh_flags.o rh_shadowman.o
15+
obj-$(CONFIG_RHEL_DIFFERENCES) += rh_messages.o rh_flags.o rh_waived.o rh_shadowman.o
1616
obj-$(CONFIG_USERMODE_DRIVER) += usermode_driver.o
1717
obj-$(CONFIG_MULTIUSER) += groups.o
1818

kernel/rh_waived.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* kernel/rh_waived.c
4+
*
5+
* rh_waived cmdline parameter support.
6+
*
7+
* Copyright (C) 2024, Red Hat, Inc. Ricardo Robaina <rrobaina@redhat.com>
8+
*/
9+
#include <linux/types.h>
10+
#include <linux/init.h>
11+
#include <linux/printk.h>
12+
#include <linux/string.h>
13+
#include <linux/panic.h>
14+
#include <linux/module.h>
15+
#include <linux/kernel.h>
16+
#include <linux/rh_flags.h>
17+
#include <linux/rh_waived.h>
18+
19+
/*
20+
* RH_INSERT_WAIVED_FEAT
21+
* This macro is intended to be used to insert items into the
22+
* rh_waived_feat_list array. It expects to get an item from
23+
* enum rh_waived_feat as its first argument, and a string
24+
* holding the feature name as its second argument.
25+
*
26+
* The feature name is also utilized as the token for the
27+
* boot parameter parser.
28+
*
29+
* Example usage:
30+
* struct rh_waived_feat_item foo[RH_WAIVED_FEAT_ITEMS] = {
31+
* RH_INSERT_WAIVED_FEAT(FOO_FEAT, "foo_feat_short_str"),
32+
* };
33+
*/
34+
#define RH_INSERT_WAIVED_FEAT(enum_item, name) \
35+
[(enum_item)] = {.feat_name = (name), .enabled = 0,}
36+
37+
/* Indicates if the rh_flag 'rh_waived' should be added. */
38+
bool __initdata add_rh_flag = false;
39+
40+
struct rh_waived_feat_item {
41+
char *feat_name;
42+
unsigned int enabled;
43+
};
44+
45+
/* Always use the marco RH_INSERT_WAIVED_FEAT to insert items to this array. */
46+
struct rh_waived_feat_item rh_waived_feat_list[RH_WAIVED_FEAT_ITEMS] = {
47+
};
48+
49+
/*
50+
* is_rh_waived() - Checks if a given waived feature has been enabled.
51+
*
52+
* @feat: waived feature.
53+
*/
54+
__inline__ bool is_rh_waived(enum rh_waived_feat feat)
55+
{
56+
return !!rh_waived_feat_list[feat].enabled;
57+
}
58+
EXPORT_SYMBOL(is_rh_waived);
59+
60+
static int __init rh_waived_setup(char *s)
61+
{
62+
int i;
63+
char *token;
64+
65+
pr_info(KERN_CONT "rh_waived: ");
66+
67+
if (!s) {
68+
for (i = 0; i < RH_WAIVED_FEAT_ITEMS; i++) {
69+
rh_waived_feat_list[i].enabled = 1;
70+
pr_info(KERN_CONT "%s%s", rh_waived_feat_list[i].feat_name,
71+
i < RH_WAIVED_FEAT_ITEMS - 1 ? " " : "\n");
72+
}
73+
}
74+
75+
while ((token = strsep(&s, ",")) != NULL) {
76+
for (i = 0; i < RH_WAIVED_FEAT_ITEMS; i++) {
77+
if (!strcmp(token, rh_waived_feat_list[i].feat_name)) {
78+
rh_waived_feat_list[i].enabled = 1;
79+
pr_info(KERN_CONT "%s%s", rh_waived_feat_list[i].feat_name,
80+
i < RH_WAIVED_FEAT_ITEMS - 1 ? " " : "\n");
81+
}
82+
}
83+
}
84+
85+
add_rh_flag = true;
86+
87+
return 0;
88+
}
89+
early_param("rh_waived", rh_waived_setup);
90+
91+
/*
92+
* rh_flags is initialized at subsys_initcall, calling rh_add_flag()
93+
* from rh_waived_setup() would result in a can't boot situation.
94+
* Deffering the inclusion 'rh_waived' rh_flag to late_initcall to
95+
* avoid this issue.
96+
*/
97+
static int __init __add_rh_flag(void)
98+
{
99+
if (add_rh_flag)
100+
rh_add_flag("rh_waived");
101+
102+
return 0;
103+
}
104+
late_initcall(__add_rh_flag);

0 commit comments

Comments
 (0)