From: Li RongQing <lirongqing@xxxxxxxxx> if CPU has not X86_BUG_ITLB_MULTIHIT bug, kvm-nx-lpage-re kthread is not needed to create Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx> --- arch/x86/kvm/mmu/mmu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 8354262..be98c69 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6667,6 +6667,11 @@ static bool get_nx_auto_mode(void) return boot_cpu_has_bug(X86_BUG_ITLB_MULTIHIT) && !cpu_mitigations_off(); } +static bool cpu_has_itlb_multihit(void) +{ + return boot_cpu_has_bug(X86_BUG_ITLB_MULTIHIT); +} + static void __set_nx_huge_pages(bool val) { nx_huge_pages = itlb_multihit_kvm_mitigation = val; @@ -6677,6 +6682,11 @@ static int set_nx_huge_pages(const char *val, const struct kernel_param *kp) bool old_val = nx_huge_pages; bool new_val; + if (!cpu_has_itlb_multihit()) { + __set_nx_huge_pages(false); + return 0; + } + /* In "auto" mode deploy workaround only if CPU has the bug. */ if (sysfs_streq(val, "off")) new_val = 0; @@ -6816,6 +6826,9 @@ static int set_nx_huge_pages_recovery_param(const char *val, const struct kernel uint old_period, new_period; int err; + if (!cpu_has_itlb_multihit()) + return 0; + was_recovery_enabled = calc_nx_huge_pages_recovery_period(&old_period); err = param_set_uint(val, kp); @@ -6971,6 +6984,9 @@ int kvm_mmu_post_init_vm(struct kvm *kvm) { int err; + if (!cpu_has_itlb_multihit()) + return 0; + err = kvm_vm_create_worker_thread(kvm, kvm_nx_huge_page_recovery_worker, 0, "kvm-nx-lpage-recovery", &kvm->arch.nx_huge_page_recovery_thread); @@ -6982,6 +6998,9 @@ int kvm_mmu_post_init_vm(struct kvm *kvm) void kvm_mmu_pre_destroy_vm(struct kvm *kvm) { + if (!cpu_has_itlb_multihit()) + return; + if (kvm->arch.nx_huge_page_recovery_thread) kthread_stop(kvm->arch.nx_huge_page_recovery_thread); } -- 2.9.4