Skip to content

Commit 3170641

Browse files
miguelafsilva5josecm
authored andcommitted
feat(unique-asid): force addr spaces to have unique IDs
All address spaces now have their unique ID. The only exception is the hypervisor itself that always has ID=0. Signed-off-by: Miguel Silva <[email protected]>
1 parent f8c4561 commit 3170641

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

src/core/mmu/inc/mem_prot/mem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <arch/mem.h>
1111
#include <page_table.h>
1212
#include <spinlock.h>
13-
14-
#define HYP_ASID 0
1513
struct addr_space {
1614
struct page_table pt;
1715
enum AS_TYPE type;

src/core/mmu/mem.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,31 @@ void mem_color_hypervisor(const paddr_t load_addr, struct mem_region* root_regio
900900
mem_unmap(&cpu()->as, va, p_cpu.num_pages, false);
901901
}
902902

903+
static unsigned long as_id_alloc(struct addr_space* as)
904+
{
905+
static spinlock_t as_id_alloc_lock = SPINLOCK_INITVAL;
906+
static asid_t asid_counter = 1;
907+
unsigned long ret = 0;
908+
909+
spin_lock(&as_id_alloc_lock);
910+
if (as->type != AS_HYP) {
911+
ret = asid_counter;
912+
asid_counter++;
913+
}
914+
spin_unlock(&as_id_alloc_lock);
915+
916+
return ret;
917+
}
918+
903919
void as_init(struct addr_space* as, enum AS_TYPE type, asid_t id, pte_t* root_pt, colormap_t colors)
904920
{
921+
UNUSED_ARG(id);
922+
905923
as->type = type;
906924
as->pt.dscr = type == AS_HYP || type == AS_HYP_CPY ? hyp_pt_dscr : vm_pt_dscr;
925+
as->id = as_id_alloc(as);
907926
as->colors = colors;
908927
as->lock = SPINLOCK_INITVAL;
909-
as->id = id;
910928

911929
if (root_pt == NULL) {
912930
size_t n = NUM_PAGES(pt_size(&as->pt, 0));

src/core/mpu/inc/mem_prot/mem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
#include <arch/mem.h>
1313
#include <arch/spinlock.h>
1414

15-
#define HYP_ASID 0
1615
#define VMPU_NUM_ENTRIES 64
17-
1816
struct mp_region {
1917
vaddr_t base;
2018
size_t size;

src/core/mpu/mem.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,30 @@ size_t mem_cpu_boot_alloc_size()
214214
return size;
215215
}
216216

217+
static unsigned long as_id_alloc(struct addr_space* as)
218+
{
219+
static spinlock_t as_id_alloc_lock = SPINLOCK_INITVAL;
220+
static asid_t asid_counter = 1;
221+
unsigned long ret = 0;
222+
223+
spin_lock(&as_id_alloc_lock);
224+
if (as->type != AS_HYP) {
225+
ret = asid_counter;
226+
asid_counter++;
227+
}
228+
spin_unlock(&as_id_alloc_lock);
229+
230+
return ret;
231+
}
232+
217233
void as_init(struct addr_space* as, enum AS_TYPE type, asid_t id, colormap_t colors)
218234
{
219235
UNUSED_ARG(colors);
236+
UNUSED_ARG(id);
220237

221238
as->type = type;
222239
as->colors = 0;
223-
as->id = id;
240+
as->id = as_id_alloc(as);
224241
as->lock = SPINLOCK_INITVAL;
225242
as_arch_init(as);
226243

0 commit comments

Comments
 (0)