From patchwork Thu Sep 15 00:04:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976700 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 83A55C6FA89 for ; Thu, 15 Sep 2022 00:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbiIOAE6 (ORCPT ); Wed, 14 Sep 2022 20:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbiIOAEz (ORCPT ); Wed, 14 Sep 2022 20:04:55 -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 CAA33BE15 for ; Wed, 14 Sep 2022 17:04:53 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id a6-20020a17090abe0600b00200303ba903so12839461pjs.2 for ; Wed, 14 Sep 2022 17:04:53 -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:from:to:cc:subject:date; bh=HzFTk0Gwvu5FDuPFjtYjvgBsWz09+mU46zeEkqoNus8=; b=rFf3RuwkENpEmYKhPVnyPwlbnkEweCcQF2YDeICA0NYA3UrC+AW00LaYU96mdcswgH z+qPQbdSykpi4ttX4ol39CA1Zw4kiPXLWLZ+aaJshE47upw/0CS9hEByNn6YN04LFoAo BAGBYgzT297eAi1CZh0m/cWHtq18xjYK2jQN1/9bNzK081wo8EUHuMuu+qO+BMrmqTpN hEhBTpA5E4MPL2zP+VkUwUeNmNDCFaUcc9pJS9q0O1xAugOstwkVUU7I1KqOqMTg5G9t 49FDb/tpcyCF4QXAaZSZ70jX2pDuFiob2NDiv7CIEO9plilb1SrDyj68NP+bnxlezqBw gkUg== 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:x-gm-message-state:from:to:cc:subject:date; bh=HzFTk0Gwvu5FDuPFjtYjvgBsWz09+mU46zeEkqoNus8=; b=6EPh/+/m9HRid+cropWb1LNAkF2z4M8OvAbSAGZRVKHTF2giTQR+XE1CGRDM3Hbeum 3ly36EbVr4GnBkS2buz7OpS5T3IpeRMw0Gbyn+bbbce1M0ZikDkVyQ0gftWIWeOiOq5B 3OoCyLdH6Koho1bhVFHOWqvTlSodcWsy6rWEqIREN0SG/mq8AmtISHPyszaa8yr+R6dj ihONqk9yRsUeNyw5Jxtiouudtt1etXZve5GRrH1nbg06RAXOo3FZ9jGHiKffnmR96Woo K2yw+8Cy0+ttLfkgEEj8uL/URPQK4EDkyJIyqQInEPzrcjMOaYU9JYcOyb3T1wR3vdS/ KoEQ== X-Gm-Message-State: ACgBeo0puAC+99lYrEaI07omqvbEGqxDbNhvCh/RKv/QCxIpgvx2KXC4 4hrIq/F2KqWmXAd53cgBVTddphEsG56CDfMi X-Google-Smtp-Source: AA6agR6/VCxlMfjO8TEoV0AWKOcLeMdVGlNDMFC9A5afIvhWzNXJadtv2rNwT8dc7QfzWCHcyfuorYf4H+jCzM4b X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a05:6a00:804:b0:544:4e98:3ff3 with SMTP id m4-20020a056a00080400b005444e983ff3mr15543952pfk.36.1663200293302; Wed, 14 Sep 2022 17:04:53 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:41 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-2-vannapurve@google.com> Subject: [V2 PATCH 1/8] KVM: selftests: move common startup logic to kvm_util.c From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Consolidate common startup logic in one place by implementing a single setup function with __attribute((constructor)) for all selftests within kvm_util.c. This allows moving logic like: /* Tell stdout not to buffer its content */ setbuf(stdout, NULL); to a single file for all selftests. This will also allow any required setup at entry in future to be done in common main function. More context is discussed at: https://lore.kernel.org/lkml/Ywa9T+jKUpaHLu%2Fl@google.com/ Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/aarch64/arch_timer.c | 3 --- tools/testing/selftests/kvm/aarch64/hypercalls.c | 2 -- tools/testing/selftests/kvm/aarch64/vgic_irq.c | 3 --- tools/testing/selftests/kvm/lib/kvm_util.c | 6 ++++++ tools/testing/selftests/kvm/memslot_perf_test.c | 3 --- tools/testing/selftests/kvm/rseq_test.c | 3 --- tools/testing/selftests/kvm/s390x/memop.c | 2 -- tools/testing/selftests/kvm/s390x/resets.c | 2 -- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 3 --- tools/testing/selftests/kvm/set_memory_region_test.c | 3 --- tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 3 --- tools/testing/selftests/kvm/x86_64/emulator_error_test.c | 3 --- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 3 --- tools/testing/selftests/kvm/x86_64/platform_info_test.c | 3 --- tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 3 --- tools/testing/selftests/kvm/x86_64/set_sregs_test.c | 3 --- .../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 3 --- tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 3 --- tools/testing/selftests/kvm/x86_64/userspace_io_test.c | 3 --- .../testing/selftests/kvm/x86_64/userspace_msr_exit_test.c | 3 --- 20 files changed, 6 insertions(+), 54 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/arch_timer.c b/tools/testing/selftests/kvm/aarch64/arch_timer.c index 574eb73f0e90..07836bd2672b 100644 --- a/tools/testing/selftests/kvm/aarch64/arch_timer.c +++ b/tools/testing/selftests/kvm/aarch64/arch_timer.c @@ -462,9 +462,6 @@ int main(int argc, char *argv[]) { struct kvm_vm *vm; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - if (!parse_args(argc, argv)) exit(KSFT_SKIP); diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c index a39da3fe4952..6463fd118429 100644 --- a/tools/testing/selftests/kvm/aarch64/hypercalls.c +++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c @@ -306,8 +306,6 @@ static void test_run(void) int main(void) { - setbuf(stdout, NULL); - test_run(); return 0; } diff --git a/tools/testing/selftests/kvm/aarch64/vgic_irq.c b/tools/testing/selftests/kvm/aarch64/vgic_irq.c index 17417220a083..3f204f2e93bf 100644 --- a/tools/testing/selftests/kvm/aarch64/vgic_irq.c +++ b/tools/testing/selftests/kvm/aarch64/vgic_irq.c @@ -818,9 +818,6 @@ int main(int argc, char **argv) int opt; bool eoi_split = false; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) { switch (opt) { case 'n': diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 9889fe0d8919..3c83838999f5 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1979,3 +1979,9 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, break; } } + +void __attribute((constructor)) kvm_selftest_init(void) +{ + /* Tell stdout not to buffer its content. */ + setbuf(stdout, NULL); +} diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testing/selftests/kvm/memslot_perf_test.c index 44995446d942..f7ba77ff45c9 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -1007,9 +1007,6 @@ int main(int argc, char *argv[]) struct test_result rbestslottime; int tctr; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - if (!parse_args(argc, argv, &targs)) return -1; diff --git a/tools/testing/selftests/kvm/rseq_test.c b/tools/testing/selftests/kvm/rseq_test.c index fac248a43666..1cc459822c27 100644 --- a/tools/testing/selftests/kvm/rseq_test.c +++ b/tools/testing/selftests/kvm/rseq_test.c @@ -205,9 +205,6 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; u32 cpu, rseq_cpu; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - r = sched_getaffinity(0, sizeof(possible_mask), &possible_mask); TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)", errno, strerror(errno)); diff --git a/tools/testing/selftests/kvm/s390x/memop.c b/tools/testing/selftests/kvm/s390x/memop.c index 9113696d5178..3fd81e58f40c 100644 --- a/tools/testing/selftests/kvm/s390x/memop.c +++ b/tools/testing/selftests/kvm/s390x/memop.c @@ -760,8 +760,6 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_MEM_OP)); - setbuf(stdout, NULL); /* Tell stdout not to buffer its content */ - ksft_print_header(); ksft_set_plan(ARRAY_SIZE(testlist)); diff --git a/tools/testing/selftests/kvm/s390x/resets.c b/tools/testing/selftests/kvm/s390x/resets.c index 19486084eb30..e41e2cb8ffa9 100644 --- a/tools/testing/selftests/kvm/s390x/resets.c +++ b/tools/testing/selftests/kvm/s390x/resets.c @@ -296,8 +296,6 @@ int main(int argc, char *argv[]) bool has_s390_vcpu_resets = kvm_check_cap(KVM_CAP_S390_VCPU_RESETS); int idx; - setbuf(stdout, NULL); /* Tell stdout not to buffer its content */ - ksft_print_header(); ksft_set_plan(ARRAY_SIZE(testlist)); diff --git a/tools/testing/selftests/kvm/s390x/sync_regs_test.c b/tools/testing/selftests/kvm/s390x/sync_regs_test.c index 3fdb6e2598eb..2ddde41c44ba 100644 --- a/tools/testing/selftests/kvm/s390x/sync_regs_test.c +++ b/tools/testing/selftests/kvm/s390x/sync_regs_test.c @@ -231,9 +231,6 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_has_cap(KVM_CAP_SYNC_REGS)); - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - ksft_print_header(); ksft_set_plan(ARRAY_SIZE(testlist)); diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 0d55f508d595..614141d6e53d 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -392,9 +392,6 @@ int main(int argc, char *argv[]) int i, loops; #endif - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - #ifdef __x86_64__ /* * FIXME: the zero-memslot test fails on aarch64 and s390x because diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c index 4208487652f8..1027a671c7d3 100644 --- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c +++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c @@ -57,9 +57,6 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE)); - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - vm = vm_create_with_one_vcpu(&vcpu, guest_code); run = vcpu->run; diff --git a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c b/tools/testing/selftests/kvm/x86_64/emulator_error_test.c index 236e11755ba6..3334adcfd591 100644 --- a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c +++ b/tools/testing/selftests/kvm/x86_64/emulator_error_test.c @@ -156,9 +156,6 @@ int main(int argc, char *argv[]) uint64_t *hva; int rc; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - TEST_REQUIRE(kvm_has_cap(KVM_CAP_SMALLER_MAXPHYADDR)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c index e804eb08dff9..5c27efbf405e 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c @@ -134,9 +134,6 @@ int main(int argc, char *argv[]) const struct kvm_cpuid2 *hv_cpuid_entries; struct kvm_vcpu *vcpu; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_CPUID)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/platform_info_test.c b/tools/testing/selftests/kvm/x86_64/platform_info_test.c index 76417c7d687b..310a104d94f0 100644 --- a/tools/testing/selftests/kvm/x86_64/platform_info_test.c +++ b/tools/testing/selftests/kvm/x86_64/platform_info_test.c @@ -72,9 +72,6 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; uint64_t msr_platform_info; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index ea4e259a1e2e..a6ffa245c897 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c @@ -447,9 +447,6 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER)); TEST_REQUIRE(use_intel_pmu() || use_amd_pmu()); diff --git a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c b/tools/testing/selftests/kvm/x86_64/set_sregs_test.c index 2bb08bf2125d..a284fcef6ed7 100644 --- a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c +++ b/tools/testing/selftests/kvm/x86_64/set_sregs_test.c @@ -82,9 +82,6 @@ int main(int argc, char *argv[]) uint64_t cr4; int rc; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - /* * Create a dummy VM, specifically to avoid doing KVM_SET_CPUID2, and * use it to verify all supported CR4 bits can be set prior to defining diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c index e637d7736012..e497ace629c1 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c @@ -194,9 +194,6 @@ static void run_test(bool is_nmi) int main(int argc, char *argv[]) { - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); TEST_ASSERT(kvm_cpu_has(X86_FEATURE_NRIPS), diff --git a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c index 9b6db0b0b13e..d2f9b5bdfab2 100644 --- a/tools/testing/selftests/kvm/x86_64/sync_regs_test.c +++ b/tools/testing/selftests/kvm/x86_64/sync_regs_test.c @@ -90,9 +90,6 @@ int main(int argc, char *argv[]) struct kvm_vcpu_events events; int rv, cap; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - cap = kvm_check_cap(KVM_CAP_SYNC_REGS); TEST_REQUIRE((cap & TEST_SYNC_FIELDS) == TEST_SYNC_FIELDS); TEST_REQUIRE(!(cap & INVALID_SYNC_FIELD)); diff --git a/tools/testing/selftests/kvm/x86_64/userspace_io_test.c b/tools/testing/selftests/kvm/x86_64/userspace_io_test.c index 7316521428f8..91076c9787b4 100644 --- a/tools/testing/selftests/kvm/x86_64/userspace_io_test.c +++ b/tools/testing/selftests/kvm/x86_64/userspace_io_test.c @@ -56,9 +56,6 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; struct ucall uc; - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - vm = vm_create_with_one_vcpu(&vcpu, guest_code); run = vcpu->run; diff --git a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c index a4f06370a245..8ef5c8b25e95 100644 --- a/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +++ b/tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c @@ -735,9 +735,6 @@ static void test_msr_permission_bitmap(void) int main(int argc, char *argv[]) { - /* Tell stdout not to buffer its content */ - setbuf(stdout, NULL); - test_msr_filter_allow(); test_msr_filter_deny(); From patchwork Thu Sep 15 00:04:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976701 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 946ADC6FA82 for ; Thu, 15 Sep 2022 00:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbiIOAFA (ORCPT ); Wed, 14 Sep 2022 20:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbiIOAE6 (ORCPT ); Wed, 14 Sep 2022 20:04:58 -0400 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 82AF0FD06 for ; Wed, 14 Sep 2022 17:04:56 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id h13-20020a63530d000000b0043087bbf72dso8162603pgb.17 for ; Wed, 14 Sep 2022 17:04:56 -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:from:to:cc:subject:date; bh=k7YNCe9q93GJKQLNbQn4DCcTE32W+gnc21Gk4wtYZRU=; b=Dcke97I3Xf1R9wOrr0D7KOe97Lixb1Dngj32GCMPg6ofYp2vRngBYLjYH5f6Gax+5H 7z7JCGkCxwAZPCQy0VhUomyvulmWIzB964FDPzC2FPXvMo09SbDgwn6aW7KAgl2XZl7H IvRJ8Os9yQEc58xg1jUFFtXZoZfFs3xA+OvWphHXtKlY2k/T2JfQYpJw7DwJai1tRzEy Cnyc+dIpp9VUCtf1AqR2Em49BDLkyGeuh5AfNkHFN27dS5FsPXtSDvp+SIZMVCWpSpYR Y0vBDqVgOBEFMn10Au98lYjJtjNuGeNtSYILkPALZ9+6ZAV+CVh+5D+G7CRW50mgBYb0 84Lw== 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:x-gm-message-state:from:to:cc:subject:date; bh=k7YNCe9q93GJKQLNbQn4DCcTE32W+gnc21Gk4wtYZRU=; b=Y3c8dn59cj786vD5CffOAlaHA0BlLIn0sSTB9C1pmW9/XqMByrwSgnzEdxNJVvQ8DJ eqdp0Rbkbq3Yzp76eW0Bkyyn0OiQI2La3E7tm+SS7DWnHXDPv2SMpWCuiPbXABU0taaR z7l30o61SoSbvj1JyUikFY1HD4OgXEmq6HOkfpuJL+pti0SPGtKItH6A35g6w48fdjF/ 6wkth3GFip+pxYgwoAP5K/X0RW66+tEbym7dVSBbvodxyH8Qc4fJXNGkZxBiKJ//JLb+ CtF820bjv8yS5kxGGLBq+nTIBC9la23US5HTbatmPXVGje8ufq9s99ItCLM62I0eSmXh mm2Q== X-Gm-Message-State: ACrzQf0rkedXEbrdIjMvbPy+6kcG04g1aPBuiM/vPHnC/RHPOuTEoghx mJZZLOUIHTCGQeLMuI33efLEnNdmJ2y/u+qe X-Google-Smtp-Source: AMsMyM5mFgtlY/T/tC3v8QhzTx5cd0v4PZoci7DL5mnWVsX73MBOIpR8vrJk1gQoMU+JJ0vlGWwS5KG3c53yqe52 X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:a09:b0:202:ab93:2afb with SMTP id o9-20020a17090a0a0900b00202ab932afbmr7459241pjo.60.1663200295926; Wed, 14 Sep 2022 17:04:55 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:42 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-3-vannapurve@google.com> Subject: [V2 PATCH 2/8] KVM: selftests: Add arch specific initialization From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Introduce arch specific API: kvm_selftest_arch_init to allow each arch to handle initialization before running any selftest logic. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve Reviewed-by: Andrew Jones --- .../selftests/kvm/include/kvm_util_base.h | 5 +++++ .../selftests/kvm/lib/aarch64/processor.c | 18 +++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 2 ++ .../selftests/kvm/lib/riscv/processor.c | 4 ++++ .../selftests/kvm/lib/s390x/processor.c | 4 ++++ .../selftests/kvm/lib/x86_64/processor.c | 4 ++++ 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 24fde97f6121..98edbbda9f97 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -834,4 +834,9 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm) return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0); } +/* + * API to execute architecture specific setup before executing selftest logic. + */ +void kvm_selftest_arch_init(void); + #endif /* SELFTEST_KVM_UTIL_BASE_H */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 6f5551368944..2281d6c5d02f 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -495,15 +495,6 @@ void aarch64_get_supported_page_sizes(uint32_t ipa, close(kvm_fd); } -/* - * arm64 doesn't have a true default mode, so start by computing the - * available IPA space and page sizes early. - */ -void __attribute__((constructor)) init_guest_modes(void) -{ - guest_modes_append_default(); -} - void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, struct arm_smccc_res *res) @@ -528,3 +519,12 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); } + +/* + * arm64 doesn't have a true default mode, so start by computing the + * available IPA space and page sizes early. + */ +void kvm_selftest_arch_init(void) +{ + guest_modes_append_default(); +} diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 3c83838999f5..dafe4471a6c7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1984,4 +1984,6 @@ void __attribute((constructor)) kvm_selftest_init(void) { /* Tell stdout not to buffer its content. */ setbuf(stdout, NULL); + + kvm_selftest_arch_init(); } diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index 604478151212..26660dd2ba78 100644 --- a/tools/testing/selftests/kvm/lib/riscv/processor.c +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -362,3 +362,7 @@ void vcpu_args_set(struct kvm_vcpu *vcpu, unsigned int num, ...) void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) { } + +void kvm_selftest_arch_init(void) +{ +} diff --git a/tools/testing/selftests/kvm/lib/s390x/processor.c b/tools/testing/selftests/kvm/lib/s390x/processor.c index 89d7340d9cbd..8654ec74009a 100644 --- a/tools/testing/selftests/kvm/lib/s390x/processor.c +++ b/tools/testing/selftests/kvm/lib/s390x/processor.c @@ -218,3 +218,7 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent) void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) { } + +void kvm_selftest_arch_init(void) +{ +} diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 2e6e61bbe81b..20bf125f9363 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1311,3 +1311,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) return val == 'Y'; } + +void kvm_selftest_arch_init(void) +{ +} From patchwork Thu Sep 15 00:04:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976702 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 F30A6C6FA89 for ; Thu, 15 Sep 2022 00:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiIOAFI (ORCPT ); Wed, 14 Sep 2022 20:05:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiIOAFB (ORCPT ); Wed, 14 Sep 2022 20:05:01 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6493611830 for ; Wed, 14 Sep 2022 17:04:59 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id a33-20020a630b61000000b00429d91cc649so8067003pgl.8 for ; Wed, 14 Sep 2022 17:04:59 -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:from:to:cc:subject:date; bh=M8kjUtGppue3sjuZ1ccxnaotzaKgHdRhRoDLnPEs3wQ=; b=QYYv9pYmzjZ/GZ3xfR1ckqaEiTUNUkkDbO5nicDoIofbwRX6en04HfwXpqyQTrendu UFRuKwNh9pZTFaQ9FdJQnxKwa/ciSv27IWRy+I20b/qulZ9ESDP6+38Z4GA3ulqiOitj +Vn6QVqxEnGGf58xvRPpvEp9bp5hJA5uEaL1Jvw/w0hFGShyI+YpVKP4EGEmpNOCAC5+ XeMgGo3aC3gGy/SZp2yl5KAQfUWgMHbKXmXWv/xS4hNC9rFLrJvfkmocTj6E+L/wKFvn LN70iu2ioUthiueAD6BNs8/oPDM066Rk9klz3yaVKSJP5jO+6ewEMmrmr8ym6eYDOmKm 8Knw== 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:x-gm-message-state:from:to:cc:subject:date; bh=M8kjUtGppue3sjuZ1ccxnaotzaKgHdRhRoDLnPEs3wQ=; b=pMEyKya2ghv3gDbHvP59scgCKJnsYKr+/nc580MbEmP+ebVPiL2Tm6BTqlmzib630P F5bDARjWSc/HDVNdUFbNvE3oIwMz+uGbtN4gDXN40/4P8ga6koTJ7HVG4AFgOsVOYX5Q rh9B13j7oYo+cL8qcy6CDoqERK0Ea9+Sjq28uSQs2rXFlJNVaA/9cVsqJFcy+dFZGL55 +Hl+cW1ZrEMYt+gnDN/TXVHCJs6BmFrnF1iCdEE8sbcoHUrs0tmckBTEp57eH6VsRUwq ONEitQYR0eGAilrTJPrGNoS4rMGG0I3/VsGEAu6Vypv9ELdSYLMRZkwlUt+wj2SD5t4t oCeg== X-Gm-Message-State: ACrzQf2j2h82Wj+AA5Yb1T6KbfCpSLAc7+z5Sv5KT/a+QiiV/RCMg1IE Inkm7R1F2WAwIP+uwcG8r1E44Pwlst07JsK5 X-Google-Smtp-Source: AMsMyM7kpC1GcEfVUy7HRZqDlom1iprzgk4MNlOV/yHhpR0p7r9yl2PDuDr3EXP93iobRxxYxtQu2BGb86gCVUBN X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:64c8:b0:202:6d4a:90f8 with SMTP id i8-20020a17090a64c800b002026d4a90f8mr7698135pjm.11.1663200298705; Wed, 14 Sep 2022 17:04:58 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:43 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-4-vannapurve@google.com> Subject: [V2 PATCH 3/8] KVM: selftests: Add arch specific post vm load setup From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add arch specific API kvm_selftest_post_vm_elf_load to possibly communicate information to VM that is already known to selftest VMM logic. This API will be used in followup commit to convey cpu vendor type to the guest vm. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/include/kvm_util_base.h | 4 ++++ tools/testing/selftests/kvm/lib/aarch64/processor.c | 4 ++++ tools/testing/selftests/kvm/lib/elf.c | 2 ++ tools/testing/selftests/kvm/lib/riscv/processor.c | 4 ++++ tools/testing/selftests/kvm/lib/s390x/processor.c | 4 ++++ tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 ++++ 6 files changed, 22 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 98edbbda9f97..73cfee3ebd76 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -839,4 +839,8 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm) */ void kvm_selftest_arch_init(void); +/* + * API to execute architecture specific setup after loading the vm elf. + */ +void kvm_arch_post_vm_elf_load(struct kvm_vm *vm); #endif /* SELFTEST_KVM_UTIL_BASE_H */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c index 2281d6c5d02f..12627c560f66 100644 --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c @@ -528,3 +528,7 @@ void kvm_selftest_arch_init(void) { guest_modes_append_default(); } + +void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) +{ +} diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c index 9f54c098d9d0..b8963a7146ce 100644 --- a/tools/testing/selftests/kvm/lib/elf.c +++ b/tools/testing/selftests/kvm/lib/elf.c @@ -189,4 +189,6 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename) phdr.p_filesz); } } + + kvm_arch_post_vm_elf_load(vm); } diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c index 26660dd2ba78..4491c0d4be45 100644 --- a/tools/testing/selftests/kvm/lib/riscv/processor.c +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c @@ -366,3 +366,7 @@ void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) void kvm_selftest_arch_init(void) { } + +void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) +{ +} diff --git a/tools/testing/selftests/kvm/lib/s390x/processor.c b/tools/testing/selftests/kvm/lib/s390x/processor.c index 8654ec74009a..332501b3693f 100644 --- a/tools/testing/selftests/kvm/lib/s390x/processor.c +++ b/tools/testing/selftests/kvm/lib/s390x/processor.c @@ -222,3 +222,7 @@ void assert_on_unhandled_exception(struct kvm_vcpu *vcpu) void kvm_selftest_arch_init(void) { } + +void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) +{ +} diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 20bf125f9363..25ae972f5c71 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1315,3 +1315,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) void kvm_selftest_arch_init(void) { } + +void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) +{ +} From patchwork Thu Sep 15 00:04:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976703 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 3BCCCECAAD3 for ; Thu, 15 Sep 2022 00:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbiIOAFQ (ORCPT ); Wed, 14 Sep 2022 20:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbiIOAFH (ORCPT ); Wed, 14 Sep 2022 20:05:07 -0400 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 E229713EA7 for ; Wed, 14 Sep 2022 17:05:01 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id g63-20020a636b42000000b004305794e112so8192081pgc.20 for ; Wed, 14 Sep 2022 17:05:01 -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:from:to:cc:subject:date; bh=rhI1CHpHnoLTF9sMnY1velsatE7KzqpaHm2Zg/NlpWU=; b=csQ+wHtL/4fYR6KUnDudrTc0f7rZcbdEOOHzeTVhZIgqP16I2UHMCa4nKJvwkDmIa1 04EiDNsGGYsa/ZoenTCo4pyTo5zKHaBi91efe9OaAlNaRgO+snXtratc/rVMkxsvUMAp 31VMO3yfzfh6Cm4pENS/+J5g+8gNzyc0ln9enq47YOyqB9UBPrN61cTtiZFrII4Zm9dK uveTLe0u+t73xwiUy8LdyI3z8CSL2y+7uHVWryjbrvAmMzs+ImrIt3aSe3KOP9StVKdb rd0EjF6Ab8sNMS2PV4Ir+kXJLtvty5YMcWkjdEe9vCJ0JX+Qgw9g7PeYKlpbOg1nAy/X 0K0w== 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:x-gm-message-state:from:to:cc:subject:date; bh=rhI1CHpHnoLTF9sMnY1velsatE7KzqpaHm2Zg/NlpWU=; b=y7+rfZaofw/rFpTWTo0/XBiEFeJ6hu/EqGInFUIB+ehuAcbVcYbwi0y76kx+34Ns/h YV0TutNkynfBOKFWUBN5+w3mYL1MfT4CnJaI0MCwsc23psDTZqiOx7vPQtYTDrZqLO+f gCVYHYZHEJMjdkvxP1ZunHVmNsbRb6wVrTkn7w8Y1xp6Sn78gAdK3evro8OWsFEOR4v1 BmFIGjyWzMilIheXvGx9cYerxacPo5s+3LzfJFLicoal+2/3FsIu3hz9Ci6+WT+6vb7X wklLUG+yzH6OhTUR2UrViizrrjsnIbnpRc0gImYAjzQnXbBDlnE8L3UwjaoJ9ovGDCEs T3gw== X-Gm-Message-State: ACgBeo1apOi6ZwstG14eI6z58B+36+p4xQWFsbXqBlT7S2My0hSfeHIO S4PgabHkAk/j1kN7/srWD2h3GYvk7mQnTHuQ X-Google-Smtp-Source: AA6agR4J+7XJTDvy3acXZ7Xp5xXcYKJyhmTX7ZLEn97ViM70m/5htdtIvuFapGYGrwQDbuzUWFwXekmcH4/ukG+F X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a62:170b:0:b0:53b:93dc:966b with SMTP id 11-20020a62170b000000b0053b93dc966bmr40331680pfx.29.1663200301099; Wed, 14 Sep 2022 17:05:01 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:44 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-5-vannapurve@google.com> Subject: [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu() From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Cache the vendor CPU type in a global variable so that multiple calls to is_intel_cpu() do not need to re-execute CPUID. Add cpu vendor check in kvm_hypercall() so that it executes correct vmcall/vmmcall instruction when running on Intel/AMD hosts. This avoids exit to KVM which anyway tries to patch the instruction according to the cpu type. As part of this change, sync the global variable is_cpu_amd into the guest so the guest can determine which hypercall instruction to use without needing to re-execute CPUID for every hypercall. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- .../testing/selftests/kvm/lib/x86_64/processor.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 25ae972f5c71..c0ae938772f6 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -19,6 +19,7 @@ #define MAX_NR_CPUID_ENTRIES 100 vm_vaddr_t exception_handlers; +static bool is_cpu_amd; static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) { @@ -1019,7 +1020,7 @@ static bool cpu_vendor_string_is(const char *vendor) bool is_intel_cpu(void) { - return cpu_vendor_string_is("GenuineIntel"); + return (is_cpu_amd == false); } /* @@ -1027,7 +1028,7 @@ bool is_intel_cpu(void) */ bool is_amd_cpu(void) { - return cpu_vendor_string_is("AuthenticAMD"); + return (is_cpu_amd == true); } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) @@ -1182,9 +1183,15 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, { uint64_t r; - asm volatile("vmcall" + if (is_amd_cpu()) + asm volatile("vmmcall" : "=a"(r) : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3)); + else + asm volatile("vmcall" + : "=a"(r) + : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3)); + return r; } @@ -1314,8 +1321,10 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) void kvm_selftest_arch_init(void) { + is_cpu_amd = cpu_vendor_string_is("AuthenticAMD"); } void kvm_arch_post_vm_elf_load(struct kvm_vm *vm) { + sync_global_to_guest(vm, is_cpu_amd); } From patchwork Thu Sep 15 00:04:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976704 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 04C2CC6FA8A for ; Thu, 15 Sep 2022 00:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbiIOAFS (ORCPT ); Wed, 14 Sep 2022 20:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbiIOAFN (ORCPT ); Wed, 14 Sep 2022 20:05:13 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1F714D28 for ; Wed, 14 Sep 2022 17:05:03 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id ev16-20020a17090aead000b00202cf672e74so5213326pjb.2 for ; Wed, 14 Sep 2022 17:05:03 -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:from:to:cc:subject:date; bh=wHYZTxyAGx9pdQAcCVui/YtY/xjqmCAf1YOadQ9i5/0=; b=gbLFlFvPXtP6TXNby7OllfZ9N4HBF6G1L43fc4Iyjnuh9l317ciioiooS/FhMqHLcI FFKo6Z0gME9FS3RZehnMuA4D30ws/x4K2BjJX9bc0znkrZj8zpbGB7UY3B4K4X0CvWyM FJiWRAaN+ByVzFNcSny1fm6gDicZW0lxuK9ZCR5WFPnBDJlkXgcSF2TsRkwO/e/c7IGu wGST+xCaiKLMRvcU/MzTgaopt6pQg9/4jPgDFf6mHYb35cVpZz8AKZPYvwNpmULM+BdJ 2YtKC4D7RqyKl42lib3pvuhNdLzdzajQq3B1Kw9IvXbONPebg2i/hE1c/VzeQhTqlm2J A8oQ== 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:x-gm-message-state:from:to:cc:subject:date; bh=wHYZTxyAGx9pdQAcCVui/YtY/xjqmCAf1YOadQ9i5/0=; b=Fbu2IGgDpvU5jT3tdDuwLp5aIZS+RVG2+5y1njfeFfE8eLcqNoZ7BesSR4okRnab6y zrs0DA0mN7YOKcOPqZ5vzbej9qahU8lkxxK2V3mQGqteZ+4WAFdh6CEJpIryc1NCfvBw CM0hr84sDFA2iLu8nYAl5EfyO5UjdJHFeeAyx1Go0LRjf6bxF8hZJ1Lo2HGmmgq+iC/8 NQ4ym/6zNKeV2WO0nOzQ8QmZgMglbDgNlEZ76s7BWXB1fRiAU/z5QFnMrF5tUNMSs+3N IfHee3Oz31JSvtdyLi2943lK59DygOb9G1444XIY5Rlki06DfAKEnm10wO5JP1yHpN9S +ZIg== X-Gm-Message-State: ACrzQf3lT9rNmeHi+eDuEwYENdoR57F3vR9ZwWDfWKXszyFma4J9e9dS ovEei8zxhmt0iGfCjPpmJjaVX6zA6bLsTCgq X-Google-Smtp-Source: AMsMyM686KHHkmbDSKxbFztZuMtfsUvL0/uqvmJDi1n43H4qJ3FJxBZEQdoaI3e9i1dqLmxjW4nSzzFmdrcbYO4H X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90b:1bc4:b0:202:fbd0:8e86 with SMTP id oa4-20020a17090b1bc400b00202fbd08e86mr7603861pjb.52.1663200303049; Wed, 14 Sep 2022 17:05:03 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:45 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-6-vannapurve@google.com> Subject: [V2 PATCH 5/8] KVM: selftests: x86: delete svm_vmcall_test From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org svm_vmcall_test is superseded by fix_hypercall_test. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/.gitignore | 1 - .../selftests/kvm/x86_64/svm_vmcall_test.c | 74 ------------------- 2 files changed, 75 deletions(-) delete mode 100644 tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index d625a3f83780..22e9a5b5488c 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -36,7 +36,6 @@ /x86_64/sev_migrate_tests /x86_64/smm_test /x86_64/state_test -/x86_64/svm_vmcall_test /x86_64/svm_int_ctl_test /x86_64/svm_nested_soft_inject_test /x86_64/sync_regs_test diff --git a/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c b/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c deleted file mode 100644 index c3ac45df7483..000000000000 --- a/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * svm_vmcall_test - * - * Copyright (C) 2020, Red Hat, Inc. - * - * Nested SVM testing: VMCALL - */ - -#include "test_util.h" -#include "kvm_util.h" -#include "processor.h" -#include "svm_util.h" - -static void l2_guest_code(struct svm_test_data *svm) -{ - __asm__ __volatile__("vmcall"); -} - -static void l1_guest_code(struct svm_test_data *svm) -{ - #define L2_GUEST_STACK_SIZE 64 - unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; - struct vmcb *vmcb = svm->vmcb; - - /* Prepare for L2 execution. */ - generic_svm_setup(svm, l2_guest_code, - &l2_guest_stack[L2_GUEST_STACK_SIZE]); - - run_guest(vmcb, svm->vmcb_gpa); - - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL); - GUEST_DONE(); -} - -int main(int argc, char *argv[]) -{ - struct kvm_vcpu *vcpu; - vm_vaddr_t svm_gva; - struct kvm_vm *vm; - - TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); - - vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); - - vcpu_alloc_svm(vm, &svm_gva); - vcpu_args_set(vcpu, 1, svm_gva); - - for (;;) { - volatile struct kvm_run *run = vcpu->run; - struct ucall uc; - - vcpu_run(vcpu); - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", - run->exit_reason, - exit_reason_str(run->exit_reason)); - - switch (get_ucall(vcpu, &uc)) { - case UCALL_ABORT: - REPORT_GUEST_ASSERT(uc); - /* NOT REACHED */ - case UCALL_SYNC: - break; - case UCALL_DONE: - goto done; - default: - TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); - } - } -done: - kvm_vm_free(vm); - return 0; -} From patchwork Thu Sep 15 00:04:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976705 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 4667AC6FA82 for ; Thu, 15 Sep 2022 00:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbiIOAFa (ORCPT ); Wed, 14 Sep 2022 20:05:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbiIOAFQ (ORCPT ); Wed, 14 Sep 2022 20:05:16 -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 891D912613 for ; Wed, 14 Sep 2022 17:05:05 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id q6-20020a17090311c600b0017266460b8fso11330528plh.4 for ; Wed, 14 Sep 2022 17:05:05 -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:from:to:cc:subject:date; bh=+j6ja5Y8ST1lkDCiHrGAifRKnD79hDMFlzwZSvjPxXQ=; b=QAWMMruvJue7fpk0q7rTxhmv1/nR3Btqv60serdgaAQxfhYBAxwMMmes1d1aDaLBMp QwMgBZ94purcmy+hVuYnwJv/mXEGJbfACNNBBaeL4luhK0ffVSg3oma2uevdZlV+kbqd OZVQZ92W6KmhRRWqfHKH1NCqhewjZ+PBclCtDjC4YakhZarYeaDdupySzq7VrwGUDPjN RBf8u9GsN7Gft1zyCdOgqtITbTQuFVWpSl7Yu/Mdojry7AB6EV14qiFPUcfPMwOHe9WN xtCWOkpfvaAFkuzTkIMgj7f91fUb7uaclz0xrypu7H7cR1qpBV3fPafl94OHMyDkUAU9 Ve+w== 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:x-gm-message-state:from:to:cc:subject:date; bh=+j6ja5Y8ST1lkDCiHrGAifRKnD79hDMFlzwZSvjPxXQ=; b=t7YfpAW/AV3I2ly/O1jaaehXeX3Oii9JQoDL4dRX1wSXCRoELTPE8jTAhxq9q3lCu8 KHNWxzhoIXyHCAwrdYI61vtFiMfbg2Jfjto4wtHtBI3uXGvZQQ97O4J1jTHw3DTnhVgu IrLif6o+vkB1YI+tglMwof/ZSjUuqP1+hJHu9n+EQzY61sthZKuo6KQf8oUVTuB+jLT2 yyCo5r7bGWY7aqc1NrkH7U2+jkMJyqLfHMA61mQmwrsZzgLKrR2VMzNCaisZRr6R75Q/ 7CcbZTFEKNWQ2RfxMq8zI/HQTMWQhZ68JphtNUnpXpRTbvvOb0rivhyDk/scgQRMv4Ld uwiA== X-Gm-Message-State: ACrzQf0nz9X0iet/JPOYOwWdf+wxvuZty68VTyZ/UBH3aGrNUaKomyXA 9d4iy7lPzN9ArYIz4i36OUxUQ34auybB3PHz X-Google-Smtp-Source: AMsMyM6lGW2/ydAIfjak7HAJ8xIaVLtWwyvqLD3KhxTIabn7lIHH9YeU5ohRTlyX27Z0FalUC+VoD/qjyrMbVsYr X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:903:2445:b0:178:38ee:70f with SMTP id l5-20020a170903244500b0017838ee070fmr1495757pls.164.1663200305003; Wed, 14 Sep 2022 17:05:05 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:46 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-7-vannapurve@google.com> Subject: [V2 PATCH 6/8] KVM: selftests: x86: Execute cpu specific hypercall from nested guests From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Execute vmcall/vmmcall from nested guests according to the cpu type. This avoid exit to KVM which would anyway patch the hypercall instruction according to the cpu type. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- .../selftests/kvm/include/x86_64/processor.h | 2 ++ tools/testing/selftests/kvm/include/x86_64/vmx.h | 9 --------- .../selftests/kvm/lib/x86_64/perf_test_util.c | 2 +- .../testing/selftests/kvm/lib/x86_64/processor.c | 15 +++++++++++++++ tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/state_test.c | 8 ++++---- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 +- .../kvm/x86_64/vmx_preemption_timer_test.c | 2 +- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 0cbc71b7af50..18a8a6a2b786 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -833,6 +833,8 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); +void nested_guest_vmcall(void); + void __vm_xsave_require_permission(int bit, const char *name); #define vm_xsave_require_permission(perm) \ diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h index 99fa1410964c..d8d4fd3353e5 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -480,15 +480,6 @@ static inline int vmresume(void) return ret; } -static inline void vmcall(void) -{ - /* Currently, L1 destroys our GPRs during vmexits. */ - __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : : - "rax", "rbx", "rcx", "rdx", - "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", - "r13", "r14", "r15"); -} - static inline int vmread(uint64_t encoding, uint64_t *value) { uint64_t tmp; diff --git a/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c b/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c index 0f344a7c89c4..b420b35b7f45 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c @@ -18,7 +18,7 @@ void perf_test_l2_guest_code(uint64_t vcpu_id) { perf_test_guest_code(vcpu_id); - vmcall(); + nested_guest_vmcall(); } extern char perf_test_l2_guest_entry[]; diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index c0ae938772f6..e12c8b543b8f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1195,6 +1195,21 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, return r; } +void nested_guest_vmcall(void) +{ + /* Currently, L1 destroys our GPRs during vmexits. */ + if (is_amd_cpu()) + __asm__ __volatile__("push %%rbp; vmmcall; pop %%rbp" : : : + "rax", "rbx", "rcx", "rdx", + "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", + "r13", "r14", "r15"); + else + __asm__ __volatile__("push %%rbp; vmcall; pop %%rbp" : : : + "rax", "rbx", "rcx", "rdx", + "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", + "r13", "r14", "r15"); +} + const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void) { static struct kvm_cpuid2 *cpuid; diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/selftests/kvm/x86_64/smm_test.c index 1f136a81858e..bf04c78c9c8e 100644 --- a/tools/testing/selftests/kvm/x86_64/smm_test.c +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c @@ -61,7 +61,7 @@ static void l2_guest_code(void) sync_with_host(10); - vmcall(); + nested_guest_vmcall(); } static void guest_code(void *arg) diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testing/selftests/kvm/x86_64/state_test.c index ea578971fb9f..a9634c06dc60 100644 --- a/tools/testing/selftests/kvm/x86_64/state_test.c +++ b/tools/testing/selftests/kvm/x86_64/state_test.c @@ -26,10 +26,10 @@ void svm_l2_guest_code(void) { GUEST_SYNC(4); /* Exit to L1 */ - vmcall(); + nested_guest_vmcall(); GUEST_SYNC(6); /* Done, exit to L1 and never come back. */ - vmcall(); + nested_guest_vmcall(); } static void svm_l1_guest_code(struct svm_test_data *svm) @@ -57,7 +57,7 @@ void vmx_l2_guest_code(void) GUEST_SYNC(6); /* Exit to L1 */ - vmcall(); + nested_guest_vmcall(); /* L1 has now set up a shadow VMCS for us. */ GUEST_ASSERT(vmreadz(GUEST_RIP) == 0xc0ffee); @@ -70,7 +70,7 @@ void vmx_l2_guest_code(void) GUEST_SYNC(12); /* Done, exit to L1 and never come back. */ - vmcall(); + nested_guest_vmcall(); } static void vmx_l1_guest_code(struct vmx_pages *vmx_pages) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c index 2d8c23d639f7..fa24e69a806c 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c @@ -42,7 +42,7 @@ static void l2_guest_code(void) GUEST_SYNC(false); /* Exit to L1 and never come back. */ - vmcall(); + nested_guest_vmcall(); } void l1_guest_code(struct vmx_pages *vmx) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c index 0efdc05969a5..04bae6995344 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c @@ -38,7 +38,7 @@ void l2_guest_code(void) { u64 vmx_pt_delta; - vmcall(); + nested_guest_vmcall(); l2_vmx_pt_start = (rdtsc() >> vmx_pt_rate) << vmx_pt_rate; /* From patchwork Thu Sep 15 00:04:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976707 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 A3350C6FA82 for ; Thu, 15 Sep 2022 00:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbiIOAGB (ORCPT ); Wed, 14 Sep 2022 20:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbiIOAF2 (ORCPT ); Wed, 14 Sep 2022 20:05:28 -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 EFF721EC68 for ; Wed, 14 Sep 2022 17:05:08 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id p18-20020a170902a41200b00172b0dc71e0so11325791plq.0 for ; Wed, 14 Sep 2022 17:05:08 -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:from:to:cc:subject:date; bh=EMYMZKY/iGQIa3JbZzMfxs2+dRoXVRV6AgQCLEGivNg=; b=SKQoQmMvyzj6768UP8KES0UGW6Xnv8ko48tcNOa6IbyMbxEl0YhsbKvyqMLfnSaKfl deamK916iD3NTrVLtCTkm12Mv7J4/xB1kIrgbMi9hhIffdeFRoCzrWSIQYxOSIrpdqDy FAFvWUQ75HUlqniZBOVcm6JWob7h/iMO5UG3XpEMd6rsI9Ys+aKQn5rIo/oz57fi8U5q 7baFSeo3wuk/mDAvJr83FVxbC3b9OrDhqZ/d+A21HRcKBJ2Cp+Xi4YswGI6HDC1XEvrJ kC0iT1x24CvvdmzG1pH8lV3gvkiYgvegubznE1s69M3M7DSi2owSwCB7NxRTWudJzuEA CCmA== 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:x-gm-message-state:from:to:cc:subject:date; bh=EMYMZKY/iGQIa3JbZzMfxs2+dRoXVRV6AgQCLEGivNg=; b=lGc4t3kBqJf6FYfx9kB/FD/8gvB2wfHnoCrLwQ4n52J4TsDeOKbezMjmlp14F1NoKu N85wJZFr4YONHJXuadfkxok0fNqvQ3UzD85jng+Fzzl84c/SBVJ2GkIagYO2oPQ6M65o zKvxqgkhvMOzulZjIQoQI8hqEgzVG+sojpDrgSFA+PYDSmX0jOdHaC/U+FxHV6A3p2r6 YMTmB9vtvNCVQHJIP8xVD/kThoUHIncrjLAQdlo4SzpfR/ZqQr/eK2xDL4V2J3XIiKZJ ecsVHzFNg3cU+MbQtIJnrJaFDc44sgQqpWmMfRooVVkKsxraWE2+Mk+ing0VE6g6JeGQ S2Rw== X-Gm-Message-State: ACgBeo2BtoUl5gVm5cpk6o0CviGEgM/4dnwLjVTYdiBIGcVMCqKl8N43 CDdlM7tLAHVJSBTV/EunLuddvELJoszxHxBw X-Google-Smtp-Source: AA6agR7/1ZFORcwZpWMCn29kzEp4zuJU5BpWSxKndEtwG7dvrtDU8Qy27Oa7QgaBUKG4z97q+TmmbVu7qdC22psN X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a63:8843:0:b0:439:3c8e:c2c0 with SMTP id l64-20020a638843000000b004393c8ec2c0mr9651931pgd.404.1663200307191; Wed, 14 Sep 2022 17:05:07 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:47 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-8-vannapurve@google.com> Subject: [V2 PATCH 7/8] Kvm: selftests: x86: Execute cpu specific vmcall instruction From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Update the vmcall instruction invocation to happen according to the cpu type. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/include/x86_64/processor.h | 8 ++++++++ tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c | 2 +- .../selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 18a8a6a2b786..74893a7a80f8 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -833,6 +833,14 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); +/* + * Execute vmcall instruction. + */ +static inline void vmcall(void) +{ + kvm_hypercall(0, 0, 0, 0, 0); +} + void nested_guest_vmcall(void); void __vm_xsave_require_permission(int bit, const char *name); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c index 5abecf06329e..8180711c8684 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c @@ -31,7 +31,7 @@ static void l2_guest_code(void) { /* Exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages, unsigned long high_gpa) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c index 465a9434d61c..37da9d01d5d6 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c @@ -76,7 +76,7 @@ static void l2_guest_code(void) check_tsc_freq(UCHECK_L2); /* exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c index 5943187e8594..00192f564d9b 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c @@ -74,7 +74,7 @@ static void l2_guest_code(void) check_ia32_tsc_adjust(-2 * TSC_ADJUST_VALUE); /* Exit to L1 */ - __asm__ __volatile__("vmcall"); + vmcall(); } static void l1_guest_code(struct vmx_pages *vmx_pages) From patchwork Thu Sep 15 00:04:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 12976706 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 EA205C6FA82 for ; Thu, 15 Sep 2022 00:05:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbiIOAFs (ORCPT ); Wed, 14 Sep 2022 20:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiIOAFS (ORCPT ); Wed, 14 Sep 2022 20:05:18 -0400 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 AC0B41CB04 for ; Wed, 14 Sep 2022 17:05:10 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id 133-20020a62198b000000b00540c0148c95so9904531pfz.14 for ; Wed, 14 Sep 2022 17:05:10 -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:from:to:cc:subject:date; bh=VuGMu9KefmyqggOIb8+6b807AZCZLCiLPgbgKLQtbrg=; b=J1nVhlMnXZ1DpLHMM7P54DQ0isb5j+fwUWjtzHYgJQrw12+CNbm2umPpgAhPFrGzr+ oI/eNFfmDwPTbpK1hmu9ejIKig1lPufMvGy70Lpui6ulazQWjBxj8gOmHqcChSbvbCgt l6CE+bSu0XA9BQoAIWofM3MmaPcEZGm/3w/58oPCSmtepDrH6HHxuLQq4JJJMdXaYc0/ EVvs2B/ZpVMNZO4l1ITqhNZvhHW9rEBSNSutb6NBCB/Sn9MjvNhHzxxu1egVysk8mm7T Mhp8wAnzY8L8VChogte06baw2mJW5gXvGxJJYWtAs0u+di4QrJMsuUoVc+lzEGjrlNdo QXgQ== 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:x-gm-message-state:from:to:cc:subject:date; bh=VuGMu9KefmyqggOIb8+6b807AZCZLCiLPgbgKLQtbrg=; b=Vgcq1p//NdYEWi5vr5+np7MN7whLdj2Lwf142/8PIdkvWBEIotZvzfqkmU8LGGDPwZ 3lGEMk2lA5J44AV59EkuHufb/4z5yXMXKMUlUWaq/sRSFMYF46vMpMe5OtlC8AscXNzD qSIzcVvjdNbdfCPO+QCzx+iPXG7a1l0AYM+a/qyRh5Uj6TC9/g/dnk3jgg8GZuMfDyFG UI+NUgRptar+nQxcyrz72R+aTNuPJQhZt0G4HSXt8YclPY+DoHWM4qUmvLhojRYDKCnF BFj+LH11gDJhVwL/k5mq/VODvPUSlSNa+IWaziNOdUwAtYJh2G8XPPDpE5rYWe6fcPx9 eKoA== X-Gm-Message-State: ACrzQf3f9rcxUuLglxWcKUR3nzky6WtVDZJYbpYYd1ULT+ISUE46WgMa rtYGiVx8y8KsyzetiCup21CpAeKwtNq0eFhK X-Google-Smtp-Source: AMsMyM6OElpGuFNQtEUj0prB/t19M02Jd8yvrXuYDoyqbkNPWUazfGaW2kr67T9YfCE+r5BgbHpNF4h2v5map84w X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90b:4b05:b0:202:b76e:a274 with SMTP id lx5-20020a17090b4b0500b00202b76ea274mr7496906pjb.59.1663200309463; Wed, 14 Sep 2022 17:05:09 -0700 (PDT) Date: Thu, 15 Sep 2022 00:04:48 +0000 In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com> Mime-Version: 1.0 References: <20220915000448.1674802-1-vannapurve@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915000448.1674802-9-vannapurve@google.com> Subject: [V2 PATCH 8/8] KVM: selftests: x86: xen: Execute cpu specific vmcall instruction From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com, seanjc@google.com, oupton@google.com, peterx@redhat.com, vkuznets@redhat.com, dmatlack@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Update xen specific hypercall invocation to execute cpu specific vmcall instructions. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- .../selftests/kvm/x86_64/xen_shinfo_test.c | 64 +++++++------------ .../selftests/kvm/x86_64/xen_vmcall_test.c | 14 ++-- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index 8a5cb800f50e..92ed07f1c772 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -145,6 +145,23 @@ static void guest_wait_for_irq(void) guest_saw_irq = false; } +static unsigned long vmcall_helper(unsigned long reg_a, unsigned long reg_di, + unsigned long reg_si) +{ + unsigned long ret; + + if (is_amd_cpu()) + __asm__ __volatile__ ("vmmcall" : + "=a" (ret) : + "a" (reg_a), "D" (reg_di), "S" (reg_si)); + else + __asm__ __volatile__ ("vmcall" : + "=a" (ret) : + "a" (reg_a), "D" (reg_di), "S" (reg_si)); + + return ret; +} + static void guest_code(void) { struct vcpu_runstate_info *rs = (void *)RUNSTATE_VADDR; @@ -217,12 +234,7 @@ static void guest_code(void) * EVTCHNOP_send hypercall. */ unsigned long rax; struct evtchn_send s = { .port = 127 }; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_event_channel_op), - "D" (EVTCHNOP_send), - "S" (&s)); - + rax = vmcall_helper(__HYPERVISOR_event_channel_op, EVTCHNOP_send, (unsigned long)&s); GUEST_ASSERT(rax == 0); guest_wait_for_irq(); @@ -232,12 +244,7 @@ static void guest_code(void) /* Deliver "outbound" event channel to an eventfd which * happens to be one of our own irqfds. */ s.port = 197; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_event_channel_op), - "D" (EVTCHNOP_send), - "S" (&s)); - + rax = vmcall_helper(__HYPERVISOR_event_channel_op, EVTCHNOP_send, (unsigned long)&s); GUEST_ASSERT(rax == 0); guest_wait_for_irq(); @@ -245,10 +252,7 @@ static void guest_code(void) GUEST_SYNC(13); /* Set a timer 100ms in the future. */ - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_set_timer_op), - "D" (rs->state_entry_time + 100000000)); + rax = vmcall_helper(__HYPERVISOR_set_timer_op, (rs->state_entry_time + 100000000), 0); GUEST_ASSERT(rax == 0); GUEST_SYNC(14); @@ -271,36 +275,21 @@ static void guest_code(void) .timeout = 0, }; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_sched_op), - "D" (SCHEDOP_poll), - "S" (&p)); - + rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p); GUEST_ASSERT(rax == 0); GUEST_SYNC(17); /* Poll for an unset port and wait for the timeout. */ p.timeout = 100000000; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_sched_op), - "D" (SCHEDOP_poll), - "S" (&p)); - + rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p); GUEST_ASSERT(rax == 0); GUEST_SYNC(18); /* A timer will wake the masked port we're waiting on, while we poll */ p.timeout = 0; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_sched_op), - "D" (SCHEDOP_poll), - "S" (&p)); - + rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p); GUEST_ASSERT(rax == 0); GUEST_SYNC(19); @@ -309,12 +298,7 @@ static void guest_code(void) * actual interrupt, while we're polling on a different port. */ ports[0]++; p.timeout = 0; - __asm__ __volatile__ ("vmcall" : - "=a" (rax) : - "a" (__HYPERVISOR_sched_op), - "D" (SCHEDOP_poll), - "S" (&p)); - + rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p); GUEST_ASSERT(rax == 0); guest_wait_for_irq(); diff --git a/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c b/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c index 88914d48c65e..e78f1b5d3af8 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c @@ -37,10 +37,16 @@ static void guest_code(void) register unsigned long r9 __asm__("r9") = ARGVALUE(6); /* First a direct invocation of 'vmcall' */ - __asm__ __volatile__("vmcall" : - "=a"(rax) : - "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), - "r"(r10), "r"(r8), "r"(r9)); + if (is_amd_cpu()) + __asm__ __volatile__("vmmcall" : + "=a"(rax) : + "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), + "r"(r10), "r"(r8), "r"(r9)); + else + __asm__ __volatile__("vmcall" : + "=a"(rax) : + "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), + "r"(r10), "r"(r8), "r"(r9)); GUEST_ASSERT(rax == RETVALUE); /* Fill in the Xen hypercall page */