From patchwork Thu Mar 11 21:16:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 85087 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 o2BLGtxn009879 for ; Thu, 11 Mar 2010 21:16:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753527Ab0CKVQx (ORCPT ); Thu, 11 Mar 2010 16:16:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8643 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753497Ab0CKVQx (ORCPT ); Thu, 11 Mar 2010 16:16:53 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2BLGp7H013073 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Mar 2010 16:16:51 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2BLGoN8016538; Thu, 11 Mar 2010 16:16:51 -0500 Received: from amt.cnet (vpn-9-206.rdu.redhat.com [10.11.9.206]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o2BLGmxS016929; Thu, 11 Mar 2010 16:16:49 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id BFC54652026; Thu, 11 Mar 2010 18:16:12 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o2BLG51M020797; Thu, 11 Mar 2010 18:16:05 -0300 Date: Thu, 11 Mar 2010 18:16:05 -0300 From: Marcelo Tosatti To: Stefan Bader , Gleb Natapov Cc: kvm@vger.kernel.org, Avi Kivity Subject: KVM: x86: ignore access permissions for hypercall patching Message-ID: <20100311211605.GA20718@amt.cnet> References: <1266414330-27444-1-git-send-email-avi@redhat.com> <1266414330-27444-14-git-send-email-avi@redhat.com> <4B925E66.5@canonical.com> <4B937AF5.5020004@redhat.com> <4B950542.2030306@canonical.com> <4B9505E6.1040501@redhat.com> <4B956283.10706@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4B956283.10706@canonical.com> User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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]); Thu, 11 Mar 2010 21:16:56 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 703f637..bf5c83f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3253,12 +3253,17 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, static int emulator_write_emulated_onepage(unsigned long addr, const void *val, unsigned int bytes, - struct kvm_vcpu *vcpu) + struct kvm_vcpu *vcpu, + bool guest_initiated) { gpa_t gpa; u32 error_code; - gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, &error_code); + + if (guest_initiated) + gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, &error_code); + else + gpa = kvm_mmu_gva_to_gpa_system(vcpu, addr, &error_code); if (gpa == UNMAPPED_GVA) { kvm_inject_page_fault(vcpu, addr, error_code); @@ -3289,24 +3294,35 @@ mmio: return X86EMUL_CONTINUE; } -int emulator_write_emulated(unsigned long addr, +int __emulator_write_emulated(unsigned long addr, const void *val, unsigned int bytes, - struct kvm_vcpu *vcpu) + struct kvm_vcpu *vcpu, + bool guest_initiated) { /* Crossing a page boundary? */ if (((addr + bytes - 1) ^ addr) & PAGE_MASK) { int rc, now; now = -addr & ~PAGE_MASK; - rc = emulator_write_emulated_onepage(addr, val, now, vcpu); + rc = emulator_write_emulated_onepage(addr, val, now, vcpu, + guest_initiated); if (rc != X86EMUL_CONTINUE) return rc; addr += now; val += now; bytes -= now; } - return emulator_write_emulated_onepage(addr, val, bytes, vcpu); + return emulator_write_emulated_onepage(addr, val, bytes, vcpu, + guest_initiated); +} + +int emulator_write_emulated(unsigned long addr, + const void *val, + unsigned int bytes, + struct kvm_vcpu *vcpu) +{ + return __emulator_write_emulated(addr, val, bytes, vcpu, true); } EXPORT_SYMBOL_GPL(emulator_write_emulated); @@ -3997,7 +4013,7 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu) kvm_x86_ops->patch_hypercall(vcpu, instruction); - return emulator_write_emulated(rip, instruction, 3, vcpu); + return __emulator_write_emulated(rip, instruction, 3, vcpu, false); } static u64 mk_cr_64(u64 curr_cr, u32 new_val)