Skip to content

Commit a7ef9b4

Browse files
committed
KVM: x86: hyper-v: fix type of valid_bank_mask
In kvm_hv_flush_tlb(), valid_bank_mask is declared as unsigned long, but is used as u64, which is wrong for i386, and has been spotted by LKP after applying "KVM: x86: hyper-v: replace bitmap_weight() with hweight64()" https://lore.kernel.org/lkml/[email protected]/ But it's wrong even without that patch because now bitmap_weight() dereferences a word after valid_bank_mask on i386. >> include/asm-generic/bitops/const_hweight.h:21:76: warning: right shift count >= width of type +[-Wshift-count-overflow] 21 | #define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32)) | ^~ include/asm-generic/bitops/const_hweight.h:10:16: note: in definition of macro '__const_hweight8' 10 | ((!!((w) & (1ULL << 0))) + \ | ^ include/asm-generic/bitops/const_hweight.h:20:31: note: in expansion of macro '__const_hweight16' 20 | #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) | ^~~~~~~~~~~~~~~~~ include/asm-generic/bitops/const_hweight.h:21:54: note: in expansion of macro '__const_hweight32' 21 | #define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32)) | ^~~~~~~~~~~~~~~~~ include/asm-generic/bitops/const_hweight.h:29:49: note: in expansion of macro '__const_hweight64' 29 | #define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w)) | ^~~~~~~~~~~~~~~~~ arch/x86/kvm/hyperv.c:1983:36: note: in expansion of macro 'hweight64' 1983 | if (hc->var_cnt != hweight64(valid_bank_mask)) | ^~~~~~~~~ CC: Borislav Petkov <[email protected]> CC: Dave Hansen <[email protected]> CC: H. Peter Anvin <[email protected]> CC: Ingo Molnar <[email protected]> CC: Jim Mattson <[email protected]> CC: Joerg Roedel <[email protected]> CC: Paolo Bonzini <[email protected]> CC: Sean Christopherson <[email protected]> CC: Thomas Gleixner <[email protected]> CC: Vitaly Kuznetsov <[email protected]> CC: Wanpeng Li <[email protected]> CC: [email protected] CC: [email protected] CC: [email protected] Reported-by: kernel test robot <[email protected]> Signed-off-by: Yury Norov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a570e68 commit a7ef9b4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kvm/hyperv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
19381938
struct hv_send_ipi_ex send_ipi_ex;
19391939
struct hv_send_ipi send_ipi;
19401940
DECLARE_BITMAP(vcpu_mask, KVM_MAX_VCPUS);
1941-
unsigned long valid_bank_mask;
1941+
u64 valid_bank_mask;
19421942
u64 sparse_banks[KVM_HV_MAX_SPARSE_VCPU_SET_BITS];
19431943
u32 vector;
19441944
bool all_cpus;
@@ -1980,7 +1980,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
19801980
valid_bank_mask = send_ipi_ex.vp_set.valid_bank_mask;
19811981
all_cpus = send_ipi_ex.vp_set.format == HV_GENERIC_SET_ALL;
19821982

1983-
if (hc->var_cnt != bitmap_weight(&valid_bank_mask, 64))
1983+
if (hc->var_cnt != bitmap_weight((unsigned long *)&valid_bank_mask, 64))
19841984
return HV_STATUS_INVALID_HYPERCALL_INPUT;
19851985

19861986
if (all_cpus)

0 commit comments

Comments
 (0)