Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHERI-RISC-V: PTE_CW/CD bugfix #201

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions target/riscv/cpu_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,15 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
*prot |= PAGE_EXEC;
}
/* add write permission on stores or if the page is already dirty,
so that we TLB miss on later writes to update the dirty bit */
so that we TLB miss on later writes to update the dirty bit.

This test could be equivalently written as
(pte & (PTE_W | PTE_D)) == (PTE_W | PTE_D)
because MMU_DATA_STORE / MMU_DATA_CAP_STORE accesses will reach
this point only if PTE_W and PTE_D are both already set prior to
this get_physical_address call or PTE_W was already set and PTE_D
has just been set above.
*/
if ((pte & PTE_W) &&
((access_type == MMU_DATA_STORE) ||
(access_type == MMU_DATA_CAP_STORE) || (pte & PTE_D))) {
Expand All @@ -784,7 +792,15 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,
}
}
}
if ((pte & PTE_CW) == 0) {

/*
* Flag this TLB entry as requiring a trap on cap-store if either
* CD or CW is clear, paralleling the existing logic around W and D
* above. As with PTE_D, the (CHERI-augmented) TCG TLB logic will
* translate again during a cap store before actually trapping,
* giving us an opportunity to set CD.
*/
if ((pte & (PTE_CD | PTE_CW)) != (PTE_CD | PTE_CW)) {
*prot |= PAGE_SC_TRAP;
}
#endif
Expand Down
Loading