82 lines
3.2 KiB
Diff
82 lines
3.2 KiB
Diff
|
|
From 52ee6f565f4b4a0ca3325e94dcb44ce68ca61eee Mon Sep 17 00:00:00 2001
|
||
|
|
From: Paolo Bonzini <pbonzini@redhat.com>
|
||
|
|
Date: Mon, 27 Feb 2023 10:41:46 +0100
|
||
|
|
Subject: [PATCH] target/i386: KVM: allow fast string operations if host
|
||
|
|
supports them
|
||
|
|
|
||
|
|
mainline inclusion
|
||
|
|
from mainline-v8.0.0-rc0
|
||
|
|
commit 3023c9b4d1092eb27a523c08d9e78cbaec67b59b
|
||
|
|
category: feature
|
||
|
|
feature: Intel fast REP string operations support
|
||
|
|
bugzilla: https://gitee.com/openeuler/intel-qemu/issues/I6ZGIX
|
||
|
|
|
||
|
|
Intel-SIG: commit 3023c9b4d109 ("target/i386: KVM: allow fast string operations if host supports them")
|
||
|
|
|
||
|
|
-------------------------------------
|
||
|
|
|
||
|
|
target/i386: KVM: allow fast string operations if host supports them
|
||
|
|
|
||
|
|
These are just a flag that documents the performance characteristic of
|
||
|
|
an instruction; it needs no hypervisor support. So include them even
|
||
|
|
if KVM does not show them. In particular, FZRM/FSRS/FSRC have only
|
||
|
|
been added very recently, but they are available on Sapphire Rapids
|
||
|
|
processors.
|
||
|
|
|
||
|
|
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
|
||
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
||
|
|
Signed-off-by: Aichun Shi <aichun.shi@intel.com>
|
||
|
|
---
|
||
|
|
target/i386/kvm/kvm.c | 17 ++++++++++++++++-
|
||
|
|
1 file changed, 16 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
|
||
|
|
index b8257e7e5f..6fa3bd9694 100644
|
||
|
|
--- a/target/i386/kvm/kvm.c
|
||
|
|
+++ b/target/i386/kvm/kvm.c
|
||
|
|
@@ -350,7 +350,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
||
|
|
{
|
||
|
|
struct kvm_cpuid2 *cpuid;
|
||
|
|
uint32_t ret = 0;
|
||
|
|
- uint32_t cpuid_1_edx;
|
||
|
|
+ uint32_t cpuid_1_edx, unused;
|
||
|
|
uint64_t bitmask;
|
||
|
|
|
||
|
|
cpuid = get_supported_cpuid(s);
|
||
|
|
@@ -397,10 +397,20 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
||
|
|
} else if (function == 6 && reg == R_EAX) {
|
||
|
|
ret |= CPUID_6_EAX_ARAT; /* safe to allow because of emulated APIC */
|
||
|
|
} else if (function == 7 && index == 0 && reg == R_EBX) {
|
||
|
|
+ /* Not new instructions, just an optimization. */
|
||
|
|
+ uint32_t ebx;
|
||
|
|
+ host_cpuid(7, 0, &unused, &ebx, &unused, &unused);
|
||
|
|
+ ret |= ebx & CPUID_7_0_EBX_ERMS;
|
||
|
|
+
|
||
|
|
if (host_tsx_broken()) {
|
||
|
|
ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
|
||
|
|
}
|
||
|
|
} else if (function == 7 && index == 0 && reg == R_EDX) {
|
||
|
|
+ /* Not new instructions, just an optimization. */
|
||
|
|
+ uint32_t edx;
|
||
|
|
+ host_cpuid(7, 0, &unused, &unused, &unused, &edx);
|
||
|
|
+ ret |= edx & CPUID_7_0_EDX_FSRM;
|
||
|
|
+
|
||
|
|
/*
|
||
|
|
* Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM hosts.
|
||
|
|
* We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
|
||
|
|
@@ -409,6 +419,11 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
|
||
|
|
if (!has_msr_arch_capabs) {
|
||
|
|
ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
|
||
|
|
}
|
||
|
|
+ } else if (function == 7 && index == 1 && reg == R_EAX) {
|
||
|
|
+ /* Not new instructions, just an optimization. */
|
||
|
|
+ uint32_t eax;
|
||
|
|
+ host_cpuid(7, 1, &eax, &unused, &unused, &unused);
|
||
|
|
+ ret |= eax & (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | CPUID_7_1_EAX_FSRC);
|
||
|
|
} else if (function == 0xd && index == 0 &&
|
||
|
|
(reg == R_EAX || reg == R_EDX)) {
|
||
|
|
/*
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|