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: [V3 PATCH 4/4] KVM: selftests: x86: Precompute the cpu type
Date: Thu, 13 Oct 2022 12:13:19 +0000 [thread overview]
Message-ID: <20221013121319.994170-5-vannapurve@google.com> (raw)
In-Reply-To: <20221013121319.994170-1-vannapurve@google.com>
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 <seanjc@google.com>
Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
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);
}
--
2.38.0.rc1.362.ged0d419d3c-goog
next prev parent reply other threads:[~2022-10-13 12:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 12:13 [V3 PATCH 0/4] Minor improvements to the selftest setup logic Vishal Annapurve
2022-10-13 12:13 ` [V3 PATCH 1/4] KVM: selftests: move common startup logic to kvm_util.c Vishal Annapurve
2022-11-15 21:03 ` Peter Gonda
2022-10-13 12:13 ` [V3 PATCH 2/4] KVM: selftests: Add arch specific initialization Vishal Annapurve
2022-10-13 14:00 ` Andrew Jones
2022-11-15 21:02 ` Peter Gonda
2022-10-13 12:13 ` [V3 PATCH 3/4] KVM: selftests: Add arch specific post vm creation hook Vishal Annapurve
2022-10-13 14:01 ` Andrew Jones
2022-11-15 20:49 ` Peter Gonda
2022-10-13 12:13 ` Vishal Annapurve [this message]
2022-10-21 0:03 ` [V3 PATCH 4/4] KVM: selftests: x86: Precompute the cpu type Sean Christopherson
2022-11-01 10:47 ` Vishal Annapurve
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=20221013121319.994170-5-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