Skip to content

Commit

Permalink
RISC-V: Avoid using invalid intermediate translations
Browse files Browse the repository at this point in the history
This is almost entirely a comment.

Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
  • Loading branch information
Palmer Dabbelt committed May 17, 2019
1 parent 9a6e7af commit 4c3aeb8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arch/riscv/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ relocate:

/*
* Load trampoline page directory, which will cause us to trap to
* stvec if VA != PA, or simply fall through if VA == PA
* stvec if VA != PA, or simply fall through if VA == PA. We need a
* full fence here because setup_vm() just wrote these PTEs and we need
* to ensure the new translations are in use.
*/
la a0, trampoline_pg_dir
srl a0, a0, PAGE_SHIFT
Expand All @@ -115,8 +117,14 @@ relocate:
la gp, __global_pointer$
.option pop

/* Switch to kernel page tables */
/*
* Switch to kernel page tables. A full fence is necessary in order to
* avoid using the trampoline translations, which are only correct for
* the first superpage. Fetching the fence is guarnteed to work
* because that first superpage is translated the same way.
*/
csrw CSR_SATP, a2
sfence.vma

ret

Expand Down

0 comments on commit 4c3aeb8

Please sign in to comment.