Skip to contentSkip to conversation

keyhandler: add handler to show Xen command line

PATCH Superseded [email protected] 3 participants 3 messages Jul 30

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 keyhandler: add handler to show Xen command line

From: Denis Mukhin <[email protected]>

Currently there's no way to print Xen command line on the emergency console for debugging purposes.

Add new keyhander 'C' to add (saved) command line printout for debugging the system.

Also, fix indentation for KEYHANDLER() entries in 'keyhandler' array.

---
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2717339023

---
 xen/common/kernel.c     |  5 +++++
 xen/common/keyhandler.c | 18 +++++++++++++-----
 xen/include/xen/lib.h   |  1 +
 3 files changed, 19 insertions(+), 5 deletions(-)
xen/common/kernel.c +5 -0
index fb45f8139995..9718a89d8088 100644
@@ -232,6 +232,11 @@ void __init cmdline_parse(const char *cmdline)
 #endif
 }
 
+const char *cmdline_get(void)
+{
+    return saved_cmdline;
+}
+
 int parse_bool(const char *s, const char *e)
 {
     size_t len = e ? ({ ASSERT(e >= s); e - s; }) : strlen(s);
xen/common/keyhandler.c +13 -5
index cb6df2823b00..55a370ac1790 100644
@@ -28,7 +28,7 @@ static unsigned char keypress_key;
 static bool alt_key_handling;
 
 static keyhandler_fn_t cf_check show_handlers, cf_check dump_hwdom_registers,
-    cf_check dump_domains, cf_check read_clocks;
+    cf_check dump_domains, cf_check read_clocks, show_cmdline;
 static irq_keyhandler_fn_t cf_check do_toggle_alt_key, cf_check dump_registers,
     cf_check reboot_machine, cf_check run_all_keyhandlers;
 
@@ -60,15 +60,17 @@ static struct keyhandler {
     IRQ_KEYHANDLER('*', run_all_keyhandlers, "print all diagnostics", 0),
 
 #ifdef CONFIG_PERF_COUNTERS
-    KEYHANDLER('p', perfc_printall, "print performance counters", 1),
-    KEYHANDLER('P', perfc_reset, "reset performance counters", 0),
+        KEYHANDLER('p', perfc_printall, "print performance counters", 1),
+        KEYHANDLER('P', perfc_reset, "reset performance counters", 0),
 #endif
 
 #ifdef CONFIG_DEBUG_LOCK_PROFILE
-    KEYHANDLER('l', spinlock_profile_printall, "print lock profile info", 1),
-    KEYHANDLER('L', spinlock_profile_reset, "reset lock profile info", 0),
+        KEYHANDLER('l', spinlock_profile_printall, "print lock profile info", 1),
+        KEYHANDLER('L', spinlock_profile_reset, "reset lock profile info", 0),
 #endif
 
+        KEYHANDLER('C', show_cmdline, "show saved command line", 0),
+
 #undef IRQ_KEYHANDLER
 #undef KEYHANDLER
 };
@@ -512,6 +514,12 @@ static void cf_check do_toggle_alt_key(unsigned char key, bool unused)
            alt_key_handling ? "alternative" : "normal");
 }
 
