Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <iommu@lists.linux.dev>, "Joerg Roedel (AMD)" <joro@8bytes.org>,
	Jean-Philippe Brucker <jpb@kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Will Deacon <will@kernel.org>,
	David Matlack <dmatlack@google.com>,
	"John Garry" <john.garry@arm.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	<patches@lists.linux.dev>, Pranjal Shrivastava <praan@google.com>,
	"Samiullah Khawaja" <skhawaja@google.com>,
	Mostafa Saleh <smostafa@google.com>
Subject: Re: [PATCH v3 06/13] iommupt/armv8: Add the 64 bit ARMv8 page table format
Date: Wed, 2 Dec 2026 16:15:59 -0800	[thread overview]
Message-ID: <axC0v8xs5P4cxh6e@nvidia.com> (raw)
In-Reply-To: <6-v3-97feb2edfbab+748d0a-iommupt_armv8_jgg@nvidia.com>

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


  reply	other threads:[~2026-12-03  0:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 23:30 [PATCH v3 00/13] Use the generic iommu page table for SMMUv3 Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 01/13] iommu/arm-smmu-v3: Change how the tlbi describes the invalidation Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 02/13] iommu/arm-smmu-v3: Support the DS expansion of range invalidation SCALE Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 03/13] iommupt: Remove the sanity check for pt_num_items_lg2() at the top level Jason Gunthorpe
2026-11-24  0:40   ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 04/13] iommupt/kunit: Do not test INCOHERENT on anything but x86 Jason Gunthorpe
2026-11-24  0:49   ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 05/13] iommupt/kunit: Skip test configs without supported features Jason Gunthorpe
2026-11-24  5:29   ` Nicolin Chen
2026-11-24 15:08     ` Jason Gunthorpe
2026-11-24 19:08       ` Nicolin Chen
2026-11-24 20:07         ` Jason Gunthorpe
2026-11-26  5:00           ` Nicolin Chen
2026-11-30 22:44   ` Nicolin Chen
2026-11-15 23:30 ` [PATCH v3 06/13] iommupt/armv8: Add the 64 bit ARMv8 page table format Jason Gunthorpe
2026-12-03  0:15   ` Nicolin Chen [this message]
2026-11-15 23:30 ` [PATCH v3 07/13] iommupt/armv8: Add DBM support Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 08/13] iommupt/armv8: Implement the iommu specific components Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 09/13] iommu/arm-smmu-v3: Remove io-pgtable-arm from sva.c Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 10/13] iommu/arm-smmu-v3: Move the DMA API comment to flush_iotlb_all Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 11/13] iommu/arm-smmu-v3: Support CONT in paging domains with errata Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 12/13] iommu/arm-smmu-v3: Use the generic iommu page table Jason Gunthorpe
2026-11-15 23:30 ` [PATCH v3 13/13] iommu: Remove pgsize from iommu_iotlb_gather Jason Gunthorpe
2026-11-24  0:04 ` [PATCH v3 00/13] Use the generic iommu page table for SMMUv3 Nicolin Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axC0v8xs5P4cxh6e@nvidia.com \
    --to=nicolinc@nvidia.com \
    --cc=dmatlack@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=john.garry@arm.com \
    --cc=joro@8bytes.org \
    --cc=jpb@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=patches@lists.linux.dev \
    --cc=praan@google.com \
    --cc=robin.murphy@arm.com \
    --cc=skhawaja@google.com \
    --cc=smostafa@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox