Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754322AbdGJUJs (ORCPT ); Mon, 10 Jul 2017 16:09:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40528 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752158AbdGJUJr (ORCPT ); Mon, 10 Jul 2017 16:09:47 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8C5D80F6D Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=david@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B8C5D80F6D Subject: Re: [PATCH v3 2/3] KVM: nVMX: Enable VMFUNC for the L1 hypervisor To: Bandan Das , kvm@vger.kernel.org Cc: pbonzini@redhat.com, linux-kernel@vger.kernel.org References: <20170710195356.31297-1-bsd@redhat.com> <20170710195356.31297-3-bsd@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <5fc42821-e544-ec6a-5e0f-4750da32da71@redhat.com> Date: Mon, 10 Jul 2017 22:09:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20170710195356.31297-3-bsd@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 10 Jul 2017 20:09:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2572 Lines: 80 > - kvm_queue_exception(vcpu, UD_VECTOR); > + struct vcpu_vmx *vmx = to_vmx(vcpu); > + struct vmcs12 *vmcs12; > + u32 function = vcpu->arch.regs[VCPU_REGS_RAX]; > + > + /* > + * VMFUNC is only supported for nested guests, but we always enable the > + * secondary control for simplicity; for non-nested mode, fake that we > + * didn't by injecting #UD. > + */ > + if (!is_guest_mode(vcpu)) { > + kvm_queue_exception(vcpu, UD_VECTOR); > + return 1; > + } > + > + vmcs12 = get_vmcs12(vcpu); > + if ((vmcs12->vm_function_control & (1 << function)) == 0) > + goto fail; > + WARN(1, "VMCS12 VM function control should have been zero"); Should this be a WARN_ONCE? > + > +fail: > + nested_vmx_vmexit(vcpu, vmx->exit_reason, > + vmcs_read32(VM_EXIT_INTR_INFO), > + vmcs_readl(EXIT_QUALIFICATION)); > return 1; > } > > @@ -10053,7 +10092,8 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, > exec_control &= ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | > SECONDARY_EXEC_RDTSCP | > SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | > - SECONDARY_EXEC_APIC_REGISTER_VIRT); > + SECONDARY_EXEC_APIC_REGISTER_VIRT | > + SECONDARY_EXEC_ENABLE_VMFUNC); > if (nested_cpu_has(vmcs12, > CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)) { > vmcs12_exec_ctrl = vmcs12->secondary_vm_exec_control & > @@ -10061,6 +10101,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, > exec_control |= vmcs12_exec_ctrl; > } > > + /* All VMFUNCs are currently emulated through L0 vmexits. */ > + if (exec_control & SECONDARY_EXEC_ENABLE_VMFUNC) > + vmcs_write64(VM_FUNCTION_CONTROL, 0); > + > if (exec_control & SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY) { > vmcs_write64(EOI_EXIT_BITMAP0, > vmcs12->eoi_exit_bitmap0); > @@ -10310,6 +10354,11 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) > vmx->nested.nested_vmx_entry_ctls_high)) > return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > > + if (nested_cpu_has_vmfunc(vmcs12) && > + (vmcs12->vm_function_control & > + ~vmx->nested.nested_vmx_vmfunc_controls)) I'd prefer the second part on one line, although it will violate 80 chars. (these variable names really start to get too lengthy to be useful) > + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > + > if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu)) > return VMXERR_ENTRY_INVALID_CONTROL_FIELD; > > Feel free to ignore my comments. Reviewed-by: David Hildenbrand -- Thanks, David