Skip to contentSkip to conversation

keyhandler to show Xen command line

PATCH Superseded [email protected] 5 participants 8 messages Aug 3 – Aug 10

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover keyhandler to show Xen command line

Tiny series which adds new 'X' keyhandler to show Xen command line to help debugging the system.

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

Denis Mukhin (2):
xen/common: annotate saved_cmdline with __ro_after_init xen/common: add keyhandler to show Xen command line

 xen/common/kernel.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/2 xen/common: annotate saved_cmdline with __ro_after_init

From: Denis Mukhin <[email protected]>

The hypervisor command line is not modified after initialization. Annotate saved_cmdline with __ro_after_init to place it in the dedicated read-only-after-init section.

---
Changes since v1:
- new patch

---
 xen/common/kernel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/kernel.c +1 -1
index fb45f8139995..d1bef9ac2b2b 100644
@@ -34,7 +34,7 @@ bool __ro_after_init opt_dit = IS_ENABLED(CONFIG_DIT_DEFAULT);
 boolean_param("dit", opt_dit);
 #endif
 
-static xen_commandline_t saved_cmdline;
+static xen_commandline_t __ro_after_init saved_cmdline;
 static const char __initconst opt_builtin_cmdline[] = CONFIG_CMDLINE;
 char __ro_after_init xen_cap_info[128];
 
Signature · 1 line
2.54.0
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/common: annotate saved_cmdline with __ro_after_init

Quoted 8 lines · On 03.08.2026 09:00, [email protected] wrote:

From: Denis Mukhin <[email protected]>

The hypervisor command line is not modified after initialization. Annotate saved_cmdline with __ro_after_init to place it in the dedicated read-only-after-init section.

#3 lore raw

PATCH v2 2/2 xen/common: add keyhandler to show Xen command line

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Currently there's no way to print Xen command line on the emergency console for debugging purposes (e.g. 'xl' is not available in dom0).

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

---
v1: https://lore.kernel.org/xen-devel/[email protected]/

Changes since v1:
- moved implementation into kernel.c

---
 xen/common/kernel.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/common/kernel.c +16 -0
