From patchwork Sat Dec 23 01:34:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liran Alon X-Patchwork-Id: 10131365 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 ED05560388 for ; Sat, 23 Dec 2017 01:35:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1BE629B30 for ; Sat, 23 Dec 2017 01:35:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C30412A0C8; Sat, 23 Dec 2017 01:35:38 +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 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 9B86C29B30 for ; Sat, 23 Dec 2017 01:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757042AbdLWBfA (ORCPT ); Fri, 22 Dec 2017 20:35:00 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41310 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756729AbdLWBe7 (ORCPT ); Fri, 22 Dec 2017 20:34:59 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vBN1VwMH124544; Sat, 23 Dec 2017 01:34:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=mbwoKhjEAlHO4upWRnPuOYI4K7nh9Z3/YYMPkWf4kfU=; b=KgOeq9+SPQnl4WEWf1XiHECWTN45kFd+KSo3Y24DZQ6f9xB7G/SxRyyL2o2hsAgcsXHa uLx7H5J1Xhbk6sRYqoAbLK/gxtssw2mIdKm+KJ6vfRbJ58rUmBGqPYcgVhEAi7W7wPA9 +hMEJLJrzFWxxnTQ2A5qLlGnKwkBpPCt7pNZao/HslT8J8lgTTJCvbNTJZEiX+kXm/rz kRcFKuhx8pJoyYaQkD/xcSKniV/3e9ruMI1JxjVGv9EEq/STyBdTFh4w9g06D3FXG49H 2+9+SaMN9M3hXq3Ka43WWwzq082yECUlJVKUVQsU4i7geZ9NPApsEVn6PCFttmbBb47q Zw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2f1dae80wc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 23 Dec 2017 01:34:55 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vBN1YsJ9022607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 23 Dec 2017 01:34:54 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vBN1Yrf2017102; Sat, 23 Dec 2017 01:34:53 GMT MIME-Version: 1.0 Message-ID: <71a46d1d-6794-4318-9512-9c6ac81380a8@default> Date: Fri, 22 Dec 2017 17:34:53 -0800 (PST) From: Liran Alon To: Cc: , , , Subject: Re: [PATCH nVMX TEST 2/2] x86: Add test for checking NMI controls on vmentry of L2 guests X-Mailer: Zimbra on Oracle Beehive Content-Disposition: inline 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712230020 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reviewed-by: Liran Alon ----- Original Message ----- From: krish.sadhukhan@oracle.com To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, rkrcmar@redhat.com Sent: Saturday, December 23, 2017 2:26:45 AM (GMT+0200) Auto-Detected Subject: [PATCH nVMX TEST 2/2] x86: Add test for checking NMI controls on vmentry of L2 guests 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)