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>
Subject: [V4 PATCH 3/4] KVM: sefltests: x86: Replace is_*cpu with is_host_*cpu
Date: Wed, 28 Dec 2022 19:24:37 +0000 [thread overview]
Message-ID: <20221228192438.2835203-4-vannapurve@google.com> (raw)
In-Reply-To: <20221228192438.2835203-1-vannapurve@google.com>
Replace APIs to query cpu type with APIs always checking the host cpu
type. This way there are two set of APIs to query CPU type:
1) this_cpu_is_*()
2) is_host_*cpu()
that can be invoked as per the usecase.
All the current callers of is_*cpu actually care about host cpu type so
they are updated to invoke is_host*cpu.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
.../testing/selftests/kvm/include/x86_64/processor.h | 4 ++--
tools/testing/selftests/kvm/lib/x86_64/processor.c | 12 ++++++------
.../selftests/kvm/x86_64/fix_hypercall_test.c | 4 ++--
.../testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +-
.../selftests/kvm/x86_64/pmu_event_filter_test.c | 4 ++--
.../x86_64/vmx_exception_with_invalid_guest_state.c | 2 +-
6 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 84edac133d8f..8f9e066c89d9 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -713,8 +713,8 @@ static inline void cpu_relax(void)
"hlt\n" \
)
-bool is_intel_cpu(void);
-bool is_amd_cpu(void);
+bool is_host_cpu_intel(void);
+bool is_host_cpu_amd(void);
struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu);
void vcpu_load_state(struct kvm_vcpu *vcpu, struct kvm_x86_state *state);
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index b3d2a9ab5ced..18f0608743d1 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -115,7 +115,7 @@ static void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent)
bool kvm_is_tdp_enabled(void)
{
- if (is_intel_cpu())
+ if (is_host_cpu_intel())
return get_kvm_intel_param_bool("ept");
else
return get_kvm_amd_param_bool("npt");
@@ -1010,14 +1010,14 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state)
free(state);
}
-bool is_intel_cpu(void)
+bool is_host_cpu_intel(void)
{
- return this_cpu_is_intel();
+ return host_cpu_is_intel;
}
-bool is_amd_cpu(void)
+bool is_host_cpu_amd(void)
{
- return this_cpu_is_amd();
+ return host_cpu_is_amd;
}
void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
@@ -1228,7 +1228,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 (!is_amd_cpu())
+ if (!is_host_cpu_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 32f7e09ef67c..e84c0c5a73b1 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 (is_intel_cpu()) {
+ if (is_host_cpu_intel()) {
native_hypercall_insn = vmx_vmcall;
other_hypercall_insn = svm_vmmcall;
- } else if (is_amd_cpu()) {
+ } else if (is_host_cpu_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 fb02581953a3..d2d5dcae98e7 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(is_intel_cpu());
+ TEST_REQUIRE(is_host_cpu_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 2de98fce7edd..289226117513 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 is_intel_cpu() &&
+ return is_host_cpu_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 is_amd_cpu() &&
+ return is_host_cpu_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 2641b286b4ed..d74b0d22385a 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(is_intel_cpu());
+ TEST_REQUIRE(is_host_cpu_intel());
TEST_REQUIRE(!vm_is_unrestricted_guest(NULL));
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
--
2.39.0.314.g84b9a713c41-goog
next prev parent reply other threads:[~2022-12-28 19:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 19:24 [V4 PATCH 0/4] Execute hypercalls according to host cpu Vishal Annapurve
2022-12-28 19:24 ` [V4 PATCH 1/4] KVM: selftests: x86: use this_cpu_* helpers Vishal Annapurve
2023-01-09 18:07 ` Sean Christopherson
2023-01-10 23:56 ` Vishal Annapurve
2022-12-28 19:24 ` [V4 PATCH 2/4] KVM: selftests: x86: Add variables to store cpu type Vishal Annapurve
2023-01-09 18:13 ` Sean Christopherson
2023-01-11 0:13 ` Vishal Annapurve
2022-12-28 19:24 ` Vishal Annapurve [this message]
2022-12-28 19:24 ` [V4 PATCH 4/4] KVM: selftests: x86: Invoke kvm hypercall as per host cpu Vishal Annapurve
2023-01-09 18:20 ` Sean Christopherson
2023-01-11 0:18 ` Vishal Annapurve
2023-01-04 19:32 ` [V4 PATCH 0/4] Execute hypercalls according to " David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221228192438.2835203-4-vannapurve@google.com \
--to=vannapurve@google.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox