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)