Skip to content

Commit ebb2d8f

Browse files
GAP-devoupton
authored andcommitted
KVM: arm64: nv: Fix incorrect VNCR invalidation range calculation
The code for invalidating VNCR entries in both kvm_invalidate_vncr_ipa() and invalidate_vncr_va() incorrectly uses a bitwise AND with `(size - 1)` instead of `~(size - 1)` to align the start address. This results in masking the address bits instead of aligning them down to the start of the block. This bug may cause stale VNCR TLB entries to remain valid even after a TLBI or MMU notifier, leading to incorrect memory translation and unexpected guest behavior. Credit to Team 0xB6 in bob14: DongHa Lee, Gyujeong Jin, Daehyeon Ko, Geonha Lee, Hyungyu Oh, and Jaewon Yang. Reviewed-by: Marc Zyngier <[email protected]> Signed-off-by: Dongha Lee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 13bba09 commit ebb2d8f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/kvm/nested.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static void kvm_invalidate_vncr_ipa(struct kvm *kvm, u64 start, u64 end)
847847

848848
ipa_size = ttl_to_size(pgshift_level_to_ttl(vt->wi.pgshift,
849849
vt->wr.level));
850-
ipa_start = vt->wr.pa & (ipa_size - 1);
850+
ipa_start = vt->wr.pa & ~(ipa_size - 1);
851851
ipa_end = ipa_start + ipa_size;
852852

853853
if (ipa_end <= start || ipa_start >= end)
@@ -887,7 +887,7 @@ static void invalidate_vncr_va(struct kvm *kvm,
887887

888888
va_size = ttl_to_size(pgshift_level_to_ttl(vt->wi.pgshift,
889889
vt->wr.level));
890-
va_start = vt->gva & (va_size - 1);
890+
va_start = vt->gva & ~(va_size - 1);
891891
va_end = va_start + va_size;
892892

893893
switch (scope->type) {

0 commit comments

Comments
 (0)