Skip to contentSkip to conversation

xen/evtchn: Implement EVTCHNOP_send_imm as a companian to EVTCHNOP_send

RFC PATCH In review Andrew Cooper 6 participants 9 messages Jul 13, 2017 – Jul 17, 2017

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 xen/evtchn: Implement EVTCHNOP_send_imm as a companian to EVTCHNOP_send

The event channel ABI passes a pointer to a subop-specific structure. Some of these structures however are smaller than the pointers passed in the ABI; EVTCHNOP_send specifically passes a 4 byte evtchn port, using a 4 or 8 byte pointer.

For translated guests (x86 HVM and all ARM), passing the port number directly avoids a guest pagetable walk, which can be very expensive for Xen to perform.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

RFC: is it worth converting the close, unmask, reset (and possibly expand_array) as well?

---
 xen/common/event_channel.c         |  4 ++++
 xen/include/public/event_channel.h | 13 ++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
xen/common/event_channel.c +4 -0
index c69f9db..79d8614 100644
@@ -1098,6 +1098,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case EVTCHNOP_send_imm:
+        rc = evtchn_send(current->domain, (unsigned long)arg.p);
+        break;
+
     case EVTCHNOP_status: {
         struct evtchn_status status;
         if ( copy_from_guest(&status, arg, 1) != 0 )
xen/include/public/event_channel.h +10 -3
index 44c549d..834787a 100644
@@ -57,6 +57,9 @@
  * `
  * @cmd  == EVTCHNOP_* (event-channel operation).
  * @args == struct evtchn_* Operation-specific extra arguments (NULL if none).
+ *
+ * For @cmd with an _imm suffix, data are passed as an integer, rather than a
+ * pointer to a structure.
  */
 
 /* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */
@@ -64,7 +67,7 @@
 #define EVTCHNOP_bind_virq        1
 #define EVTCHNOP_bind_pirq        2
 #define EVTCHNOP_close            3
-#define EVTCHNOP_send             4
+#define EVTCHNOP_send             4 /* Deprecated.  Use EVTCHNOP_send_imm in preference. */
 #define EVTCHNOP_status           5
 #define EVTCHNOP_alloc_unbound    6
 #define EVTCHNOP_bind_ipi         7
@@ -74,6 +77,7 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#define EVTCHNOP_send_imm        14
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
@@ -186,8 +190,11 @@ struct evtchn_close {
 typedef struct evtchn_close evtchn_close_t;
 
 /*
- * EVTCHNOP_send: Send an event to the remote end of the channel whose local
- * endpoint is <port>.
+ * EVTCHNOP_send{,_imm}: Send an event to the remote end of the channel whose
+ * local endpoint is <port>.
+ *
+ * For EVTCHNOP_send, arg is a pointer to an evtchn_send_t.  For
+ * EVTCHNOP_send_imm, arg is the port directly.
  */
 struct evtchn_send {
     /* IN parameters. */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Andrew Cooper
Sent: 13 July 2017 09:51
To: Xen-devel <[email protected]>
Cc: Juergen Gross <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: [Xen-devel] [PATCH RFC] xen/evtchn: Implement EVTCHNOP_send_imm as a companian to EVTCHNOP_send

The event channel ABI passes a pointer to a subop-specific structure. Some of
these structures however are smaller than the pointers passed in the ABI; EVTCHNOP_send specifically passes a 4 byte evtchn port, using a 4 or 8 byte pointer.

Quoted 6 lines

For translated guests (x86 HVM and all ARM), passing the port number directly
avoids a guest pagetable walk, which can be very expensive for Xen to perform.

LGTM. I suspect this will help performance of PV drivers quite a bit.

Quoted 82 lines

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

RFC: is it worth converting the close, unmask, reset (and possibly expand_array) as well?

---
 xen/common/event_channel.c         |  4 ++++
 xen/include/public/event_channel.h | 13 ++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
xen/common/event_channel.c +4 -0
index c69f9db..79d8614 100644
@@ -1098,6 +1098,10 @@ long do_event_channel_op(int cmd,
 XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case EVTCHNOP_send_imm:
+        rc = evtchn_send(current->domain, (unsigned long)arg.p);
+        break;
+
     case EVTCHNOP_status: {
         struct evtchn_status status;
         if ( copy_from_guest(&status, arg, 1) != 0 )
xen/include/public/event_channel.h +0 -0
index 44c549d..834787a 100644
@@ -57,6 +57,9 @@
  * `
  * @cmd  == EVTCHNOP_* (event-channel operation).
  * @args == struct evtchn_* Operation-specific extra arguments (NULL if

none).
+ *
+ * For @cmd with an _imm suffix, data are passed as an integer, rather than a
+ * pointer to a structure.
*/

/* ` enum event_channel_op { // EVTCHNOP_* => struct evtchn_* */

xen/include/public/event_channel.h +1 -1
@@ -64,7 +67,7 @@
 #define EVTCHNOP_bind_virq        1
 #define EVTCHNOP_bind_pirq        2
 #define EVTCHNOP_close            3
-#define EVTCHNOP_send             4
+#define EVTCHNOP_send             4 /* Deprecated.  Use

EVTCHNOP_send_imm in preference. */

 #define EVTCHNOP_status           5
 #define EVTCHNOP_alloc_unbound    6
 #define EVTCHNOP_bind_ipi         7
xen/include/public/event_channel.h +1 -1
@@ -74,6 +77,7 @@
 #define EVTCHNOP_init_control    11
 #define EVTCHNOP_expand_array    12
 #define EVTCHNOP_set_priority    13
+#define EVTCHNOP_send_imm        14
 /* ` } */
 
 typedef uint32_t evtchn_port_t;
@@ -186,8 +190,11 @@ struct evtchn_close {
 typedef struct evtchn_close evtchn_close_t;
 
 /*
- * EVTCHNOP_send: Send an event to the remote end of the channel

whose local
- * endpoint is <port>.
+ * EVTCHNOP_send{,_imm}: Send an event to the remote end of the channel whose
+ * local endpoint is <port>.
+ *
+ * For EVTCHNOP_send, arg is a pointer to an evtchn_send_t. For
+ * EVTCHNOP_send_imm, arg is the port directly.
*/

 struct evtchn_send {
     /* IN parameters. */
Quoted 8 lines

--
2.1.4

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

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

#2 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

The event channel ABI passes a pointer to a subop-specific structure. Some of these structures however are smaller than the pointers passed in the ABI; EVTCHNOP_send specifically passes a 4 byte evtchn port, using a 4 or 8 byte pointer.

For translated guests (x86 HVM and all ARM), passing the port number directly avoids a guest pagetable walk, which can be very expensive for Xen to perform.

I'm absolutely in favor of the approach.

Could we please discuss which hypercalls should offer an immediate variant before implementing one after the other? I believe those should all be introduced at the same time in order to make deciding which variant to use in domU easier: I don't want to have a boolean for each possible hypercall, but just one.

Juergen

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

#3 lore raw
Quoted 6 lines · Juergen Groß
Quoted 5 lines · Andrew Cooper

The event channel ABI passes a pointer to a subop-specific structure. Some of these structures however are smaller than the pointers passed in the ABI; EVTCHNOP_send specifically passes a 4 byte evtchn port, using a 4 or 8 byte pointer.

Quoted 7 lines
Quoted 4 lines

For translated guests (x86 HVM and all ARM), passing the port number directly avoids a guest pagetable walk, which can be very expensive for Xen to perform.

I'm absolutely in favor of the approach.

+1

Quoted 5 lines

Could we please discuss which hypercalls should offer an immediate variant before implementing one after the other? I believe those should all be introduced at the same time in order to make deciding which variant to use in domU easier: I don't want to have a boolean for each possible hypercall, but just one.

+1

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

#4 lore raw
In reply to Andrew Cooper
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 07/13/17 9:50 AM >>>

RFC: is it worth converting the close, unmask, reset (and possibly expand_array) as well?

I can't see close and even more so reset to be performance critical. Unmask otoh may be (depending on use); no sure about expand_array.

Jan

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

#5 lore raw
Quoted 11 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 13 July 2017 21:36
To: Andrew Cooper <[email protected]>
Cc: Juergen Gross <[email protected]>; [email protected]; Wei Liu <[email protected]>; [email protected]; [email protected]; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH RFC] xen/evtchn: Implement EVTCHNOP_send_imm as a companian to EVTCHNOP_send

Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 07/13/17 9:50 AM >>>

RFC: is it worth converting the close, unmask, reset (and possibly expand_array) as well?

I can't see close and even more so reset to be performance critical. Unmask otoh may be (depending on use); no sure about expand_array.

IIRC the unmask hypercall only needs to be made in certain circumstances when direct unmasking of the fifo structure might race (can't remember the detail offhand), but it still seems like a reasonable target for an immediate argument.

Paul

Quoted 7 lines

Jan

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

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

#6 lore raw
In reply to Andrew Cooper

xen/common/event_channel.c long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1102

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.07.17 at 09:50, <[email protected]> wrote:
xen/common/event_channel.c +2 -0
@@ -1098,6 +1098,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case EVTCHNOP_send_imm:
+        rc = evtchn_send(current->domain, (unsigned long)arg.p);

Two more things: For one this discards the upper half of the 64-bit handle. I'd suggest you instead check it to be zero. And then x86's do_event_channel_op_compat() should refuse to handle "immediate" commands.

Jan

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

#7 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.07.17 at 09:50, <[email protected]> wrote:
xen/common/event_channel.c +0 -0
@@ -1098,6 +1098,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
Quoted 5 lines

xen/common/event_channel.c long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1102

Quoted 2 lines
xen/common/event_channel.c +2 -0
+    case EVTCHNOP_send_imm:
+        rc = evtchn_send(current->domain, (unsigned long)arg.p);

Two more things: For one this discards the upper half of the 64-bit handle. I'd suggest you instead check it to be zero.

+1, keeping in mind that arg will be 32-bit on ARM32 platforms and 64-bit on ARM64 platforms.

Moreover, evtchn_send takes an unsigned int as argument, why are you casting arg.p to (unsigned long)?

Quoted 2 lines

And then x86's do_event_channel_op_compat() should refuse to handle "immediate" commands.

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

#8 lore raw
Quoted 12 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich

xen/common/event_channel.c long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 1102

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.07.17 at 09:50, <[email protected]> wrote:
xen/common/event_channel.c +2 -0
@@ -1098,6 +1098,10 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
     }
 
+    case EVTCHNOP_send_imm:
+        rc = evtchn_send(current->domain, (unsigned long)arg.p);

Two more things: For one this discards the upper half of the 64-bit handle. I'd suggest you instead check it to be zero.

Quoted 5 lines

+1, keeping in mind that arg will be 32-bit on ARM32 platforms and 64-bit on ARM64 platforms.

Moreover, evtchn_send takes an unsigned int as argument, why are you casting arg.p to (unsigned long)?

Because arg.p is a pointer, and casting that to an unsigned int will break on 64bit builds. (IIRC, GCC tolerates casting a pointer to an integer of suitable width, but not if a truncation would happen).

It probably wants to be:

uintptr_t port = (uintptr_t)arg.p;

if ( port > (evtchn_port_t)-1 )

    fail;

to be properly within the C spec.

~Andrew

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