Skip to content

Commit c1db104

Browse files
committed
rh_features: move rh_features entry to sys/kernel
JIRA: https://issues.redhat.com/browse/RHEL-122981 This patch is a backport of the following RHEL-only commit: commit f8a16e956bfc72efd4ed56d19821a1de812cb8ad Author: Ricardo Robaina <rrobaina@redhat.com> Date: Fri May 10 20:31:21 2024 -0300 rh_features: move rh_features entry to sys/kernel JIRA: https://issues.redhat.com/browse/RHEL-32987 Conflicts: - register_sysctl_table() is currently deprecated, replacing it with register_sysctl_init() This patch is a backport of the following upstream commit: commit b42078ac845a3bfb5a6bfc621515e5a7acba510a Author: Hangbin Liu <haliu@redhat.com> Date: Wed Nov 13 13:54:23 2019 -0500 [kernel] rh_features: move rh_features entry to sys/kernel Message-id: <20191113135423.25652-1-haliu@redhat.com> Patchwork-id: 286074 O-Subject: [RHEL8.2 net PATCHv3] rh_features: move rh_features entry to sys/kernel Bugzilla: 1660583 RH-Acked-by: Ivan Vecera <ivecera@redhat.com> RH-Acked-by: Jiri Benc <jbenc@redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1660583 Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=24659187 Upstream Status: RHEL only Test: tested with sos-3.7-7.el8_1 and we can save rh_features correctly In the past we put the rh_feature info to /proc/driver/rh_feature. Prarit ask to put this to a more suitable place. And the file needs to be picked up by sosreport. /proc/sys/kernel may not be a very good place. But since we already has the 'tainted' file (as well as some others, e.g. osrelease or version) there, we can put it here before finding a more suitable place. v2: Move rh_features_show in to ifdef CONFIG_SYSCTL. Also as Jiri suggested: a) we need to check the register_sysctl_table return value. b) Change list_for_each_entry_rcu to list_for_each_entry_lockless in rh_print_used_features, which is more correct from the documentation point of view. v3: As Jiri remind, we may get overflow with snprintf, use scnprintf instead. Signed-off-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Bruno Meneguele <bmeneg@redhat.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
1 parent e82b3a7 commit c1db104

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

kernel/rh_features.c

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/rh_features.h>
88

99
#define RH_FEATURE_NAME_LEN 32
10+
#define MAX_RH_FEATURES 128
11+
#define MAX_RH_FEATURE_NAME_LEN (MAX_RH_FEATURES * RH_FEATURE_NAME_LEN)
1012

1113
struct rh_feature {
1214
struct list_head list;
@@ -58,38 +60,56 @@ void rh_print_used_features(void)
5860
if (list_empty(&rh_feature_list))
5961
return;
6062
printk(KERN_DEFAULT "Features:");
61-
list_for_each_entry_rcu(feat, &rh_feature_list, list) {
63+
list_for_each_entry_lockless(feat, &rh_feature_list, list) {
6264
pr_cont(" %s", feat->name);
6365
}
6466
pr_cont("\n");
6567
}
6668
EXPORT_SYMBOL(rh_print_used_features);
6769

68-
static int rh_features_show(struct seq_file *seq, void *unused)
70+
#ifdef CONFIG_SYSCTL
71+
static int rh_features_show(struct ctl_table *ctl, int write,
72+
void __user *buffer, size_t *lenp,
73+
loff_t *ppos)
6974
{
75+
struct ctl_table tbl = { .maxlen = MAX_RH_FEATURE_NAME_LEN, };
7076
struct rh_feature *feat;
71-
bool space = false;
77+
size_t offs = 0;
78+
int ret;
79+
80+
tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
81+
if (!tbl.data)
82+
return -ENOMEM;
7283

73-
if (list_empty(&rh_feature_list))
74-
return 0;
7584
rcu_read_lock();
7685
list_for_each_entry_rcu(feat, &rh_feature_list, list) {
77-
if (space)
78-
seq_puts(seq, " ");
79-
seq_puts(seq, feat->name);
80-
space = true;
86+
offs += scnprintf(tbl.data + offs, tbl.maxlen - offs, "%s%s",
87+
offs == 0 ? "" : " ", feat->name);
8188
}
8289
rcu_read_unlock();
83-
seq_puts(seq, "\n");
84-
return 0;
90+
91+
ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
92+
kfree(tbl.data);
93+
return ret;
8594
}
8695

96+
static struct ctl_table rh_features_table[] = {
97+
{
98+
.procname = "rh_features",
99+
.data = &rh_feature_list,
100+
.maxlen = MAX_RH_FEATURE_NAME_LEN,
101+
.mode = 0444,
102+
.proc_handler = rh_features_show,
103+
},
104+
{ }
105+
};
106+
#endif
107+
87108
static __init int rh_features_init(void)
88109
{
89-
struct proc_dir_entry *ent;
90-
91-
ent = proc_create_single("driver/rh_features", 0, NULL, rh_features_show);
92-
WARN_ON(!ent);
110+
#ifdef CONFIG_SYSCTL
111+
register_sysctl_init("kernel", rh_features_table);
112+
#endif
93113
return 0;
94114
}
95115
subsys_initcall(rh_features_init);

0 commit comments

Comments
 (0)