From 1186befb7e37ab4ff9374f64116d588b3c32b95b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 7 Sep 2023 12:25:41 +0100 Subject: [PATCH] 6.1-stable patches added patches: kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch --- ...ow-sticky-disabling-of-nx_huge_pages.patch | 135 ++++++++++++++++++ ...-use-kstrtobool-instead-of-strtobool.patch | 45 ++++++ queue-6.1/series | 2 + 3 files changed, 182 insertions(+) create mode 100644 queue-6.1/kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch create mode 100644 queue-6.1/kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch diff --git a/queue-6.1/kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch b/queue-6.1/kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch new file mode 100644 index 00000000000..1287ba94b26 --- /dev/null +++ b/queue-6.1/kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch @@ -0,0 +1,135 @@ +From 0b210faf337314e4bc88e796218bc70c72a51209 Mon Sep 17 00:00:00 2001 +From: Sean Christopherson +Date: Thu, 1 Jun 2023 17:58:59 -0700 +Subject: KVM: x86/mmu: Add "never" option to allow sticky disabling of nx_huge_pages + +From: Sean Christopherson + +commit 0b210faf337314e4bc88e796218bc70c72a51209 upstream. + +Add a "never" option to the nx_huge_pages module param to allow userspace +to do a one-way hard disabling of the mitigation, and don't create the +per-VM recovery threads when the mitigation is hard disabled. Letting +userspace pinky swear that userspace doesn't want to enable NX mitigation +(without reloading KVM) allows certain use cases to avoid the latency +problems associated with spawning a kthread for each VM. + +E.g. in FaaS use cases, the guest kernel is trusted and the host may +create 100+ VMs per logical CPU, which can result in 100ms+ latencies when +a burst of VMs is created. + +Reported-by: Li RongQing +Closes: https://lore.kernel.org/all/1679555884-32544-1-git-send-email-lirongqing@baidu.com +Cc: Yong He +Cc: Robert Hoo +Cc: Kai Huang +Reviewed-by: Robert Hoo +Acked-by: Kai Huang +Tested-by: Luiz Capitulino +Reviewed-by: Li RongQing +Link: https://lore.kernel.org/r/20230602005859.784190-1-seanjc@google.com +Signed-off-by: Sean Christopherson +[ Resolved a small conflict in arch/x86/kvm/mmu/mmu.c::kvm_mmu_post_init_vm() + which is due kvm_nx_lpage_recovery_worker() being renamed in upstream + commit 55c510e26ab6181c132327a8b90c864e6193ce27 ] +Signed-off-by: Luiz Capitulino +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/mmu/mmu.c | 41 ++++++++++++++++++++++++++++++++++++----- + 1 file changed, 36 insertions(+), 5 deletions(-) + +--- a/arch/x86/kvm/mmu/mmu.c ++++ b/arch/x86/kvm/mmu/mmu.c +@@ -56,6 +56,8 @@ + + extern bool itlb_multihit_kvm_mitigation; + ++static bool nx_hugepage_mitigation_hard_disabled; ++ + int __read_mostly nx_huge_pages = -1; + static uint __read_mostly nx_huge_pages_recovery_period_ms; + #ifdef CONFIG_PREEMPT_RT +@@ -65,12 +67,13 @@ static uint __read_mostly nx_huge_pages_ + static uint __read_mostly nx_huge_pages_recovery_ratio = 60; + #endif + ++static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp); + static int set_nx_huge_pages(const char *val, const struct kernel_param *kp); + static int set_nx_huge_pages_recovery_param(const char *val, const struct kernel_param *kp); + + static const struct kernel_param_ops nx_huge_pages_ops = { + .set = set_nx_huge_pages, +- .get = param_get_bool, ++ .get = get_nx_huge_pages, + }; + + static const struct kernel_param_ops nx_huge_pages_recovery_param_ops = { +@@ -6645,6 +6648,14 @@ static void mmu_destroy_caches(void) + kmem_cache_destroy(mmu_page_header_cache); + } + ++static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp) ++{ ++ if (nx_hugepage_mitigation_hard_disabled) ++ return sprintf(buffer, "never\n"); ++ ++ return param_get_bool(buffer, kp); ++} ++ + static bool get_nx_auto_mode(void) + { + /* Return true when CPU has the bug, and mitigations are ON */ +@@ -6661,15 +6672,29 @@ static int set_nx_huge_pages(const char + bool old_val = nx_huge_pages; + bool new_val; + ++ if (nx_hugepage_mitigation_hard_disabled) ++ return -EPERM; ++ + /* In "auto" mode deploy workaround only if CPU has the bug. */ +- if (sysfs_streq(val, "off")) ++ if (sysfs_streq(val, "off")) { + new_val = 0; +- else if (sysfs_streq(val, "force")) ++ } else if (sysfs_streq(val, "force")) { + new_val = 1; +- else if (sysfs_streq(val, "auto")) ++ } else if (sysfs_streq(val, "auto")) { + new_val = get_nx_auto_mode(); +- else if (kstrtobool(val, &new_val) < 0) ++ } else if (sysfs_streq(val, "never")) { ++ new_val = 0; ++ ++ mutex_lock(&kvm_lock); ++ if (!list_empty(&vm_list)) { ++ mutex_unlock(&kvm_lock); ++ return -EBUSY; ++ } ++ nx_hugepage_mitigation_hard_disabled = true; ++ mutex_unlock(&kvm_lock); ++ } else if (kstrtobool(val, &new_val) < 0) { + return -EINVAL; ++ } + + __set_nx_huge_pages(new_val); + +@@ -6800,6 +6825,9 @@ static int set_nx_huge_pages_recovery_pa + uint old_period, new_period; + int err; + ++ if (nx_hugepage_mitigation_hard_disabled) ++ return -EPERM; ++ + was_recovery_enabled = calc_nx_huge_pages_recovery_period(&old_period); + + err = param_set_uint(val, kp); +@@ -6923,6 +6951,9 @@ int kvm_mmu_post_init_vm(struct kvm *kvm + { + int err; + ++ if (nx_hugepage_mitigation_hard_disabled) ++ return 0; ++ + err = kvm_vm_create_worker_thread(kvm, kvm_nx_lpage_recovery_worker, 0, + "kvm-nx-lpage-recovery", + &kvm->arch.nx_lpage_recovery_thread); diff --git a/queue-6.1/kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch b/queue-6.1/kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch new file mode 100644 index 00000000000..a718ef1d382 --- /dev/null +++ b/queue-6.1/kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch @@ -0,0 +1,45 @@ +From 11b36fe7d4500c8ef73677c087f302fd713101c2 Mon Sep 17 00:00:00 2001 +From: Christophe JAILLET +Date: Sat, 14 Jan 2023 10:39:11 +0100 +Subject: KVM: x86/mmu: Use kstrtobool() instead of strtobool() + +From: Christophe JAILLET + +commit 11b36fe7d4500c8ef73677c087f302fd713101c2 upstream. + +strtobool() is the same as kstrtobool(). +However, the latter is more used within the kernel. + +In order to remove strtobool() and slightly simplify kstrtox.h, switch to +the other function name. + +While at it, include the corresponding header file () + +Signed-off-by: Christophe JAILLET +Link: https://lore.kernel.org/r/670882aa04dbdd171b46d3b20ffab87158454616.1673689135.git.christophe.jaillet@wanadoo.fr +Signed-off-by: Sean Christopherson +Signed-off-by: Luiz Capitulino +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/mmu/mmu.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/arch/x86/kvm/mmu/mmu.c ++++ b/arch/x86/kvm/mmu/mmu.c +@@ -42,6 +42,7 @@ + #include + #include + #include ++#include + #include + + #include +@@ -6667,7 +6668,7 @@ static int set_nx_huge_pages(const char + new_val = 1; + else if (sysfs_streq(val, "auto")) + new_val = get_nx_auto_mode(); +- else if (strtobool(val, &new_val) < 0) ++ else if (kstrtobool(val, &new_val) < 0) + return -EINVAL; + + __set_nx_huge_pages(new_val); diff --git a/queue-6.1/series b/queue-6.1/series index fc6ef7ddae7..72622fa9952 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -79,3 +79,5 @@ of-property-simplify-of_link_to_phandle.patch cpufreq-intel_pstate-set-stale-cpu-frequency-to-minimum.patch crypto-rsa-pkcs1pad-use-helper-to-set-reqsize.patch tpm-enable-hwrng-only-for-pluton-on-amd-cpus.patch +kvm-x86-mmu-use-kstrtobool-instead-of-strtobool.patch +kvm-x86-mmu-add-never-option-to-allow-sticky-disabling-of-nx_huge_pages.patch -- 2.47.3