Skip to content

Commit 5950c01

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 7dba0a9 commit 5950c01

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
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: 17 additions & 5 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)
@@ -210,9 +208,10 @@ static void vm_init_dev(struct vm* vm, const struct vm_config* vm_config)
210208
for (size_t i = 0; i < vm_config->platform.dev_num; i++) {
211209
struct vm_dev_region* dev = &vm_config->platform.devs[i];
212210

213-
size_t n = ALIGN(dev->size, PAGE_SIZE) / PAGE_SIZE;
214-
215-
if (dev->va != INVALID_VA) {
211+
if (DEFINED(MMIO_SLAVE_SIDE_PROT)) {
212+
vm_arch_allow_mmio_access(dev);
213+
} else if (dev->va != INVALID_VA) {
214+
size_t n = ALIGN(dev->size, PAGE_SIZE) / PAGE_SIZE;
216215
mem_alloc_map_dev(&vm->as, SEC_VM_ANY, (vaddr_t)dev->va, dev->pa, n);
217216
}
218217

@@ -319,6 +318,12 @@ struct vm* vm_init(struct vm_allocation* vm_alloc, const struct vm_config* vm_co
319318

320319
cpu_sync_barrier(&vm->sync);
321320

321+
if (master) {
322+
vm_mem_prot_init(vm, vm_config);
323+
}
324+
325+
cpu_sync_barrier(&vm->sync);
326+
322327
/**
323328
* Perform architecture dependent initializations. This includes, for example, setting the page
324329
* table pointer and other virtualization extensions specifics.
@@ -422,3 +427,10 @@ void vcpu_run(struct vcpu* vcpu)
422427
cpu_powerdown();
423428
}
424429
}
430+
431+
__attribute__((weak)) void vm_arch_allow_mmio_access(struct vm_dev_region* dev)
432+
{
433+
UNUSED_ARG(dev);
434+
ERROR("vm_arch_allow_mmio_access must be implemented by the arch!")
435+
return;
436+
}

0 commit comments

Comments
 (0)