* [PATCH 1/2] i386: kvm: Disable arch_capabilities if MSR can't be set
2019-01-25 22:06 [PATCH 0/2] i386: arch_capabilities fixes + migratability Eduardo Habkost
@ 2019-01-25 22:06 ` Eduardo Habkost
2019-01-25 22:06 ` [PATCH 2/2] i386: Make arch_capabilities migratable Eduardo Habkost
2019-03-20 15:18 ` [PATCH 0/2] i386: arch_capabilities fixes + migratability Eduardo Habkost
2 siblings, 0 replies; 4+ messages in thread
From: Eduardo Habkost @ 2019-01-25 22:06 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, kvm, Radim Krčmář,
KarimAllah Ahmed, Marcelo Tosatti, Robert Hoo, Darren Kenny,
Tao Xu, Paolo Bonzini, Konrad Rzeszutek Wilk, Jim Mattson,
David Woodhouse, Richard Henderson
KVM has two bugs in the handling of MSR_IA32_ARCH_CAPABILITIES:
1) Linux commit commit 1eaafe91a0df ("kvm: x86: IA32_ARCH_CAPABILITIES
is always supported") makes GET_SUPPORTED_CPUID return
arch_capabilities even if running on SVM. This makes "-cpu
host,migratable=off" incorrectly expose arch_capabilities on CPUID on
AMD hosts (where the MSR is not emulated by KVM).
2) KVM_GET_MSR_INDEX_LIST does not return MSR_IA32_ARCH_CAPABILITIES if
the MSR is not supported by the host CPU. This makes QEMU not
initialize the MSR properly at kvm_put_msrs() on those hosts.
Work around both bugs on the QEMU side, by checking if the MSR
was returned by KVM_GET_MSR_INDEX_LIST before returning the
feature flag on kvm_arch_get_supported_cpuid().
This has the unfortunate side effect of making arch_capabilities
unavailable on hosts without hardware support for the MSR until bug #2
is fixed on KVM, but I can't see another way to work around bug #1
without that side effect.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Jim Mattson <jmattson@google.com>
Cc: KarimAllah Ahmed <karahmed@amazon.de>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Darren Kenny <darren.kenny@oracle.com>
---
target/i386/kvm.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 9af4542fb8..4fa3e3806a 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -389,6 +389,15 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
if (host_tsx_blacklisted()) {
ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
}
+ } else if (function == 7 && index == 0 && reg == R_EDX) {
+ /*
+ * Linux incorrectly v4.17-v4.20 return ARCH_CAPABILITIES on SVM.
+ * We can detect the bug by checking if MSR_IA32_ARCH_CAPABILITIES is
+ * returned by KVM_GET_MSR_INDEX_LIST.
+ */
+ if (!has_msr_arch_capabs) {
+ ret &= ~CPUID_7_0_EDX_ARCH_CAPABILITIES;
+ }
} else if (function == 0x80000001 && reg == R_ECX) {
/*
* It's safe to enable TOPOEXT even if it's not returned by
--
2.18.0.rc1.1.g3f1ff2140
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] i386: Make arch_capabilities migratable
2019-01-25 22:06 [PATCH 0/2] i386: arch_capabilities fixes + migratability Eduardo Habkost
2019-01-25 22:06 ` [PATCH 1/2] i386: kvm: Disable arch_capabilities if MSR can't be set Eduardo Habkost
@ 2019-01-25 22:06 ` Eduardo Habkost
2019-03-20 15:18 ` [PATCH 0/2] i386: arch_capabilities fixes + migratability Eduardo Habkost
2 siblings, 0 replies; 4+ messages in thread
From: Eduardo Habkost @ 2019-01-25 22:06 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, kvm, Radim Krčmář,
Marcelo Tosatti, Robert Hoo, Tao Xu, Paolo Bonzini,
Richard Henderson
Now that kvm_arch_get_supported_cpuid() will only return
arch_capabilities if QEMU is able to initialize the MSR properly,
we know that the feature is safely migratable.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target/i386/cpu.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 2f5412592d..3ff91d794d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1088,7 +1088,6 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
.reg = R_EDX,
},
.tcg_features = TCG_7_0_EDX_FEATURES,
- .unmigratable_flags = CPUID_7_0_EDX_ARCH_CAPABILITIES,
},
[FEAT_8000_0007_EDX] = {
.type = CPUID_FEATURE_WORD,
--
2.18.0.rc1.1.g3f1ff2140
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] i386: arch_capabilities fixes + migratability
2019-01-25 22:06 [PATCH 0/2] i386: arch_capabilities fixes + migratability Eduardo Habkost
2019-01-25 22:06 ` [PATCH 1/2] i386: kvm: Disable arch_capabilities if MSR can't be set Eduardo Habkost
2019-01-25 22:06 ` [PATCH 2/2] i386: Make arch_capabilities migratable Eduardo Habkost
@ 2019-03-20 15:18 ` Eduardo Habkost
2 siblings, 0 replies; 4+ messages in thread
From: Eduardo Habkost @ 2019-03-20 15:18 UTC (permalink / raw)
To: qemu-devel
Cc: kvm, Radim Krčmář, Marcelo Tosatti, Robert Hoo,
Tao Xu, Paolo Bonzini, Richard Henderson
It looks like this has slipped through the cracks. I'm queueing
this series for -rc1.
On Fri, Jan 25, 2019 at 08:06:04PM -0200, Eduardo Habkost wrote:
> This series works around KVM bugs that affect the arch_capabilities
> feature. One bug made the feature be enabled incorrect on AMD hosts,
> and another one made the feature unsafe to enable on most Intel hosts.
> With the work around, we can finally make arch_capabilities a migratable
> feature.
>
> Unfortunately, the work around has the side effect of making
> arch_capabilities unavailable on hosts without hardware support for the
> feature until one of the KVM bugs is fixed.
>
> Eduardo Habkost (2):
> i386: kvm: Disable arch_capabilities if MSR can't be set
> i386: Make arch_capabilities migratable
>
> target/i386/cpu.c | 1 -
> target/i386/kvm.c | 9 +++++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> --
> 2.18.0.rc1.1.g3f1ff2140
>
--
Eduardo
^ permalink raw reply [flat|nested] 4+ messages in thread