From patchwork Wed Jan 19 16:45:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lewis X-Patchwork-Id: 12717674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9D9AC433F5 for ; Wed, 19 Jan 2022 16:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356218AbiASQpx (ORCPT ); Wed, 19 Jan 2022 11:45:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356215AbiASQpw (ORCPT ); Wed, 19 Jan 2022 11:45:52 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 541EEC061574 for ; Wed, 19 Jan 2022 08:45:52 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id o20-20020a656a54000000b003441a994d60so1941445pgu.6 for ; Wed, 19 Jan 2022 08:45:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/BijbWVuPGfDe5bzECq0SaWh1RFGQecgoREE5TmFYxI=; b=BnNnpQcwAectZUSK5KbIlwZdbZiBM6Kz9NdhD1cuhMgFphUsG+jbPBwrir8gKeboGu kwVYAlHV992igWe3u2X3h7Oii25LYSDljXLEXWJRTyaQHrtc3uK3ZVIKwf0rZklCyVrr gYWOn0/4BrZRulgDOaU3cZIxoig9z7pMvGqFtsE6kIcJVsV3Hd/ewb/TvmeyYsVCjFkx ICncSq554DVQdVYZzgIoB1Z3AsRjJYVGS4bPoUSubsnl5SKVAcmk2w6NWTLawGwALtxU MYEoplKJIOKH0OAAHADoFpbGqmzmv7cf2VSkqanyRAZ/Uja6+RhE4GZwmRnzRBgODOAK iXcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/BijbWVuPGfDe5bzECq0SaWh1RFGQecgoREE5TmFYxI=; b=27gh0PyNd+CgMF9+hdJYlASO7t1H4WaV6GYD4UTYSpj7b84AE0RQsfRa74TixftzOW qtL0IbdoEUF+dwkhNnUkEkgftUK/kteFTUhvSDG8DhEQnFPFVKUR9HzpIT03NL8bJpbO +Z9aOihF0XsfXLDEP7ZunIwtwLHgyWp5/u0hLHjvQuNN/57FZrfwNU+f2jkyV6aV7l+Y C1KxiSUX8fj4zzQCPXSstvu9c1WDRYTSS1aDcI1W0Jk4yRx1OyQusI9LymjU+VodJAvk vIUEKR1yk8oJAs7fzwPTKPIBbfR21s0bMFh78ksT+VLiwJ3xWbtxVKCEHccGv2Ah+LQp S+1g== X-Gm-Message-State: AOAM532QPsO6+QKimcYUYYa44qAPFlxvNhCneHDGXh+ZaswH+OQp04Ls R0CUEGaSkTSiQ+9ZXapoGrbXuNosQMTY9uedLiY6j7QsfTaksOMZ0XatgEH7uqYfpnBpkY2wzpd wAuBIraPUTEwRgIWzWTNepBWD/tbh6E562G6NLo6kGuwFjWHDA46qY230y/qCLehyi86a X-Google-Smtp-Source: ABdhPJzp8UffUcAih9mJLVBzHahrEM5F9ShWM8TNvXgAjcnh+lsqONAlxD8cjTyCetp+280ZPFx2oEJ0QNOaPdwV X-Received: from aaronlewis.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2675]) (user=aaronlewis job=sendgmr) by 2002:a17:90b:2406:: with SMTP id nr6mr2011176pjb.99.1642610751643; Wed, 19 Jan 2022 08:45:51 -0800 (PST) Date: Wed, 19 Jan 2022 16:45:39 +0000 In-Reply-To: <20220119164541.3905055-1-aaronlewis@google.com> Message-Id: <20220119164541.3905055-2-aaronlewis@google.com> Mime-Version: 1.0 References: <20220119164541.3905055-1-aaronlewis@google.com> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [kvm-unit-tests PATCH v3 1/3] x86: Make exception_mnemonic() visible to the tests From: Aaron Lewis To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org exception_mnemonic() is a useful function for more than just desc.c. Make it global, so it can be used in other KUT tests. Signed-off-by: Aaron Lewis --- lib/x86/desc.c | 2 +- lib/x86/desc.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 16b7256..c2eb16e 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -91,7 +91,7 @@ struct ex_record { extern struct ex_record exception_table_start, exception_table_end; -static const char* exception_mnemonic(int vector) +const char* exception_mnemonic(int vector) { switch(vector) { case 0: return "#DE"; diff --git a/lib/x86/desc.h b/lib/x86/desc.h index 9b81da0..ad6277b 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -224,6 +224,7 @@ void set_intr_alt_stack(int e, void *fn); void print_current_tss_info(void); handler handle_exception(u8 v, handler fn); void unhandled_exception(struct ex_regs *regs, bool cpu); +const char* exception_mnemonic(int vector); bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data), void *data); From patchwork Wed Jan 19 16:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lewis X-Patchwork-Id: 12717675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1243CC433F5 for ; Wed, 19 Jan 2022 16:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356228AbiASQqA (ORCPT ); Wed, 19 Jan 2022 11:46:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356215AbiASQp5 (ORCPT ); Wed, 19 Jan 2022 11:45:57 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F64AC061574 for ; Wed, 19 Jan 2022 08:45:57 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id q4-20020aa78424000000b004c022bd294eso1895978pfn.1 for ; Wed, 19 Jan 2022 08:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=K0R65dke/1V33m8zh6lNnvCgpLK4Zxzc+KjXhgOQ+hk=; b=hsITvGKcZ+JY/AMdqQBtngJ9eF1HHubdtKQ7dqWkePq2L29wmZdW6n6Mg0yuym89Aj DihmFga9kDHpBAYHCoACdQ23+fEQYhohtoc7eobg0FB/k+6t0PNyAa+/Qo82LR6CxMl+ YsihdX+HgWSeEpqWaC8k/dFKCO8lVgYfdlBN3SJxOStd3twN9c/OHPKcjA1MS+OFcwgt WM1PMz51fAzzb0rDJCIt/sVKpDnbmLJBwaDfi6gTpxLZrWCowySrUE8qPzx/1c8XU2K4 4ugi5nIZRxSul8uFMi66EzQQ0vtf2BvsdWU66kP6xkI1wpp2312kt4VSu19ppBwg14Jx Mdsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=K0R65dke/1V33m8zh6lNnvCgpLK4Zxzc+KjXhgOQ+hk=; b=N/4EXbLtDqKorLEvvaGqGeZwf8me2pc5vdgiCft9HJTz8Ikc9Wjpa30QcdWrLau3WD BCBOoWw4n88k8t2DbjsR/7yi9xPCXLxiqrhqSOalbnp6T29RIco40qKVkbC80oMSVx6C PG0X3EgxJd2JTjZ+qP7bv1DYT1fl7Jve+BiiQWnxVC/oI4SvGhXkYEz5lolP1jjxvWcw SAe3LIq1VWNAnJgL7AVgVD7hcWuofnuNTlPhal9TSOURk7/Zf2klR6sh6SIJfWHPfl64 CUQrBjdmRAQmeSUlHUuyj9JRy216/NEEyPATESNHHcVzsUro19RWi+jBjQ59PQx97yLb //Qg== X-Gm-Message-State: AOAM531sMlrzog1EV6vbovpbDQkiwazS2lNHmshWsRO1FApDiGXADhSP zw8IrssgU1xfzXs1uNAggNaWjrsl/JsQxlWcngEkopdvEmHHK/SvEBQAblEE/hZsRFUKZ128d1u /tNxGbCgl8065cMG842BOApsImwjSh8uw2Aey7agJ9E5Z2ER95nW3+sghmthE/+9QZcFn X-Google-Smtp-Source: ABdhPJwObjaFXWN6TVVXBoXToHvWOKebT/FgX+ZgshcZUC/R5dvNOF7jbpkhuT/R17uON0mCT767G4PNKSALe15Q X-Received: from aaronlewis.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2675]) (user=aaronlewis job=sendgmr) by 2002:a05:6a00:1681:b0:4a8:2462:ba0a with SMTP id k1-20020a056a00168100b004a82462ba0amr31628322pfc.75.1642610756583; Wed, 19 Jan 2022 08:45:56 -0800 (PST) Date: Wed, 19 Jan 2022 16:45:40 +0000 In-Reply-To: <20220119164541.3905055-1-aaronlewis@google.com> Message-Id: <20220119164541.3905055-3-aaronlewis@google.com> Mime-Version: 1.0 References: <20220119164541.3905055-1-aaronlewis@google.com> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [kvm-unit-tests PATCH v3 2/3] x86: Add support for running a nested guest multiple times in one test From: Aaron Lewis To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KUT has a limit of only being able to run one nested guest per vmx test. This is limiting and not necessary. Add support for allowing a test to run guest code multiple times. Signed-off-by: Aaron Lewis --- x86/vmx.c | 24 ++++++++++++++++++++++-- x86/vmx.h | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index f4fbb94..51eed8c 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1884,15 +1884,35 @@ void test_add_teardown(test_teardown_func func, void *data) step->data = data; } +static void __test_set_guest(test_guest_func func) +{ + assert(current->v2); + v2_guest_main = func; +} + /* * Set the target of the first enter_guest call. Can only be called once per * test. Must be called before first enter_guest call. */ void test_set_guest(test_guest_func func) { - assert(current->v2); TEST_ASSERT_MSG(!v2_guest_main, "Already set guest func."); - v2_guest_main = func; + __test_set_guest(func); +} + +/* + * Set the target of the enter_guest call and reset the RIP so 'func' will + * start from the beginning. This can be called multiple times per test. + */ +void test_override_guest(test_guest_func func) +{ + __test_set_guest(func); + init_vmcs_guest(); +} + +void test_set_guest_finished(void) +{ + guest_finished = 1; } static void check_for_guest_termination(union exit_reason exit_reason) diff --git a/x86/vmx.h b/x86/vmx.h index 4423986..11cb665 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -1055,7 +1055,9 @@ void hypercall(u32 hypercall_no); typedef void (*test_guest_func)(void); typedef void (*test_teardown_func)(void *data); void test_set_guest(test_guest_func func); +void test_override_guest(test_guest_func func); void test_add_teardown(test_teardown_func func, void *data); void test_skip(const char *msg); +void test_set_guest_finished(void); #endif From patchwork Wed Jan 19 16:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lewis X-Patchwork-Id: 12717676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7815EC433FE for ; Wed, 19 Jan 2022 16:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356221AbiASQqC (ORCPT ); Wed, 19 Jan 2022 11:46:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356220AbiASQqB (ORCPT ); Wed, 19 Jan 2022 11:46:01 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14358C061574 for ; Wed, 19 Jan 2022 08:46:01 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id i6-20020a626d06000000b004c0abfd53b3so1865709pfc.12 for ; Wed, 19 Jan 2022 08:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aQ84rLzeWRy9pgNzzxqSbqP8vcIZNPbwGvo2TNGU7N0=; b=l2xqZZqCbiAKGdHrq8v/ofnRrlYdp5At5q08M3yA+IBfLFyog0KxyRsESVBLO7xQ1B SJd9q4VnnV33ErFmyw4cexnc3DPrY+ncEXBFidHwJivtYG4dyyRgdwvji3gnry3WfPPY BbuqP3mLRUvi5OSjDSdx69j6ygysbhGgRoNv7el8XRY+HtiYA5h5bsSC2198p5+saBQV saZCN+LB3/mTNcTVRMv/ee9hhjtEd8a5BVLW8opnanSWhJjt1JmtI0pIlpdID/pG2riP GU5m2iPk3WzM5pkMzTFBunZVKtmxctvVO90f5VmpGPoVdBNdCWf0lVEV/7+dN5D92r/2 xiFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aQ84rLzeWRy9pgNzzxqSbqP8vcIZNPbwGvo2TNGU7N0=; b=yNaV1K2Hvc/4JMZotTc3+5hxRU7nJh4j3N0yjEqw8ENYfGPWK1LMlkOF5w876rW0kJ 4qAVUZJazRMsUJrS1XklNPDPnEtpt7crP3aIa04N7AaWNsfpcFeMCSY1XWQUh6iv+4qa N5WWcWcgKf6o9Z8Er6kp70cdUwMV+Qsudk/wWDFn6RsTJKbLFfXzAZWRIo+5jGd+aoiG aE0eoEAIVLbLSOuH8T3mnceBwkc6qB2K5GsAHdR0dVgIbOW4TkCS5Wzyysc6a6gfk9K+ 20WdVh8lPlqIU4TqjnBXMJDrgurXtZo0xzGvqwrQsX0m+DnT+a/J2YAos/Jfr1btGGzz a9gA== X-Gm-Message-State: AOAM532ZwWXzqcV8yvxcLqkkqJlsApJCD7md9gtvbO0rDIn2Os0IPnnL N1ewU5dX5XwcOtiUqQCo61jST8HHx3VBBEhShONjWybtEzDP9Fv1qoeVTPgdwUIMOungx539AkJ SJ8aoj3VirHNt+5vSYAj2GLbryqQZFmh1Ymw1uSRoLG+gf1p/IAGKxih5xiU09fxZSo5e X-Google-Smtp-Source: ABdhPJzdvrRV8vgGMGOmUrWbbiTeXddWfE57CAuIuSY32U2ho4OsdlWku9ifODmGcJ8BTSs08EPwxhXr7nvKe4lr X-Received: from aaronlewis.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2675]) (user=aaronlewis job=sendgmr) by 2002:a63:6e4e:: with SMTP id j75mr28039915pgc.293.1642610760394; Wed, 19 Jan 2022 08:46:00 -0800 (PST) Date: Wed, 19 Jan 2022 16:45:41 +0000 In-Reply-To: <20220119164541.3905055-1-aaronlewis@google.com> Message-Id: <20220119164541.3905055-4-aaronlewis@google.com> Mime-Version: 1.0 References: <20220119164541.3905055-1-aaronlewis@google.com> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [kvm-unit-tests PATCH v3 3/3] x86: Add test coverage for nested_vmx_reflect_vmexit() testing From: Aaron Lewis To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com, Aaron Lewis Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a framework and test cases to ensure exceptions that occur in L2 are forwarded to the correct place by nested_vmx_reflect_vmexit(). Add testing for exceptions: #GP, #UD, #DE, #DB, #BP, and #AC. Signed-off-by: Aaron Lewis --- x86/unittests.cfg | 7 +++ x86/vmx_tests.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/x86/unittests.cfg b/x86/unittests.cfg index 9a70ba3..8399b05 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -390,6 +390,13 @@ arch = x86_64 groups = vmx nested_exception check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y +[vmx_exception_test] +file = vmx.flat +extra_params = -cpu max,+vmx -append vmx_exception_test +arch = x86_64 +groups = vmx nested_exception +timeout = 10 + [debug] file = debug.flat arch = x86_64 diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 3d57ed6..af6f33b 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -21,6 +21,7 @@ #include "smp.h" #include "delay.h" #include "access.h" +#include "x86/usermode.h" #define VPID_CAP_INVVPID_TYPES_SHIFT 40 @@ -10701,6 +10702,133 @@ static void vmx_pf_vpid_test(void) __vmx_pf_vpid_test(invalidate_tlb_new_vpid, 1); } +static void vmx_l2_gp_test(void) +{ + *(volatile u64 *)NONCANONICAL = 0; +} + +static void vmx_l2_ud_test(void) +{ + asm volatile ("ud2"); +} + +static void vmx_l2_de_test(void) +{ + asm volatile ( + "xor %%eax, %%eax\n\t" + "xor %%ebx, %%ebx\n\t" + "xor %%edx, %%edx\n\t" + "idiv %%ebx\n\t" + ::: "eax", "ebx", "edx"); +} + +static void vmx_l2_bp_test(void) +{ + asm volatile ("int3"); +} + +static void vmx_l2_db_test(void) +{ + write_rflags(read_rflags() | X86_EFLAGS_TF); +} + +static uint64_t usermode_callback(void) +{ + /* Trigger an #AC by writing 8 bytes to a 4-byte aligned address. */ + asm volatile( + "sub $0x10, %rsp\n\t" + "movq $0, 0x4(%rsp)\n\t" + "add $0x10, %rsp\n\t"); + + return 0; +} + +static void vmx_l2_ac_test(void) +{ + bool raised_vector = false; + + write_cr0(read_cr0() | X86_CR0_AM); + write_rflags(read_rflags() | X86_EFLAGS_AC); + + run_in_user(usermode_callback, AC_VECTOR, 0, 0, 0, 0, &raised_vector); + report(raised_vector, "#AC vector raised from usermode in L2"); + vmcall(); +} + +struct vmx_exception_test { + u8 vector; + void (*guest_code)(void); +}; + +struct vmx_exception_test vmx_exception_tests[] = { + { GP_VECTOR, vmx_l2_gp_test }, + { UD_VECTOR, vmx_l2_ud_test }, + { DE_VECTOR, vmx_l2_de_test }, + { DB_VECTOR, vmx_l2_db_test }, + { BP_VECTOR, vmx_l2_bp_test }, + { AC_VECTOR, vmx_l2_ac_test }, +}; + +static u8 vmx_exception_test_vector; + +static void vmx_exception_handler(struct ex_regs *regs) +{ + report(regs->vector == vmx_exception_test_vector, + "Handling %s in L2's exception handler", + exception_mnemonic(vmx_exception_test_vector)); + vmcall(); +} + +static void handle_exception_in_l2(u8 vector) +{ + handler old_handler = handle_exception(vector, vmx_exception_handler); + + vmx_exception_test_vector = vector; + + enter_guest(); + report(vmcs_read(EXI_REASON) == VMX_VMCALL, + "%s handled by L2", exception_mnemonic(vector)); + + handle_exception(vector, old_handler); +} + +static void handle_exception_in_l1(u32 vector) +{ + u32 old_eb = vmcs_read(EXC_BITMAP); + + vmcs_write(EXC_BITMAP, old_eb | (1u << vector)); + + enter_guest(); + + report((vmcs_read(EXI_REASON) == VMX_EXC_NMI) && + ((vmcs_read(EXI_INTR_INFO) & 0xff) == vector), + "%s handled by L1", exception_mnemonic(vector)); + + vmcs_write(EXC_BITMAP, old_eb); +} + +static void vmx_exception_test(void) +{ + struct vmx_exception_test *t; + int i; + + for (i = 0; i < ARRAY_SIZE(vmx_exception_tests); i++) { + t = &vmx_exception_tests[i]; + + /* + * Override the guest code before each run even though it's the + * same code, the VMCS guest state needs to be reinitialized. + */ + test_override_guest(t->guest_code); + handle_exception_in_l2(t->vector); + + test_override_guest(t->guest_code); + handle_exception_in_l1(t->vector); + } + + test_set_guest_finished(); +} + #define TEST(name) { #name, .v2 = name } /* name/init/guest_main/exit_handler/syscall_handler/guest_regs */ @@ -10810,5 +10938,6 @@ struct vmx_test vmx_tests[] = { TEST(vmx_pf_no_vpid_test), TEST(vmx_pf_invvpid_test), TEST(vmx_pf_vpid_test), + TEST(vmx_exception_test), { NULL, NULL, NULL, NULL, NULL, {0} }, };