From patchwork Mon Jun 9 21:04:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bandan Das X-Patchwork-Id: 4323841 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 51A5D9F387 for ; Mon, 9 Jun 2014 21:05:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BB45201BC for ; Mon, 9 Jun 2014 21:05:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CBF72016C for ; Mon, 9 Jun 2014 21:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932207AbaFIVFW (ORCPT ); Mon, 9 Jun 2014 17:05:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60240 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932200AbaFIVFU (ORCPT ); Mon, 9 Jun 2014 17:05:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s59L5Ia7019337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Jun 2014 17:05:18 -0400 Received: from aqua.redhat.com (vpn-49-150.rdu2.redhat.com [10.10.49.150]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s59L51MX016605; Mon, 9 Jun 2014 17:05:17 -0400 From: Bandan Das To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jan Kiszka Subject: [PATCH kvm-unit-tests v2 3/3] VMX: Updated test_vmclear and test_vmptrld Date: Mon, 9 Jun 2014 17:04:54 -0400 Message-Id: <1402347894-13659-4-git-send-email-bsd@redhat.com> In-Reply-To: <1402347894-13659-1-git-send-email-bsd@redhat.com> References: <1402347894-13659-1-git-send-email-bsd@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check if the vmcs pointer is not aligned to page size, and if bits beyond physical address width are set. Also, vmclear and vmptrld should fail if the vmxon region is supplied instead of the vmcs Signed-off-by: Bandan Das --- x86/vmx.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 13e2be8..b29fc05 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -134,7 +134,35 @@ void print_vmexit_info() static void test_vmclear(void) { - report("test vmclear", vmcs_clear(vmcs_root) == 0); + struct vmcs *tmp_root; + int width = cpuid(0x80000008).a & 0xff; + + /* + * Note- The tests below do not necessarily have a + * valid VMCS, but that's ok since the invalid vmcs + * is only used for a specific test and is discarded + * without touching its contents + */ + + /* Unaligned page access */ + tmp_root = (struct vmcs *)((intptr_t)vmcs_root + 1); + report("test vmclear with unaligned vmcs", + vmcs_clear(tmp_root) == 1); + + /* gpa bits beyond physical address width are set*/ + tmp_root = (struct vmcs *)((intptr_t)vmcs_root | + ((u64)1 << (width+1))); + report("test vmclear with vmcs address bits set beyond physical address width", + vmcs_clear(tmp_root) == 1); + + /* Pass VMXON region */ + tmp_root = (struct vmcs *)vmxon_region; + report("test vmclear with vmxon region", + vmcs_clear(tmp_root) == 1); + + /* Valid VMCS */ + report("test vmclear with valid vmcs region", vmcs_clear(vmcs_root) == 0); + } static void test_vmxoff(void) @@ -639,11 +667,29 @@ out: static void test_vmptrld(void) { - struct vmcs *vmcs; + struct vmcs *vmcs, *tmp_root; + int width = cpuid(0x80000008).a & 0xff; vmcs = alloc_page(); vmcs->revision_id = basic.revision; - report("test vmptrld", make_vmcs_current(vmcs) == 0); + + /* Unaligned page access */ + tmp_root = (struct vmcs *)((intptr_t)vmcs + 1); + report("test vmptrld with unaligned vmcs", + vmcs_clear(tmp_root) == 1); + + /* gpa bits beyond physical address width are set*/ + tmp_root = (struct vmcs *)((intptr_t)vmcs | + ((u64)1 << (width+1))); + report("test vmptrld with vmcs address bits set beyond physical address width", + vmcs_clear(tmp_root) == 1); + + /* Pass VMXON region */ + tmp_root = (struct vmcs *)vmxon_region; + report("test vmptrld with vmxon region", + vmcs_clear(tmp_root) == 1); + + report("test vmptrld with valid vmcs region", make_vmcs_current(vmcs) == 0); } static void test_vmptrst(void)