From patchwork Tue Nov 13 06:12:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 250A21759 for ; Tue, 13 Nov 2018 06:36:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 153EB28FDF for ; Tue, 13 Nov 2018 06:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0965F29ABC; Tue, 13 Nov 2018 06:36:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18647298FE for ; Tue, 13 Nov 2018 06:36:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731010AbeKMQdB (ORCPT ); Tue, 13 Nov 2018 11:33:01 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47202 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730935AbeKMQdB (ORCPT ); Tue, 13 Nov 2018 11:33:01 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAD6YdP3050428; Tue, 13 Nov 2018 06:36:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=h/kUNptiQW+gOAbFiS+n/ofUlDWBCwGbVy+GbO2yikI=; b=GaXjqfB0II2LkZF/erLdjRWXCxg5Xao4un8txeii+HNVBtD56ce0U9yqdtqKXS3sIoGD RJZsF9Uya30b5jzjLgGhrHKaxo0/HWF3fAYz0qC/a6gP52o+yk90QyxC/dcAVDrAythv 7MsZ1j9x/hUFStKsVaRgAXcwgElazrfyMjNmdLUQ6p6gUcKR73lp6KTs/dlnVK8Q90ZD rmNEEQK1akujOU8pWqSBHjFCFUEnB33iM6Qkh6f9JvX01T8Y1MGK+4cugwp8kyU90OHr SPrT4KsHc3vDvSnX63CVbO5h0QBcS9aJ80vKmmM12qPEA8Bb4aNVZrpiTK1bqv1ezbyZ 6Q== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2nnwg18fsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:18 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aHGI005385 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:17 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aHlm004943; Tue, 13 Nov 2018 06:36:17 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Nov 2018 22:36:17 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH 5/6] nVMX x86: Re-organize the code in check_vmentry_prereqs(), that are related to VM-Exit Control Fields Date: Tue, 13 Nov 2018 01:12:08 -0500 Message-Id: <20181113061209.6843-6-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181113061209.6843-1-krish.sadhukhan@oracle.com> References: <20181113061209.6843-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9075 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=809 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811130062 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Separate out the checks in check_vmentry_prereqs(), that are related to the VM-Exit Control Fields, to a separate function. The re-organized code is easier for readability, enhancement and maintenance. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas Reviewed-by: Mark Kanda --- arch/x86/kvm/vmx.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 68335f5..b063cfa 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11692,18 +11692,26 @@ static int nested_vmx_check_msr_switch(struct kvm_vcpu *vcpu, static int nested_vmx_check_msr_switch_controls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { + if (vmcs12->vm_entry_msr_load_count == 0) + return 0; /* Fast path */ + if (nested_vmx_check_msr_switch(vcpu, VM_ENTRY_MSR_LOAD_COUNT, + VM_ENTRY_MSR_LOAD_ADDR)) + return -EINVAL; + return 0; +} + +static int nested_vmx_check_exit_msr_switch_controls(struct kvm_vcpu *vcpu, + struct vmcs12 *vmcs12) +{ if (vmcs12->vm_exit_msr_load_count == 0 && - vmcs12->vm_exit_msr_store_count == 0 && - vmcs12->vm_entry_msr_load_count == 0) + vmcs12->vm_exit_msr_store_count == 0) return 0; /* Fast path */ if (nested_vmx_check_msr_switch(vcpu, VM_EXIT_MSR_LOAD_COUNT, VM_EXIT_MSR_LOAD_ADDR) || nested_vmx_check_msr_switch(vcpu, VM_EXIT_MSR_STORE_COUNT, - VM_EXIT_MSR_STORE_ADDR) || - nested_vmx_check_msr_switch(vcpu, VM_ENTRY_MSR_LOAD_COUNT, - VM_ENTRY_MSR_LOAD_ADDR)) + VM_EXIT_MSR_STORE_ADDR)) return -EINVAL; - return 0; + return 0; } static int nested_vmx_check_pml_controls(struct kvm_vcpu *vcpu, @@ -12387,13 +12395,25 @@ static int nested_check_vm_execution_ctls(struct vmcs12 *vmcs12) return 0; } +/* + * Checks related to VM-Exit Control Fields + */ +static int nested_check_vm_exit_ctls(struct vmcs12 *vmcs12) +{ + if (nested_vmx_check_exit_msr_switch_controls(vcpu, vmcs12)) + return -EINVAL; + + return 0; +} + static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { struct vcpu_vmx *vmx = to_vmx(vcpu); if (nested_check_guest_state_area(vmcs12) || nested_check_host_state_area(vmcs12) || - nested_check_vm_execution_ctls(vmcs12)) + nested_check_vm_execution_ctls(vmcs12) || + nested_check_vm_exit_ctls(vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; if (nested_vmx_check_msr_switch_controls(vcpu, vmcs12))