Skip to contentSkip to conversation

x86/hvm: Allow guest_request vm_events coming from userspace

PATCH In review Alexandru Isaila 3 participants 4 messages Aug 29, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 x86/hvm: Allow guest_request vm_events coming from userspace

In some introspection usecases, an in-guest agent needs to communicate with the external introspection agent. An existing mechanism is HVMOP_guest_request_vm_event, but this is restricted to kernel usecases like all other hypercalls.

Introduce a mechanism whereby the introspection agent can whitelist the use of HVMOP_guest_request_vm_event directly from userspace.

---
Changes since V9:
- Changed allow_userspace type from uint8_t ro bool
- Added Wei Liu's ack from v7

Note: Could not test on ARM, compiled both on arm and x86

---
 tools/libxc/include/xenctrl.h |  2 +-
 tools/libxc/xc_monitor.c      |  3 ++-
 xen/arch/x86/hvm/hypercall.c  |  5 +++++
 xen/common/monitor.c          |  1 +
 xen/include/asm-arm/monitor.h |  6 ++++++
 xen/include/asm-x86/domain.h  | 19 ++++++++++---------
 xen/include/asm-x86/monitor.h |  6 ++++++
 xen/include/public/domctl.h   |  1 +
 8 files changed, 32 insertions(+), 11 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
index bde8313..a3d0929 100644
@@ -2021,7 +2021,7 @@ int xc_monitor_software_breakpoint(xc_interface *xch, domid_t domain_id,
 int xc_monitor_descriptor_access(xc_interface *xch, domid_t domain_id,
                                  bool enable);
 int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id,
-                             bool enable, bool sync);
+                             bool enable, bool sync, bool allow_userspace);
 int xc_monitor_debug_exceptions(xc_interface *xch, domid_t domain_id,
                                 bool enable, bool sync);
 int xc_monitor_cpuid(xc_interface *xch, domid_t domain_id, bool enable);
tools/libxc/xc_monitor.c +2 -1
index b44ce93..a677820 100644
@@ -147,7 +147,7 @@ int xc_monitor_descriptor_access(xc_interface *xch, domid_t domain_id,
 }
 
 int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id, bool enable,
-                             bool sync)
+                             bool sync, bool allow_userspace)
 {
     DECLARE_DOMCTL;
 
@@ -157,6 +157,7 @@ int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id, bool enable,
                                     : XEN_DOMCTL_MONITOR_OP_DISABLE;
     domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST;
     domctl.u.monitor_op.u.guest_request.sync = sync;
+    domctl.u.monitor_op.u.guest_request.allow_userspace = enable ? allow_userspace : false;
 
     return do_domctl(xch, &domctl);
 }
xen/arch/x86/hvm/hypercall.c +5 -0
index e7238ce..5742dd1 100644
@@ -155,6 +155,11 @@ int hvm_hypercall(struct cpu_user_regs *regs)
         /* Fallthrough to permission check. */
     case 4:
     case 2:
+        if ( currd->arch.monitor.guest_request_userspace_enabled &&
+            eax == __HYPERVISOR_hvm_op &&
+            (mode == 8 ? regs->rdi : regs->ebx) == HVMOP_guest_request_vm_event )
+            break;
+
         if ( unlikely(hvm_get_cpl(curr)) )
         {
     default:
xen/common/monitor.c +1 -0
index 451f42f..4c540e5 100644
@@ -75,6 +75,7 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop)
         domain_pause(d);
         d->monitor.guest_request_sync = mop->u.guest_request.sync;
         d->monitor.guest_request_enabled = requested_status;
+        arch_monitor_allow_userspace(d, mop->u.guest_request.allow_userspace);
         domain_unpause(d);
         break;
     }
xen/include/asm-arm/monitor.h +6 -0
index 1c4fea3..2bdad7d 100644
@@ -26,6 +26,12 @@
 #include <public/domctl.h>
 
 static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+    return;
+}
+
+static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
     /* No arch-specific monitor ops on ARM. */