+static void cf_check show_cmdline(unsigned char key)
+{
+    printk("'%c' pressed -> showing saved command line\n", key);
+    printk("%s\n", cmdline_get());
+}
+
 void __init initialize_keytable(void)
 {
     if ( num_present_cpus() > 16 )
xen/include/xen/lib.h +1 -0
index 3c545ff33c61..094873dc8ba6 100644
@@ -19,6 +19,7 @@
 
 struct domain;
 
+const char *cmdline_get(void);
 void cmdline_parse(const char *cmdline);
 int parse_bool(const char *s, const char *e);
 
Signature · 1 line
2.54.0
#1 lore raw
Quoted 7 lines · On 30.07.26 08:15, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Currently there's no way to print Xen command line on the emergency console for debugging purposes.

Add new keyhander 'C' to add (saved) command line printout for debugging the system.

'C' is already taken for "trigger a crashdump". Many keyhandlers are registered dynamically via register_keyhandler().

What about 'X' for "General Xen information"?

This would allow for adding more information later, like e.g. physical memory size, number of CPUs, number of active domains, etc., without the need of burning another debug key for that.

Juergen

#2 lore raw
In reply to [email protected]
Quoted 1 line · On 30.07.2026 08:15, [email protected] wrote:

From: Denis Mukhin <[email protected]>

First, you want to update Roger's email address that you use. This is now the 2nd patch that you sent to his old address, and the latest after sending the 1st you should have noticed.

Quoted 5 lines

Currently there's no way to print Xen command line on the emergency console for debugging purposes.

Add new keyhander 'C' to add (saved) command line printout for debugging the system.

If others think spending a precious character on this, I think I won't attempt to veto this, but I'm definitely not going to ack such. More importantly though you shouldn't be using a character that's already in use.

Nevertheless a few comments below.

Quoted 1 line

Also, fix indentation for KEYHANDLER() entries in 'keyhandler' array.

"fix" as in "break"? Patch context alone doesn't make clear at all why you'd do this. Looking at the full source I think I can see why you think something may be wrong there, but I don't think it is - the earlier block outside of the #ifdef-s is different in this regard, imo.

xen/common/kernel.c void __init cmdline_parse(const char *cmdline) · line 238

Quoted 10 lines
xen/common/kernel.c +4 -0
@@ -232,6 +232,11 @@ void __init cmdline_parse(const char *cmdline)
 #endif
 }
 
+const char *cmdline_get(void)
+{
+    return saved_cmdline;
+}

To accompany both this use and the pre-existing ones, perhaps it's time to mark saved_cmdline[] __ro_after_init (in a separate patch preferably)?

Quoted 19 lines
xen/common/keyhandler.c +3 -3
@@ -28,7 +28,7 @@ static unsigned char keypress_key;
 static bool alt_key_handling;
 
 static keyhandler_fn_t cf_check show_handlers, cf_check dump_hwdom_registers,
-    cf_check dump_domains, cf_check read_clocks;
+    cf_check dump_domains, cf_check read_clocks, show_cmdline;
 static irq_keyhandler_fn_t cf_check do_toggle_alt_key, cf_check dump_registers,
     cf_check reboot_machine, cf_check run_all_keyhandlers;
 
@@ -60,15 +60,17 @@ static struct keyhandler {
     IRQ_KEYHANDLER('*', run_all_keyhandlers, "print all diagnostics", 0),
 
 #ifdef CONFIG_PERF_COUNTERS
-    KEYHANDLER('p', perfc_printall, "print performance counters", 1),
-    KEYHANDLER('P', perfc_reset, "reset performance counters", 0),
+        KEYHANDLER('p', perfc_printall, "print performance counters", 1),
+        KEYHANDLER('P', perfc_reset, "reset performance counters", 0),

xen/common/keyhandler.c static struct keyhandler { · line 72

Quoted 10 lines
xen/common/keyhandler.c +3 -2
 #endif
 
 #ifdef CONFIG_DEBUG_LOCK_PROFILE
-    KEYHANDLER('l', spinlock_profile_printall, "print lock profile info", 1),
-    KEYHANDLER('L', spinlock_profile_reset, "reset lock profile info", 0),
+        KEYHANDLER('l', spinlock_profile_printall, "print lock profile info", 1),
+        KEYHANDLER('L', spinlock_profile_reset, "reset lock profile info", 0),
 #endif
 
+        KEYHANDLER('C', show_cmdline, "show saved command line", 0),

Why not insert at the appropriate slot in the earlier block outside of any #ifdef?

As to the help text - in how far is "saved" relevant there?

xen/common/keyhandler.c static void cf_check do_toggle_alt_key(unsigned char key, bool unused) · line 521

Quoted 9 lines
xen/common/keyhandler.c +5 -0
@@ -512,6 +514,12 @@ static void cf_check do_toggle_alt_key(unsigned char key, bool unused)
            alt_key_handling ? "alternative" : "normal");
 }
 
+static void cf_check show_cmdline(unsigned char key)
+{
+    printk("'%c' pressed -> showing saved command line\n", key);
+    printk("%s\n", cmdline_get());
+}

If this lived in kernel.c, the new cmdline_get() wouldn't be needed at all.

Jan