Skip to content

Commit 6f54e31

Browse files
committed
fix(iodispatcher): initialize virtio_requests_lock and hypercall context fields
Initialize client->virtio_requests_lock in bao_io_client_create(). Without explicitly initializing this mutex, the first lock operation can trigger a breakpoint (BKP) exception on RISC-V due to operating on an uninitialized lock structure. Also explicitly initialize ctx.access_width and ctx.npend_req in bao_dispatch_io() before issuing the hypercall. This avoids passing uninitialized stack data to the hypervisor and makes the hypercall context state fully defined. These changes improve robustness and prevent runtime exceptions on RISC-V systems. Signed-off-by: João Peixoto <joaopeixotooficial@gmail.com>
1 parent 5940e1c commit 6f54e31

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

iodispatcher/io_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ struct bao_io_client* bao_io_client_create(struct bao_dm* dm, bao_io_client_hand
279279
}
280280

281281
INIT_LIST_HEAD(&client->virtio_requests);
282+
mutex_init(&client->virtio_requests_lock);
282283
init_rwsem(&client->range_lock);
283284
INIT_LIST_HEAD(&client->range_list);
284285
init_waitqueue_head(&client->wq);

iodispatcher/io_dispatcher.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ int bao_dispatch_io(struct bao_dm* dm)
6363
ctx.addr = 0;
6464
ctx.value = 0;
6565
ctx.request_id = 0;
66+
ctx.access_width = 0;
67+
ctx.npend_req = 0;
6668

6769
if (bao_remio_hypercall(&ctx)) {
6870
return -EFAULT;

0 commit comments

Comments
 (0)