Skip to contentSkip to conversation

mini-os: Using new hypercall interfaces

PATCH In review Dietmar Hahn 2 participants 4 messages Nov 22, 2006 – Nov 24, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mini-os: Using new hypercall interfaces

Hi,

this patch switches to the newer interfaces for HYPERVISOR_sched_op() and HYPERVISOR_event_channel_op(). I testet it only on x86_32 because I have no x86_64 machine! Please have a look!
Thanks.

Dietmar.

# HG changeset patch
# User [email protected]
# Date 1164206513 -3600
# Node ID 74abfaeeb7ba15d7ca366c814c412d1ccc594532 # Parent 1ef9954a26686b35b946d889726d4d35c283c2a0 Switched to new interfaces HYPERVISOR_sched_op() and HYPERVISOR_event_channel_op().

extras/mini-os/events.c +9 -9
diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/events.c
@@ -88,18 +88,18 @@ void unbind_evtchn(evtchn_port_t port )
 
 int bind_virq(uint32_t virq, evtchn_handler_t handler, void *data)
 {
-	evtchn_bind_virq_t op;
-
-	/* Try to bind the virq to a port */
-	op.virq = virq;
-	op.vcpu = smp_processor_id();
-
-	if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op) != 0 )
+	struct evtchn_bind_virq send =
+	{
+		.virq = virq,
+		.vcpu = smp_processor_id()
+	};
+	if(HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &send) != 0)
 	{
 		printk("Failed to bind virtual IRQ %d\n", virq);
 		return 1;
-    }
-    bind_evtchn(op.port, handler, data);
+	}
+	bind_evtchn(send.port, handler, NULL);
+
 	return 0;
 }
 
extras/mini-os/include/x86/x86_32/hypercall-x86_32.h +23 -4
diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/include/x86/x86_32/hypercall-x86_32.h
@@ -165,9 +165,16 @@ HYPERVISOR_fpu_taskswitch(
 	return _hypercall1(int, fpu_taskswitch, set);
 }
 
+ static inline int
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
@@ -238,9 +245,21 @@ HYPERVISOR_update_va_mapping(
 
 static inline int
 HYPERVISOR_event_channel_op(
-	int cmd, void *op)
-{
-	return _hypercall2(int, event_channel_op, cmd, op);
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, event_channel_op, cmd, arg);
+
+#ifdef CONFIG_XEN_COMPAT_030002
+	if (unlikely(rc == -ENOSYS)) {
+		struct evtchn_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, event_channel_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+
+	return rc;
 }
 
 static inline int
extras/mini-os/include/x86/x86_64/hypercall-x86_64.h +23 -4
diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/include/x86/x86_64/hypercall-x86_64.h
@@ -170,8 +170,15 @@ HYPERVISOR_fpu_taskswitch(
 }
 
 static inline int
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
+static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
@@ -235,9 +242,21 @@ HYPERVISOR_update_va_mapping(
 
 static inline int
 HYPERVISOR_event_channel_op(
-       int cmd, void *op)
-{
-    return _hypercall2(int, event_channel_op, cmd, op);
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, event_channel_op, cmd, arg);
+
+#ifdef CONFIG_XEN_COMPAT_030002
+	if (unlikely(rc == -ENOSYS)) {
+		struct evtchn_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, event_channel_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+
+	return rc;
 }
 
 static inline int
extras/mini-os/kernel.c +11 -1
diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/kernel.c
@@ -28,6 +28,7 @@
  */
 
 #include <os.h>
+#include <errno.h>
 #include <hypervisor.h>
 #include <mm.h>
 #include <events.h>
@@ -159,5 +160,14 @@ void do_exit(void)
 void do_exit(void)
 {
     printk("Do_exit called!\n");
-    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
+    for( ;; )
+    {
+        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+        int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+        if(rc == -ENOSYS)
+        {
+            HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, SHUTDOWN_crash);
+        }
+    }
 }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

You've dropped 'data' from bind_evtchn() call in your changes to events.c. That breaks our API, where event handler gets void* to some piece of data supplied when binding a channel. It looks to me that no changes to events.c are required whatsoever.

Apart of that everything looks fine. Could you resend the patch?

Cheers
Gregor

Quoted 173 lines · Dietmar Hahn

Hi,

this patch switches to the newer interfaces for HYPERVISOR_sched_op() and HYPERVISOR_event_channel_op(). I testet it only on x86_32 because I have no x86_64 machine! Please have a look!
Thanks.

Dietmar.

------------------------------------------------------------------------

# HG changeset patch
# User [email protected]
# Date 1164206513 -3600
# Node ID 74abfaeeb7ba15d7ca366c814c412d1ccc594532 # Parent 1ef9954a26686b35b946d889726d4d35c283c2a0 Switched to new interfaces HYPERVISOR_sched_op() and HYPERVISOR_event_channel_op().

diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/events.c

extras/mini-os/events.c +9 -9
@@ -88,18 +88,18 @@ void unbind_evtchn(evtchn_port_t port )
 
 int bind_virq(uint32_t virq, evtchn_handler_t handler, void *data)
 {
-	evtchn_bind_virq_t op;
-
-	/* Try to bind the virq to a port */
-	op.virq = virq;
-	op.vcpu = smp_processor_id();
-
-	if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op) != 0 )
+	struct evtchn_bind_virq send =
+	{
+		.virq = virq,
+		.vcpu = smp_processor_id()
+	};
+	if(HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &send) != 0)
 	{
 		printk("Failed to bind virtual IRQ %d\n", virq);
 		return 1;
-    }
-    bind_evtchn(op.port, handler, data);
+	}
+	bind_evtchn(send.port, handler, NULL);
+
 	return 0;
 }
 

diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/include/x86/x86_32/hypercall-x86_32.h

extras/mini-os/include/x86/x86_32/hypercall-x86_32.h +23 -4
@@ -165,9 +165,16 @@ HYPERVISOR_fpu_taskswitch(
 	return _hypercall1(int, fpu_taskswitch, set);
 }
 
+ static inline int
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
@@ -238,9 +245,21 @@ HYPERVISOR_update_va_mapping(
 
 static inline int
 HYPERVISOR_event_channel_op(
-	int cmd, void *op)
-{
-	return _hypercall2(int, event_channel_op, cmd, op);
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, event_channel_op, cmd, arg);
+
+#ifdef CONFIG_XEN_COMPAT_030002
+	if (unlikely(rc == -ENOSYS)) {
+		struct evtchn_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, event_channel_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+
+	return rc;
 }
 
 static inline int

diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/include/x86/x86_64/hypercall-x86_64.h

extras/mini-os/include/x86/x86_64/hypercall-x86_64.h +23 -4
@@ -170,8 +170,15 @@ HYPERVISOR_fpu_taskswitch(
 }
 
 static inline int
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
+static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
@@ -235,9 +242,21 @@ HYPERVISOR_update_va_mapping(
 
 static inline int
 HYPERVISOR_event_channel_op(
-       int cmd, void *op)
-{
-    return _hypercall2(int, event_channel_op, cmd, op);
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, event_channel_op, cmd, arg);
+
+#ifdef CONFIG_XEN_COMPAT_030002
+	if (unlikely(rc == -ENOSYS)) {
+		struct evtchn_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, event_channel_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+
+	return rc;
 }
 
 static inline int

diff -r 1ef9954a2668 -r 74abfaeeb7ba extras/mini-os/kernel.c

extras/mini-os/kernel.c +11 -1
@@ -28,6 +28,7 @@
  */
 
 #include <os.h>
+#include <errno.h>
 #include <hypervisor.h>
 #include <mm.h>
 #include <events.h>
@@ -159,5 +160,14 @@ void do_exit(void)
 void do_exit(void)
 {
     printk("Do_exit called!\n");
-    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
+    for( ;; )
+    {
+        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+        int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+        if(rc == -ENOSYS)
+        {
+            HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, SHUTDOWN_crash);
+        }
+    }
 }
#2 lore raw

Hi Gregor,

Quoted 4 lines

You've dropped 'data' from bind_evtchn() call in your changes to events.c. That breaks our API, where event handler gets void* to some piece of data supplied when binding a channel. It looks to me that no changes to events.c are required whatsoever.

Sorry, my fault. I overlooked last changes to the HYPERVISOR_event_channel_op() hypercall :-(.
I resend the patch only with the changed hypercall HYPERVISOR_sched_op(). Thanks.

Dietmar.

# HG changeset patch
# User [email protected]
# Date 1164268700 -3600
# Node ID 85056d526e1496d0f3a2449b51e4ba6a2361baec # Parent 2ef0f17a9af9b6b3b2f76460e0f9da5112c0bd79 Switched to new interface for HYPERVISOR_sched_op().

extras/mini-os/include/x86/x86_32/hypercall-x86_32.h +1 -1
diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/include/x86/x86_32/hypercall-x86_32.h
@@ -167,7 +167,7 @@ HYPERVISOR_fpu_taskswitch(
 
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
extras/mini-os/include/x86/x86_64/hypercall-x86_64.h +1 -1
diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/include/x86/x86_64/hypercall-x86_64.h
@@ -171,7 +171,7 @@ HYPERVISOR_fpu_taskswitch(
 
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }
extras/mini-os/kernel.c +5 -1
diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/kernel.c
@@ -159,5 +159,9 @@ void do_exit(void)
 void do_exit(void)
 {
     printk("Do_exit called!\n");
-    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
+    for( ;; )
+    {
+        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+    }
 }

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

This patch looks all fine. Tested on both 32 and 64 bit machines.

Keir could you apply please.

Thanks.
Grerog

Quoted 62 lines · Dietmar Hahn

Hi Gregor,

Quoted 4 lines

You've dropped 'data' from bind_evtchn() call in your changes to events.c. That breaks our API, where event handler gets void* to some piece of data supplied when binding a channel. It looks to me that no changes to events.c are required whatsoever.

Sorry, my fault. I overlooked last changes to the HYPERVISOR_event_channel_op() hypercall :-(. I resend the patch only with the changed hypercall HYPERVISOR_sched_op(). Thanks.

Dietmar.

------------------------------------------------------------------------

# HG changeset patch
# User [email protected]
# Date 1164268700 -3600
# Node ID 85056d526e1496d0f3a2449b51e4ba6a2361baec # Parent 2ef0f17a9af9b6b3b2f76460e0f9da5112c0bd79 Switched to new interface for HYPERVISOR_sched_op().

diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/include/x86/x86_32/hypercall-x86_32.h

extras/mini-os/include/x86/x86_32/hypercall-x86_32.h +1 -1
@@ -167,7 +167,7 @@ HYPERVISOR_fpu_taskswitch(
 
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }

diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/include/x86/x86_64/hypercall-x86_64.h

extras/mini-os/include/x86/x86_64/hypercall-x86_64.h +1 -1
@@ -171,7 +171,7 @@ HYPERVISOR_fpu_taskswitch(
 
 static inline int
 HYPERVISOR_sched_op(
-	int cmd, unsigned long arg)
+	int cmd, void *arg)
 {
 	return _hypercall2(int, sched_op, cmd, arg);
 }

diff -r 2ef0f17a9af9 -r 85056d526e14 extras/mini-os/kernel.c

extras/mini-os/kernel.c +5 -1
@@ -159,5 +159,9 @@ void do_exit(void)
 void do_exit(void)
 {
     printk("Do_exit called!\n");
-    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
+    for( ;; )
+    {
+        struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash };
+        HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
+    }
 }