Message ID | 20221228192438.2835203-2-vannapurve@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2050707wrt; Wed, 28 Dec 2022 11:25:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXvsSXGWbGRqaOPkULD8yalpcfl+Neuc9RN3yZvNEMDZb1Lmx+8CR/8aeFyfpbLU/ntlrQzW X-Received: by 2002:a17:90b:1296:b0:219:36c6:f06d with SMTP id fw22-20020a17090b129600b0021936c6f06dmr29573773pjb.20.1672255554187; Wed, 28 Dec 2022 11:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672255554; cv=none; d=google.com; s=arc-20160816; b=Dx/aFeD9nuTUyQ9DRQOnhYhTefsAF+6VtKNUJikyKtRmHPokfIb8I3DGzluLr2ZqJ4 XnYtSeSPGapRT+RTe2aWSc9r+6R6dTXBhejdcNQQNEKjGu3ikUN/4ASBhL35kUYrY38E FPC85QuXUiyxnlj4scFxFQFPH9KPECwvYC+OtIlUKJaDZxKD0IkCEVlctfdoGLSbVQW8 yiDN4kAhbxVk7O+XISC1kCz2K9lMKuMimkvNy6W6Eugj7qi2uQElQQ/bhIUCHzc0kY5E e8EMJFUSFQlt0vtRHPEiB9HAaoCSOugThpAO6gK2iVj3O1/eJM9aE60PyIWlSuqP5er7 v8SA== 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=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=VdzuBsM5xjL0O6kR80Zp+Fbj1hPV2ccVG65SkbSMXfAC/i1atdea8fqCHU/OIq3wPA iG39WiJNfZS6zPsUeFbt5w/B8WtU37CwWut1J3DDL84ZHbB4sVlnprXW0ZW0x9qKtt+P AMXPB7iIVXrA0pmv8y8pz8emkH3nwNaAXbH0BUxytiK6yGMrWNyzl6RK9GdrIMXRA9HE I0YFTQsPdQP7tKXyi/vpKA4q3OJW1/+Qe3ZHrgpaBUEJQ6Ce+kSqCj3ralMgizhE+o4P a3+0WfD5cCl78FdU/D2qAjAQ37ySS61w7YAuU63R/BIKsfBK+qwmiq6+DXL/Jr21KXX5 vT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cpM7ihQB; 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 pc3-20020a17090b3b8300b0022601981ba2si7196120pjb.99.2022.12.28.11.25.42; Wed, 28 Dec 2022 11:25:54 -0800 (PST) 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=cpM7ihQB; 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 S231879AbiL1TY7 (ORCPT <rfc822;eddaouddi.ayoub@gmail.com> + 99 others); Wed, 28 Dec 2022 14:24:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233144AbiL1TYv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 28 Dec 2022 14:24:51 -0500 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 697E61741D for <linux-kernel@vger.kernel.org>; Wed, 28 Dec 2022 11:24:50 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id o18-20020a170902d4d200b00189d4c25568so12649695plg.13 for <linux-kernel@vger.kernel.org>; Wed, 28 Dec 2022 11:24:50 -0800 (PST) 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=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=cpM7ihQBd4FEp1qLIXzpJmruvJ3gQgEt9GzCCQuDYzGWE0/JQl180tij1IgB+3C1fI NI/CRB81Gq7Pn7zvsbktzzDsMrOjqyRGhefHNbr/27eV0KSb4bCymBjgValGjt5659P5 hnCuNueNq8N5g0T66+w9ELo5UBp8JnSXjCa9c3UVTjbtYAeJzkqJcs5a1fnnFFO1mAp1 LDzoMxKw2q/igdHUkIIUKWPRY4xdesLfXRisswaP4wC5MvSNJbOf3E1Y+S66a+hQj4lS 5oYExQ4FmaX+p9xdEUupA5dRNDU9nWqyptcGEq35t6lkLJu41sgez82NakYbR60frdT0 RgJg== 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=Mo9WWk49bq3o6GgXHJZvpBlrKizEyknLEVuJxarZm6w=; b=qWd5t4M0dEV3w8+LQYRzIUw3EzBk9vk0NlC0PkrpZjzikZNKh4O8QHhuDP0gUyVQ8X rgh0xCOexEZNAtbtLUVoZSUfSNCknxlljmFoW4Ovu6ogahS3WTMGetzFhbS5++WdhPji B9BivnWAp3MAp9eHSINHPjdeb4IrQSgP96/0u4mndRJSd6ppScBFBIjJfzyOrtQMgsr8 GAsSedRwReQSX2m60ZJxUPqJy0d8siYeH1ILIWXDSS77as0SEcOuDRdTxsSJ6apKgF0V cQ4XzbvbRxBT83sKx7ZYQaSmAbkTrU4dIC4L9I//o8ZHk4y2B4hDdpMs17m/UCqpUgaj mIPg== X-Gm-Message-State: AFqh2kppVZgS/4oPMI31Bq/fM56GbpLm+G2I7vdFOydXdfuYPPQL/w6/ qa0TnQxliTwiei4saJ0P+JjOJJEogv9eFZjU X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a17:90b:4d83:b0:220:1f03:129b with SMTP id oj3-20020a17090b4d8300b002201f03129bmr106930pjb.0.1672255489536; Wed, 28 Dec 2022 11:24:49 -0800 (PST) Date: Wed, 28 Dec 2022 19:24:35 +0000 In-Reply-To: <20221228192438.2835203-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221228192438.2835203-1-vannapurve@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221228192438.2835203-2-vannapurve@google.com> Subject: [V4 PATCH 1/4] KVM: selftests: x86: use this_cpu_* helpers From: Vishal Annapurve <vannapurve@google.com> 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 <vannapurve@google.com> Content-Type: text/plain; charset="UTF-8" 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753487040162557515?= X-GMAIL-MSGID: =?utf-8?q?1753487040162557515?= |
Series | Execute hypercalls according to host cpu | |
Commit Message
Vishal Annapurve
Dec. 28, 2022, 7:24 p.m. UTC
Use this_cpu_* helpers to query the cpu vendor.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
.../selftests/kvm/include/x86_64/processor.h | 22 +++++++++++++++++++
.../selftests/kvm/lib/x86_64/processor.c | 16 ++------------
2 files changed, 24 insertions(+), 14 deletions(-)
Comments
On Wed, Dec 28, 2022, Vishal Annapurve wrote: > Use this_cpu_* helpers to query the cpu vendor. Neither the changelog nor the shortlog captures what this patch actually does, or rather what I inteded it to do. Specifically, what I suggested (or intended to suggest) was: KVM: selftests: Rename vendor string helpers to use "this_cpu" prefix > Suggested-by: Sean Christopherson <seanjc@google.com> > Signed-off-by: Vishal Annapurve <vannapurve@google.com> > --- ... > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index acfa1d01e7df..a799af572f3f 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -1006,26 +1006,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state) > free(state); > } > > -static bool cpu_vendor_string_is(const char *vendor) > -{ > - const uint32_t *chunk = (const uint32_t *)vendor; > - uint32_t eax, ebx, ecx, edx; > - > - cpuid(0, &eax, &ebx, &ecx, &edx); > - return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]); > -} > - > bool is_intel_cpu(void) Drop the is_intel_cpu() and is_amd_cpu() wrappers. The whole point of the rename was so that it's obvious at the call site that the function is checking the "current" CPU context. That obviously means dropping the is_host_cpu_amd() and is_host_cpu_intel() wrappers too. IMO, the extra layer to jump through (more from a code reading perspective then a code generation perspective) isn't worth protecting the booleans. It's slightly more churn (in between patches, not overall), but the benefit is that it allows squasing patches 2 and 3 into a single patch, e.g. "KVM: selftests: Cache host CPU vendor (AMD vs. Intel)" --- tools/testing/selftests/kvm/include/x86_64/processor.h | 3 +++ tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++++---- tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 4 ++-- tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +- .../testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 4 ++-- .../kvm/x86_64/vmx_exception_with_invalid_guest_state.c | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index fdb1af5ca611..c7885f72132a 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -19,6 +19,9 @@ #include "../kvm_util.h" +extern bool host_cpu_is_intel; +extern bool host_cpu_is_amd; + #define NMI_VECTOR 0x02 #define X86_EFLAGS_FIXED (1u << 1) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index 0b8de34aa10e..84915bc7d689 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -19,8 +19,8 @@ #define MAX_NR_CPUID_ENTRIES 100 vm_vaddr_t exception_handlers; -static bool host_cpu_is_amd; -static bool host_cpu_is_intel; +bool host_cpu_is_amd; +bool host_cpu_is_intel; static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) { @@ -115,7 +115,7 @@ static void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent) bool kvm_is_tdp_enabled(void) { - if (this_cpu_is_intel()) + if (host_cpu_is_intel) return get_kvm_intel_param_bool("ept"); else return get_kvm_amd_param_bool("npt"); @@ -1218,7 +1218,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) max_gfn = (1ULL << (vm->pa_bits - vm->page_shift)) - 1; /* Avoid reserved HyperTransport region on AMD processors. */ - if (!this_cpu_is_amd()) + if (!host_cpu_is_amd) return max_gfn; /* On parts with <40 physical address bits, the area is fully hidden */ diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c index 5489c9836ec8..0f728f05ea82 100644 --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c @@ -48,10 +48,10 @@ static void guest_main(void) const uint8_t *other_hypercall_insn; uint64_t ret; - if (this_cpu_is_intel()) { + if (host_cpu_is_intel) { native_hypercall_insn = vmx_vmcall; other_hypercall_insn = svm_vmmcall; - } else if (this_cpu_is_amd()) { + } else if (host_cpu_is_amd) { native_hypercall_insn = svm_vmmcall; other_hypercall_insn = vmx_vmcall; } else { diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c index b0a2a0bae0f3..ce1ccc4c1503 100644 --- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c @@ -93,7 +93,7 @@ int main(void) { int warnings_before, warnings_after; - TEST_REQUIRE(this_cpu_is_intel()); + TEST_REQUIRE(host_cpu_is_intel); TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); 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 c728822461b2..4dbb454e1760 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 @@ -363,7 +363,7 @@ static void test_pmu_config_disable(void (*guest_code)(void)) */ static bool use_intel_pmu(void) { - return this_cpu_is_intel() && + return host_cpu_is_intel && kvm_cpu_property(X86_PROPERTY_PMU_VERSION) && kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS) && kvm_pmu_has(X86_PMU_FEATURE_BRANCH_INSNS_RETIRED); @@ -397,7 +397,7 @@ static bool use_amd_pmu(void) uint32_t family = kvm_cpu_family(); uint32_t model = kvm_cpu_model(); - return this_cpu_is_amd() && + return host_cpu_is_amd && (is_zen1(family, model) || is_zen2(family, model) || is_zen3(family, model)); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c index 53e1ef2fc774..ccdfa5dc1a4d 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; - TEST_REQUIRE(this_cpu_is_intel()); + TEST_REQUIRE(host_cpu_is_intel); TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); vm = vm_create_with_one_vcpu(&vcpu, guest_code); base-commit: 04b420511919f7b78f17f5fa6dc92975a8b2d7c4 --
On Mon, Jan 9, 2023 at 10:07 AM Sean Christopherson <seanjc@google.com> wrote: > > On Wed, Dec 28, 2022, Vishal Annapurve wrote: > > Use this_cpu_* helpers to query the cpu vendor. > > Neither the changelog nor the shortlog captures what this patch actually does, > or rather what I inteded it to do. Specifically, what I suggested (or intended > to suggest) was: > > KVM: selftests: Rename vendor string helpers to use "this_cpu" prefix > > > Suggested-by: Sean Christopherson <seanjc@google.com> > > Signed-off-by: Vishal Annapurve <vannapurve@google.com> > > --- > > ... > > > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > > index acfa1d01e7df..a799af572f3f 100644 > > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > > @@ -1006,26 +1006,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state) > > free(state); > > } > > > > -static bool cpu_vendor_string_is(const char *vendor) > > -{ > > - const uint32_t *chunk = (const uint32_t *)vendor; > > - uint32_t eax, ebx, ecx, edx; > > - > > - cpuid(0, &eax, &ebx, &ecx, &edx); > > - return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]); > > -} > > - > > bool is_intel_cpu(void) > > Drop the is_intel_cpu() and is_amd_cpu() wrappers. The whole point of the rename > was so that it's obvious at the call site that the function is checking the "current" > CPU context. > > That obviously means dropping the is_host_cpu_amd() and is_host_cpu_intel() wrappers > too. IMO, the extra layer to jump through (more from a code reading perspective then > a code generation perspective) isn't worth protecting the booleans. > > It's slightly more churn (in between patches, not overall), but the benefit is that > it allows squasing patches 2 and 3 into a single patch, e.g. "KVM: selftests: Cache > host CPU vendor (AMD vs. Intel)" > > --- > tools/testing/selftests/kvm/include/x86_64/processor.h | 3 +++ > tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++++---- > tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c | 4 ++-- > tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +- > .../testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 4 ++-- > .../kvm/x86_64/vmx_exception_with_invalid_guest_state.c | 2 +- > 6 files changed, 13 insertions(+), 10 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h > index fdb1af5ca611..c7885f72132a 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/processor.h > +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h > @@ -19,6 +19,9 @@ > > #include "../kvm_util.h" > > +extern bool host_cpu_is_intel; > +extern bool host_cpu_is_amd; > + > #define NMI_VECTOR 0x02 > > #define X86_EFLAGS_FIXED (1u << 1) > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index 0b8de34aa10e..84915bc7d689 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -19,8 +19,8 @@ > #define MAX_NR_CPUID_ENTRIES 100 > > vm_vaddr_t exception_handlers; > -static bool host_cpu_is_amd; > -static bool host_cpu_is_intel; > +bool host_cpu_is_amd; > +bool host_cpu_is_intel; > > static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) > { > @@ -115,7 +115,7 @@ static void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent) > > bool kvm_is_tdp_enabled(void) > { > - if (this_cpu_is_intel()) > + if (host_cpu_is_intel) > return get_kvm_intel_param_bool("ept"); > else > return get_kvm_amd_param_bool("npt"); > @@ -1218,7 +1218,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) > max_gfn = (1ULL << (vm->pa_bits - vm->page_shift)) - 1; > > /* Avoid reserved HyperTransport region on AMD processors. */ > - if (!this_cpu_is_amd()) > + if (!host_cpu_is_amd) > return max_gfn; > > /* On parts with <40 physical address bits, the area is fully hidden */ > diff --git a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c > index 5489c9836ec8..0f728f05ea82 100644 > --- a/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c > +++ b/tools/testing/selftests/kvm/x86_64/fix_hypercall_test.c > @@ -48,10 +48,10 @@ static void guest_main(void) > const uint8_t *other_hypercall_insn; > uint64_t ret; > > - if (this_cpu_is_intel()) { > + if (host_cpu_is_intel) { > native_hypercall_insn = vmx_vmcall; > other_hypercall_insn = svm_vmmcall; > - } else if (this_cpu_is_amd()) { > + } else if (host_cpu_is_amd) { > native_hypercall_insn = svm_vmmcall; > other_hypercall_insn = vmx_vmcall; > } else { > diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c > index b0a2a0bae0f3..ce1ccc4c1503 100644 > --- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c > +++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c > @@ -93,7 +93,7 @@ int main(void) > { > int warnings_before, warnings_after; > > - TEST_REQUIRE(this_cpu_is_intel()); > + TEST_REQUIRE(host_cpu_is_intel); > > TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); > > 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 c728822461b2..4dbb454e1760 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 > @@ -363,7 +363,7 @@ static void test_pmu_config_disable(void (*guest_code)(void)) > */ > static bool use_intel_pmu(void) > { > - return this_cpu_is_intel() && > + return host_cpu_is_intel && > kvm_cpu_property(X86_PROPERTY_PMU_VERSION) && > kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS) && > kvm_pmu_has(X86_PMU_FEATURE_BRANCH_INSNS_RETIRED); > @@ -397,7 +397,7 @@ static bool use_amd_pmu(void) > uint32_t family = kvm_cpu_family(); > uint32_t model = kvm_cpu_model(); > > - return this_cpu_is_amd() && > + return host_cpu_is_amd && > (is_zen1(family, model) || > is_zen2(family, model) || > is_zen3(family, model)); > diff --git a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c > index 53e1ef2fc774..ccdfa5dc1a4d 100644 > --- a/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c > +++ b/tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c > @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) > struct kvm_vcpu *vcpu; > struct kvm_vm *vm; > > - TEST_REQUIRE(this_cpu_is_intel()); > + TEST_REQUIRE(host_cpu_is_intel); > TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); > > vm = vm_create_with_one_vcpu(&vcpu, guest_code); > > base-commit: 04b420511919f7b78f17f5fa6dc92975a8b2d7c4 > -- > Ack, that makes sense. Will include this suggestion in the next version.
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 2a5f47d51388..84edac133d8f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -555,6 +555,28 @@ static inline uint32_t this_cpu_model(void) return x86_model(this_cpu_fms()); } +static inline bool this_cpu_vendor_string_is(const char *vendor) +{ + const uint32_t *chunk = (const uint32_t *)vendor; + uint32_t eax, ebx, ecx, edx; + + cpuid(0, &eax, &ebx, &ecx, &edx); + return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]); +} + +static inline bool this_cpu_is_intel(void) +{ + return this_cpu_vendor_string_is("GenuineIntel"); +} + +/* + * Exclude early K5 samples with a vendor string of "AMDisbetter!" + */ +static inline bool this_cpu_is_amd(void) +{ + return this_cpu_vendor_string_is("AuthenticAMD"); +} + static inline uint32_t __this_cpu_has(uint32_t function, uint32_t index, uint8_t reg, uint8_t lo, uint8_t hi) { diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c index acfa1d01e7df..a799af572f3f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1006,26 +1006,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state) free(state); } -static bool cpu_vendor_string_is(const char *vendor) -{ - const uint32_t *chunk = (const uint32_t *)vendor; - uint32_t eax, ebx, ecx, edx; - - cpuid(0, &eax, &ebx, &ecx, &edx); - return (ebx == chunk[0] && edx == chunk[1] && ecx == chunk[2]); -} - bool is_intel_cpu(void) { - return cpu_vendor_string_is("GenuineIntel"); + return this_cpu_is_intel(); } -/* - * Exclude early K5 samples with a vendor string of "AMDisbetter!" - */ bool is_amd_cpu(void) { - return cpu_vendor_string_is("AuthenticAMD"); + return this_cpu_is_amd(); } void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)