From patchwork Tue Mar 14 13:30:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9623351 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 EE2D560492 for ; Tue, 14 Mar 2017 13:32:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E373526419 for ; Tue, 14 Mar 2017 13:32:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D732228577; Tue, 14 Mar 2017 13:32:39 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 7BD2F26419 for ; Tue, 14 Mar 2017 13:32:39 +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 1cnmX2-0003lt-5W; Tue, 14 Mar 2017 13:30:32 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cnmX0-0003ln-UN for xen-devel@lists.xen.org; Tue, 14 Mar 2017 13:30:31 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id C3/18-16699-670F7C85; Tue, 14 Mar 2017 13:30:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRWlGSWpSXmKPExsUSfTxjoW7ph+M RBm/vSFss+biYxYHR4+ju30wBjFGsmXlJ+RUJrBlfX51iL+iQq7j6pZu1gfG4WBcjJ4eQgIfE okUb2boYuYDstYwST5v6mSCcq4wSjasbWGCqFu/cBVW1n1Hi36UudpAEm4ChxOqNLWwgtoiAt MS1z5cZQWxmgUSJxxdnMIHYwgIOEjvvLgEbxCKgKvFi2nRWEJtXwFNi4aHFYHMkBOQkTh6bDB TnALJzJFbfroYwpST+tyqBrJUQ2MAiMePYcSaIchmJRxNvsk1gFFjAyLCKUaM4tagstUjXyEw vqSgzPaMkNzEzR9fQwFgvN7W4ODE9NScxqVgvOT93EyMwsOoZGBh3MDbs9TvEKMnBpCTKqzn/ eIQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd7y90A5waLU9NSKtMwcYIjDpCU4eJREeO++A0rzF hck5hZnpkOkTjEac8yZvfsNE8ee1QfeMAmx5OXnpUqJ8xaDTBIAKc0ozYMbBIu9S4yyUsK8jA wMDEI8BalFuZklqPKvGMU5GJWEebNApvBk5pXA7XsFdAoT0CmJP4+AnFKSiJCSamBsPnXQaf9 /TymPiEXLEoua/lzn5npzUt6z1oXNzPL2IRb2GebpLAvXWPVzMui8OJVntKqDteCy7WKmv1OC NFc+P+gzfQvT4X2CYf1V13JCd/B2HQl+fuh8lDzbkpmiQaa9bqv41/2U1rpTcUQ7faOV37KHB 9bKsYS/mnpGq2qZcWJdhe7Xf1xKLMUZiYZazEXFiQA0MxAZuAIAAA== X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1489498228!59288728!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49219 invoked from network); 14 Mar 2017 13:30:29 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-11.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 14 Mar 2017 13:30:29 -0000 Received: (qmail 22479 invoked from network); 14 Mar 2017 15:30:27 +0200 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 14 Mar 2017 15:30:27 +0200 Received: from smtp01.buh.bitdefender.com (smtp.bitdefender.biz [10.17.80.75]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id A30917FC05 for ; Tue, 14 Mar 2017 15:30:27 +0200 (EET) Received: (qmail 12693 invoked from network); 14 Mar 2017 15:30:27 +0200 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp01.buh.bitdefender.com with AES128-SHA256 encrypted SMTP; 14 Mar 2017 15:30:27 +0200 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Tue, 14 Mar 2017 15:30:18 +0200 Message-Id: <1489498218-11452-1-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp01.buh.bitdefender.com, sigver: 7.70168 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 443206, Stamp: 3], Multi: [Enabled, t: (0.000011, 0.018255)], BW: [Enabled, t: (0.000010)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.005486), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.011250, 0.000205)], URL: [Enabled, t: (0.000004, 0.000001)], RTDA: [Enabled, t: (0.177564), Hit: No, Details: v2.4.4; Id: 11.5eu789.1bb6c44fv.16pl], total: 0(775) X-BitDefender-CF-Stamp: none Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, Razvan Cojocaru Subject: [Xen-devel] [PATCH] tools/libxc: Exposed XEN_DOMCTL_getvcpuextstate 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 It's useful for an introspection tool to be able to inspect XSAVE states. Xen already has a DOMCTL that can be used for this purpose, but it had no public libxc wrapper. This patch adds xc_vcpu_get_extstate(). Signed-off-by: Razvan Cojocaru Acked-by: Wei Liu --- tools/libxc/include/xenctrl.h | 23 +++++++++++++++++ tools/libxc/xc_domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index a48981a..b80d150 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -487,6 +487,11 @@ typedef union } start_info_any_t; #endif +typedef struct xc_vcpu_extstate { + uint64_t xfeature_mask; + uint64_t size; + void *buffer; +} xc_vcpu_extstate_t; typedef struct xen_arch_domainconfig xc_domain_configuration_t; int xc_domain_create(xc_interface *xch, uint32_t ssidref, @@ -880,6 +885,24 @@ int xc_vcpu_getcontext(xc_interface *xch, uint32_t vcpu, vcpu_guest_context_any_t *ctxt); +/** + * This function returns information about the XSAVE state of a particular + * vcpu of a domain. If extstate->size and extstate->xfeature_mask are 0, + * the call is considered a query to retrieve them and the buffer is not + * filled. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid the domain to get information from + * @parm vcpu the vcpu number + * @parm extstate a pointer to a structure to store the XSAVE state of the + * domain + * @return 0 on success, negative error code on failure + */ +int xc_vcpu_get_extstate(xc_interface *xch, + uint32_t domid, + uint32_t vcpu, + xc_vcpu_extstate_t *extstate); + typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t; int xc_vcpu_getinfo(xc_interface *xch, uint32_t domid, diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index d862e53..71e5d93 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -555,6 +555,65 @@ int xc_vcpu_getcontext(xc_interface *xch, return rc; } +int xc_vcpu_get_extstate(xc_interface *xch, + uint32_t domid, + uint32_t vcpu, + xc_vcpu_extstate_t *extstate) +{ + int rc; + DECLARE_DOMCTL; + DECLARE_HYPERCALL_BUFFER(void, buffer); + bool get_state; + + if ( !extstate ) + return -EINVAL; + + domctl.cmd = XEN_DOMCTL_getvcpuextstate; + domctl.domain = (domid_t)domid; + domctl.u.vcpuextstate.vcpu = (uint16_t)vcpu; + domctl.u.vcpuextstate.xfeature_mask = extstate->xfeature_mask; + domctl.u.vcpuextstate.size = extstate->size; + + get_state = (extstate->size != 0); + + if ( get_state ) + { + buffer = xc_hypercall_buffer_alloc(xch, buffer, extstate->size); + + if ( !buffer ) + { + PERROR("Unable to allocate memory for vcpu%u's xsave context", + vcpu); + rc = -ENOMEM; + goto out; + } + + set_xen_guest_handle(domctl.u.vcpuextstate.buffer, buffer); + } + + rc = do_domctl(xch, &domctl); + + if ( rc ) + goto out; + + /* A query for the size of buffer to use. */ + if ( !extstate->size && !extstate->xfeature_mask ) + { + extstate->xfeature_mask = domctl.u.vcpuextstate.xfeature_mask; + extstate->size = domctl.u.vcpuextstate.size; + goto out; + } + + if ( get_state ) + memcpy(extstate->buffer, buffer, extstate->size); + +out: + if ( get_state ) + xc_hypercall_buffer_free(xch, buffer); + + return rc; +} + int xc_watchdog(xc_interface *xch, uint32_t id, uint32_t timeout)