From patchwork Fri Apr 21 00:50:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691551 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 05B916038D for ; Fri, 21 Apr 2017 00:51:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBD6B2847B for ; Fri, 21 Apr 2017 00:51:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0C1928480; Fri, 21 Apr 2017 00:51:14 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 754812847B for ; Fri, 21 Apr 2017 00:51:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034038AbdDUAvH (ORCPT ); Thu, 20 Apr 2017 20:51:07 -0400 Received: from mail-oi0-f43.google.com ([209.85.218.43]:34099 "EHLO mail-oi0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033580AbdDUAuh (ORCPT ); Thu, 20 Apr 2017 20:50:37 -0400 Received: by mail-oi0-f43.google.com with SMTP id x184so74079382oia.1 for ; Thu, 20 Apr 2017 17:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vz1pqgyVsvM6qfS+5dzJn1sz++b8VcjCvmjZ6oAok/U=; b=GR9uhsMNqF402SQDp9xbEsEbNYNu1lO5xWsDo56ZY/9gP30B0+95Yp4nOwXxHuuR+B w7kQI4jN1FaHW2mNxiDhmYVISlxV2MbcAccAtCLnH0MSOrU9Io0HT7lvF7Bd0zQvtu0D LdYq3jVNOkD8+dsTGNxIO2PO+mPSjzuHBI6vduAzvc4DgKMyB9++hKbToWkBb2jYgrMg VUrqM5t10piAzCuzIspecP5QHNyallu3tVRuwCWQgDeFwSA70h6mqcsonHUvVXanGjRi W8is6Hx6vpuiLcNSqm+1i95Iw9/9tUQbFFSQgoGesZ1vZenJBmA7orRWb78UvWzIE1kR ZX1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Vz1pqgyVsvM6qfS+5dzJn1sz++b8VcjCvmjZ6oAok/U=; b=C88+QSLdZwUwuoLCymKdyhyk5wzVaAjMsAm49fwi7OSgRtnimyIFrdBiau6gZYuKQG aTKXf44VAPPt2LeqZHiWbfAdIcCibTGvyhIcFS1xPYeEMfMkMdiCrHFiqNxnM7UGwa4G u7QQ6elfxehtKb9y8RW+fSbZMOo9sk27iUCw0B8PaAQwvEuQg5CFy7C8yKxu6n5YiDCl 19XFxEsHy/iM+a5vMyqq8HMiudjrybV9dRHUfC+nrzM2aeaYihdDxdvuS0/U7Tr+M8qY Md/KdNxeX9c0Eteyc7O8SWQgeydUOpcUgANS3JvhiikhuWrcmAYxFlvokB8uKIM4gVw8 licA== X-Gm-Message-State: AN3rC/7ifHXfrXmr7CWRY3yf73r77CbVLNEU11lzxzX+WT3gjxnwiHnf 842rGq1oNzAK+tJp X-Received: by 10.84.238.9 with SMTP id u9mr12906898plk.174.1492735836551; Thu, 20 Apr 2017 17:50:36 -0700 (PDT) Received: from dmatlack.sea.corp.google.com ([100.100.206.82]) by smtp.gmail.com with ESMTPSA id e13sm12466486pfb.30.2017.04.20.17.50.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:35 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: Peter Feiner , David Matlack Subject: [kvm-unit-tests PATCH 28/32] x86: ept capability utilities Date: Thu, 20 Apr 2017 17:50:00 -0700 Message-Id: <20170421005004.137260-29-dmatlack@google.com> X-Mailer: git-send-email 2.12.2.816.g2cccc81164-goog In-Reply-To: <20170421005004.137260-1-dmatlack@google.com> References: <20170421005004.137260-1-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Feiner Signed-off-by: Peter Feiner Signed-off-by: David Matlack --- x86/vmx.c | 30 ++++++++++++++++++++++++++++++ x86/vmx.h | 6 ++++++ x86/vmx_tests.c | 6 ++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index c003d5d11e63..f7a34d20ab6a 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -973,6 +973,36 @@ void set_ept_pte(unsigned long *pml4, unsigned long guest_addr, pt[offset] = pte_val; } +bool ept_2m_supported(void) +{ + return ept_vpid.val & EPT_CAP_2M_PAGE; +} + +bool ept_1g_supported(void) +{ + return ept_vpid.val & EPT_CAP_1G_PAGE; +} + +bool ept_huge_pages_supported(int level) +{ + if (level == 2) + return ept_2m_supported(); + else if (level == 3) + return ept_1g_supported(); + else + return false; +} + +bool ept_execute_only_supported(void) +{ + return ept_vpid.val & EPT_CAP_WT; +} + +bool ept_ad_bits_supported(void) +{ + return ept_vpid.val & EPT_CAP_AD_FLAG; +} + void vpid_sync(int type, u16 vpid) { switch(type) { diff --git a/x86/vmx.h b/x86/vmx.h index 4b899aa69145..890cdcc9e67f 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -699,6 +699,12 @@ void check_ept_ad(unsigned long *pml4, u64 guest_cr3, void clear_ept_ad(unsigned long *pml4, u64 guest_cr3, unsigned long guest_addr); +bool ept_2m_supported(void); +bool ept_1g_supported(void); +bool ept_huge_pages_supported(int level); +bool ept_execute_only_supported(void); +bool ept_ad_bits_supported(void); + void enter_guest(void); typedef void (*test_guest_func)(void); diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index be01709d3057..bf45bd2566ca 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -943,7 +943,6 @@ static int insn_intercept_exit_handler() /* Enables EPT and sets up the identity map. */ static int setup_ept(bool enable_ad) { - int support_2m; unsigned long end_of_memory; u32 ctrl_cpu[2]; @@ -983,15 +982,14 @@ static int setup_ept(bool enable_ad) if (enable_ad) eptp |= EPTP_AD_FLAG; vmcs_write(EPTP, eptp); - support_2m = !!(ept_vpid.val & EPT_CAP_2M_PAGE); end_of_memory = fwcfg_get_u64(FW_CFG_RAM_SIZE); if (end_of_memory < (1ul << 32)) end_of_memory = (1ul << 32); /* Cannot use large EPT pages if we need to track EPT * accessed/dirty bits at 4K granularity. */ - setup_ept_range(pml4, 0, end_of_memory, - 0, !enable_ad && support_2m, + setup_ept_range(pml4, 0, end_of_memory, 0, + !enable_ad && ept_2m_supported(), EPT_WA | EPT_RA | EPT_EA); return 0; }