From patchwork Thu Aug 3 15:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 9879351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D2725603B4 for ; Thu, 3 Aug 2017 15:31:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C47AD2872C for ; Thu, 3 Aug 2017 15:31:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8ECC28945; Thu, 3 Aug 2017 15:31:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 92C0C2872C for ; Thu, 3 Aug 2017 15:31:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddI3q-0000NQ-QR; Thu, 03 Aug 2017 15:29:18 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddI3p-0000NH-P8 for xen-devel@lists.xen.org; Thu, 03 Aug 2017 15:29:17 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id CB/7B-02177-C4143895; Thu, 03 Aug 2017 15:29:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42KJPp7Rquvj2Bx psOW0qMWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmtF2Sb3ggmHFjdXXmBsY36t1MXJyMAtYS/T+ a2bsYuTiYBFoZpHY8G86E4Tzk1liV/9bNpAqIQF3idXnV4NVCQnMZ5T492wxO0TCTeL/zvVQi aWMEufubWEESbAJGEi8+voNzBYRkJa49vkyWBGzwAImiXWz14J1CwsESGxc18HcxcgBtE9V4v KzWpAwL9C26af3sYDYEgJyEjfPdTJPYORbwMiwilGjOLWoLLVI19BcL6koMz2jJDcxM0fX0MB ULze1uDgxPTUnMalYLzk/dxMjMFQYgGAH48XTnocYJTmYlER5q481RQrxJeWnVGYkFmfEF5Xm pBYfYpTh4FCS4F1p3xwpJFiUmp5akZaZAwxamLQEB4+SCG8ASJq3uCAxtzgzHSJ1itGYY8Pq9 V+YOF5N+P+NSYglLz8vVUqctwSkVACkNKM0D24QLJouMcpKCfMyAp0mxFOQWpSbWYIq/4pRnI NRSZj3OsgUnsy8Erh9r4BOYQI65U9dI8gpJYkIKakGRpkkPpZTmydpuq/4pPL96NoNpbtFT7R 8MsgUcgnKUjW2u18k5n51IddEPjWpVQ1RCUWZybm5my6m5aQ6zQhaHCccXFP5bPm8Roe94Ubn 9+RJH17j9e2Y1b+pxn1TZu1VTg77bdRYdvcu1+16XcXaSz5PTt95eXrlz2P3WjyfmTPJ1xws+ H4uQomlOCPRUIu5qDgRACPdn4ahAgAA X-Env-Sender: aisaila@bitdefender.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1501774155!77314230!1 X-Originating-IP: [91.199.104.133] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56826 invoked from network); 3 Aug 2017 15:29:16 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-10.tower-206.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 3 Aug 2017 15:29:16 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=HKQqTsZW76yebMeC516oQndWbFsuhe7e0RtDPETMa78Tq+Jckp7TCD/ZOddpk5SNzijSfWWAds2buKVRffKxQQKL6bgtrwq58lPuDC4QK/5TPagr3NRgM5pDN26h06eWmuOcpqrSZIcNwAwG6E6Ce873hG8TM0FnYUWq3Ff0QjaEtZXYdCH3gPfnBtRyz4YvojStfl0w7t1uCXy0ZR+Hvy0ptPeB/98OqX15lkW1xC0eCETEO3cRjSRJiIPL2bpDxKCG5kyZgJ3818M8qC0B2mmvFT3gby0xAyq7FBx4gM1BS3RzMuLDQ2X7X81utyI4Vqnf5VYT5iXZSsUniOY0yQ==; h=Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id; s=default; bh=hn4vxSlsccvDnQa0o1ZxN xuw+6A=; b=zOorDXvaS0uAz3Ogetx4IxudXuLmVawHVH66nU0sugAY7rjAGbLwM BsXMqe2cbhxcnOrpl+bHWxZYfIllmd1F5K+Tk/vSuRJaTqXS9CNpTUDNUKSbJQDe 9AIIdQLLkFHdsUbCq+8gCpVASWv/al6dtWKFRKHEK5YOgym1yWtIzl/LnEBqZteR X3KhxuvnFWOfIJ28EZ78EfvzAYbuDHwpOvTDxK9klfuGg6RDQjtY16vdq/t/pEx2 ldmQdRGvcppD+n/EBE00vq5Azv6WVxSckLSDiffstoyqRGGziRq2G263+76w0oug neeOE/dmC1asto6ZDHSgFLNCy91IK0zAw== Received: (qmail 21276 invoked from network); 3 Aug 2017 18:29:13 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 3 Aug 2017 18:29:13 +0300 Received: (qmail 1135 invoked from network); 3 Aug 2017 18:29:12 +0300 Received: from unknown (HELO aisaila-Latitude-E5570.dsd.bitdefender.biz) (10.10.195.54) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 3 Aug 2017 18:29:12 +0300 From: Alexandru Isaila To: xen-devel@lists.xen.org Date: Thu, 3 Aug 2017 18:29:10 +0300 Message-Id: <1501774150-11683-1-git-send-email-aisaila@bitdefender.com> X-Mailer: git-send-email 2.7.4 Cc: sstabellini@kernel.org, wei.liu2@citrix.com, rcojocaru@bitdefender.com, George.Dunlap@eu.citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, tamas@tklengyel.com, jbeulich@suse.com, andrew.cooper3@citrix.com, Alexandru Isaila Subject: [Xen-devel] [PATCH v3] x86/hvm: Allow guest_request vm_events coming from userspace X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Allow guest userspace code to request that a vm_event be sent out via VMCALL. This functionality seems to be handy for a number of Xen developers, as stated on the mailing list (thread "[Xen-devel] HVMOP_guest_request_vm_event only works from guest in ring0"). This is a use case in communication between a userspace application in the guest and the introspection application in dom0. Signed-off-by: Alexandru Isaila --- Changes since V2: -Added a new flag to enable the vm call from the guest userspace --- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_monitor.c | 14 ++++++++++++++ xen/arch/x86/hvm/hypercall.c | 8 ++++++++ xen/common/monitor.c | 13 +++++++++++++ xen/include/public/domctl.h | 21 +++++++++++---------- xen/include/xen/sched.h | 5 +++-- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index bde8313..eed60db 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2022,6 +2022,8 @@ 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); +int xc_monitor_guest_userspace_vmcall(xc_interface *xch, domid_t domain_id, + bool enable); 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); diff --git a/tools/libxc/xc_monitor.c b/tools/libxc/xc_monitor.c index b44ce93..63c6320 100644 --- a/tools/libxc/xc_monitor.c +++ b/tools/libxc/xc_monitor.c @@ -161,6 +161,20 @@ int xc_monitor_guest_request(xc_interface *xch, domid_t domain_id, bool enable, return do_domctl(xch, &domctl); } +int xc_allow_guest_userspace_vmcall(xc_interface *xch, domid_t domain_id, bool enable) +{ + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_monitor_op; + domctl.domain = domain_id; + domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE + : XEN_DOMCTL_MONITOR_OP_DISABLE; + domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_GUEST_USERSPACE_VMCALL; + + return do_domctl(xch, &domctl); +} + + int xc_monitor_emulate_each_rep(xc_interface *xch, domid_t domain_id, bool enable) { diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index e7238ce..c7fab4b 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -152,9 +152,17 @@ int hvm_hypercall(struct cpu_user_regs *regs) { case 8: eax = regs->rax; + if ( currd->monitor.guest_request_userspace_vmcall && + eax == __HYPERVISOR_hvm_op && + regs->rdi == HVMOP_guest_request_vm_event ) + break; /* Fallthrough to permission check. */ case 4: case 2: + if ( mode != 8 && currd->monitor.guest_request_userspace_vmcall && + eax == __HYPERVISOR_hvm_op && + regs->ebx == HVMOP_guest_request_vm_event ) + break; if ( unlikely(hvm_get_cpl(curr)) ) { default: diff --git a/xen/common/monitor.c b/xen/common/monitor.c index 451f42f..4011dc3 100644 --- a/xen/common/monitor.c +++ b/xen/common/monitor.c @@ -78,6 +78,19 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) domain_unpause(d); break; } + case XEN_DOMCTL_MONITOR_EVENT_GUEST_USERSPACE_VMCALL: + { + bool_t old_status = d->monitor.guest_request_enabled; + + if ( unlikely(old_status == requested_status) ) + return -EEXIST; + + domain_pause(d); + d->monitor.guest_request_sync = mop->u.guest_request.sync; + d->monitor.guest_request_userspace_vmcall = requested_status; + domain_unpause(d); + break; + } default: /* Give arch-side the chance to handle this event */ diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index ff39762..e782517 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1073,16 +1073,17 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); #define XEN_DOMCTL_MONITOR_OP_GET_CAPABILITIES 2 #define XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP 3 -#define XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG 0 -#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR 1 -#define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP 2 -#define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 3 -#define XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST 4 -#define XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION 5 -#define XEN_DOMCTL_MONITOR_EVENT_CPUID 6 -#define XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL 7 -#define XEN_DOMCTL_MONITOR_EVENT_INTERRUPT 8 -#define XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS 9 +#define XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG 0 +#define XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR 1 +#define XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP 2 +#define XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT 3 +#define XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST 4 +#define XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION 5 +#define XEN_DOMCTL_MONITOR_EVENT_CPUID 6 +#define XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL 7 +#define XEN_DOMCTL_MONITOR_EVENT_INTERRUPT 8 +#define XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS 9 +#define XEN_DOMCTL_MONITOR_EVENT_GUEST_USERSPACE_VMCALL 10 struct xen_domctl_monitor_op { uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 6673b27..11137b0 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -480,8 +480,9 @@ struct domain /* Common monitor options */ struct { - unsigned int guest_request_enabled : 1; - unsigned int guest_request_sync : 1; + unsigned int guest_request_enabled : 1; + unsigned int guest_request_sync : 1; + unsigned int guest_request_userspace_vmcall : 1; } monitor; };