From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Bader Subject: Re: KVM: x86: ignore access permissions for hypercall patching Date: Thu, 11 Mar 2010 22:22:52 +0100 Message-ID: <4B995F2C.6080708@canonical.com> 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> <20100311211605.GA20718@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Gleb Natapov , kvm@vger.kernel.org, Avi Kivity To: Marcelo Tosatti Return-path: Received: from adelie.canonical.com ([91.189.90.139]:58500 "EHLO adelie.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753646Ab0CKVW4 (ORCPT ); Thu, 11 Mar 2010 16:22:56 -0500 In-Reply-To: <20100311211605.GA20718@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: With this patch applied on top, I was able to boot my guest on a AMD host system. Marcelo Tosatti wrote: > 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 Tested-by: Stefan Bader > > 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)