Merge branch 'for-linus' from master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband

+104 -72
+1
drivers/infiniband/core/uverbs.h
··· 69 70 struct ib_uverbs_file { 71 struct kref ref; 72 struct ib_uverbs_device *device; 73 struct ib_ucontext *ucontext; 74 struct ib_event_handler event_handler;
··· 69 70 struct ib_uverbs_file { 71 struct kref ref; 72 + struct semaphore mutex; 73 struct ib_uverbs_device *device; 74 struct ib_ucontext *ucontext; 75 struct ib_event_handler event_handler;
+66 -54
drivers/infiniband/core/uverbs_cmd.c
··· 76 struct ib_uverbs_get_context_resp resp; 77 struct ib_udata udata; 78 struct ib_device *ibdev = file->device->ib_dev; 79 int i; 80 - int ret = in_len; 81 82 if (out_len < sizeof resp) 83 return -ENOSPC; ··· 86 if (copy_from_user(&cmd, buf, sizeof cmd)) 87 return -EFAULT; 88 89 INIT_UDATA(&udata, buf + sizeof cmd, 90 (unsigned long) cmd.response + sizeof resp, 91 in_len - sizeof cmd, out_len - sizeof resp); 92 93 - file->ucontext = ibdev->alloc_ucontext(ibdev, &udata); 94 - if (IS_ERR(file->ucontext)) { 95 - ret = PTR_ERR(file->ucontext); 96 - file->ucontext = NULL; 97 - return ret; 98 - } 99 100 - file->ucontext->device = ibdev; 101 - INIT_LIST_HEAD(&file->ucontext->pd_list); 102 - INIT_LIST_HEAD(&file->ucontext->mr_list); 103 - INIT_LIST_HEAD(&file->ucontext->mw_list); 104 - INIT_LIST_HEAD(&file->ucontext->cq_list); 105 - INIT_LIST_HEAD(&file->ucontext->qp_list); 106 - INIT_LIST_HEAD(&file->ucontext->srq_list); 107 - INIT_LIST_HEAD(&file->ucontext->ah_list); 108 - spin_lock_init(&file->ucontext->lock); 109 110 resp.async_fd = file->async_file.fd; 111 for (i = 0; i < file->device->num_comp; ++i) 112 if (copy_to_user((void __user *) (unsigned long) cmd.cq_fd_tab + 113 i * sizeof (__u32), 114 - &file->comp_file[i].fd, sizeof (__u32))) 115 - goto err; 116 117 if (copy_to_user((void __user *) (unsigned long) cmd.response, 118 - &resp, sizeof resp)) 119 - goto err; 120 121 return in_len; 122 123 - err: 124 - ibdev->dealloc_ucontext(file->ucontext); 125 - file->ucontext = NULL; 126 127 - return -EFAULT; 128 } 129 130 ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file, ··· 364 if (ret) 365 goto err_pd; 366 367 - spin_lock_irq(&file->ucontext->lock); 368 list_add_tail(&uobj->list, &file->ucontext->pd_list); 369 - spin_unlock_irq(&file->ucontext->lock); 370 371 memset(&resp, 0, sizeof resp); 372 resp.pd_handle = uobj->id; ··· 380 return in_len; 381 382 err_list: 383 - spin_lock_irq(&file->ucontext->lock); 384 list_del(&uobj->list); 385 - spin_unlock_irq(&file->ucontext->lock); 386 387 down(&ib_uverbs_idr_mutex); 388 idr_remove(&ib_uverbs_pd_idr, uobj->id); ··· 422 423 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle); 424 425 - spin_lock_irq(&file->ucontext->lock); 426 list_del(&uobj->list); 427 - spin_unlock_irq(&file->ucontext->lock); 428 429 kfree(uobj); 430 ··· 524 525 resp.mr_handle = obj->uobject.id; 526 527 - spin_lock_irq(&file->ucontext->lock); 528 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 529 - spin_unlock_irq(&file->ucontext->lock); 530 531 if (copy_to_user((void __user *) (unsigned long) cmd.response, 532 &resp, sizeof resp)) { ··· 539 return in_len; 540 541 err_list: 542 - spin_lock_irq(&file->ucontext->lock); 543 list_del(&obj->uobject.list); 544 - spin_unlock_irq(&file->ucontext->lock); 545 546 err_unreg: 547 ib_dereg_mr(mr); ··· 582 583 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle); 584 585 - spin_lock_irq(&file->ucontext->lock); 586 list_del(&memobj->uobject.list); 587 - spin_unlock_irq(&file->ucontext->lock); 588 589 ib_umem_release(file->device->ib_dev, &memobj->umem); 590 kfree(memobj); ··· 659 if (ret) 660 goto err_cq; 661 662 - spin_lock_irq(&file->ucontext->lock); 663 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 664 - spin_unlock_irq(&file->ucontext->lock); 665 666 memset(&resp, 0, sizeof resp); 667 resp.cq_handle = uobj->uobject.id; ··· 676 return in_len; 677 678 err_list: 679 - spin_lock_irq(&file->ucontext->lock); 680 list_del(&uobj->uobject.list); 681 - spin_unlock_irq(&file->ucontext->lock); 682 683 down(&ib_uverbs_idr_mutex); 684 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); ··· 724 725 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); 726 727 - spin_lock_irq(&file->ucontext->lock); 728 list_del(&uobj->uobject.list); 729 - spin_unlock_irq(&file->ucontext->lock); 730 731 spin_lock_irq(&file->comp_file[0].lock); 732 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) { ··· 859 860 resp.qp_handle = uobj->uobject.id; 861 862 - spin_lock_irq(&file->ucontext->lock); 863 list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list); 864 - spin_unlock_irq(&file->ucontext->lock); 865 866 if (copy_to_user((void __user *) (unsigned long) cmd.response, 867 &resp, sizeof resp)) { ··· 874 return in_len; 875 876 err_list: 877 - spin_lock_irq(&file->ucontext->lock); 878 list_del(&uobj->uobject.list); 879 - spin_unlock_irq(&file->ucontext->lock); 880 881 err_destroy: 882 ib_destroy_qp(qp); ··· 1001 1002 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); 1003 1004 - spin_lock_irq(&file->ucontext->lock); 1005 list_del(&uobj->uobject.list); 1006 - spin_unlock_irq(&file->ucontext->lock); 1007 1008 spin_lock_irq(&file->async_file.lock); 1009 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { ··· 1148 1149 resp.srq_handle = uobj->uobject.id; 1150 1151 - spin_lock_irq(&file->ucontext->lock); 1152 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1153 - spin_unlock_irq(&file->ucontext->lock); 1154 1155 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1156 &resp, sizeof resp)) { ··· 1163 return in_len; 1164 1165 err_list: 1166 - spin_lock_irq(&file->ucontext->lock); 1167 list_del(&uobj->uobject.list); 1168 - spin_unlock_irq(&file->ucontext->lock); 1169 1170 err_destroy: 1171 ib_destroy_srq(srq); ··· 1239 1240 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); 1241 1242 - spin_lock_irq(&file->ucontext->lock); 1243 list_del(&uobj->uobject.list); 1244 - spin_unlock_irq(&file->ucontext->lock); 1245 1246 spin_lock_irq(&file->async_file.lock); 1247 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
··· 76 struct ib_uverbs_get_context_resp resp; 77 struct ib_udata udata; 78 struct ib_device *ibdev = file->device->ib_dev; 79 + struct ib_ucontext *ucontext; 80 int i; 81 + int ret; 82 83 if (out_len < sizeof resp) 84 return -ENOSPC; ··· 85 if (copy_from_user(&cmd, buf, sizeof cmd)) 86 return -EFAULT; 87 88 + down(&file->mutex); 89 + 90 + if (file->ucontext) { 91 + ret = -EINVAL; 92 + goto err; 93 + } 94 + 95 INIT_UDATA(&udata, buf + sizeof cmd, 96 (unsigned long) cmd.response + sizeof resp, 97 in_len - sizeof cmd, out_len - sizeof resp); 98 99 + ucontext = ibdev->alloc_ucontext(ibdev, &udata); 100 + if (IS_ERR(ucontext)) 101 + return PTR_ERR(file->ucontext); 102 103 + ucontext->device = ibdev; 104 + INIT_LIST_HEAD(&ucontext->pd_list); 105 + INIT_LIST_HEAD(&ucontext->mr_list); 106 + INIT_LIST_HEAD(&ucontext->mw_list); 107 + INIT_LIST_HEAD(&ucontext->cq_list); 108 + INIT_LIST_HEAD(&ucontext->qp_list); 109 + INIT_LIST_HEAD(&ucontext->srq_list); 110 + INIT_LIST_HEAD(&ucontext->ah_list); 111 112 resp.async_fd = file->async_file.fd; 113 for (i = 0; i < file->device->num_comp; ++i) 114 if (copy_to_user((void __user *) (unsigned long) cmd.cq_fd_tab + 115 i * sizeof (__u32), 116 + &file->comp_file[i].fd, sizeof (__u32))) { 117 + ret = -EFAULT; 118 + goto err_free; 119 + } 120 121 if (copy_to_user((void __user *) (unsigned long) cmd.response, 122 + &resp, sizeof resp)) { 123 + ret = -EFAULT; 124 + goto err_free; 125 + } 126 + 127 + file->ucontext = ucontext; 128 + up(&file->mutex); 129 130 return in_len; 131 132 + err_free: 133 + ibdev->dealloc_ucontext(ucontext); 134 135 + err: 136 + up(&file->mutex); 137 + return ret; 138 } 139 140 ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file, ··· 352 if (ret) 353 goto err_pd; 354 355 + down(&file->mutex); 356 list_add_tail(&uobj->list, &file->ucontext->pd_list); 357 + up(&file->mutex); 358 359 memset(&resp, 0, sizeof resp); 360 resp.pd_handle = uobj->id; ··· 368 return in_len; 369 370 err_list: 371 + down(&file->mutex); 372 list_del(&uobj->list); 373 + up(&file->mutex); 374 375 down(&ib_uverbs_idr_mutex); 376 idr_remove(&ib_uverbs_pd_idr, uobj->id); ··· 410 411 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle); 412 413 + down(&file->mutex); 414 list_del(&uobj->list); 415 + up(&file->mutex); 416 417 kfree(uobj); 418 ··· 512 513 resp.mr_handle = obj->uobject.id; 514 515 + down(&file->mutex); 516 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 517 + up(&file->mutex); 518 519 if (copy_to_user((void __user *) (unsigned long) cmd.response, 520 &resp, sizeof resp)) { ··· 527 return in_len; 528 529 err_list: 530 + down(&file->mutex); 531 list_del(&obj->uobject.list); 532 + up(&file->mutex); 533 534 err_unreg: 535 ib_dereg_mr(mr); ··· 570 571 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle); 572 573 + down(&file->mutex); 574 list_del(&memobj->uobject.list); 575 + up(&file->mutex); 576 577 ib_umem_release(file->device->ib_dev, &memobj->umem); 578 kfree(memobj); ··· 647 if (ret) 648 goto err_cq; 649 650 + down(&file->mutex); 651 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 652 + up(&file->mutex); 653 654 memset(&resp, 0, sizeof resp); 655 resp.cq_handle = uobj->uobject.id; ··· 664 return in_len; 665 666 err_list: 667 + down(&file->mutex); 668 list_del(&uobj->uobject.list); 669 + up(&file->mutex); 670 671 down(&ib_uverbs_idr_mutex); 672 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); ··· 712 713 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); 714 715 + down(&file->mutex); 716 list_del(&uobj->uobject.list); 717 + up(&file->mutex); 718 719 spin_lock_irq(&file->comp_file[0].lock); 720 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) { ··· 847 848 resp.qp_handle = uobj->uobject.id; 849 850 + down(&file->mutex); 851 list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list); 852 + up(&file->mutex); 853 854 if (copy_to_user((void __user *) (unsigned long) cmd.response, 855 &resp, sizeof resp)) { ··· 862 return in_len; 863 864 err_list: 865 + down(&file->mutex); 866 list_del(&uobj->uobject.list); 867 + up(&file->mutex); 868 869 err_destroy: 870 ib_destroy_qp(qp); ··· 989 990 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); 991 992 + down(&file->mutex); 993 list_del(&uobj->uobject.list); 994 + up(&file->mutex); 995 996 spin_lock_irq(&file->async_file.lock); 997 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) { ··· 1136 1137 resp.srq_handle = uobj->uobject.id; 1138 1139 + down(&file->mutex); 1140 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1141 + up(&file->mutex); 1142 1143 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1144 &resp, sizeof resp)) { ··· 1151 return in_len; 1152 1153 err_list: 1154 + down(&file->mutex); 1155 list_del(&uobj->uobject.list); 1156 + up(&file->mutex); 1157 1158 err_destroy: 1159 ib_destroy_srq(srq); ··· 1227 1228 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); 1229 1230 + down(&file->mutex); 1231 list_del(&uobj->uobject.list); 1232 + up(&file->mutex); 1233 1234 spin_lock_irq(&file->async_file.lock); 1235 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
+19 -8
drivers/infiniband/core/uverbs_main.c
··· 448 if (hdr.in_words * 4 != count) 449 return -EINVAL; 450 451 - if (hdr.command < 0 || hdr.command >= ARRAY_SIZE(uverbs_cmd_table)) 452 return -EINVAL; 453 454 if (!file->ucontext && ··· 486 file = kmalloc(sizeof *file + 487 (dev->num_comp - 1) * sizeof (struct ib_uverbs_event_file), 488 GFP_KERNEL); 489 - if (!file) 490 - return -ENOMEM; 491 492 file->device = dev; 493 kref_init(&file->ref); 494 495 file->ucontext = NULL; 496 497 ret = ib_uverbs_event_init(&file->async_file, file); 498 if (ret) 499 - goto err; 500 501 file->async_file.is_async = 1; 502 503 - kref_get(&file->ref); 504 - 505 for (i = 0; i < dev->num_comp; ++i) { 506 ret = ib_uverbs_event_init(&file->comp_file[i], file); 507 if (ret) 508 goto err_async; 509 - kref_get(&file->ref); 510 file->comp_file[i].is_async = 0; 511 } 512 ··· 528 529 ib_uverbs_event_release(&file->async_file); 530 531 - err: 532 kref_put(&file->ref, ib_uverbs_release_file); 533 534 return ret; 535 } 536
··· 448 if (hdr.in_words * 4 != count) 449 return -EINVAL; 450 451 + if (hdr.command < 0 || 452 + hdr.command >= ARRAY_SIZE(uverbs_cmd_table) || 453 + !uverbs_cmd_table[hdr.command]) 454 return -EINVAL; 455 456 if (!file->ucontext && ··· 484 file = kmalloc(sizeof *file + 485 (dev->num_comp - 1) * sizeof (struct ib_uverbs_event_file), 486 GFP_KERNEL); 487 + if (!file) { 488 + ret = -ENOMEM; 489 + goto err; 490 + } 491 492 file->device = dev; 493 kref_init(&file->ref); 494 + init_MUTEX(&file->mutex); 495 496 file->ucontext = NULL; 497 498 + kref_get(&file->ref); 499 ret = ib_uverbs_event_init(&file->async_file, file); 500 if (ret) 501 + goto err_kref; 502 503 file->async_file.is_async = 1; 504 505 for (i = 0; i < dev->num_comp; ++i) { 506 + kref_get(&file->ref); 507 ret = ib_uverbs_event_init(&file->comp_file[i], file); 508 if (ret) 509 goto err_async; 510 file->comp_file[i].is_async = 0; 511 } 512 ··· 524 525 ib_uverbs_event_release(&file->async_file); 526 527 + err_kref: 528 + /* 529 + * One extra kref_put() because we took a reference before the 530 + * event file creation that failed and got us here. 531 + */ 532 + kref_put(&file->ref, ib_uverbs_release_file); 533 kref_put(&file->ref, ib_uverbs_release_file); 534 535 + err: 536 + module_put(dev->ib_dev->owner); 537 return ret; 538 } 539
+2 -2
drivers/infiniband/hw/mthca/mthca_cmd.c
··· 605 err = -EINVAL; 606 goto out; 607 } 608 - for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i, ++nent) { 609 if (virt != -1) { 610 pages[nent * 2] = cpu_to_be64(virt); 611 virt += 1 << lg; ··· 616 ts += 1 << (lg - 10); 617 ++tc; 618 619 - if (nent == MTHCA_MAILBOX_SIZE / 16) { 620 err = mthca_cmd(dev, mailbox->dma, nent, 0, op, 621 CMD_TIME_CLASS_B, status); 622 if (err || *status)
··· 605 err = -EINVAL; 606 goto out; 607 } 608 + for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i) { 609 if (virt != -1) { 610 pages[nent * 2] = cpu_to_be64(virt); 611 virt += 1 << lg; ··· 616 ts += 1 << (lg - 10); 617 ++tc; 618 619 + if (++nent == MTHCA_MAILBOX_SIZE / 16) { 620 err = mthca_cmd(dev, mailbox->dma, nent, 0, op, 621 CMD_TIME_CLASS_B, status); 622 if (err || *status)
+1 -1
drivers/infiniband/hw/mthca/mthca_eq.c
··· 836 dev->eq_table.clr_mask = 837 swab32(1 << (dev->eq_table.inta_pin & 31)); 838 dev->eq_table.clr_int = dev->clr_base + 839 - (dev->eq_table.inta_pin < 31 ? 4 : 0); 840 } 841 842 dev->eq_table.arm_mask = 0;
··· 836 dev->eq_table.clr_mask = 837 swab32(1 << (dev->eq_table.inta_pin & 31)); 838 dev->eq_table.clr_int = dev->clr_base + 839 + (dev->eq_table.inta_pin < 32 ? 4 : 0); 840 } 841 842 dev->eq_table.arm_mask = 0;
+14 -5
drivers/infiniband/hw/mthca/mthca_memfree.c
··· 290 int i; 291 u8 status; 292 293 - num_icm = obj_size * nobj / MTHCA_TABLE_CHUNK_SIZE; 294 295 table = kmalloc(sizeof *table + num_icm * sizeof *table->icm, GFP_KERNEL); 296 if (!table) ··· 529 goto found; 530 } 531 532 if (dev->db_tab->max_group1 >= dev->db_tab->min_group2 - 1) { 533 ret = -ENOMEM; 534 goto out; 535 } 536 537 page = dev->db_tab->page + end; 538 page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096, 539 &page->mapping, GFP_KERNEL); 540 if (!page->db_rec) { ··· 567 } 568 569 bitmap_zero(page->used, MTHCA_DB_REC_PER_PAGE); 570 - if (group == 0) 571 - ++dev->db_tab->max_group1; 572 - else 573 - --dev->db_tab->min_group2; 574 575 found: 576 j = find_first_zero_bit(page->used, MTHCA_DB_REC_PER_PAGE);
··· 290 int i; 291 u8 status; 292 293 + num_icm = (obj_size * nobj + MTHCA_TABLE_CHUNK_SIZE - 1) / MTHCA_TABLE_CHUNK_SIZE; 294 295 table = kmalloc(sizeof *table + num_icm * sizeof *table->icm, GFP_KERNEL); 296 if (!table) ··· 529 goto found; 530 } 531 532 + for (i = start; i != end; i += dir) 533 + if (!dev->db_tab->page[i].db_rec) { 534 + page = dev->db_tab->page + i; 535 + goto alloc; 536 + } 537 + 538 if (dev->db_tab->max_group1 >= dev->db_tab->min_group2 - 1) { 539 ret = -ENOMEM; 540 goto out; 541 } 542 543 + if (group == 0) 544 + ++dev->db_tab->max_group1; 545 + else 546 + --dev->db_tab->min_group2; 547 + 548 page = dev->db_tab->page + end; 549 + 550 + alloc: 551 page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096, 552 &page->mapping, GFP_KERNEL); 553 if (!page->db_rec) { ··· 554 } 555 556 bitmap_zero(page->used, MTHCA_DB_REC_PER_PAGE); 557 558 found: 559 j = find_first_zero_bit(page->used, MTHCA_DB_REC_PER_PAGE);
+1 -1
drivers/infiniband/hw/mthca/mthca_provider.c
··· 84 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) & 85 0xffffff; 86 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); 87 - props->hw_ver = be16_to_cpup((__be16 *) (out_mad->data + 32)); 88 memcpy(&props->sys_image_guid, out_mad->data + 4, 8); 89 memcpy(&props->node_guid, out_mad->data + 12, 8); 90
··· 84 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) & 85 0xffffff; 86 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30)); 87 + props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32)); 88 memcpy(&props->sys_image_guid, out_mad->data + 4, 8); 89 memcpy(&props->node_guid, out_mad->data + 12, 8); 90
-1
include/rdma/ib_verbs.h
··· 665 struct list_head qp_list; 666 struct list_head srq_list; 667 struct list_head ah_list; 668 - spinlock_t lock; 669 }; 670 671 struct ib_uobject {
··· 665 struct list_head qp_list; 666 struct list_head srq_list; 667 struct list_head ah_list; 668 }; 669 670 struct ib_uobject {