From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C904C4CECE for ; Thu, 12 Mar 2020 23:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51D4820637 for ; Thu, 12 Mar 2020 23:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbgCLX1z (ORCPT ); Thu, 12 Mar 2020 19:27:55 -0400 Received: from mga14.intel.com ([192.55.52.115]:14954 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726845AbgCLX1r (ORCPT ); Thu, 12 Mar 2020 19:27:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Mar 2020 16:27:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,546,1574150400"; d="scan'208";a="261705933" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by orsmga002.jf.intel.com with ESMTP; 12 Mar 2020 16:27:46 -0700 From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org Subject: [kvm-unit-tests PATCH 3/8] nVMX: Consolidate non-canonical code in test_canonical() Date: Thu, 12 Mar 2020 16:27:40 -0700 Message-Id: <20200312232745.884-4-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200312232745.884-1-sean.j.christopherson@intel.com> References: <20200312232745.884-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Refactor test_canonical() to provide a single flow for the non-canonical path. Practically speaking, its extremely unlikely the field being tested already has a non-canonical address, and even less likely that it's anything other than NONCANONICAL. I.e. the added complexity doesn't come with added coverage. Signed-off-by: Sean Christopherson --- x86/vmx_tests.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index c4077b1..ac02b9d 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -7411,6 +7411,11 @@ static void test_canonical(u64 field, const char * field_name, bool host) { u64 addr_saved = vmcs_read(field); + /* + * Use the existing value if possible. Writing a random canonical + * value is not an option as doing so would corrupt the field being + * tested and likely hose the test. + */ if (is_canonical(addr_saved)) { if (host) { report_prefix_pushf("%s %lx", field_name, addr_saved); @@ -7422,33 +7427,22 @@ static void test_canonical(u64 field, const char * field_name, bool host) VMX_VMCALL, addr_saved, field_name); } + } - vmcs_write(field, NONCANONICAL); + vmcs_write(field, NONCANONICAL); - if (host) { - report_prefix_pushf("%s %llx", field_name, NONCANONICAL); - test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); - report_prefix_pop(); - } else { - enter_guest_with_invalid_guest_state(); - report_guest_state_test("Test canonical address", - VMX_FAIL_STATE | VMX_ENTRY_FAILURE, - NONCANONICAL, field_name); - } - - vmcs_write(field, addr_saved); + if (host) { + report_prefix_pushf("%s %llx", field_name, NONCANONICAL); + test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); + report_prefix_pop(); } else { - if (host) { - report_prefix_pushf("%s %llx", field_name, NONCANONICAL); - test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD); - report_prefix_pop(); - } else { - enter_guest_with_invalid_guest_state(); - report_guest_state_test("Test canonical address", - VMX_FAIL_STATE | VMX_ENTRY_FAILURE, - NONCANONICAL, field_name); - } + enter_guest_with_invalid_guest_state(); + report_guest_state_test("Test non-canonical address", + VMX_FAIL_STATE | VMX_ENTRY_FAILURE, + NONCANONICAL, field_name); } + + vmcs_write(field, addr_saved); } #define TEST_RPL_TI_FLAGS(reg, name) \ -- 2.24.1