Skip to content

Commit f0a2ce4

Browse files
committed
fix(core/remio): add shared memory verification
This commit ensures that the shared memory between the frontend and backend is properly aligned, as both sides must maintain perfect alignment for correct functionality. Signed-off-by: João Peixoto <[email protected]>
1 parent 7c277bf commit f0a2ce4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/core/remio.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ void remio_init(void)
394394
{
395395
size_t frontend_cnt = 0, backend_cnt = 0;
396396
int devices[REMIO_MAX_DEVICES][REMIO_NUM_DEV_TYPES];
397+
struct remio_shmem shmem[REMIO_MAX_DEVICES][REMIO_NUM_DEV_TYPES];
397398

398399
/** Only execute the Remote I/O initialization routine on the master CPU */
399400
if (!cpu_is_master()) {
@@ -407,6 +408,8 @@ void remio_init(void)
407408
for (size_t i = 0; i < REMIO_MAX_DEVICES; i++) {
408409
devices[i][REMIO_DEV_FRONTEND] = REMIO_DEVICE_UNINITIALIZED;
409410
devices[i][REMIO_DEV_BACKEND] = REMIO_DEVICE_UNINITIALIZED;
411+
shmem[i][REMIO_DEV_FRONTEND] = (struct remio_shmem){ 0 };
412+
shmem[i][REMIO_DEV_BACKEND] = (struct remio_shmem){ 0 };
410413
}
411414

412415
/** Create the Remote I/O devices based on the VM configuration */
@@ -429,9 +432,11 @@ void remio_init(void)
429432
list_push(&remio_device_list, (node_t*)device);
430433
backend_cnt++;
431434
devices[dev->id][REMIO_DEV_BACKEND] = (int)vm_id;
435+
shmem[dev->id][REMIO_DEV_BACKEND] = dev->shmem;
432436
} else if (dev->type == REMIO_DEV_FRONTEND) {
433437
frontend_cnt++;
434438
devices[dev->id][REMIO_DEV_FRONTEND] = (int)vm_id;
439+
shmem[dev->id][REMIO_DEV_FRONTEND] = dev->shmem;
435440
} else {
436441
ERROR("Unknown Remote I/O device type");
437442
}
@@ -443,6 +448,20 @@ void remio_init(void)
443448
ERROR("There is no 1-to-1 mapping between a Remote I/O backend and Remote I/O frontend");
444449
}
445450

451+
/** Check if the shared memory regions are correctly configured */
452+
for (size_t i = 0; i < REMIO_MAX_DEVICES; i++) {
453+
if (devices[i][REMIO_DEV_FRONTEND] != REMIO_DEVICE_UNINITIALIZED &&
454+
devices[i][REMIO_DEV_BACKEND] != REMIO_DEVICE_UNINITIALIZED) {
455+
if (shmem[i][REMIO_DEV_FRONTEND].base != shmem[i][REMIO_DEV_BACKEND].base ||
456+
shmem[i][REMIO_DEV_FRONTEND].size != shmem[i][REMIO_DEV_BACKEND].size ||
457+
shmem[i][REMIO_DEV_FRONTEND].shmem_id != shmem[i][REMIO_DEV_BACKEND].shmem_id) {
458+
ERROR("Invalid shared memory region configuration for Remote I/O device %d.\n"
459+
"The frontend and backend shared memory regions must be the aligned.",
460+
i);
461+
}
462+
}
463+
}
464+
446465
/** Update the Remote I/O device configuration */
447466
for (size_t vm_id = 0; vm_id < config.vmlist_size; vm_id++) {
448467
struct vm_config* vm_config = &config.vmlist[vm_id];

0 commit comments

Comments
 (0)