Skip to content

Commit 01f0139

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 e239802 commit 01f0139

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
@@ -223,13 +223,30 @@ static void mem_mmio_init_regions(struct addr_space* as)
223223
}
224224
}
225225

226+
static unsigned long as_id_alloc(struct addr_space* as)
227+
{
228+
static spinlock_t as_id_alloc_lock = SPINLOCK_INITVAL;
229+
static asid_t asid_counter = 1;
230+
unsigned long ret = 0;
231+
232+
spin_lock(&as_id_alloc_lock);
233+
if (as->type != AS_HYP) {
234+
ret = asid_counter;
235+
asid_counter++;
236+
}
237+
spin_unlock(&as_id_alloc_lock);
238+
239+
return ret;
240+
}
241+
226242
void as_init(struct addr_space* as, enum AS_TYPE type, asid_t id, colormap_t colors)
227243
{
228244
UNUSED_ARG(colors);
245+
UNUSED_ARG(id);
229246

230247
as->type = type;
231248
as->colors = 0;
232-
as->id = id;
249+
as->id = as_id_alloc(as);
233250
as->lock = SPINLOCK_INITVAL;
234251
as_arch_init(as);
235252

0 commit comments

Comments
 (0)