Message ID | 1538279422-25997-1-git-send-email-yanjun.zhu@oracle.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [1/1] IB: rxe: avoid srq memory leak | expand |
Hi Zhu, Thank you for the patch! Yet something to improve: [auto build test ERROR on sof-driver-fuweitax/master] [also build test ERROR on v4.19-rc5 next-20180928] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Zhu-Yanjun/IB-rxe-avoid-srq-memory-leak/20180930-115114 base: https://github.com/fuweitax/linux master config: sparc-allmodconfig (attached as .config) compiler: sparc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree GCC_VERSION=7.2.0 make.cross ARCH=sparc All errors (new ones prefixed by >>): drivers/infiniband/sw/rxe/rxe_srq.c: In function 'rxe_srq_from_init': >> drivers/infiniband/sw/rxe/rxe_srq.c:133:3: error: implicit declaration of function 'vfree'; did you mean 'kvfree'? [-Werror=implicit-function-declaration] vfree(q->buf); ^~~~~ kvfree cc1: some warnings being treated as errors vim +133 drivers/infiniband/sw/rxe/rxe_srq.c 99 100 int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq, 101 struct ib_srq_init_attr *init, 102 struct ib_ucontext *context, 103 struct rxe_create_srq_resp __user *uresp) 104 { 105 int err; 106 int srq_wqe_size; 107 struct rxe_queue *q; 108 109 srq->ibsrq.event_handler = init->event_handler; 110 srq->ibsrq.srq_context = init->srq_context; 111 srq->limit = init->attr.srq_limit; 112 srq->srq_num = srq->pelem.index; 113 srq->rq.max_wr = init->attr.max_wr; 114 srq->rq.max_sge = init->attr.max_sge; 115 116 srq_wqe_size = rcv_wqe_size(srq->rq.max_sge); 117 118 spin_lock_init(&srq->rq.producer_lock); 119 spin_lock_init(&srq->rq.consumer_lock); 120 121 q = rxe_queue_init(rxe, &srq->rq.max_wr, 122 srq_wqe_size); 123 if (!q) { 124 pr_warn("unable to allocate queue for srq\n"); 125 return -ENOMEM; 126 } 127 128 srq->rq.queue = q; 129 130 err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, context, q->buf, 131 q->buf_size, &q->ip); 132 if (err) { > 133 vfree(q->buf); 134 kfree(q); 135 return err; 136 } 137 138 if (uresp) { 139 if (copy_to_user(&uresp->srq_num, &srq->srq_num, 140 sizeof(uresp->srq_num))) { 141 rxe_queue_cleanup(q); 142 return -EFAULT; 143 } 144 } 145 146 return 0; 147 } 148 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Sorry. V2 has fixed this problem. Please make tests with V2. If any problem, please let me know. Thanks a lot. Zhu Yanjun On 2018/9/30 14:53, kbuild test robot wrote: > Hi Zhu, > > Thank you for the patch! Yet something to improve: > > [auto build test ERROR on sof-driver-fuweitax/master] > [also build test ERROR on v4.19-rc5 next-20180928] > [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] > > url: https://github.com/0day-ci/linux/commits/Zhu-Yanjun/IB-rxe-avoid-srq-memory-leak/20180930-115114 > base: https://github.com/fuweitax/linux master > config: sparc-allmodconfig (attached as .config) > compiler: sparc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0 > reproduce: > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # save the attached .config to linux build tree > GCC_VERSION=7.2.0 make.cross ARCH=sparc > > All errors (new ones prefixed by >>): > > drivers/infiniband/sw/rxe/rxe_srq.c: In function 'rxe_srq_from_init': >>> drivers/infiniband/sw/rxe/rxe_srq.c:133:3: error: implicit declaration of function 'vfree'; did you mean 'kvfree'? [-Werror=implicit-function-declaration] > vfree(q->buf); > ^~~~~ > kvfree > cc1: some warnings being treated as errors > > vim +133 drivers/infiniband/sw/rxe/rxe_srq.c > > 99 > 100 int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq, > 101 struct ib_srq_init_attr *init, > 102 struct ib_ucontext *context, > 103 struct rxe_create_srq_resp __user *uresp) > 104 { > 105 int err; > 106 int srq_wqe_size; > 107 struct rxe_queue *q; > 108 > 109 srq->ibsrq.event_handler = init->event_handler; > 110 srq->ibsrq.srq_context = init->srq_context; > 111 srq->limit = init->attr.srq_limit; > 112 srq->srq_num = srq->pelem.index; > 113 srq->rq.max_wr = init->attr.max_wr; > 114 srq->rq.max_sge = init->attr.max_sge; > 115 > 116 srq_wqe_size = rcv_wqe_size(srq->rq.max_sge); > 117 > 118 spin_lock_init(&srq->rq.producer_lock); > 119 spin_lock_init(&srq->rq.consumer_lock); > 120 > 121 q = rxe_queue_init(rxe, &srq->rq.max_wr, > 122 srq_wqe_size); > 123 if (!q) { > 124 pr_warn("unable to allocate queue for srq\n"); > 125 return -ENOMEM; > 126 } > 127 > 128 srq->rq.queue = q; > 129 > 130 err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, context, q->buf, > 131 q->buf_size, &q->ip); > 132 if (err) { > > 133 vfree(q->buf); > 134 kfree(q); > 135 return err; > 136 } > 137 > 138 if (uresp) { > 139 if (copy_to_user(&uresp->srq_num, &srq->srq_num, > 140 sizeof(uresp->srq_num))) { > 141 rxe_queue_cleanup(q); > 142 return -EFAULT; > 143 } > 144 } > 145 > 146 return 0; > 147 } > 148 > > --- > 0-DAY kernel test infrastructure Open Source Technology Center > https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/drivers/infiniband/sw/rxe/rxe_srq.c b/drivers/infiniband/sw/rxe/rxe_srq.c index 0d6c04b..ba068d3 100644 --- a/drivers/infiniband/sw/rxe/rxe_srq.c +++ b/drivers/infiniband/sw/rxe/rxe_srq.c @@ -129,13 +129,18 @@ int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq, err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, context, q->buf, q->buf_size, &q->ip); - if (err) + if (err) { + vfree(q->buf); + kfree(q); return err; + } if (uresp) { if (copy_to_user(&uresp->srq_num, &srq->srq_num, - sizeof(uresp->srq_num))) + sizeof(uresp->srq_num))) { + rxe_queue_cleanup(q); return -EFAULT; + } } return 0;
In rxe_queue_init, q and q->buf are allocated. In do_mmap_info, q->ip is allocated. When error occurs, rxe_srq_from_init and the later error handler do not free these allocated memories. This will make memory leak. CC: Srinivas Eeda <srinivas.eeda@oracle.com> CC: Junxiao Bi <junxiao.bi@oracle.com> Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com> --- drivers/infiniband/sw/rxe/rxe_srq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)