From patchwork Fri Apr 21 00:49:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691511 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 7F8B46038D for ; Fri, 21 Apr 2017 00:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71B982847B for ; Fri, 21 Apr 2017 00:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 666EB28489; Fri, 21 Apr 2017 00:50:25 +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 EFFF72847B for ; Fri, 21 Apr 2017 00:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033691AbdDUAuT (ORCPT ); Thu, 20 Apr 2017 20:50:19 -0400 Received: from mail-io0-f174.google.com ([209.85.223.174]:33141 "EHLO mail-io0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030868AbdDUAuN (ORCPT ); Thu, 20 Apr 2017 20:50:13 -0400 Received: by mail-io0-f174.google.com with SMTP id k87so95043333ioi.0 for ; Thu, 20 Apr 2017 17:50:13 -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=+lJCtV+4KIDXp0dQvdr/se3gu5pTYzVaC99tnxIKKzU=; b=LvHQxN40ngEz6qXHaPuOFJUUDks9WBHtbBruKaYqHth5Hzn0UQVv89gE1DkjUFD5Rd C9uIjnRsfzIPZ4AeKuKYaJPf4hVzsLxaI4YVXaHEJLUZbOmfyU0nmbwzCFnYYKDVsYHv SnB5oIa9DbCfdJ9chey4QnZrWvl5vW28fhA3il/ql4btjRgrRpN6d8esqV4kuf9u0z0/ mKutC1lHw9gOMW2l/ie+PkxeJxoHuxu7GeMEq0BAUpgdK2PgPaDghaduV7fPtExeYzcZ ytcU8udE06zDhqersVPlm550SchCKwc2dUmeWT1lxlJNZYgyhEHHRMdt8GksWs9CXTwq jOWQ== 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=+lJCtV+4KIDXp0dQvdr/se3gu5pTYzVaC99tnxIKKzU=; b=sh+3tK5eByv6Hjp4yk49wWNewScE+O7OfXnE0PIsmW8j2XDb1x8ls6IL8rVh5es2nP nfxeNAR3Ojw826Yc25BwTld3XHlyYJeDVrAT/JMentZ59/lRTigbgrcOY+GbqmzM5v8m //PWI4zui32b2YZvmjPDCOueffkOWf74nizVvXA5cwM9fXiI8SWFTjmo/EB8GG6J+OYu vIjFHFvVE+/jRKdIrrO+w8PGvHqxtcyQKwKK4e4wo9RyTQnsX8oXqAk8mCWpNZDOvxxl XrNbx3q+4QQCs50eWdQ+AuG0+PQGRwWcQ1F10V/3cBQ2Oxr0mvRqnDSkA3jMbye8mvCO x0tQ== X-Gm-Message-State: AN3rC/7aJFqWwgiF+fpFvOPTAHOJ+rg8LPfqdYlCHuM2pWnevTzgT98k q/HMyn+bfe3QkPR2 X-Received: by 10.99.104.6 with SMTP id d6mr546015pgc.185.1492735811070; Thu, 20 Apr 2017 17:50:11 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:10 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: David Matlack Subject: [kvm-unit-tests PATCH 03/32] x86: move basic vmx tests into separate test cases Date: Thu, 20 Apr 2017 17:49:35 -0700 Message-Id: <20170421005004.137260-4-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 By default every vmx kvm-unit-test runs a series of tests at startup. This patch moves those startup tests into test cases which are only run when requested. Signed-off-by: David Matlack --- x86/unittests.cfg | 36 +++++++++++++++++++++++++++++++ x86/vmx.c | 64 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index a267638733aa..c942adad6325 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -200,6 +200,42 @@ extra_params = -cpu host,+vmx arch = x86_64 groups = vmx +[vmx_test_vmx_feature_control] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmx_feature_control +arch = x86_64 +groups = vmx + +[vmx_test_vmxon] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmxon +arch = x86_64 +groups = vmx + +[vmx_test_vmptrld] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmptrld +arch = x86_64 +groups = vmx + +[vmx_test_vmclear] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmclear +arch = x86_64 +groups = vmx + +[vmx_test_vmptrst] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmptrst +arch = x86_64 +groups = vmx + +[vmx_test_vmx_caps] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmx_caps +arch = x86_64 +groups = vmx + [vmx_vmenter] file = vmx.flat extra_params = -cpu host,+vmx -append vmenter diff --git a/x86/vmx.c b/x86/vmx.c index 202cfaaa822e..0590b69ec1d2 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -45,6 +45,7 @@ struct regs regs; struct vmx_test *current; u64 hypercall_field; bool launched; +static int matched; union vmx_basic basic; union vmx_ctrl_msr ctrl_pin_rev; @@ -1171,55 +1172,86 @@ static bool test_name_wanted(const char *name, const char *wanted) return *n == '\0' && *w == '\0'; } -static bool test_wanted(struct vmx_test *test, char *wanted[], int nwanted) +static bool test_wanted(const char *name, char *wanted[], int nwanted) { + bool is_wanted = true; int i; if (!nwanted) - return true; + goto out; for (i = 0; i < nwanted; ++i) { - if (test_name_wanted(test->name, wanted[i])) - return true; + if (test_name_wanted(name, wanted[i])) + goto out; } - return false; + + is_wanted = false; + +out: + if (is_wanted) + matched++; + return is_wanted; } int main(int argc, char *argv[]) { int i = 0; - int matched = 0; setup_vm(); setup_idt(); hypercall_field = 0; + argv++; + argc--; + if (!(cpuid(1).c & (1 << 5))) { printf("WARNING: vmx not supported, add '-cpu host'\n"); goto exit; } init_vmx(); - if (test_vmx_feature_control() != 0) - goto exit; + if (test_wanted("test_vmx_feature_control", argv, argc)) { + /* Sets MSR_IA32_FEATURE_CONTROL to 0x5 */ + if (test_vmx_feature_control() != 0) + goto exit; + } else { + if ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) != 0x5) + wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5); + } + /* Set basic test ctxt the same as "null" */ current = &vmx_tests[0]; - if (test_vmxon() != 0) - goto exit; - test_vmptrld(); - test_vmclear(); - test_vmptrst(); + + if (test_wanted("test_vmxon", argv, argc)) { + /* Enables VMX */ + if (test_vmxon() != 0) + goto exit; + } else { + if (vmx_on()) { + report("vmxon", 0); + goto exit; + } + } + + if (test_wanted("test_vmptrld", argv, argc)) + test_vmptrld(); + if (test_wanted("test_vmclear", argv, argc)) + test_vmclear(); + if (test_wanted("test_vmptrst", argv, argc)) + test_vmptrst(); init_vmcs(&vmcs_root); if (vmx_run()) { report("test vmlaunch", 0); goto exit; } + test_vmxoff(); - test_vmx_caps(); + + if (test_wanted("test_vmx_caps", argv, argc)) + test_vmx_caps(); while (vmx_tests[++i].name != NULL) { - if (!test_wanted(&vmx_tests[i], argv + 1, argc - 1)) + if (!test_wanted(vmx_tests[i].name, argv, argc)) continue; - matched++; if (test_run(&vmx_tests[i])) goto exit; }