Skip to contentSkip to conversation

libxl: create control/sysrq xenstore node

PATCH In review Vitaly Kuznetsov 3 participants 7 messages Sep 4, 2018 – Sep 5, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: create control/sysrq xenstore node

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

---
- Linux code will need to be modified too. With this patch we get something like

sysrq: SysRq : Emergency Sync
xen:manage: Error -34 reading sysrq code in control/sysrq Emergency Sync complete

This new ERANGE fault happens because after we clean control/sysrq node xenstore watch in the guest is re-asserted but the value is empty ("") so xenbus_scanf() fails "%c" parsing.

It seems the feature is long broken.

---
 tools/libxl/libxl_create.c | 3 +++
 1 file changed, 3 insertions(+)
tools/libxl/libxl_create.c +3 -0
index b7b44e280b..d60f952f73 100644
@@ -692,6 +692,9 @@ retry_transaction:
                         GCSPRINTF("%s/control/feature-s4", dom_path),
                         rwperm, ARRAY_SIZE(rwperm));
     }
+    libxl__xs_mknod(gc, t,
+                    GCSPRINTF("%s/control/sysrq", dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
     libxl__xs_mknod(gc, t,
                     GCSPRINTF("%s/device/suspend/event-channel", dom_path),
                     rwperm, ARRAY_SIZE(rwperm));
Signature · 7 lines
2.14.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 10 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

Quoted 6 lines

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

Hmm... this node isn't documented.

Can you point me to the code in Linux?

Quoted 34 lines

---
- Linux code will need to be modified too. With this patch we get something like

sysrq: SysRq : Emergency Sync
xen:manage: Error -34 reading sysrq code in control/sysrq Emergency Sync complete

This new ERANGE fault happens because after we clean control/sysrq node xenstore watch in the guest is re-asserted but the value is empty ("") so xenbus_scanf() fails "%c" parsing.

It seems the feature is long broken.

---
 tools/libxl/libxl_create.c | 3 +++
 1 file changed, 3 insertions(+)
tools/libxl/libxl_create.c +3 -0
index b7b44e280b..d60f952f73 100644
@@ -692,6 +692,9 @@ retry_transaction:
                         GCSPRINTF("%s/control/feature-s4", dom_path),
                         rwperm, ARRAY_SIZE(rwperm));
     }
+    libxl__xs_mknod(gc, t,
+                    GCSPRINTF("%s/control/sysrq", dom_path),
+                    rwperm, ARRAY_SIZE(rwperm));
     libxl__xs_mknod(gc, t,
                     GCSPRINTF("%s/device/suspend/event-channel", dom_path),
                     rwperm, ARRAY_SIZE(rwperm));
Signature · 1 line
2.14.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 11 lines · Wei Liu
Quoted 10 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

Quoted 9 lines
Quoted 6 lines

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

Hmm... this node isn't documented.

But libxl already writes it, see libxl_send_sysrq().

Quoted 2 lines

Can you point me to the code in Linux?

Sure,

drivers/xen/manage.c:

static void sysrq_handler(struct xenbus_watch *watch, const char *path,
const char *token)

{
	char sysrq_key = '\0';
	struct xenbus_transaction xbt;
	int err;

again:

	err = xenbus_transaction_start(&xbt);
	if (err)
		return;
	err = xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key);
	if (err < 0) {
		/*
		 * The Xenstore watch fires directly after registering it and
		 * after a suspend/resume cycle. So ENOENT is no error but
		 * might happen in those cases.
		 */
		if (err != -ENOENT)
			pr_err("Error %d reading sysrq code in control/sysrq\n",
			       err);
		xenbus_transaction_end(xbt, 1);
		return;
	}

	if (sysrq_key != '\0') {
		err = xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
		if (err) {
			pr_err("%s: Error %d writing sysrq in control/sysrq\n",
			       __func__, err);
			xenbus_transaction_end(xbt, 1);
			return;
		}
	}

	err = xenbus_transaction_end(xbt, 0);
	if (err == -EAGAIN)
		goto again;

	if (sysrq_key != '\0')
		handle_sysrq(sysrq_key);
}

static struct xenbus_watch sysrq_watch = {
.node = "control/sysrq",
.callback = sysrq_handler
};

Signature · 6 lines
  Vitaly

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

Also CC Linux maintainers.

Quoted 18 lines · Vitaly Kuznetsov
Quoted 16 lines · Wei Liu
Quoted 15 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Hmm... this node isn't documented.

But libxl already writes it, see libxl_send_sysrq().

I think your patch is fine.

What I wanted to do is to document this node. :p

Quoted 7 lines
Quoted 3 lines

Can you point me to the code in Linux?

Sure,

drivers/xen/manage.c:

Alright, it appears DomU only expects a single character to be written.

I have written the following diff, do you think it is sensible? I believe this is Linux only, but I have CC Roger for correction.

