RDMA/rxe: Fix memory leak in error path code
Subsystems (2)
PATCH 1/1 RDMA/rxe: Fix memory leak in error path code
In rxe_mr_init_user() in rxe_mr.c at the third error the driver fails to free the memory at mr->map. This patch adds code to do that. This error only occurs if page_address() fails to return a non zero address which should never happen for 64 bit architectures.
Reported by: Haakon Bugge <[email protected]>
--- drivers/infiniband/sw/rxe/rxe_mr.c | 41 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-)
drivers/infiniband/sw/rxe/rxe_mr.c +24 -17
@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter; -int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;
@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; } mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ; map = mr->map;if (length >0 ) { buf = map[0 ]->buf;
@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;
@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; }
Signature · 1 line
2.30.2
Quoted 4 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.
Hi Bob,
Thanks for your quick fix.
It looks good to me.
Best Regards,
Xiao Yang
Quoted 91 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>--- drivers/infiniband/sw/rxe/rxe_mr.c | 41 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +24
-17@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter; -int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; } mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ; map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; }
Zhu Yanjun
maintainerQuoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.
If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 95 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>--- drivers/infiniband/sw/rxe/rxe_mr.c | 41 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +24
-18@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter; -int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; } mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ; map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2
Haakon Bugge
Reviewed-byQuoted 38 lines · Zhu Yanjun
Quoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 20 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>---
drivers/infiniband/sw/rxe/rxe_mr.c| 41 +++++++++++++++++-------------1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +0
-4@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter;
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr) · line 114
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c +6
-2-int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;
This white-space stripping must be another issue, not related to the memleak?
Quoted 27 lines
Quoted 27 lines
drivers/infiniband/sw/rxe/rxe_mr.c +7
-6int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; }
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, · line 141
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c +1
-1mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ;
White-space change.
Otherwise:
Thxs, Håkon
Quoted 35 lines
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe_mr.c +10
-5map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2
Zhu Yanjun
maintainerQuoted 77 lines · Haakon Bugge
Quoted 39 lines · Zhu Yanjun
Quoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 20 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>---
drivers/infiniband/sw/rxe/rxe_mr.c| 41 +++++++++++++++++-------------1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +0
-4@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter;Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr) · line 114
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c +6
-2-int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;This white-space stripping must be another issue, not related to the memleak?
Quoted 27 lines
Quoted 27 lines
drivers/infiniband/sw/rxe/rxe_mr.c +7
-6int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; }
Quoted 7 lines
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, · line 141
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c +1
-1mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ;White-space change.
Yeah. It seems that some white-space changes in this commit.
Zhu Yanjun
Quoted 46 lines
Otherwise:
Reviewed-by Håkon Bugge <[email protected]>Thxs, Håkon
Quoted 35 lines
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe_mr.c +10
-5map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2
Jason has been asking for patches to pass clang-format-patch so I've been cleaning up the code near functional changes since it doesn't like extra spaces such as for vertical alignment.
If I could figure out how ib_umem_works there is a chance that it would fail if it couldn't map all the user space virtual memory into kernel virtual addresses. But so far I have failed. It's fairly complex.
Bob
Quoted 137 lines · Zhu Yanjun
Quoted 77 lines · Haakon Bugge
Quoted 39 lines · Zhu Yanjun
Quoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 20 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>---
drivers/infiniband/sw/rxe/rxe_mr.c| 41 +++++++++++++++++-------------1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +0
-4@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter;Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr) · line 114
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c +6
-2-int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;This white-space stripping must be another issue, not related to the memleak?
Quoted 27 lines
Quoted 27 lines
drivers/infiniband/sw/rxe/rxe_mr.c +7
-6int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; }Quoted 7 lines
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, · line 141
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c +1
-1mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ;White-space change.
Yeah. It seems that some white-space changes in this commit.
Zhu Yanjun
Quoted 46 lines
Otherwise:
Reviewed-by Håkon Bugge <[email protected]>Thxs, Håkon
Quoted 35 lines
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe_mr.c +10
-5map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2
Sorry that was ib_umem_get().
Quoted 150 lines · Robert Pearson
Jason has been asking for patches to pass clang-format-patch so I've been cleaning up the code near functional changes since it doesn't like extra spaces such as for vertical alignment.
If I could figure out how
ib_umem_worksthere is a chance that it would fail if it couldn't map all the user space virtual memory into kernel virtual addresses. But so far I have failed. It's fairly complex.Bob
Quoted 137 lines · Zhu Yanjun
Quoted 77 lines · Haakon Bugge
Quoted 39 lines · Zhu Yanjun
Quoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 20 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>---
drivers/infiniband/sw/rxe/rxe_mr.c| 41 +++++++++++++++++-------------1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +0
-4@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter;Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr) · line 114
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c +6
-2-int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;This white-space stripping must be another issue, not related to the memleak?
Quoted 27 lines
Quoted 27 lines
drivers/infiniband/sw/rxe/rxe_mr.c +7
-6int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; }Quoted 7 lines
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, · line 141
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c +1
-1mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ;White-space change.
Yeah. It seems that some white-space changes in this commit.
Zhu Yanjun
Quoted 46 lines
Otherwise:
Reviewed-by Håkon Bugge <[email protected]>Thxs, Håkon
Quoted 35 lines
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe_mr.c +10
-5map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2
Jason Gunthorpe
maintainerQuoted 3 lines · Robert Pearson
Jason has been asking for patches to pass clang-format-patch so I've been cleaning up the code near functional changes since it doesn't like extra spaces such as for vertical alignment.
don't mix things though, new code should be closer to the standard style, but don't mix significant style cleanups with bug fixes
Quoted 4 lines
If I could figure out how
ib_umem_worksthere is a chance that it would fail if it couldn't map all the user space virtual memory into kernel virtual addresses. But so far I have failed. It's fairly complex.
It can fail for lots of reasons?
Jason
Quoted 7 lines · Robert Pearson
Jason has been asking for patches to pass clang-format-patch so I've been cleaning up the code near functional changes since it doesn't like extra spaces such as for vertical alignment.
One of my former colleague "trained" me on this, and almost wrote "not related to commit" on my forehead :-)
My preference is that you make one commit with style changes, another with functional changes. If the latter is reverted, Jason would still be happy about the style, right? And, it makes the process of reviewing simpler (at least for me).
Quoted 4 lines
If I could figure out how
ib_umem_worksthere is a chance that it would fail if it couldn't map all the user space virtual memory into kernel virtual addresses. But so far I have failed. It's fairly complex.
;-)
Thxs, Håkon
Quoted 141 lines
Bob
Quoted 137 lines · Zhu Yanjun
Quoted 77 lines · Haakon Bugge
Quoted 39 lines · Zhu Yanjun
Quoted 5 lines · Bob Pearson
In
rxe_mr_init_user()inrxe_mr.cat the third error the driver fails to free the memory atmr->map. This patch adds code to do that. This error only occurs ifpage_address()fails to return a non zero address which should never happen for 64 bit architectures.If this will never happen for 64 bit architectures, is it possible to exclude 64 bit architecture with some MACROs or others?
Thanks,
Zhu Yanjun
Quoted 20 lines
Fixes 8700e3e7c485 ("Soft RoCE driver")Reported by: Haakon Bugge <[email protected]>
Signed-off-by Bob Pearson <[email protected]>---
drivers/infiniband/sw/rxe/rxe_mr.c| 41 +++++++++++++++++-------------1 file changed, 24 insertions(+), 17 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +0
-4@@ -106,20 +106,21 @@ void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr)int rxe_mr_init_user (struct rxe_pd *pd,u64 start,u64 length,u64 iova,int access,struct rxe_mr *mr) { -struct rxe_map **map; -struct rxe_phys_buf *buf =NULL ; -struct ib_umem *umem; -struct sg_page_iter sg_iter;Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c void rxe_mr_init_dma(struct rxe_pd *pd, int access, struct rxe_mr *mr) · line 114
Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_mr.c +6
-2-int num_buf; -void *vaddr; +struct rxe_map **map; +struct rxe_phys_buf *buf =NULL ; +struct ib_umem *umem; +struct sg_page_iter sg_iter; +int num_buf; +void *vaddr;This white-space stripping must be another issue, not related to the memleak?
Quoted 27 lines
Quoted 27 lines
drivers/infiniband/sw/rxe/rxe_mr.c +7
-6int err; +int i; umem =ib_umem_get (pd->ibpd.device, start, length, access);if (IS_ERR (umem)) { -pr_warn ("err %d from rxe_umem_get\n" , - (int )PTR_ERR (umem)); +pr_warn ("%s: Unable to pin memory region err = %d\n" , + __func__, (int )PTR_ERR (umem)); err =PTR_ERR (umem); - goto err1; + goto err_out; } mr->umem = umem;@@ -129,15 +130,15 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, err =rxe_mr_alloc (mr, num_buf);if (err) { -pr_warn ("err %d from rxe_mr_alloc\n" , err); -ib_umem_release (umem); - goto err1; +pr_warn ("%s: Unable to allocate memory for map\n" , + __func__); + goto err_release_umem; }Quoted 7 lines
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, · line 141
Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_mr.c +1
-1mr->page_shift =PAGE_SHIFT ; mr->page_mask =PAGE_SIZE -1 ; - num_buf =0 ; + num_buf =0 ;White-space change.
Yeah. It seems that some white-space changes in this commit.
Zhu Yanjun
Quoted 46 lines
Otherwise:
Reviewed-by Håkon Bugge <[email protected]>Thxs, Håkon
Quoted 35 lines
Quoted 35 lines
drivers/infiniband/sw/rxe/rxe_mr.c +10
-5map = mr->map;if (length >0 ) { buf = map[0 ]->buf;@@ -151,10 +152,10 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova, vaddr =page_address (sg_page_iter_page (&sg_iter));if (!vaddr) { -pr_warn ("null vaddr\n" ); -ib_umem_release (umem); +pr_warn ("%s: Unable to get virtual address\n" , + __func__); err = -ENOMEM ; - goto err1; + goto err_cleanup_map; } buf->addr = (uintptr_t )vaddr;@@ -177,7 +178,13 @@ int rxe_mr_init_user(struct rxe_pd *pd, u64 start, u64 length, u64 iova,return 0 ; -err1: +err_cleanup_map: +for (i =0 ; i < mr->num_map; i++) +kfree (mr->map[i]); +kfree (mr->map); +err_release_umem: +ib_umem_release (umem); +err_out:return err; } --2.30.2