* [PATCH 0/2] KVM: x86: Fix UBSAN bool warnings in module parameters @ 2026-02-10 6:46 Gal Pressman 2026-02-10 6:46 ` [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter Gal Pressman 2026-02-10 6:46 ` [PATCH 2/2] KVM: x86/mmu: Fix UBSAN warning when reading nx_huge_pages parameter Gal Pressman 0 siblings, 2 replies; 7+ messages in thread From: Gal Pressman @ 2026-02-10 6:46 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Naveen N Rao, kvm, linux-kernel Cc: Gal Pressman Several KVM module parameters use int to support a special -1 (auto) value, but rely on param_get_bool() for the sysfs getter. When userspace reads these parameters before the auto value is resolved, param_get_bool() interprets the int as a bool, triggering UBSAN "load of value 255 is not a valid value for type '_Bool'" warnings. Fix both instances by implementing getter functions that handle the -1 case before falling through to param_get_bool(). Gal Pressman (2): KVM: SVM: Fix UBSAN warning when reading avic parameter KVM: x86/mmu: Fix UBSAN warning when reading nx_huge_pages parameter arch/x86/kvm/mmu/mmu.c | 5 +++++ arch/x86/kvm/svm/avic.c | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) -- 2.52.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter 2026-02-10 6:46 [PATCH 0/2] KVM: x86: Fix UBSAN bool warnings in module parameters Gal Pressman @ 2026-02-10 6:46 ` Gal Pressman 2026-02-23 16:38 ` Naveen N Rao 2026-02-10 6:46 ` [PATCH 2/2] KVM: x86/mmu: Fix UBSAN warning when reading nx_huge_pages parameter Gal Pressman 1 sibling, 1 reply; 7+ messages in thread From: Gal Pressman @ 2026-02-10 6:46 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Naveen N Rao, kvm, linux-kernel Cc: Gal Pressman, Dragos Tatulea The avic parameter is stored as an int to support the special value -1 (AVIC_AUTO_MODE), but the cited commit changed it from bool to int while keeping param_get_bool() as the getter function. This causes UBSAN to report "load of value 255 is not a valid value for type '_Bool'" when the parameter is read via sysfs. The issue happens in two scenarios: 1. During module load: There's a time window between when module parameters are registered, and when avic_hardware_setup() runs to resolve the value, where the value is -1. 2. On non-AMD systems: On non-AMD hardware, the kvm_is_svm_supported() check returns early. The avic_hardware_setup() function never runs, so avic remains -1. Fix that by implementing a getter function that properly reads and converts the -1 value into an 'auto' string. Triggered by sos report: UBSAN: invalid-load in kernel/params.c:323:33 load of value 255 is not a valid value for type '_Bool' CPU: 0 UID: 0 PID: 4667 Comm: sos Not tainted 6.19.0-rc5net_mlx5_1e86836 #1 NONE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x69/0xa0 ubsan_epilogue+0x5/0x2b __ubsan_handle_load_invalid_value.cold+0x47/0x4c ? lock_acquire+0x219/0x2c0 param_get_bool.cold+0xf/0x14 param_attr_show+0x51/0x80 module_attr_show+0x19/0x30 sysfs_kf_seq_show+0xac/0xf0 seq_read_iter+0x100/0x410 copy_splice_read+0x1b4/0x360 splice_direct_to_actor+0xbd/0x270 ? wait_for_space+0xb0/0xb0 do_splice_direct+0x72/0xb0 ? propagate_umount+0x870/0x870 do_sendfile+0x3a3/0x470 __x64_sys_sendfile64+0x5e/0xe0 do_syscall_64+0x70/0x8c0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 Fixes: ca2967de5a5b ("KVM: SVM: Enable AVIC by default for Zen4+ if x2AVIC is support") Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Gal Pressman <gal@nvidia.com> --- arch/x86/kvm/svm/avic.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 6b77b2033208..48de0f475ca5 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -19,6 +19,7 @@ #include <linux/amd-iommu.h> #include <linux/kvm_host.h> #include <linux/kvm_irqfd.h> +#include <linux/sysfs.h> #include <asm/irq_remapping.h> #include <asm/msr.h> @@ -76,10 +77,20 @@ static int avic_param_set(const char *val, const struct kernel_param *kp) return param_set_bint(val, kp); } +static int avic_param_get(char *buffer, const struct kernel_param *kp) +{ + int val = *(int *)kp->arg; + + if (val == AVIC_AUTO_MODE) + return sysfs_emit(buffer, "auto\n"); + + return param_get_bool(buffer, kp); +} + static const struct kernel_param_ops avic_ops = { .flags = KERNEL_PARAM_OPS_FL_NOARG, .set = avic_param_set, - .get = param_get_bool, + .get = avic_param_get, }; /* -- 2.52.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter 2026-02-10 6:46 ` [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter Gal Pressman @ 2026-02-23 16:38 ` Naveen N Rao 2026-02-24 9:18 ` Gal Pressman 0 siblings, 1 reply; 7+ messages in thread From: Naveen N Rao @ 2026-02-23 16:38 UTC (permalink / raw) To: Gal Pressman Cc: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel, Dragos Tatulea On Tue, Feb 10, 2026 at 08:46:20AM +0200, Gal Pressman wrote: > > +static int avic_param_get(char *buffer, const struct kernel_param *kp) > +{ > + int val = *(int *)kp->arg; > + > + if (val == AVIC_AUTO_MODE) > + return sysfs_emit(buffer, "auto\n"); My preference would be to return 'N' here, so that this continues to return a boolean value when read. - Naveen ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter 2026-02-23 16:38 ` Naveen N Rao @ 2026-02-24 9:18 ` Gal Pressman 2026-02-25 6:27 ` Naveen N Rao 0 siblings, 1 reply; 7+ messages in thread From: Gal Pressman @ 2026-02-24 9:18 UTC (permalink / raw) To: Naveen N Rao Cc: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel, Dragos Tatulea On 23/02/2026 18:38, Naveen N Rao wrote: > On Tue, Feb 10, 2026 at 08:46:20AM +0200, Gal Pressman wrote: >> >> +static int avic_param_get(char *buffer, const struct kernel_param *kp) >> +{ >> + int val = *(int *)kp->arg; >> + >> + if (val == AVIC_AUTO_MODE) >> + return sysfs_emit(buffer, "auto\n"); > > My preference would be to return 'N' here, so that this continues to > return a boolean value when read. I guess the boolean conversion used to return 'Y' before this patch, why is 'N' better? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter 2026-02-24 9:18 ` Gal Pressman @ 2026-02-25 6:27 ` Naveen N Rao 2026-02-25 6:48 ` Gal Pressman 0 siblings, 1 reply; 7+ messages in thread From: Naveen N Rao @ 2026-02-25 6:27 UTC (permalink / raw) To: Gal Pressman Cc: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel, Dragos Tatulea On Tue, Feb 24, 2026 at 11:18:01AM +0200, Gal Pressman wrote: > On 23/02/2026 18:38, Naveen N Rao wrote: > > On Tue, Feb 10, 2026 at 08:46:20AM +0200, Gal Pressman wrote: > >> > >> +static int avic_param_get(char *buffer, const struct kernel_param *kp) > >> +{ > >> + int val = *(int *)kp->arg; > >> + > >> + if (val == AVIC_AUTO_MODE) > >> + return sysfs_emit(buffer, "auto\n"); > > > > My preference would be to return 'N' here, so that this continues to > > return a boolean value when read. > > I guess the boolean conversion used to return 'Y' before this patch, why > is 'N' better? Because that would reflect the state of AVIC more accurately: - in the case of kvm-amd module still being loaded, AVIC has not yet been enabled, and - in the case of a non-AMD system, AVIC is not enabled and is not active. Also, note that AVIC used to default to 'N' until recently. - Naveen ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter 2026-02-25 6:27 ` Naveen N Rao @ 2026-02-25 6:48 ` Gal Pressman 0 siblings, 0 replies; 7+ messages in thread From: Gal Pressman @ 2026-02-25 6:48 UTC (permalink / raw) To: Naveen N Rao Cc: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, kvm, linux-kernel, Dragos Tatulea On 25/02/2026 8:27, Naveen N Rao wrote: > On Tue, Feb 24, 2026 at 11:18:01AM +0200, Gal Pressman wrote: >> On 23/02/2026 18:38, Naveen N Rao wrote: >>> On Tue, Feb 10, 2026 at 08:46:20AM +0200, Gal Pressman wrote: >>>> >>>> +static int avic_param_get(char *buffer, const struct kernel_param *kp) >>>> +{ >>>> + int val = *(int *)kp->arg; >>>> + >>>> + if (val == AVIC_AUTO_MODE) >>>> + return sysfs_emit(buffer, "auto\n"); >>> >>> My preference would be to return 'N' here, so that this continues to >>> return a boolean value when read. >> >> I guess the boolean conversion used to return 'Y' before this patch, why >> is 'N' better? > > Because that would reflect the state of AVIC more accurately: > - in the case of kvm-amd module still being loaded, AVIC has not yet > been enabled, and > - in the case of a non-AMD system, AVIC is not enabled and is not > active. > > Also, note that AVIC used to default to 'N' until recently. Will change in v2, thanks for the review. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] KVM: x86/mmu: Fix UBSAN warning when reading nx_huge_pages parameter 2026-02-10 6:46 [PATCH 0/2] KVM: x86: Fix UBSAN bool warnings in module parameters Gal Pressman 2026-02-10 6:46 ` [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter Gal Pressman @ 2026-02-10 6:46 ` Gal Pressman 1 sibling, 0 replies; 7+ messages in thread From: Gal Pressman @ 2026-02-10 6:46 UTC (permalink / raw) To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Naveen N Rao, kvm, linux-kernel Cc: Gal Pressman, Dragos Tatulea The nx_huge_pages parameter is stored as an int (initialized to -1 to indicate auto mode), but get_nx_huge_pages() calls param_get_bool() which expects a bool pointer. This causes UBSAN to report "load of value 255 is not a valid value for type '_Bool'" when the parameter is read via sysfs during a narrow time window. The issue occurs during module load: the module parameter is registered and its sysfs file becomes readable before the kvm_mmu_x86_module_init() function runs: 1. Module load begins, static variable initialized to -1 2. mod_sysfs_setup() creates /sys/module/kvm/parameters/nx_huge_pages 3. (Parameter readable, value = -1) 4. do_init_module() runs kvm_x86_init() 5. kvm_mmu_x86_module_init() resolves -1 to bool If userspace (e.g., sos report) reads the parameter during step 3, param_get_bool() dereferences the int as a bool, triggering the UBSAN warning. Fix that by properly reading and converting the -1 value into an 'auto' string. Fixes: b8e8c8303ff2 ("kvm: mmu: ITLB_MULTIHIT mitigation") Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Gal Pressman <gal@nvidia.com> --- arch/x86/kvm/mmu/mmu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 02c450686b4a..3644d1db8be1 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -7488,9 +7488,14 @@ static void kvm_wake_nx_recovery_thread(struct kvm *kvm) static int get_nx_huge_pages(char *buffer, const struct kernel_param *kp) { + int val = *(int *)kp->arg; + if (nx_hugepage_mitigation_hard_disabled) return sysfs_emit(buffer, "never\n"); + if (val == -1) + return sysfs_emit(buffer, "auto\n"); + return param_get_bool(buffer, kp); } -- 2.52.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-25 6:48 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-02-10 6:46 [PATCH 0/2] KVM: x86: Fix UBSAN bool warnings in module parameters Gal Pressman 2026-02-10 6:46 ` [PATCH 1/2] KVM: SVM: Fix UBSAN warning when reading avic parameter Gal Pressman 2026-02-23 16:38 ` Naveen N Rao 2026-02-24 9:18 ` Gal Pressman 2026-02-25 6:27 ` Naveen N Rao 2026-02-25 6:48 ` Gal Pressman 2026-02-10 6:46 ` [PATCH 2/2] KVM: x86/mmu: Fix UBSAN warning when reading nx_huge_pages parameter Gal Pressman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®