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.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,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 D019AC10F0E for ; Thu, 18 Apr 2019 22:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A054020693 for ; Thu, 18 Apr 2019 22:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PvfbjzOD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726069AbfDRWFe (ORCPT ); Thu, 18 Apr 2019 18:05:34 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:39758 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbfDRWFe (ORCPT ); Thu, 18 Apr 2019 18:05:34 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3ILswHJ076931; Thu, 18 Apr 2019 22:05:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=2mpKrZPYOzAAVJqMO+ZPNHhFM+bwKiZrqkvBjuL5Hkw=; b=PvfbjzODMeyy1ScknJbT9d0Av7FanL6P6SiLoYxDW3GKFVx+Vbu0YUfe/PyR06pWGzZ5 BdgXxEXrg7pNTJ2jGzvQln7AosUfwrJEIYQF1Cn+8BPc0KgJW3QO/dKoI8a959tUgLUA IYrEvwKW8Td03QSCNQD8B4OsuR1wULgeh+DuqEYwQMYru3EHaZhEWLaOck0Nfp14elxr QTnJc4OeNAOlPL0MQVaJZf50Y0i57OhUwHAISavZCT2Hq/C0m8lCvDCVczSZTxqdTUBI n6Vehg9T6w8iCBYJLa5fDUW8Co9QiMIsMH8mkssQ3eJyXEvAtUXoblJvEnlktob/KmSN 4w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 2ru59dkaqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 22:05:27 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3IM4E9A095054; Thu, 18 Apr 2019 22:05:26 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2rv2tw7a71-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 22:05:26 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x3IM5Q0S024823; Thu, 18 Apr 2019 22:05:26 GMT Received: from ban25x6uut29.us.oracle.com (/10.153.73.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 18 Apr 2019 15:05:26 -0700 From: Krish Sadhukhan To: kvm@vger.kernel.org Cc: rkrcmar@redhat.com, pbonzini@redhat.com, jmattson@google.com Subject: [PATCH 1/2][kvm-unit-test nVMX]: Move the functionality of enter_guest() to __enter_guest() and make the former a wrapper of the latter Date: Thu, 18 Apr 2019 17:39:40 -0400 Message-Id: <20190418213941.20977-2-krish.sadhukhan@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190418213941.20977-1-krish.sadhukhan@oracle.com> References: <20190418213941.20977-1-krish.sadhukhan@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9231 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904180128 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9231 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904180128 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently enter_guest() aborts on any type of vmentry failures (early failures or invalid guest state). But the vmentry tests that want to validate the guest state need to continue running in spite of vmentry failures arising out of an invalid guest state. This patch moves the functionality of enter_guest() to __enter_guest() which accepts a parameter to conditionally abort the test as opposed to the behavior of enter_guest(). enter_guest() now calls __enter_guest() and preserves compatibility of existing callers which expect the test to be aborted on any type of vmentry failures. Signed-off-by: Krish Sadhukhan Suggested-by: Jim Mattson Reviewed-by: Karl Heubaum --- x86/vmx.c | 27 ++++++++++++++++++--------- x86/vmx.h | 4 ++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 6ba56bc..d29d21a 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1583,10 +1583,10 @@ entry_failure_handler(struct vmentry_failure *failure) } /* - * Tries to enter the guest. Returns true iff entry succeeded. Otherwise, + * Tries to enter the guest. Returns true if entry succeeded. Otherwise, * populates @failure. */ -static bool vmx_enter_guest(struct vmentry_failure *failure) +static void vmx_enter_guest(struct vmentry_failure *failure) { failure->early = 0; @@ -1620,8 +1620,6 @@ static bool vmx_enter_guest(struct vmentry_failure *failure) failure->vmlaunch = !launched; failure->instr = launched ? "vmresume" : "vmlaunch"; - - return !failure->early && !(vmcs_read(EXI_REASON) & VMX_ENTRY_FAILURE); } static int vmx_run(void) @@ -1631,7 +1629,9 @@ static int vmx_run(void) bool entered; struct vmentry_failure failure; - entered = vmx_enter_guest(&failure); + vmx_enter_guest(&failure); + entered = !failure.early && + !(vmcs_read(EXI_REASON) & VMX_ENTRY_FAILURE); if (entered) { /* @@ -1765,10 +1765,9 @@ void test_set_guest(test_guest_func func) /* * Enters the guest (or launches it for the first time). Error to call once the - * guest has returned (i.e., run past the end of its guest() function). Also - * aborts if guest entry fails. + * guest has returned (i.e., run past the end of its guest() function). */ -void enter_guest(void) +void __enter_guest(u8 abort_flag) { struct vmentry_failure failure; @@ -1778,7 +1777,11 @@ void enter_guest(void) TEST_ASSERT_MSG(!guest_finished, "Called enter_guest() after guest returned."); - if (!vmx_enter_guest(&failure)) { + vmx_enter_guest(&failure); + if ((abort_flag & ABORT_ON_EARLY_VMENTRY_FAIL && failure.early) || + (abort_flag & ABORT_ON_INVALID_GUEST_STATE && + vmcs_read(EXI_REASON) & VMX_ENTRY_FAILURE)) { + print_vmentry_failure_info(&failure); abort(); } @@ -1807,6 +1810,12 @@ void enter_guest(void) } } +void enter_guest(void) +{ + __enter_guest(ABORT_ON_EARLY_VMENTRY_FAIL | + ABORT_ON_INVALID_GUEST_STATE); +} + extern struct vmx_test vmx_tests[]; static bool diff --git a/x86/vmx.h b/x86/vmx.h index 8a00f73..eefd5dc 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -645,6 +645,9 @@ enum vm_instruction_error_number { #define VMCS_FIELD_RESERVED_SHIFT (15) #define VMCS_FIELD_BIT_SIZE (BITS_PER_LONG) +#define ABORT_ON_EARLY_VMENTRY_FAIL 0x1 +#define ABORT_ON_INVALID_GUEST_STATE 0x2 + extern struct regs regs; extern union vmx_basic basic; @@ -830,6 +833,7 @@ bool ept_execute_only_supported(void); bool ept_ad_bits_supported(void); void enter_guest(void); +void __enter_guest(u8); typedef void (*test_guest_func)(void); typedef void (*test_teardown_func)(void *data); -- 2.17.2