forked from pxk27/riscv-hyp-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hfence_tests.c
63 lines (49 loc) · 1.5 KB
/
hfence_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <rvh_test.h>
#include <page_tables.h>
bool hfence_test() {
TEST_START();
uintptr_t vaddr;
uint64_t val;
bool cond;
write64(phys_page_base(SWITCH1), 0x111111111);
write64(phys_page_base(SWITCH2), 0x222222222);
//////////////////////////////////////////////////////////////////////
goto_priv(PRIV_HS);
set_prev_priv(PRIV_VS);
hpt_init();
vspt_init();
vaddr = vs_page_base(SWITCH1);
val = hlvd(vaddr);
cond = true;
vspt_switch();
cond &= hlvd(vaddr) == val;
hfence_vvma();
cond &= hlvd(vaddr) != val;
hpt_switch();
cond &= hlvd(vaddr) != val;
hfence_gvma();
cond &= hlvd(vaddr) == val;
TEST_ASSERT("hfences correctly invalidate guest tlb entries", cond);
//////////////////////////////////////////////////////////////////////
goto_priv(PRIV_HS);
val = hlvd(vaddr);
cond = true;
hpt_switch();
sfence();
cond &= hlvd(vaddr) == val;
TEST_ASSERT("hs sfence doest not affect guest level tlb entries", cond);
//////////////////////////////////////////////////////////////////////
goto_priv(PRIV_HS);
hspt_init();
vaddr = hs_page_base(SWITCH1);
val = read64(vaddr);
cond = true;
hspt_switch();
goto_priv(PRIV_VS);
sfence();
goto_priv(PRIV_HS);
cond &= read64(vaddr) == val;
TEST_ASSERT("vs sfence doest not affect hypervisor level tlb entries", cond);
//////////////////////////////////////////////////////////////////////
TEST_END();
}