mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
basic phys_to_virt framework set up.
This commit is contained in:
parent
9f3922feec
commit
2faf331052
10 changed files with 230 additions and 252 deletions
|
@ -115,6 +115,38 @@ size_t virt_to_phys(size_t addr)
|
|||
}
|
||||
}
|
||||
|
||||
size_t phys_to_virt(size_t addr)
|
||||
{
|
||||
size_t * pml4 = self[PAGE_LEVELS-1];
|
||||
for(size_t i=0; i<(1 << PAGE_MAP_BITS); i++) {
|
||||
if (!(pml4[i] & PG_PRESENT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t * pdpt = (size_t *) (pml4[i] & PAGE_MASK);
|
||||
for(size_t j=0; j<(1 << PAGE_MAP_BITS); j++) {
|
||||
if (!(pdpt[j] & PG_PRESENT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t * pgd = (size_t *) (pdpt[j] & PAGE_MASK);
|
||||
for(size_t k=0; k<(1 << PAGE_MAP_BITS); k++) {
|
||||
if (!(pgd[k] & PG_PRESENT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t * pgt = (size_t *) (pgd[k] & PAGE_MASK);
|
||||
for(size_t l=0; l<(1 << PAGE_MAP_BITS); l++) {
|
||||
if (pgt[l] & PG_PRESENT) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get memory page size
|
||||
*/
|
||||
|
|
|
@ -41,11 +41,11 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
struct ibv_device ** ibv_get_device_list(int * num_devices);
|
||||
const char * ibv_get_device_name(struct ibv_device *device);
|
||||
struct ibv_context * ibv_open_device(struct ibv_device * device);
|
||||
int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr);
|
||||
struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context);
|
||||
struct ibv_device ** ibv_get_device_list(int * num_devices);
|
||||
|
||||
void kernel_ibv_log();
|
||||
|
||||
|
|
|
@ -37,7 +37,11 @@ extern uint8_t * kernel_start_host;
|
|||
|
||||
|
||||
inline size_t guest_to_host(size_t address) {
|
||||
return virt_to_phys(address) + (size_t) kernel_start_host;
|
||||
return address ? virt_to_phys(address) + (size_t) kernel_start_host : address;
|
||||
}
|
||||
|
||||
inline size_t host_to_guest(size_t address) {
|
||||
return address ? phys_to_virt(address - (size_t) kernel_start_host) : address;
|
||||
}
|
||||
|
||||
|
||||
|
|
159
kernel/ibv.c
159
kernel/ibv.c
|
@ -45,35 +45,47 @@
|
|||
#define MAX_NUM_OF_IBV_DEVICES 16
|
||||
|
||||
|
||||
static void * ret_guest_ptr;
|
||||
static void * ret_guest;
|
||||
|
||||
|
||||
/*
|
||||
* ibv_open_device
|
||||
* ibv_get_device_list
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
struct ibv_device * device;
|
||||
int * num_devices;
|
||||
// Return value:
|
||||
struct ibv_context * ret;
|
||||
} __attribute__((packed)) uhyve_ibv_open_device_t;
|
||||
struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES];
|
||||
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
|
||||
|
||||
struct ibv_context * ibv_open_device(struct ibv_device * device) {
|
||||
/* printf("LOG: ibv_open_device"); */
|
||||
uhyve_ibv_open_device_t uhyve_args;
|
||||
uhyve_args.device = guest_to_host_ibv_device(device);
|
||||
struct ibv_device ** 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;
|
||||
uhyve_args.num_devices = (int *) guest_to_host((size_t) num_devices);
|
||||
|
||||
ret_guest_ptr = kmalloc(sizeof(struct ibv_context));
|
||||
uhyve_args.ret = (struct ibv_context *) guest_to_host((size_t) ret_guest_ptr);
|
||||
// Allocate memory for return value.
|
||||
struct ibv_device * devs = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device));
|
||||
struct ibv_device ** ret_guest = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *));
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned)guest_to_host((size_t)&uhyve_args));
|
||||
// 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;
|
||||
ret_guest[i] = device_address;
|
||||
uhyve_args.ret[i] = (struct ibv_device *) guest_to_host((size_t) device_address);
|
||||
}
|
||||
|
||||
host_to_guest_ibv_device(device);
|
||||
uhyve_args.ret = (struct ibv_context *) ret_guest_ptr;
|
||||
// TODO: Fix pointers in returned data structures.
|
||||
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args));
|
||||
|
||||
return uhyve_args.ret;
|
||||
for (int i = 0; i < MAX_NUM_OF_IBV_DEVICES; i++) {
|
||||
host_to_guest_ibv_device(ret_guest[i]);
|
||||
struct ibv_device * device_address = devs + i;
|
||||
ret_guest[i] = device_address;
|
||||
uhyve_args.ret[i] = (struct ibv_device *) guest_to_host((size_t) device_address);
|
||||
}
|
||||
|
||||
return ret_guest;
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,14 +104,44 @@ const char * ibv_get_device_name(struct ibv_device * device) {
|
|||
uhyve_ibv_get_device_name_t uhyve_args;
|
||||
uhyve_args.device = guest_to_host_ibv_device(device);
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) guest_to_host((size_t) &uhyve_args));
|
||||
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args));
|
||||
|
||||
host_to_guest_ibv_device(device);
|
||||
ret_guest = host_to_guest((size_t) uhyve_args.ret);
|
||||
// Lookup return address in hash map created earlier. Found? convert back.
|
||||
// Hack for testing:
|
||||
uhyve_args.ret = uhyve_args.device->name;
|
||||
// Hack for testing, replace by line above.
|
||||
ret_guest = device->name;
|
||||
|
||||
return uhyve_args.ret;
|
||||
return ret_guest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* ibv_open_device
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
struct ibv_device * device;
|
||||
// Return value:
|
||||
struct ibv_context * ret;
|
||||
} __attribute__((packed)) uhyve_ibv_open_device_t;
|
||||
|
||||
struct ibv_context * ibv_open_device(struct ibv_device * device) {
|
||||
/* printf("LOG: ibv_open_device"); */
|
||||
uhyve_ibv_open_device_t uhyve_args;
|
||||
uhyve_args.device = guest_to_host_ibv_device(device);
|
||||
|
||||
ret_guest = kmalloc(sizeof(struct ibv_context));
|
||||
uhyve_args.ret = (struct ibv_context *) guest_to_host((size_t) ret_guest);
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_OPEN_DEVICE, (unsigned)virt_to_phys((size_t)&uhyve_args));
|
||||
|
||||
host_to_guest_ibv_device(device);
|
||||
host_to_guest_ibv_context((struct ibv_context * ) ret_guest);
|
||||
|
||||
return ret_guest;
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,7 +165,7 @@ int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_po
|
|||
uhyve_args.port_num = port_num;
|
||||
uhyve_args.port_attr = guest_to_host_ibv_port_attr(port_attr);
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) guest_to_host((size_t) &uhyve_args));
|
||||
uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args));
|
||||
|
||||
host_to_guest_ibv_context(context);
|
||||
host_to_guest_ibv_port_attr(port_attr);
|
||||
|
@ -148,80 +190,15 @@ struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context)
|
|||
uhyve_ibv_create_comp_channel_t uhyve_args;
|
||||
uhyve_args.context = guest_to_host_ibv_context(context);
|
||||
|
||||
ret_guest_ptr = kmalloc(sizeof(struct ibv_comp_channel));
|
||||
uhyve_args.ret = (struct ibv_comp_channel *) guest_to_host((size_t) ret_guest_ptr);
|
||||
ret_guest = kmalloc(sizeof(struct ibv_comp_channel));
|
||||
uhyve_args.ret = (struct ibv_comp_channel *) guest_to_host((size_t) ret_guest);
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) guest_to_host((size_t) &uhyve_args));
|
||||
uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args));
|
||||
|
||||
host_to_guest_ibv_context(context);
|
||||
uhyve_args.ret = (struct ibv_comp_channel *) ret_guest_ptr;
|
||||
host_to_guest_ibv_comp_channel(ret_guest);
|
||||
|
||||
return uhyve_args.ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ibv_get_device_list
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
int * num_devices;
|
||||
// Return value:
|
||||
struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES];
|
||||
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
|
||||
|
||||
/* struct ibv_device ** 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; */
|
||||
/* uhyve_args.test = 42; */
|
||||
|
||||
/* uhyve_args.num_devices = (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 ** ret_guest_ptr = kmalloc(MAX_NUM_OF_IBV_DEVICES * sizeof(struct ibv_device *)); */
|
||||
|
||||
/* for (int i = 0; i < MAX_NUM_OF_IBV_DEVICES; i++) { */
|
||||
/* struct ibv_device * device_address = devs + i; */
|
||||
/* ret_guest_ptr[i] = device_address; */
|
||||
/* uhyve_args.ret[i] = (struct ibv_device *) virt_to_phys((size_t) device_address); */
|
||||
/* } */
|
||||
/* uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST_OLD, (unsigned) virt_to_phys((size_t) &uhyve_args)); */
|
||||
|
||||
/* // -------------- */
|
||||
|
||||
/* uhyve_args.num_devices = (int *) guest_to_host((size_t) num_devices); */
|
||||
|
||||
/* for (int i = 0; i < MAX_NUM_OF_IBV_DEVICES; i++) { */
|
||||
/* uhyve_args.ret[i] = (struct ibv_device *) guest_to_host((size_t) ret_guest_ptr[i]); */
|
||||
/* } */
|
||||
|
||||
/* uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) guest_to_host((size_t) &uhyve_args)); */
|
||||
|
||||
/* return ret_guest_ptr; */
|
||||
/* } */
|
||||
|
||||
|
||||
struct ibv_device ** 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;
|
||||
uhyve_args.num_devices = (int *) guest_to_host((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 ** ret_guest_ptr = 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;
|
||||
ret_guest_ptr[i] = device_address;
|
||||
uhyve_args.ret[i] = (struct ibv_device *) guest_to_host((size_t) device_address);
|
||||
}
|
||||
|
||||
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args));
|
||||
return ret_guest_ptr;
|
||||
return ret_guest;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ void host_to_guest_ibv_device(struct ibv_device * device) { }
|
|||
* struct ibv_context
|
||||
*/
|
||||
|
||||
static struct {
|
||||
struct ibv_device * device;
|
||||
void * abi_compat;
|
||||
} ibv_context_virt_ptrs;
|
||||
/* static struct { */
|
||||
/* struct ibv_device * device; */
|
||||
/* void * abi_compat; */
|
||||
/* } ibv_context_virt_ptrs; */
|
||||
|
||||
struct ibv_context * guest_to_host_ibv_context(struct ibv_context * context) {
|
||||
ibv_context_virt_ptrs.device = context->device,
|
||||
|
@ -81,40 +81,40 @@ void host_to_guest_ibv_context(struct ibv_context * context) {
|
|||
* struct ibv_context_ops
|
||||
*/
|
||||
|
||||
static struct {
|
||||
int (*query_device)(struct ibv_context *, struct ibv_device_attr *);
|
||||
int (*query_port)(struct ibv_context *, uint8_t, struct ibv_port_attr *);
|
||||
struct ibv_pd * (*alloc_pd)(struct ibv_context *);
|
||||
int (*dealloc_pd)(struct ibv_pd *);
|
||||
struct ibv_mr * (*reg_mr)(struct ibv_pd *, void *, size_t, int);
|
||||
int (*rereg_mr)(struct ibv_mr *, int, struct ibv_pd *, void *, size_t, int);
|
||||
int (*dereg_mr)(struct ibv_mr *);
|
||||
struct ibv_mw * (*alloc_mw)(struct ibv_pd *, enum ibv_mw_type);
|
||||
int (*bind_mw)(struct ibv_qp *, struct ibv_mw *, struct ibv_mw_bind *);
|
||||
int (*dealloc_mw)(struct ibv_mw *);
|
||||
struct ibv_cq * (*create_cq)(struct ibv_context *, int, struct ibv_comp_channel *, int);
|
||||
int (*poll_cq)(struct ibv_cq *, int, struct ibv_wc *);
|
||||
int (*req_notify_cq)(struct ibv_cq *, int);
|
||||
void (*cq_event)(struct ibv_cq *);
|
||||
int (*resize_cq)(struct ibv_cq *, int);
|
||||
int (*destroy_cq)(struct ibv_cq *);
|
||||
struct ibv_srq * (*create_srq)(struct ibv_pd *, struct ibv_srq_init_attr *);
|
||||
int (*modify_srq)(struct ibv_srq *, struct ibv_srq_attr *, int);
|
||||
int (*query_srq)(struct ibv_srq *, struct ibv_srq_attr *);
|
||||
int (*destroy_srq)(struct ibv_srq *);
|
||||
int (*post_srq_recv)(struct ibv_srq *, struct ibv_recv_wr *, struct ibv_recv_wr **);
|
||||
struct ibv_qp * (*create_qp)(struct ibv_pd *, struct ibv_qp_init_attr *);
|
||||
int (*query_qp)(struct ibv_qp *, struct ibv_qp_attr *, int, struct ibv_qp_init_attr *);
|
||||
int (*modify_qp)(struct ibv_qp *, struct ibv_qp_attr *, int);
|
||||
int (*destroy_qp)(struct ibv_qp *);
|
||||
int (*post_send)(struct ibv_qp *, struct ibv_send_wr *, struct ibv_send_wr **);
|
||||
int (*post_recv)(struct ibv_qp *, struct ibv_recv_wr *, struct ibv_recv_wr **);
|
||||
struct ibv_ah * (*create_ah)(struct ibv_pd *, struct ibv_ah_attr *);
|
||||
int (*destroy_ah)(struct ibv_ah *);
|
||||
int (*attach_mcast)(struct ibv_qp *, const union ibv_gid *, uint16_t);
|
||||
int (*detach_mcast)(struct ibv_qp *, const union ibv_gid *, uint16_t);
|
||||
void (*async_event)(struct ibv_async_event *);
|
||||
} ibv_context_ops_virt_ptrs;
|
||||
/* static struct { */
|
||||
/* int (*query_device)(struct ibv_context *, struct ibv_device_attr *); */
|
||||
/* int (*query_port)(struct ibv_context *, uint8_t, struct ibv_port_attr *); */
|
||||
/* struct ibv_pd * (*alloc_pd)(struct ibv_context *); */
|
||||
/* int (*dealloc_pd)(struct ibv_pd *); */
|
||||
/* struct ibv_mr * (*reg_mr)(struct ibv_pd *, void *, size_t, int); */
|
||||
/* int (*rereg_mr)(struct ibv_mr *, int, struct ibv_pd *, void *, size_t, int); */
|
||||
/* int (*dereg_mr)(struct ibv_mr *); */
|
||||
/* struct ibv_mw * (*alloc_mw)(struct ibv_pd *, enum ibv_mw_type); */
|
||||
/* int (*bind_mw)(struct ibv_qp *, struct ibv_mw *, struct ibv_mw_bind *); */
|
||||
/* int (*dealloc_mw)(struct ibv_mw *); */
|
||||
/* struct ibv_cq * (*create_cq)(struct ibv_context *, int, struct ibv_comp_channel *, int); */
|
||||
/* int (*poll_cq)(struct ibv_cq *, int, struct ibv_wc *); */
|
||||
/* int (*req_notify_cq)(struct ibv_cq *, int); */
|
||||
/* void (*cq_event)(struct ibv_cq *); */
|
||||
/* int (*resize_cq)(struct ibv_cq *, int); */
|
||||
/* int (*destroy_cq)(struct ibv_cq *); */
|
||||
/* struct ibv_srq * (*create_srq)(struct ibv_pd *, struct ibv_srq_init_attr *); */
|
||||
/* int (*modify_srq)(struct ibv_srq *, struct ibv_srq_attr *, int); */
|
||||
/* int (*query_srq)(struct ibv_srq *, struct ibv_srq_attr *); */
|
||||
/* int (*destroy_srq)(struct ibv_srq *); */
|
||||
/* int (*post_srq_recv)(struct ibv_srq *, struct ibv_recv_wr *, struct ibv_recv_wr **); */
|
||||
/* struct ibv_qp * (*create_qp)(struct ibv_pd *, struct ibv_qp_init_attr *); */
|
||||
/* int (*query_qp)(struct ibv_qp *, struct ibv_qp_attr *, int, struct ibv_qp_init_attr *); */
|
||||
/* int (*modify_qp)(struct ibv_qp *, struct ibv_qp_attr *, int); */
|
||||
/* int (*destroy_qp)(struct ibv_qp *); */
|
||||
/* int (*post_send)(struct ibv_qp *, struct ibv_send_wr *, struct ibv_send_wr **); */
|
||||
/* int (*post_recv)(struct ibv_qp *, struct ibv_recv_wr *, struct ibv_recv_wr **); */
|
||||
/* struct ibv_ah * (*create_ah)(struct ibv_pd *, struct ibv_ah_attr *); */
|
||||
/* int (*destroy_ah)(struct ibv_ah *); */
|
||||
/* int (*attach_mcast)(struct ibv_qp *, const union ibv_gid *, uint16_t); */
|
||||
/* int (*detach_mcast)(struct ibv_qp *, const union ibv_gid *, uint16_t); */
|
||||
/* void (*async_event)(struct ibv_async_event *); */
|
||||
/* } ibv_context_ops_virt_ptrs; */
|
||||
|
||||
struct ibv_context_ops * guest_to_host_ibv_context_ops(struct ibv_context_ops * context_ops) {
|
||||
ibv_context_ops_virt_ptrs.query_device = context_ops->query_device;
|
||||
|
@ -238,9 +238,9 @@ void host_to_guest_ibv_port_attr(struct ibv_port_attr * port_attr) {}
|
|||
* struct ibv_comp_channel
|
||||
*/
|
||||
|
||||
static struct {
|
||||
struct ibv_context * context;
|
||||
} ibv_comp_channel_virt_ptrs;
|
||||
/* static struct { */
|
||||
/* struct ibv_context * context; */
|
||||
/* } ibv_comp_channel_virt_ptrs; */
|
||||
|
||||
struct ibv_comp_channel * guest_to_host_ibv_comp_channel(struct ibv_comp_channel * channel) {
|
||||
ibv_comp_channel_virt_ptrs.context = channel->context;
|
||||
|
@ -278,9 +278,9 @@ void host_to_guest_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat) {
|
|||
* pthread_mutex_t
|
||||
*/
|
||||
|
||||
static struct {
|
||||
_pthread_descr __m_owner;
|
||||
} pthread_mutex_t_virt_ptrs;
|
||||
/* static struct { */
|
||||
/* _pthread_descr __m_owner; */
|
||||
/* } pthread_mutex_t_virt_ptrs; */
|
||||
|
||||
pthread_mutex_t * guest_to_host_pthread_mutex_t(pthread_mutex_t * mutex) {
|
||||
pthread_mutex_t_virt_ptrs.__m_owner = mutex->__m_owner; // TODO:
|
||||
|
|
|
@ -33,25 +33,26 @@
|
|||
#include <infiniband/verbs.h> // Linux include
|
||||
|
||||
|
||||
// struct ibv_context * ibv_open_device(struct ibv_device * device);
|
||||
// const char* ibv_get_device_name(struct ibv_device *device);
|
||||
// int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr);
|
||||
// struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context);
|
||||
|
||||
|
||||
/*
|
||||
* ibv_open_device
|
||||
* ibv_get_device_list
|
||||
*/
|
||||
|
||||
void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) {
|
||||
printf("LOG: UHYVE - call_ibv_open_device");
|
||||
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
|
||||
uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data);
|
||||
void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem) {
|
||||
printf("LOG: UHYVE - call_ibv_get_device_list\n");
|
||||
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);
|
||||
|
||||
struct ibv_context * host_ret = ibv_open_device(args->device);
|
||||
memcpy(args->ret, host_ret, sizeof(host_ret));
|
||||
// TODO: Convert ptrs contained in return value.
|
||||
free(host_ret);
|
||||
// Call IBV function from hypervisor
|
||||
int num_devices;
|
||||
struct ibv_device **host_ret = ibv_get_device_list(&num_devices);
|
||||
|
||||
// Copy number of devices and device stucts to kernel memory
|
||||
if (args->num_devices) {
|
||||
memcpy(args->num_devices, &num_devices, sizeof(num_devices));
|
||||
}
|
||||
for (int d = 0; d < num_devices; d++) {
|
||||
memcpy(args->ret[d], host_ret[d], sizeof(struct ibv_device));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,13 +66,33 @@ void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem) {
|
|||
uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data);
|
||||
|
||||
// TODO: Tricky because char ptr isn't allocated in called function.
|
||||
const char * host_ret = ibv_get_device_name(args->device);
|
||||
memcpy(args->ret, host_ret, sizeof(host_ret));
|
||||
args->ret = ibv_get_device_name(args->device);
|
||||
/* memcpy(args->ret, host_ret, sizeof(host_ret)); */
|
||||
// TODO: Convert ptrs contained in return value.
|
||||
// TODO: How to tell if ret needs to be deleted?
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ibv_open_device
|
||||
*/
|
||||
|
||||
void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) {
|
||||
printf("LOG: UHYVE - call_ibv_open_device\n");
|
||||
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
|
||||
uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data);
|
||||
|
||||
printf("LOG: UHYVE - call_ibv_open_device\n");
|
||||
struct ibv_context * host_ret = ibv_open_device(args->device);
|
||||
printf("LOG: UHYVE - call_ibv_open_device\n");
|
||||
memcpy(args->ret, host_ret, sizeof(host_ret));
|
||||
printf("LOG: UHYVE - call_ibv_open_device\n");
|
||||
// TODO: Convert ptrs contained in return value.
|
||||
free(host_ret);
|
||||
printf("LOG: UHYVE - call_ibv_open_device\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ibv_query_port
|
||||
*/
|
||||
|
@ -102,26 +123,3 @@ void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem) {
|
|||
}
|
||||
|
||||
|
||||
void call_ibv_get_device_list(struct kvm_run * run, uint8_t * guest_mem) {
|
||||
printf("LOG: UHYVE - call_ibv_get_device_list");
|
||||
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);
|
||||
|
||||
printf("LOG: UHYVE - call_ibv_get_device_list");
|
||||
// Call IBV function from hypervisor
|
||||
int num_devices;
|
||||
struct ibv_device **host_ret = ibv_get_device_list(&num_devices);
|
||||
|
||||
printf("LOG: UHYVE - call_ibv_get_device_list");
|
||||
// Copy number of devices to kernel memory
|
||||
if (args->num_devices) {
|
||||
memcpy(args->num_devices, &num_devices, sizeof(num_devices));
|
||||
}
|
||||
|
||||
printf("LOG: UHYVE - call_ibv_get_device_list");
|
||||
for (int d = 0; d < num_devices; d++) {
|
||||
// Copy array entry containing ibv_device struct to kernel memory
|
||||
printf("LOG: UHYVE FOR - call_ibv_get_device_list");
|
||||
memcpy(args->ret[d], host_ret[d], sizeof(struct ibv_device));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,10 @@ typedef enum {
|
|||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
struct ibv_device * device;
|
||||
int * num_devices;
|
||||
// Return value:
|
||||
struct ibv_context * ret;
|
||||
} __attribute__((packed)) uhyve_ibv_open_device_t;
|
||||
struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES];
|
||||
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
|
@ -53,6 +53,13 @@ typedef struct {
|
|||
const char * ret; // TODO Should this be const?
|
||||
} __attribute__((packed)) uhyve_ibv_get_device_name_t;
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
struct ibv_device * device;
|
||||
// Return value:
|
||||
struct ibv_context * ret;
|
||||
} __attribute__((packed)) uhyve_ibv_open_device_t;
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
struct ibv_context * context;
|
||||
|
@ -69,13 +76,6 @@ typedef struct {
|
|||
struct ibv_comp_channel * ret;
|
||||
} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;
|
||||
|
||||
typedef struct {
|
||||
// Parameters:
|
||||
int * num_devices;
|
||||
// Return value:
|
||||
struct ibv_device * ret[MAX_NUM_OF_IBV_DEVICES];
|
||||
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
|
||||
|
||||
void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem);
|
||||
void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem);
|
||||
void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem);
|
||||
|
|
|
@ -474,9 +474,7 @@ static int load_kernel(uint8_t* mem, char* path)
|
|||
}
|
||||
|
||||
// TODO: Compiler Warning
|
||||
printf("LOG: GUEST_MEM\n");
|
||||
*((uint64_t*) (mem+paddr-GUEST_OFFSET + 0xBC)) = guest_mem; // host-virtual start address (kernel_start_host)
|
||||
printf("LOG: GUEST_MEM\n");
|
||||
|
||||
}
|
||||
*((uint64_t*) (mem+paddr-GUEST_OFFSET + 0x38)) += memsz; // total kernel size
|
||||
|
@ -980,43 +978,27 @@ static int vcpu_loop(void)
|
|||
}
|
||||
|
||||
// InfiniBand
|
||||
case UHYVE_PORT_IBV_OPEN_DEVICE:
|
||||
call_ibv_open_device(run, guest_mem);
|
||||
case UHYVE_PORT_IBV_GET_DEVICE_LIST: {
|
||||
printf("LOG: UHYVE CASE\n");
|
||||
call_ibv_get_device_list(run, guest_mem);
|
||||
break;
|
||||
case UHYVE_PORT_IBV_GET_DEVICE_NAME:
|
||||
printf("LOG: UHYVE CASE UHYVE_PORT_IBV_GET_DEVICE_NAME\n");
|
||||
call_ibv_get_device_name(run, guest_mem);
|
||||
break;
|
||||
case UHYVE_PORT_IBV_OPEN_DEVICE:
|
||||
printf("LOG: UHYVE CASE UHYVE_PORT_IBV_OPEN_DEVICE\n");
|
||||
call_ibv_open_device(run, guest_mem);
|
||||
break;
|
||||
case UHYVE_PORT_IBV_QUERY_PORT:
|
||||
printf("LOG: UHYVE CASE UHYVE_PORT_IBV_QUERY_PORT\n");
|
||||
call_ibv_query_port(run, guest_mem);
|
||||
break;
|
||||
case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL:
|
||||
printf("LOG: UHYVE CASE UHYVE_PORT_IBV_CREATE_COMP_CHANNEL\n");
|
||||
call_ibv_create_comp_channel(run, guest_mem);
|
||||
break;
|
||||
|
||||
case UHYVE_PORT_IBV_GET_DEVICE_LIST: {
|
||||
printf("LOG: UHYVE CASE");
|
||||
call_ibv_get_device_list(run, guest_mem);
|
||||
|
||||
/* 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 **host_ret = ibv_get_device_list(&num_devices); */
|
||||
|
||||
/* // Copy number of devices to kernel memory */
|
||||
/* if (args->num_devices) { */
|
||||
/* memcpy(args->num_devices, &num_devices, sizeof(num_devices)); */
|
||||
/* } */
|
||||
|
||||
/* for (int d = 0; d < num_devices; d++) { */
|
||||
/* // Copy array entry containing ibv_device struct to kernel memory */
|
||||
/* printf("LOG: UHYVE CASE FOR\n"); */
|
||||
/* memcpy(args->ret[d], host_ret[d], sizeof(struct ibv_device)); */
|
||||
/* } */
|
||||
|
||||
/* printf("LOG: UHYVE CASE\n"); */
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
|
||||
#include <hermit/ibv.h> // Geht per cmake copy workaround
|
||||
|
||||
#define N 255
|
||||
/* #define N 255 */
|
||||
|
||||
static void test_handler(int s)
|
||||
{
|
||||
printf("Receive signal with number %d\n", s);
|
||||
}
|
||||
/* static void test_handler(int s) */
|
||||
/* { */
|
||||
/* printf("Receive signal with number %d\n", s); */
|
||||
/* } */
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -51,34 +51,19 @@ int main(int argc, char** argv)
|
|||
struct ibv_device **dev_list;
|
||||
int num_devices;
|
||||
|
||||
printf("ib-test.c: before kernel ibv_log\n");
|
||||
kernel_ibv_log();
|
||||
printf("ib-test.c: before get dev list.\n");
|
||||
dev_list = ibv_get_device_list(&num_devices);
|
||||
printf("ib-test.c: after get dev list.\n");
|
||||
printf("after get device list -- ib-test.c: num devices: %d\n", num_devices);
|
||||
|
||||
printf("ib-test.c: num devices: %d\n", num_devices);
|
||||
printf("before get device name.\n");
|
||||
const char* dev_name = ibv_get_device_name(dev_list[0]);
|
||||
printf("after get device name -- Device: %s", dev_name);
|
||||
|
||||
/* for (int i=0; i < num_devices; i++) { */
|
||||
/* printf("ib_test.c: Device name No. %d: %s\n", i, dev_list[i]->name); */
|
||||
/* } */
|
||||
printf("before open_device\n");
|
||||
ibv_context * context = ibv_open_device(dev_list[0]);
|
||||
printf("after open device name -- Device: %s", dev_name);
|
||||
|
||||
/*if (!dev_list) {*/
|
||||
/*perror("Failed to get IB devices list");*/
|
||||
/*return 1;*/
|
||||
/*}*/
|
||||
/*printf("after dev list check.\n");*/
|
||||
|
||||
/*const char* dev_name = ibv_get_device_name(dev_list[0]);*/
|
||||
/*printf("after get device name.\n");*/
|
||||
|
||||
/*if (!dev_name) {*/
|
||||
/*perror("Failed to get devices name");*/
|
||||
/*return 1;*/
|
||||
/*}*/
|
||||
|
||||
/*printf("Device: %s", dev_name);*/
|
||||
/*printf("\nafter get dev name.\n");*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -310,10 +310,10 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
int rx_depth, int port,
|
||||
int use_event)
|
||||
{
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
struct pingpong_context *ctx;
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
ctx = malloc(sizeof *ctx);
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
@ -322,7 +322,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
ctx->send_flags = IBV_SEND_SIGNALED;
|
||||
ctx->rx_depth = rx_depth;
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
ctx->buf = memalign(page_size, size + 40);
|
||||
if (!ctx->buf) {
|
||||
fprintf(stderr, "Couldn't allocate work buf.\n");
|
||||
|
@ -332,7 +332,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
/* FIXME memset(ctx->buf, 0, size + 40); */
|
||||
memset(ctx->buf, 0x7b, size + 40);
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
ctx->context = ibv_open_device(ib_dev);
|
||||
if (!ctx->context) {
|
||||
fprintf(stderr, "Couldn't get context for %s\n",
|
||||
|
@ -340,7 +340,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
goto clean_buffer;
|
||||
}
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
{
|
||||
struct ibv_port_attr port_info = {};
|
||||
int mtu;
|
||||
|
@ -356,7 +356,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
}
|
||||
}
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
printf("LOG: PINGPONG - pp_init_ctx\n");
|
||||
if (use_event) {
|
||||
ctx->channel = ibv_create_comp_channel(ctx->context);
|
||||
if (!ctx->channel) {
|
||||
|
@ -572,7 +572,7 @@ static void usage(const char *argv0)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("LOG: PINGPONG - main");
|
||||
printf("LOG: PINGPONG - main\n");
|
||||
struct ibv_device **dev_list;
|
||||
struct ibv_device *ib_dev;
|
||||
struct pingpong_context *ctx;
|
||||
|
@ -594,14 +594,14 @@ int main(int argc, char *argv[])
|
|||
int gidx = -1;
|
||||
char gid[33];
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
printf("LOG: PINGPONG - main\n");
|
||||
srand48(getpid() * time(NULL));
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
printf("LOG: PINGPONG - main\n");
|
||||
while (1) {
|
||||
int c;
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
printf("LOG: PINGPONG - main\n");
|
||||
static struct option long_options[] = {
|
||||
{ .name = "port", .has_arg = 1, .val = 'p' },
|
||||
{ .name = "ib-dev", .has_arg = 1, .val = 'd' },
|
||||
|
|
Loading…
Add table
Reference in a new issue