All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
To: jgg@nvidia.com, leonro@nvidia.com
Cc: Dean Luick <dean.luick@cornelisnetworks.com>, linux-rdma@vger.kernel.org
Subject: [PATCH for-rc 3/6] IB/hfi1: Reserve user expected TIDs
Date: Mon, 09 Jan 2023 12:31:16 -0500	[thread overview]
Message-ID: <167328547636.1472310.7419712824785353905.stgit@awfm-02.cornelisnetworks.com> (raw)
In-Reply-To: <167328512911.1472310.3529280633243532911.stgit@awfm-02.cornelisnetworks.com>

From: Dean Luick <dean.luick@cornelisnetworks.com>

To avoid a race, reserve the number of user expected
TIDs before setup.

Fixes: 7e7a436ecb6e ("staging/hfi1: Add TID entry program function body")
Signed-off-by: Dean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
---
 drivers/infiniband/hw/hfi1/user_exp_rcv.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/infiniband/hw/hfi1/user_exp_rcv.c b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
index 3c609b11e71c..d7487555d109 100644
--- a/drivers/infiniband/hw/hfi1/user_exp_rcv.c
+++ b/drivers/infiniband/hw/hfi1/user_exp_rcv.c
@@ -282,16 +282,13 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
 	/* Find sets of physically contiguous pages */
 	tidbuf->n_psets = find_phys_blocks(tidbuf, pinned);
 
-	/*
-	 * We don't need to access this under a lock since tid_used is per
-	 * process and the same process cannot be in hfi1_user_exp_rcv_clear()
-	 * and hfi1_user_exp_rcv_setup() at the same time.
-	 */
+	/* Reserve the number of expected tids to be used. */
 	spin_lock(&fd->tid_lock);
 	if (fd->tid_used + tidbuf->n_psets > fd->tid_limit)
 		pageset_count = fd->tid_limit - fd->tid_used;
 	else
 		pageset_count = tidbuf->n_psets;
+	fd->tid_used += pageset_count;
 	spin_unlock(&fd->tid_lock);
 
 	if (!pageset_count)
@@ -400,10 +397,11 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
 nomem:
 	hfi1_cdbg(TID, "total mapped: tidpairs:%u pages:%u (%d)", tididx,
 		  mapped_pages, ret);
+	/* adjust reserved tid_used to actual count */
+	spin_lock(&fd->tid_lock);
+	fd->tid_used -= pageset_count - tididx;
+	spin_unlock(&fd->tid_lock);
 	if (tididx) {
-		spin_lock(&fd->tid_lock);
-		fd->tid_used += tididx;
-		spin_unlock(&fd->tid_lock);
 		tinfo->tidcnt = tididx;
 		tinfo->length = mapped_pages * PAGE_SIZE;
 



  parent reply	other threads:[~2023-01-09 17:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 17:31 [PATCH for-rc 0/6] HFI fixups around expected recv Dennis Dalessandro
2023-01-09 17:31 ` [PATCH for-rc 1/6] IB/hfi1: Restore allocated resources on failed copyout Dennis Dalessandro
2023-01-10 10:12   ` Leon Romanovsky
2023-01-09 17:31 ` [PATCH for-rc 2/6] IB/hfi1: Reject a zero-length user expected buffer Dennis Dalessandro
2023-01-09 17:31 ` Dennis Dalessandro [this message]
2023-01-09 17:31 ` [PATCH for-rc 4/6] IB/hfi1: Fix expected receive setup error exit issues Dennis Dalessandro
2023-01-09 17:31 ` [PATCH for-rc 5/6] IB/hfi1: Immediately remove invalid memory from hardware Dennis Dalessandro
2023-01-09 17:31 ` [PATCH for-rc 6/6] IB/hfi1: Remove user expected buffer invalidate race Dennis Dalessandro
2023-01-16 15:41   ` Jason Gunthorpe
2023-01-17 19:19     ` Dean Luick
2023-01-18 12:42       ` Jason Gunthorpe
2023-01-19 16:00         ` Dean Luick
2023-01-19 18:05           ` Jason Gunthorpe
2023-01-20 16:09             ` Dean Luick
2023-01-10 10:17 ` [PATCH for-rc 0/6] HFI fixups around expected recv Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=167328547636.1472310.7419712824785353905.stgit@awfm-02.cornelisnetworks.com \
    --to=dennis.dalessandro@cornelisnetworks.com \
    --cc=dean.luick@cornelisnetworks.com \
    --cc=jgg@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.