alpha: define granularity hint PTE bits

Bits <6:5> of the Alpha PTE are the granularity hint, described in Table
22-3 of the Alpha Architecture Reference Manual. A hint of N marks the
PTE as one of a block of 8^N physically contiguous, naturally aligned
pages that the translation buffer may map with a single entry. With 8KB
pages that gives 64KB, 512KB and 4MB blocks.

Define the field and the helpers to encode and decode it. Nothing sets a
non-zero hint yet.

Add the hint to _PAGE_CHG_MASK so that pte_modify() preserves it. Swap
PTEs leave bits <31:0> clear, so pte_huge() is false on swap, migration
and marker entries, and page table entries above the last level keep a
zero hint where pmd_bad() would reject anything else.

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>
Tested-by: Magnus Lindholm <linmag7@gmail.com>
Signed-off-by: Matt Turner <mattst88@gmail.com>
Link: https://lore.kernel.org/r/20261007-alpha-hugepages-v2-4-8e108af2d961@gmail.com
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
This commit is contained in:
Matt Turner 2026-10-07 23:24:07 -04:00 committed by Magnus Lindholm
parent 5cea79aacf
commit 5072e72dd3

View File

@ -65,6 +65,8 @@ struct vm_area_struct;
#define _PAGE_FOW 0x0004 /* used for page protection (fault on write) */
#define _PAGE_FOE 0x0008 /* used for page protection (fault on exec) */
#define _PAGE_ASM 0x0010
#define _PAGE_GH_MASK 0x0060 /* granularity hint, PTE<6:5> */
#define _PAGE_GH_SHIFT 5
#define _PAGE_KRE 0x0100 /* kernel read enable, in __ACCESS_BITS */
#define _PAGE_URE 0x0200 /* user read enable, in __ACCESS_BITS */
#define _PAGE_KWE 0x1000 /* kernel write enable, in __DIRTY_BITS */
@ -95,7 +97,36 @@ struct vm_area_struct;
#define _PFN_MASK 0xFFFFFFFF00000000UL
#define _PAGE_TABLE (_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
#define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS | _PAGE_SPECIAL)
/*
* pte_modify() must preserve the granularity hint, or
* hugetlb_change_protection() would turn a block into single-page PTEs.
*/
#define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS | \
_PAGE_GH_MASK | _PAGE_SPECIAL)
/*
* Granularity hints. A PTE with hint order N is one of a block of 8^N
* physically contiguous pages, naturally aligned both virtually and
* physically, that the TB may map with a single entry. With 8KB pages the
* four encodings give 8KB, 64KB, 512KB and 4MB.
*
* Every PTE of a block must still carry the PFN of its own page, and all of
* them must agree in bits <15:0>: the protection, fault, hint and valid bits.
* __ACCESS_BITS and __DIRTY_BITS reach into that range, so young and dirty
* updates have to be applied to the whole block too.
*
* The hint is advisory: an implementation that ignores it still translates
* correctly through the individual PTEs, so it is safe to set on any Alpha.
*/
#define GH_ORDER_MAX 4 /* hint orders 0..3 */
#define gh_cont_shift(order) (PAGE_SHIFT + 3 * (order))
#define gh_cont_size(order) (1UL << gh_cont_shift(order))
#define gh_cont_mask(order) (~(gh_cont_size(order) - 1))
#define gh_pte_num(order) (1UL << (3 * (order)))
#define for_each_gh_order(order) \
for ((order) = 1; (order) < GH_ORDER_MAX; (order)++)
/*
* All the normal masks have the "page accessed" bits on, as any time they are used,
@ -261,6 +292,24 @@ extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= __ACCESS_BITS; retu
extern inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
extern inline pte_t pte_mkspecial(pte_t pte) { pte_val(pte) |= _PAGE_SPECIAL; return pte; }
extern inline unsigned int pte_gh_order(pte_t pte)
{
return (pte_val(pte) & _PAGE_GH_MASK) >> _PAGE_GH_SHIFT;
}
extern inline pte_t pte_mkgh(pte_t pte, unsigned int order)
{
pte_val(pte) &= ~_PAGE_GH_MASK;
pte_val(pte) |= (unsigned long)order << _PAGE_GH_SHIFT;
return pte;
}
/*
* Swap PTEs leave bits <31:0> clear, so this is false for every swap,
* migration and marker entry, not just for ordinary small pages.
*/
extern inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_GH_MASK; }
/*
* The smp_rmb() in the following functions are required to order the load of
* *dir (the pointer in the top level page table) with any subsequent load of