x86/hvm: Allow guest_request vm_events coming from userspace
PATCH v6 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 V5:
- Added the bool allow_userspace to the xc_monitor_guest_request function
--- 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-x86/domain.h | 19 ++++++++++--------- xen/include/public/domctl.h | 1 + 6 files changed, 20 insertions(+), 11 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
@@ -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
@@ -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
@@ -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
@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop->u.guest_request.allow_userspace;domain_unpause (d);break ; }
xen/include/asm-x86/domain.h +10 -9
@@ -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/public/domctl.h +1 -0
@@ -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
Quoted 9 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_eventdirectly from userspace.Signed-off-by Alexandru Isaila <[email protected]>
Quoted 119 lines
---
Changes since V5:
- Added the boolallow_userspaceto thexc_monitor_guest_requestfunction--- 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-x86/domain.h | 19 ++++++++++--------- xen/include/public/domctl.h | 1 + 6 files changed, 20 insertions(+), 11 deletions(-)tools/libxc/include/xenctrl.h +1
-1@@ -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@@ -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@@ -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@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop->u.guest_request.allow_userspace;domain_unpause (d);break ; }xen/include/asm-x86/domain.h +10
-9@@ -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/public/domctl.h +1
-1@@ -1124,6 +1124,7 @@ struct xen_domctl_monitor_op {struct {/* Pause vCPU until response */ uint8_t sync; +uint8_t allow_userspace; } guest_request;struct { --
Quoted 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
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_eventdirectly from userspace.Signed-off-by Alexandru Isaila <[email protected]>
Quoted 7 lines
---
Changes since V5:
- Added the boolallow_userspaceto thexc_monitor_guest_requestfunction--- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_monitor.c | 3 ++-
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
xen/common/monitor.c int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) · line 78
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop->u.guest_request.allow_userspace;
This breaks the build on ARM.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop-
Quoted 2 lines
xen/common/monitor.c int monitor_domctl(struct domain *d, struct · line 80
Quoted 1 line
xen/common/monitor.c +0
-0>u.guest_request.allow_userspace;This breaks the build on ARM.
There are 2 solutions, I can move the case in x86/monitor.c in the arch_monitor_domctl_event function or I can make a arch specific function that does the assignment in the x86 case and does nothing in the arm case. What approach do you prefer?
Quoted 6 lines
Jan
________________________
This email was scanned by Bitdefender
Thanks,
Alex
________________________
This email was scanned by Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.08.17 at 15:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop-
Quoted 6 lines
Quoted 2 lines
xen/common/monitor.c int monitor_domctl(struct domain *d, struct · line 80
Quoted 1 line
xen/common/monitor.c +0
-0>u.guest_request.allow_userspace;This breaks the build on ARM.
There are 2 solutions, I can move the case in
x86/monitor.cin thearch_monitor_domctl_eventfunction or I can make a arch specific function that does the assignment in the x86 case and does nothing in the arm case. What approach do you prefer?
That's a question to the maintainers of that code. What I care about is that patches touching common code please are at least build-checked on the other architecture before submission.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 25.08.17 at 15:00, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
xen/common/monitor.c int monitor_domctl(struct domain *d, struct · line 80
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop- >u.guest_request.allow_userspace;This breaks the build on ARM.
Quoted 9 lines
Quoted 4 lines
There are 2 solutions, I can move the case in
x86/monitor.cin thearch_monitor_domctl_eventfunction or I can make a arch specific function that does the assignment in the x86 case and does nothing in the arm case. What approach do you prefer?That's a question to the maintainers of that code. What I care about is that patches touching common code please are at least build-checked on the other architecture before submission.
Ough, yes, please build-check your code on both architectures before sending them. As for which route to take I prefer in this case doing the arch specific function that does the assignment when needed and is empty when not. The function itself could probably be declared as static inline too.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 25.08.17 at 15:00, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
xen/common/monitor.c int monitor_domctl(struct domain *d, struct · line 80
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop- > u.guest_request.allow_userspace;This breaks the build on ARM.
Quoted 8 lines
Quoted 4 lines
There are 2 solutions, I can move the case in
x86/monitor.cin thearch_monitor_domctl_eventfunction or I can make a arch specific function that does the assignment in the x86 case and does nothing in the arm case. What approach do you prefer?That's a question to the maintainers of that code. What I care about is that patches touching common code please are at least build-checked on the other architecture before submission.
I don't think this is a reasonable requirement. That's what push gates (and Travis) are for.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 25.08.17 at 17:49, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 25.08.17 at 15:00, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines · On 17.08.17 at 13:50, <[email protected]> wrote:
xen/common/monitor.c +1
-0@@ -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; + d->arch.monitor.guest_request_userspace_enabled = mop-Quoted 2 lines
xen/common/monitor.c int monitor_domctl(struct domain *d, struct · line 80
Quoted 1 line
xen/common/monitor.c +0
-0> u.guest_request.allow_userspace;This breaks the build on ARM.
There are 2 solutions, I can move the case in
x86/monitor.cin thearch_monitor_domctl_eventfunction or I can make a arch specific function that does the assignment in the x86 case and does nothing in the arm case. What approach do you prefer?
Quoted 6 lines
Quoted 3 lines
That's a question to the maintainers of that code. What I care about is that patches touching common code please are at least build-checked on the other architecture before submission.
I don't think this is a reasonable requirement. That's what push gates (and Travis) are for.
Hmm, I can see your way of thinking, but to me (doing an ARM build test if I don't forget it before pushing) it's a waste of time to apply a patch only to then find it breaks the build and needs reverting.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel