From patchwork Wed Jan 10 19:50:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)\" via" X-Patchwork-Id: 10156063 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 1016D601A1 for ; Wed, 10 Jan 2018 19:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 021C928469 for ; Wed, 10 Jan 2018 19:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA9F128471; Wed, 10 Jan 2018 19:52:48 +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_SIGNED, 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 8E6EE28469 for ; Wed, 10 Jan 2018 19:52:48 +0000 (UTC) Received: from localhost ([::1]:35684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZMQZ-00043Z-SV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Jan 2018 14:52:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZMPb-0003I2-Tn for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZMPa-0001cw-Uw for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:47 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:45006) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZMPa-0001bT-Jq for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:46 -0500 Received: by mail-pg0-x243.google.com with SMTP id m20so194307pgc.11 for ; Wed, 10 Jan 2018 11:51:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R0rZOOT0wo9+rhCPtC2NurFouhqgl+G+pyqs2y4ePnY=; b=GRpXnylqqJq3ByUH4MQtV8QXLENWOMhc1TiI7g2g+bc1w2O+AHRtCICOKZU5MxEELy c0EYv7zj6VL/vz8G4iRjzDT5uDyUSluBcma/tIy+M4/RDcYzzTFzIavGgAC1C5ljXyHH 4UyxeP8QTopx+d1XhouwFKHovZU3dDBJa6ehXXCyc6PC+rGivjADEk/m01n9ol0nnLWM AKt0UORFXGSHAEfLnJjsc7vOQy1Osv/0cTQU7WdPuMlhMO5F3jo3G/m57tY74kcaCRSG lE1RPteuvhScbUq2evZhENtKGnjhbNRl3faWAJbpGXOIw9+DIVUpKf8zDv4CPEqR27cE ic6g== 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=R0rZOOT0wo9+rhCPtC2NurFouhqgl+G+pyqs2y4ePnY=; b=YTSyOG3XoY27+l+HGrRpWiZM6glCPfqUtPUxHHYbFCZpN1mMZoT5HhiZGWTUaqXoyp fJHLn7Za/LXUyO40zaPkfg5rPR12N0XHw0pLIRmnDRuCHBqZ1V6V4IBpHlpJ/lRPexf0 A6KsvM4TzOw7tv1GUooBdlGTBlXxndkI0KrBIuOQDQk4yR4v1aSG81by41u6FRBFPYsI gLOpJd/ZYGUc7mXRXR66PUumBvbHdFyvl4cAnoCAw/lHyZvqOSyKd2foXwxP4uhInqOB 9XP77AcfOpkDhMhgKASRgvdx6JiS9baP3RYGZWwExKOFTNYtRnBlT98VXERXTe5xUn7x XcrA== X-Gm-Message-State: AKwxytdbn8etRFShp2//RzFEOF2lSAMcIM3NGr6etBi0+QVCXYzYL20+ nPRGCY0xqe7b/uS9gyhjjgsCmQ== X-Google-Smtp-Source: ACJfBovCzVnZqzUwyvhEPCi3mRiH4DPQZM0EHD7uqp+NHq7dyK1RKiiP96YfULOFJMSUTEX5CGFPTQ== X-Received: by 10.99.180.76 with SMTP id n12mr6776746pgu.8.1515613905248; Wed, 10 Jan 2018 11:51:45 -0800 (PST) Received: from paxos.mtv.corp.google.com ([2620:0:1000:1611:f4de:39e6:d38c:64eb]) by smtp.gmail.com with ESMTPSA id m23sm31298128pgv.45.2018.01.10.11.51.43 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jan 2018 11:51:44 -0800 (PST) To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 11:50:55 -0800 Message-Id: <20180110195056.85403-2-lepton@google.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180110195056.85403-1-lepton@google.com> References: <20180110064706.49777-1-lepton@google.com> <20180110195056.85403-1-lepton@google.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v2 2/3] target/i386: hax: change to use x86_update_hflags 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: , X-Patchwork-Original-From: Tao Wu via Qemu-devel From: "Zhijian Li (Fujitsu)\" via" Reply-To: Tao Wu Cc: pbonzini@redhat.com, Tao Wu , ehabkost@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change to use x86_update_hflags instead of keeping another copy at hax side. This also fix bug like HF_CPL_MASK should be SS.DPL, not CS.DPL. Signed-off-by: Tao Wu --- target/i386/hax-all.c | 53 ++------------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c index 3ce6950296..dc379373f7 100644 --- a/target/i386/hax-all.c +++ b/target/i386/hax-all.c @@ -31,6 +31,7 @@ #include "qemu-common.h" #include "strings.h" +#include "common_i386.h" #include "hax-i386.h" #include "sysemu/accel.h" #include "sysemu/sysemu.h" @@ -782,56 +783,6 @@ static int hax_set_segments(CPUArchState *env, struct vcpu_state_t *sregs) return 0; } -/* - * After get the state from the kernel module, some - * qemu emulator state need be updated also - */ -static int hax_setup_qemu_emulator(CPUArchState *env) -{ - -#define HFLAG_COPY_MASK (~( \ - HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ - HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ - HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ - HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK)) - - uint32_t hflags; - - hflags = (env->segs[R_CS].flags >> DESC_DPL_SHIFT) & HF_CPL_MASK; - hflags |= (env->cr[0] & CR0_PE_MASK) << (HF_PE_SHIFT - CR0_PE_SHIFT); - hflags |= (env->cr[0] << (HF_MP_SHIFT - CR0_MP_SHIFT)) & - (HF_MP_MASK | HF_EM_MASK | HF_TS_MASK); - hflags |= (env->eflags & (HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK)); - hflags |= (env->cr[4] & CR4_OSFXSR_MASK) << - (HF_OSFXSR_SHIFT - CR4_OSFXSR_SHIFT); - - if (env->efer & MSR_EFER_LMA) { - hflags |= HF_LMA_MASK; - } - - if ((hflags & HF_LMA_MASK) && (env->segs[R_CS].flags & DESC_L_MASK)) { - hflags |= HF_CS32_MASK | HF_SS32_MASK | HF_CS64_MASK; - } else { - hflags |= (env->segs[R_CS].flags & DESC_B_MASK) >> - (DESC_B_SHIFT - HF_CS32_SHIFT); - hflags |= (env->segs[R_SS].flags & DESC_B_MASK) >> - (DESC_B_SHIFT - HF_SS32_SHIFT); - if (!(env->cr[0] & CR0_PE_MASK) || - (env->eflags & VM_MASK) || !(hflags & HF_CS32_MASK)) { - hflags |= HF_ADDSEG_MASK; - } else { - hflags |= ((env->segs[R_DS].base | - env->segs[R_ES].base | - env->segs[R_SS].base) != 0) << HF_ADDSEG_SHIFT; - } - } - - hflags &= ~HF_SMM_MASK; - - env->hflags = (env->hflags & HFLAG_COPY_MASK) | hflags; - return 0; -} - static int hax_sync_vcpu_register(CPUArchState *env, int set) { struct vcpu_state_t regs; @@ -888,7 +839,7 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set) } } if (!set) { - hax_setup_qemu_emulator(env); + x86_update_hflags(env); } return 0; }