From patchwork Wed Aug 30 08:26:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?UTF-8?q?Sergio=20Andr=C3=A9s=20G=C3=B3mez=20Del=20Real?= X-Patchwork-Id: 9928861 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 8CD1860309 for ; Wed, 30 Aug 2017 08:29:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C9F425D9E for ; Wed, 30 Aug 2017 08:29:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F7B126D08; Wed, 30 Aug 2017 08:29:14 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E38AB26E69 for ; Wed, 30 Aug 2017 08:29:13 +0000 (UTC) Received: from localhost ([::1]:48980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmyN7-0002YY-3P for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Aug 2017 04:29:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmyLi-0002UC-JL for qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmyLe-0000Mq-RQ for qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:27:46 -0400 Received: from mail-ua0-x242.google.com ([2607:f8b0:400c:c08::242]:34719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dmyLe-0000MV-MJ for qemu-devel@nongnu.org; Wed, 30 Aug 2017 04:27:42 -0400 Received: by mail-ua0-x242.google.com with SMTP id 105so2346896uad.1 for ; Wed, 30 Aug 2017 01:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OkQLdaa875ZZxu2RJ1SbjpI6uzJU6+I2c2l5ub0vLac=; b=VJtfQNqg7ByjVStw7J7TZM3zHCHpdpYnmomwUvZpZmU27oxVaG0OWrOivjzezNEXSm O94stQihqnUsc++q6hpUjowa8Xw7cRkSG4IVTAkMPIm4uLbSXBvYIMRVw6hO7zHueN/E Be2EjZEygIChfHJZTMjXRftviP3di03CBGasxiOPd1KifzqBgTGqnWtCIqpH59y+Pxsn zSKjMrocKswO/A1TR4zcvMKT4JMCIiSmi9UdZxdMxbTybP0r3xf/JNhfa8v6OoVI5lvC rZaKrrVH6hhVYfA4mf+HwkE73wt/ofYxnYqZqAqy06HNqUAkKIY+41DGz53Qaban3Kb7 OwjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OkQLdaa875ZZxu2RJ1SbjpI6uzJU6+I2c2l5ub0vLac=; b=m0P3wH95IDWUwTh8Rfi7thmV+y2oJpxk2Yb2ABQHIijryMAT6+d9OvR+dSrahZkjjK HCwxTVn6bzK2hN01K34Q2A7ff8Iv+3r5hUVmjTJ9fUWwz2rh7dAHSMhZ/rVD9tUUXUWp IluT8Dn5t8l4nTMtFbFl3//MRcVg64zPLPODOjGIDd+qGnKSjlEmrjZ+eD4ZA8FXOgU0 rXXywzk3dZs4+jGLLEaJaWcthhgKzUbqC6h45LDthV6yGBn+zxjWEMFVAWLDB7A1YVUY iZJ4jJoJS4MsuWOFbKPnGbTwyazQn7mrtxE3jDo2dcC8cdgSl6kOcjcbYmDiViBAQQit aX6w== X-Gm-Message-State: AHYfb5j0rF2YTCMmuVhvxYSpOhWqSxtzw32255QfGopOlXeWNF6eXl7x Aq72bvxyrtygrAOo X-Received: by 10.159.34.134 with SMTP id 6mr460591uan.107.1504081661941; Wed, 30 Aug 2017 01:27:41 -0700 (PDT) Received: from localhost.localdomain ([191.109.6.85]) by smtp.gmail.com with ESMTPSA id h74sm1079197vka.8.2017.08.30.01.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Aug 2017 01:27:41 -0700 (PDT) From: Sergio Andres Gomez Del Real X-Google-Original-From: Sergio Andres Gomez Del Real To: qemu-devel@nongnu.org Date: Wed, 30 Aug 2017 03:26:55 -0500 Message-Id: <20170830082702.3011-7-Sergio.G.DelReal@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170830082702.3011-1-Sergio.G.DelReal@gmail.com> References: <20170830082702.3011-1-Sergio.G.DelReal@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400c:c08::242 Subject: [Qemu-devel] [PATCH v2 06/13] hvf: use new helper functions for put/get xsave X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergio Andres Gomez Del Real Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit makes use of the helper functions for handling xsave in xsave_helper.c, which are shared with kvm. Signed-off-by: Sergio Andres Gomez Del Real --- target/i386/hvf-utils/x86hvf.c | 63 ++++++------------------------------------ 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/target/i386/hvf-utils/x86hvf.c b/target/i386/hvf-utils/x86hvf.c index 967be2e7fe..819d760624 100644 --- a/target/i386/hvf-utils/x86hvf.c +++ b/target/i386/hvf-utils/x86hvf.c @@ -76,36 +76,13 @@ void hvf_get_segment(SegmentCache *qseg, struct vmx_segment *vmx_seg) void hvf_put_xsave(CPUState *cpu_state) { - int x; struct hvf_xsave_buf *xsave; - + xsave = X86_CPU(cpu_state)->env.kvm_xsave_buf; - memset(xsave, 0, sizeof(*xsave)); - - memcpy(&xsave->data[4], &X86_CPU(cpu_state)->env.fpdp, sizeof(X86_CPU(cpu_state)->env.fpdp)); - memcpy(&xsave->data[2], &X86_CPU(cpu_state)->env.fpip, sizeof(X86_CPU(cpu_state)->env.fpip)); - memcpy(&xsave->data[8], &X86_CPU(cpu_state)->env.fpregs, sizeof(X86_CPU(cpu_state)->env.fpregs)); - memcpy(&xsave->data[144], &X86_CPU(cpu_state)->env.ymmh_regs, sizeof(X86_CPU(cpu_state)->env.ymmh_regs)); - memcpy(&xsave->data[288], &X86_CPU(cpu_state)->env.zmmh_regs, sizeof(X86_CPU(cpu_state)->env.zmmh_regs)); - memcpy(&xsave->data[272], &X86_CPU(cpu_state)->env.opmask_regs, sizeof(X86_CPU(cpu_state)->env.opmask_regs)); - memcpy(&xsave->data[240], &X86_CPU(cpu_state)->env.bnd_regs, sizeof(X86_CPU(cpu_state)->env.bnd_regs)); - memcpy(&xsave->data[256], &X86_CPU(cpu_state)->env.bndcs_regs, sizeof(X86_CPU(cpu_state)->env.bndcs_regs)); - memcpy(&xsave->data[416], &X86_CPU(cpu_state)->env.hi16_zmm_regs, sizeof(X86_CPU(cpu_state)->env.hi16_zmm_regs)); - - xsave->data[0] = (uint16_t)X86_CPU(cpu_state)->env.fpuc; - xsave->data[0] |= (X86_CPU(cpu_state)->env.fpus << 16); - xsave->data[0] |= (X86_CPU(cpu_state)->env.fpstt & 7) << 11; - - for (x = 0; x < 8; ++x) - xsave->data[1] |= ((!X86_CPU(cpu_state)->env.fptags[x]) << x); - xsave->data[1] |= (uint32_t)(X86_CPU(cpu_state)->env.fpop << 16); - - memcpy(&xsave->data[40], &X86_CPU(cpu_state)->env.xmm_regs, sizeof(X86_CPU(cpu_state)->env.xmm_regs)); - - xsave->data[6] = X86_CPU(cpu_state)->env.mxcsr; - *(uint64_t *)&xsave->data[128] = X86_CPU(cpu_state)->env.xstate_bv; - - if (hv_vcpu_write_fpstate(cpu_state->hvf_fd, xsave->data, 4096)){ + + x86_cpu_xsave_all_areas(X86_CPU(cpu_state), xsave); + + if (hv_vcpu_write_fpstate(cpu_state->hvf_fd, xsave->data, 4096)) { abort(); } } @@ -187,39 +164,15 @@ void hvf_put_msrs(CPUState *cpu_state) void hvf_get_xsave(CPUState *cpu_state) { - int x; struct hvf_xsave_buf *xsave; - + xsave = X86_CPU(cpu_state)->env.kvm_xsave_buf; - + if (hv_vcpu_read_fpstate(cpu_state->hvf_fd, xsave->data, 4096)) { abort(); } - memcpy(&X86_CPU(cpu_state)->env.fpdp, &xsave->data[4], sizeof(X86_CPU(cpu_state)->env.fpdp)); - memcpy(&X86_CPU(cpu_state)->env.fpip, &xsave->data[2], sizeof(X86_CPU(cpu_state)->env.fpip)); - memcpy(&X86_CPU(cpu_state)->env.fpregs, &xsave->data[8], sizeof(X86_CPU(cpu_state)->env.fpregs)); - memcpy(&X86_CPU(cpu_state)->env.ymmh_regs, &xsave->data[144], sizeof(X86_CPU(cpu_state)->env.ymmh_regs)); - memcpy(&X86_CPU(cpu_state)->env.zmmh_regs, &xsave->data[288], sizeof(X86_CPU(cpu_state)->env.zmmh_regs)); - memcpy(&X86_CPU(cpu_state)->env.opmask_regs, &xsave->data[272], sizeof(X86_CPU(cpu_state)->env.opmask_regs)); - memcpy(&X86_CPU(cpu_state)->env.bnd_regs, &xsave->data[240], sizeof(X86_CPU(cpu_state)->env.bnd_regs)); - memcpy(&X86_CPU(cpu_state)->env.bndcs_regs, &xsave->data[256], sizeof(X86_CPU(cpu_state)->env.bndcs_regs)); - memcpy(&X86_CPU(cpu_state)->env.hi16_zmm_regs, &xsave->data[416], sizeof(X86_CPU(cpu_state)->env.hi16_zmm_regs)); - - - X86_CPU(cpu_state)->env.fpuc = (uint16_t)xsave->data[0]; - X86_CPU(cpu_state)->env.fpus = (uint16_t)(xsave->data[0] >> 16); - X86_CPU(cpu_state)->env.fpstt = (X86_CPU(cpu_state)->env.fpus >> 11) & 7; - X86_CPU(cpu_state)->env.fpop = (uint16_t)(xsave->data[1] >> 16); - - for (x = 0; x < 8; ++x) - X86_CPU(cpu_state)->env.fptags[x] = - ((((uint16_t)xsave->data[1] >> x) & 1) == 0); - - memcpy(&X86_CPU(cpu_state)->env.xmm_regs, &xsave->data[40], sizeof(X86_CPU(cpu_state)->env.xmm_regs)); - - X86_CPU(cpu_state)->env.mxcsr = xsave->data[6]; - X86_CPU(cpu_state)->env.xstate_bv = *(uint64_t *)&xsave->data[128]; + x86_cpu_xrstor_all_areas(X86_CPU(cpu_state), xsave); } void hvf_get_segments(CPUState *cpu_state)