xen/include/asm-x86/domain.h +10 -9
index c10522b..de02507 100644
@@ -396,15 +396,16 @@ struct arch_domain
 
     /* Arch-specific monitor options */
     struct {
-        unsigned int write_ctrlreg_enabled       : 4;
-        unsigned int write_ctrlreg_sync          : 4;
-        unsigned int write_ctrlreg_onchangeonly  : 4;
-        unsigned int singlestep_enabled          : 1;
-        unsigned int software_breakpoint_enabled : 1;
-        unsigned int debug_exception_enabled     : 1;
-        unsigned int debug_exception_sync        : 1;
-        unsigned int cpuid_enabled               : 1;
-        unsigned int descriptor_access_enabled   : 1;
+        unsigned int write_ctrlreg_enabled                                 : 4;
+        unsigned int write_ctrlreg_sync                                    : 4;
+        unsigned int write_ctrlreg_onchangeonly                            : 4;
+        unsigned int singlestep_enabled                                    : 1;
+        unsigned int software_breakpoint_enabled                           : 1;
+        unsigned int debug_exception_enabled                               : 1;
+        unsigned int debug_exception_sync                                  : 1;
+        unsigned int cpuid_enabled                                         : 1;
+        unsigned int descriptor_access_enabled                             : 1;
+        unsigned int guest_request_userspace_enabled                       : 1;
         struct monitor_msr_bitmap *msr_bitmap;
         uint64_t write_ctrlreg_mask[4];
     } monitor;
xen/include/asm-x86/monitor.h +6 -0
index c5c323b..765d0b4 100644
@@ -33,6 +33,12 @@ struct monitor_msr_bitmap {
 };
 
 static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+    d->arch.monitor.guest_request_userspace_enabled = allow_userspace;
+}
+
+static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
     int rc = 0;
xen/include/public/domctl.h +1 -0
index ff39762..5997c52 100644
@@ -1124,6 +1124,7 @@ struct xen_domctl_monitor_op {
         struct {
             /* Pause vCPU until response */
             uint8_t sync;
+            uint8_t allow_userspace;
         } guest_request;
 
         struct {
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v10 1/1
#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 29.08.17 at 11:23, <[email protected]> wrote:

In some introspection usecases, an in-guest agent needs to communicate with the external introspection agent. An existing mechanism is HVMOP_guest_request_vm_event, but this is restricted to kernel usecases like all other hypercalls.

Introduce a mechanism whereby the introspection agent can whitelist the use of HVMOP_guest_request_vm_event directly from userspace.

For the pieces it applies to

However, as I keep looking at pieces which shouldn't really require my attention, I've noticed one more cosmetic issue:

xen/include/asm-arm/monitor.h line 32

Quoted 10 lines
xen/include/asm-arm/monitor.h +4 -0
@@ -26,6 +26,12 @@
 #include <public/domctl.h>
 
 static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+    return;
+}

I don't see the point of the return statement here. But I'll leave it to the ARM maintainers, and it would be easy to drop while committing if no other issues are going to arise.

Jan

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

#2 lore raw
Quoted 23 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 29.08.17 at 11:23, <[email protected]> wrote:

In some introspection usecases, an in-guest agent needs to communicate with the external introspection agent. An existing mechanism is HVMOP_guest_request_vm_event, but this is restricted to kernel usecases like all other hypercalls.

Introduce a mechanism whereby the introspection agent can whitelist the use of HVMOP_guest_request_vm_event directly from userspace.

For the pieces it applies to

However, as I keep looking at pieces which shouldn't really require my attention, I've noticed one more cosmetic issue:

Quoted 5 lines
xen/include/asm-arm/monitor.h +0 -0
@@ -26,6 +26,12 @@
 #include <public/domctl.h>
 
Quoted 10 lines

xen/include/asm-arm/monitor.h line 32

Quoted 5 lines
xen/include/asm-arm/monitor.h +4 -0
 static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+    return;
+}

I don't see the point of the return statement here. But I'll leave it to the ARM maintainers, and it would be easy to drop while committing if no other issues are going to arise.

I would bet that a sane compiler wouldn't generate anything for that with or without return in there but sure, if we can drop it then why not.

Tamas

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

Acked-by on v10 1/1
#3 lore raw
In reply to Alexandru Isaila
Quoted 10 lines · Alexandru Isaila

In some introspection usecases, an in-guest agent needs to communicate with the external introspection agent. An existing mechanism is HVMOP_guest_request_vm_event, but this is restricted to kernel usecases like all other hypercalls.

Introduce a mechanism whereby the introspection agent can whitelist the use of HVMOP_guest_request_vm_event directly from userspace.

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