From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: KVM: x86: ignore access permissions for hypercall patching Date: Thu, 11 Mar 2010 18:16:05 -0300 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-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Avi Kivity To: Stefan Bader , Gleb Natapov Return-path: 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 Content-Disposition: inline In-Reply-To: <4B956283.10706@canonical.com> Sender: kvm-owner@vger.kernel.org List-ID: Ignore access permissions while patching hypercall instructions. Otherwise KVM injects a page fault when trying to patch vmcall on read-only text regions: Freeing initrd memory: 8843k freed Freeing unused kernel memory: 660k freed Write protecting the kernel text: 4780k Write protecting the kernel read-only data: 1912k BUG: unable to handle kernel paging request at c01292e3 IP: [] kvm_leave_lazy_mmu+0x43/0x70 *pde = 00910067 *pte = 00129161 Oops: 0003 [#1] SMP CC: stable@kernel.org Reported-by: Stefan Bader Signed-off-by: Marcelo Tosatti 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)