From patchwork Tue Nov 13 06:12:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679803 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 3D3701759 for ; Tue, 13 Nov 2018 06:36:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DE4528FDF for ; Tue, 13 Nov 2018 06:36:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21F8929ABC; Tue, 13 Nov 2018 06:36:32 +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 BC62E28FDF for ; Tue, 13 Nov 2018 06:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731001AbeKMQdB (ORCPT ); Tue, 13 Nov 2018 11:33:01 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:60774 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730819AbeKMQdB (ORCPT ); Tue, 13 Nov 2018 11:33:01 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAD6ZG43018291; Tue, 13 Nov 2018 06:36:17 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=BIhmCxsAm9Szfkmc+RuGDN+Rg6o8kDJXGmo+jhdJQFU=; b=Dh72CQPfFwcQ1ajvbkkVAU2EwQC7ImIyD6eNKVcTWO/g6wdza0+LjkUe5XCW4ECQQ5FI Q1yjccE51f64skvs7WgWE+YBuR9X0qAgWGvJgxLQEd6NmlSvqMgnkFfam1nCc3BfEWIs GJU1bguRUosoev7oB+SKNwAPuphbkDM2EfYDztHZJmzta1cTb/vkNuVW3PoHz4ML5vpL 6i9AuTQxjbXGX6CZqwFhEyNVVrVgasK8RIIbiyFsAsYGwMjxV+Pq8xx6NT+Df7gpPE9Z +l2vDHfigQFdwCCRB3LIgSaT1sEk5j4d01OHlnpEw4Ag7cvIlwENYLpjv6h6+YGQii6A 0g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2nnw6egjd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:17 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aFFf032284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:16 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 wAD6aFIA004926; Tue, 13 Nov 2018 06:36:15 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:15 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH 1/6] nVMX x86: Re-name check_vmentry_pre[post]reqs to nested_check_vmentry_pre[post] Date: Tue, 13 Nov 2018 01:12:04 -0500 Message-Id: <20181113061209.6843-2-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=699 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 Re-name the functions check_vmentry_pre[post]reqs to nested_check_pre[post]reqs because these functions are used only in nested context. Signed-off-by: Krish Sadhukhan Reviewed-by: Liran Alon Reviewed-by: Mihai Carabas Reviewed-by: Mark Kanda --- arch/x86/kvm/vmx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 8dae47e..0f6c38f 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12313,7 +12313,7 @@ static int nested_vmx_check_nmi_controls(struct vmcs12 *vmcs12) return 0; } -static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) +static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -12472,7 +12472,7 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu, return r; } -static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, +static int nested_check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, u32 *exit_qual) { bool ia32e; @@ -12650,7 +12650,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) goto out; } - ret = check_vmentry_prereqs(vcpu, vmcs12); + ret = nested_check_vmentry_prereqs(vcpu, vmcs12); if (ret) { nested_vmx_failValid(vcpu, ret); goto out; @@ -12665,7 +12665,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) */ skip_emulated_instruction(vcpu); - ret = check_vmentry_postreqs(vcpu, vmcs12, &exit_qual); + ret = nested_check_vmentry_postreqs(vcpu, vmcs12, &exit_qual); if (ret) { nested_vmx_entry_failure(vcpu, vmcs12, EXIT_REASON_INVALID_STATE, exit_qual); @@ -13987,8 +13987,8 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu, return -EINVAL; } - if (check_vmentry_prereqs(vcpu, vmcs12) || - check_vmentry_postreqs(vcpu, vmcs12, &exit_qual)) + if (nested_check_vmentry_prereqs(vcpu, vmcs12) || + nested_check_vmentry_postreqs(vcpu, vmcs12, &exit_qual)) return -EINVAL; if (kvm_state->flags & KVM_STATE_NESTED_RUN_PENDING) From patchwork Tue Nov 13 06:12:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679799 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 4CCC114BA for ; Tue, 13 Nov 2018 06:36:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CCF628FDF for ; Tue, 13 Nov 2018 06:36:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3161D29ABC; Tue, 13 Nov 2018 06:36:29 +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 CE65028FDF for ; Tue, 13 Nov 2018 06:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731049AbeKMQdF (ORCPT ); Tue, 13 Nov 2018 11:33:05 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47242 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731025AbeKMQdE (ORCPT ); Tue, 13 Nov 2018 11:33:04 -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 wAD6Ye80050453; Tue, 13 Nov 2018 06:36:22 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=mwANRWznVtkr8QEKMwWC979a9KcW5acSknjYia1jrHM=; b=gs0IybASCdwSt2dcJqep+LyjVNpsnm5WKGg+p2thRjc80x9WhMUJs0ctY1fZKGwoJC56 jLgW/8Yo7+dUT8ByLtYLZKpiL/oQ8kd8Vdr/JSHXH+Yg9acXW017hz69DhZ12Jj2ftUG AWyMwhCTY9ftsXNBRfG+nDbAC5kJckP9GrbD1ekNMGyMcXagkIspEAOrA36sRvHJogPj dokDSXWqTWNhqwDEhNUHmsaKOer3vOSCktsZFPmQ1h/4sNV6taObxZUTwLPXHKUOOZGj BvLxKvJVUoTgEmOS6DOszUjG1CoAADNOniBgJWLhNlGMyTh15klcjf+ILy96zet13zXq iA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2nnwg18ft5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:22 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aGrp032307 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:16 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 wAD6aGsi004930; Tue, 13 Nov 2018 06:36:16 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:15 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH 2/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), related to Guest State Area Date: Tue, 13 Nov 2018 01:12:05 -0500 Message-Id: <20181113061209.6843-3-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=999 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 nested_check_vmentry_prereqs(), that are related to Guest State Area, 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 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 0f6c38f..d9f3bc7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12313,12 +12313,23 @@ static int nested_vmx_check_nmi_controls(struct vmcs12 *vmcs12) return 0; } +/* + * Checks related to Guest State Area + */ +static int nested_check_guest_state_area(struct vmcs12 *vmcs12) +{ + if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE && + vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT) + 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 (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE && - vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT) + if (nested_check_guest_state_area(vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12)) From patchwork Tue Nov 13 06:12:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679793 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 AF33614BA for ; Tue, 13 Nov 2018 06:36:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EB9828FDF for ; Tue, 13 Nov 2018 06:36:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91C8229AC7; Tue, 13 Nov 2018 06:36:26 +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 3C25728FDF for ; Tue, 13 Nov 2018 06:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731024AbeKMQdD (ORCPT ); Tue, 13 Nov 2018 11:33:03 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:60788 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730984AbeKMQdC (ORCPT ); Tue, 13 Nov 2018 11:33:02 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAD6YFHB017733; 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=Ec62fG9umyAW7eiaAQ7SSwuJS1HYPkq0O6CkTMLRDKc=; b=sq6/9+fU7Kl7QgpPxpVgaW+Wtaung9WEbWxQxB3u5lp0SH8lCmherpWdazoZdaisSfQt /7mDSckZ0c+yeIyfcYOOOLlmjUtF6i8kJE+DA9GZoLV/VOPs1omxmL0a062xFNYic2ux //Cmk4YD7yYNFQiiOAcYDG3geDLsaEEcjlWrxeQzqKXrwQKOzdI0zTdytTiUI0+z+kCd Dp0y3d46OLjwIh3peOSErJZCJ3Ef7Q1nJq8g3mf2TbWrGz186JZ+aUdiWeZW2ZJFBM+y LqGeTUho9g3P+3UZzk1Oq3KANsy/TlqnJIj/EVemW/d7WmanXZOY+YqHJr8obuuDBv7H Iw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2nnw6egjd8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:17 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aGsx032324 (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 wAD6aGDE004935; Tue, 13 Nov 2018 06:36:16 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:16 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH 3/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), that are related to Host State Area Date: Tue, 13 Nov 2018 01:12:06 -0500 Message-Id: <20181113061209.6843-4-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=999 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 nested_check_vmentry_prereqs(), that are related to the Host State Area, 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d9f3bc7..735b634 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12325,11 +12325,25 @@ static int nested_check_guest_state_area(struct vmcs12 *vmcs12) return 0; } +/* + * Checks related to Host State Area + */ +static int nested_check_host_state_area(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) { struct vcpu_vmx *vmx = to_vmx(vcpu); - if (nested_check_guest_state_area(vmcs12)) + if (nested_check_guest_state_area(vmcs12) || + nested_check_host_state_area(vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12)) @@ -12392,11 +12406,6 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu)) 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)) - return VMXERR_ENTRY_INVALID_HOST_STATE_FIELD; - /* * From the Intel SDM, volume 3: * Fields relevant to VM-entry event injection must be set properly. From patchwork Tue Nov 13 06:12:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679801 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 D30CE1759 for ; Tue, 13 Nov 2018 06:36:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D8828FDF for ; Tue, 13 Nov 2018 06:36:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B521B29ABC; Tue, 13 Nov 2018 06:36:30 +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 4C71928FDF for ; Tue, 13 Nov 2018 06:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731052AbeKMQdH (ORCPT ); Tue, 13 Nov 2018 11:33:07 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47208 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730979AbeKMQdB (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 wAD6YEK3050338; 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=9SkOcs6WN2SuEskC5qk4ZOXC7x1AZTPFD6WFt2yj610=; b=CefeqCsVaEj3HTTibU8yL1Rguio7D1XLF3mfsIgF6oRoJOVIpHF1VCz7e8QXNjkMTvYu 4/lLh1tJvSroMkWwqXMLI4G7UhPXDkyvFOe6bpIaHWUULmE0Ll4l3C1kcTbBo1LQPEwb nH4OOmvxRxRPltwxNDhWSSgtpXJdEqa9wqe1HDvqz2vJ5H80pv6VrwmOwqU3/54zccjg gictdRvXVE21VDpDBJE5PE4JX51e0e7ZsKQ89VY9TOKlF1dqLtGib5HuSg/v8IJrh1pq UgUXkh8aInU4AC0wLeK/LVcxiRmcVVEB4Gt2BZs9bAUErEx35QKnKNGYN+rGbj95KZYG ZA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2nnwg18fst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:18 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aHAh005377 (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 aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wAD6aHKY010566; 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:16 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH 4/6] nVMX x86: Re-organize the code in nested_check_vmentry_prereqs(), that is related to VM-Execution Control Fields Date: Tue, 13 Nov 2018 01:12:07 -0500 Message-Id: <20181113061209.6843-5-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=999 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 nested_check_vmentry_prereqs(), that are related to the VM-Execution 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 | 73 ++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 735b634..68335f5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -12338,39 +12338,19 @@ static int nested_check_host_state_area(struct vmcs12 *vmcs12) 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)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_msr_bitmap_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_apic_access_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_tpr_shadow_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_apicv_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_msr_switch_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_pml_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_shadow_vmcs_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (!vmx_control_verify(vmcs12->cpu_based_vm_exec_control, +/* + * Checks related to VM-Execution Control Fields + */ +static int nested_check_vm_execution_ctls(struct vmcs12 *vmcs12) +{ + if (nested_vmx_check_io_bitmap_controls(vcpu, vmcs12) || + nested_vmx_check_msr_bitmap_controls(vcpu, vmcs12) || + nested_vmx_check_apic_access_controls(vcpu, vmcs12) || + nested_vmx_check_tpr_shadow_controls(vcpu, vmcs12) || + nested_vmx_check_apicv_controls(vcpu, vmcs12) || + nested_vmx_check_pml_controls(vcpu, vmcs12) || + nested_vmx_check_shadow_vmcs_controls(vcpu, vmcs12) || + !vmx_control_verify(vmcs12->cpu_based_vm_exec_control, vmx->nested.msrs.procbased_ctls_low, vmx->nested.msrs.procbased_ctls_high) || (nested_cpu_has(vmcs12, CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) && @@ -12385,25 +12365,38 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm vmx->nested.msrs.exit_ctls_high) || !vmx_control_verify(vmcs12->vm_entry_controls, vmx->nested.msrs.entry_ctls_low, - vmx->nested.msrs.entry_ctls_high)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_nmi_controls(vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + vmx->nested.msrs.entry_ctls_high) || + nested_vmx_check_nmi_controls(vmcs12)) + return -EINVAL; if (nested_cpu_has_vmfunc(vmcs12)) { if (vmcs12->vm_function_control & ~vmx->nested.msrs.vmfunc_controls) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + return -EINVAL; if (nested_cpu_has_eptp_switching(vmcs12)) { if (!nested_cpu_has_ept(vmcs12) || !page_address_valid(vcpu, vmcs12->eptp_list_address)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + return -EINVAL; } } if (vmcs12->cr3_target_count > nested_cpu_vmx_misc_cr3_count(vcpu)) + 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)) + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + + if (nested_vmx_check_msr_switch_controls(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; /* 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)) From patchwork Tue Nov 13 06:12:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10679797 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 DAB3814BA 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 CA23C28FDF for ; Tue, 13 Nov 2018 06:36:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE46929ABC; 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 59F5E28FDF for ; Tue, 13 Nov 2018 06:36:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731012AbeKMQdE (ORCPT ); Tue, 13 Nov 2018 11:33:04 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47228 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731013AbeKMQdD (ORCPT ); Tue, 13 Nov 2018 11:33:03 -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 wAD6YALD050044; Tue, 13 Nov 2018 06:36:19 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=klkmhta09SPjw8Ja5qaDDeo4NHtfGtQgPphfn8jg+YI=; b=CjKGFJzGgFBdTKS/WNovmIaue7klxaLwzVINTO9uF7LkzLPzZzHtYdkF+Bk3urCgdPJa YMbqfBC/o7AR/NYJ/CrDKxsC0XmK46XHQkVqRW2QIpl7HFi7wrCLxnRRWRSEGOeO+mDL 3RRgpwVgYkFRyhLR3lKadJuSxlyZjhxfGx+fTGJ+BOZnyHLkZ7wml2MT5Ih0yQhv1Q6T XvtVap70kp18KqywYUzcUHuFQ3FqmsxCAoFHQmR5M51VP5QmaYvGgAG/jFcBbH48L4oW d5RgEV7udETX4Boc5vNHBsbUFC73F7agYJorO7U7SmhIma9oiVEzhk/5QC+19vXujF23 sA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2nnwg18fsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:19 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aI0P005395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 06:36:18 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wAD6aI1U028108; Tue, 13 Nov 2018 06:36:18 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 6/6] nVMX x86: Re-organize the code in check_vmentry_prereqs(), that are related to VM-Entry Control Fields Date: Tue, 13 Nov 2018 01:12:09 -0500 Message-Id: <20181113061209.6843-7-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=886 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-Entry 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 | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b063cfa..a376eb1 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11689,7 +11689,7 @@ static int nested_vmx_check_msr_switch(struct kvm_vcpu *vcpu, return 0; } -static int nested_vmx_check_msr_switch_controls(struct kvm_vcpu *vcpu, +static int nested_vmx_check_entry_msr_switch_controls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) { if (vmcs12->vm_entry_msr_load_count == 0) @@ -12403,22 +12403,6 @@ 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_exit_ctls(vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - - if (nested_vmx_check_msr_switch_controls(vcpu, vmcs12)) - return VMXERR_ENTRY_INVALID_CONTROL_FIELD; - /* * From the Intel SDM, volume 3: * Fields relevant to VM-entry event injection must be set properly. @@ -12478,6 +12462,20 @@ static int nested_check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vm 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_exit_ctls(vmcs12) || + nested_vmx_check_entry_msr_switch_controls(vmcs12)) + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + + return 0; +} + static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) {