Skip to contentSkip to conversation

xen/common: add keyhandler to show Xen command line

PATCH Superseded [email protected] 3 participants 3 messages Aug 11 – Aug 12

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 xen/common: add keyhandler to show Xen command line

Currently there's no way to print Xen command line on the emergency console for debugging purposes when 'xl' is not unavailable.

Add new keyhander 'X' to do command line printout.

---
Changes since v3:
- print built-in command line too
- change handler to print command line only

Changes since v2:
- account for CONFIG_CMDLINE_OVERRIDE case

v3: https://lore.kernel.org/xen-devel/[email protected]/
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2751523722

---
 xen/common/kernel.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
xen/common/kernel.c +32 -0
index d1bef9ac2b2b..8a43e4421002 100644
@@ -5,6 +5,7 @@
  */
 
 #include <xen/init.h>
+#include <xen/keyhandler.h>
 #include <xen/lib.h>
 #include <xen/errno.h>
 #include <xen/param.h>
@@ -505,6 +506,37 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_cmdline(unsigned char key)
+{
+    const char *builtin_cmdline = CONFIG_CMDLINE;
+    const char *cmdline;
+
+    printk("'%c' pressed -> showing hypervisor command line\n", key);
+
+    if ( builtin_cmdline[0] )
+        cmdline = builtin_cmdline;
+    else
+        cmdline = "<NULL>";
+
+    printk("Built-in command line: %s\n", cmdline);
+
+    if ( IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) )
+        cmdline = "<NULL> (CONFIG_CMDLINE_OVERRIDE=y)";
+    else
+        cmdline = saved_cmdline;
+
+    printk("Command line: %s\n", cmdline);
+}
+
+static int __init cf_check misc_init(void)
+{
+    register_keyhandler('X', show_cmdline,
+                        "show hypervisor command line", 0);
+
+    return 0;
+}
+__initcall(misc_init);
+
 static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct xen_varbuf user_str;
Signature · 1 line
2.54.0
#1 lore raw

xen/common/kernel.c static int __init cf_check param_init(void) · line 511

Quoted 7 lines · On 11.08.2026 23:09, [email protected] wrote:
xen/common/kernel.c +3 -0
@@ -505,6 +506,37 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_cmdline(unsigned char key)
+{
+    const char *builtin_cmdline = CONFIG_CMDLINE;

Maybe compilers manage to optimize this to the equivalent of

    static const char builtin_cmdline[] = CONFIG_CMDLINE;

yet even then I see no reason why it wouldn't want spelling that way anyway.

Plus this raises the question: Why would we need two instances of the string in the Xen image? If you need the literal at runtime, re-use opt_builtin_cmdline[] by dropping __initconst from it.

xen/common/kernel.c static int __init cf_check param_init(void) · line 521

Quoted 10 lines
xen/common/kernel.c +10 -0
+    const char *cmdline;
+
+    printk("'%c' pressed -> showing hypervisor command line\n", key);
+
+    if ( builtin_cmdline[0] )
+        cmdline = builtin_cmdline;
+    else
+        cmdline = "<NULL>";
+
+    printk("Built-in command line: %s\n", cmdline);

What use is this line when <NULL> is shown?

Jan

#2 lore raw
In reply to [email protected]
Quoted 2 lines · On 8/11/26 11:09 PM, [email protected] wrote:

Currently there's no way to print Xen command line on the emergency console for debugging purposes when 'xl' is not unavailable.

It looks like 'not' should be dropped. 'unavailable' covers 'not' itself.

Quoted 40 lines

Add new keyhander 'X' to do command line printout.

---
Changes since v3:
- print built-in command line too
- change handler to print command line only

Changes since v2:
- account for CONFIG_CMDLINE_OVERRIDE case

v3: https://lore.kernel.org/xen-devel/[email protected]/
CI: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2751523722

---
  xen/common/kernel.c | 32 ++++++++++++++++++++++++++++++++
  1 file changed, 32 insertions(+)
xen/common/kernel.c +7 -0
index d1bef9ac2b2b..8a43e4421002 100644
@@ -5,6 +5,7 @@
   */
 
  #include <xen/init.h>
+#include <xen/keyhandler.h>
  #include <xen/lib.h>
  #include <xen/errno.h>
  #include <xen/param.h>
@@ -505,6 +506,37 @@ static int __init cf_check param_init(void)
  __initcall(param_init);
  #endif
 
+static void cf_check show_cmdline(unsigned char key)
+{
+    const char *builtin_cmdline = CONFIG_CMDLINE;
+    const char *cmdline;
+
+    printk("'%c' pressed -> showing hypervisor command line\n", key);

xen/common/kernel.c static int __init cf_check param_init(void) · line 524

Quoted 10 lines
xen/common/kernel.c +10 -0
+
+    if ( builtin_cmdline[0] )
+        cmdline = builtin_cmdline;
+    else
+        cmdline = "<NULL>";
+
+    printk("Built-in command line: %s\n", cmdline);
+
+    if ( IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) )
+        cmdline = "<NULL> (CONFIG_CMDLINE_OVERRIDE=y)";

Won't be better to use <ignored> instead of <NULL>? Also it reflects the comment (But if CONFIG_CMDLINE_OVERRIDE is set to y, @cmdline will be ignored.) above cmdline_parse() function better.

xen/common/kernel.c static int __init cf_check param_init(void) · line 526

Quoted 2 lines
xen/common/kernel.c +2 -0
+    else
+        cmdline = saved_cmdline;

IIUC, saved_cmdline could be empty and I think we should take that into account too:

    if ( IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) )
        cmdline = "<ignored> (CONFIG_CMDLINE_OVERRIDE=y)";
    else if ( saved_cmdline[0] )
        cmdline = saved_cmdline;
    else
        cmdline = "<NULL>";

xen/common/kernel.c static int __init cf_check param_init(void) · line 534

Quoted 8 lines
xen/common/kernel.c +8 -0
+
+    printk("Command line: %s\n", cmdline);
+}
+
+static int __init cf_check misc_init(void)
+{
+    register_keyhandler('X', show_cmdline,
+                        "show hypervisor command line", 0);

Last argument is declared as bool so I think it will be better to use false here.

~ Oleksii