Skip to content

Commit ddf9c6d

Browse files
author
Paolo Abeni
committed
Merge branch 'netconsole-add-support-for-userdata-release'
Breno Leitao says: ==================== netconsole: Add support for userdata release I am submitting a series of patches that introduce a new feature for the netconsole subsystem, specifically the addition of the 'release' field to the sysdata structure. This feature allows the kernel release/version to be appended to the userdata dictionary in every message sent, enhancing the information available for debugging and monitoring purposes. This complements the already supported release prepend feature, which was added some time ago. The release prepend appends the release information at the message header, which is not ideal for two reasons: 1) It is difficult to determine if a message includes this information, making it hard and resource-intensive to parse. 2) When a message is fragmented, the release information is appended to every message fragment, consuming valuable space in the packet. The "release prepend" feature was created before the concept of userdata and sysdata. Now that this format has proven successful, we are implementing the release feature as part of this enhanced structure. This patch series aims to improve the netconsole subsystem by providing a more efficient and user-friendly way to include kernel release information in messages. I believe these changes will significantly aid in system analysis and troubleshooting. Suggested-by: Manu Bretelle <[email protected]> Signed-off-by: Breno Leitao <[email protected]> ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 08d0185 + 56ad890 commit ddf9c6d

File tree

3 files changed

+133
-7
lines changed

3 files changed

+133
-7
lines changed

Documentation/networking/netconsole.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,31 @@ Example::
272272
In this example, the message was generated while "echo" was the current
273273
scheduled process.
274274

275+
Kernel release auto population in userdata
276+
------------------------------------------
277+
278+
Within the netconsole configfs hierarchy, there is a file named `release_enabled`
279+
located in the `userdata` directory. This file controls the kernel release
280+
(version) auto-population feature, which appends the kernel release information
281+
to userdata dictionary in every message sent.
282+
283+
To enable the release auto-population::
284+
285+
echo 1 > /sys/kernel/config/netconsole/target1/userdata/release_enabled
286+
287+
Example::
288+
289+
echo "This is a message" > /dev/kmsg
290+
12,607,22085407756,-;This is a message
291+
release=6.14.0-rc6-01219-g3c027fbd941d
292+
293+
.. note::
294+
295+
This feature provides the same data as the "release prepend" feature.
296+
However, in this case, the release information is appended to the userdata
297+
dictionary rather than being included in the message header.
298+
299+
275300
CPU number auto population in userdata
276301
--------------------------------------
277302

drivers/net/netconsole.c

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ enum sysdata_feature {
106106
SYSDATA_CPU_NR = BIT(0),
107107
/* Populate the task name (as in current->comm) in sysdata */
108108
SYSDATA_TASKNAME = BIT(1),
109+
/* Kernel release/version as part of sysdata */
110+
SYSDATA_RELEASE = BIT(2),
109111
};
110112

