Skip to content

Commit 29df3f4

Browse files
feat(slave-side-prot): add device access control enable function
Each architecture needs to implement their access control function. This function is called during the dev init for vms, and is executed instead of the original memory mapping. Signed-off-by: Miguel Silva <[email protected]>
1 parent a411e60 commit 29df3f4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/core/inc/vm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,6 @@ unsigned long vcpu_readpc(struct vcpu* vcpu);
183183
void vcpu_writepc(struct vcpu* vcpu, unsigned long pc);
184184
void vcpu_arch_reset(struct vcpu* vcpu, vaddr_t entry);
185185
bool vcpu_arch_is_on(struct vcpu* vcpu);
186+
void vm_arch_allow_mmio_access(struct vm_dev_region* dev);
186187

187188
#endif /* __VM_H__ */

src/core/vm.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ static void vm_master_init(struct vm* vm, const struct vm_config* vm_config, vmi
2020
vm->lock = SPINLOCK_INITVAL;
2121

2222
cpu_sync_init(&vm->sync, vm->cpu_num);
23-
24-
vm_mem_prot_init(vm, vm_config);
2523
}
2624

2725
static void vm_cpu_init(struct vm* vm)
@@ -212,8 +210,12 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config)
212210

213211
size_t n = ALIGN(dev->size, PAGE_SIZE) / PAGE_SIZE;
214212

215-
if (dev->va != INVALID_VA) {
216-
mem_alloc_map_dev(&vm->as, SEC_VM_ANY, (vaddr_t)dev->va, dev->pa, n);
213+
if (DEFINED(MMIO_SLAVE_SIDE_PROT)) {
214+
vm_arch_allow_mmio_access(dev);
215+
} else {
216+
if (dev->va != INVALID_VA) {
217+
mem_alloc_map_dev(&vm->as, SEC_VM_ANY, (vaddr_t)dev->va, dev->pa, n);
218+
}
217219
}
218220

219221
for (size_t j = 0; j < dev->interrupt_num; j++) {
@@ -319,6 +321,12 @@ struct vm* vm_init(struct vm_allocation* vm_alloc, const struct vm_config* vm_co
319321

320322
cpu_sync_barrier(&vm->sync);
321323

324+
if (master) {
325+
vm_mem_prot_init(vm, vm_config);
326+
}
327+
328+
cpu_sync_barrier(&vm->sync);
329+
322330
/**
323331
* Perform architecture dependent initializations. This includes, for example, setting the page
324332
* table pointer and other virtualization extensions specifics.
@@ -422,3 +430,10 @@ void vcpu_run(struct vcpu* vcpu)
422430
cpu_powerdown();
423431
}
424432
}
433+
434+
__attribute__((weak)) void vm_arch_allow_mmio_access(struct vm_dev_region* dev)
435+
{
436+
UNUSED_ARG(dev);
437+
ERROR("vm_arch_allow_mmio_access must be implemented by the arch!")
438+
return;
439+
}

0 commit comments

Comments
 (0)