Skip to main content

PagingConstsTrait

Trait PagingConstsTrait 

Source
pub trait PagingConstsTrait:
    Clone
    + Debug
    + Send
    + Sync
    + 'static {
    const BASE_PAGE_SIZE: usize;
    const NR_LEVELS: PagingLevel;
    const HIGHEST_TRANSLATION_LEVEL: PagingLevel;
    const PTE_SIZE: usize;
    const ADDRESS_WIDTH: usize;
    const VA_SIGN_EXT: bool;

    // Required method
    proof fn lemma_paging_consts_requirements();

    // Provided method
    proof fn lemma_paging_consts_properties() { ... }
}
Expand description

A minimal set of constants that determines the paging system. This provides an abstraction over most paging modes in common architectures.

Verification requires 4 KiB pages, 8-byte PTEs, 1..=MAX_NR_LEVELS levels, and 12 + 9 * NR_LEVELS <= ADDRESS_WIDTH < usize::BITS.

Required Associated Constants§

Source

const BASE_PAGE_SIZE: usize

The smallest page size. This is also the page size at level 1 page tables.

Source

const NR_LEVELS: PagingLevel

The number of levels in the page table. The numbering of levels goes from deepest node to the root node. For example, the level 1 to 5 on AMD64 corresponds to Page Tables, Page Directory Tables, Page Directory Pointer Tables, Page-Map Level-4 Table, and Page-Map Level-5 Table, respectively.

Source

const HIGHEST_TRANSLATION_LEVEL: PagingLevel

The highest level that a PTE can be directly used to translate a VA. This affects the the largest page size supported by the page table.

Source

const PTE_SIZE: usize

The size of a PTE.

Source

const ADDRESS_WIDTH: usize

The address width may be BASE_PAGE_SIZE.ilog2() + NR_LEVELS * IN_FRAME_INDEX_BITS. If it is shorter than that, the higher bits in the highest level are ignored.

Source

const VA_SIGN_EXT: bool

Whether virtual addresses are sign-extended.

The sign bit of a Vaddr is the bit at index PagingConstsTrait::ADDRESS_WIDTH - 1. If this constant is true, bits in Vaddr that are higher than the sign bit must be equal to the sign bit. If an address violates this rule, both the hardware and OSTD should reject it.

Otherwise, if this constant is false, higher bits must be zero.

Regardless of sign extension, Vaddr is always not signed upon calculation. That means, 0xffff_ffff_ffff_0000 < 0xffff_ffff_ffff_0001 is true.

Required Methods§

Source

proof fn lemma_paging_consts_requirements()

ensures
Self::BASE_PAGE_SIZE == 4096,
1 <= Self::NR_LEVELS <= MAX_NR_LEVELS,
0 < Self::BASE_PAGE_SIZE,
is_pow2(Self::BASE_PAGE_SIZE as int),
0 < Self::HIGHEST_TRANSLATION_LEVEL <= Self::NR_LEVELS < PagingLevel::MAX,
is_pow2(Self::PTE_SIZE as int),
0 < Self::PTE_SIZE <= Self::BASE_PAGE_SIZE,
0 < Self::ADDRESS_WIDTH < usize::BITS,
Self::BASE_PAGE_SIZE.ilog2()
    + (Self::BASE_PAGE_SIZE / Self::PTE_SIZE).ilog2() * Self::NR_LEVELS
    <= Self::ADDRESS_WIDTH,
Self::PTE_SIZE == core::mem::size_of::<usize>(),

The requirements of the paging constants so that the memory management system can work correctly.

NOTE: The postcondition is designed to be minimal, to actually be used in proofs, call lemma_paging_consts_properties instead to get all the properties that are derived from the requirements.

Provided Methods§

Source

proof fn lemma_paging_consts_properties()

ensures
Self::PTE_SIZE == 8,
Self::BASE_PAGE_SIZE.ilog2()
    + (Self::BASE_PAGE_SIZE / Self::PTE_SIZE).ilog2() * (Self::NR_LEVELS - 1)
    <= Self::ADDRESS_WIDTH,
0 < Self::BASE_PAGE_SIZE / Self::PTE_SIZE <= Self::BASE_PAGE_SIZE,
is_pow2((Self::BASE_PAGE_SIZE / Self::PTE_SIZE) as int),
Self::BASE_PAGE_SIZE / Self::PTE_SIZE == NR_ENTRIES,
Self::BASE_PAGE_SIZE == 4096,
1 <= Self::NR_LEVELS <= MAX_NR_LEVELS,
0 < Self::BASE_PAGE_SIZE,
is_pow2(Self::BASE_PAGE_SIZE as int),
0 < Self::HIGHEST_TRANSLATION_LEVEL <= Self::NR_LEVELS < PagingLevel::MAX,
is_pow2(Self::PTE_SIZE as int),
0 < Self::PTE_SIZE <= Self::BASE_PAGE_SIZE,
0 < Self::ADDRESS_WIDTH < usize::BITS,
Self::BASE_PAGE_SIZE.ilog2()
    + (Self::BASE_PAGE_SIZE / Self::PTE_SIZE).ilog2() * Self::NR_LEVELS
    <= Self::ADDRESS_WIDTH,
Self::PTE_SIZE == core::mem::size_of::<usize>(),

The derived properties of the paging constants.

NOTE: Implementations of PagingConstsTrait do not need to implement this lemma, the proof is automatically inherited from the default implementation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<C: PageTableConfig> PagingConstsTrait for C

Source§

const BASE_PAGE_SIZE: usize = <C::C>::BASE_PAGE_SIZE

Source§

const NR_LEVELS: PagingLevel = <C::C>::NR_LEVELS

Source§

const HIGHEST_TRANSLATION_LEVEL: PagingLevel = <C::C>::HIGHEST_TRANSLATION_LEVEL

Source§

const PTE_SIZE: usize = <C::C>::PTE_SIZE

Source§

const ADDRESS_WIDTH: usize = <C::C>::ADDRESS_WIDTH

Source§

const VA_SIGN_EXT: bool = <C::C>::VA_SIGN_EXT