From patchwork Tue Feb 5 22:34:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krish Sadhukhan X-Patchwork-Id: 10798645 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 E9E4E13B4 for ; Tue, 5 Feb 2019 22:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB4602C54B for ; Tue, 5 Feb 2019 22:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFC262C5AD; Tue, 5 Feb 2019 22:59: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=-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 BF5922C54B for ; Tue, 5 Feb 2019 22:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730384AbfBEW7e (ORCPT ); Tue, 5 Feb 2019 17:59:34 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:39972 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729312AbfBEW7d (ORCPT ); Tue, 5 Feb 2019 17:59:33 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x15MxR2D067939; Tue, 5 Feb 2019 22:59: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; s=corp-2018-07-02; bh=fuOnEijO9SbXMMrAMB24KyZW8299Kc8hJyYut3NCC6s=; b=pBwuN0g69kmlvM1qFOjkHHfuAjKziRKjYiu5kximdvF4Puy8i4XwtzJ07BHYrlbUpgmV puPp8B1vDYRmJWDNj0wjedEKq40PZHlZC38Gp05RchGg0E65EvNz1tBdOrvFWmZ7WCRX lgXXjj83m7+TyDSw2b7Arc89w9HwXvsqLhGU4Aos7DYiDhn1hDVzoQ3tp9WYB+LFpU+7 tyqX6cVYDbK4jM17YtDto2SWuJdiXSs6Ltc/y93MVIZc19UeAiI9FNPTJQBDVHnXCwx/ N5GmvrQdDM0gtGb5iV5CBQTfQzHUf/DDu54dPADOWKd2t9mhzg/qh2RxtWhmSqQCZRAl 5g== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qd9are16h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Feb 2019 22:59:27 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x15MxQLE002379 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Feb 2019 22:59:26 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x15MxPpg004162; Tue, 5 Feb 2019 22:59:25 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Feb 2019 22:59:25 +0000 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, jmattson@google.com Subject: [PATCH 4/4 v2][kvm-unit-test nVMX]: Test HOST_SYSENTER_ESP and HOST_SYSENTER_EIP fields on vmentry of L2 guests Date: Tue, 5 Feb 2019 17:34:27 -0500 Message-Id: <20190205223427.7387-5-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190205223427.7387-1-krish.sadhukhan@oracle.com> References: <20190205223427.7387-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=884 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902050168 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 is performed on vmentry of L2 guests: On processors that support Intel 64 architecture, the IA32_SYSENTER_ESP field and the IA32_SYSENTER_EIP field must each contain a canonical address. Signed-off-by: Krish Sadhukhan Reviewed-by: Mihai Carabas --- x86/unittests.cfg | 6 ++++ x86/vmx_tests.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index d7975e9..580dd8c 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -542,6 +542,12 @@ extra_params = -cpu host,+vmx -m 2560 -append vmx_controls_test arch = x86_64 groups = vmx +[vmx_host_state_area] +file = vmx.flat +extra_params = -cpu host,+vmx -m 2560 -append vmx_host_state_area_test +arch = x86_64 +groups = vmx + [vmx_vmentry_movss_shadow_test] file = vmx.flat extra_params = -cpu host,+vmx -m 2560 -append vmentry_movss_shadow_test diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index b69a7d9..487eb6f 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -4935,6 +4935,80 @@ static void vmx_controls_test(void) test_vm_entry_ctls(); } +/* + * On processors that support Intel 64 architecture, the IA32_SYSENTER_ESP + * field and the IA32_SYSENTER_EIP field must each contain a canonical + * address. + * + * [Intel SDM] + */ +static void test_host_ctl_regs(void) +{ + u64 addr_saved = vmcs_read(HOST_SYSENTER_ESP); + u64 addr = addr_saved; + + if (!is_canonical(addr)) { + report_prefix_pushf("HOST_SYSENTER_ESP non-canonical"); + test_vmlaunch(false, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + } else { + report_prefix_pushf("HOST_SYSENTER_ESP canonical"); + test_vmlaunch(true, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + + addr |= 1ull << 48; + vmcs_write(HOST_SYSENTER_ESP, addr); + report_prefix_pushf("HOST_SYSENTER_ESP non-canonical"); + test_vmlaunch(false, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + + vmcs_write(HOST_SYSENTER_ESP, addr_saved); + } + + addr_saved = vmcs_read(HOST_SYSENTER_EIP); + addr = addr_saved; + + if (!is_canonical(addr)) { + report_prefix_pushf("HOST_SYSENTER_EIP non-canonical"); + test_vmlaunch(false, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + } else { + report_prefix_pushf("HOST_SYSENTER_EIP canonical"); + test_vmlaunch(true, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + + addr |= 1ull << 48; + vmcs_write(HOST_SYSENTER_EIP, addr); + report_prefix_pushf("HOST_SYSENTER_EIP non-canonical"); + test_vmlaunch(false, false, + VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); + + vmcs_write(HOST_SYSENTER_EIP, addr_saved); + } +} + +/* + * Check that the virtual CPU checks the VMX Host State Area as + * documented in the Intel SDM. + */ +static void vmx_host_state_area_test(void) +{ + /* + * Bit 1 of the guest's RFLAGS must be 1, or VM-entry will + * fail due to invalid guest state, should we make it that + * far. + */ + vmcs_write(GUEST_RFLAGS, 0); + + test_host_ctl_regs(); +} + static bool valid_vmcs_for_vmentry(void) { struct vmcs *current_vmcs = NULL; @@ -6356,6 +6430,7 @@ struct vmx_test vmx_tests[] = { TEST(invvpid_test_v2), /* VM-entry tests */ TEST(vmx_controls_test), + TEST(vmx_host_state_area_test), TEST(vmentry_movss_shadow_test), /* APICv tests */ TEST(vmx_eoi_bitmap_ioapic_scan_test),