From patchwork Tue Aug 8 08:27:35 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: 9886821 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 23DCB601EB for ; Tue, 8 Aug 2017 08:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14AE1286D5 for ; Tue, 8 Aug 2017 08:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08DC628743; Tue, 8 Aug 2017 08:31:04 +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 5CADF286D5 for ; Tue, 8 Aug 2017 08:31:03 +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 1dezrc-0004Xi-FR; Tue, 08 Aug 2017 08:27:44 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dezrb-0004Xc-Qm for xen-devel@lists.xen.org; Tue, 08 Aug 2017 08:27:43 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id A7/39-03557-EF579895; Tue, 08 Aug 2017 08:27:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsUSfTyjVfdfaWe kwY65ghZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a3TXfYCybYVOx9MZ+9gXG9ThcjJwezgLVE 779mxi5GLg4WgWYWiWPHu1ghnJ/MEu2f2thAqoQE3CVuLG1jAkkICcxnlFjx6zs7TOLu7dvME ImljBJ72y6xgCTYBAwkXn39xghiiwhIS1z7fBlsB7PAAiaJdbPXgnULCwRIfOpvZgaxWQRUJR pfHABr4BVwk7jTuxmsRkJATuLmuU7mCYx8CxgZVjFqFKcWlaUW6Rqa6yUVZaZnlOQmZuboGhq Y6eWmFhcnpqfmJCYV6yXn525iBIYLAxDsYLy9MeAQoyQHk5Io7ybtzkghvqT8lMqMxOKM+KLS nNTiQ4wyHBxKErwZJUA5waLU9NSKtMwcYODCpCU4eJREeM+CpHmLCxJzizPTIVKnGI05Nqxe/ 4WJ49WE/9+YhFjy8vNSpcR514OUCoCUZpTmwQ2CRdQlRlkpYV5GoNOEeApSi3IzS1DlXzGKcz AqCfNOBpnCk5lXArfvFdApTECnRPiCnVKSiJCSamAskEnn6l2VevmCVoZG+6ZwrbxMm1NvFrx yOvyhRLahp/fmgTerJF/or96Zxfdr89K0lXdK5s+ZMOsG55QdKxvDcr4nmk9n+N56/fyG13lP 1/7XDAw+cM6hSjbmaO61ifrP3ZpDWeP+LlxsvnRn3v7DqVclZ0gFvHx3PdNEy3nSjButL3Y+L MmoUWIpzkg01GIuKk4EAHLiv4ijAgAA X-Env-Sender: aisaila@bitdefender.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1502180861!78990226!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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6848 invoked from network); 8 Aug 2017 08:27:42 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-11.tower-27.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 8 Aug 2017 08:27:42 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=E83qC5W0i57uv3eQMNV/a3/WpYCbdLdIznglUFot7Qe4YmJg4Mj+YbFykuqRwJVxrL93JuksmBP0aCyATqJs0wVW/zNKs5N3TTvfuNtpmrCgxoxZldlWswZsh49/xiOjwN6AyRUY9rDWNSzP/vdQZxA43ZqlgP9Fnvl1nDMNZDs1QlHFGgeU87t0eBm/04xqMt8mLKuJd0lrv0boAup/LtKX2DWu3+7phnDFlZdErA/XnJ6MKq13e5FaIcFYZTMs5v3/jDk4p6AZTAGxw73/P9NvhACGiQ+H5sCvpQqjuKu+r1fT2wEkZqcfN+MNpkc1tTqh7TCIkrYzPiCXqX2ixg==; 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=b2REB/r4uCHnzpCSCCFjC q3n+UU=; b=ghkDFHssqifI0B7EZiM3OmhFz88i4MaVnI2nCH0xnbncCwDokzDEe 2ukVpzKuzyov9geosXtLDekFYtJUJrZZfZflwrzWTitS8/qMIQ5uoHVuCnNG9gMm aZjPwEMciZArEqjlyMDtYPVW1rPAvByzIYI9xc8M8u8rO5FVsZKLtJXULq3Vdn71 Snn7FThM+ZmF2MoJmeQLqEpDNEXQi2sIjRI+p2hyxz+lglVxhIa2wDXLasoG0N+r zGPPIIpNM8uM5Nwq7HxTK/T0VRvawdonHevBPY/oS79GeAvnbGgXd+LIk3XxIdr/ Eo1KNWDxbEWyAEQL79dt0ll369L3M2uQA== Received: (qmail 18917 invoked from network); 8 Aug 2017 11:27:40 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 8 Aug 2017 11:27:40 +0300 Received: (qmail 23347 invoked from network); 8 Aug 2017 11:27:40 +0300 Received: from unknown (HELO aisaila-Latitude-E5570.dsd.bitdefender.biz) (10.10.195.54) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 8 Aug 2017 11:27:40 +0300 From: Alexandru Isaila To: xen-devel@lists.xen.org Date: Tue, 8 Aug 2017 11:27:35 +0300 Message-Id: <1502180855-7500-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 v5] 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 Acked-by: Wei Liu --- Changes since V4: - Changed function mane from xc_allow_guest_userspace_event to xc_monitor_guest_userspace_event - Fixed guest_request_enabled check - Delete the guest_request_sync - Changed guest_request_userspace_event to guest_request_userspace_enabled - Moved guest_request_userspace_enabled flag from sched.h to domain.h --- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_monitor.c | 14 ++++++++++++++ xen/arch/x86/hvm/hypercall.c | 5 +++++ xen/common/monitor.c | 13 +++++++++++++ xen/include/asm-x86/domain.h | 19 ++++++++++--------- xen/include/public/domctl.h | 21 +++++++++++---------- 6 files changed, 54 insertions(+), 19 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index bde8313..c72e12d 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_monitor_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..bd8cbcf 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_monitor_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..5742dd1 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->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: diff --git a/xen/common/monitor.c b/xen/common/monitor.c index 451f42f..080a405 100644 --- a/xen/common/monitor.c +++ b/xen/common/monitor.c @@ -79,6 +79,19 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop) break; } + case XEN_DOMCTL_MONITOR_EVENT_GUEST_USERSPACE_EVENT: + { + bool old_status = d->arch.monitor.guest_request_userspace_enabled; + + if ( unlikely(old_status == requested_status) ) + return -EEXIST; + + domain_pause(d); + d->arch.monitor.guest_request_userspace_enabled = 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/asm-x86/domain.h b/xen/include/asm-x86/domain.h index c10522b..de02507 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -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; 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_* */