From patchwork Wed Jan 10 19:50:54 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: 10156061 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 EDED7601A1 for ; Wed, 10 Jan 2018 19:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFC5128469 for ; Wed, 10 Jan 2018 19:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D39152851E; Wed, 10 Jan 2018 19:52:28 +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 2C84E28469 for ; Wed, 10 Jan 2018 19:52:27 +0000 (UTC) Received: from localhost ([::1]:35668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZMQE-0003jh-NZ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 10 Jan 2018 14:52:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZMPM-0003At-Qr for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZMPL-0001KY-E5 for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:32 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:34423) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZMPL-0001Jd-26 for qemu-devel@nongnu.org; Wed, 10 Jan 2018 14:51:31 -0500 Received: by mail-pg0-x244.google.com with SMTP id j4so232408pgp.1 for ; Wed, 10 Jan 2018 11:51:30 -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=XWtMIuVfu3NRf2JISJIj/zsROmUncbTtztgOf4xX5hU=; b=HqsDlIG1zFVLJuGJspfYMaYE6esQHQrOxAIQpGZC0GkJRJWkTFWeAlPDVvsrx1RE6+ w7qlWPn29iT1XiqmUQbogs3zHJ+qB0syczANu94tC1tfzaLkoCEx3v75U1Nu02OO8/pA IvxT+0IAA7OnSqi+h6njL7PSUjGAUrv6Fj/ZgTTIwS8t2ETT9CJ3uGtBuSBknPp++tLi ZzF4OnNoMmybNhywzYQkh14JZnL8oJh56qdKkdU9vo4S4tVJfCPRBqk39uSEqf8mbOmh yY5lcsCo3ymJSPuDPAb/9XS2pw1B43unSwIqlzV38T71uDbHAjbU2CV4reoZgPEj6e5z U81g== 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=XWtMIuVfu3NRf2JISJIj/zsROmUncbTtztgOf4xX5hU=; b=lnuQi2Uai2hDn3mS9G+bTCCNwDfQt2RB9TiGrEz524BIMMcqKSCrhP74QrnORWDHWT Utjiqs3tRXdjZ1/cw3K7frGVsR8oyKr9dS8JQmXGk1pH65Rt9IlH8wzjWYp3ni5Sc+Ap Ho1usmJwVNGrwxUejJ45sJkFV1hlxTZJw2MRCFj6uBScxD3aGQ/xDX+oDNLu8selBibp 3yKoxizR6u0wnQ9EBtmV4U2iG1wyP0xjkmCehz0FXrdVhdmn3YZu70vsX8eQjddKoAcC 61wSy+usuKhpZ1XzoHyIlEZzge1x4oV+wvqE81fsd2CF1Y4Thlt+y+0vop4xuTH9MAGf nt/w== X-Gm-Message-State: AKGB3mK1B+avj3Xbd86y/1fcb0GSYxlPc8HXkbyFxuu9dJu9iWGc3Li1 yAsEnPXTDunMksBKw7IFiLFmvA== X-Google-Smtp-Source: ACJfBot/O+WSsI1EEw45A2W1tb4xJ0V2XB65jH4IogmeguljkS/rO4J0q0F03Sbm3KjRrPkDQRKwXA== X-Received: by 10.99.95.4 with SMTP id t4mr14012505pgb.291.1515613889447; Wed, 10 Jan 2018 11:51:29 -0800 (PST) Received: from paxos.mtv.corp.google.com ([2620:0:1000:1611:f4de:39e6:d38c:64eb]) by smtp.gmail.com with ESMTPSA id g19sm36034054pfb.65.2018.01.10.11.51.28 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jan 2018 11:51:28 -0800 (PST) To: qemu-devel@nongnu.org Date: Wed, 10 Jan 2018 11:50:54 -0800 Message-Id: <20180110195056.85403-1-lepton@google.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180110064706.49777-1-lepton@google.com> References: <20180110064706.49777-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::244 Subject: [Qemu-devel] [PATCH v2 1/3] target/i386: move hflags update code to a function 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 We will share the same code for hax/kvm. Signed-off-by: Tao Wu --- target/i386/Makefile.objs | 2 +- target/i386/common_i386.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ target/i386/common_i386.h | 14 +++++++++++++ target/i386/kvm.c | 41 ++------------------------------------ 4 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 target/i386/common_i386.c create mode 100644 target/i386/common_i386.h diff --git a/target/i386/Makefile.objs b/target/i386/Makefile.objs index 44103a693b..072d502954 100644 --- a/target/i386/Makefile.objs +++ b/target/i386/Makefile.objs @@ -1,4 +1,4 @@ -obj-y += helper.o cpu.o gdbstub.o xsave_helper.o +obj-y += helper.o cpu.o gdbstub.o xsave_helper.o common_i386.o obj-$(CONFIG_TCG) += translate.o obj-$(CONFIG_TCG) += bpt_helper.o cc_helper.o excp_helper.o fpu_helper.o obj-$(CONFIG_TCG) += int_helper.o mem_helper.o misc_helper.o mpx_helper.o diff --git a/target/i386/common_i386.c b/target/i386/common_i386.c new file mode 100644 index 0000000000..285d8bfa48 --- /dev/null +++ b/target/i386/common_i386.c @@ -0,0 +1,50 @@ +/* + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "common_i386.h" + +void x86_update_hflags(CPUX86State *env) +{ + uint32_t hflags; +#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) + + hflags = env->hflags & HFLAG_COPY_MASK; + hflags |= (env->segs[R_SS].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)); + + if (env->cr[4] & CR4_OSFXSR_MASK) { + hflags |= HF_OSFXSR_MASK; + } + + 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; + } + } + env->hflags = hflags; + + return; +} diff --git a/target/i386/common_i386.h b/target/i386/common_i386.h new file mode 100644 index 0000000000..ed2471de62 --- /dev/null +++ b/target/i386/common_i386.h @@ -0,0 +1,14 @@ +/* + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef TARGET_I386_COMMON_I386_H +#define TARGET_I386_COMMON_I386_H + +#include "qemu/osdep.h" +#include "cpu.h" + +void x86_update_hflags(CPUX86State* env); + +#endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6f69e2fcfd..f197eaf5c6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -25,6 +25,7 @@ #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm_int.h" +#include "common_i386.h" #include "kvm_i386.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -1877,7 +1878,6 @@ static int kvm_get_sregs(X86CPU *cpu) { CPUX86State *env = &cpu->env; struct kvm_sregs sregs; - uint32_t hflags; int bit, i, ret; ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_SREGS, &sregs); @@ -1919,44 +1919,7 @@ static int kvm_get_sregs(X86CPU *cpu) env->efer = sregs.efer; /* changes to apic base and cr8/tpr are read back via kvm_arch_post_run */ - -#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) - - hflags = env->hflags & HFLAG_COPY_MASK; - hflags |= (env->segs[R_SS].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)); - - if (env->cr[4] & CR4_OSFXSR_MASK) { - hflags |= HF_OSFXSR_MASK; - } - - 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; - } - } - env->hflags = hflags; + x86_update_hflags(env); return 0; }