diff --git a/kernel/ibv.c b/kernel/ibv.c index 25216baed..89bb405a2 100644 --- a/kernel/ibv.c +++ b/kernel/ibv.c @@ -34,24 +34,27 @@ #include // GEHT -#define MAX_NUM_OF_IBV_DEVICES 16 +// TODO: Can/should we separate ibv_get_device_list into two KVM exit IOs to +// allocate the right amount of memory? +#define MAX_NUM_OF_IBV_DEVICES 16 typedef struct { - // In: int *num_devices; - // Out: struct ibv_device *dev_phys_ptr_list[MAX_NUM_OF_IBV_DEVICES]; - /*struct ibv_device **device_list;*/ + // TODO: Can we make the return type struct ibv_device**? } __attribute__((packed)) uhyve_ibv_get_device_list_t; struct ibv_device** h_ibv_get_device_list(int *num_devices) { + // num_devices can be mapped to physical memory right away. uhyve_ibv_get_device_list_t uhyve_args = {(int*) virt_to_phys((size_t) num_devices)}; + // Allocate memory for return value. struct ibv_device *devs = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device)); - struct ibv_device **list_virt; - list_virt = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *)); // NUM + 1 ??? + struct ibv_device **list_virt = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *)); + // We keep a list of the virtual addresses, so we can return it later, and map + // to physical addresses for the args struct passed to uhyve. for (int i = 0; i < MAX_NUM_OF_IBV_DEVICES; i++) { struct ibv_device* device_address = devs + i; list_virt[i] = device_address; diff --git a/tools/uhyve.c b/tools/uhyve.c index dbe9bd6b2..8a4ca8b1b 100644 --- a/tools/uhyve.c +++ b/tools/uhyve.c @@ -972,22 +972,18 @@ static int vcpu_loop(void) unsigned data = *((unsigned*)((size_t)run+run->io.data_offset)); uhyve_ibv_get_device_list_t* args = (uhyve_ibv_get_device_list_t*) (guest_mem+data); + // Call IBV function from hypervisor int num_devices; struct ibv_device **temp_dev_list = ibv_get_device_list(&num_devices); - printf("uhyve.c: before memcpy num_devices.\n"); - memcpy(guest_mem+(size_t)args->num_devices, &num_devices, sizeof(num_devices)); - /*memcpy(args->num_devices, &num_devices, sizeof(num_devices));*/ - printf("uhyve.c: before for loop.\n"); + // Copy number of devices to kernel memory + memcpy(guest_mem+(size_t)args->num_devices, &num_devices, sizeof(num_devices)); + for (int d = 0; d < num_devices; d++) { // TODO switch to num devices - /*struct ibv_device* dest_device_guest = guest_mem + (size_t)args->first_device + d*sizeof(struct ibv_device);*/ - /*struct ibv_device* dest_device_guest = guest_mem + (size_t)args->first_device;*/ - /*memcpy(dest_device_guest, temp_dev_list[d], sizeof(struct ibv_device));*/ printf("uhyve.c: before memcpy list[d].\n"); + // Copy array entry containing ibv_device struct to kernel memory memcpy(guest_mem + (size_t)args->dev_phys_ptr_list[d], temp_dev_list[d], sizeof(struct ibv_device)); } - - printf("uhyve.c: before break.\n"); break; }