Skip to content

Commit 6673047

Browse files
author
Marc Zyngier
committed
KVM: arm64: Mask out non-VA bits from TLBI VA* on VNCR invalidation
When handling a TLBI VA* instruction that potentially targets a VNCR page mapping, we fail to mask out the top bits that contain the ASID and TTL fields, hence potentially failing the VA check in the TLB code. An additional wrinkle is that we fail to sign extend the VA, again leading to failed VA checks. Fix both in one go by sign-extending the VA from bit 48, making it comparable to the way we interpret VNCR_EL2.BADDR. Fixes: 4ffa72a ("KVM: arm64: nv: Add S1 TLB invalidation primitive for VNCR_EL2") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 94d8897 commit 6673047

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/arm64/kvm/nested.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ static void invalidate_vncr_va(struct kvm *kvm,
918918
}
919919
}
920920

921+
#define tlbi_va_s1_to_va(v) (u64)sign_extend64((v) << 12, 48)
922+
921923
static void compute_s1_tlbi_range(struct kvm_vcpu *vcpu, u32 inst, u64 val,
922924
struct s1e2_tlbi_scope *scope)
923925
{
@@ -964,7 +966,7 @@ static void compute_s1_tlbi_range(struct kvm_vcpu *vcpu, u32 inst, u64 val,
964966
scope->size = ttl_to_size(FIELD_GET(TLBI_TTL_MASK, val));
965967
if (!scope->size)
966968
scope->size = SZ_1G;
967-
scope->va = (val << 12) & ~(scope->size - 1);
969+
scope->va = tlbi_va_s1_to_va(val) & ~(scope->size - 1);
968970
scope->asid = FIELD_GET(TLBIR_ASID_MASK, val);
969971
break;
970972
case OP_TLBI_ASIDE1:
@@ -992,7 +994,7 @@ static void compute_s1_tlbi_range(struct kvm_vcpu *vcpu, u32 inst, u64 val,
992994
scope->size = ttl_to_size(FIELD_GET(TLBI_TTL_MASK, val));
993995
if (!scope->size)
994996
scope->size = SZ_1G;
995-
scope->va = (val << 12) & ~(scope->size - 1);
997+
scope->va = tlbi_va_s1_to_va(val) & ~(scope->size - 1);
996998
break;
997999
case OP_TLBI_RVAE2:
9981000
case OP_TLBI_RVAE2IS:

0 commit comments

Comments
 (0)