Skip to content

Commit fa13843

Browse files
committed
KVM: X86: fix lazy allocation of rmaps
If allocation of rmaps fails, but some of the pointers have already been written, those pointers can be cleaned up when the memslot is freed, or even reused later for another attempt at allocating the rmaps. Therefore there is no need to WARN, as done for example in memslot_rmap_alloc, but the allocation *must* be skipped lest KVM will overwrite the previous pointer and will indeed leak memory. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e2b6d94 commit fa13843

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/x86/kvm/x86.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11392,7 +11392,8 @@ static int memslot_rmap_alloc(struct kvm_memory_slot *slot,
1139211392
int level = i + 1;
1139311393
int lpages = __kvm_mmu_slot_lpages(slot, npages, level);
1139411394

11395-
WARN_ON(slot->arch.rmap[i]);
11395+
if (slot->arch.rmap[i])
11396+
continue;
1139611397

1139711398
slot->arch.rmap[i] = kvcalloc(lpages, sz, GFP_KERNEL_ACCOUNT);
1139811399
if (!slot->arch.rmap[i]) {

0 commit comments

Comments
 (0)