From patchwork Thu Oct 13 12:13:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 2034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp239803wrs; Thu, 13 Oct 2022 05:15:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5I/JEjhLrRv0ujT38eRgMc2bQSpyYFdbQ6UrpI8SbpmWvtoynolDfQwSUKz+bYRnf0F+Po X-Received: by 2002:a17:907:3d8f:b0:78d:b46e:eadd with SMTP id he15-20020a1709073d8f00b0078db46eeaddmr16734783ejc.277.1665663317384; Thu, 13 Oct 2022 05:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665663317; cv=none; d=google.com; s=arc-20160816; b=FOTKlHDUAIbtVgyRyCcvKFHKP1VEG7NmOrjVjXbKSFT1QqF0kLoyj9Wvrlef4hBsRc gqE4tAjwUyo6KV4T4v2aRWE1FwHNY4Vyz87EM9lhG0NPVnQAaBr1CDp2pHHZbZOC+zof KjtRTpOrItA5nrPJeFNMDaUYP9qgJUSKQIILt/PrX8NhZT0+/38yiQa4ku/eFKdYV5M/ rVJAuGYVyhAcJGgQY1fAJq8HsEUNspY9IFbdztrZNQ57yOLnhgBngxMVz3Ffbcd3fF7/ VKY2z3S3I0Qn/jVQJjmQ0tbBEfv38/tRWbweIUELMy6J4OJJ8MBdXd8hR3fLGZ16f07G hHpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Ha6GYXqOCdxk7Kwn26PWu14QdftbtUnZTnWvsuhKyeA=; b=Q/CQKev6miBA2hv5gBXI4O/i+KAOY+e0Nb6ri3HkFNPSNPoHr7JMvQhrmuMm+uY12C kh7sGd3cEnAwVseqqYCiAyQ+Yik1PtUEp+B1YiVq2U82lBjc2SuWfKkFK700pDfhBwEi LXhG/d/DldavinKYDWxgoXOa3xoAm2oG56wWO8LckQV2MyGGNswc0CJaCcwmC0GxstCW gu1516Gn+xWn5TecTNv5bWWaEYqGnk4gPRKTyZxetwpdDdKyVZPZgM78Tq58uZMtcgHU thle7/EyWGsUi87Suu5rVdgxVKgz+/KTt/gbA6pAsi4cK7NkRw4A5bUeFJZLwUEz//5w fvRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qi6xs+1D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf26-20020a0564021a5a00b004587e08bc14si17013756edb.508.2022.10.13.05.14.52; Thu, 13 Oct 2022 05:15:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qi6xs+1D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbiJMMNu (ORCPT + 99 others); Thu, 13 Oct 2022 08:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiJMMNr (ORCPT ); Thu, 13 Oct 2022 08:13:47 -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 29CFAF984F for ; Thu, 13 Oct 2022 05:13:44 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id p15-20020a170902e74f00b00181927a941fso1212546plf.17 for ; Thu, 13 Oct 2022 05:13:44 -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:message-id:reply-to; bh=Ha6GYXqOCdxk7Kwn26PWu14QdftbtUnZTnWvsuhKyeA=; b=qi6xs+1DmyJ+XBybmwxGghutK/vyh8MrXuZP2ndTxf6cRb8+TjU4GMhNFldA677yVz Rf0SCBRboTZI2pemoxW61pbGMK6ObK/hbhFwYIqLjFY7ty5HjlTEuQTES9hwXFQpRoHy 1FWH6ts/E+Y0/8eoOWVrMoXiY6RxmSsXtF9I2EZO86Oz34Ql1e9SxfMQkimC5elYlYE9 HfU+alIrI4QinOyiqgxBuM88Nod5g2+3CoYgzWnhqKJIvV+tuIhg5mtVGv7ZCvYig7Kl 50jiEmjAb/BjPbke1eFLV0JP28WuaBjLUqcOI5fNAP6pCSojeO4RNHFgXQYZkUa2BG2t WTrA== 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:message-id:reply-to; bh=Ha6GYXqOCdxk7Kwn26PWu14QdftbtUnZTnWvsuhKyeA=; b=uJqKeFjaIxW8G7vrpvL4qNlQkD/4cr+MQ4dB05aLCH6LiAqmktBTVOSy19Ij1d/mbi ecmUrFnJC1TWfRxkHtyDUyqRP60Tz0uRz3pP2rQtqL0jXg98z3Ay4a5UAALUtTDZDhO0 ikG3B1y2IEywPQbTpIphJ8bNSlHbhCDapIcztqoLIDRybrEySZ41ch3M+AxJ6V4N3Ond w5YcLUxQNm4ZFUfH+zKW4JJIYGVlpYbo9cJCfUd29ts5Etz4Gemo0HBxBSPvLfDsQ1me QP/Zj2UURqmwvmHMopvJT60CMmLwXrp8oJ4nyTQmcYqjS7HGUFjfSiQNxzFVRbrmQDsx PfgA== X-Gm-Message-State: ACrzQf3hWTVLjbcXd1ZX16+SFPQId3nXqIdQA1zaw1QwqX5n9LGQXz7v EWTcbwWhfwE6yG5S7CKOvsSBd5s9DXw7O5Gu X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a05:6a00:1306:b0:555:6d3f:11ed with SMTP id j6-20020a056a00130600b005556d3f11edmr35687794pfu.55.1665663224332; Thu, 13 Oct 2022 05:13:44 -0700 (PDT) Date: Thu, 13 Oct 2022 12:13:16 +0000 In-Reply-To: <20221013121319.994170-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221013121319.994170-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221013121319.994170-2-vannapurve@google.com> Subject: [V3 PATCH 1/4] 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 , Andrew Jones X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746574578724342573?= X-GMAIL-MSGID: =?utf-8?q?1746574578724342573?= 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 Reviewed-by: Peter Gonda --- 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 f1cb1627161f..37d7d144c74e 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2021,3 +2021,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 6f88da7e60be..18297b803159 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 Oct 13 12:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 2035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp239983wrs; Thu, 13 Oct 2022 05:15:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6yWV0qZqVJ2WJlbs3PS6T29EP2ZR/b8qHqDfB2JRgg61QP89fHDSa+g9sZT4oA/4w6STMF X-Received: by 2002:a05:6402:84d:b0:454:f41d:6ccf with SMTP id b13-20020a056402084d00b00454f41d6ccfmr30973066edz.129.1665663335957; Thu, 13 Oct 2022 05:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665663335; cv=none; d=google.com; s=arc-20160816; b=ZdS6xZC88uxTkFN9IwLA7XoxfZu9/s3Epj/M22wQB7xIgxlbwgtjavf90uDu42hRbi UVmzHdXfwNwu8CUNKZwGN1TQgs111TRt2tfh+50McQ2fZ/kQ7gwPejycQU+faaXHwyuA usUErQ8b0mbcvdsyNyIUfzN/VsjmE+IjUd2QfjT3HFD/tCqr7RB5gOcukbAx5oU663Ah YYeAvR1toxv9CcWWxWc+FXXxdBBDm27LAacKK710wXIh0pNQK3kalmHuXaW3y3ljC/X9 LpCEasF9sLPgtCFCGfSKZqfTgO5zsF81+fLlDSXyTux/2tV7eFVtyKFLFY4Bl9A6VrHn Hr9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=W0XCXGnUdg2SY4SlBEuTZRqi3g7wdYiLHgqiL1Ekay4=; b=A0Pm1A1S9HlpDCUJSN7DH+EVcbAB+CCseEKQqkbF/bTCV71loFSAXp3te1IUlbo1MO ti+wtK3NQvXS6pZ3/CtKYAqy1nKyKHxAfIEE5glUG79zeK+CS0D4AsHzJVXnSMG8Ts7t F5dxxJTeG/3bHT9YZNMOwhAgSxODNxHN5nRDSCvTdFc9uBk+S7LoVVFzFOC0BI/CYc/I gxwwGBSa2H7C12ITe6eUIc22K+1Lf7pFK1KH0G8or92Qm25yMrrLcUvVIQdfIth6ZmjK l4HPh7sFjtheoQ7li50RbWrCklWtrgi88hyLokOBeK5TU7s7wi1iY0tY9Ihhn2p0vb7Z YTkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qfuhOnPK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn2-20020a17090794c200b007823d2b20fdsi21035342ejc.219.2022.10.13.05.15.09; Thu, 13 Oct 2022 05:15:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qfuhOnPK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiJMMOB (ORCPT + 99 others); Thu, 13 Oct 2022 08:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbiJMMNu (ORCPT ); Thu, 13 Oct 2022 08:13:50 -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 2E833FAA79 for ; Thu, 13 Oct 2022 05:13:48 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id k19-20020a056a00135300b0054096343fc6so1129718pfu.10 for ; Thu, 13 Oct 2022 05:13:48 -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:message-id:reply-to; bh=W0XCXGnUdg2SY4SlBEuTZRqi3g7wdYiLHgqiL1Ekay4=; b=qfuhOnPKPiE9nOPmxpWDofvLE1v/HBJRVx5sRm7TU0Tq9N/cBxEHqYygbL24hz9fwH vaOHCNa0EkhEx5ahAJ0RSJX2N+1c3KnE5h5zZ0eT0owPqCHiM63pOMCY+oIa1VF/Prvg QHR/8vheeM6Vg+Ntpf1Dpc9PNamQMsjGygzXafnJ6oe6s67Qy5ed/c3Fb4tNRLru8kL5 5yPBFzhj+1Ls4aQOVOFNT9pALR7PyYRRzfKVXgCssZv4ppXlDZhtpvNXRoq+GoLXnkB9 thINxy5uzUKts0Rh/R+JS8TmGC8I+tx+X04TDfIbYMWfeWXvEn9qjct8JFigQFqXRSrC E/FA== 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:message-id:reply-to; bh=W0XCXGnUdg2SY4SlBEuTZRqi3g7wdYiLHgqiL1Ekay4=; b=MuVl6KMhDWxL/ElGoCzvElFWR5x5m1CXn5laTEkyp3RESw2uS5mV5n9Bnjhcnd9cX+ eEYUA1HbfkQfsjyg9vo+iIojJaFrMNoItKMXEvduzX8SdstCPAmRNwkER2nBunlE5wb7 Yfc1Xm7HaME1qEsDid8c0/usbNiCk1G2j0gdNiP0OknnNKcrBR33+xQQt0EXuk9jdAZT d64rASnn1cpMX+gNy7nhbXCPg+9n+PH5clbNljw536je42FTzX28DGKNH5d/W/z4l353 3V+YVR+16mSwFAmM1Kkoys02jhLPyucqCUVwvB3OYGW6KTvtDo342LsWhtgx/8EQMana WH/Q== X-Gm-Message-State: ACrzQf202+M6iu6wP+C6s0cnHWfwks8KsbZpUmShzhMltydg7ifAVw9E qMbTRx1AExCYNFThTfR4eyg381ZQSphoT/ea X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:902:f708:b0:178:9b70:310b with SMTP id h8-20020a170902f70800b001789b70310bmr33951512plo.65.1665663227656; Thu, 13 Oct 2022 05:13:47 -0700 (PDT) Date: Thu, 13 Oct 2022 12:13:17 +0000 In-Reply-To: <20221013121319.994170-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221013121319.994170-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221013121319.994170-3-vannapurve@google.com> Subject: [V3 PATCH 2/4] 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746574598308801202?= X-GMAIL-MSGID: =?utf-8?q?1746574598308801202?= 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 Reviewed-by: Peter Gonda --- .../selftests/kvm/include/kvm_util_base.h | 5 +++++ .../selftests/kvm/lib/aarch64/processor.c | 18 +++++++++--------- tools/testing/selftests/kvm/lib/kvm_util.c | 6 ++++++ 3 files changed, 20 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 e42a09cd24a0..eec0e4898efe 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -838,4 +838,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 main(). + */ +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..0de4aabc0c76 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"); } + +void kvm_selftest_arch_init(void) +{ + /* + * arm64 doesn't have a true default mode, so start by computing the + * available IPA space and page sizes early. + */ + 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 37d7d144c74e..deb4c731b9fa 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2022,8 +2022,14 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, } } +__weak void kvm_selftest_arch_init(void) +{ +} + void __attribute((constructor)) kvm_selftest_init(void) { /* Tell stdout not to buffer its content. */ setbuf(stdout, NULL); + + kvm_selftest_arch_init(); } From patchwork Thu Oct 13 12:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 2036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp240512wrs; Thu, 13 Oct 2022 05:16:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4m0/qB7mFcfeclOmauKVhfruNeqRgVd8T9ue+javYeP7VrI8PXBtZxNqoechZAisuxbw0c X-Received: by 2002:a05:6402:298e:b0:451:129e:1b35 with SMTP id eq14-20020a056402298e00b00451129e1b35mr31509461edb.79.1665663399003; Thu, 13 Oct 2022 05:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665663398; cv=none; d=google.com; s=arc-20160816; b=XbKyFXJaayU/JojLeulttjT21njNZT2oz3HqHrHIIhv3YpLEQ8c36F53MaI7CrMBCD K9qNb18/lUiooMqieLxkX/8fVSNQWP+6gyPdjcTaJT1fjOasgP8GYGCCWyooKhrzp9Dm FO1pwlvdHHYPVyb3WvEvN/Yf0i1pz3GUQ2sdlmPQYbghtACo7qcktKSzj6JytVT3gkEz gl0DhCwTeUFisPDEp8D9H3074MLf+7Strn2SH8qOw4O8eupPIBPAu1Lokn92UR4fP6V0 Q3vAN8+0ihBnsZsQzUMHJxpLkkYR/sztz48WNRL5pGVV2WktvARNbMRTMYU+y0H5NGZV gX8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=V0aWW8bYZcwHBD680JFtsAetqc8rikFJrjlci3PTsrQ=; b=Ck8RK9f2dPk3ts68z05TVliaqJrgvS6c7YNSTn9JshwZIZPdXCa46xHLA103CsUjSe kVFIJtMuO1QNo01w8uALY0HcKuzpQiTnUrsKMFsiwssdwzB4RR0PST6vS9JRZ4gRy5uS BqSuAgezlJ+YZURyXh27cboHrP/DD91ujmCLX5k1p6qHntxaMCzuVJluKRxGLIDor0EQ eirOWZ1hxEQmHzRIart9QeYcj0hWhYE16nFWOLOy69Eh+CwCNU0bhc5+SkrvYqeCldMW vZLcLEzXd3LWWFlwDBsdGgmyFmLUKk60rtKEZGTon71bZsgXvWjFrzTAC4pweHv0DVXP yOMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mrImrw9i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ee29-20020a056402291d00b004572618668asi14329415edb.461.2022.10.13.05.16.13; Thu, 13 Oct 2022 05:16:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mrImrw9i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbiJMMOE (ORCPT + 99 others); Thu, 13 Oct 2022 08:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiJMMNx (ORCPT ); Thu, 13 Oct 2022 08:13:53 -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 73616FE76F for ; Thu, 13 Oct 2022 05:13:51 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id il7-20020a17090b164700b0020d1029ceaaso3210873pjb.8 for ; Thu, 13 Oct 2022 05:13: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:from:to:cc:subject:date:message-id:reply-to; bh=V0aWW8bYZcwHBD680JFtsAetqc8rikFJrjlci3PTsrQ=; b=mrImrw9iRdZRmVVn3GynmwX3YCsy4SMTIdW1kb3OWriCm4QyX3xxUKJ3xPaqFRfIDZ jD2YV7LE4SRRpOA/oDGRX2PdPM86tgj0I6I/Gd2KHSV6VyXKfb1VH1tfPDV/1ObiOxet TiQpjp4DdTrfFB1AtaoTh6RO8iz31izgANRCSt+NWPB3PIvTQ4S9IJ2DVmhQ45pSoD8b ZpkIASLfpDCIRPXdLiVljzCkFEHIAA9DInb4VjV9FdQY358XVAd0BFTva7kHYQ3Wl3Xu fYGsJ1Mk6A9zbbD3tkJvTRyB/RDRKC79C/TCecFPpDwNzKXfncJ0UHkbbbRa1j9hhsIj pjkw== 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:message-id:reply-to; bh=V0aWW8bYZcwHBD680JFtsAetqc8rikFJrjlci3PTsrQ=; b=0mv/Gm+uYzE1IIDAWn7vOSzAEAvww1EmGlcVD5zxlnb8Yevqsc8y/SQ8pNw36IvH/s 7xulgQYfK3HTdB9UGkb4ELbDGEFk5K2gTAH8Gn5M/l9SS7sbZk7nVSYLRbjmj0+1K3Ao HB/G+ISspxmzZGPfkmmPaX857AzrXdOXljknOglTtb19YAMwjNbDQgJp00cpzmY9rfWT wTHxjjT2SGpCxyLQbOK+2naII7VMXML0uMt/GT5yHtgYbE57qSs/GyzFyHPjToVHeHlr Ymio8YzwtdLS+ThqR9F0ojkJTqZ/SqsTstmL9sL+TEy+mZBPpBLsJpl2UA1YHUaKI5pR ItEg== X-Gm-Message-State: ACrzQf2ufqwFieoiUIRB+5TZMHm3bkKLJfKKYZzyhWwB8FKCpLPnijI+ nwnedL+llBp19gR2S9Py2cg4P8ORDaoSZhzl X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:902:64c2:b0:17b:6546:54be with SMTP id y2-20020a17090264c200b0017b654654bemr35968508pli.60.1665663230813; Thu, 13 Oct 2022 05:13:50 -0700 (PDT) Date: Thu, 13 Oct 2022 12:13:18 +0000 In-Reply-To: <20221013121319.994170-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221013121319.994170-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221013121319.994170-4-vannapurve@google.com> Subject: [V3 PATCH 3/4] KVM: selftests: Add arch specific post vm creation hook 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746574664207334369?= X-GMAIL-MSGID: =?utf-8?q?1746574664207334369?= Add arch specific API kvm_arch_vm_post_create to perform any required setup after VM creation. 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 Reviewed-by: Andrew Jones Reviewed-by: Peter Gonda --- tools/testing/selftests/kvm/include/kvm_util_base.h | 4 ++++ tools/testing/selftests/kvm/lib/kvm_util.c | 9 ++++++--- tools/testing/selftests/kvm/lib/x86_64/processor.c | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index eec0e4898efe..1e7d3eae8c91 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -843,4 +843,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 creating the VM. + */ +void kvm_arch_vm_post_create(struct kvm_vm *vm); #endif /* SELFTEST_KVM_UTIL_BASE_H */ diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index deb4c731b9fa..3ed72980c996 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -340,9 +340,8 @@ struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint32_t nr_runnable_vcpus, kvm_vm_elf_load(vm, program_invocation_name); -#ifdef __x86_64__ - vm_create_irqchip(vm); -#endif + kvm_arch_vm_post_create(vm); + return vm; } @@ -2022,6 +2021,10 @@ void __vm_get_stat(struct kvm_vm *vm, const char *stat_name, uint64_t *data, } } +__weak void kvm_arch_vm_post_create(struct kvm_vm *vm) +{ +} + __weak 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 39c4409ef56a..fa65e8142c16 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1327,3 +1327,9 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) return get_kvm_intel_param_bool("unrestricted_guest"); } + + +void kvm_arch_vm_post_create(struct kvm_vm *vm) +{ + vm_create_irqchip(vm); +} From patchwork Thu Oct 13 12:13:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 2038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp241582wrs; Thu, 13 Oct 2022 05:19:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6C6PrJqxJhn3/jzxavxFnfgr0+G5vufJ2wLlEIJY8gE+TqiUOgLzdo8GUjwHXshu24BelQ X-Received: by 2002:a17:906:9c83:b0:779:c14c:55e4 with SMTP id fj3-20020a1709069c8300b00779c14c55e4mr25755133ejc.619.1665663552884; Thu, 13 Oct 2022 05:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665663552; cv=none; d=google.com; s=arc-20160816; b=e2FSElOE23H1rBLaB803z14gO3h6IQJWMiZehOaqsL5x5XPO/BTA20JNqcmTKE+c3j GmOMN9DrHpADkhsSP/odhdLnG8i4WeUrFDTbT3wAOWAIsMqpbNguanurtLgCi5gmiCVb TcPPUcUDUZuAiLJJ3Vq1nO/vNwH4DpsQBS+NtsJvJfWjeR822j6HxuMEKLtcsY4meEc+ t+TWw+v47Vxa05J3Y5/wSlU5VAW7oKjgsyQnlQN4d2n/9y3T+1GV/SJDsYT+OKbzpk1W mgFFfrB0lPJq6fM+43EhhfL28WuX7IOQKwT3EyREdCBR2U/lFyMq/ELVkAup7dH36Ku1 88Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=BBmCWWVsfDszOLrl6FTujJi9v+keaDMIKKZSe6pczgtfCkG2dyG8F87ITNknjby02T A8LDiZCQIxgq9NQKWby3RfXhW+BbY2XFLfy7L+NJwE0mVCwlG3HhF+VOkvKmUmqszs/0 iwIyBELJ0SPGW0lMifZZOk+DqHJGeN9TEUx9kbOBigBr52uWtFVd00N3gMgsAZEPJemK Q9jWqYtRtG5t3GheNY5oI77M9reXJBcL0lug/x3yowbsiBwpAXdGaBVem605wPjQVhRP E0tdDCqEDmdmuBMC3W3kNtKWMgm4irCISPXMnbwg8O7Lgx8n4ySqUfZSWk23VWLA/Bdr ZKdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ii25z3y8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fg4-20020a056402548400b0045cb9cf913csi2904234edb.424.2022.10.13.05.18.47; Thu, 13 Oct 2022 05:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ii25z3y8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiJMMOJ (ORCPT + 99 others); Thu, 13 Oct 2022 08:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiJMMOC (ORCPT ); Thu, 13 Oct 2022 08:14:02 -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 C7244FDB62 for ; Thu, 13 Oct 2022 05:13:54 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id c12-20020a170903234c00b0017f695bf8f0so1213633plh.6 for ; Thu, 13 Oct 2022 05:13:54 -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:message-id:reply-to; bh=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=Ii25z3y8bR8LKI7fL+IKrahfLIIcV3i2dTRT7mx45kXaZTqxy+AlAEJavNtwpa3Anw FzlrCvqcIVsgqY5N/4i6RpGtHtnXrv/KT6iO8pgRcqZeKk0f08HQPZeixvrS75+Ucw5L VV0Kp9LASJiH661+y+0zqS+0bi4Ge2wi5JIRdmc3Simtu4fnznbSA2LJuCQfxGGBNgOd km5BGclc4f2DTtfQwUTKXBVv+e3Mc14iEnNDliLXhGJtJJ+t/Xt3wBj9OliaFx99xuMS sLj0INBleT8YXIcOCau1ft0h9gLiAptL/Q5xHngJ5C8CySJVqOXuEHFcRnQWu/xLRthx +jsw== 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:message-id:reply-to; bh=H9SaswMeDVA0PXtGn+/RgF2ttyuiFbIBcmIgImTCEOc=; b=kx5bs8SMo/JlRSkshW1ibiJ6Oo9XWpmGWCA/iPY863u18NoiNOzp0LqlyUX1evxTxw EYIJ6jhB05p75UMB0ZfMkkuuOMeG2NilwzaYLgYqFUIQMTnz3UwNxRyJpn0/cPIoiMZ/ wbUn+6edUtYBKVQ5Bk6pK/77nVzmNiQ03LXTAK7SOYI0zaGynOimtNINGR1IZOq5lL03 5KkX2G7d9/Kfv7n5qNRKk2Hc7NhibwgXTbljRUAkRT1EFI/5MvDFGUy0HxrvF1Mr1Bqd jzzgzFyUZlTa8iE8EGe7/ni1kdT/3NdRbNEb/SrllRpGii2mp7zn+3Fh4lANQA4TI0YS IGZw== X-Gm-Message-State: ACrzQf2YGcQW/44Bf9GGgAEwo2s1e4GJMl8warSHOg3XX6upweBKfy2A 90y7+5bMOKG/AEVPpTACN3Kq+Xan9RDRMw7Y X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90a:8c8e:b0:202:883b:2644 with SMTP id b14-20020a17090a8c8e00b00202883b2644mr10744181pjo.89.1665663233436; Thu, 13 Oct 2022 05:13:53 -0700 (PDT) Date: Thu, 13 Oct 2022 12:13:19 +0000 In-Reply-To: <20221013121319.994170-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221013121319.994170-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221013121319.994170-5-vannapurve@google.com> Subject: [V3 PATCH 4/4] KVM: selftests: x86: Precompute the cpu type 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746574825356452079?= X-GMAIL-MSGID: =?utf-8?q?1746574825356452079?= Cache the vendor CPU type in a global variable so that multiple calls to is_amd/intel_cpu() do not need to re-execute CPUID. Sync the global variable is_cpu_amd into the guest so the guest can also avoid executing CPUID instruction. Suggested-by: Sean Christopherson Signed-off-by: Vishal Annapurve --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index fa65e8142c16..f508e58346e9 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) { @@ -1046,7 +1047,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; } /* @@ -1054,7 +1055,7 @@ bool is_intel_cpu(void) */ bool is_amd_cpu(void) { - return cpu_vendor_string_is("AuthenticAMD"); + return is_cpu_amd; } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits) @@ -1328,8 +1329,13 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm) return get_kvm_intel_param_bool("unrestricted_guest"); } +void kvm_selftest_arch_init(void) +{ + is_cpu_amd = cpu_vendor_string_is("AuthenticAMD"); +} void kvm_arch_vm_post_create(struct kvm_vm *vm) { vm_create_irqchip(vm); + sync_global_to_guest(vm, is_cpu_amd); }