IB/hfi1: Switch to using the pin query function
authorMitko Haralanov <mitko.haralanov@intel.com>
Tue, 8 Mar 2016 19:15:39 +0000 (11:15 -0800)
committerDoug Ledford <dledford@redhat.com>
Mon, 21 Mar 2016 19:55:25 +0000 (15:55 -0400)
Use the new function to query whether the expected receive
user buffer can be pinned successfully. This requires that
a new variable be added to the hfi1_filedata structure used
to hold the number of pages pinned by the expected receive
code.

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: Dean Luick <dean.luick@intel.com>
Signed-off-by: Mitko Haralanov <mitko.haralanov@intel.com>
Signed-off-by: Jubin John <jubin.john@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/staging/rdma/hfi1/hfi.h
drivers/staging/rdma/hfi1/user_exp_rcv.c

index 3dc644d92e3a3cdacf129ad83f9ab405c78e0e98..16cbdc4073e0d16fe245e756410fb11af8609057 100644 (file)
@@ -1190,6 +1190,7 @@ struct hfi1_filedata {
        struct hfi1_user_sdma_pkt_q *pq;
        /* for cpu affinity; -1 if none */
        int rec_cpu_num;
+       u32 tid_n_pinned;
        struct rb_root tid_rb_root;
        struct tid_rb_node **entry_to_rb;
        spinlock_t tid_lock; /* protect tid_[limit,used] counters */
index 591605a13243d25fdb9a3880a755a1fae3add751..0861e095df8d458c3ecabb908c5345ed9a872c6b 100644 (file)
@@ -396,11 +396,14 @@ int hfi1_user_exp_rcv_setup(struct file *fp, struct hfi1_tid_info *tinfo)
         * pages, accept the amount pinned so far and program only that.
         * User space knows how to deal with partially programmed buffers.
         */
+       if (!hfi1_can_pin_pages(dd, fd->tid_n_pinned, npages))
+               return -ENOMEM;
        pinned = hfi1_acquire_user_pages(vaddr, npages, true, pages);
        if (pinned <= 0) {
                ret = pinned;
                goto bail;
        }
+       fd->tid_n_pinned += npages;
 
        /* Find sets of physically contiguous pages */
        npagesets = find_phys_blocks(pages, pinned, pagesets);
@@ -549,10 +552,12 @@ nomem:
         * If not everything was mapped (due to insufficient RcvArray entries,
         * for example), unpin all unmapped pages so we can pin them nex time.
         */
-       if (mapped_pages != pinned)
+       if (mapped_pages != pinned) {
                hfi1_release_user_pages(current->mm, &pages[mapped_pages],
                                        pinned - mapped_pages,
                                        false);
+               fd->tid_n_pinned -= pinned - mapped_pages;
+       }
 bail:
        kfree(pagesets);
        kfree(pages);
@@ -924,6 +929,7 @@ static void clear_tid_node(struct hfi1_filedata *fd, u16 subctxt,
        pci_unmap_single(dd->pcidev, node->dma_addr, node->mmu.len,
                         PCI_DMA_FROMDEVICE);
        hfi1_release_user_pages(current->mm, node->pages, node->npages, true);
+       fd->tid_n_pinned -= node->npages;
 
        node->grp->used--;
        node->grp->map &= ~(1 << (node->rcventry - node->grp->base));