[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git-commits-head
Subject:    RDMA/mlx5: Fix prefetch memory leak if get_prefetchable_mr fails
From:       Linux Kernel Mailing List <linux-kernel () vger ! kernel ! org>
Date:       2020-07-31 16:42:15
Message-ID: git-mailbomb-linux-master-5351a56b1a4ceafd7a17ebfdf3cda430cdfd365d () kernel ! org
[Download RAW message or body]

Commit:     5351a56b1a4ceafd7a17ebfdf3cda430cdfd365d
Parent:     31142a4ba617f5aa8aefdf1c65561ca30d43f360
Refname:    refs/heads/master
Web:        https://git.kernel.org/torvalds/c/5351a56b1a4ceafd7a17ebfdf3cda430cdfd365d
Author:     Jason Gunthorpe <jgg@nvidia.com>
AuthorDate: Mon Jul 27 12:57:12 2020 +0300
Committer:  Jason Gunthorpe <jgg@nvidia.com>
CommitDate: Mon Jul 27 11:50:20 2020 -0300

    RDMA/mlx5: Fix prefetch memory leak if get_prefetchable_mr fails
    
    destroy_prefetch_work() must always be called if the work is not going
    to be queued. The num_sge also should have been set to i, not i-1
    which avoids the condition where it shouldn't have been called in the
    first place.
    
    Cc: stable@vger.kernel.org
    Fixes: fb985e278a30 ("RDMA/mlx5: Use SRCU properly in ODP prefetch")
    Link: https://lore.kernel.org/r/20200727095712.495652-1-leon@kernel.org
    Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
    Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/infiniband/hw/mlx5/odp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
index 1ab676b66894..77dca1e05bba 100644
--- a/drivers/infiniband/hw/mlx5/odp.c
+++ b/drivers/infiniband/hw/mlx5/odp.c
@@ -1797,9 +1797,7 @@ static bool init_prefetch_work(struct ib_pd *pd,
 		work->frags[i].mr =
 			get_prefetchable_mr(pd, advice, sg_list[i].lkey);
 		if (!work->frags[i].mr) {
-			work->num_sge = i - 1;
-			if (i)
-				destroy_prefetch_work(work);
+			work->num_sge = i;
 			return false;
 		}
 
@@ -1865,6 +1863,7 @@ int mlx5_ib_advise_mr_prefetch(struct ib_pd *pd,
 	srcu_key = srcu_read_lock(&dev->odp_srcu);
 	if (!init_prefetch_work(pd, advice, pf_flags, work, sg_list, num_sge)) {
 		srcu_read_unlock(&dev->odp_srcu, srcu_key);
+		destroy_prefetch_work(work);
 		return -EINVAL;
 	}
 	queue_work(system_unbound_wq, &work->work);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic