Skip to contentSkip to conversation

KVM: x86/mmu: Skip rmap operations if rmaps not allocated

bug report Dan Carpenter 2 participants 2 messages Jun 25, 2021 – Jul 1, 2021 KVM

lore
Share & tools
lore
#0 lore raw

Hello Ben Gardon,

The patch e2209710ccc5: "KVM: x86/mmu: Skip rmap operations if rmaps not allocated" from May 18, 2021, leads to the following static checker warning:

	arch/x86/kvm/mmu/mmu.c:5704 kvm_mmu_zap_collapsible_sptes()
	error: uninitialized symbol 'flush'.

arch/x86/kvm/mmu/mmu.c
5687 void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
5688 const struct kvm_memory_slot *memslot)
5689 {

  5690          /* FIXME: const-ify all uses of struct kvm_memory_slot.  */
  5691          struct kvm_memory_slot *slot = (struct kvm_memory_slot *)memslot;
  5692          bool flush;
                ^^^^^^^^^^

needs to be "bool flush = false;"

5693
5694 if (kvm_memslots_have_rmaps(kvm)) {

  5695                  write_lock(&kvm->mmu_lock);
  5696                  flush = slot_handle_leaf(kvm, slot, kvm_mmu_zap_collapsible_spte, true);
  5697                  if (flush)
  5698                          kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
  5699                  write_unlock(&kvm->mmu_lock);
  5700          }
  5701  
  5702          if (is_tdp_mmu_enabled(kvm)) {
  5703                  read_lock(&kvm->mmu_lock);
  5704                  flush = kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot, flush);
                                                                             ^^^^^

Unintialized.

  5705                  if (flush)
  5706                          kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
  5707                  read_unlock(&kvm->mmu_lock);
  5708          }
  5709  }

regards,
dan carpenter

#1 lore raw

Hi Dan,

Thanks for reporting this. I believe it's already been fixed by "KVM:
x86/mmu: Fix uninitialized boolean variable flush" from Colin King.

Quoted 43 lines · Dan Carpenter

Hello Ben Gardon,

The patch e2209710ccc5: "KVM: x86/mmu: Skip rmap operations if rmaps not allocated" from May 18, 2021, leads to the following static checker warning:

arch/x86/kvm/mmu/mmu.c:5704 kvm_mmu_zap_collapsible_sptes()
error: uninitialized symbol 'flush'.

arch/x86/kvm/mmu/mmu.c
5687 void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,
5688 const struct kvm_memory_slot *memslot)
5689 {

  5690          /* FIXME: const-ify all uses of struct kvm_memory_slot.  */
  5691          struct kvm_memory_slot *slot = (struct kvm_memory_slot *)memslot;
  5692          bool flush;
                ^^^^^^^^^^

needs to be "bool flush = false;"

5693
5694 if (kvm_memslots_have_rmaps(kvm)) {

  5695                  write_lock(&kvm->mmu_lock);
  5696                  flush = slot_handle_leaf(kvm, slot, kvm_mmu_zap_collapsible_spte, true);
  5697                  if (flush)
  5698                          kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
  5699                  write_unlock(&kvm->mmu_lock);
  5700          }
  5701
  5702          if (is_tdp_mmu_enabled(kvm)) {
  5703                  read_lock(&kvm->mmu_lock);
  5704                  flush = kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot, flush);
                                                                             ^^^^^

Unintialized.

  5705                  if (flush)
  5706                          kvm_arch_flush_remote_tlbs_memslot(kvm, slot);
  5707                  read_unlock(&kvm->mmu_lock);
  5708          }
  5709  }

regards,
dan carpenter