From patchwork Wed Dec 8 17:06:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Har'El X-Patchwork-Id: 391162 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 oB8H6hsV019873 for ; Wed, 8 Dec 2010 17:06:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753937Ab0LHRGl (ORCPT ); Wed, 8 Dec 2010 12:06:41 -0500 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:46002 "EHLO mtagate7.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753318Ab0LHRGl (ORCPT ); Wed, 8 Dec 2010 12:06:41 -0500 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id oB8H6eEr004112 for ; Wed, 8 Dec 2010 17:06:40 GMT Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oB8H6fHv3629140 for ; Wed, 8 Dec 2010 17:06:41 GMT Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oB8H6dY4020418 for ; Wed, 8 Dec 2010 10:06:39 -0700 Received: from rice.haifa.ibm.com (rice.haifa.ibm.com [9.148.8.217]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oB8H6cgR020409 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Dec 2010 10:06:39 -0700 Received: from rice.haifa.ibm.com (lnx-nyh.haifa.ibm.com [127.0.0.1]) by rice.haifa.ibm.com (8.14.4/8.14.4) with ESMTP id oB8H6bpY008698; Wed, 8 Dec 2010 19:06:37 +0200 Received: (from nyh@localhost) by rice.haifa.ibm.com (8.14.4/8.14.4/Submit) id oB8H6b7V008696; Wed, 8 Dec 2010 19:06:37 +0200 Date: Wed, 8 Dec 2010 19:06:37 +0200 Message-Id: <201012081706.oB8H6b7V008696@rice.haifa.ibm.com> X-Authentication-Warning: rice.haifa.ibm.com: nyh set sender to "Nadav Har'El" using -f Cc: gleb@redhat.com, avi@redhat.com To: kvm@vger.kernel.org From: "Nadav Har'El" References: <1291827596-nyh@il.ibm.com> Subject: [PATCH 13/28] nVMX: Implement VMPTRST 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 (demeter1.kernel.org [140.211.167.41]); Wed, 08 Dec 2010 17:06:44 +0000 (UTC) --- .before/arch/x86/kvm/x86.c 2010-12-08 18:56:50.000000000 +0200 +++ .after/arch/x86/kvm/x86.c 2010-12-08 18:56:50.000000000 +0200 @@ -3705,7 +3705,7 @@ static int kvm_read_guest_virt_system(gv return kvm_read_guest_virt_helper(addr, val, bytes, vcpu, 0, exception); } -static int kvm_write_guest_virt_system(gva_t addr, void *val, +int kvm_write_guest_virt_system(gva_t addr, void *val, unsigned int bytes, struct kvm_vcpu *vcpu, struct x86_exception *exception) @@ -3736,6 +3736,7 @@ static int kvm_write_guest_virt_system(g out: return r; } +EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); static int emulator_read_emulated(unsigned long addr, void *val, --- .before/arch/x86/kvm/x86.h 2010-12-08 18:56:50.000000000 +0200 +++ .after/arch/x86/kvm/x86.h 2010-12-08 18:56:50.000000000 +0200 @@ -77,6 +77,9 @@ int kvm_inject_realmode_interrupt(struct int kvm_read_guest_virt(gva_t addr, void *val, unsigned int bytes, struct kvm_vcpu *vcpu, struct x86_exception *exception); +int kvm_write_guest_virt_system(gva_t addr, void *val, unsigned int bytes, + struct kvm_vcpu *vcpu, struct x86_exception *exception); + void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data); #endif --- .before/arch/x86/kvm/vmx.c 2010-12-08 18:56:50.000000000 +0200 +++ .after/arch/x86/kvm/vmx.c 2010-12-08 18:56:50.000000000 +0200 @@ -4530,6 +4530,31 @@ static int handle_vmptrld(struct kvm_vcp return 1; } +/* Emulate the VMPTRST instruction */ +static int handle_vmptrst(struct kvm_vcpu *vcpu) +{ + unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION); + u32 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); + gva_t vmcs_gva; + + if (!nested_vmx_check_permission(vcpu)) + return 1; + + if (get_vmx_mem_address(vcpu, exit_qualification, + vmx_instruction_info, &vmcs_gva)) + return 1; + /* ok to use *_system, because handle_vmread verified cpl=0 */ + if (kvm_write_guest_virt_system(vmcs_gva, + (void *)&to_vmx(vcpu)->nested.current_vmptr, + sizeof(u64), vcpu, NULL)) { + kvm_queue_exception(vcpu, PF_VECTOR); + return 1; + } + nested_vmx_succeed(vcpu); + skip_emulated_instruction(vcpu); + return 1; +} + /* * The exit handlers return 1 if the exit was handled fully and guest execution * may resume. Otherwise they set the kvm_run parameter to indicate what needs @@ -4554,7 +4579,7 @@ static int (*kvm_vmx_exit_handlers[])(st [EXIT_REASON_VMCLEAR] = handle_vmclear, [EXIT_REASON_VMLAUNCH] = handle_vmx_insn, [EXIT_REASON_VMPTRLD] = handle_vmptrld, - [EXIT_REASON_VMPTRST] = handle_vmx_insn, + [EXIT_REASON_VMPTRST] = handle_vmptrst, [EXIT_REASON_VMREAD] = handle_vmx_insn, [EXIT_REASON_VMRESUME] = handle_vmx_insn, [EXIT_REASON_VMWRITE] = handle_vmx_insn,