Skip to content

Commit f8ceb79

Browse files
fix(mpu): Dealloate vMPU entry if mpu fails to insert region
Added a function that deallocates a vMPU entry whenever the mpu fails to insert a region. Signed-off-by: Miguel Silva <[email protected]>
1 parent ffcf041 commit f8ceb79

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/core/mpu/mem.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ static mpid_t mem_vmpu_allocate_entry(struct addr_space* as)
107107
return mpid;
108108
}
109109

110+
static void mem_vmpu_deallocate_entry(struct addr_space* as, mpid_t mpid)
111+
{
112+
struct mpe* mpe = mem_vmpu_get_entry(as, mpid);
113+
114+
mpe->region.base = 0;
115+
mpe->region.size = 0;
116+
mpe->region.mem_flags = PTE_INVALID;
117+
mpe->region.as_sec = SEC_UNKNOWN;
118+
mpe->state = MPE_S_FREE;
119+
mpe->lock = false;
120+
}
121+
110122
static mpid_t mem_vmpu_get_entry_by_addr(struct addr_space* as, vaddr_t addr)
111123
{
112124
mpid_t mpid = INVALID_MPID;
@@ -496,6 +508,7 @@ static void mem_vmpu_coalesce_contiguous(struct addr_space* as, bool broadcast)
496508
bool mem_map(struct addr_space* as, struct mp_region* mpr, bool broadcast, bool locked)
497509
{
498510
bool mapped = false;
511+
mpid_t mpid = INVALID_MPID;
499512

500513
if (mpr->size == 0) {
501514
return true;
@@ -509,9 +522,11 @@ bool mem_map(struct addr_space* as, struct mp_region* mpr, bool broadcast, bool
509522
spin_lock(&as->lock);
510523

511524
if (mem_vmpu_find_overlapping_region(as, mpr) == INVALID_MPID) {
512-
mpid_t mpid = mem_vmpu_allocate_entry(as);
525+
mpid = mem_vmpu_allocate_entry(as);
513526
if (mpid != INVALID_MPID) {
514527
mapped = mem_vmpu_insert_region(as, mpid, mpr, broadcast, locked);
528+
} else {
529+
mem_vmpu_deallocate_entry(as, mpid);
515530
}
516531
}
517532

0 commit comments

Comments
 (0)