Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <chantr4@gmail.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
====================

Link: https://patch.msgid.link/20250314-netcons_release-v1-0-07979c4b86af@debian.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+133 -7
+25
Documentation/networking/netconsole.rst
··· 272 272 In this example, the message was generated while "echo" was the current 273 273 scheduled process. 274 274 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 + 275 300 CPU number auto population in userdata 276 301 -------------------------------------- 277 302
+67 -4
drivers/net/netconsole.c
··· 106 106 SYSDATA_CPU_NR = BIT(0), 107 107 /* Populate the task name (as in current->comm) in sysdata */ 108 108 SYSDATA_TASKNAME = BIT(1), 109 + /* Kernel release/version as part of sysdata */ 110 + SYSDATA_RELEASE = BIT(2), 109 111 }; 110 112 111 113 /** ··· 442 440 return sysfs_emit(buf, "%d\n", taskname_enabled); 443 441 } 444 442 443 + static ssize_t sysdata_release_enabled_show(struct config_item *item, 444 + char *buf) 445 + { 446 + struct netconsole_target *nt = to_target(item->ci_parent); 447 + bool release_enabled; 448 + 449 + mutex_lock(&dynamic_netconsole_mutex); 450 + release_enabled = !!(nt->sysdata_fields & SYSDATA_TASKNAME); 451 + mutex_unlock(&dynamic_netconsole_mutex); 452 + 453 + return sysfs_emit(buf, "%d\n", release_enabled); 454 + } 455 + 445 456 /* 446 457 * This one is special -- targets created through the configfs interface 447 458 * are not enabled (and the corresponding netpoll activated) by default. ··· 734 719 entries += 1; 735 720 if (nt->sysdata_fields & SYSDATA_TASKNAME) 736 721 entries += 1; 722 + if (nt->sysdata_fields & SYSDATA_RELEASE) 723 + entries += 1; 737 724 738 725 return entries; 739 726 } ··· 872 855 nt->extradata_complete[nt->userdata_length] = 0; 873 856 } 874 857 858 + static ssize_t sysdata_release_enabled_store(struct config_item *item, 859 + const char *buf, size_t count) 860 + { 861 + struct netconsole_target *nt = to_target(item->ci_parent); 862 + bool release_enabled, curr; 863 + ssize_t ret; 864 + 865 + ret = kstrtobool(buf, &release_enabled); 866 + if (ret) 867 + return ret; 868 + 869 + mutex_lock(&dynamic_netconsole_mutex); 870 + curr = !!(nt->sysdata_fields & SYSDATA_RELEASE); 871 + if (release_enabled == curr) 872 + goto unlock_ok; 873 + 874 + if (release_enabled && 875 + count_extradata_entries(nt) >= MAX_EXTRADATA_ITEMS) { 876 + ret = -ENOSPC; 877 + goto unlock; 878 + } 879 + 880 + if (release_enabled) 881 + nt->sysdata_fields |= SYSDATA_RELEASE; 882 + else 883 + disable_sysdata_feature(nt, SYSDATA_RELEASE); 884 + 885 + unlock_ok: 886 + ret = strnlen(buf, count); 887 + unlock: 888 + mutex_unlock(&dynamic_netconsole_mutex); 889 + return ret; 890 + } 891 + 875 892 static ssize_t sysdata_taskname_enabled_store(struct config_item *item, 876 893 const char *buf, size_t count) 877 894 { ··· 986 935 CONFIGFS_ATTR(userdatum_, value); 987 936 CONFIGFS_ATTR(sysdata_, cpu_nr_enabled); 988 937 CONFIGFS_ATTR(sysdata_, taskname_enabled); 938 + CONFIGFS_ATTR(sysdata_, release_enabled); 989 939 990 940 static struct configfs_attribute *userdatum_attrs[] = { 991 941 &userdatum_attr_value, ··· 1048 996 static struct configfs_attribute *userdata_attrs[] = { 1049 997 &sysdata_attr_cpu_nr_enabled, 1050 998 &sysdata_attr_taskname_enabled, 999 + &sysdata_attr_release_enabled, 1051 1000 NULL, 1052 1001 }; 1053 1002 ··· 1224 1171 init_target_config_group(nt, target_name); 1225 1172 } 1226 1173 1227 - static int append_cpu_nr(struct netconsole_target *nt, int offset) 1174 + static int sysdata_append_cpu_nr(struct netconsole_target *nt, int offset) 1228 1175 { 1229 1176 /* Append cpu=%d at extradata_complete after userdata str */ 1230 1177 return scnprintf(&nt->extradata_complete[offset], ··· 1232 1179 raw_smp_processor_id()); 1233 1180 } 1234 1181 1235 - static int append_taskname(struct netconsole_target *nt, int offset) 1182 + static int sysdata_append_taskname(struct netconsole_target *nt, int offset) 1236 1183 { 1237 1184 return scnprintf(&nt->extradata_complete[offset], 1238 1185 MAX_EXTRADATA_ENTRY_LEN, " taskname=%s\n", 1239 1186 current->comm); 1240 1187 } 1188 + 1189 + static int sysdata_append_release(struct netconsole_target *nt, int offset) 1190 + { 1191 + return scnprintf(&nt->extradata_complete[offset], 1192 + MAX_EXTRADATA_ENTRY_LEN, " release=%s\n", 1193 + init_utsname()->release); 1194 + } 1195 + 1241 1196 /* 1242 1197 * prepare_extradata - append sysdata at extradata_complete in runtime 1243 1198 * @nt: target to send message to ··· 1264 1203 goto out; 1265 1204 1266 1205 if (nt->sysdata_fields & SYSDATA_CPU_NR) 1267 - extradata_len += append_cpu_nr(nt, extradata_len); 1206 + extradata_len += sysdata_append_cpu_nr(nt, extradata_len); 1268 1207 if (nt->sysdata_fields & SYSDATA_TASKNAME) 1269 - extradata_len += append_taskname(nt, extradata_len); 1208 + extradata_len += sysdata_append_taskname(nt, extradata_len); 1209 + if (nt->sysdata_fields & SYSDATA_RELEASE) 1210 + extradata_len += sysdata_append_release(nt, extradata_len); 1270 1211 1271 1212 WARN_ON_ONCE(extradata_len > 1272 1213 MAX_EXTRADATA_ENTRY_LEN * MAX_EXTRADATA_ITEMS);
+41 -3
tools/testing/selftests/drivers/net/netcons_sysdata.sh
··· 42 42 echo 1 > "${NETCONS_PATH}/userdata/taskname_enabled" 43 43 } 44 44 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 + 45 56 # Disable the sysdata cpu_nr feature 46 57 function unset_cpu_nr() { 47 58 echo 0 > "${NETCONS_PATH}/userdata/cpu_nr_enabled" ··· 61 50 # Once called, taskname=<..> will not be appended anymore 62 51 function unset_taskname() { 63 52 echo 0 > "${NETCONS_PATH}/userdata/taskname_enabled" 53 + } 54 + 55 + function unset_release() { 56 + echo 0 > "${NETCONS_PATH}/userdata/release_enabled" 64 57 } 65 58 66 59 # Test if MSG contains sysdata ··· 108 93 pkill_socat 109 94 } 110 95 96 + function validate_release() { 97 + RELEASE=$(uname -r) 98 + 99 + if [ ! -f "$OUTPUT_FILE" ]; then 100 + echo "FAIL: File was not generated." >&2 101 + exit "${ksft_fail}" 102 + fi 103 + 104 + if ! grep -q "release=${RELEASE}" "${OUTPUT_FILE}"; then 105 + echo "FAIL: 'release=${RELEASE}' not found in ${OUTPUT_FILE}" >&2 106 + cat "${OUTPUT_FILE}" >&2 107 + exit "${ksft_fail}" 108 + fi 109 + } 110 + 111 111 # Test if MSG content exists in OUTPUT_FILE but no `cpu=` and `taskname=` 112 112 # strings 113 113 function validate_no_sysdata() { ··· 145 115 146 116 if grep -q "taskname=" "${OUTPUT_FILE}"; then 147 117 echo "FAIL: 'taskname= found in ${OUTPUT_FILE}" >&2 118 + cat "${OUTPUT_FILE}" >&2 119 + exit "${ksft_fail}" 120 + fi 121 + 122 + if grep -q "release=" "${OUTPUT_FILE}"; then 123 + echo "FAIL: 'release= found in ${OUTPUT_FILE}" >&2 148 124 cat "${OUTPUT_FILE}" >&2 149 125 exit "${ksft_fail}" 150 126 fi ··· 205 169 set_cpu_nr 206 170 # Enable taskname to be appended to sysdata 207 171 set_taskname 172 + set_release 208 173 runtest 209 174 # Make sure the message was received in the dst part 210 175 # and exit 176 + validate_release 211 177 validate_sysdata 212 178 213 179 #==================================================== ··· 222 184 MSG="Test #2 from CPU${CPU}" 223 185 set_user_data 224 186 runtest 187 + validate_release 225 188 validate_sysdata 226 189 227 190 # =================================================== 228 191 # TEST #3 229 - # Unset cpu_nr, so, no CPU should be appended. 230 - # userdata is still set 192 + # Unset all sysdata, fail if any userdata is set 231 193 # =================================================== 232 194 CPU=$((RANDOM % $(nproc))) 233 195 OUTPUT_FILE="/tmp/${TARGET}_3" 234 196 MSG="Test #3 from CPU${CPU}" 235 - # Enable the auto population of cpu_nr 236 197 unset_cpu_nr 237 198 unset_taskname 199 + unset_release 238 200 runtest 239 201 # At this time, cpu= shouldn't be present in the msg 240 202 validate_no_sysdata