111113
/**
@@ -440,6 +442,19 @@ static ssize_t sysdata_taskname_enabled_show(struct config_item *item,
440442
return sysfs_emit(buf, "%d\n", taskname_enabled);
441443
}
442444

445+
static ssize_t sysdata_release_enabled_show(struct config_item *item,
446+
char *buf)
447+
{
448+
struct netconsole_target *nt = to_target(item->ci_parent);
449+
bool release_enabled;
450+
451+
mutex_lock(&dynamic_netconsole_mutex);
452+
release_enabled = !!(nt->sysdata_fields & SYSDATA_TASKNAME);
453+
mutex_unlock(&dynamic_netconsole_mutex);
454+
455+
return sysfs_emit(buf, "%d\n", release_enabled);
456+
}
457+
443458
/*
444459
* This one is special -- targets created through the configfs interface
445460
* are not enabled (and the corresponding netpoll activated) by default.
@@ -719,6 +734,8 @@ static size_t count_extradata_entries(struct netconsole_target *nt)
719734
entries += 1;
720735
if (nt->sysdata_fields & SYSDATA_TASKNAME)
721736
entries += 1;
737+
if (nt->sysdata_fields & SYSDATA_RELEASE)
738+
entries += 1;
722739

723740
return entries;
724741
}
@@ -855,6 +872,40 @@ static void disable_sysdata_feature(struct netconsole_target *nt,
855872
nt->extradata_complete[nt->userdata_length] = 0;
856873
}
857874

875+
static ssize_t sysdata_release_enabled_store(struct config_item *item,
876+
const char *buf, size_t count)
877+
{
878+
struct netconsole_target *nt = to_target(item->ci_parent);
879+
bool release_enabled, curr;
880+
ssize_t ret;
881+
882+
ret = kstrtobool(buf, &release_enabled);
883+
if (ret)
884+
return ret;
885+
886+
mutex_lock(&dynamic_netconsole_mutex);
887+
curr = !!(nt->sysdata_fields & SYSDATA_RELEASE);
888+
if (release_enabled == curr)
889+
goto unlock_ok;
890+
891+
if (release_enabled &&
892+
count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) {
893+
ret = -ENOSPC;
894+
goto unlock;
895+
}
896+
897+
if (release_enabled)
898+
nt->sysdata_fields |= SYSDATA_RELEASE;
899+
else
900+
disable_sysdata_feature(nt, SYSDATA_RELEASE);
901+
902+
unlock_ok:
903+
ret = strnlen(buf, count);
904+
unlock:
905+
mutex_unlock(&dynamic_netconsole_mutex);
906+
return ret;
907+
}
908+
858909
static ssize_t sysdata_taskname_enabled_store(struct config_item *item,
859910
const char *buf, size_t count)
860911
{
@@ -935,6 +986,7 @@ static ssize_t sysdata_cpu_nr_enabled_store(struct config_item *item,
935986
CONFIGFS_ATTR(userdatum_, value);
936987
CONFIGFS_ATTR(sysdata_, cpu_nr_enabled);
937988
CONFIGFS_ATTR(sysdata_, taskname_enabled);
989+
CONFIGFS_ATTR(sysdata_, release_enabled);
938990

939991
static struct configfs_attribute *userdatum_attrs[] = {
940992
&userdatum_attr_value,
@@ -996,6 +1048,7 @@ static void userdatum_drop(struct config_group *group, struct config_item *item)
9961048
static struct configfs_attribute *userdata_attrs[] = {
9971049
&sysdata_attr_cpu_nr_enabled,
9981050
&sysdata_attr_taskname_enabled,
1051+
&sysdata_attr_release_enabled,
9991052
NULL,
10001053
};
10011054

@@ -1171,20 +1224,28 @@ static void populate_configfs_item(struct netconsole_target *nt,
11711224
init_target_config_group(nt, target_name);
11721225
}
11731226

1174-
static int append_cpu_nr(struct netconsole_target *nt, int offset)
1227+
static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset)
11751228
{
11761229
/* Append cpu=%d at extradata_complete after userdata str */
11771230
return scnprintf(&nt->extradata_complete[offset],
11781231
MAX_EXTRADATA_ENTRY_LEN, " cpu=%u\n",
11791232
raw_smp_processor_id());
11801233
}
11811234

