From nobody Mon Apr 6 08:06:21 2026 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 AE266C54EE9 for ; Thu, 8 Sep 2022 23:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbiIHXel (ORCPT ); Thu, 8 Sep 2022 19:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231331AbiIHXeA (ORCPT ); Thu, 8 Sep 2022 19:34:00 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F1510E868 for ; Thu, 8 Sep 2022 16:31:42 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id oj13-20020a17090b4d8d00b002025cda7659so1949642pjb.0 for ; Thu, 08 Sep 2022 16:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=7Rae3f/XG8eHxbe+XI3rjEcvv9iBFaTeOYNpjRbfcJ8=; b=P1HVemU5Q8l1jHsQ63dpPPBxDNfL3tb1pUm8q4PL+UgH4QBu4+NtJgd8XkKKaIWo+4 k1CEKZkaGyuYGCVnuCKb4hFmgnLdIRztZGXNvIX5oVQBfUCzOqxLRf8mw1ERykDWH4NJ wy2ZzK0YQlXRJNHEoo7w63tqN+10/phJMQjAVrdtqo+M1nI1Jkl3130hL+fAKd+c0NMi BWLVTPqb+2OuhbG2Emeuiwo9CbXF8aCMNVNlaMCUNSMSp4E3NPdj9AdWmNb3LGydn4yg Y30xOFFHvJ1pOKV2OeWGI7rgXEs19ufmuhDW8TVCAPcnC1BoxH1cAR2Qw5FAO8v1478J wMaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=7Rae3f/XG8eHxbe+XI3rjEcvv9iBFaTeOYNpjRbfcJ8=; b=3SQ7/cm7HpH6/ptLW2CskG6g79yPFpmKZlPgpKswnTjpM/zEZys7wNLTcLt49KVuHf NwHbRE0hgS3jAAv4spS9cehQVd9vTIqq3cAEZnS9fsX72eszBAVMOdCvguOW4n6A0lfj UjCQVfelHznMtA7wnH1kbAFiyHnoefWs2GoBYzp9NC92GHXqkSXouEq7LFSJ/wZ70szx J4bxwCJmXtiVou67dLoa22fk4q5A0B0m4WMSw9vIdZbyVjPxvpuRANE2Nccfy+rjOjda Qh3GjySvfz+vSeTDqGB8GJgQG0cROe0HF+a4rzTdgzPsSOZDPVpRNRTBpSKu5Y2lh+6i mk6Q== X-Gm-Message-State: ACgBeo2Hy7npaEUL/BPbMDIuNpaFkxUTIS5xJi1xuj8jrd2knETdeKGO zGhz5p/fxGe1fPEbwhwbnJtlJzF0bCA= X-Google-Smtp-Source: AA6agR6+JFj4LISGeG3WjfMkkR4u9HVYWVC84UL5YJpClnQ7aQNZeM9iC7B6L5Hv/dEp8eGr9UV8LnDK+pw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr118873pje.0.1662679901039; Thu, 08 Sep 2022 16:31:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:30 +0000 In-Reply-To: <20220908233134.3523339-1-seanjc@google.com> Mime-Version: 1.0 References: <20220908233134.3523339-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-2-seanjc@google.com> Subject: [PATCH 1/5] KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement memcmp(), memcpy(), and memset() to override the compiler's built-in versions in order to guarantee that the compiler won't generate out-of-line calls to external functions via the PLT. This allows the helpers to be safely used in guest code, as KVM selftests don't support dynamic loading of guest code. Steal the implementations from the kernel's generic versions, sans the optimizations in memcmp() for unaligned accesses. Put the utilities in a separate compilation unit and build with -ffreestanding to fudge around a gcc "feature" where it will optimize memset(), memcpy(), etc... by generating a recursive call. I.e. the compiler optimizes itself into infinite recursion. Alternatively, the individual functions could be tagged with optimize("no-tree-loop-distribute-patterns"), but using "optimize" for anything but debug is discouraged, and Linus NAK'd the use of the flag in the kernel proper[*]. https://lore.kernel.org/lkml/CAHk-=3Dwik-oXnUpfZ6Hw37uLykc-_P0Apyn2XuX-odh-= 3Nzop8w@mail.gmail.com Cc: Andrew Jones Cc: Anup Patel Cc: Atish Patra Cc: Christian Borntraeger Cc: Janosch Frank Cc: Claudio Imbrenda Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 8 ++++- .../selftests/kvm/include/kvm_util_base.h | 10 ++++++ tools/testing/selftests/kvm/lib/kvm_string.c | 33 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/lib/kvm_string.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests= /kvm/Makefile index 4c122f1b1737..92a0c05645b5 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -48,6 +48,8 @@ LIBKVM +=3D lib/rbtree.c LIBKVM +=3D lib/sparsebit.c LIBKVM +=3D lib/test_util.c =20 +LIBKVM_STRING +=3D lib/kvm_string.c + LIBKVM_x86_64 +=3D lib/x86_64/apic.c LIBKVM_x86_64 +=3D lib/x86_64/handlers.S LIBKVM_x86_64 +=3D lib/x86_64/perf_test_util.c @@ -220,7 +222,8 @@ LIBKVM_C :=3D $(filter %.c,$(LIBKVM)) LIBKVM_S :=3D $(filter %.S,$(LIBKVM)) LIBKVM_C_OBJ :=3D $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C)) LIBKVM_S_OBJ :=3D $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S)) -LIBKVM_OBJS =3D $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) +LIBKVM_STRING_OBJ :=3D $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_STRING)) +LIBKVM_OBJS =3D $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(LIBKVM_STRING_OBJ) =20 EXTRA_CLEAN +=3D $(LIBKVM_OBJS) cscope.* =20 @@ -231,6 +234,9 @@ $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ =20 +$(LIBKVM_STRING_OBJ): $(OUTPUT)/%.o: %.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -ffreestanding $< -o $@ + x :=3D $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) $(TEST_GEN_PROGS): $(LIBKVM_OBJS) $(TEST_GEN_PROGS_EXTENDED): $(LIBKVM_OBJS) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/te= sting/selftests/kvm/include/kvm_util_base.h index 24fde97f6121..bdb751f4825c 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -173,6 +173,16 @@ struct vm_guest_mode_params { }; extern const struct vm_guest_mode_params vm_guest_mode_params[]; =20 +/* + * Override the "basic" built-in string helpers so that they can be used in + * guest code. KVM selftests don't support dynamic loading in guest code = and + * will jump into the weeds if the compiler decides to insert an out-of-li= ne + * call via the PLT. + */ +int memcmp(const void *cs, const void *ct, size_t count); +void *memcpy(void *dest, const void *src, size_t count); +void *memset(void *s, int c, size_t count); + int open_path_or_exit(const char *path, int flags); int open_kvm_dev_path_or_exit(void); unsigned int kvm_check_cap(long cap); diff --git a/tools/testing/selftests/kvm/lib/kvm_string.c b/tools/testing/s= elftests/kvm/lib/kvm_string.c new file mode 100644 index 000000000000..a60d56d4e5b8 --- /dev/null +++ b/tools/testing/selftests/kvm/lib/kvm_string.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "kvm_util.h" + +int memcmp(const void *cs, const void *ct, size_t count) +{ + const unsigned char *su1, *su2; + int res =3D 0; + + for (su1 =3D cs, su2 =3D ct; 0 < count; ++su1, ++su2, count--) { + if ((res =3D *su1 - *su2) !=3D 0) + break; + } + return res; +} + +void *memcpy(void *dest, const void *src, size_t count) +{ + char *tmp =3D dest; + const char *s =3D src; + + while (count--) + *tmp++ =3D *s++; + return dest; +} + +void *memset(void *s, int c, size_t count) +{ + char *xs =3D s; + + while (count--) + *xs++ =3D c; + return s; +} --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 08:06:21 2026 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 7B3D6C54EE9 for ; Thu, 8 Sep 2022 23:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230431AbiIHXeq (ORCPT ); Thu, 8 Sep 2022 19:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbiIHXd7 (ORCPT ); Thu, 8 Sep 2022 19:33:59 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CCA51223AE for ; Thu, 8 Sep 2022 16:31:44 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d7-20020a170903230700b00177f6dd8472so146728plh.6 for ; Thu, 08 Sep 2022 16:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date; bh=Z/wAO7o0uv9mRFKbOQwdugyUqT7UTMkhxbmUHk+l8EY=; b=IkB3irGFigCl/eI2GfiWUAdk+jp1yryLOuRxeiDAHbAnpTZTZebSNjsIX0WwigGctR xldX0JihO0wwuN/pFeGk488tFXqpca88t4ssuW0VWRZVnaIGaRUk78D+BKHFAJP7ZpkT 2ToShsCdxyy4AfUaD3Dhmitw8eInd7mORNOJqpEr4LKvW6qIr6h8fDq/qxMmzz8M2peu BCyVguInJOHXMuHPy7o2Nnt2tSV0rgnKFhiRTjDvB9r2HNSHpEyiPJhSSjbHGkS0Xu2m kK1ASu8iJKY60hRESnnyZfvFx4AMd+Q4TP8NOzzIMouKQmTbqZXqoPC/GnotaHJ1pRP8 wZrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date; bh=Z/wAO7o0uv9mRFKbOQwdugyUqT7UTMkhxbmUHk+l8EY=; b=Lxp0IiZnwGCNdSxoarehwwL+IJ+G/qT+kesK3vGuY/HakV7nA3rxiYkwmT8Ib4U5J8 BkEHtnRRqAVOPHFpRaeXebFtDR3RX2LSUqWGhsFCX/vfRe1BDTABHiQDFjkiH+Fb6In0 LwM2zb4Sjf4gCZOkYrQtgJt4AqiW5L5HeqFlrGF1WL7xWUMOtpONb6XU3HzKZm0q0pyw 0JWevFp1hXzYynEcclYqZ2g5bYXtszKXSDTzxK12ZFAUL27PmeBRGITIcy9uPMuHlxc8 iNyE7skEzM6qx6616j9cqqhrNsiyI9H5pg3s21dr97zIAU3AZBgHM0XpkpfPrQLX5J3K FZpg== X-Gm-Message-State: ACgBeo2/31vFUgc1FbJ0fJVLvguUe873X+HNBXr0zKwfGe7ATYFYQwO0 pjp90uHZ+v/NSz663FXlMlP0oeuslFM= X-Google-Smtp-Source: AA6agR5Df/HcRg0Wq4FafCs9EFBud8rofBtdiX6Xq8TU7TScl/0Guln8a4baCGugW2ag8dwsd/7nQjN7jTs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:b4d:b0:540:cee1:657e with SMTP id p13-20020a056a000b4d00b00540cee1657emr2385360pfo.22.1662679903483; Thu, 08 Sep 2022 16:31:43 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:31 +0000 In-Reply-To: <20220908233134.3523339-1-seanjc@google.com> Mime-Version: 1.0 References: <20220908233134.3523339-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-3-seanjc@google.com> Subject: [PATCH 2/5] KVM: selftests: Compare insn opcodes directly in fix_hypercall_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Directly compare the expected versus observed hypercall instructions when verifying that KVM patched in the native hypercall (FIX_HYPERCALL_INSN quirk enabled). gcc rightly complains that doing a 4-byte memcpy() with an "unsigned char" as the source generates an out-of-bounds accesses. Alternatively, "exp" and "obs" could be declared as 3-byte arrays, but there's no known reason to copy locally instead of comparing directly. In function =E2=80=98assert_hypercall_insn=E2=80=99, inlined from =E2=80=98guest_main=E2=80=99 at x86_64/fix_hypercall_test.= c:91:2: x86_64/fix_hypercall_test.c:63:9: error: array subscript =E2=80=98unsigned = int[0]=E2=80=99 is partly outside array bounds of =E2=80=98unsigned char[1]=E2=80=99 [-Wer= ror=3Darray-bounds] 63 | memcpy(&exp, exp_insn, sizeof(exp)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ x86_64/fix_hypercall_test.c: In function =E2=80=98guest_main=E2=80=99: x86_64/fix_hypercall_test.c:42:22: note: object =E2=80=98vmx_hypercall_insn= =E2=80=99 of size 1 42 | extern unsigned char vmx_hypercall_insn; | ^~~~~~~~~~~~~~~~~~ x86_64/fix_hypercall_test.c:25:22: note: object =E2=80=98svm_hypercall_insn= =E2=80=99 of size 1 25 | extern unsigned char svm_hypercall_insn; | ^~~~~~~~~~~~~~~~~~ In function =E2=80=98assert_hypercall_insn=E2=80=99, inlined from =E2=80=98guest_main=E2=80=99 at x86_64/fix_hypercall_test.= c:91:2: x86_64/fix_hypercall_test.c:64:9: error: array subscript =E2=80=98unsigned = int[0]=E2=80=99 is partly outside array bounds of =E2=80=98unsigned char[1]=E2=80=99 [-Wer= ror=3Darray-bounds] 64 | memcpy(&obs, obs_insn, sizeof(obs)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ x86_64/fix_hypercall_test.c: In function =E2=80=98guest_main=E2=80=99: x86_64/fix_hypercall_test.c:25:22: note: object =E2=80=98svm_hypercall_insn= =E2=80=99 of size 1 25 | extern unsigned char svm_hypercall_insn; | ^~~~~~~~~~~~~~~~~~ x86_64/fix_hypercall_test.c:42:22: note: object =E2=80=98vmx_hypercall_insn= =E2=80=99 of size 1 42 | extern unsigned char vmx_hypercall_insn; | ^~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [../lib.mk:135: tools/testing/selftests/kvm/x86_64/fix_hypercall_= test] Error 1 Fixes: 6c2fa8b20d0c ("selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN= ") Cc: Oliver Upton Signed-off-by: Sean Christopherson Reviewed-by: Oliver Upton --- .../selftests/kvm/x86_64/fix_hypercall_test.c | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tool= s/testing/selftests/kvm/x86_64/fix_hypercall_test.c index b1905d280ef5..2512df357ab3 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -14,6 +14,9 @@ #include "kvm_util.h" #include "processor.h" =20 +/* VMCALL and VMMCALL are both 3-byte opcodes. */ +#define HYPERCALL_INSN_SIZE 3 + static bool ud_expected; =20 static void guest_ud_handler(struct ex_regs *regs) @@ -22,7 +25,7 @@ static void guest_ud_handler(struct ex_regs *regs) GUEST_DONE(); } =20 -extern unsigned char svm_hypercall_insn; +extern unsigned char svm_hypercall_insn[HYPERCALL_INSN_SIZE]; static uint64_t svm_do_sched_yield(uint8_t apic_id) { uint64_t ret; @@ -39,7 +42,7 @@ static uint64_t svm_do_sched_yield(uint8_t apic_id) return ret; } =20 -extern unsigned char vmx_hypercall_insn; +extern unsigned char vmx_hypercall_insn[HYPERCALL_INSN_SIZE]; static uint64_t vmx_do_sched_yield(uint8_t apic_id) { uint64_t ret; @@ -56,16 +59,6 @@ static uint64_t vmx_do_sched_yield(uint8_t apic_id) return ret; } =20 -static void assert_hypercall_insn(unsigned char *exp_insn, unsigned char *= obs_insn) -{ - uint32_t exp =3D 0, obs =3D 0; - - memcpy(&exp, exp_insn, sizeof(exp)); - memcpy(&obs, obs_insn, sizeof(obs)); - - GUEST_ASSERT_EQ(exp, obs); -} - static void guest_main(void) { unsigned char *native_hypercall_insn, *hypercall_insn; @@ -74,12 +67,12 @@ static void guest_main(void) apic_id =3D GET_APIC_ID_FIELD(xapic_read_reg(APIC_ID)); =20 if (is_intel_cpu()) { - native_hypercall_insn =3D &vmx_hypercall_insn; - hypercall_insn =3D &svm_hypercall_insn; + native_hypercall_insn =3D vmx_hypercall_insn; + hypercall_insn =3D svm_hypercall_insn; svm_do_sched_yield(apic_id); } else if (is_amd_cpu()) { - native_hypercall_insn =3D &svm_hypercall_insn; - hypercall_insn =3D &vmx_hypercall_insn; + native_hypercall_insn =3D svm_hypercall_insn; + hypercall_insn =3D vmx_hypercall_insn; vmx_do_sched_yield(apic_id); } else { GUEST_ASSERT(0); @@ -87,8 +80,13 @@ static void guest_main(void) return; } =20 + /* + * The hypercall didn't #UD (guest_ud_handler() signals "done" if a #UD + * occurs). Verify that a #UD is NOT expected and that KVM patched in + * the native hypercall. + */ GUEST_ASSERT(!ud_expected); - assert_hypercall_insn(native_hypercall_insn, hypercall_insn); + GUEST_ASSERT(!memcmp(native_hypercall_insn, hypercall_insn, HYPERCALL_INS= N_SIZE)); GUEST_DONE(); } =20 --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 08:06:21 2026 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 267BFC54EE9 for ; Thu, 8 Sep 2022 23:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiIHXeh (ORCPT ); Thu, 8 Sep 2022 19:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbiIHXeD (ORCPT ); Thu, 8 Sep 2022 19:34:03 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60B6C108721 for ; Thu, 8 Sep 2022 16:31:46 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id q6-20020a17090311c600b0017266460b8fso150805plh.4 for ; Thu, 08 Sep 2022 16:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=xeFgTKLEFiHOB/M2DDI+MkAiIXTDAhcWUCQwueHFFYo=; b=fHJCkeC4xm2CCMxwGvZeMN4WIrs+Rz2fN6+vaYnp/UJ6pc1sAQQxxB/ouafFLTNMa6 MXdzZ23sWrlw3ZuFX7HcAqF3t16sutl3QssHRs5L2LQpy12bj7jTCU437CctdcJ3fn0r /9k3/R5oCr9E0VQhnkD6WWrq206x+JtlVfHib8u9W3zuE98hMB0fiA+CKg5KGeGrz3Oi V6fogMfEyvwtVfm4gEIOl008Vswek6Elst5RLuWsn4LenjRCUp0PSkqOwEWyt/PBHnVH eHK98WSnISjOpeBHV+iHAK/vvyiKnLd5UF/UmByhMVoi/BBcD0hg8srk1A9Waqbz2yXx +DUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=xeFgTKLEFiHOB/M2DDI+MkAiIXTDAhcWUCQwueHFFYo=; b=reN1RKZfWOsaF4TJ27xCxvjTPG9zfhGPTLPWUoluoFBztX0L/Qf30MXer6jzMTa5LY JDYszsUe086EDR74n8UWvni4BXiVz9IhpKGH+VExkkGz+2ngp/lcrnbXIDBALbQy9d4R tJ1h2dUwpiqIl5o2WdUbMUKDmhbIufvekgyZ/O3Lfr6sPdhYZto8wHSuAbOAgGiaLtPn 6FM2U3BD0vZ2pohS5X1aWpYIGLiwtWapHmRt5NR/5rSM5SpKQuc4wHGjciM+vioMVf+R PmQqwd6Uh9YycP2xH1tlpoEjvqi3LQwLp43H0oo/rFjL3JxRVuwnpwi3tsoDP9xOYRKY ky2w== X-Gm-Message-State: ACgBeo1ulJSfjyASZhTMbryzxgcLjni6PQUt1vfdcONH9TdGR2ugFE2N PT0nY7xl+sBnuketYvXyv8N3V1G8Zz0= X-Google-Smtp-Source: AA6agR5+KvZYz7gdURCU07mIkYGoV0EpUavYTtuEpBeF40snucz+v+X1NUyfoJ3tC7ZKV8JLUy5EoDi1KEU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:e7c2:b0:1f5:85ab:938c with SMTP id kb2-20020a17090ae7c200b001f585ab938cmr6706565pjb.133.1662679905144; Thu, 08 Sep 2022 16:31:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:32 +0000 In-Reply-To: <20220908233134.3523339-1-seanjc@google.com> Mime-Version: 1.0 References: <20220908233134.3523339-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-4-seanjc@google.com> Subject: [PATCH 3/5] KVM: selftests: Remove unnecessary register shuffling in fix_hypercall_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use input constraints to load RAX and RBX when testing that KVM correctly does/doesn't patch the "wrong" hypercall. There's no need to manually load RAX and RBX, and no reason to clobber them either (KVM is not supposed to modify anything other than RAX). Signed-off-by: Sean Christopherson Reviewed-by: Oliver Upton --- .../selftests/kvm/x86_64/fix_hypercall_test.c | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tool= s/testing/selftests/kvm/x86_64/fix_hypercall_test.c index 2512df357ab3..dde97be3e719 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -30,14 +30,11 @@ static uint64_t svm_do_sched_yield(uint8_t apic_id) { uint64_t ret; =20 - asm volatile("mov %1, %%rax\n\t" - "mov %2, %%rbx\n\t" - "svm_hypercall_insn:\n\t" + asm volatile("svm_hypercall_insn:\n\t" "vmmcall\n\t" - "mov %%rax, %0\n\t" - : "=3Dr"(ret) - : "r"((uint64_t)KVM_HC_SCHED_YIELD), "r"((uint64_t)apic_id) - : "rax", "rbx", "memory"); + : "=3Da"(ret) + : "a"((uint64_t)KVM_HC_SCHED_YIELD), "b"((uint64_t)apic_id) + : "memory"); =20 return ret; } @@ -47,14 +44,11 @@ static uint64_t vmx_do_sched_yield(uint8_t apic_id) { uint64_t ret; =20 - asm volatile("mov %1, %%rax\n\t" - "mov %2, %%rbx\n\t" - "vmx_hypercall_insn:\n\t" + asm volatile("vmx_hypercall_insn:\n\t" "vmcall\n\t" - "mov %%rax, %0\n\t" - : "=3Dr"(ret) - : "r"((uint64_t)KVM_HC_SCHED_YIELD), "r"((uint64_t)apic_id) - : "rax", "rbx", "memory"); + : "=3Da"(ret) + : "a"((uint64_t)KVM_HC_SCHED_YIELD), "b"((uint64_t)apic_id) + : "memory"); =20 return ret; } --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 08:06:21 2026 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 EEC6CC6FA83 for ; Thu, 8 Sep 2022 23:34:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbiIHXea (ORCPT ); Thu, 8 Sep 2022 19:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231356AbiIHXeD (ORCPT ); Thu, 8 Sep 2022 19:34:03 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3844010D73C for ; Thu, 8 Sep 2022 16:31:51 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id w14-20020a170902e88e00b00177ab7a12f6so125869plg.16 for ; Thu, 08 Sep 2022 16:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=Kq7Ss9OAHHpQQ8yCW1BLkqtyFB//rSEYUTl89YUKn0Q=; b=VhldITLk7+bmmPtIWtuWHo+WTW8MShqlxBof+v4NI1fiQ7tYJy9DThm2Wthntum6xd OX7WZbYcykUhQV/ZZ4De7i4UGVtBVXZBZuoA21BmEAUJbSKeX0Cu+DzuKjz8KobjGe0y SfjiTKYX9It2saLW/Pvcn+qs9Frb/0CxihE7N+6Mz9M3y/JM/MFdS12gF6yQnPpvlhoY WQxs1oyr3FGqderPqn/KiJbJocAQUAvGoJGkGyegUZ/fas6swqYPtvx1er3IIz/5nazu bVSrswS/KqcFzBiEA2Kpxftq/+vVbGQr018WTPyzCkx7lhKXG7pyhK+VSnflJ+39MGs9 QojQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=Kq7Ss9OAHHpQQ8yCW1BLkqtyFB//rSEYUTl89YUKn0Q=; b=Z1fNQEEZsME7myUXdF+4+dW9z2ha9coOdyfHOdGGJH8NFjFjsdVLz3PyjD35Xxza/s sMwPLMJxuOWRMHQx90/LAwXNwPhGHtcCPC6ywGUa6fhynWiC7XWcFXBYgmvOLuvBQ8jZ /kh0jO+USB4cg75mW0f14KoS3F7xMmMEd690naWcGQRMU/8FMwdIrWWbPgTHOe1A+Vm1 Qq+vGZQN+ByFW3sSbNAHUKWvrCvVKNGd2VJQ5FrU+wO3T82YKNzqhtZAA8mVpGwqB0rO lGItUA6XcIHQxBPYrd9QfvhB9Jynhb81OX3V7M39+YgTe0cVEB6vBeMhMV54unBQPaSK Nnlg== X-Gm-Message-State: ACgBeo2uT3nBnk810ChYSwN9LcluS1tSRM/D2EEjOVDMXXFBIsgbDIEE e6Q++c0JCAo5dUmUzDnqwQVzPN+OM1c= X-Google-Smtp-Source: AA6agR4C0togMqSWJ7Nl/286XAZPOB2ZvwN9FkL/sTRhlyIbmFJwUqT44ToPUX3IgcTitRDZZTuhTkJl0Qw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:ed08:0:b0:537:17a6:57aa with SMTP id u8-20020a62ed08000000b0053717a657aamr11662126pfh.6.1662679906905; Thu, 08 Sep 2022 16:31:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:33 +0000 In-Reply-To: <20220908233134.3523339-1-seanjc@google.com> Mime-Version: 1.0 References: <20220908233134.3523339-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-5-seanjc@google.com> Subject: [PATCH 4/5] KVM: selftests: Explicitly verify KVM doesn't patch hypercall if quirk==off From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Explicitly verify that KVM doesn't patch in the native hypercall if the FIX_HYPERCALL_INSN quirk is disabled. The test currently verifies that a #UD occurred, but doesn't actually verify that no patching occurred. Signed-off-by: Sean Christopherson --- .../selftests/kvm/x86_64/fix_hypercall_test.c | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tool= s/testing/selftests/kvm/x86_64/fix_hypercall_test.c index dde97be3e719..5925da3b3648 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -21,8 +21,8 @@ static bool ud_expected; =20 static void guest_ud_handler(struct ex_regs *regs) { - GUEST_ASSERT(ud_expected); - GUEST_DONE(); + regs->rax =3D -EFAULT; + regs->rip +=3D HYPERCALL_INSN_SIZE; } =20 extern unsigned char svm_hypercall_insn[HYPERCALL_INSN_SIZE]; @@ -57,17 +57,18 @@ static void guest_main(void) { unsigned char *native_hypercall_insn, *hypercall_insn; uint8_t apic_id; + uint64_t ret; =20 apic_id =3D GET_APIC_ID_FIELD(xapic_read_reg(APIC_ID)); =20 if (is_intel_cpu()) { native_hypercall_insn =3D vmx_hypercall_insn; hypercall_insn =3D svm_hypercall_insn; - svm_do_sched_yield(apic_id); + ret =3D svm_do_sched_yield(apic_id); } else if (is_amd_cpu()) { native_hypercall_insn =3D svm_hypercall_insn; hypercall_insn =3D vmx_hypercall_insn; - vmx_do_sched_yield(apic_id); + ret =3D vmx_do_sched_yield(apic_id); } else { GUEST_ASSERT(0); /* unreachable */ @@ -75,12 +76,28 @@ static void guest_main(void) } =20 /* - * The hypercall didn't #UD (guest_ud_handler() signals "done" if a #UD - * occurs). Verify that a #UD is NOT expected and that KVM patched in - * the native hypercall. + * If the quirk is disabled, verify that guest_ud_handler() "returned" + * -EFAULT and that KVM did NOT patch the hypercall. If the quirk is + * enabled, verify that the hypercall succeeded and that KVM patched in + * the "right" hypercall. */ - GUEST_ASSERT(!ud_expected); - GUEST_ASSERT(!memcmp(native_hypercall_insn, hypercall_insn, HYPERCALL_INS= N_SIZE)); + if (ud_expected) { + GUEST_ASSERT(ret =3D=3D (uint64_t)-EFAULT); + + /* + * Divergence should occur only on the last byte, as the VMCALL + * (0F 01 C1) and VMMCALL (0F 01 D9) share the first two bytes. + */ + GUEST_ASSERT(!memcmp(native_hypercall_insn, hypercall_insn, + HYPERCALL_INSN_SIZE - 1)); + GUEST_ASSERT(memcmp(native_hypercall_insn, hypercall_insn, + HYPERCALL_INSN_SIZE)); + } else { + GUEST_ASSERT(!ret); + GUEST_ASSERT(!memcmp(native_hypercall_insn, hypercall_insn, + HYPERCALL_INSN_SIZE)); + } + GUEST_DONE(); } =20 --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 08:06:21 2026 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 46060ECAAD5 for ; Thu, 8 Sep 2022 23:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbiIHXe4 (ORCPT ); Thu, 8 Sep 2022 19:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231364AbiIHXeE (ORCPT ); Thu, 8 Sep 2022 19:34:04 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5E7C10F8ED for ; Thu, 8 Sep 2022 16:31:49 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id v18-20020a17090a899200b00200a2c60f3aso2199679pjn.5 for ; Thu, 08 Sep 2022 16:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=pR1IVVufUDoLTi7sM6oCGasuX8D5bEWKzHsK5TFQcjA=; b=SX1Arlkk9SXL+yXwVHelHtbPesxMkKFSWRgdWNPe60pe4PPF/Ksx+DrYv59q+p822t qdRaYY+1oiHQYa2apG6DXI3edxKcbkRVV5uiZdk5Bf49RmqsP5R3AsSks6vjDVRMpwFh 3nAbt5iAnC3qgauHbLFi5iTpfj+bfOHXiG9KvrfficB8mHmR8/py1j+cwrHjypH99zpi DHAA+kAEjL6wARYr/gYUDnr3rtT5g6RaCCjHVs8Fin8Trw0kJ9IL9qbA0p+ZcbOmib7O e74dOXCziorpnV2ITxi+Qdr1l3brBLOcbvFtTWB5oHN71YWuHV7ICn74Ecd6pPD4BKS4 UJcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=pR1IVVufUDoLTi7sM6oCGasuX8D5bEWKzHsK5TFQcjA=; b=B6EGgFtxW19dWiBYdwALOcoVYN425Kem2RMdtgRvUIxXN+DkLfqFm26q3I8B/QC3qv EAY9iQcQjvwTZL2GX/+n7zIirpoBMletlalf/Lid+VDIL1UjGSfQzFyzboyUGa+ZwSYK mUIWBnXkR5um5nolDcQPV3pvdJfGgdE0KDBiRjXXB3ID/N5NQSbPKiq7m8Sj8v1996UF SWKui2njUmGk+o4lbFH3DazaVOJG2JGC3eAN81yR95dQ76XF9ZUX/5alRrP2l1okpU50 Oxie6FnpIKyjqpC4SrPXSg2JRQCGOM6FQ2pxID3/CeZSV/WUQ7lw4rPNkB0FtKBFO33o a1AQ== X-Gm-Message-State: ACgBeo2x1A6h8QkpgTMgipZItfCMjVXWef6+0rA1EwZrTTLNvyrZOdWF I9WeIp2ARju2ytEkzgAmpKq3MFbbCSw= X-Google-Smtp-Source: AA6agR4XlUDA4rSv8HuDaVOd7n0uD2AzVoaUOTKU3me7i+UtljPpFWgpXphG8R/kJnJaK8ckDWoeZLVZjJA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr118903pje.0.1662679908489; Thu, 08 Sep 2022 16:31:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 8 Sep 2022 23:31:34 +0000 In-Reply-To: <20220908233134.3523339-1-seanjc@google.com> Mime-Version: 1.0 References: <20220908233134.3523339-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220908233134.3523339-6-seanjc@google.com> Subject: [PATCH 5/5] KVM: selftests: Dedup subtests of fix_hypercall_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jones , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Oliver Upton Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Combine fix_hypercall_test's two subtests into a common routine, the only difference between the two is whether or not disable the quirk. Passing a boolean is a little gross, but using an enum to make it super obvious that the callers are enabling/disabling the quirk seems like overkill. No functional change intended. Signed-off-by: Sean Christopherson Reviewed-by: Oliver Upton --- .../selftests/kvm/x86_64/fix_hypercall_test.c | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tool= s/testing/selftests/kvm/x86_64/fix_hypercall_test.c index 5925da3b3648..4bbc4b95136f 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -17,7 +17,7 @@ /* VMCALL and VMMCALL are both 3-byte opcodes. */ #define HYPERCALL_INSN_SIZE 3 =20 -static bool ud_expected; +static bool quirk_disabled; =20 static void guest_ud_handler(struct ex_regs *regs) { @@ -81,7 +81,7 @@ static void guest_main(void) * enabled, verify that the hypercall succeeded and that KVM patched in * the "right" hypercall. */ - if (ud_expected) { + if (quirk_disabled) { GUEST_ASSERT(ret =3D=3D (uint64_t)-EFAULT); =20 /* @@ -101,13 +101,6 @@ static void guest_main(void) GUEST_DONE(); } =20 -static void setup_ud_vector(struct kvm_vcpu *vcpu) -{ - vm_init_descriptor_tables(vcpu->vm); - vcpu_init_descriptor_tables(vcpu); - vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler); -} - static void enter_guest(struct kvm_vcpu *vcpu) { struct kvm_run *run =3D vcpu->run; @@ -128,35 +121,23 @@ static void enter_guest(struct kvm_vcpu *vcpu) } } =20 -static void test_fix_hypercall(void) +static void test_fix_hypercall(bool disable_quirk) { struct kvm_vcpu *vcpu; struct kvm_vm *vm; =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_main); - setup_ud_vector(vcpu); =20 - ud_expected =3D false; - sync_global_to_guest(vm, ud_expected); + vm_init_descriptor_tables(vcpu->vm); + vcpu_init_descriptor_tables(vcpu); + vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler); =20 - virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); + if (disable_quirk) + vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, + KVM_X86_QUIRK_FIX_HYPERCALL_INSN); =20 - enter_guest(vcpu); -} - -static void test_fix_hypercall_disabled(void) -{ - struct kvm_vcpu *vcpu; - struct kvm_vm *vm; - - vm =3D vm_create_with_one_vcpu(&vcpu, guest_main); - setup_ud_vector(vcpu); - - vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2, - KVM_X86_QUIRK_FIX_HYPERCALL_INSN); - - ud_expected =3D true; - sync_global_to_guest(vm, ud_expected); + quirk_disabled =3D disable_quirk; + sync_global_to_guest(vm, quirk_disabled); =20 virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); =20 @@ -167,6 +148,6 @@ int main(void) { TEST_REQUIRE(kvm_check_cap(KVM_CAP_DISABLE_QUIRKS2) & KVM_X86_QUIRK_FIX_H= YPERCALL_INSN); =20 - test_fix_hypercall(); - test_fix_hypercall_disabled(); + test_fix_hypercall(false); + test_fix_hypercall(true); } --=20 2.37.2.789.g6183377224-goog