[PATCH v3 06/13] iommupt/armv8: Add the 64 bit ARMv8 page table format
Nicolin Chen
nicolinc at nvidia.com
Wed Dec 2 16:15:59 PST 2026
On Sun, Nov 15, 2026 at 07:30:36PM -0400, Jason Gunthorpe wrote:
> +++ b/drivers/iommu/generic_pt/fmt/armv8.h
> @@ -0,0 +1,485 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES
> + *
> + * The page table format described by ARM DDI 0487 L.b, Chapter D8
> + * "The AArch64 Virtual Memory System Architecture" (VMSAv8-64).
> + * With the right cfg this will also implement the VMSAv8-32 Long
> + * Descriptor format.
Nit: M.d is the latest version. See if it's worth asking AI to
update it and the session numbers in the file.
> +#include <linux/limits.h>
> +#include <linux/sizes.h>
> +#include <linux/string.h>
It seems that these three headers aren't used.
> +enum {
> + PT_MAX_OUTPUT_ADDRESS_LG2 =
> + (PT_SUPPORTED_FEATURE(PT_FEAT_ARMV8_LPA2) |
> + PT_SUPPORTED_FEATURE(PT_FEAT_ARMV8_LPA)) ? 52 : 48,
> + /* See armv8pt_iommu_fmt_init() */
> + PT_MAX_VA_ADDRESS_LG2 =
> + (PT_SUPPORTED_FEATURE(PT_FEAT_ARMV8_LPA2) |
> + PT_SUPPORTED_FEATURE(PT_FEAT_ARMV8_LVA) |
> + PT_SUPPORTED_FEATURE(PT_FEAT_ARMV8_LPA)) ? 52 : 48,
> +
> + /*
> + * D24.2.195 TTBR_ELx BADDR:
> + *
> + * Bits A[(x-1):0] of the stage 1 translation table base address are
> + * zero. Address bit x is the minimum address bit required to align the
> + * translation table to the size of the table. x is calculated based on
> + * LOG2(StartTableSize), as described in VMSAv9-128. The smallest
> + * permitted value of x is 5.
The spec (M.d) defines 6:
"
D24.2.208 TTBR0_EL1, Translation Table Base Register 0 (EL1)
BADDR[47:1], bits [47:1]
When TTBR0_EL1.BADDR represents a 52-bit addresses, all of the following apply:
- Bits A[51:48] of the stage 1 translation table base address bits are in register bits[5:2].
- Register bit[1] is RES0.
- The smallest permitted value of x is 6.
- When x>6, register bits[(x-1):6] are RES0.
".
EL2 and EL3 have the same piece.
> + * R_KBLCR requires the table to be aligned to its own size.
> + *
> + * SMMU S2TTB additionally says: In addition, a 64-byte minimum
> + * alignment on starting-level translation table addresses is imposed
> + * when S2TG selects 64KB granules and the effective S2PS value
> + * indicates 52-bit output. In this case bits [5:0] are treated as zero.
I think 6 also matches the R_KBLCR here for 64-bit alignment?
> + */
> + PT_TOP_PHYS_MASK = GENMASK_ULL(51, 5),
And here, should it be GENMASK_ULL(51, 6)?
> +};
> +
> +/* Common PTE bits */
> +enum {
> + ARMV8PT_FMT_VALID = BIT(0),
> + ARMV8PT_FMT_PAGE = BIT(1),
> + ARMV8PT_FMT_TABLE = BIT(1),
> + ARMV8PT_FMT_NS = BIT(5),
NS belongs to S1 only.
For S2, bit-5 is MemAttr[3], and bit-55 is Non-secure (NS).
> + ARMV8PT_FMT_SH = GENMASK(9, 8),
> + ARMV8PT_FMT_AF = BIT(10),
> +
> + /* 64K FEAT_LPA: OA[51:48] in bits[15:12], Figures D8-14/15 */
> + ARMV8PT_FMT_OA52_LPA = GENMASK_ULL(15, 12),
> + /* 4K/16K FEAT_LPA2 (DS=1): OA[51:50] in bits[9:8], Figures D8-14/15 */
> + ARMV8PT_FMT_OA52_LPA2 = GENMASK_ULL(9, 8),
> +
> + ARMV8PT_FMT_CONTIG = BIT_ULL(52),
> + ARMV8PT_FMT_UXN = BIT_ULL(53),
> + ARMV8PT_FMT_PXN = BIT_ULL(54),
The bits for UXN and PXN are swapped. And S2 doesn't define them
as UXN and PXN but XN[1:0],
Perhaps move UXN/PXN to "S1 PTE bits" and add an ARMV8PT_FMT_S2NX
to "S2 PTE bits"?
> + ARMV8PT_FMT_NSTABLE = BIT_ULL(63),
This doesn't seem to be common but S1 only.
Bit-63 NSTABLE is only defined in
Table D8-50 Stage 1 VMSAv8-64 Table descriptor fields
not in
Table D8-51 Stage 2 VMSAv8-64 Table descriptor fields
Table D8-52 Stage 1 VMSAv8-64 Block and Page descriptor fields
Table D8-53 Stage 2 VMSAv8-64 Block and Page descriptor fields
> +/* Number contiguous entries that ARMV8PT_FMT_CONTIG will join at this level */
> +static inline unsigned short
> +armv8pt_contig_count_lg2(const struct pt_state *pts)
> +{
> + unsigned int tgsz_lg2 = armv8pt_tgsz_lg2(pts);
> +
> + if (tgsz_lg2 == SZLG2_4K)
> + return ilog2(16); /* 64KB, 32MB, 16GB, 8TB */
> + else if (tgsz_lg2 == SZLG2_16K && pts->level == ARML2)
> + return ilog2(32); /* 1GB */
> + else if (tgsz_lg2 == SZLG2_16K && pts->level == ARML3)
> + return ilog2(128); /* 2MB */
> + else if (tgsz_lg2 == SZLG2_64K)
> + return ilog2(32); /* 2MB, 16GB, 128TB */
> + return ilog2(1);
> +}
In "D8.7.1 The Contiguous bit", I don't see the 8TB and 128TB
being listed.
Also, should SZLG2_64K check level == ARML2 or ARML3?
> +static inline u64 armv8pt_sw_bit(unsigned int bitnr)
> +{
> + if (__builtin_constant_p(bitnr) && bitnr > 3)
> + BUILD_BUG();
> +
> + /*
> + * D8.3 Tables D8-50 through D8-53: Bits marked IGNORED in Table
> + * descriptors and "Reserved for software use" in Block and Page
> + * descriptors.
> + *
> + * Bits [58:56] are safe for all descriptor types at both stage 1
> + * and stage 2. Bit [55] is additionally available at stage 1
> + * (Table D8-52).
Per Table D8-53 Stage 2 VMSAv8-64 Block and Page descriptor fields,
bit-58 is only available for stage 2 when VTCR_EL2.AssuredOnly=0.
Nicolin
More information about the linux-arm-kernel
mailing list