target/alpha: honor the page table entry granularity hint
PATCH 1/1 target/alpha: honor the page table entry granularity hint
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.
--- target/alpha/cpu.h | 1 + target/alpha/helper.c | 7 +++++++ 2 files changed, 8 insertions(+)
target/alpha/cpu.h +1 -0
@@ -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,
target/alpha/helper.c +7 -0
@@ -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
Signature · 1 line
2.55.0
Quoted 13 lines · Matt Turner
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.
Quoted 6 lines
The size passed to
tlb_set_page()staysTARGET_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 <[email protected]>---
Ping for review. Kernel support for hugepages on Alpha landed in master today.
Quoted 16 lines · Matt Turner
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()staysTARGET_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.
Quoted 5 lines
Signed-off-by Matt Turner<[email protected]>--- 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.
r~