KVM: x86/hyper-v: Use preallocated per-vCPU buffer for de-sparsified vCPU masks
authorSean Christopherson <seanjc@google.com>
Fri, 13 Jun 2025 19:39:22 +0000 (12:39 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 24 Jun 2025 19:20:16 +0000 (12:20 -0700)
Use a preallocated per-vCPU bitmap for tracking the unpacked set of vCPUs
being targeted for Hyper-V's paravirt TLB flushing.  If KVM_MAX_NR_VCPUS
is set to 4096 (which is allowed even for MAXSMP=n builds), putting the
vCPU mask on-stack pushes kvm_hv_flush_tlb() past the default FRAME_WARN
limit.

  arch/x86/kvm/hyperv.c:2001:12: error: stack frame size (1288) exceeds limit (1024)
                                 in 'kvm_hv_flush_tlb' [-Werror,-Wframe-larger-than]
  2001 | static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
       |            ^
  1 error generated.

Note, sparse_banks was given the same treatment by commit 7d5e88d301f8
("KVM: x86: hyper-v: Use preallocated buffer in 'struct kvm_vcpu_hv'
instead of on-stack 'sparse_banks'"), for the exact same reason.

Reported-by: Abinash Lalotra <abinashsinghlalotra@gmail.com>
Closes: https://lore.kernel.org/all/20250613111023.786265-1-abinashsinghlalotra@gmail.com
Link: https://lore.kernel.org/all/aEylI-O8kFnFHrOH@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/hyperv.c

index b4a391929cdbaa9960e870ade649606bdcab2e9a..ee43615d96d86cb13cef5ebf6d011ac5c8dcd7e2 100644 (file)
@@ -700,8 +700,13 @@ struct kvm_vcpu_hv {
 
        struct kvm_vcpu_hv_tlb_flush_fifo tlb_flush_fifo[HV_NR_TLB_FLUSH_FIFOS];
 
-       /* Preallocated buffer for handling hypercalls passing sparse vCPU set */
+       /*
+        * Preallocated buffers for handling hypercalls that pass sparse vCPU
+        * sets (for high vCPU counts, they're too large to comfortably fit on
+        * the stack).
+        */
        u64 sparse_banks[HV_MAX_SPARSE_VCPU_BANKS];
+       DECLARE_BITMAP(vcpu_mask, KVM_MAX_VCPUS);
 
        struct hv_vp_assist_page vp_assist_page;
 
index 24f0318c50d790ce70b04f3b61a827d4768da3da..75221a11e15e59fc930c77e7da0c1cbff41e1fb9 100644 (file)
@@ -2001,11 +2001,11 @@ out_flush_all:
 static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
 {
        struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
+       unsigned long *vcpu_mask = hv_vcpu->vcpu_mask;
        u64 *sparse_banks = hv_vcpu->sparse_banks;
        struct kvm *kvm = vcpu->kvm;
        struct hv_tlb_flush_ex flush_ex;
        struct hv_tlb_flush flush;
-       DECLARE_BITMAP(vcpu_mask, KVM_MAX_VCPUS);
        struct kvm_vcpu_hv_tlb_flush_fifo *tlb_flush_fifo;
        /*
         * Normally, there can be no more than 'KVM_HV_TLB_FLUSH_FIFO_SIZE'