From patchwork Wed Feb 10 14:39:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asia Slowinska X-Patchwork-Id: 8272351 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 834B1BEEE5 for ; Wed, 10 Feb 2016 14:39:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 623DA203B1 for ; Wed, 10 Feb 2016 14:39:33 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 34507203DA for ; Wed, 10 Feb 2016 14:39:32 +0000 (UTC) Received: from localhost ([::1]:39837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTVvX-0001YG-9X for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Feb 2016 09:39:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTVvK-0001XT-E2 for qemu-devel@nongnu.org; Wed, 10 Feb 2016 09:39:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTVvD-0002Xr-SM for qemu-devel@nongnu.org; Wed, 10 Feb 2016 09:39:18 -0500 Received: from mail-lf0-x229.google.com ([2a00:1450:4010:c07::229]:33160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTVvD-0002Xf-CS for qemu-devel@nongnu.org; Wed, 10 Feb 2016 09:39:11 -0500 Received: by mail-lf0-x229.google.com with SMTP id m1so13046390lfg.0 for ; Wed, 10 Feb 2016 06:39:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lastline-com.20150623.gappssmtp.com; s=20150623; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=uFByhEgOcBFE90zO2Wxq4dWrOOkuQEQrYtxneJsFou0=; b=vDKo0P6gG6HHy5PrV/aaUF9pOw2Lsao9J+uxxjgXFnKT9MaN7gVdLflvOXjSdR7O0C mUuqOjXdSYxtksqd6fbWDncOW4KoB4VFhH4yZUKBFg0+ac8euLxRd481hoCSWJfSMldd /Ll6ggeKqQ2OSZbXHqfBmeACa+4433hUqlG7+W67aojJWXssetlU3boczMgQ2EWauu2H L5qzCLAwbi2qKzegCUwOzFkrJrg0a/NcnnusrksWUzWvJkvheBG7iusxvCTQUxXNpzqA /1Jo9o3KPbld8sroi+qAp6rlDS8JQNqkXKD8t+q0gyhSjV/gXf2nag4aAiV0XtWT6wNS J6mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=uFByhEgOcBFE90zO2Wxq4dWrOOkuQEQrYtxneJsFou0=; b=MdzICmK0no8VT916BmUWsifCKD2sJT+Wg7aE4yggvYZBgbYAdDguWz7h08GNpnRbI/ 8RnucfotS0BI9U+3EuNCF1W/OrrwhaeHJR2yr/ebhJMGa7SDSp9Pkr04X4nwiei53KbG QQ5E42dE20XtAQm9zm/LMLciYJO7oWM68G0648yrVmDIyRY18/ID6qqNySzwZPmYdP40 lI8FYAkWq+fDnY3Y56Wgh128srZuCEg2uZ2frHj+9+J9v+Ln5N4WRuYDNdVhvYxymbjY +rlF+Bk3qhuj8n+a4iaS8001N2T3hg568VCAa/JBCJNuFcX/gCuiKNkUgVSUh+gOEOuG +ftg== X-Gm-Message-State: AG10YOQHT1qBMYcJYYIf+qat+ENwIvWGsoK/qxkoUbPChH6ctkP1lwiEx33dCJxkg/8L3YTOF+rpJncUQy5xXQ== MIME-Version: 1.0 X-Received: by 10.25.160.85 with SMTP id j82mr16587695lfe.36.1455115150400; Wed, 10 Feb 2016 06:39:10 -0800 (PST) Received: by 10.25.215.226 with HTTP; Wed, 10 Feb 2016 06:39:10 -0800 (PST) In-Reply-To: <56BB4674.3050903@redhat.com> References: <56BB4674.3050903@redhat.com> Date: Wed, 10 Feb 2016 15:39:10 +0100 Message-ID: From: Asia Slowinska To: Paolo Bonzini X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::229 Cc: A Slowinska , qemu-devel@nongnu.org, ehabkost@redhat.com, rth@twiddle.net Subject: Re: [Qemu-devel] [PATCH] target-i386/kvm.c: Fix the order of FPU registers in xsave X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: asia@lastline.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, HTML_MESSAGE, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Many thanks for the reply. I'm sorry for the typo in the previous patch. Below comes a new one. Best regards, asia Stick to the right order of the FPU registers in xsave (as specified in the Intel manual.) Otherwise, instructions loading the FPU state don't set it up correctly. To set up FPU, software needs to provide a buffer of 80 bytes storing 8 FPU registers. They are organized in a stack. FPU assumes that the first field of the buffer is ST0, then ST1, and so on. QEMU maintains a circular buffer. When preparing these 80 bytes for KVM, QEMU just uses memcpy instead of copying the elements in a proper order. Signed-off-by: Asia Slowinska --- target-i386/kvm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 94024bc..a9e6c75 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1325,8 +1325,10 @@ static int kvm_put_xsave(X86CPU *cpu) xsave->region[XSAVE_FTW_FOP] = (uint32_t)(env->fpop << 16) + twd; memcpy(&xsave->region[XSAVE_CWD_RIP], &env->fpip, sizeof(env->fpip)); memcpy(&xsave->region[XSAVE_CWD_RDP], &env->fpdp, sizeof(env->fpdp)); - memcpy(&xsave->region[XSAVE_ST_SPACE], env->fpregs, - sizeof env->fpregs); + for (i = 0; i < 8; i++) { + memcpy(&xsave_region[XSAVE_ST_SPACE + i * 4], + &env->fpregs[(env->fpstt + i) & 7], 16); + } xsave->region[XSAVE_MXCSR] = env->mxcsr; *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV] = env->xstate_bv; memcpy(&xsave->region[XSAVE_BNDREGS], env->bnd_regs, @@ -1745,8 +1747,10 @@ static int kvm_get_xsave(X86CPU *cpu) memcpy(&env->fpip, &xsave->region[XSAVE_CWD_RIP], sizeof(env->fpip)); memcpy(&env->fpdp, &xsave->region[XSAVE_CWD_RDP], sizeof(env->fpdp)); env->mxcsr = xsave->region[XSAVE_MXCSR]; - memcpy(env->fpregs, &xsave->region[XSAVE_ST_SPACE], - sizeof env->fpregs); + for (i = 0; i < 8; i++) { + memcpy(&env->fpregs[(env->fpstt + i) & 7], + &xsave_region[XSAVE_ST_SPACE + i * 4], 16); + } env->xstate_bv = *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV]; memcpy(env->bnd_regs, &xsave->region[XSAVE_BNDREGS], sizeof env->bnd_regs);