Skip to content

Commit f58e4ec

Browse files
paulusmackgregkh
authored andcommitted
KVM: PPC: Book3S HV: Fix handling of secondary HPTEG in HPT resizing code
[ Upstream commit 05f2bb0 ] This fixes the computation of the HPTE index to use when the HPT resizing code encounters a bolted HPTE which is stored in its secondary HPTE group. The code inverts the HPTE group number, which is correct, but doesn't then mask it with new_hash_mask. As a result, new_pteg will be effectively negative, resulting in new_hptep pointing before the new HPT, which will corrupt memory. In addition, this removes two BUG_ON statements. The condition that the BUG_ONs were testing -- that we have computed the hash value incorrectly -- has never been observed in testing, and if it did occur, would only affect the guest, not the host. Given that BUG_ON should only be used in conditions where the kernel (i.e. the host kernel, in this case) can't possibly continue execution, it is not appropriate here. Reviewed-by: David Gibson <[email protected]> Signed-off-by: Paul Mackerras <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d6b0049 commit f58e4ec

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

arch/powerpc/kvm/book3s_64_mmu_hv.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,12 +1348,8 @@ static unsigned long resize_hpt_rehash_hpte(struct kvm_resize_hpt *resize,
13481348
}
13491349

13501350
new_pteg = hash & new_hash_mask;
1351-
if (vpte & HPTE_V_SECONDARY) {
1352-
BUG_ON(~pteg != (hash & old_hash_mask));
1353-
new_pteg = ~new_pteg;
1354-
} else {
1355-
BUG_ON(pteg != (hash & old_hash_mask));
1356-
}
1351+
if (vpte & HPTE_V_SECONDARY)
1352+
new_pteg = ~hash & new_hash_mask;
13571353

13581354
new_idx = new_pteg * HPTES_PER_GROUP + (idx % HPTES_PER_GROUP);
13591355
new_hptep = (__be64 *)(new->virt + (new_idx << 4));

0 commit comments

Comments
 (0)