From patchwork Fri Aug 4 11:32:04 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: 9881039 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 9210E60375 for ; Fri, 4 Aug 2017 11:34:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87DC2289A8 for ; Fri, 4 Aug 2017 11:34:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C2F8289BE; Fri, 4 Aug 2017 11:34:45 +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 EDB77289A8 for ; Fri, 4 Aug 2017 11:34:44 +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 1ddaq8-00024v-9f; Fri, 04 Aug 2017 11:32:24 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddaq6-00024p-Ds for xen-devel@lists.xen.org; Fri, 04 Aug 2017 11:32:22 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 88/C1-01724-54B54895; Fri, 04 Aug 2017 11:32:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42KJPp7RqusS3RJ pcG6dkcWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrHyxQHmgqdGFQ9OrGNsYDyo1sXIycEsYC3R +6+ZsYuRi4NFoJlF4l1rPyuE85NZ4unBZpYuRg4OIQE3idObikDiQgLzGSVmnD7BBtINEr9y8 DMTRGIpo8SbRcdZQRJsAgYSr75+YwSxRQSkJa59vgy2gllgAZPEutlr2UESwgIBEvP61oAVsQ ioSsxf1wY2lRdo6vrFP1hAbAkBOYmb5zqZJzDyLWBkWMWoXpxaVJZapGuul1SUmZ5RkpuYmaN raGCsl5taXJyYnpqTmFSsl5yfu4kRGCoMQLCDsfG70yFGSQ4mJVHe6mNNkUJ8SfkplRmJxRnx RaU5qcWHGGU4OJQkeP9FtkQKCRalpqdWpGXmAIMWJi3BwaMkwrsCJM1bXJCYW5yZDpE6xWjMs WH1+i9MHK8m/P/GJMSSl5+XKiXO+wekVACkNKM0D24QLJouMcpKCfMyAp0mxFOQWpSbWYIq/4 pRnINRSZj3G8gUnsy8Erh9r4BOYQI65U9dI8gpJYkIKakGxu4j1+bM7glhtEiLeKHof8nCn3f bnNbz8VksjkJ71RhznBW+d3y9WPZs2uEa/eDHMq73fS9ObXz0ruK1edt/D43L73Qv23wOnLCO 3VnSdTpX89ylegdravMcHgvPKBIIP/szunoyF8fdryfmXT3tf/VhjUj4qg1519y+qLBPmBjeO f/nv+OL7ZRYijMSDbWYi4oTAf+B0UihAgAA X-Env-Sender: aisaila@bitdefender.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1501846340!108442932!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 20999 invoked from network); 4 Aug 2017 11:32:20 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-14.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 4 Aug 2017 11:32:20 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=lC5orBm/HB6lmgRuJNzchLMt87RnnnkG1Nn5fJCPp1AcaNgAozbqCxSp0Iy6NyGQrbyv+B9C8tumup/JBkUZrPhULYTXTliUOSaSLc3ezcxhB8RCdukj/CxM8qphmp0Y1HYvGnheZig3tWXkJHQ6yLsrzD3UzufsfLh9FeVN5Srak6X7u6pr6LZKv5bacV6RFzDxH97YKh8B2IgXfb8DUlzQW17/ONe1NKNzNxMAO8WQx/fPCfMnTiiUv7G0b6rknaO/RbdTBKM1HJvaCLX5pFe/OKx4CCW9O6LdsCPpOv9kjU1K9cWCjHrtdcABqkeOGD5fOHQUmxFxQbeLnBgRVA==; 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=mXGSDk5CsVzM9r66JHvL/ n55jAI=; b=AGpHIpb/WSEaLvcpuQk45HCXecoJTaBAE3pO/d8TxuhC1MeJ0fDU6 UX+hPtn7FNTu2+o57l6+1bvh50/pk8JLOXo/uYm6ho/1+Zc8rP0anQGhCoe3rDQV vgme1rYgIVxuYtq51iLh2G+wB9GovFoE+6YjSKQ4xnSSpKJkRM2IAPoTVvNrHD5J VKgbTzZtwXDjRnfeAb+YnaHootwddzgicTDfVnglFMZzmoFSlAhH1+ok/pNVVJR3 7f8GoVr2utKe+13leZcKPe0QIGbMIZCTIuYbSt+Ay1HIG+0XBJ8c31p0kr2Ozq72 WjC63K9WbDiLK61Nueahg1aJvwEBnGNsQ== Received: (qmail 2130 invoked from network); 4 Aug 2017 14:32:18 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 4 Aug 2017 14:32:18 +0300 Received: (qmail 3076 invoked from network); 4 Aug 2017 14:32:18 +0300 Received: from unknown (HELO aisaila-Latitude-E5570.dsd.bitdefender.biz) (10.10.195.54) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 4 Aug 2017 14:32:18 +0300 From: Alexandru Isaila To: xen-devel@lists.xen.org Date: Fri, 4 Aug 2017 14:32:04 +0300 Message-Id: <1501846324-4683-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 v4] 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 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. Signed-off-by: Alexandru Isaila Reviewed-by: Andrew Cooper , with one note to --- Changes since V3: - Changed commit message - Added new lines - Indent the maximum space on the defines - Chaned the name of the define/function name/struct member from vmcall to event --- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_monitor.c | 14 ++++++++++++++ xen/arch/x86/hvm/hypercall.c | 5 +++++ xen/common/monitor.c | 14 ++++++++++++++ xen/include/public/domctl.h | 21 +++++++++++---------- xen/include/xen/sched.h | 5 +++-- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index bde8313..90a056f 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2022,6 +2022,7 @@ 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_allow_guest_userspace_event(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..6064c39 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_event(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_EVENT; + + 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..8eb5f49 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -155,6 +155,11 @@ int hvm_hypercall(struct cpu_user_regs *regs) /* Fallthrough to permission check. */ case 4: case 2: + if ( currd->monitor.guest_request_userspace_event && + eax == __HYPERVISOR_hvm_op && + (mode == 8 ? regs->rdi : 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..21a1457 100644 --- a/xen/common/monitor.c +++ b/xen/common/monitor.c @@ -79,6 +79,20 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) break; } + case XEN_DOMCTL_MONITOR_EVENT_GUEST_USERSPACE_EVENT: + { + 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_event = requested_status; + domain_unpause(d); + break; + } + default: /* Give arch-side the chance to handle this event */ return arch_monitor_domctl_event(d, mop); diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index ff39762..870495c 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_EVENT 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..898a132 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_event : 1; } monitor; };