Skip to content

Commit

Permalink
env: trap and page fault filter mechanism (riscv#40)
Browse files Browse the repository at this point in the history
Certain tests (particularly negative) may require a fault to occur.

However in order to pass the tests, page fault and traps must return back
to the tests. This patch add support for page fault and trap filtering
in env.

Signed-off-by: Deepak Gupta <[email protected]>
  • Loading branch information
deepak0414 authored Feb 2, 2023
1 parent 34a1175 commit 982f93f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions p/riscv_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
#define EXTRA_TVEC_MACHINE
#define EXTRA_INIT
#define EXTRA_INIT_TIMER
#define FILTER_TRAP
#define FILTER_PAGE_FAULT

#define INTERRUPT_HANDLER j other_exception /* No interrupts should occur */

Expand Down
10 changes: 10 additions & 0 deletions v/riscv_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
extra_boot: \
EXTRA_INIT \
ret; \
.global trap_filter; \
trap_filter: \
FILTER_TRAP \
li a0, 0; \
ret; \
.global pf_filter; \
pf_filter: \
FILTER_PAGE_FAULT \
li a0, 0; \
ret; \
.global userstart; \
userstart: \
init
Expand Down
15 changes: 15 additions & 0 deletions v/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,14 @@ static void evict(unsigned long addr)
}
}

extern int pf_filter(uintptr_t addr, uintptr_t *pte, int *copy);
extern int trap_filter(trapframe_t *tf);

void handle_fault(uintptr_t addr, uintptr_t cause)
{
uintptr_t filter_encodings = 0;
int copy_page = 1;

assert(addr >= PGSIZE && addr < MAX_TEST_PAGES * PGSIZE);
addr = addr/PGSIZE*PGSIZE;

Expand All @@ -159,6 +165,11 @@ void handle_fault(uintptr_t addr, uintptr_t cause)
freelist_tail = 0;

uintptr_t new_pte = (node->addr >> PGSHIFT << PTE_PPN_SHIFT) | PTE_V | PTE_U | PTE_R | PTE_W | PTE_X;

if (pf_filter(addr, &filter_encodings, &copy_page)) {
new_pte = (node->addr >> PGSHIFT << PTE_PPN_SHIFT) | filter_encodings;
}

user_llpt[addr/PGSIZE] = new_pte | PTE_A | PTE_D;
flush_page(addr);

Expand All @@ -177,6 +188,10 @@ void handle_fault(uintptr_t addr, uintptr_t cause)

void handle_trap(trapframe_t* tf)
{
if (trap_filter(tf)) {
pop_tf(tf);
}

if (tf->cause == CAUSE_USER_ECALL)
{
int n = tf->gpr[10];
Expand Down

0 comments on commit 982f93f

Please sign in to comment.