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

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