提交 84e79b9d 编写于 作者: B Bart Van Assche 提交者: Zheng Zengkai

RDMA/srpt: Introduce a reference count in struct srpt_device

stable inclusion
from stable-v5.10.137
commit d14a44cf2919920c61496ff252240fbfc5551faf
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d14a44cf2919920c61496ff252240fbfc5551faf

--------------------------------

[ Upstream commit aa7dfbb4 ]

This will be used to keep struct srpt_device around as long as either the
RDMA port exists or a LIO target port is associated with the struct
srpt_device.

Link: https://lore.kernel.org/r/20220727193415.1583860-3-bvanassche@acm.orgSigned-off-by: NBart Van Assche <bvanassche@acm.org>
Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 71ec26d4
......@@ -3101,6 +3101,18 @@ static int srpt_use_srq(struct srpt_device *sdev, bool use_srq)
return ret;
}
static void srpt_free_sdev(struct kref *refcnt)
{
struct srpt_device *sdev = container_of(refcnt, typeof(*sdev), refcnt);
kfree(sdev);
}
static void srpt_sdev_put(struct srpt_device *sdev)
{
kref_put(&sdev->refcnt, srpt_free_sdev);
}
/**
* srpt_add_one - InfiniBand device addition callback function
* @device: Describes a HCA.
......@@ -3118,6 +3130,7 @@ static int srpt_add_one(struct ib_device *device)
if (!sdev)
return -ENOMEM;
kref_init(&sdev->refcnt);
sdev->device = device;
mutex_init(&sdev->sdev_mutex);
......@@ -3213,7 +3226,7 @@ static int srpt_add_one(struct ib_device *device)
srpt_free_srq(sdev);
ib_dealloc_pd(sdev->pd);
free_dev:
kfree(sdev);
srpt_sdev_put(sdev);
pr_info("%s(%s) failed.\n", __func__, dev_name(&device->dev));
return ret;
}
......@@ -3257,7 +3270,7 @@ static void srpt_remove_one(struct ib_device *device, void *client_data)
ib_dealloc_pd(sdev->pd);
kfree(sdev);
srpt_sdev_put(sdev);
}
static struct ib_client srpt_client = {
......
......@@ -434,6 +434,7 @@ struct srpt_port {
/**
* struct srpt_device - information associated by SRPT with a single HCA
* @refcnt: Reference count for this device.
* @device: Backpointer to the struct ib_device managed by the IB core.
* @pd: IB protection domain.
* @lkey: L_Key (local key) with write access to all local memory.
......@@ -449,6 +450,7 @@ struct srpt_port {
* @port: Information about the ports owned by this HCA.
*/
struct srpt_device {
struct kref refcnt;
struct ib_device *device;
struct ib_pd *pd;
u32 lkey;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册