]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/xen: Bug the VM if 32-bit KVM observes a 64-bit mode hypercall
authorSean Christopherson <seanjc@google.com>
Fri, 29 May 2026 22:21:45 +0000 (15:21 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 3 Jun 2026 12:34:46 +0000 (05:34 -0700)
Bug the VM if 32-bit KVM attempts to handle a 64-bit hypercall, primarily
so that a future change to set "input" in mode-specific code doesn't
trigger a false positive warn=>error:

  arch/x86/kvm/xen.c:1687:6: error: variable 'input' is used uninitialized
                                    whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
   1687 |         if (!longmode) {
        |             ^~~~~~~~~
  arch/x86/kvm/xen.c:1708:31: note: uninitialized use occurs here
   1708 |         trace_kvm_xen_hypercall(cpl, input, params[0], params[1], params[2],
        |                                      ^~~~~
  x86/kvm/xen.c:1687:2: note: remove the 'if' if its condition is always true
   1687 |         if (!longmode) {
        |         ^~~~~~~~~~~~~~
  arch/x86/kvm/xen.c:1677:11: note: initialize the variable 'input' to silence this warning
   1677 |         u64 input, params[6], r = -ENOSYS;
        |                  ^
  1 error generated.

Note, params[] also has the same flaw, but -Wsometimes-uninitialized
doesn't seem to be enforced for arrays, presumably because it's difficult
to avoid false positives on specific entries.

Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Link: https://patch.msgid.link/20260529222223.870923-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/xen.c

index 91fd3673c09a2ef3dc154050e01df608182e59e5..6d9be74bb673c477e12067cf9ab739ada4a0cb01 100644 (file)
@@ -1694,16 +1694,19 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
                params[4] = (u32)kvm_rdi_read(vcpu);
                params[5] = (u32)kvm_rbp_read(vcpu);
        }
-#ifdef CONFIG_X86_64
        else {
+#ifdef CONFIG_X86_64
                params[0] = (u64)kvm_rdi_read(vcpu);
                params[1] = (u64)kvm_rsi_read(vcpu);
                params[2] = (u64)kvm_rdx_read(vcpu);
                params[3] = (u64)kvm_r10_read(vcpu);
                params[4] = (u64)kvm_r8_read(vcpu);
                params[5] = (u64)kvm_r9_read(vcpu);
-       }
+#else
+               KVM_BUG_ON(1, vcpu->kvm);
+               return -EIO;
 #endif
+       }
        cpl = kvm_x86_call(get_cpl)(vcpu);
        trace_kvm_xen_hypercall(cpl, input, params[0], params[1], params[2],
                                params[3], params[4], params[5]);