From patchwork Wed May 25 02:06:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 814672 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4P26PBx006565 for ; Wed, 25 May 2011 02:06:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753426Ab1EYCGW (ORCPT ); Tue, 24 May 2011 22:06:22 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:50056 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752365Ab1EYCGW (ORCPT ); Tue, 24 May 2011 22:06:22 -0400 Received: by iyb14 with SMTP id 14so5784703iyb.19 for ; Tue, 24 May 2011 19:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:x-mailer :mime-version:content-type:content-transfer-encoding; bh=LWVZlMmsx4PfrKtUrd+1j65U7V24vqIDj3trKDzamTQ=; b=I80ntKoeMMHpQF3xZOsZFgJratn4BebXEVNxm6gxYlAkda9laP5QnuK4EUOEpobZeA qnQX0vwI0iUoenzD+enPMsJJ3ErbkraVHmA5XKjw3qwb5fveSCeMSp0T2xyXXPDKqrjt 5eoHpWJl9B5K29Nsqp7mDe9lUPkPFVnTE8EII= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=jRxtI0ZA4hQD5TZkZaE+JeEzUdXN0icdkrpmjGVjzRm3s2aOT/djDvkN6QnY911RoH H3GMBiDenuzygd6zz+lT3aPqIUAWI4odYasgd0+ozCsRFtz4hLK2vCowUgSoejRrV1Rn QumbmxMrUusGnMJpjJNbDtdTaKQuPe/5dHMdw= Received: by 10.42.229.3 with SMTP id jg3mr10950275icb.425.1306289181522; Tue, 24 May 2011 19:06:21 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id 14sm3568225ibc.25.2011.05.24.19.06.18 (version=SSLv3 cipher=OTHER); Tue, 24 May 2011 19:06:20 -0700 (PDT) Date: Wed, 25 May 2011 11:06:16 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, gleb@redhat.com Subject: [PATCH 1/2] KVM: x86 emulator: Clean up init_emulate_ctxt() Message-Id: <20110525110616.7cd61e29.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 25 May 2011 02:06:26 +0000 (UTC) From: Takuya Yoshikawa Use a local pointer to the emulate_ctxt for simplicity. Then, arrange the hard-to-read mode selection lines neatly. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/x86.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index da48622..e7d337e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4508,7 +4508,8 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu) static void init_emulate_ctxt(struct kvm_vcpu *vcpu) { - struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; + struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; + struct decode_cache *c = &ctxt->decode; int cs_db, cs_l; /* @@ -4521,15 +4522,15 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu) kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); - vcpu->arch.emulate_ctxt.eflags = kvm_get_rflags(vcpu); - vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu); - vcpu->arch.emulate_ctxt.mode = - (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL : - (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) - ? X86EMUL_MODE_VM86 : cs_l - ? X86EMUL_MODE_PROT64 : cs_db - ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16; - vcpu->arch.emulate_ctxt.guest_mode = is_guest_mode(vcpu); + ctxt->eflags = kvm_get_rflags(vcpu); + ctxt->eip = kvm_rip_read(vcpu); + ctxt->mode = (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL : + (ctxt->eflags & X86_EFLAGS_VM) ? X86EMUL_MODE_VM86 : + cs_l ? X86EMUL_MODE_PROT64 : + cs_db ? X86EMUL_MODE_PROT32 : + X86EMUL_MODE_PROT16; + ctxt->guest_mode = is_guest_mode(vcpu); + memset(c, 0, sizeof(struct decode_cache)); memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); vcpu->arch.emulate_regs_need_sync_from_vcpu = false;