]> Gentwo Git Trees - linux/.git/commit
genpt: Generic Page Table base API
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 4 Nov 2025 18:29:59 +0000 (14:29 -0400)
committerJoerg Roedel <joerg.roedel@amd.com>
Wed, 5 Nov 2025 08:07:04 +0000 (09:07 +0100)
commit7c5b184db7145fd417785377337bd15c4fe1d0f4
treed311910f9d8361d33b520377b75c73bf3b737b71
parentfd714986e4e46effa6697b13d32918fc59608ccb
genpt: Generic Page Table base API

The generic API is intended to be separated from the implementation of
page table algorithms. It contains only accessors for walking and
manipulating the table and helpers that are useful for building an
implementation. Memory management is not in the generic API, but part of
the implementation.

Using a multi-compilation approach the implementation module would include
headers in this order:

  common.h
  defs_FMT.h
  pt_defs.h
  FMT.h
  pt_common.h
  IMPLEMENTATION.h

Where each compilation unit would have a combination of FMT and
IMPLEMENTATION to produce a per-format per-implementation module.

The API is designed so that the format headers have minimal logic, and
default implementations are provided if the format doesn't include one.

Generally formats provide their code via an inline function using the
pattern:

  static inline FMTpt_XX(..) {}
  #define pt_XX FMTpt_XX

The common code then enforces a function signature so that there is no
drift in function arguments, or accidental polymorphic functions (as has
been slightly troublesome in mm). Use of function-like #defines are
avoided in the format even though many of the functions are small enough.

Provide kdocs for the API surface.

This is enough to implement the 8 initial format variations with all of
their features:
 * Entries comprised of contiguous blocks of IO PTEs for larger page
   sizes (AMDv1, ARMv8)
 * Multi-level tables, up to 6 levels. Runtime selected top level
 * The size of the top table level can be selected at runtime (ARM's
   concatenated tables)
 * The number of levels in the table can optionally increase dynamically
   during map (AMDv1)
 * Optional leaf entries at any level
 * 32 bit/64 bit virtual and output addresses, using every bit
 * Sign extended addressing (x86)
 * Dirty tracking

A basic simple format takes about 200 lines to declare the require inline
functions.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Tested-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
.clang-format
drivers/iommu/Kconfig
drivers/iommu/generic_pt/Kconfig [new file with mode: 0644]
drivers/iommu/generic_pt/pt_common.h [new file with mode: 0644]
drivers/iommu/generic_pt/pt_defs.h [new file with mode: 0644]
drivers/iommu/generic_pt/pt_fmt_defaults.h [new file with mode: 0644]
drivers/iommu/generic_pt/pt_iter.h [new file with mode: 0644]
drivers/iommu/generic_pt/pt_log2.h [new file with mode: 0644]
include/linux/generic_pt/common.h [new file with mode: 0644]