x86/kvm: do not setup pv tlb flush when not paravirtualized
Subsystems (3)
PATCH 1/1 x86/kvm: do not setup pv tlb flush when not paravirtualized
kvm_setup_pv_tlb_flush will waste memory and print a misguiding message when KVM paravirtualization is not available.
Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems, kvm_arch_para_features will return bogus data, causing kvm_setup_pv_tlb_flush to detect support for pv tlb flush.
Testing for kvm_para_available will work as it checks for the hypervisor signature.
Besides, when the "nopv" command line parameter is used, it should not continue as well, as kvm_guest_init will no be called in that case.
--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/kvm.c +3 -0
@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {
Signature · 1 line
2.24.0
Vitaly Kuznetsov
reviewerQuoted 26 lines · Thadeu Lima de Souza Cascardo
kvm_setup_pv_tlb_flushwill waste memory and print a misguiding message when KVM paravirtualization is not available.Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems,
kvm_arch_para_featureswill return bogus data, causingkvm_setup_pv_tlb_flushto detect support for pv tlb flush.Testing for
kvm_para_availablewill work as it checks for the hypervisor signature.Besides, when the "nopv" command line parameter is used, it should not continue as well, as
kvm_guest_initwill no be called in that case.Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/kvm.c +0
-0
arch/x86/kernel/kvm.c static __init int kvm_setup_pv_tlb_flush(void) · line 744
Quoted 9 lines
arch/x86/kernel/kvm.c +3
-0@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {
The patch will fix the immediate issue, but why kvm_setup_pv_tlb_flush() is just an arch_initcall() which will be executed regardless of the fact if we are running on KVM or not?
In Hyper-V we setup PV TLB flush from ms_hyperv_init_platform() -- which only happens if Hyper-V platform was detected. Why don't we do it from kvm_init_platform() in KVM?
Signature · 1 line
Vitaly
Quoted 42 lines · Vitaly Kuznetsov
Quoted 26 lines · Thadeu Lima de Souza Cascardo
kvm_setup_pv_tlb_flushwill waste memory and print a misguiding message when KVM paravirtualization is not available.Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems,
kvm_arch_para_featureswill return bogus data, causingkvm_setup_pv_tlb_flushto detect support for pv tlb flush.Testing for
kvm_para_availablewill work as it checks for the hypervisor signature.Besides, when the "nopv" command line parameter is used, it should not continue as well, as
kvm_guest_initwill no be called in that case.Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/kvm.c +0
-0arch/x86/kernel/kvm.c static __init int kvm_setup_pv_tlb_flush(void) · line 744
Quoted 9 lines
arch/x86/kernel/kvm.c +3
-0@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {The patch will fix the immediate issue, but why
kvm_setup_pv_tlb_flush()is just anarch_initcall()which will be executed regardless of the fact if we are running on KVM or not?
Quoted 7 lines
In Hyper-V we setup PV TLB flush from
ms_hyperv_init_platform()-- which only happens if Hyper-V platform was detected. Why don't we do it fromkvm_init_platform()in KVM?Signature · 1 line
Vitaly
Because we can't call the allocator that early.
Also, see the thread where this was "decided", the v6 of the original patch:
https://lore.kernel.org/kvm/20171129162118.GA10661@flask/
Regards.
Cascardo.
Quoted 52 lines · Thadeu Lima de Souza Cascardo
Quoted 42 lines · Vitaly Kuznetsov
Quoted 26 lines · Thadeu Lima de Souza Cascardo
kvm_setup_pv_tlb_flushwill waste memory and print a misguiding message when KVM paravirtualization is not available.Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems,
kvm_arch_para_featureswill return bogus data, causingkvm_setup_pv_tlb_flushto detect support for pv tlb flush.Testing for
kvm_para_availablewill work as it checks for the hypervisor signature.Besides, when the "nopv" command line parameter is used, it should not continue as well, as
kvm_guest_initwill no be called in that case.Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/kvm.c +0
-0arch/x86/kernel/kvm.c static __init int kvm_setup_pv_tlb_flush(void) · line 744
Quoted 9 lines
arch/x86/kernel/kvm.c +3
-0@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {The patch will fix the immediate issue, but why
kvm_setup_pv_tlb_flush()is just anarch_initcall()which will be executed regardless of the fact if we are running on KVM or not?Quoted 7 lines
In Hyper-V we setup PV TLB flush from
ms_hyperv_init_platform()-- which only happens if Hyper-V platform was detected. Why don't we do it fromkvm_init_platform()in KVM?--
Vitaly
Quoted 5 lines
Because we can't call the allocator that early.
Also, see the thread where this was "decided", the v6 of the original patch:
A little change to this function.
https://lore.kernel.org/kvm/CANRm+CwK0Cg45mktda9Yz9fsjPCvtuB8O+fma5L3tV725ki1qw@mail.gmail.com
Testing is a great appreciated. (Still in vacation)
Wanpeng
Vitaly Kuznetsov
reviewerQuoted 51 lines · Thadeu Lima de Souza Cascardo
Quoted 42 lines · Vitaly Kuznetsov
Quoted 26 lines · Thadeu Lima de Souza Cascardo
kvm_setup_pv_tlb_flushwill waste memory and print a misguiding message when KVM paravirtualization is not available.Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems,
kvm_arch_para_featureswill return bogus data, causingkvm_setup_pv_tlb_flushto detect support for pv tlb flush.Testing for
kvm_para_availablewill work as it checks for the hypervisor signature.Besides, when the "nopv" command line parameter is used, it should not continue as well, as
kvm_guest_initwill no be called in that case.Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/kvm.c +0
-0arch/x86/kernel/kvm.c static __init int kvm_setup_pv_tlb_flush(void) · line 744
Quoted 9 lines
arch/x86/kernel/kvm.c +3
-0@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {The patch will fix the immediate issue, but why
kvm_setup_pv_tlb_flush()is just anarch_initcall()which will be executed regardless of the fact if we are running on KVM or not?Quoted 7 lines
In Hyper-V we setup PV TLB flush from
ms_hyperv_init_platform()-- which only happens if Hyper-V platform was detected. Why don't we do it fromkvm_init_platform()in KVM?Signature · 1 line
Vitaly
Quoted 5 lines
Because we can't call the allocator that early.
Also, see the thread where this was "decided", the v6 of the original patch:
Ok, I see, it's basically about what we prioritize: shorter boot time vs smaller memory footprint. I'd personally vote for the former but the opposite opinion is equally valid. Let's preserve the status quo.
Signature · 1 line
Vitaly
Quoted 27 lines · Thadeu Lima de Souza Cascardo
kvm_setup_pv_tlb_flushwill waste memory and print a misguiding message when KVM paravirtualization is not available.Intel SDM says that the when cpuid is used with EAX higher than the maximum supported value for basic of extended function, the data for the highest supported basic function will be returned.
So, in some systems,
kvm_arch_para_featureswill return bogus data, causingkvm_setup_pv_tlb_flushto detect support for pv tlb flush.Testing for
kvm_para_availablewill work as it checks for the hypervisor signature.Besides, when the "nopv" command line parameter is used, it should not continue as well, as
kvm_guest_initwill no be called in that case.Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>--- arch/x86/kernel/kvm.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/kvm.c +0
-0
arch/x86/kernel/kvm.c static __init int kvm_setup_pv_tlb_flush(void) · line 744
Quoted 9 lines
arch/x86/kernel/kvm.c +3
-0@@ -736,6 +736,9 @@ static __init int kvm_setup_pv_tlb_flush(void) {int cpu; +if (!kvm_para_available () || nopv) +return 0 ; +if (kvm_para_has_feature (KVM_FEATURE_PV_TLB_FLUSH ) && !kvm_para_has_hint (KVM_HINTS_REALTIME ) &&kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) {
Queued, thanks.
Paolo