Skip to content

Commit 5ef646b

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 d30848a commit 5ef646b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config)
212212

213213
size_t n = ALIGN(dev->size, PAGE_SIZE) / PAGE_SIZE;
214214

215-
if (dev->va != INVALID_VA) {
216-
mem_alloc_map_dev(&vm->as, SEC_VM_ANY, (vaddr_t)dev->va, dev->pa, n);
215+
if (DEFINED(MMIO_SLAVE_SIDE_PROT)) {
216+
vm_arch_allow_mmio_access(dev);
217+
} else {
218+
if (dev->va != INVALID_VA) {
219+
mem_alloc_map_dev(&vm->as, SEC_VM_ANY, (vaddr_t)dev->va, dev->pa, n);
220+
}
217221
}
218222

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

320324
cpu_sync_barrier(&vm->sync);
321325

326+
if (master) {
327+
vm_mem_prot_init(vm, vm_config);
328+
}
329+
330+
cpu_sync_barrier(&vm->sync);
331+
322332
/**
323333
* Perform architecture dependent initializations. This includes, for example, setting the page
324334
* table pointer and other virtualization extensions specifics.
@@ -422,3 +432,10 @@ void vcpu_run(struct vcpu* vcpu)
422432
cpu_powerdown();
423433
}
424434
}
435+
436+
__attribute__((weak)) void vm_arch_allow_mmio_access(struct vm_dev_region* dev)
437+
{
438+
UNUSED_ARG(dev);
439+
ERROR("vm_arch_allow_mmio_access must be implemented by the arch!")
440+
return;
441+
}

0 commit comments

Comments
 (0)