Skip to content

Commit c747964

Browse files
committed
fix SV57 translation for kernel address space
In SV57 **virtual** addresses look as follows: +--------+---------+---------+---------+---------+---------+-----------+ |copy of | VPN[4] | VPN[3] | VPN[2] | VPN[1] | VPN[0] | OFFSET | | bit 56 | 9 bits | 9 bits | 9 bits | 9 bits | 9 bits | 12 bits | +--------+---------+---------+---------+---------+---------+-----------+ | 63 57 | 56 48 | 47 40 | 39 32 | 31 24 | 23 12 | 11 0 | while the structure of **physical** address is: +------------+----------+----------+---------+----------+-----------+ | PPN[4] | PPN[3] | PPN[2] | PPN[1] | PPN[0] | OFFSET | | 8 bits | 9 bits | 9 bits | 9 bits | 9 bits | 12 bits | +------------+----------+----------+---------+----------+-----------+ | 55 48 | 47 39 | 38 30 | 29 21 | 20 12 | 11 0 | So the size of effective VA is 57, while PA is 56 bits. When our translation routine constructs the final physical address, it preserves a portion of the original virtual address (to handle superpage cases). To mask out the part of the original VA that must be replaced with the PPN from the PTE, the **virt2phys_info_t::pa_ppn_mask** field is used. In our codebase pa_ppn_mask[4] was initialized incorrectly for SV57 mode, resulting in a single bit from the original VA to leak through, producing an incorrect physical address.
1 parent 49f3640 commit c747964

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/target/riscv/riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static const virt2phys_info_t sv57 = {
272272
.pte_ppn_shift = {10, 19, 28, 37, 46},
273273
.pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
274274
.pa_ppn_shift = {12, 21, 30, 39, 48},
275-
.pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
275+
.pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
276276
};
277277

278278
static const virt2phys_info_t sv57x4 = {

0 commit comments

Comments
 (0)