1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

Improved generated code.

This commit is contained in:
Annika Wierichs 2017-11-02 16:41:29 +01:00
parent cc0cb1c882
commit bec8a1859c
8 changed files with 826 additions and 907 deletions

View file

@ -99,337 +99,337 @@ struct ibv_context * ibv_open_device(struct ibv_device * device) {
}
typedef struct {
// Parameters:
int * num_devices;
// Return value:
struct ibv_device ** ret; // TODO
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
/*typedef struct {*/
/*// Parameters:*/
/*int * num_devices;*/
/*// Return value:*/
/*struct ibv_device ** ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_get_device_list_t;*/
struct ibv_device ** ibv_get_device_list(int * num_devices) {
uhyve_ibv_get_device_list_t uhyve_args;
uhyve_args->num_devices = (int *) virt_to_phys((size_t) num_devices);
/*struct ibv_device ** ibv_get_device_list(int * num_devices) {*/
/*uhyve_ibv_get_device_list_t uhyve_args;*/
/*uhyve_args->num_devices = (int *) virt_to_phys((size_t) num_devices);*/
// TODO: Take care of return value.
/*// TODO: Take care of return value.*/
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_LIST, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
return uhyve_args.ret;
// TODO: Fix pointers in returned data structures.
}
/*return uhyve_args.ret;*/
/*// TODO: Fix pointers in returned data structures.*/
/*}*/
typedef struct {
// Parameters:
struct ibv_device * device;
// Return value:
const char * ret; // TODO
} __attribute__((packed)) uhyve_ibv_get_device_name_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_device * device;*/
/*// Return value:*/
/*const char * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_get_device_name_t;*/
const char * ibv_get_device_name(struct ibv_device * device) {
uhyve_ibv_get_device_name_t uhyve_args;
uhyve_args->device = (struct ibv_device *) virt_to_phys((size_t) device);
/*const char * ibv_get_device_name(struct ibv_device * device) {*/
/*uhyve_ibv_get_device_name_t uhyve_args;*/
/*uhyve_args->device = (struct ibv_device *) virt_to_phys((size_t) device);*/
uhyve_args->ret = kmalloc(sizeof(const char));
/*uhyve_args->ret = kmalloc(sizeof(const char));*/
uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_GET_DEVICE_NAME, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_context * context;
uint8_t port_num;
struct ibv_port_attr * port_attr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_query_port_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_context * context;*/
/*uint8_t port_num;*/
/*struct ibv_port_attr * port_attr;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_query_port_t;*/
int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) {
uhyve_ibv_query_port_t uhyve_args;
/*int ibv_query_port(struct ibv_context * context, uint8_t port_num, struct ibv_port_attr * port_attr) {*/
/*uhyve_ibv_query_port_t uhyve_args;*/
uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);
uhyve_args->port_num = port_num;
uhyve_args->port_attr = (struct ibv_port_attr *) virt_to_phys((size_t) port_attr);
/*uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);*/
/*uhyve_args->port_num = port_num;*/
/*uhyve_args->port_attr = (struct ibv_port_attr *) virt_to_phys((size_t) port_attr);*/
uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_QUERY_PORT, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
return uhyve_args.ret;
}
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
struct ibv_comp_channel * ret; // TODO
} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_context * context;*/
/*// Return value:*/
/*struct ibv_comp_channel * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;*/
struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) {
uhyve_ibv_create_comp_channel_t uhyve_args;
uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);
/*struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) {*/
/*uhyve_ibv_create_comp_channel_t uhyve_args;*/
/*uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);*/
uhyve_args->ret = kmalloc(sizeof(struct ibv_comp_channel));
/*uhyve_args->ret = kmalloc(sizeof(struct ibv_comp_channel));*/
uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_CREATE_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
struct ibv_pd * ret; // TODO
} __attribute__((packed)) uhyve_ibv_alloc_pd_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_context * context;*/
/*// Return value:*/
/*struct ibv_pd * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_alloc_pd_t;*/
struct ibv_pd * ibv_alloc_pd(struct ibv_context * context) {
uhyve_ibv_alloc_pd_t uhyve_args;
uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);
/*struct ibv_pd * ibv_alloc_pd(struct ibv_context * context) {*/
/*uhyve_ibv_alloc_pd_t uhyve_args;*/
/*uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);*/
uhyve_args->ret = kmalloc(sizeof(struct ibv_pd));
/*uhyve_args->ret = kmalloc(sizeof(struct ibv_pd));*/
uhyve_send(UHYVE_PORT_IBV_ALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_ALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_pd * pd;
void * addr;
int length;
int access;
// Return value:
struct ibv_mr * ret; // TODO
} __attribute__((packed)) uhyve_ibv_reg_mr_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_pd * pd;*/
/*void * addr;*/
/*int length;*/
/*int access;*/
/*// Return value:*/
/*struct ibv_mr * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_reg_mr_t;*/
struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access) {
uhyve_ibv_reg_mr_t uhyve_args;
uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);
uhyve_args->addr = (void *) virt_to_phys((size_t) addr);
uhyve_args->length = length;
uhyve_args->access = access;
/*struct ibv_mr * ibv_reg_mr(struct ibv_pd * pd, void * addr, int length, int access) {*/
/*uhyve_ibv_reg_mr_t uhyve_args;*/
/*uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);*/
/*uhyve_args->addr = (void *) virt_to_phys((size_t) addr);*/
/*uhyve_args->length = length;*/
/*uhyve_args->access = access;*/
uhyve_args->ret = kmalloc(sizeof(struct ibv_mr));
/*uhyve_args->ret = kmalloc(sizeof(struct ibv_mr));*/
uhyve_send(UHYVE_PORT_IBV_REG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_REG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_context * context;
int cqe;
void * cq_context;
struct ibv_comp_channel * channel;
int comp_vector;
// Return value:
struct ibv_cq * ret; // TODO
} __attribute__((packed)) uhyve_ibv_create_cq_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_context * context;*/
/*int cqe;*/
/*void * cq_context;*/
/*struct ibv_comp_channel * channel;*/
/*int comp_vector;*/
/*// Return value:*/
/*struct ibv_cq * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_create_cq_t;*/
struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector) {
uhyve_ibv_create_cq_t uhyve_args;
uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);
uhyve_args->cqe = cqe;
uhyve_args->cq_context = (void *) virt_to_phys((size_t) cq_context);
uhyve_args->channel = (struct ibv_comp_channel *) virt_to_phys((size_t) channel);
uhyve_args->comp_vector = comp_vector;
/*struct ibv_cq * ibv_create_cq(struct ibv_context * context, int cqe, void * cq_context, struct ibv_comp_channel * channel, int comp_vector) {*/
/*uhyve_ibv_create_cq_t uhyve_args;*/
/*uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);*/
/*uhyve_args->cqe = cqe;*/
/*uhyve_args->cq_context = (void *) virt_to_phys((size_t) cq_context);*/
/*uhyve_args->channel = (struct ibv_comp_channel *) virt_to_phys((size_t) channel);*/
/*uhyve_args->comp_vector = comp_vector;*/
uhyve_args->ret = kmalloc(sizeof(struct ibv_cq));
/*uhyve_args->ret = kmalloc(sizeof(struct ibv_cq));*/
uhyve_send(UHYVE_PORT_IBV_CREATE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_CREATE_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_pd * pd;
struct ibv_qp_init_attr * qp_init_attr;
// Return value:
struct ibv_qp * ret; // TODO
} __attribute__((packed)) uhyve_ibv_create_qp_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_pd * pd;*/
/*struct ibv_qp_init_attr * qp_init_attr;*/
/*// Return value:*/
/*struct ibv_qp * ret; // TODO*/
/*} __attribute__((packed)) uhyve_ibv_create_qp_t;*/
struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr) {
uhyve_ibv_create_qp_t uhyve_args;
uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);
uhyve_args->qp_init_attr = (struct ibv_qp_init_attr *) virt_to_phys((size_t) qp_init_attr);
/*struct ibv_qp * ibv_create_qp(struct ibv_pd * pd, struct ibv_qp_init_attr * qp_init_attr) {*/
/*uhyve_ibv_create_qp_t uhyve_args;*/
/*uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);*/
/*uhyve_args->qp_init_attr = (struct ibv_qp_init_attr *) virt_to_phys((size_t) qp_init_attr);*/
uhyve_args->ret = kmalloc(sizeof(struct ibv_qp));
/*uhyve_args->ret = kmalloc(sizeof(struct ibv_qp));*/
uhyve_send(UHYVE_PORT_IBV_CREATE_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_CREATE_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_qp * qp;
struct ibv_qp_attr * attr;
int attr_mask;
struct ibv_qp_init_attr * init_attr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_query_qp_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_qp * qp;*/
/*struct ibv_qp_attr * attr;*/
/*int attr_mask;*/
/*struct ibv_qp_init_attr * init_attr;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_query_qp_t;*/
int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr) {
uhyve_ibv_query_qp_t uhyve_args;
uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);
uhyve_args->attr = (struct ibv_qp_attr *) virt_to_phys((size_t) attr);
uhyve_args->attr_mask = attr_mask;
uhyve_args->init_attr = (struct ibv_qp_init_attr *) virt_to_phys((size_t) init_attr);
/*int ibv_query_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask, struct ibv_qp_init_attr * init_attr) {*/
/*uhyve_ibv_query_qp_t uhyve_args;*/
/*uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);*/
/*uhyve_args->attr = (struct ibv_qp_attr *) virt_to_phys((size_t) attr);*/
/*uhyve_args->attr_mask = attr_mask;*/
/*uhyve_args->init_attr = (struct ibv_qp_init_attr *) virt_to_phys((size_t) init_attr);*/
uhyve_send(UHYVE_PORT_IBV_QUERY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_QUERY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_qp * qp;
struct ibv_qp_attr * attr;
int attr_mask;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_modify_qp_t;
int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask) {
uhyve_ibv_modify_qp_t uhyve_args;
uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);
uhyve_args->attr = (struct ibv_qp_attr *) virt_to_phys((size_t) attr);
uhyve_args->attr_mask = attr_mask;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_qp * qp;*/
/*struct ibv_qp_attr * attr;*/
/*int attr_mask;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_modify_qp_t;*/
/*int ibv_modify_qp(struct ibv_qp * qp, struct ibv_qp_attr * attr, int attr_mask) {*/
/*uhyve_ibv_modify_qp_t uhyve_args;*/
/*uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);*/
/*uhyve_args->attr = (struct ibv_qp_attr *) virt_to_phys((size_t) attr);*/
/*uhyve_args->attr_mask = attr_mask;*/
uhyve_send(UHYVE_PORT_IBV_MODIFY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_MODIFY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_qp * qp;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_qp_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_qp * qp;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_destroy_qp_t;*/
int ibv_destroy_qp(struct ibv_qp * qp) {
uhyve_ibv_destroy_qp_t uhyve_args;
uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);
/*int ibv_destroy_qp(struct ibv_qp * qp) {*/
/*uhyve_ibv_destroy_qp_t uhyve_args;*/
/*uhyve_args->qp = (struct ibv_qp *) virt_to_phys((size_t) qp);*/
uhyve_send(UHYVE_PORT_IBV_DESTROY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_DESTROY_QP, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_cq * cq;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_cq_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_cq * cq;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_destroy_cq_t;*/
int ibv_destroy_cq(struct ibv_cq * cq) {
uhyve_ibv_destroy_cq_t uhyve_args;
uhyve_args->cq = (struct ibv_cq *) virt_to_phys((size_t) cq);
/*int ibv_destroy_cq(struct ibv_cq * cq) {*/
/*uhyve_ibv_destroy_cq_t uhyve_args;*/
/*uhyve_args->cq = (struct ibv_cq *) virt_to_phys((size_t) cq);*/
uhyve_send(UHYVE_PORT_IBV_DESTROY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_DESTROY_CQ, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_mr * mr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_dereg_mr_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_mr * mr;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_dereg_mr_t;*/
int ibv_dereg_mr(struct ibv_mr * mr) {
uhyve_ibv_dereg_mr_t uhyve_args;
uhyve_args->mr = (struct ibv_mr *) virt_to_phys((size_t) mr);
/*int ibv_dereg_mr(struct ibv_mr * mr) {*/
/*uhyve_ibv_dereg_mr_t uhyve_args;*/
/*uhyve_args->mr = (struct ibv_mr *) virt_to_phys((size_t) mr);*/
uhyve_send(UHYVE_PORT_IBV_DEREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_DEREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_pd * pd;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_dealloc_pd_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_pd * pd;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_dealloc_pd_t;*/
int ibv_dealloc_pd(struct ibv_pd * pd) {
uhyve_ibv_dealloc_pd_t uhyve_args;
uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);
/*int ibv_dealloc_pd(struct ibv_pd * pd) {*/
/*uhyve_ibv_dealloc_pd_t uhyve_args;*/
/*uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);*/
uhyve_send(UHYVE_PORT_IBV_DEALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_DEALLOC_PD, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_comp_channel * channel;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_comp_channel * channel;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t;*/
int ibv_destroy_comp_channel(struct ibv_comp_channel * channel) {
uhyve_ibv_destroy_comp_channel_t uhyve_args;
uhyve_args->channel = (struct ibv_comp_channel *) virt_to_phys((size_t) channel);
/*int ibv_destroy_comp_channel(struct ibv_comp_channel * channel) {*/
/*uhyve_ibv_destroy_comp_channel_t uhyve_args;*/
/*uhyve_args->channel = (struct ibv_comp_channel *) virt_to_phys((size_t) channel);*/
uhyve_send(UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_close_device_t;
/*typedef struct {*/
/*// Parameters:*/
/*struct ibv_context * context;*/
/*// Return value:*/
/*int ret;*/
/*} __attribute__((packed)) uhyve_ibv_close_device_t;*/
int ibv_close_device(struct ibv_context * context) {
uhyve_ibv_close_device_t uhyve_args;
uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);
/*int ibv_close_device(struct ibv_context * context) {*/
/*uhyve_ibv_close_device_t uhyve_args;*/
/*uhyve_args->context = (struct ibv_context *) virt_to_phys((size_t) context);*/
uhyve_send(UHYVE_PORT_IBV_CLOSE_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args));
/*uhyve_send(UHYVE_PORT_IBV_CLOSE_DEVICE, (unsigned) virt_to_phys((size_t) &uhyve_args));*/
// TODO: Fix pointers in returned data structures.
return uhyve_args.ret;
}
/*// TODO: Fix pointers in returned data structures.*/
/*return uhyve_args.ret;*/
/*}*/

View file

@ -0,0 +1,150 @@
void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data);
struct ibv_context * host_ret = (guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_get_device_list(struct kvm_run * run, uint8_t * 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);
struct ibv_device ** host_ret = (guest_mem+(size_t)args->num_devices);
// TODO: Take care of struct ibv_device ** return value.
}
void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data);
const char * host_ret = (guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->context, port_num, guest_mem+(size_t)args->port_attr);
args->ret = host_ret;
}
void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) (guest_mem + data);
struct ibv_comp_channel * host_ret = (guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_alloc_pd(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_alloc_pd_t * args = (uhyve_ibv_alloc_pd_t *) (guest_mem + data);
struct ibv_pd * host_ret = (guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_reg_mr(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_reg_mr_t * args = (uhyve_ibv_reg_mr_t *) (guest_mem + data);
struct ibv_mr * host_ret = (guest_mem+(size_t)args->pd, guest_mem+(size_t)args->addr, length, access);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_create_cq(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_cq_t * args = (uhyve_ibv_create_cq_t *) (guest_mem + data);
struct ibv_cq * host_ret = (guest_mem+(size_t)args->context, cqe, guest_mem+(size_t)args->cq_context, guest_mem+(size_t)args->channel, comp_vector);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_create_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_qp_t * args = (uhyve_ibv_create_qp_t *) (guest_mem + data);
struct ibv_qp * host_ret = (guest_mem+(size_t)args->pd, guest_mem+(size_t)args->qp_init_attr);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_query_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_qp_t * args = (uhyve_ibv_query_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask, guest_mem+(size_t)args->init_attr);
args->ret = host_ret;
}
void call_ibv_modify_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_modify_qp_t * args = (uhyve_ibv_modify_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask);
args->ret = host_ret;
}
void call_ibv_destroy_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_qp_t * args = (uhyve_ibv_destroy_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp);
args->ret = host_ret;
}
void call_ibv_destroy_cq(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_cq_t * args = (uhyve_ibv_destroy_cq_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->cq);
args->ret = host_ret;
}
void call_ibv_dereg_mr(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dereg_mr_t * args = (uhyve_ibv_dereg_mr_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->mr);
args->ret = host_ret;
}
void call_ibv_dealloc_pd(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dealloc_pd_t * args = (uhyve_ibv_dealloc_pd_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->pd);
args->ret = host_ret;
}
void call_ibv_destroy_comp_channel(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_comp_channel_t * args = (uhyve_ibv_destroy_comp_channel_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->channel);
args->ret = host_ret;
}
void call_ibv_close_device(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_close_device_t * args = (uhyve_ibv_close_device_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->context);
args->ret = host_ret;
}

View file

@ -1,153 +1,52 @@
case UHYVE_PORT_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);
struct ibv_context * host_ret = ibv_open_device(guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_OPEN_DEVICE:
call_ibv_open_device(run, guest_mem);
break;
}
case UHYVE_PORT_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);
struct ibv_device ** host_ret = ibv_get_device_list(guest_mem+(size_t)args->num_devices);
// TODO: Take care of struct ibv_device ** return value.
case UHYVE_PORT_IBV_GET_DEVICE_LIST:
call_ibv_get_device_list(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_GET_DEVICE_NAME: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data);
const char * host_ret = ibv_get_device_name(guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_GET_DEVICE_NAME:
call_ibv_get_device_name(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_QUERY_PORT: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (guest_mem + data);
int host_ret = ibv_query_port(guest_mem+(size_t)args->context, port_num, guest_mem+(size_t)args->port_attr);
args->ret = host_ret;
case UHYVE_PORT_IBV_QUERY_PORT:
call_ibv_query_port(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) (guest_mem + data);
struct ibv_comp_channel * host_ret = ibv_create_comp_channel(guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL:
call_ibv_create_comp_channel(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_ALLOC_PD: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_alloc_pd_t * args = (uhyve_ibv_alloc_pd_t *) (guest_mem + data);
struct ibv_pd * host_ret = ibv_alloc_pd(guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_ALLOC_PD:
call_ibv_alloc_pd(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_REG_MR: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_reg_mr_t * args = (uhyve_ibv_reg_mr_t *) (guest_mem + data);
struct ibv_mr * host_ret = ibv_reg_mr(guest_mem+(size_t)args->pd, guest_mem+(size_t)args->addr, length, access);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_REG_MR:
call_ibv_reg_mr(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_CREATE_CQ: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_cq_t * args = (uhyve_ibv_create_cq_t *) (guest_mem + data);
struct ibv_cq * host_ret = ibv_create_cq(guest_mem+(size_t)args->context, cqe, guest_mem+(size_t)args->cq_context, guest_mem+(size_t)args->channel, comp_vector);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_CREATE_CQ:
call_ibv_create_cq(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_CREATE_QP: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_qp_t * args = (uhyve_ibv_create_qp_t *) (guest_mem + data);
struct ibv_qp * host_ret = ibv_create_qp(guest_mem+(size_t)args->pd, guest_mem+(size_t)args->qp_init_attr);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
case UHYVE_PORT_IBV_CREATE_QP:
call_ibv_create_qp(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_QUERY_QP: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_qp_t * args = (uhyve_ibv_query_qp_t *) (guest_mem + data);
int host_ret = ibv_query_qp(guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask, guest_mem+(size_t)args->init_attr);
args->ret = host_ret;
case UHYVE_PORT_IBV_QUERY_QP:
call_ibv_query_qp(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_MODIFY_QP: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_modify_qp_t * args = (uhyve_ibv_modify_qp_t *) (guest_mem + data);
int host_ret = ibv_modify_qp(guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask);
args->ret = host_ret;
case UHYVE_PORT_IBV_MODIFY_QP:
call_ibv_modify_qp(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_DESTROY_QP: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_qp_t * args = (uhyve_ibv_destroy_qp_t *) (guest_mem + data);
int host_ret = ibv_destroy_qp(guest_mem+(size_t)args->qp);
args->ret = host_ret;
case UHYVE_PORT_IBV_DESTROY_QP:
call_ibv_destroy_qp(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_DESTROY_CQ: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_cq_t * args = (uhyve_ibv_destroy_cq_t *) (guest_mem + data);
int host_ret = ibv_destroy_cq(guest_mem+(size_t)args->cq);
args->ret = host_ret;
case UHYVE_PORT_IBV_DESTROY_CQ:
call_ibv_destroy_cq(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_DEREG_MR: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dereg_mr_t * args = (uhyve_ibv_dereg_mr_t *) (guest_mem + data);
int host_ret = ibv_dereg_mr(guest_mem+(size_t)args->mr);
args->ret = host_ret;
case UHYVE_PORT_IBV_DEREG_MR:
call_ibv_dereg_mr(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_DEALLOC_PD: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dealloc_pd_t * args = (uhyve_ibv_dealloc_pd_t *) (guest_mem + data);
int host_ret = ibv_dealloc_pd(guest_mem+(size_t)args->pd);
args->ret = host_ret;
case UHYVE_PORT_IBV_DEALLOC_PD:
call_ibv_dealloc_pd(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_comp_channel_t * args = (uhyve_ibv_destroy_comp_channel_t *) (guest_mem + data);
int host_ret = ibv_destroy_comp_channel(guest_mem+(size_t)args->channel);
args->ret = host_ret;
case UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL:
call_ibv_destroy_comp_channel(run, guest_mem);
break;
}
case UHYVE_PORT_IBV_CLOSE_DEVICE: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_close_device_t * args = (uhyve_ibv_close_device_t *) (guest_mem + data);
int host_ret = ibv_close_device(guest_mem+(size_t)args->context);
args->ret = host_ret;
break;
}
case UHYVE_PORT_IBV_CLOSE_DEVICE:
call_ibv_close_device(run, guest_mem);
break;

View file

@ -97,10 +97,14 @@ UHYVE_CASES_GEN_PATH = "GEN-tools-uhyve.c"
UHYVE_IBV_HEADER_GEN_PATH = "GEN-tools-uhyve-ibv-ports.h"
INCLUDE_STDDEF_GEN_PATH = "GEN-include-hermit-stddef.h"
UHYVE_IBV_HEADER_STRUCTS_GEN_PATH = "GEN-tools-uhyve-ibv-structs.h"
UHYVE_HOST_FCNS_GEN_PATH = "GEN-tools-uhyve-ibv.c"
# Starting number of the sequence used for IBV ports.
PORT_NUMBER_START = 0x510
TABS = ["", "\t", "\t\t", "\t\t\t", "\t\t\t\t"]
NEWLINES = ["", "\n", "\n\n"]
def get_struct_name(function_name):
"""Returns the matching struct name for a given function name.
@ -208,7 +212,32 @@ def generate_kernel_function(ret, function_name, params):
return function
def generate_uhyve_case(ret, function_name, params):
def generate_uhyve_cases(function_name):
""" TODO
Generates a switch-case that catches a KVM exit IO for the given function in uhyve.
Args:
ret: Return type as string.
function_name: Function name as string.
params: Parameters as list of strings.
Returns:
Generated switch-case code as string.
"""
cases = ""
for function_name in function_names:
port_name = "UHYVE_PORT_" + function_name.upper()
struct_name = get_struct_name(function_name)
cases += "{0}{1}case {2}:".format(NEWLINES[1], TABS[3], port_name)
cases += "{0}{1}call_{2}(run, guest_mem);".format(NEWLINES[1], TABS[4], function_name)
cases += "{0}{1}break;".format(NEWLINES[1], TABS[4])
return cases
def generate_uhyve_host_function(ret, function_name, params):
"""Generates a switch-case that catches a KVM exit IO for the given function in uhyve.
Args:
@ -243,31 +272,31 @@ def generate_uhyve_case(ret, function_name, params):
host_param = "{0}".format(param_name)
return host_param
port_name = "UHYVE_PORT_" + function_name.upper()
struct_name = get_struct_name(function_name)
case = "\n\t\t\tcase {0}: {{".format(port_name)
case += "\n\t\t\t\tunsigned data = *((unsigned*)((size_t)run+run->io.data_offset));"
case += "\n\t\t\t\t{0} * args = ({0} *) (guest_mem + data);".format(struct_name)
case += "\n\n\t\t\t\t{0} host_ret = {1}(".format(ret, function_name)
fcn = "{0}void call_{1}(struct kvm_run * run, uint8_t * guest_mem) {{".format(NEWLINES[1], function_name)
fcn += "{0}{1}unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));".format(NEWLINES[1], TABS[1])
fcn += "{0}{1}{2} * args = ({2} *) (guest_mem + data);".format(NEWLINES[1], TABS[1], struct_name)
fcn += "{0}{1}{2} host_ret = {1}(".format(NEWLINES[2], TABS[1], ret, function_name)
for param in params[:-1]:
case += generate_host_call_parameter(param) + ", "
fcn += generate_host_call_parameter(param) + ", "
else:
case += generate_host_call_parameter(params[-1]) + ");"
fcn += generate_host_call_parameter(params[-1]) + ");"
if "**" in ret:
case += "\n\t\t\t\t// TODO: Take care of {0} return value.".format(ret)
fcn += "{0}{1}// TODO: Take care of {2} return value.".format(NEWLINES[1], TABS[1], ret)
elif "*" in ret:
case += "\n\t\t\t\tmemcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));"
fcn += "{0}{1}memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));".format(NEWLINES[1], TABS[1])
fcn += "{0}{1}// TODO: Convert ptrs contained in return value.".format(NEWLINES[1], TABS[1])
fcn += "{0}{1}// TODO: Delete host_ret data structure.".format(NEWLINES[1], TABS[1])
else:
case += "\n\t\t\t\targs->ret = host_ret;"
fcn += "{0}{1}args->ret = host_ret;".format(NEWLINES[1], TABS[1])
case += "\n\t\t\t\tbreak;"
case += "\n\t\t\t}\n"
fcn += "{0}}}{0}".format(NEWLINES[1])
return case
return fcn
def generate_port_enum(function_names):
@ -307,7 +336,7 @@ def generate_port_macros(function_names):
if __name__ == "__main__":
with open(SRC_PATH, "r") as f_src, \
open(IBV_GEN_PATH, "w") as f_ibv, \
open(UHYVE_CASES_GEN_PATH, "w") as f_uhyve, \
open(UHYVE_HOST_FCNS_GEN_PATH, "w") as f_uhyve_host_fncs, \
open(UHYVE_IBV_HEADER_STRUCTS_GEN_PATH, "w") as f_structs:
function_names = []
for line in f_src:
@ -321,13 +350,17 @@ if __name__ == "__main__":
kernel_function = generate_kernel_function(ret, function_name, params)
f_ibv.write(kernel_function)
uhyve_case = generate_uhyve_case(ret, function_name, params)
f_uhyve.write(uhyve_case)
uhyve_fnc = generate_uhyve_host_function(ret, function_name, params)
f_uhyve_host_fncs.write(uhyve_fnc)
with open(UHYVE_IBV_HEADER_GEN_PATH, "w") as f_uhyve_ibv:
port_enum = generate_port_enum(function_names)
f_uhyve_ibv.write(port_enum)
with open(UHYVE_CASES_GEN_PATH, "w") as f_cases:
uhyve_cases = generate_uhyve_cases(function_names)
f_cases.write(uhyve_cases)
with open(INCLUDE_STDDEF_GEN_PATH, "w") as f_stddef:
port_macros = generate_port_macros(function_names)
f_stddef.write(port_macros)

View file

@ -1,330 +0,0 @@
#!/usr/bin/env python
"""Copyright (c) 2017, Annika Wierichs, RWTH Aachen University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This script expects a text file containing function prototypes as input
(SRC_PATH). It generates the following C code snippets for each individual given
function in the input file. Todo notes are inserted whereever more work is
required.
1. The definition of a struct that contains all parameters and the return value
of a given function.
Required in: ./kernel/ibv.c
Example:
typedef struct {
// Parameters:
struct ibv_mr * mr;
int flags;
struct ibv_pd * pd;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_rereg_mr_t;
2. The definition of the kernel space function that sends a KVM exit IO to
uhyve.
Required in: ./kernel/ibv.c
Example:
int ibv_rereg_mr(struct ibv_mr * mr, int flags, struct ibv_pd * pd) {
uhyve_ibv_rereg_mr_t uhyve_args;
uhyve_args->mr = (struct ibv_mr *) virt_to_phys((size_t) mr);
uhyve_args->flags = flags;
uhyve_args->pd = (struct ibv_pd *) virt_to_phys((size_t) pd);
uhyve_send(UHYVE_PORT_IBV_REREG_MR, (unsigned) virt_to_phys((size_t) &uhyve_args));
return uhyve_args.ret;
}
3. The switch-case that catches the KVM exit IO sent to uhyve by the kernel.
Required in: ./tool/uhyve.c
Example:
case UHYVE_PORT_IBV_REREG_MR: {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_rereg_mr_t * args = (uhyve_ibv_rereg_mr_t *) (guest_mem + data);
int host_ret = ibv_rereg_mr(guest_mem+(size_t)args->mr, flags, guest_mem+(size_t)args->pd);
args->ret = host_ret;
break;
}
The script also generates an enum mapping all functions to KVM exit IO port
names and numbers.
Required in: ./tool/uhyve-ibv.h
Example:
typedef enum {
UHYVE_PORT_IBV_WC_STATUS_STR = 0x510,
UHYVE_PORT_IBV_RATE_TO_MULT = 0x511,
UHYVE_PORT_MULT_TO_IBV_RATE = 0x512,
// ...
} uhyve_ibv_t;
"""
# Path of the input file containing function prototypes.
SRC_PATH = "function-prototypes-0.txt"
# Paths of the files that are generated by the script.
IBV_GEN_PATH = "GEN-kernel-ibv.c"
UHYVE_CASES_GEN_PATH = "GEN-tools-uhyve.c"
UHYVE_IBV_HEADER_GEN_PATH = "GEN-tools-uhyve-ibv.h"
INCLUDE_STDDEF_GEN_PATH = "GEN-include-hermit-stddef.h"
# Starting number of the sequence used for IBV ports.
PORT_NUMBER_START = 0x510
def get_struct_name(function_name):
"""Returns the matching struct name for a given function name.
"""
return "uhyve_{0}_t".format(function_name)
def parse_line(line):
"""Parses a line containing a function prototype.
Args:
line: Line of the following format:
<return_type> <function_name>(<param_type> <param_name>, [...])
Returns:
Return type, function name, parameters as Tuple[string, string, list[string]]
"""
parens_split = line.split("(")
ret_and_name = parens_split[0].split(" ")
all_params = parens_split[-1][:-1]
ret = " ".join(ret_and_name[:-1])
function_name = ret_and_name[-1]
params = all_params.split(",")
params[-1] = params[-1][:-1]
return ret, function_name, params
def generate_struct(ret, function_name, params):
"""Generates the struct to hold a function's parameters and return value.
Args:
ret: Return type as string.
function_name: Function name as string.
params: Parameters as list of strings.
Returns:
Generated struct as string.
"""
struct = "typedef struct {\n"
if params:
struct += "\t// Parameters:\n"
for param in params:
struct += "\t{0};\n".format(param)
if ret is not "void":
struct += "\t// Return value:\n"
struct += "\t{0} ret;\n".format(ret)
struct_name = get_struct_name(function_name)
struct += "}} __attribute__((packed)) {0};\n\n".format(struct_name)
return struct
def generate_kernel_function(ret, function_name, params):
"""Generates the kernel function that sends the KVM exit IO to uhyve.
Args:
ret: Return type as string.
function_name: Function name as string.
params: Parameters as list of strings.
Returns:
Generated function as string.
"""
function = "{0} {1}({2}) {{\n".format(ret, function_name, ", ".join(params))
# Create uhyve_args and define parameters
struct_name = get_struct_name(function_name)
function += "\t{0} uhyve_args;\n".format(struct_name)
for param in params:
param_split = param.split(" ")
param_type = " ".join(param_split[:-1])
param_name = param_split[-1]
# Define struct members according to their type.
if "**" in param_type:
function += "\t// TODO: Take care of ** parameter.\n"
elif "*" in param_type:
function += "\tuhyve_args->{0} = " "({1}) virt_to_phys((size_t) {2});\n".format(
param_name, param_type, param_name)
else:
function += "\tuhyve_args->{0} = {0};\n".format(param_name)
# Allocate memory for return value if it is a pointer.
if "**" in ret:
function += "\n\t// TODO: Take care of return value.\n"
elif "*" in ret:
function += "\n\tuhyve_args->ret = kmalloc(sizeof({0}));\n".format(ret[:-2])
# call uhyve_send() using the respective port ID.
port_name = "UHYVE_PORT_" + function_name.upper()
function += "\n\tuhyve_send({0}, (unsigned) virt_to_phys((size_t) " \
"&uhyve_args));\n\n".format(port_name)
function += "\t// TODO: Fix pointers in returned data structures.\n"
function += "\treturn uhyve_args.ret;\n"
function += "}\n\n\n"
return function
def generate_uhyve_case(ret, function_name, params):
"""Generates a switch-case that catches a KVM exit IO for the given function in uhyve.
Args:
ret: Return type as string.
function_name: Function name as string.
params: Parameters as list of strings.
Returns:
Generated switch-case code as string.
"""
def generate_host_call_parameter(param):
"""Generates the parameter for the host's function called from within uhyve.
This distinguishes between pointers and non-pointers since pointers have to
be converted to host memory addresses.
Example for pointer: guest_mem+(size_t)args->param
Example for non-pointer: args->param
Args:
param: The parameter type and name as a single string.
Returns:
Generated parameter,
"""
param_name = param.split(" ")[-1]
if "**" in param:
host_param = "/* TODO: param {0}*/".format(param_name)
elif "*" in param:
host_param = "guest_mem+(size_t)args->{0}".format(param_name)
else:
host_param = "{0}".format(param_name)
return host_param
port_name = "UHYVE_PORT_" + function_name.upper()
struct_name = get_struct_name(function_name)
case = "\n\t\t\tcase {0}: {{".format(port_name)
case += "\n\t\t\t\tunsigned data = *((unsigned*)((size_t)run+run->io.data_offset));"
case += "\n\t\t\t\t{0} * args = ({0} *) (guest_mem + data);".format(struct_name)
case += "\n\n\t\t\t\t{0} host_ret = {1}(".format(ret, function_name)
for param in params[:-1]:
case += generate_host_call_parameter(param) + ", "
else:
case += generate_host_call_parameter(params[-1]) + ");"
if "**" in ret:
case += "\n\t\t\t\t// TODO: Take care of {0} return value.".format(ret)
elif "*" in ret:
case += "\n\t\t\t\tmemcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));"
else:
case += "\n\t\t\t\targs->ret = host_ret;"
case += "\n\t\t\t\tbreak;"
case += "\n\t\t\t}\n"
return case
def generate_port_enum(function_names):
"""Generates the enum mapping KVM exit IO port names to port numbers.
Args:
function_names: All function names to be mapped to ports as list of strings.
Returns:
Generated complete enum.
"""
port_enum = "typedef enum {"
for num, function_name in enumerate(function_names, PORT_NUMBER_START):
port_enum += "\n\tUHYVE_PORT_{0} = 0x{1},".format(function_name.upper(),
format(num, "X"))
port_enum += "\n} uhyve_ibv_t;"
return port_enum
def generate_port_macros(function_names):
"""Generates the compiler macros mapping KVM exit IO port names to port numbers.
Args:
function_names: All function names to be mapped to ports as list of strings.
Returns:
Generated list of compiler macros.
"""
macros = ""
for num, function_name in enumerate(function_names, PORT_NUMBER_START):
macros += "\n#define UHYVE_PORT_{0} 0x{1},".format(function_name.upper(),
format(num, "X"))
return macros
if __name__ == "__main__":
with open(SRC_PATH, "r") as f_src, \
open(IBV_GEN_PATH, "w") as f_ibv, \
open(UHYVE_CASES_GEN_PATH, "w") as f_uhyve:
function_names = []
for line in f_src:
ret, function_name, params = parse_line(line)
function_names.append(function_name)
struct = generate_struct(ret, function_name, params)
f_ibv.write(struct)
kernel_function = generate_kernel_function(ret, function_name, params)
f_ibv.write(kernel_function)
uhyve_case = generate_uhyve_case(ret, function_name, params)
f_uhyve.write(uhyve_case)
with open(UHYVE_IBV_HEADER_GEN_PATH, "w") as f_uhyve_ibv:
port_enum = generate_port_enum(function_names)
f_uhyve_ibv.write(port_enum)
with open(INCLUDE_STDDEF_GEN_PATH, "w") as f_stddef:
port_macros = generate_port_macros(function_names)
f_stddef.write(port_macros)

194
tools/uhyve-ibv.c Normal file
View file

@ -0,0 +1,194 @@
/*
* Copyright (c) 2017, Annika Wierichs, RWTH Aachen University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* TODO: Documentation
*
*/
#include "uhyve-ibv.h"
#include <infiniband/verbs.h> // Linux include
void call_ibv_open_device(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_open_device_t * args = (uhyve_ibv_open_device_t *) (guest_mem + data);
struct ibv_context * host_ret = (guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_open_device(struct kvm_run * run, uint8_t * 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 **temp_dev_list = ibv_get_device_list(&num_devices);
// 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++) {
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));
}
}
void call_ibv_get_device_name(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_get_device_name_t * args = (uhyve_ibv_get_device_name_t *) (guest_mem + data);
const char * host_ret = (guest_mem+(size_t)args->device);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_query_port(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->context, port_num, guest_mem+(size_t)args->port_attr);
args->ret = host_ret;
}
void call_ibv_create_comp_channel(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) (guest_mem + data);
struct ibv_comp_channel * host_ret = (guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_alloc_pd(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_alloc_pd_t * args = (uhyve_ibv_alloc_pd_t *) (guest_mem + data);
struct ibv_pd * host_ret = (guest_mem+(size_t)args->context);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_reg_mr(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_reg_mr_t * args = (uhyve_ibv_reg_mr_t *) (guest_mem + data);
struct ibv_mr * host_ret = (guest_mem+(size_t)args->pd, guest_mem+(size_t)args->addr, length, access);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_create_cq(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_cq_t * args = (uhyve_ibv_create_cq_t *) (guest_mem + data);
struct ibv_cq * host_ret = (guest_mem+(size_t)args->context, cqe, guest_mem+(size_t)args->cq_context, guest_mem+(size_t)args->channel, comp_vector);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_create_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_create_qp_t * args = (uhyve_ibv_create_qp_t *) (guest_mem + data);
struct ibv_qp * host_ret = (guest_mem+(size_t)args->pd, guest_mem+(size_t)args->qp_init_attr);
memcpy(guest_mem+(size_t)args->ret, host_ret, sizeof(host_ret));
// TODO: Convert ptrs contained in return value.
// TODO: Delete host_ret data structure.
}
void call_ibv_query_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_query_qp_t * args = (uhyve_ibv_query_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask, guest_mem+(size_t)args->init_attr);
args->ret = host_ret;
}
void call_ibv_modify_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_modify_qp_t * args = (uhyve_ibv_modify_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp, guest_mem+(size_t)args->attr, attr_mask);
args->ret = host_ret;
}
void call_ibv_destroy_qp(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_qp_t * args = (uhyve_ibv_destroy_qp_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->qp);
args->ret = host_ret;
}
void call_ibv_destroy_cq(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_cq_t * args = (uhyve_ibv_destroy_cq_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->cq);
args->ret = host_ret;
}
void call_ibv_dereg_mr(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dereg_mr_t * args = (uhyve_ibv_dereg_mr_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->mr);
args->ret = host_ret;
}
void call_ibv_dealloc_pd(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_dealloc_pd_t * args = (uhyve_ibv_dealloc_pd_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->pd);
args->ret = host_ret;
}
void call_ibv_destroy_comp_channel(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_destroy_comp_channel_t * args = (uhyve_ibv_destroy_comp_channel_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->channel);
args->ret = host_ret;
}
void call_ibv_close_device(struct kvm_run * run, uint8_t * guest_mem) {
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
uhyve_ibv_close_device_t * args = (uhyve_ibv_close_device_t *) (guest_mem + data);
int host_ret = (guest_mem+(size_t)args->context);
args->ret = host_ret;
}

View file

@ -66,118 +66,118 @@ typedef struct {
const char * ret;
} __attribute__((packed)) uhyve_ibv_get_device_name_t;
typedef struct {
// Parameters:
struct ibv_context * context;
uint8_t port_num;
struct ibv_port_attr * port_attr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_query_port_t;
//typedef struct {
//// Parameters:
//struct ibv_context * context;
//uint8_t port_num;
//struct ibv_port_attr * port_attr;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_query_port_t;
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
struct ibv_comp_channel * ret;
} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;
//typedef struct {
//// Parameters:
//struct ibv_context * context;
//// Return value:
//struct ibv_comp_channel * ret;
//} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
struct ibv_pd * ret;
} __attribute__((packed)) uhyve_ibv_alloc_pd_t;
//typedef struct {
//// Parameters:
//struct ibv_context * context;
//// Return value:
//struct ibv_pd * ret;
//} __attribute__((packed)) uhyve_ibv_alloc_pd_t;
typedef struct {
// Parameters:
struct ibv_pd * pd;
void * addr;
int length;
int access;
// Return value:
struct ibv_mr * ret;
} __attribute__((packed)) uhyve_ibv_reg_mr_t;
//typedef struct {
//// Parameters:
//struct ibv_pd * pd;
//void * addr;
//int length;
//int access;
//// Return value:
//struct ibv_mr * ret;
//} __attribute__((packed)) uhyve_ibv_reg_mr_t;
typedef struct {
// Parameters:
struct ibv_context * context;
int cqe;
void * cq_context;
struct ibv_comp_channel * channel;
int comp_vector;
// Return value:
struct ibv_cq * ret;
} __attribute__((packed)) uhyve_ibv_create_cq_t;
//typedef struct {
//// Parameters:
//struct ibv_context * context;
//int cqe;
//void * cq_context;
//struct ibv_comp_channel * channel;
//int comp_vector;
//// Return value:
//struct ibv_cq * ret;
//} __attribute__((packed)) uhyve_ibv_create_cq_t;
typedef struct {
// Parameters:
struct ibv_pd * pd;
struct ibv_qp_init_attr * qp_init_attr;
// Return value:
struct ibv_qp * ret;
} __attribute__((packed)) uhyve_ibv_create_qp_t;
//typedef struct {
//// Parameters:
//struct ibv_pd * pd;
//struct ibv_qp_init_attr * qp_init_attr;
//// Return value:
//struct ibv_qp * ret;
//} __attribute__((packed)) uhyve_ibv_create_qp_t;
typedef struct {
// Parameters:
struct ibv_qp * qp;
struct ibv_qp_attr * attr;
int attr_mask;
struct ibv_qp_init_attr * init_attr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_query_qp_t;
//typedef struct {
//// Parameters:
//struct ibv_qp * qp;
//struct ibv_qp_attr * attr;
//int attr_mask;
//struct ibv_qp_init_attr * init_attr;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_query_qp_t;
typedef struct {
// Parameters:
struct ibv_qp * qp;
struct ibv_qp_attr * attr;
int attr_mask;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_modify_qp_t;
//typedef struct {
//// Parameters:
//struct ibv_qp * qp;
//struct ibv_qp_attr * attr;
//int attr_mask;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_modify_qp_t;
typedef struct {
// Parameters:
struct ibv_qp * qp;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_qp_t;
//typedef struct {
//// Parameters:
//struct ibv_qp * qp;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_destroy_qp_t;
typedef struct {
// Parameters:
struct ibv_cq * cq;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_cq_t;
//typedef struct {
//// Parameters:
//struct ibv_cq * cq;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_destroy_cq_t;
typedef struct {
// Parameters:
struct ibv_mr * mr;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_dereg_mr_t;
//typedef struct {
//// Parameters:
//struct ibv_mr * mr;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_dereg_mr_t;
typedef struct {
// Parameters:
struct ibv_pd * pd;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_dealloc_pd_t;
//typedef struct {
//// Parameters:
//struct ibv_pd * pd;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_dealloc_pd_t;
typedef struct {
// Parameters:
struct ibv_comp_channel * channel;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t;
//typedef struct {
//// Parameters:
//struct ibv_comp_channel * channel;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_destroy_comp_channel_t;
typedef struct {
// Parameters:
struct ibv_context * context;
// Return value:
int ret;
} __attribute__((packed)) uhyve_ibv_close_device_t;
//typedef struct {
//// Parameters:
//struct ibv_context * context;
//// Return value:
//int ret;
//} __attribute__((packed)) uhyve_ibv_close_device_t;
#endif // UHYVE_IBV_H
//#endif // UHYVE_IBV_H

View file

@ -967,84 +967,57 @@ static int vcpu_loop(void)
}
// InfiniBand
case UHYVE_PORT_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);
// Call IBV function from hypervisor
int num_devices;
struct ibv_device **temp_dev_list = ibv_get_device_list(&num_devices);
// 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++) {
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));
}
break;
}
case UHYVE_PORT_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);
struct ibv_context* context = ibv_open_device(guest_mem+(size_t)args->device);
// Copy return value to memory location allocated in kernel space.
memcpy(guest_mem+(size_t)args->ret, context, sizeof(context));
break;
}
case UHYVE_PORT_IBV_MODIFY_QP: {
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);
// 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
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));
}
break;
}
case UHYVE_PORT_IBV_CREATE_AH: {
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);
// 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
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));
}
break;
}
/*case UHYVE_PORT_IBV_GET_DEVICE_NAME: {*/
/*unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));*/
/*uhyve_ibv_get_device_name_t* args = (uhyve_ibv_get_device_name_t*) (guest_mem+data);*/
/*args->ret = ibv_get_device_name((struct ibv_device*)(guest_mem+(size_t)args->device));*/
/*printf("UHYVE_PORT_IBV_GET_DEVICE_NAME\n");*/
/*break;*/
/*}*/
case UHYVE_PORT_IBV_OPEN_DEVICE:
call_ibv_open_device(run, guest_mem);
break;
case UHYVE_PORT_IBV_GET_DEVICE_LIST:
call_ibv_get_device_list(run, guest_mem);
break;
case UHYVE_PORT_IBV_GET_DEVICE_NAME:
call_ibv_get_device_name(run, guest_mem);
break;
case UHYVE_PORT_IBV_QUERY_PORT:
call_ibv_query_port(run, guest_mem);
break;
case UHYVE_PORT_IBV_CREATE_COMP_CHANNEL:
call_ibv_create_comp_channel(run, guest_mem);
break;
case UHYVE_PORT_IBV_ALLOC_PD:
call_ibv_alloc_pd(run, guest_mem);
break;
case UHYVE_PORT_IBV_REG_MR:
call_ibv_reg_mr(run, guest_mem);
break;
case UHYVE_PORT_IBV_CREATE_CQ:
call_ibv_create_cq(run, guest_mem);
break;
case UHYVE_PORT_IBV_CREATE_QP:
call_ibv_create_qp(run, guest_mem);
break;
case UHYVE_PORT_IBV_QUERY_QP:
call_ibv_query_qp(run, guest_mem);
break;
case UHYVE_PORT_IBV_MODIFY_QP:
call_ibv_modify_qp(run, guest_mem);
break;
case UHYVE_PORT_IBV_DESTROY_QP:
call_ibv_destroy_qp(run, guest_mem);
break;
case UHYVE_PORT_IBV_DESTROY_CQ:
call_ibv_destroy_cq(run, guest_mem);
break;
case UHYVE_PORT_IBV_DEREG_MR:
call_ibv_dereg_mr(run, guest_mem);
break;
case UHYVE_PORT_IBV_DEALLOC_PD:
call_ibv_dealloc_pd(run, guest_mem);
break;
case UHYVE_PORT_IBV_DESTROY_COMP_CHANNEL:
call_ibv_destroy_comp_channel(run, guest_mem);
break;
case UHYVE_PORT_IBV_CLOSE_DEVICE:
call_ibv_close_device(run, guest_mem);
break;
default:
err(1, "KVM: unhandled KVM_EXIT_IO at port 0x%x, direction %d\n", run->io.port, run->io.direction);