1182-
static int append_taskname(struct netconsole_target *nt, int offset)
1235+
static int sysdata_append_taskname(struct netconsole_target *nt, int offset)
11831236
{
11841237
return scnprintf(&nt->extradata_complete[offset],
11851238
MAX_EXTRADATA_ENTRY_LEN, " taskname=%s\n",
11861239
current->comm);
11871240
}
1241+
1242+
static int sysdata_append_release(struct netconsole_target *nt, int offset)
1243+
{
1244+
return scnprintf(&nt->extradata_complete[offset],
1245+
MAX_EXTRADATA_ENTRY_LEN, " release=%s\n",
1246+
init_utsname()->release);
1247+
}
1248+
11881249
/*
11891250
* prepare_extradata - append sysdata at extradata_complete in runtime
11901251
* @nt: target to send message to
@@ -1203,9 +1264,11 @@ static int prepare_extradata(struct netconsole_target *nt)
12031264
goto out;
12041265

12051266
if (nt->sysdata_fields & SYSDATA_CPU_NR)
1206-
extradata_len += append_cpu_nr(nt, extradata_len);
1267+
extradata_len += sysdata_append_cpu_nr(nt, extradata_len);
12071268
if (nt->sysdata_fields & SYSDATA_TASKNAME)
1208-
extradata_len += append_taskname(nt, extradata_len);
1269+
extradata_len += sysdata_append_taskname(nt, extradata_len);
1270+
if (nt->sysdata_fields & SYSDATA_RELEASE)
1271+
extradata_len += sysdata_append_release(nt, extradata_len);
12091272

12101273
WARN_ON_ONCE(extradata_len >
12111274
MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS);

tools/testing/selftests/drivers/net/netcons_sysdata.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function set_taskname() {
4242
echo 1 > "${NETCONS_PATH}/userdata/taskname_enabled"
4343
}
4444

45+
# Enable the release to be appended to sysdata
46+
function set_release() {
47+
if [[ ! -f "${NETCONS_PATH}/userdata/release_enabled" ]]
48+
then
49+
echo "Not able to enable release sysdata append. Configfs not available in ${NETCONS_PATH}/userdata/release_enabled" >&2
50+
exit "${ksft_skip}"
51+
fi
52+
53+
echo 1 > "${NETCONS_PATH}/userdata/release_enabled"
54+
}
55+
4556
# Disable the sysdata cpu_nr feature
4657
function unset_cpu_nr() {
4758
echo 0 > "${NETCONS_PATH}/userdata/cpu_nr_enabled"
@@ -52,6 +63,10 @@ function unset_taskname() {
5263
echo 0 > "${NETCONS_PATH}/userdata/taskname_enabled"
5364
}
5465

66+
function unset_release() {
67+
echo 0 > "${NETCONS_PATH}/userdata/release_enabled"
68+
}
69+
5570
# Test if MSG contains sysdata
5671
function validate_sysdata() {
5772
# OUTPUT_FILE will contain something like:
@@ -93,6 +108,21 @@ function validate_sysdata() {
93108
pkill_socat
94109
}
95110

111+
function validate_release() {
112+
RELEASE=$(uname -r)
113+
114+
if [ ! -f "$OUTPUT_FILE" ]; then
115+
echo "FAIL: File was not generated." >&2
116+
exit "${ksft_fail}"
117+
fi
118+
119+
if ! grep -q "release=${RELEASE}" "${OUTPUT_FILE}"; then
120+
echo "FAIL: 'release=${RELEASE}' not found in ${OUTPUT_FILE}" >&2
121+
cat "${OUTPUT_FILE}" >&2
122+
exit "${ksft_fail}"
123+
fi
124+
}
125+
96126
# Test if MSG content exists in OUTPUT_FILE but no `cpu=` and `taskname=`
97127
# strings
98128
function validate_no_sysdata() {
@@ -119,6 +149,12 @@ function validate_no_sysdata() {
119149
exit "${ksft_fail}"
120150
fi
121151

152+
if grep -q "release=" "${OUTPUT_FILE}"; then
153+
echo "FAIL: 'release= found in ${OUTPUT_FILE}" >&2
154+
cat "${OUTPUT_FILE}" >&2
155+
exit "${ksft_fail}"
156+
fi
157+
122158
rm "${OUTPUT_FILE}"
123159
}
124160

@@ -169,9 +205,11 @@ MSG="Test #1 from CPU${CPU}"
169205
set_cpu_nr
170206
# Enable taskname to be appended to sysdata
171207
set_taskname
208+
set_release
172209
runtest
173210
# Make sure the message was received in the dst part
174211
# and exit
212+
validate_release
175213
validate_sysdata
176214

177215
#====================================================
@@ -184,19 +222,19 @@ OUTPUT_FILE="/tmp/${TARGET}_2"
184222
MSG="Test #2 from CPU${CPU}"
185223
set_user_data
186224
runtest
225+
validate_release
187226
validate_sysdata
188227

189228
# ===================================================
190229
# TEST #3
191-
# Unset cpu_nr, so, no CPU should be appended.
192-
# userdata is still set
230+
# Unset all sysdata, fail if any userdata is set
193231
# ===================================================
194232
CPU=$((RANDOM % $(nproc)))
195233
OUTPUT_FILE="/tmp/${TARGET}_3"
196234
MSG="Test #3 from CPU${CPU}"
197-
# Enable the auto population of cpu_nr
198235
unset_cpu_nr
199236
unset_taskname
237+
unset_release
200238
runtest
201239
# At this time, cpu= shouldn't be present in the msg
202240
validate_no_sysdata

0 commit comments

Comments
 (0)