index d1bef9ac2b2b..9f334c92e3ab 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,21 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_hypervisor_info(unsigned char key)
+{
+    printk("'%c' pressed -> showing hypervisor information\n", key);
+    printk("Command line: %s\n", saved_cmdline);
+}
+
+static int __init cf_check misc_init(void)
+{
+    register_keyhandler('X', show_hypervisor_info,
+                        "show hypervisor information", 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
#4 lore raw

Re: [PATCH v2 2/2] xen/common: add keyhandler to show Xen command line

Quoted 30 lines · On Mon, 3 Aug 2026, [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 (e.g. 'xl' is not available in dom0).

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

---
v1: https://lore.kernel.org/xen-devel/[email protected]/

Changes since v1:
- moved implementation into kernel.c

---
 xen/common/kernel.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/common/kernel.c +1 -0
index d1bef9ac2b2b..9f334c92e3ab 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>

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

Quoted 7 lines
xen/common/kernel.c +4 -0
@@ -505,6 +506,21 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_hypervisor_info(unsigned char key)
+{
+    printk("'%c' pressed -> showing hypervisor information\n", key);
+    printk("Command line: %s\n", saved_cmdline);

if CONFIG_CMDLINE_OVERRIDE is defined, saved_cmdline is empty. We could at least do this:

#ifdef CONFIG_CMDLINE_OVERRIDE
    printk("Bootloader command line ignored (CONFIG_CMDLINE_OVERRIDE=y)\n");
#else
    printk("Command line: %s\n", saved_cmdline);

#endif

Other than that it is fine for me

Quoted 17 lines
xen/common/kernel.c +11 -0
+}
+
+static int __init cf_check misc_init(void)
+{
+    register_keyhandler('X', show_hypervisor_info,
+                        "show hypervisor information", 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
#5 lore raw

Re: [PATCH v2 2/2] xen/common: add keyhandler to show Xen command line

Quoted 42 lines · Stefano Stabellini
Quoted 30 lines · On Mon, 3 Aug 2026, [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 (e.g. 'xl' is not available in dom0).

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

---
v1: https://lore.kernel.org/xen-devel/[email protected]/

Changes since v1:
- moved implementation into kernel.c

---
 xen/common/kernel.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/common/kernel.c +1 -0
index d1bef9ac2b2b..9f334c92e3ab 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>

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

Quoted 7 lines
xen/common/kernel.c +4 -0
@@ -505,6 +506,21 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_hypervisor_info(unsigned char key)
+{
+    printk("'%c' pressed -> showing hypervisor information\n", key);
+    printk("Command line: %s\n", saved_cmdline);

if CONFIG_CMDLINE_OVERRIDE is defined, saved_cmdline is empty. We could at least do this:

Quoted 5 lines
#ifdef CONFIG_CMDLINE_OVERRIDE
    printk("Bootloader command line ignored (CONFIG_CMDLINE_OVERRIDE=y)\n");
#else
    printk("Command line: %s\n", saved_cmdline);

#endif

Actually, CONFIG_CMDLINE can set the built-in command line which can be non-empty.

Perhaps, something like this:

    printk("Command line (built-in): %s\n", opt_builtin_cmdline);
#ifndef CONFIG_CMDLINE_OVERRIDE
    printk("Command line: %s\n", saved_cmdline);

#endif

What do you think?

Quoted 23 lines

Other than that it is fine for me

Quoted 17 lines
xen/common/kernel.c +11 -0
+}
+
+static int __init cf_check misc_init(void)
+{
+    register_keyhandler('X', show_hypervisor_info,
+                        "show hypervisor information", 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
#6 lore raw

Re: [PATCH v2 2/2] xen/common: add keyhandler to show Xen command line

Quoted 52 lines · On 8/8/26 4:38 AM, [email protected] wrote:
Quoted 42 lines · Stefano Stabellini
Quoted 30 lines · On Mon, 3 Aug 2026, [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 (e.g. 'xl' is not available in dom0).

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

---
v1: https://lore.kernel.org/xen-devel/[email protected]/

Changes since v1:
- moved implementation into kernel.c

---
  xen/common/kernel.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
xen/common/kernel.c +1 -0
index d1bef9ac2b2b..9f334c92e3ab 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>

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

Quoted 7 lines
xen/common/kernel.c +4 -0
@@ -505,6 +506,21 @@ static int __init cf_check param_init(void)
  __initcall(param_init);
  #endif
 
+static void cf_check show_hypervisor_info(unsigned char key)
+{
+    printk("'%c' pressed -> showing hypervisor information\n", key);
+    printk("Command line: %s\n", saved_cmdline);

if CONFIG_CMDLINE_OVERRIDE is defined, saved_cmdline is empty. We could at least do this:

Quoted 5 lines
#ifdef CONFIG_CMDLINE_OVERRIDE
     printk("Bootloader command line ignored (CONFIG_CMDLINE_OVERRIDE=y)\n");
#else
     printk("Command line: %s\n", saved_cmdline);

#endif

Actually, CONFIG_CMDLINE can set the built-in command line which can be non-empty.

Quoted 8 lines

Perhaps, something like this:

     printk("Command line (built-in): %s\n", opt_builtin_cmdline);
#ifndef CONFIG_CMDLINE_OVERRIDE
     printk("Command line: %s\n", saved_cmdline);

#endif

What do you think?

Considering that opt_builtin_cmdline is declared as __initconst won't it be an issue to print it in non-init function (show_hypervisor_info())? In other words, I expected that __init section should be freed at some point and I expect that it should be data abort here.

~ Oleksii

#7 lore raw

Re: [PATCH v2 2/2] xen/common: add keyhandler to show Xen command line

In reply to [email protected]
Quoted 52 lines · On Fri, Aug 07, 2026 at 07:38:28PM -0700, [email protected] wrote:
Quoted 42 lines · Stefano Stabellini
Quoted 30 lines · On Mon, 3 Aug 2026, [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 (e.g. 'xl' is not available in dom0).

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

---
v1: https://lore.kernel.org/xen-devel/[email protected]/

Changes since v1:
- moved implementation into kernel.c

---
 xen/common/kernel.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/common/kernel.c +1 -0
index d1bef9ac2b2b..9f334c92e3ab 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>

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

Quoted 7 lines
xen/common/kernel.c +4 -0
@@ -505,6 +506,21 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
+static void cf_check show_hypervisor_info(unsigned char key)
+{
+    printk("'%c' pressed -> showing hypervisor information\n", key);
+    printk("Command line: %s\n", saved_cmdline);

if CONFIG_CMDLINE_OVERRIDE is defined, saved_cmdline is empty. We could at least do this:

Quoted 5 lines
#ifdef CONFIG_CMDLINE_OVERRIDE
    printk("Bootloader command line ignored (CONFIG_CMDLINE_OVERRIDE=y)\n");
#else
    printk("Command line: %s\n", saved_cmdline);

#endif

Actually, CONFIG_CMDLINE can set the built-in command line which can be non-empty.

Quoted 6 lines

Perhaps, something like this:

    printk("Command line (built-in): %s\n", opt_builtin_cmdline);
#ifndef CONFIG_CMDLINE_OVERRIDE
    printk("Command line: %s\n", saved_cmdline);

#endif

Aside from the remark from Oleksii, can you use IS_ENABLED() here instead of preprocessor conditionals?

Thanks, Roger.