From patchwork Mon Mar 15 11:59:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 85928 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2FC0R0C004934 for ; Mon, 15 Mar 2010 12:00:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936202Ab0COMAK (ORCPT ); Mon, 15 Mar 2010 08:00:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43353 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936193Ab0COL77 (ORCPT ); Mon, 15 Mar 2010 07:59:59 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2FBxwAX022654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 07:59:58 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2FBxw4t028022 for ; Mon, 15 Mar 2010 07:59:58 -0400 Received: from localhost.localdomain (file.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 8647C250061; Mon, 15 Mar 2010 13:59:57 +0200 (IST) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH 3/5] KVM: Don't follow an atomic operation by a non-atomic one Date: Mon, 15 Mar 2010 13:59:55 +0200 Message-Id: <1268654397-6650-4-git-send-email-avi@redhat.com> In-Reply-To: <1268654397-6650-1-git-send-email-avi@redhat.com> References: <1268654397-6650-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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.3 (demeter.kernel.org [140.211.167.41]); Mon, 15 Mar 2010 12:00:29 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d724a52..2c0f632 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3227,7 +3227,8 @@ static int emulator_write_emulated_onepage(unsigned long addr, const void *val, unsigned int bytes, struct kvm_vcpu *vcpu, - bool guest_initiated) + bool guest_initiated, + bool mmu_only) { gpa_t gpa; u32 error_code; @@ -3247,6 +3248,10 @@ static int emulator_write_emulated_onepage(unsigned long addr, if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) goto mmio; + if (mmu_only) { + kvm_mmu_pte_write(vcpu, gpa, val, bytes, 1); + return X86EMUL_CONTINUE; + } if (emulator_write_phys(vcpu, gpa, val, bytes)) return X86EMUL_CONTINUE; @@ -3271,7 +3276,8 @@ int __emulator_write_emulated(unsigned long addr, const void *val, unsigned int bytes, struct kvm_vcpu *vcpu, - bool guest_initiated) + bool guest_initiated, + bool mmu_only) { /* Crossing a page boundary? */ if (((addr + bytes - 1) ^ addr) & PAGE_MASK) { @@ -3279,7 +3285,7 @@ int __emulator_write_emulated(unsigned long addr, now = -addr & ~PAGE_MASK; rc = emulator_write_emulated_onepage(addr, val, now, vcpu, - guest_initiated); + guest_initiated, mmu_only); if (rc != X86EMUL_CONTINUE) return rc; addr += now; @@ -3287,7 +3293,7 @@ int __emulator_write_emulated(unsigned long addr, bytes -= now; } return emulator_write_emulated_onepage(addr, val, bytes, vcpu, - guest_initiated); + guest_initiated, mmu_only); } int emulator_write_emulated(unsigned long addr, @@ -3295,7 +3301,7 @@ int emulator_write_emulated(unsigned long addr, unsigned int bytes, struct kvm_vcpu *vcpu) { - return __emulator_write_emulated(addr, val, bytes, vcpu, true); + return __emulator_write_emulated(addr, val, bytes, vcpu, true, false); } EXPORT_SYMBOL_GPL(emulator_write_emulated); @@ -3359,6 +3365,8 @@ static int emulator_cmpxchg_emulated(unsigned long addr, if (!exchanged) return X86EMUL_CMPXCHG_FAILED; + return __emulator_write_emulated(addr, new, bytes, vcpu, true, true); + emul_write: printk_once(KERN_WARNING "kvm: emulating exchange as write\n"); @@ -4013,7 +4021,8 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu) kvm_x86_ops->patch_hypercall(vcpu, instruction); - return __emulator_write_emulated(rip, instruction, 3, vcpu, false); + return __emulator_write_emulated(rip, instruction, 3, vcpu, + false, false); } static u64 mk_cr_64(u64 curr_cr, u32 new_val)