Skip to content

Commit 34c84b3

Browse files
committed
Merge branch 'netconsole-cpu-population'
Breno Leitao says: ==================== netconsole: Add support for CPU population The current implementation of netconsole sends all log messages in parallel, which can lead to an intermixed and interleaved output on the receiving side. This makes it challenging to demultiplex the messages and attribute them to their originating CPUs. As a result, users and developers often struggle to effectively analyze and debug the parallel log output received through netconsole. Example of a message got from produciton hosts: ------------[ cut here ]------------ ------------[ cut here ]------------ refcount_t: saturated; leaking memory. WARNING: CPU: 2 PID: 1613668 at lib/refcount.c:22 refcount_warn_saturate+0x5e/0xe0 refcount_t: addition on 0; use-after-free. WARNING: CPU: 26 PID: 4139916 at lib/refcount.c:25 refcount_warn_saturate+0x7d/0xe0 Modules linked in: bpf_preload(E) vhost_net(E) tun(E) vhost(E) This series of patches introduces a new feature to the netconsole subsystem that allows the automatic population of the CPU number in the userdata field for each log message. This enhancement provides several benefits: * Improved demultiplexing of parallel log output: When multiple CPUs are sending messages concurrently, the added CPU number in the userdata makes it easier to differentiate and attribute the messages to their originating CPUs. * Better visibility into message sources: The CPU number information gives users and developers more insight into which specific CPU a particular log message came from, which can be valuable for debugging and analysis. The changes in this series are as follows Patches:: Patch "consolidate send buffers into netconsole_target struct" ================================================= Move the static buffers to netconsole target, from static declaration in send_msg_no_fragmentation() and send_msg_fragmented(). Patch "netconsole: Rename userdata to extradata" ================================================= Create the a concept of extradata, which encompasses the concept of userdata and the upcoming sysdatao Sysdata is a new concept being added, which is basically fields that are populated by the kernel. At this time only the CPU#, but, there is a desire to add current task name, kernel release version, etc. Patch "netconsole: Helper to count number of used entries" =========================================================== Create a simple helper to count number of entries in extradata. I am separating this in a function since it will need to count userdata and sysdata. For instance, when the user adds an extra userdata, we need to check if there is space, counting the previous data entries (from userdata and cpu data) Patch "Introduce configfs helpers for sysdata features" ====================================================== Create the concept of sysdata feature in the netconsole target, and create the configfs helpers to enable the bit in nt->sysdata Patch "Include sysdata in extradata entry count" ================================================ Add the concept of sysdata when counting for available space in the buffer. This will protect users from creating new userdata/sysdata if there is no more space Patch "netconsole: add support for sysdata and CPU population" =============================================================== This is the core patch. Basically add a new option to enable automatic CPU number population in the netconsole userdata Provides a new "cpu_nr" sysfs attribute to control this feature Patch "netconsole: selftest: test CPU number auto-population" ============================================================= Expands the existing netconsole selftest to verify the CPU number auto-population functionality Ensures the received netconsole messages contain the expected "cpu=<CPU>" entry in the message. Test different permutation with userdata Patch "netconsole: docs: Add documentation for CPU number auto-population" ============================================================================= Updates the netconsole documentation to explain the new CPU number auto-population feature Provides instructions on how to enable and use the feature I believe these changes will be a valuable addition to the netconsole subsystem, enhancing its usefulness for kernel developers and users. PS: This patchset is on top of the patch that created netcons_fragmented_msg selftest: https://lore.kernel.org/all/[email protected]/ --- Changes in v5: - Fixed a kernel doc syntax syntax (Simon) - Link to v4: https://lore.kernel.org/r/[email protected] Changes in v4: - Fixed Kernel doc for netconsole_target (Simon) - Fixed a typo in disable_sysdata_feature (Simon) - Improved sysdata_cpu_nr_show() to return !! in a bit-wise operation - Link to v3: https://lore.kernel.org/r/[email protected] Changes in v3: - Moved the buffer into netconsole_target, avoiding static functions in the send path (Jakub). - Fix a documentation error (Randy Dunlap) - Created a function that handle all the extradata, consolidating it in a single place (Jakub) - Split the patch even more, trying to simplify the review. - Link to v2: https://lore.kernel.org/r/[email protected] Changes in v2: - Create the concept of extradata and sysdata. This will make the design easier to understand, and the code easier to read. * Basically extradata encompasses userdata and the new sysdata. Userdata originates from user, and sysdata originates in kernel. - Improved the test to send from a very specific CPU, which can be checked to be correct on the other side, as suggested by Jakub. - Fixed a bug where CPU # was populated at the wrong place - Link to v1: https://lore.kernel.org/r/[email protected] ==================== Signed-off-by: Breno Leitao <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents acdefab + a7aec70 commit 34c84b3

File tree

5 files changed

+427
-64
lines changed

5 files changed

+427
-64
lines changed

Documentation/networking/netconsole.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Release prepend support by Breno Leitao <[email protected]>, Jul 7 2023
1717

1818
Userdata append support by Matthew Wood <[email protected]>, Jan 22 2024
1919

20+
Sysdata append support by Breno Leitao <[email protected]>, Jan 15 2025
21+
2022
Please send bug reports to Matt Mackall <[email protected]>
2123
Satyam Sharma <[email protected]>, and Cong Wang <[email protected]>
2224

@@ -238,6 +240,49 @@ Delete `userdata` entries with `rmdir`::
238240

239241
It is recommended to not write user data values with newlines.
240242

243+
CPU number auto population in userdata
244+
--------------------------------------
245+
246+
Inside the netconsole configfs hierarchy, there is a file called
247+
`cpu_nr` under the `userdata` directory. This file is used to enable or disable
248+
the automatic CPU number population feature. This feature automatically
249+
populates the CPU number that is sending the message.
250+
251+
To enable the CPU number auto-population::
252+
253+
echo 1 > /sys/kernel/config/netconsole/target1/userdata/cpu_nr
254+
255+
When this option is enabled, the netconsole messages will include an additional
256+
line in the userdata field with the format `cpu=<cpu_number>`. This allows the
257+
receiver of the netconsole messages to easily differentiate and demultiplex
258+
messages originating from different CPUs, which is particularly useful when
259+
dealing with parallel log output.
260+
261+
Example::
262+
263+
echo "This is a message" > /dev/kmsg
264+
12,607,22085407756,-;This is a message
265+
cpu=42
266+
267+
In this example, the message was sent by CPU 42.
268+
269+
.. note::
270+
271+
If the user has set a conflicting `cpu` key in the userdata dictionary,
272+
both keys will be reported, with the kernel-populated entry appearing after
273+
the user one. For example::
274+
275+
# User-defined CPU entry
276+
mkdir -p /sys/kernel/config/netconsole/target1/userdata/cpu
277+
echo "1" > /sys/kernel/config/netconsole/target1/userdata/cpu/value
278+
279+
Output might look like::
280+
281+
12,607,22085407756,-;This is a message
282+
cpu=1
283+
cpu=42 # kernel-populated value
284+
285+
241286
Extended console:
242287
=================
243288

0 commit comments

Comments
 (0)