]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: nv: Use pgtable definitions in stage-2 walk
authorOliver Upton <oupton@kernel.org>
Mon, 24 Nov 2025 19:01:51 +0000 (11:01 -0800)
committerOliver Upton <oupton@kernel.org>
Mon, 1 Dec 2025 08:44:02 +0000 (00:44 -0800)
Use the existing page table definitions instead of magic numbers for the
stage-2 table walk.

Reviewed-by: Marc Zyngier <maz@kernel.org>
Tested-by: Marc Zyngier <maz@kernel.org>
Link: https://msgid.link/20251124190158.177318-10-oupton@kernel.org
Signed-off-by: Oliver Upton <oupton@kernel.org>
arch/arm64/kvm/nested.c

index 75d26c0ba3e0cd9d8038d6cbe546ae10a2881ceb..a096766c6ec3e598ca6cf0296ae5560d0854f86c 100644 (file)
@@ -282,14 +282,23 @@ static int walk_nested_s2_pgd(struct kvm_vcpu *vcpu, phys_addr_t ipa,
                        return ret;
 
                /* Check for valid descriptor at this point */
-               if (!(desc & 1) || ((desc & 3) == 1 && level == 3)) {
+               if (!(desc & KVM_PTE_VALID)) {
                        out->esr = compute_fsc(level, ESR_ELx_FSC_FAULT);
                        out->desc = desc;
                        return 1;
                }
 
-               /* We're at the final level or block translation level */
-               if ((desc & 3) == 1 || level == 3)
+               if (FIELD_GET(KVM_PTE_TYPE, desc) == KVM_PTE_TYPE_BLOCK) {
+                       if (level < 3)
+                               break;
+
+                       out->esr = compute_fsc(level, ESR_ELx_FSC_FAULT);
+                       out->desc = desc;
+                       return 1;
+               }
+
+               /* We're at the final level */
+               if (level == 3)
                        break;
 
                if (check_output_size(wi, desc)) {
@@ -316,7 +325,7 @@ static int walk_nested_s2_pgd(struct kvm_vcpu *vcpu, phys_addr_t ipa,
                return 1;
        }
 
-       if (!(desc & BIT(10))) {
+       if (!(desc & KVM_PTE_LEAF_ATTR_LO_S2_AF)) {
                out->esr = compute_fsc(level, ESR_ELx_FSC_ACCESS);
                out->desc = desc;
                return 1;
@@ -329,8 +338,8 @@ static int walk_nested_s2_pgd(struct kvm_vcpu *vcpu, phys_addr_t ipa,
                (ipa & GENMASK_ULL(addr_bottom - 1, 0));
        out->output = paddr;
        out->block_size = 1UL << ((3 - level) * stride + wi->pgshift);
-       out->readable = desc & (0b01 << 6);
-       out->writable = desc & (0b10 << 6);
+       out->readable = desc & KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R;
+       out->writable = desc & KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W;
        out->level = level;
        out->desc = desc;
        return 0;