mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
first test compiling. Segfault due to mutex conversion missing.ecit
This commit is contained in:
parent
0e1ba141e6
commit
9b108aecae
6 changed files with 51 additions and 10 deletions
|
@ -42,12 +42,11 @@ extern "C" {
|
|||
|
||||
// TODO: File necessary?
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
struct ibv_device ** ibv_get_device_list(int * num_devices);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -47,11 +47,13 @@ struct ibv_context_ops * guest_to_host_ibv_context_ops(struct ibv_context_ops
|
|||
struct ibv_port_attr * guest_to_host_ibv_port_attr(struct ibv_port_attr * port_attr);
|
||||
struct ibv_comp_channel * guest_to_host_ibv_comp_channel(struct ibv_comp_channel * channel);
|
||||
struct ibv_abi_compat_v2 * guest_to_host_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat);
|
||||
pthread_mutex_t * guest_to_host_pthread_mutex_t(pthread_mutex_t * mutex);
|
||||
|
||||
void host_to_guest_ibv_device(struct ibv_device * device);
|
||||
void host_to_guest_ibv_context(struct ibv_context * context);
|
||||
void host_to_guest_ibv_context_ops(struct ibv_context_ops * context_ops);
|
||||
void host_to_guest_ibv_port_attr(struct ibv_port_attr * port_attr);
|
||||
void host_to_guest_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat);
|
||||
void host_to_guest_pthread_mutex_t(pthread_mutex_t * mutex);
|
||||
|
||||
#endif // __IBV_GUEST_HOST_H__
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
// TODO: Can/should we separate ibv_get_device_list into two KVM exit IOs to
|
||||
// allocate the right amount of memory?
|
||||
#define MAX_NUM_OF_IBV_DEVICES 16
|
||||
#define MAX_NUM_OF_IBV_DEVICES 16
|
||||
|
||||
|
||||
static void * ret_guest_ptr;
|
||||
|
@ -59,6 +59,7 @@ typedef struct {
|
|||
} __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);
|
||||
|
||||
|
@ -115,6 +116,7 @@ typedef struct {
|
|||
} __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) {
|
||||
/* printf("LOG: ibv_query_port"); */
|
||||
uhyve_ibv_query_port_t uhyve_args;
|
||||
uhyve_args.context = guest_to_host_ibv_context(context);
|
||||
uhyve_args.port_num = port_num;
|
||||
|
@ -141,6 +143,7 @@ typedef struct {
|
|||
} __attribute__((packed)) uhyve_ibv_create_comp_channel_t;
|
||||
|
||||
struct ibv_comp_channel * ibv_create_comp_channel(struct ibv_context * context) {
|
||||
/* printf("LOG: ibv_create_comp_channel"); */
|
||||
uhyve_ibv_create_comp_channel_t uhyve_args;
|
||||
uhyve_args.context = guest_to_host_ibv_context(context);
|
||||
|
||||
|
@ -168,6 +171,7 @@ typedef struct {
|
|||
} __attribute__((packed)) uhyve_ibv_get_device_list_t;
|
||||
|
||||
struct ibv_device ** ibv_get_device_list(int * num_devices) {
|
||||
/* printf("LOG: ibv_get_device_list"); */
|
||||
// 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);
|
||||
|
|
|
@ -62,7 +62,7 @@ struct ibv_context * guest_to_host_ibv_context(struct ibv_context * context) {
|
|||
context->device = guest_to_host_ibv_device(context->device);
|
||||
context->abi_compat = guest_to_host_ibv_abi_compat_v2(context->abi_compat);
|
||||
guest_to_host_ibv_context_ops(&context->ops);
|
||||
/*guest_to_host_pthread_mutex_t(&context->mutex); // TODO*/
|
||||
guest_to_host_pthread_mutex_t(&context->mutex); // TODO
|
||||
|
||||
return (struct ibv_context *) guest_to_host((size_t) context);
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ static struct {
|
|||
} 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,
|
||||
ibv_comp_channel_virt_ptrs.context = channel->context;
|
||||
|
||||
channel->context = guest_to_host_ibv_context(channel->context);
|
||||
|
||||
|
@ -263,12 +263,33 @@ void host_to_guest_ibv_comp_channel(struct ibv_comp_channel * channel) {
|
|||
|
||||
struct ibv_abi_compat_v2 * guest_to_host_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat) {
|
||||
guest_to_host_ibv_comp_channel(&abi_compat->channel);
|
||||
/* guest_to_host_pthread_mutex_t(&abi_compat->in_use); */
|
||||
guest_to_host_pthread_mutex_t(&abi_compat->in_use);
|
||||
|
||||
return (struct ibv_abi_compat_v2 *) guest_to_host((size_t) abi_compat);
|
||||
}
|
||||
|
||||
void host_to_guest_ibv_abi_compat_v2(struct ibv_abi_compat_v2 * abi_compat) {
|
||||
host_to_guest_ibv_comp_channel(&abi_compat->channel);
|
||||
/* host_to_guest_pthread_mutex_t(&abi_compat->in_use); */
|
||||
host_to_guest_pthread_mutex_t(&abi_compat->in_use);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* pthread_mutex_t
|
||||
*/
|
||||
|
||||
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:
|
||||
|
||||
/* mutex->__m_owner = guest_to_host__pthread_descr(mutex->__m_owner); */
|
||||
|
||||
return (struct pthread_mutex_t *) guest_to_host((size_t) mutex);
|
||||
}
|
||||
|
||||
void host_to_guest_pthread_mutex_t(pthread_mutex_t * mutex) {
|
||||
/* host_to_guest__pthread_descr(mutex->__m_owner); */
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
*/
|
||||
|
||||
void call_ibv_open_device(struct kvm_run * run) {
|
||||
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 *) data;
|
||||
|
||||
|
@ -59,6 +60,7 @@ void call_ibv_open_device(struct kvm_run * run) {
|
|||
*/
|
||||
|
||||
void call_ibv_get_device_name(struct kvm_run * run) {
|
||||
printf("LOG: UHYVE - call_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 *) data;
|
||||
|
||||
|
@ -75,6 +77,7 @@ void call_ibv_get_device_name(struct kvm_run * run) {
|
|||
*/
|
||||
|
||||
void call_ibv_query_port(struct kvm_run * run) {
|
||||
printf("LOG: UHYVE - call_ibv_query_port");
|
||||
unsigned data = *((unsigned*)((size_t)run+run->io.data_offset));
|
||||
uhyve_ibv_query_port_t * args = (uhyve_ibv_query_port_t *) (data);
|
||||
|
||||
|
@ -88,6 +91,7 @@ void call_ibv_query_port(struct kvm_run * run) {
|
|||
*/
|
||||
|
||||
void call_ibv_create_comp_channel(struct kvm_run * run) {
|
||||
printf("LOG: UHYVE - call_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 *) data;
|
||||
/*uhyve_ibv_create_comp_channel_t * args = (uhyve_ibv_create_comp_channel_t *) get_data(run);*/
|
||||
|
@ -99,6 +103,7 @@ void call_ibv_create_comp_channel(struct kvm_run * run) {
|
|||
|
||||
|
||||
void call_ibv_get_device_list(struct kvm_run * run) {
|
||||
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 *) data;
|
||||
|
||||
|
|
|
@ -310,8 +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");
|
||||
struct pingpong_context *ctx;
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
ctx = malloc(sizeof *ctx);
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
@ -320,6 +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");
|
||||
ctx->buf = memalign(page_size, size + 40);
|
||||
if (!ctx->buf) {
|
||||
fprintf(stderr, "Couldn't allocate work buf.\n");
|
||||
|
@ -329,6 +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");
|
||||
ctx->context = ibv_open_device(ib_dev);
|
||||
if (!ctx->context) {
|
||||
fprintf(stderr, "Couldn't get context for %s\n",
|
||||
|
@ -336,6 +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");
|
||||
{
|
||||
struct ibv_port_attr port_info = {};
|
||||
int mtu;
|
||||
|
@ -351,6 +356,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
|
|||
}
|
||||
}
|
||||
|
||||
printf("LOG: PINGPONG - pp_init_ctx");
|
||||
if (use_event) {
|
||||
ctx->channel = ibv_create_comp_channel(ctx->context);
|
||||
if (!ctx->channel) {
|
||||
|
@ -566,6 +572,7 @@ static void usage(const char *argv0)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("LOG: PINGPONG - main");
|
||||
struct ibv_device **dev_list;
|
||||
struct ibv_device *ib_dev;
|
||||
struct pingpong_context *ctx;
|
||||
|
@ -587,11 +594,14 @@ int main(int argc, char *argv[])
|
|||
int gidx = -1;
|
||||
char gid[33];
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
srand48(getpid() * time(NULL));
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
while (1) {
|
||||
int c;
|
||||
|
||||
printf("LOG: PINGPONG - main");
|
||||
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