From patchwork Thu Nov 1 05:21:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10663493 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 EE13613A4 for ; Thu, 1 Nov 2018 05:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A6A2BC02 for ; Thu, 1 Nov 2018 05:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBFD02BC07; Thu, 1 Nov 2018 05:46:09 +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 857EC2BC02 for ; Thu, 1 Nov 2018 05:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727688AbeKAOrg (ORCPT ); Thu, 1 Nov 2018 10:47:36 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56192 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727573AbeKAOrf (ORCPT ); Thu, 1 Nov 2018 10:47:35 -0400 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 wA15hvq4055330; Thu, 1 Nov 2018 05:45:58 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=t1mvf/XuuoSjG0W3QfQbblQXxFubid+e63PtLt1AY04=; b=P7BTjj+LeR/DJK+AGbh9juLScTzF0gezq93Gy/F4x/U4TM1vgNI6cSpU5Cg+RtdP/s2i 15Ut+Mwe+z/DxstGhpVVQGhhFhzN2y6491TjKG+0FnFZakjuiZwkCyXexcfiy2K8x1uc 4kmC3aKdvsu42qT/UAicweGc8VmZLtbkCmflXf+Ntq+766h+P83eEVSscXvtsj6o+K8l hzSe2w9DvTZNq6MsWyKkGkCtICqm2szi2DiRrjWVpBVnHN7URL7j9vEi63pFoiaxWU1z 8FLVOpRgyazNn8gLwjJeB4HS388u8aMpLLIvesSp2qkIrRd4RBHOt0F0CnvrAklJhh8R Bw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2ncfyq6us8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Nov 2018 05:45:58 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wA15jvxx016280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Nov 2018 05:45:57 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA15jv68029166; Thu, 1 Nov 2018 05:45:57 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 Oct 2018 22:45:56 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 1/2] nVMX x86: Check VMX-preemption timer controls on vmentry of L2 guests Date: Thu, 1 Nov 2018 01:21:58 -0400 Message-Id: <20181101052159.32695-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181101052159.32695-1-krish.sadhukhan@oracle.com> References: <20181101052159.32695-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9063 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=839 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811010052 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to section "Checks on VMX Controls" in Intel SDM vol 3C, the following check needs to be enforced on vmentry of L2 guests: If the "activate VMX-preemption timer" VM-execution control is 0, the the "save VMX-preemption timer value" VM-exit control must also be 0. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas Reviewed-by: Liran Alon --- arch/x86/kvm/vmx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index e665aa7..8c8f840 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2054,6 +2054,12 @@ static inline bool nested_cpu_has_shadow_vmcs(struct vmcs12 *vmcs12) return nested_cpu_has2(vmcs12, SECONDARY_EXEC_SHADOW_VMCS); } +static inline bool nested_cpu_has_save_preemption_timer(struct vmcs12 *vmcs12) +{ + return vmcs12->vm_exit_controls & + VM_EXIT_SAVE_VMX_PREEMPTION_TIMER; +} + static inline bool is_nmi(u32 intr_info) { return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK)) @@ -12409,6 +12415,10 @@ static int check_vmentry_prereqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) if (nested_vmx_check_msr_switch_controls(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + if (!nested_cpu_has_preemption_timer(vmcs12) && + nested_cpu_has_save_preemption_timer(vmcs12)) + return VMXERR_ENTRY_INVALID_CONTROL_FIELD; + if (nested_vmx_check_pml_controls(vcpu, vmcs12)) return VMXERR_ENTRY_INVALID_CONTROL_FIELD; From patchwork Thu Nov 1 05:21:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10663491 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 A927617DF for ; Thu, 1 Nov 2018 05:46:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A45102BC02 for ; Thu, 1 Nov 2018 05:46:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 984BF2BC07; Thu, 1 Nov 2018 05:46:07 +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 386612BC05 for ; Thu, 1 Nov 2018 05:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbeKAOrd (ORCPT ); Thu, 1 Nov 2018 10:47:33 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:38822 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727573AbeKAOrd (ORCPT ); Thu, 1 Nov 2018 10:47:33 -0400 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 wA15i64v052597; Thu, 1 Nov 2018 05:45:58 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=ZdwyifdIm0IXz1dA5kY/H6iDZD493LipVg1LXrQsolI=; b=KLmfE19NJppAawe410LbMqs/aBWHxQJ2kgX8d09fHZisu6DVR4wySFP6j5YUow+VJrlG YFQsZLK3qnMFeHGAjbxA/Z7E0wFwB26BiPA0QylvGOr/jQZh5jBbbD1PCMNOKqzjQgqw COA+uvaW/0O3MwAKKq8jaISrCrVibKJWr4DT44kkfkOWHRrs/+/DKQAwSzB1orYMMs33 53rICjcRyhGFeI34FH4jV2G0MrlUHVRBxYcUd4F1TK9HdEa6wb90HL4HlRrQPFSTUWwl qFuBt2CacTgd5T3+uEaS4/6CH1yFBB3UzRJIE78VGx5DuuPZSu5y7YvAzVvtNPamnR3N wQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2nducmbgsn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Nov 2018 05:45:58 +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 wA15jvJs016292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Nov 2018 05:45:58 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA15jv9g020612; Thu, 1 Nov 2018 05:45:57 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 Oct 2018 22:45:57 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 2/2][kvm-unit-test] nVMX x86: Check VMX-preemption timer controls on vmentry of L2 guests Date: Thu, 1 Nov 2018 01:21:59 -0400 Message-Id: <20181101052159.32695-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20181101052159.32695-1-krish.sadhukhan@oracle.com> References: <20181101052159.32695-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9063 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=848 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811010052 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to section "Checks on VMX Controls" in Intel SDM vol 3C, the following check needs to be enforced on vmentry of L2 guests: If the "activate VMX-preemption timer" VM-execution control is 0, the the "save VMX-preemption timer value" VM-exit control must also be 0. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas --- x86/vmx_tests.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index b105b23..7f49048 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4721,6 +4721,55 @@ static void test_pml(void) vmcs_write(CPU_EXEC_CTRL1, secondary_saved); } + /* + * If the "activate VMX-preemption timer" VM-execution control is 0, the + * the "save VMX-preemption timer value" VM-exit control must also be 0. + * + * [Intel SDM] + */ +static void test_vmx_preemption_timer(void) +{ + u32 saved_pin = vmcs_read(PIN_CONTROLS); + u32 saved_exit = vmcs_read(EXI_CONTROLS); + u32 pin = saved_pin; + u32 exit = saved_exit; + + if (!((ctrl_exit_rev.clr & EXI_SAVE_PREEMPT) || + (ctrl_pin_rev.clr & PIN_PREEMPT))) { + printf("\"Save-VMX-preemption-timer\" control and/or \"Enable-VMX-preemption-timer\" control is not supported\n"); + return; + } + + pin |= PIN_PREEMPT; + vmcs_write(PIN_CONTROLS, pin); + exit &= ~EXI_SAVE_PREEMPT; + vmcs_write(EXI_CONTROLS, exit); + report_prefix_pushf("enable-VMX-preemption-timer enabled, save-VMX-preemption-timer disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + exit |= EXI_SAVE_PREEMPT; + vmcs_write(EXI_CONTROLS, exit); + report_prefix_pushf("enable-VMX-preemption-timer enabled, save-VMX-preemption-timer enabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + pin &= ~PIN_PREEMPT; + vmcs_write(PIN_CONTROLS, pin); + report_prefix_pushf("enable-VMX-preemption-timer disabled, save-VMX-preemption-timer enabled"); + test_vmx_controls(false, false); + report_prefix_pop(); + + exit &= ~EXI_SAVE_PREEMPT; + vmcs_write(EXI_CONTROLS, exit); + report_prefix_pushf("enable-VMX-preemption-timer disabled, save-VMX-preemption-timer disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, saved_pin); + vmcs_write(EXI_CONTROLS, saved_exit); +} + /* * Check that the virtual CPU checks all of the VMX controls as * documented in the Intel SDM. @@ -4747,6 +4796,7 @@ static void vmx_controls_test(void) test_invalid_event_injection(); test_vpid(); test_eptp(); + test_vmx_preemption_timer(); } static bool valid_vmcs_for_vmentry(void)