On Mon, Sep 07, 2020 at 03:21:46PM +0300, Leon Romanovsky wrote: > From: Leon Romanovsky <leonro@xxxxxxxxxxxx> > > Refactor the restrack code to make sure that kref inside restrack entry > properly kref the object in which it is embedded. This slight change is > needed for future conversions of MR and QP which are refcounted before > the release and kfree. > > The ideal flow from ib_core perspective as follows: > * Allocate ib_* structure with rdma_zalloc_*. Given how things are going it would be good to eventually include the kref initialization in the allocation: struct rdma_restrack_entry *_rdma_zalloc_drv_obj_gfp(struct ib_device *ibdev, size_t size, size_t res_offset, gfp_t flags); { struct rdma_restrack_entry res = kzalloc(size, flags) + res_offset; [..] return res; } #define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp) \ container_of(_rdma_zalloc_drv_obj_gfp( \ ib_dev, (ib_dev)->ops.size_##ib_type, \ offsetof(struct ib_type, res), gfp), \ struct ib_type, res) As the idea is every drv_obj will have the kref The patch looks OK, the rdma_restrack_new calls are all near their matching allocations Jason