docs/misc/xenstore-paths.markdown +8 -0
index 60c8b3fbe5..33d281915c 100644
@@ -410,6 +410,14 @@ by udev ("0") or will be run by the toolstack directly ("1").
 
 ### Platform Feature and Control Paths
 
+#### ~/control/sysrq = (""|COMMAND) [w]
+
+This is the PV SysRq control node. A toolstack can write a single character
+representing a magic SysRq key understood by the Linux kernel.  The guest
+acknowledges a request by writing the empty string back to the command node.
+
+This protocol is Linux only.
+
 #### ~/control/shutdown = (""|COMMAND) [w]
 
 This is the PV shutdown control node. A toolstack can write various

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 55 lines · Wei Liu

Also CC Linux maintainers.

Quoted 18 lines · Vitaly Kuznetsov
Quoted 16 lines · Wei Liu
Quoted 15 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Hmm... this node isn't documented.

But libxl already writes it, see libxl_send_sysrq().

I think your patch is fine.

What I wanted to do is to document this node. :p

Quoted 7 lines
Quoted 3 lines

Can you point me to the code in Linux?

Sure,

drivers/xen/manage.c:

Alright, it appears DomU only expects a single character to be written.

I have written the following diff, do you think it is sensible? I believe this is Linux only, but I have CC Roger for correction.

docs/misc/xenstore-paths.markdown +1 -0
index 60c8b3fbe5..33d281915c 100644
@@ -410,6 +410,14 @@ by udev ("0") or will be run by the toolstack directly ("1").
 
 ### Platform Feature and Control Paths
 
+#### ~/control/sysrq = (""|COMMAND) [w]

docs/misc/xenstore-paths.markdown by udev ("0") or will be run by the toolstack directly ("1"). · line 423

Quoted 10 lines
docs/misc/xenstore-paths.markdown +7 -0
+
+This is the PV SysRq control node. A toolstack can write a single character
+representing a magic SysRq key understood by the Linux kernel.  The guest
+acknowledges a request by writing the empty string back to the command node.
+
+This protocol is Linux only.
+
 #### ~/control/shutdown = (""|COMMAND) [w]
 
 This is the PV shutdown control node. A toolstack can write various

LGTM. I haven't implemented this on FreeBSD, and I very much doubt NetBSD uses it at all. FreeBSD doesn't have such thing as sysrq keys, there's only a key sequence used in order to break into the debugger from the console AFAIK.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
In reply to Wei Liu
Quoted 53 lines · Wei Liu

Also CC Linux maintainers.

Quoted 18 lines · Vitaly Kuznetsov
Quoted 16 lines · Wei Liu
Quoted 15 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Hmm... this node isn't documented.

But libxl already writes it, see libxl_send_sysrq().

I think your patch is fine.

What I wanted to do is to document this node. :p

Quoted 7 lines
Quoted 3 lines

Can you point me to the code in Linux?

Sure,

drivers/xen/manage.c:

Alright, it appears DomU only expects a single character to be written.

I have written the following diff, do you think it is sensible? I believe this is Linux only, but I have CC Roger for correction.

docs/misc/xenstore-paths.markdown +0 -0
index 60c8b3fbe5..33d281915c 100644
@@ -410,6 +410,14 @@ by udev ("0") or will be run by the toolstack directly ("1").
 
 ### Platform Feature and Control Paths
 

docs/misc/xenstore-paths.markdown by udev ("0") or will be run by the toolstack directly ("1"). · line 422

Quoted 10 lines
docs/misc/xenstore-paths.markdown +8 -0
+#### ~/control/sysrq = (""|COMMAND) [w]
+
+This is the PV SysRq control node. A toolstack can write a single character
+representing a magic SysRq key understood by the Linux kernel.  The guest
+acknowledges a request by writing the empty string back to the command node.
+
+This protocol is Linux only.
+
 #### ~/control/shutdown = (""|COMMAND) [w]
 

Makes perfect sense to me and sounds correct, thanks!

Signature · 6 lines
  Vitaly

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#6 lore raw
In reply to Vitaly Kuznetsov
Quoted 10 lines · Vitaly Kuznetsov

'xl sysrq' command doesn't work with modern Linux guests with the following message in guest's log:

xen:manage: sysrq_handler: Error -13 writing sysrq in control/sysrq

xenstore trace confirms:

IN 0x24bd9a0 20180904 04:36:32 WRITE (control/sysrq ) OUT 0x24bd9a0 20180904 04:36:32 ERROR (EACCES )

Quoted 6 lines

The problem seems to be in the fact that we don't pre-create control/sysrq xenstore node and libxl_send_sysrq() doing libxl__xs_printf() creates it as read-only. As we want to allow guests to clean 'control/sysrq' after the requested action is performed, we need to make this node writable.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel