From patchwork Mon Jul 23 22:42:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10541265 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 F02D8112E for ; Mon, 23 Jul 2018 23:05:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF20B28531 for ; Mon, 23 Jul 2018 23:05:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D30072858A; Mon, 23 Jul 2018 23:05:45 +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 74E3028531 for ; Mon, 23 Jul 2018 23:05:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388107AbeGXAJM (ORCPT ); Mon, 23 Jul 2018 20:09:12 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51410 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388066AbeGXAJM (ORCPT ); Mon, 23 Jul 2018 20:09:12 -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 w6NN5G41188375; Mon, 23 Jul 2018 23:05:29 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=6iNQIu7f/Z1SeMbBSmioLmbF0HOpLdVHA2N7wUKageA=; b=cf7u7uP9hGdrhCPzq/9FzJfi3lumja1W5EFi5d8pQbchxEsFEm3s3mOIniMKKfp+ZAJ6 UFz4cQDT2tb33TvILn5uGmgLOnJxX+ErdNaLWLIM4GkWCSaupMYthl9NMNn7nulUOgfQ i2xHhcz5DHVb3nQEIg+S0/Vf6jS/yWP1Z9ulDZFVF+FKoWmd7eOE6rvAkzWc1WzH5SMM 3e+D4jQcEy4venRD1Y3zATmh3QGP0Rt8YR4aWjBKUgQe/5kNg/BYh/UUXyqVwwcpTZdh hmffeAbYe6+lmSJTI7d8H85iIe77W61u4007AM/NRps2xBIKqSaGch81wZ/KDTzh4EmO BQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2kbv8sxk3c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jul 2018 23:05:29 +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 w6NN5SmH005997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jul 2018 23:05:28 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6NN5SNu027098; Mon, 23 Jul 2018 23:05:28 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Jul 2018 16:05:28 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [kvm-unit-test] nVMX x86: "external-interrupt exiting" must be set if "virtual-interrupt delivery" is set Date: Mon, 23 Jul 2018 18:42:40 -0400 Message-Id: <20180723224240.18360-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180723224240.18360-1-krish.sadhukhan@oracle.com> References: <20180723224240.18360-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8963 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=713 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807230252 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 "virtual-interrupt delivery" VM-execution control is 1, the "external-interrupt exiting" VM-execution control must be 1. This unit-test validates the above vmentry check. Signed-off-by: Krish Sadhukhan Reviewed-by: Karl Heubaum Reviewed-by: Jim Mattson --- x86/vmx_tests.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index e9fbc22..8821aed 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3690,11 +3690,57 @@ static void test_apic_virtual_ctls(void) vmcs_write(CPU_EXEC_CTRL1, saved_secondary); } +/* + * If the "virtual-interrupt delivery" VM-execution control is 1, the + * "external-interrupt exiting" VM-execution control must be 1. + * [Intel SDM] + */ +static void test_virtual_intr_ctls(void) +{ + u32 saved_primary = vmcs_read(CPU_EXEC_CTRL0); + u32 saved_secondary = vmcs_read(CPU_EXEC_CTRL1); + u32 pin_saved = vmcs_read(PIN_CONTROLS); + u32 primary = saved_primary; + u32 secondary = saved_secondary; + u32 pin = pin_saved; + + if (!((ctrl_cpu_rev[1].clr & CPU_VINTD) && + (ctrl_pin_rev.clr & PIN_EXTINT))) + return; + + vmcs_write(CPU_EXEC_CTRL0, primary | CPU_SECONDARY | CPU_TPR_SHADOW); + vmcs_write(CPU_EXEC_CTRL1, secondary & ~CPU_VINTD); + vmcs_write(PIN_CONTROLS, pin & ~PIN_EXTINT); + report_prefix_pushf("Virtualize interrupt-delivery disabled; external-interrupt exiting disabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(CPU_EXEC_CTRL1, secondary | CPU_VINTD); + report_prefix_pushf("Virtualize interrupt-delivery enabled; external-interrupt exiting disabled"); + test_vmx_controls(false, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, pin | PIN_EXTINT); + report_prefix_pushf("Virtualize interrupt-delivery enabled; external-interrupt exiting enabled"); + test_vmx_controls(true, false); + report_prefix_pop(); + + vmcs_write(PIN_CONTROLS, pin & ~PIN_EXTINT); + report_prefix_pushf("Virtualize interrupt-delivery enabled; external-interrupt exiting disabled"); + test_vmx_controls(false, false); + report_prefix_pop(); + + vmcs_write(CPU_EXEC_CTRL0, saved_primary); + vmcs_write(CPU_EXEC_CTRL1, saved_secondary); + vmcs_write(PIN_CONTROLS, pin_saved); +} + static void test_apic_ctls(void) { test_apic_virt_addr(); test_apic_access_addr(); test_apic_virtual_ctls(); + test_virtual_intr_ctls(); } static void set_vtpr(unsigned vtpr)