[PATCH] target/alpha: honor the page table entry granularity hint

Matt Turner posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261008193119.1246259-1-mattst88@gmail.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>
target/alpha/cpu.h    | 1 +
target/alpha/helper.c | 7 +++++++
2 files changed, 8 insertions(+)
[PATCH] target/alpha: honor the page table entry granularity hint
Posted by Matt Turner 1 month, 2 weeks ago
PTE<6:5> is the granularity hint. A hint of N says the entry is one of a
block of 8^N pages (64KB, 512KB or 4MB) that are contiguous and naturally
aligned in both address spaces, so that one translation buffer entry may
map the whole block. Such an entry takes the frame number bits above the
block size from the PTE and everything below from the virtual address.

Do the same: mask the frame number down to the block base and take the
offset within the block from the address. A well-formed block translates
exactly as before. A block whose frames are not contiguous or not aligned
now gets a wrong translation, as it can on hardware, instead of working
by accident.

The size passed to tlb_set_page() stays TARGET_PAGE_SIZE. A translation
buffer is free to ignore the hint, so a guest already has to invalidate
every page of a block, and one entry per page is all that is needed.

Signed-off-by: Matt Turner <mattst88@gmail.com>
---
 target/alpha/cpu.h    | 1 +
 target/alpha/helper.c | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git ./target/alpha/cpu.h ./target/alpha/cpu.h
index 378bd96d94..93b8795257 100644
--- ./target/alpha/cpu.h
+++ ./target/alpha/cpu.h
@@ -321,6 +321,7 @@ enum {
     PTE_FOW   = 0x0004,  /* used for page protection (fault on write) */
     PTE_FOE   = 0x0008,  /* used for page protection (fault on exec) */
     PTE_ASM   = 0x0010,
+    PTE_GH    = 0x0060,  /* granularity hint */
     PTE_KRE   = 0x0100,
     PTE_URE   = 0x0200,
     PTE_KWE   = 0x1000,
diff --git ./target/alpha/helper.c ./target/alpha/helper.c
index c3614ecafd..bedc0df483 100644
--- ./target/alpha/helper.c
+++ ./target/alpha/helper.c
@@ -267,6 +267,13 @@ static int get_physical_address(CPUAlphaState *env, vaddr addr,
         goto exit;
     }
 
+    /* A granularity hint of N maps a block of 8^N pages with one entry. */
+    if (L3pte & PTE_GH) {
+        hwaddr mask = (TARGET_PAGE_SIZE << (3 * ((L3pte & PTE_GH) >> 5))) - 1;
+
+        phys = (phys & ~mask) | (addr & mask & TARGET_PAGE_MASK);
+    }
+
 #if PAGE_READ != 1 || PAGE_WRITE != 2 || PAGE_EXEC != 4
 # error page bits out of date
 #endif
-- 
2.55.0
Re: [PATCH] target/alpha: honor the page table entry granularity hint
Posted by Richard Henderson 1 month ago
On 10/8/26 21:31, Matt Turner wrote:
> PTE<6:5> is the granularity hint. A hint of N says the entry is one of a
> block of 8^N pages (64KB, 512KB or 4MB) that are contiguous and naturally
> aligned in both address spaces, so that one translation buffer entry may
> map the whole block. Such an entry takes the frame number bits above the
> block size from the PTE and everything below from the virtual address.
> 
> Do the same: mask the frame number down to the block base and take the
> offset within the block from the address. A well-formed block translates
> exactly as before. A block whose frames are not contiguous or not aligned
> now gets a wrong translation, as it can on hardware, instead of working
> by accident.
> 
> The size passed to tlb_set_page() stays TARGET_PAGE_SIZE. A translation
> buffer is free to ignore the hint, so a guest already has to invalidate
> every page of a block, and one entry per page is all that is needed.
> 
> Signed-off-by: Matt Turner<mattst88@gmail.com>
> ---
>   target/alpha/cpu.h    | 1 +
>   target/alpha/helper.c | 7 +++++++
>   2 files changed, 8 insertions(+)

Mm.  I had never implemented this before because the well-formed case 
shouldn't matter.  But I can understand wanting the ill-formed case to 
fail in the same way.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Re: [PATCH] target/alpha: honor the page table entry granularity hint
Posted by Matt Turner 1 month ago
On Thu, Oct 8, 2026 at 3:31 PM Matt Turner <mattst88@gmail.com> wrote:
>
> PTE<6:5> is the granularity hint. A hint of N says the entry is one of a
> block of 8^N pages (64KB, 512KB or 4MB) that are contiguous and naturally
> aligned in both address spaces, so that one translation buffer entry may
> map the whole block. Such an entry takes the frame number bits above the
> block size from the PTE and everything below from the virtual address.
>
> Do the same: mask the frame number down to the block base and take the
> offset within the block from the address. A well-formed block translates
> exactly as before. A block whose frames are not contiguous or not aligned
> now gets a wrong translation, as it can on hardware, instead of working
> by accident.
>
> The size passed to tlb_set_page() stays TARGET_PAGE_SIZE. A translation
> buffer is free to ignore the hint, so a guest already has to invalidate
> every page of a block, and one entry per page is all that is needed.
>
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---

Ping for review. Kernel support for hugepages on Alpha landed in master today.