From patchwork Fri Apr 21 00:49:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691555 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 E9A536038D for ; Fri, 21 Apr 2017 00:51:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC3002843F for ; Fri, 21 Apr 2017 00:51:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFE2E2848D; Fri, 21 Apr 2017 00:51:20 +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 7735C2843F for ; Fri, 21 Apr 2017 00:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034313AbdDUAvT (ORCPT ); Thu, 20 Apr 2017 20:51:19 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:35197 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034024AbdDUAu3 (ORCPT ); Thu, 20 Apr 2017 20:50:29 -0400 Received: by mail-io0-f169.google.com with SMTP id r16so90787096ioi.2 for ; Thu, 20 Apr 2017 17:50:24 -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=xIypva9jJeHB2xwpce+61JNqxNutSD/HXKVvIDe6KYg=; b=MZMvRMpvooLlhJ1urrbuAxJwjZwrwJe7CPt/BgnQP/2R72uLMeVxPGhctTRITgL3rp +2cswsF9dFbsW79ihFlvEnTzzHp2sCu25LBv3j1YCXrbbH+cIXitrid7886CLEnd5hSk DF4aB0X2bZb3MnQlhOuc9Z+mxnSl9x7nmB+e3p0WQq5Ufxv9vvIiqnxqqxm1uUkLdeBA oztnUWvW2gwzJHvDz/VAM3aPTVdk7MAvGENyBm2oYb2PRvurVvg1hQQTuVZPKlA1sCC0 Dr14iDfFV5GYpVvQSur+Mcx1kk6B+zCLKQhbGEDL8FRwm8wNjXHQk3TkwwkLjg+rE3Tu uFvg== 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=xIypva9jJeHB2xwpce+61JNqxNutSD/HXKVvIDe6KYg=; b=kQDw2xuAh8w5kftYUdolNQA3QqgQmX0Vk3sfXQOAyu7mzQigNzt1y+XBWWhCnHZD+9 wUpr0ke8KySbD839DBcC5MCSl3j5MjzrVOM9qHDt2oJ5NNHXjInmsq4R7N/8vuCG3rHn nRqhrt7X6+zxQm5RLLxMMdB1TM+TusnNODF4mUUZpWYTYRtNb+QA0pHDI0bTmcUtejOV EKNkiMx4otufKRNxGOKAD+HNJcVoBV7ztbhIBC4u3x0nFEN1s9Ce3UJnNwTB+mqjV4m/ EpiG7YQqaxEXYwf2Ya8Wom2OrVSWcKWpzLpVKBNHX416QWwwsx7mG55HbJXV+MW8OQJ4 vhqQ== X-Gm-Message-State: AN3rC/7y66W8aiF2loMtygHYRT1qMEGyFGSAwgeZa7XyPdYmpA6S0fNh /KcDgDvriV1DL4NAB1s1sw== X-Received: by 10.99.0.79 with SMTP id 76mr9827127pga.119.1492735817746; Thu, 20 Apr 2017 17:50:17 -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.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:16 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: David Matlack Subject: [kvm-unit-tests PATCH 10/32] x86: vmcs lifecycle test Date: Thu, 20 Apr 2017 17:49:42 -0700 Message-Id: <20170421005004.137260-11-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 This test VMCLEARs and VMPTRLDs two VMCS's to put each VMCS into different states of active/not-active and current/not-current and then verifies that VMREAD/VMWRITE to the current VMCS work correctly. Signed-off-by: David Matlack --- x86/unittests.cfg | 6 ++++++ x86/vmx.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 7973f2f62d26..0f2c94fb548d 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -236,6 +236,12 @@ extra_params = -cpu host,+vmx -append test_vmwrite_vmread arch = x86_64 groups = vmx +[vmx_test_vmcs_lifecycle] +file = vmx.flat +extra_params = -cpu host,+vmx -append test_vmcs_lifecycle +arch = x86_64 +groups = vmx + [vmx_test_vmx_caps] file = vmx.flat extra_params = -cpu host,+vmx -append test_vmx_caps diff --git a/x86/vmx.c b/x86/vmx.c index 47404fbbd782..7daa1d110c82 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -300,6 +300,64 @@ void test_vmwrite_vmread(void) free_page(vmcs); } +void test_vmcs_lifecycle(void) +{ + struct vmcs *vmcs[2] = {}; + int i; + + for (i = 0; i < ARRAY_SIZE(vmcs); i++) { + vmcs[i] = alloc_page(); + memset(vmcs[i], 0, PAGE_SIZE); + vmcs[i]->revision_id = basic.revision; + } + +#define VMPTRLD(_i) do { \ + assert(_i < ARRAY_SIZE(vmcs)); \ + assert(!make_vmcs_current(vmcs[_i])); \ + printf("VMPTRLD VMCS%d\n", (_i)); \ +} while (0) + +#define VMCLEAR(_i) do { \ + assert(_i < ARRAY_SIZE(vmcs)); \ + assert(!vmcs_clear(vmcs[_i])); \ + printf("VMCLEAR VMCS%d\n", (_i)); \ +} while (0) + + VMCLEAR(0); + VMPTRLD(0); + set_all_vmcs_fields(0); + report("current:VMCS0 active:[VMCS0]", check_all_vmcs_fields(0)); + + VMCLEAR(0); + VMPTRLD(0); + report("current:VMCS0 active:[VMCS0]", check_all_vmcs_fields(0)); + + VMCLEAR(1); + report("current:VMCS0 active:[VMCS0]", check_all_vmcs_fields(0)); + + VMPTRLD(1); + set_all_vmcs_fields(1); + report("current:VMCS1 active:[VMCS0,VCMS1]", check_all_vmcs_fields(1)); + + VMPTRLD(0); + report("current:VMCS0 active:[VMCS0,VCMS1]", check_all_vmcs_fields(0)); + VMPTRLD(1); + report("current:VMCS1 active:[VMCS0,VCMS1]", check_all_vmcs_fields(1)); + VMPTRLD(1); + report("current:VMCS1 active:[VMCS0,VCMS1]", check_all_vmcs_fields(1)); + + VMCLEAR(0); + report("current:VMCS1 active:[VCMS1]", check_all_vmcs_fields(1)); + + for (i = 0; i < ARRAY_SIZE(vmcs); i++) { + VMCLEAR(i); + free_page(vmcs[i]); + } + +#undef VMPTRLD +#undef VMCLEAR +} + void vmx_set_test_stage(u32 s) { barrier(); @@ -1472,6 +1530,8 @@ int main(int argc, const char *argv[]) test_vmptrst(); if (test_wanted("test_vmwrite_vmread", argv, argc)) test_vmwrite_vmread(); + if (test_wanted("test_vmcs_lifecycle", argv, argc)) + test_vmcs_lifecycle(); init_vmcs(&vmcs_root); if (vmx_run()) {