@@ -56,60 +56,66 @@ static int split_large_page(uint64_t *pte,
56
56
return 0 ;
57
57
}
58
58
59
+ static inline void __modify_pte (uint64_t * pte ,
60
+ uint64_t prot_set , uint64_t prot_clr )
61
+ {
62
+ uint64_t new_pte = * pte ;
63
+ new_pte &= ~prot_clr ;
64
+ new_pte |= prot_set ;
65
+ set_pte (pte , new_pte );
66
+ }
67
+
59
68
/*
60
- * In PT level, modify [vaddr_start, vaddr_end) MR PTA.
69
+ * In PT level,
70
+ * modify [vaddr_start, vaddr_end) memory type or page access right.
61
71
*/
62
72
static int modify_pte (uint64_t * pde ,
63
73
uint64_t vaddr_start , uint64_t vaddr_end ,
64
74
uint64_t prot_set , uint64_t prot_clr ,
65
75
enum _page_table_type ptt )
66
76
{
67
- uint64_t * pd_page = pde_page_vaddr (* pde );
77
+ uint64_t * pt_page = pde_page_vaddr (* pde );
68
78
uint64_t vaddr = vaddr_start ;
69
79
uint64_t index = pte_index (vaddr );
70
80
71
81
dev_dbg (ACRN_DBG_MMU , "%s, vaddr: [0x%llx - 0x%llx]\n" ,
72
82
__func__ , vaddr , vaddr_end );
73
83
for (; index < PTRS_PER_PTE ; index ++ ) {
74
- uint64_t new_pte , * pte = pd_page + index ;
75
- uint64_t vaddr_next = (vaddr & PTE_MASK ) + PTE_SIZE ;
84
+ uint64_t * pte = pt_page + index ;
76
85
77
86
if (pgentry_present (ptt , * pte ) == 0UL ) {
78
87
pr_err ("%s, invalid op, pte not present\n" , __func__ );
79
88
return - EFAULT ;
80
89
}
81
90
82
- new_pte = * pte ;
83
- new_pte &= ~prot_clr ;
84
- new_pte |= prot_set ;
85
- set_pte (pte , new_pte );
86
-
87
- if (vaddr_next >= vaddr_end ) {
91
+ __modify_pte (pte , prot_set , prot_clr );
92
+ vaddr += PTE_SIZE ;
93
+ if (vaddr >= vaddr_end ) {
88
94
break ;
89
95
}
90
- vaddr = vaddr_next ;
91
96
}
92
97
93
98
return 0 ;
94
99
}
95
100
96
101
/*
97
- * In PD level, modify [vaddr_start, vaddr_end) MR PTA.
102
+ * In PD level,
103
+ * modify [vaddr_start, vaddr_end) memory type or page access right.
98
104
*/
99
105
static int modify_pde (uint64_t * pdpte ,
100
106
uint64_t vaddr_start , uint64_t vaddr_end ,
101
107
uint64_t prot_set , uint64_t prot_clr ,
102
108
enum _page_table_type ptt )
103
109
{
104
110
int ret = 0 ;
105
- uint64_t * pdpt_page = pdpte_page_vaddr (* pdpte );
111
+ uint64_t * pd_page = pdpte_page_vaddr (* pdpte );
106
112
uint64_t vaddr = vaddr_start ;
107
113
uint64_t index = pde_index (vaddr );
108
114
109
115
dev_dbg (ACRN_DBG_MMU , "%s, vaddr: [0x%llx - 0x%llx]\n" ,
110
116
__func__ , vaddr , vaddr_end );
111
117
for (; index < PTRS_PER_PDE ; index ++ ) {
112
- uint64_t * pde = pdpt_page + index ;
118
+ uint64_t * pde = pd_page + index ;
113
119
uint64_t vaddr_next = (vaddr & PDE_MASK ) + PDE_SIZE ;
114
120
115
121
if (pgentry_present (ptt , * pde ) == 0UL ) {
@@ -123,10 +129,7 @@ static int modify_pde(uint64_t *pdpte,
123
129
return ret ;
124
130
}
125
131
} else {
126
- uint64_t new_pde = * pde ;
127
- new_pde &= ~prot_clr ;
128
- new_pde |= prot_set ;
129
- set_pte (pde , new_pde );
132
+ __modify_pte (pde , prot_set , prot_clr );
130
133
if (vaddr_next < vaddr_end ) {
131
134
vaddr = vaddr_next ;
132
135
continue ;
@@ -146,22 +149,23 @@ static int modify_pde(uint64_t *pdpte,
146
149
}
147
150
148
151
/*
149
- * In PDPT level, modify [vaddr, vaddr_end) MR PTA.
152
+ * In PDPT level,
153
+ * modify [vaddr_start, vaddr_end) memory type or page access right.
150
154
*/
151
155
static int modify_pdpte (uint64_t * pml4e ,
152
156
uint64_t vaddr_start , uint64_t vaddr_end ,
153
157
uint64_t prot_set , uint64_t prot_clr ,
154
158
enum _page_table_type ptt )
155
159
{
156
160
int ret = 0 ;
157
- uint64_t * pml4_page = pml4e_page_vaddr (* pml4e );
161
+ uint64_t * pdpt_page = pml4e_page_vaddr (* pml4e );
158
162
uint64_t vaddr = vaddr_start ;
159
163
uint64_t index = pdpte_index (vaddr );
160
164
161
165
dev_dbg (ACRN_DBG_MMU , "%s, vaddr: [0x%llx - 0x%llx]\n" ,
162
166
__func__ , vaddr , vaddr_end );
163
167
for (; index < PTRS_PER_PDPTE ; index ++ ) {
164
- uint64_t * pdpte = pml4_page + index ;
168
+ uint64_t * pdpte = pdpt_page + index ;
165
169
uint64_t vaddr_next = (vaddr & PDPTE_MASK ) + PDPTE_SIZE ;
166
170
167
171
if (pgentry_present (ptt , * pdpte ) == 0UL ) {
@@ -175,10 +179,7 @@ static int modify_pdpte(uint64_t *pml4e,
175
179
return ret ;
176
180
}
177
181
} else {
178
- uint64_t new_pdpte = * pdpte ;
179
- new_pdpte &= ~prot_clr ;
180
- new_pdpte |= prot_set ;
181
- set_pte (pdpte , new_pdpte );
182
+ __modify_pte (pdpte , prot_set , prot_clr );
182
183
if (vaddr_next < vaddr_end ) {
183
184
vaddr = vaddr_next ;
184
185
continue ;
@@ -198,9 +199,9 @@ static int modify_pdpte(uint64_t *pml4e,
198
199
}
199
200
200
201
/*
201
- * modify [vaddr, vaddr + size ) memory region page table attributes .
202
- * prot_clr - attributes want to be clear
203
- * prot_set - attributes want to be set
202
+ * modify [vaddr, vaddr + size ) memory type or page access right .
203
+ * prot_clr - memory type or page access right want to be clear
204
+ * prot_set - memory type or page access right want to be set
204
205
* @pre: the prot_set and prot_clr should set before call this function.
205
206
* If you just want to modify access rights, you can just set the prot_clr
206
207
* to what you want to set, prot_clr to what you want to clear. But if you
0 commit comments