From patchwork Fri Apr 21 00:49:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691553 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 DEB156038D for ; Fri, 21 Apr 2017 00:51:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF3CD2843F for ; Fri, 21 Apr 2017 00:51:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C390C2848D; Fri, 21 Apr 2017 00:51:19 +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 4CF9C28480 for ; Fri, 21 Apr 2017 00:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034234AbdDUAvR (ORCPT ); Thu, 20 Apr 2017 20:51:17 -0400 Received: from mail-io0-f171.google.com ([209.85.223.171]:36296 "EHLO mail-io0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034028AbdDUAua (ORCPT ); Thu, 20 Apr 2017 20:50:30 -0400 Received: by mail-io0-f171.google.com with SMTP id o22so104069615iod.3 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=ke1zo7JgzxBsY9NfUfmP4ipToFSG1SPLxvGVx+1b+O8=; b=Jwy0mXSRf2HgyYIzPg4gvWDpCjBKev15rv/nmXF6HdNP9hSbCDW5FfgoM1FFucwu+I ymWfMGckjY8T9oBwE0Ow567osEztQa7g8L03kRT4MULMdJ9O61+CG0pxAaNDGnTCvaqr SlOKsYjnLlF6UkLi/56v1lkv8CzSL+hBM/4qzSAgsJxDjMdSA1pK9xTNLRI+eYyPTyDI xAJ2mjzyOynFTi0q9H157XvToEJj+4akCKNJx4SidkDmorYaenEsJQfD9JJzgdPEl0Nk 57zlKVRaUHdAKMTpmXP7SzzDqmd7A/majROgXneRnpnHnXQi3LpEqC+Ra0awQcfdOtQW AyMg== 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=ke1zo7JgzxBsY9NfUfmP4ipToFSG1SPLxvGVx+1b+O8=; b=Inj6c9ZLIQX5RyGNS6V3NGFWcLg9p7kqVlkW5+VQlNiL8zFdM489fcGoFBcRkwWNZT 81yNspl7/xstlTkxNN9l0sTOvi8FXDzFmTUlIdeG9SllgyzL8WjvGF3gju51gt7qy9xI OAje+xIGWvmbbQMYHhTmndfJl6364QiVyTqnDVadWAQkVUN7PtA0iEuuXLPqBoWzQmiM gLDI55RIAhsMh95MiYCBz0vWxtVB+iIn47ohu0kVLh8OtT3qKsUmFBKKsj6ilRPgexmS DGDzkbQOhVcRHsHDhezA4AfImqt9ytAXOcJNOeNdb/F5VyfvXVVa7x4tbJJut+v7gtbR PXkQ== X-Gm-Message-State: AN3rC/5tO1vQXZmPd+XvqxEVpAdGFIOPT/HjDznZNvt8ZF5DMTXDe+uS +/Fzf64Diu8QEK/OIZIN1g== X-Received: by 10.98.50.196 with SMTP id y187mr9944450pfy.148.1492735818767; Thu, 20 Apr 2017 17:50:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:17 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: David Matlack Subject: [kvm-unit-tests PATCH 11/32] x86: test VMCS in memory after VMCLEAR Date: Thu, 20 Apr 2017 17:49:43 -0700 Message-Id: <20170421005004.137260-12-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 The Intel SDM states that following a VMCLEAR instruction, the VMCS given as an operand to VMCLEAR should be resident in memory. If the CPU caches VMCS data outside of memory, VMCLEAR must flush this cache to memory. Signed-off-by: David Matlack --- x86/vmx.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/x86/vmx.c b/x86/vmx.c index 7daa1d110c82..fd1aa3bc6c2e 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -487,6 +487,42 @@ print_vmentry_failure_info(struct vmentry_failure *failure) { } } +/* + * VMCLEAR should ensures all VMCS state is flushed to the VMCS + * region in memory. + */ +static void test_vmclear_flushing(void) +{ + struct vmcs *vmcs[3] = {}; + int i; + + for (i = 0; i < ARRAY_SIZE(vmcs); i++) { + vmcs[i] = alloc_page(); + memset(vmcs[i], 0, PAGE_SIZE); + } + + vmcs[0]->revision_id = basic.revision; + assert(!vmcs_clear(vmcs[0])); + assert(!make_vmcs_current(vmcs[0])); + set_all_vmcs_fields(0x86); + + assert(!vmcs_clear(vmcs[0])); + memcpy(vmcs[1], vmcs[0], basic.size); + assert(!make_vmcs_current(vmcs[1])); + report("test vmclear flush (current VMCS)", check_all_vmcs_fields(0x86)); + + set_all_vmcs_fields(0x87); + assert(!make_vmcs_current(vmcs[0])); + assert(!vmcs_clear(vmcs[1])); + memcpy(vmcs[2], vmcs[1], basic.size); + assert(!make_vmcs_current(vmcs[2])); + report("test vmclear flush (!current VMCS)", check_all_vmcs_fields(0x87)); + + for (i = 0; i < ARRAY_SIZE(vmcs); i++) { + assert(!vmcs_clear(vmcs[i])); + free_page(vmcs[i]); + } +} static void test_vmclear(void) { @@ -519,6 +555,7 @@ static void test_vmclear(void) /* Valid VMCS */ report("test vmclear with valid vmcs region", vmcs_clear(vmcs_root) == 0); + test_vmclear_flushing(); } static void test_vmxoff(void)