Hi.
I allocated a shared memory with read only permission and tried to
register it
(as read only memory) and failed.
(in the kernel level: drivers/infiniband/core/umem.c, function
get_user_pages failed)
Attached is a short code that reproduces this error.
Is this is an expected behavior?
thanks
Dotan
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/shm.h>
#include <infiniband/verbs.h>
struct config_t {
const char *dev_name;
int ib_port;
};
struct config_t config = {
"mthca0", /* dev_name */
1, /* ib_port */
};
/*************************************************************
* Function: print_config
*************************************************************/
static void print_config(void)
{
printf(" ------------------------------------------------\n");
printf(" Current pid : %d\n", getpid());
printf(" Device name : \"%s\"\n", config.dev_name);
printf(" IB port : %u\n", config.ib_port);
printf(" ------------------------------------------------\n");
}
/*************************************************************
**************************************************************
* main
*************************************************************
*************************************************************/
int main(int argc, char *argv[])
{
struct ibv_device **dev_list;
struct ibv_device *ib_dev = NULL;
struct ibv_context *context = NULL;
struct ibv_pd *pd = NULL;
struct ibv_mr *mr = NULL;
void *buf = NULL;
struct shmid_ds shmid_data;
int shmid = -1;
key_t key = 0x12345;
int i;
int page_size;
int num_devices;
int result = 1;
print_config();
page_size = sysconf(_SC_PAGESIZE);
/* get device names in the system */
dev_list = ibv_get_device_list(&num_devices);
if (!dev_list) {
fprintf(stderr, "failed to get IB devices list\n");
goto cleanup;
}
for (i = 0; i < num_devices; i ++) {
if (!strcmp(ibv_get_device_name(dev_list[i]), config.dev_name))
{
ib_dev = dev_list[i];
break;
}
}
if (!ib_dev) {
fprintf(stderr, "IB device %s wasn't found\n", config.dev_name);
goto cleanup;
}
shmid = shmget(key, page_size, IPC_CREAT);
if (shmid < 0) {
fprintf(stderr, "Couldn't get shared memory key.\n");
goto cleanup;
}
buf = shmat(shmid, NULL, SHM_RDONLY);
if (buf == ((void *)(-1))) {
fprintf(stderr, "Couldn't allocate work buf.\n");
if (shmctl(shmid, IPC_RMID, &shmid_data))
fprintf(stderr, "Couldn't delete shared memory id.\n");
goto cleanup;
}
printf("Shared memory was allocated\n");
context = ibv_open_device(ib_dev);
if (!context) {
fprintf(stderr, "Couldn't get context for %s\n",
ibv_get_device_name(ib_dev));
goto cleanup;
}
pd = ibv_alloc_pd(context);
if (!pd) {
fprintf(stderr, "Couldn't allocate PD\n");
goto cleanup;
}
/* mr = ibv_reg_mr(pd, buf, page_size, IBV_ACCESS_LOCAL_WRITE); */
mr = ibv_reg_mr(pd, buf, page_size, 0);
if (!mr) {
fprintf(stderr, "Couldn't allocate MR\n");
goto cleanup;
}
result = 0;
cleanup:
if (mr) {
if (ibv_dereg_mr(mr)) {
fprintf(stderr, "Couldn't deregister MR.\n");
result = 1;
}
}
if (pd) {
if (ibv_dealloc_pd(pd)) {
fprintf(stderr, "Couldn't deallocate PD.\n");
result = 1;
}
}
if (context) {
if (ibv_close_device(context)) {
fprintf(stderr, "Couldn't close IB device.\n");
result = 1;
}
}
if (buf) {
if (shmdt(buf)) {
fprintf(stderr, "Couldn't detach shared memory.\n");
result = 1;
}
}
if (shmid > 0) {
if (shmctl(shmid, IPC_RMID, &shmid_data)) {
fprintf(stderr, "Couldn't delete shared memory id.\n");
result = 1;
}
}
printf("Return status is %d\n", result);
return result;
}
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general
To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general