From patchwork Thu Nov 15 05:45:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10683595 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 F1F5746E4 for ; Thu, 15 Nov 2018 06:10:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E29032BCD4 for ; Thu, 15 Nov 2018 06:10:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6EC12BCD8; Thu, 15 Nov 2018 06:10:14 +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 7F7E92BCD6 for ; Thu, 15 Nov 2018 06:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbeKOQQl (ORCPT ); Thu, 15 Nov 2018 11:16:41 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42234 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbeKOQQk (ORCPT ); Thu, 15 Nov 2018 11:16:40 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAF649ap106169; Thu, 15 Nov 2018 06:10:08 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=l+WpjbFtuc+9CEBo/C4T3XINfvzE/5cwbCJhuQeo1Ek=; b=Y3vXoxhJsjhIj3GctUMNKLNVgkk4gmklkzcMSBlLg/zjBH+gTSi/LCTM3GoScjW28g3m wNvCkKRUjJDMSJGrIYeISPfGClWDlgrCbJsIAFRLSulT7vmt/pCxYnqaer6cFkE4wZZr IOSeZb7eEI0VQyNQ31+dY6TxnNCtzja889fbN8Q5Lc1XC9ZOhbJ5uQe+lv6MdCzhtGK0 od4hAJZFCKGynm2ehe+Vs4At1+psGsydojo9yVP/YFvwKy+kAfjtuhbVQQq5yI2WmKbq iPVuc/vudYJFZk6uzh6fnXleACjQ1wnf1EFPfUKxxXgVf+q7LYaEoRU32osfz48yWvvQ iQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2nr7cs7ju2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Nov 2018 06:10:08 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wAF6A7wE031418 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Nov 2018 06:10:07 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wAF6A7Ut023646; Thu, 15 Nov 2018 06:10:07 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 14 Nov 2018 22:10:07 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH v2 5/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), that are related to Host Control Registers and MSRs Date: Thu, 15 Nov 2018 00:45:53 -0500 Message-Id: <20181115054554.4831-6-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181115054554.4831-1-krish.sadhukhan@oracle.com> References: <20181115054554.4831-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9077 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=874 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811150055 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 nested_check_vmentry_prereqs(), that are related to the Host Control Registers and MSRs, to a separate function. The re-organized cod 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 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 368e38d..93e49aa 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12518,6 +12518,19 @@ static int nested_check_vm_entry_ctls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs return 0; } +/* + * Checks related to Host Control Registers and MSRs + */ +static int nested_check_host_ctl_regs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) +{ + if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) || + !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) || + !nested_cr3_valid(vcpu, vmcs12->host_cr3)) + return -EINVAL; + + return 0; +} + static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE && @@ -12529,9 +12542,7 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm nested_check_vm_entry_ctls(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - if (!nested_host_cr0_valid(vcpu, vmcs12->host_cr0) || - !nested_host_cr4_valid(vcpu, vmcs12->host_cr4) || - !nested_cr3_valid(vcpu, vmcs12->host_cr3)) + if (nested_check_host_ctl_regs(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD; return 0;