From patchwork Sat Dec 23 00:13:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10131271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBFA06019D for ; Sat, 23 Dec 2017 00:26:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD61129DAA for ; Sat, 23 Dec 2017 00:26:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C05B22A1F5; Sat, 23 Dec 2017 00:26:36 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 5F79129DAA for ; Sat, 23 Dec 2017 00:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756808AbdLWA0d (ORCPT ); Fri, 22 Dec 2017 19:26:33 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:52324 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756065AbdLWA0a (ORCPT ); Fri, 22 Dec 2017 19:26:30 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vBN0NLVr185895; Sat, 23 Dec 2017 00:26:27 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 : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=1BChgXFZ7FXHyXqkHsj5+0cVZQEqsskyyr2k5PzJZeY=; b=iZ/oaYt56L/0vNzUUxl8kmXiq+u6I9mH2nllKkoVbIxeMBr7hCIdT7D4gSqTNfsPhdoo jbB8KnaN1v8Gdu1f8LCRBK5Z52O5py/CNzr3esdfqSJsJpdIXOazRXm1oODK6HbcZ7C2 cOawwTgA7MluDOiSYl9qgpGrQCABToMxx0hjy1R5RzplcKY+oeZ77OHSHKy2sx29SBZN 2Zi1eELkhXxqxIMb1dg4nxGj/Ipcru1+Q8vSnNpntEg9OMtImfyBEI56OFNYgs1H0A1i 6Wc+AZp3eorLIlnixQcnB/u1qCgAWYdNClJTaSgtzzVZpnEsHDNjzLVVYWVuJ7Ywa8YW hw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2f1cecg0bq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 Dec 2017 00:26:27 +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 vBN0LQwq031530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 23 Dec 2017 00:21:26 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 vBN0LP39018956; Sat, 23 Dec 2017 00:21:25 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 22 Dec 2017 16:21:25 -0800 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Subject: [PATCH nVMX TEST 2/2] x86: Add test for checking NMI controls on vmentry of L2 guests Date: Fri, 22 Dec 2017 19:13:58 -0500 Message-Id: <20171223001358.19629-3-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171223001358.19629-1-krish.sadhukhan@oracle.com> References: <20171223001358.19629-1-krish.sadhukhan@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8753 signatures=668650 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=846 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712230004 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This test validates the following vmentry checks from Intel SDM 26.2.1.1: 1. If the “NMI exiting” VM-execution control is 0, the “virtual NMIs” VM-execution control must be 0. 2. If the “virtual NMIs” VM-execution control is 0, the “NMI-window exiting” VM-execution control must be 0. Signed-off-by: Krish Sadhukhan --- x86/vmx_tests.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index e8c97f2..1eb8af7 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3553,6 +3553,88 @@ static void test_tpr_threshold(void) } /* + * This test verifies the following two vmentry checks: + * + * If the "NMI exiting" VM-execution control is 0, "Virtual NMIs" + * VM-execution control must be 0. + * [Intel SDM] + * + * If the “virtual NMIs” VM-execution control is 0, the “NMI-window + * exiting” VM-execution control must be 0. + * [Intel SDM] + */ +static void test_nmi_ctrls(void) +{ + u32 pin_ctrls, cpu_ctrls0, test_pin_ctrls, test_cpu_ctrls0; + + if (((ctrl_pin_rev.clr & (PIN_NMI | PIN_VIRT_NMI)) != + (PIN_NMI | PIN_VIRT_NMI)) || + ! (ctrl_cpu_rev[0].clr & CPU_NMI_WINDOW)) { + test_skip("NMI controls not supported !"); + return; + } + + /* Save the controls so that we can restore them after our tests */ + pin_ctrls = vmcs_read(PIN_CONTROLS); + cpu_ctrls0 = vmcs_read(CPU_EXEC_CTRL0); + + test_pin_ctrls = pin_ctrls & ~(PIN_NMI | PIN_VIRT_NMI); + test_cpu_ctrls0 = cpu_ctrls0 & ~CPU_NMI_WINDOW; + + vmcs_write(PIN_CONTROLS, test_pin_ctrls); + report_prefix_pushf("NMI-exiting disabled, virtual-NMIs disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls | PIN_VIRT_NMI); + report_prefix_pushf("NMI-exiting disabled, virtual-NMIs enabled"); + test_vmx_controls(false, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls | (PIN_NMI | PIN_VIRT_NMI)); + report_prefix_pushf("NMI-exiting enabled, virtual-NMIs enabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls | PIN_NMI); + report_prefix_pushf("NMI-exiting enabled, virtual-NMIs disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls); + vmcs_write(CPU_EXEC_CTRL0, test_cpu_ctrls0 | CPU_NMI_WINDOW); + report_prefix_pushf("Virtual-NMIs disabled, NMI-window-exiting " + "enabled"); + test_vmx_controls(false, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls); + vmcs_write(CPU_EXEC_CTRL0, test_cpu_ctrls0); + report_prefix_pushf("Virtual-NMIs disabled, NMI-window-exiting " + "disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls | (PIN_NMI | PIN_VIRT_NMI)); + vmcs_write(CPU_EXEC_CTRL0, test_cpu_ctrls0 | CPU_NMI_WINDOW); + report_prefix_pushf("Virtual-NMIs enabled, NMI-window-exiting " + "enabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, test_pin_ctrls | (PIN_NMI | PIN_VIRT_NMI)); + vmcs_write(CPU_EXEC_CTRL0, test_cpu_ctrls0); + report_prefix_pushf("Virtual-NMIs enabled, NMI-window-exiting " + "disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + /* Restore the controls to their original values */ + vmcs_write(CPU_EXEC_CTRL0, cpu_ctrls0); + vmcs_write(PIN_CONTROLS, pin_ctrls); +} + +/* * Check that the virtual CPU checks all of the VMX controls as * documented in the Intel SDM. */ @@ -3573,6 +3655,7 @@ static void vmx_controls_test(void) test_msr_bitmap(); test_apic_virt_addr(); test_tpr_threshold(); + test_nmi_ctrls(); } static bool valid_vmcs_for_vmentry(void)