public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 02/30] IB/core: Add kref to IB devices
@ 2015-02-19 10:16 Somnath Kotur
  0 siblings, 0 replies; 60+ messages in thread
From: Somnath Kotur @ 2015-02-19 10:16 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Matan Barak, Somnath Kotur

From: Matan Barak <matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

Previously. we used device_mutex lock in order to protect
the device's list. That means that in order to guarantee a
device isn't freed while we use it, we had to lock all
devices.

Adding a kref per IB device. Before an IB device
is unregistered, we wait before its not held anymore.

Signed-off-by: Matan Barak <matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Somnath Kotur <somnath.kotur-laKkSmNT4hbQT0dZR+AlfA@public.gmane.org>
---
 drivers/infiniband/core/device.c |   41 ++++++++++++++++++++++++++++++++++++++
 include/rdma/ib_verbs.h          |    6 +++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 18c1ece..8616a95 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -261,6 +261,39 @@ out:
 	return ret;
 }
 
+static void ib_device_complete_cb(struct kref *kref)
+{
+	struct ib_device *device = container_of(kref, struct ib_device,
+						refcount);
+
+	if (device->reg_state >= IB_DEV_UNREGISTERING)
+		complete(&device->free);
+}
+
+/**
+ * ib_device_hold - increase the reference count of device
+ * @device: ib device to prevent from being free'd
+ *
+ * Prevent the device from being free'd.
+ */
+void ib_device_hold(struct ib_device *device)
+{
+	kref_get(&device->refcount);
+}
+EXPORT_SYMBOL(ib_device_hold);
+
+/**
+ * ib_device_put - decrease the reference count of device
+ * @device: allows this device to be free'd
+ *
+ * Puts the ib_device and allows it to be free'd.
+ */
+int ib_device_put(struct ib_device *device)
+{
+	return kref_put(&device->refcount, ib_device_complete_cb);
+}
+EXPORT_SYMBOL(ib_device_put);
+
 /**
  * ib_register_device - Register an IB device with IB core
  * @device:Device to register
@@ -312,6 +345,9 @@ int ib_register_device(struct ib_device *device,
 
 	list_add_tail(&device->core_list, &device_list);
 
+	kref_init(&device->refcount);
+	init_completion(&device->free);
+
 	device->reg_state = IB_DEV_REGISTERED;
 
 	{
@@ -342,6 +378,8 @@ void ib_unregister_device(struct ib_device *device)
 
 	mutex_lock(&device_mutex);
 
+	device->reg_state = IB_DEV_UNREGISTERING;
+
 	list_for_each_entry_reverse(client, &client_list, list)
 		if (client->remove)
 			client->remove(device);
@@ -355,6 +393,9 @@ void ib_unregister_device(struct ib_device *device)
 
 	ib_device_unregister_sysfs(device);
 
+	ib_device_put(device);
+	wait_for_completion(&device->free);
+
 	spin_lock_irqsave(&device->client_data_lock, flags);
 	list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
 		kfree(context);
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 1866595..a7593b0 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1716,6 +1716,7 @@ struct ib_device {
 	enum {
 		IB_DEV_UNINITIALIZED,
 		IB_DEV_REGISTERED,
+		IB_DEV_UNREGISTERING,
 		IB_DEV_UNREGISTERED
 	}                            reg_state;
 
@@ -1728,6 +1729,8 @@ struct ib_device {
 	u32			     local_dma_lkey;
 	u8                           node_type;
 	u8                           phys_port_cnt;
+	struct kref		     refcount;
+	struct completion	     free;
 };
 
 struct ib_client {
@@ -1741,6 +1744,9 @@ struct ib_client {
 struct ib_device *ib_alloc_device(size_t size);
 void ib_dealloc_device(struct ib_device *device);
 
+void ib_device_hold(struct ib_device *device);
+int ib_device_put(struct ib_device *device);
+
 int ib_register_device(struct ib_device *device,
 		       int (*port_callback)(struct ib_device *,
 					    u8, struct kobject *));
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2015-02-24  8:05 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1424383365-19337-1-git-send-email-somnath.kotur@emulex.com>
     [not found] ` <1424383365-19337-1-git-send-email-somnath.kotur-laKkSmNT4hbQT0dZR+AlfA@public.gmane.org>
2015-02-19 22:02   ` [PATCH 01/30] IB/core: Add RoCE GID cache Somnath Kotur
2015-02-19 22:02   ` [PATCH 02/30] IB/core: Add kref to IB devices Somnath Kotur
     [not found]     ` <1b381c86-9f29-49a6-b7c5-9571d4490f5c-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 10:57       ` Haggai Eran
     [not found]         ` <54E5C1AF.4010400-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 12:34           ` Matan Barak
2015-02-19 22:02   ` [PATCH 03/30] IB/core: Add RoCE GID population Somnath Kotur
2015-02-19 22:02   ` [PATCH 04/30] IB/core: Add default GID for RoCE GID Cache Somnath Kotur
2015-02-19 22:02   ` [PATCH 05/30] IB/core: Add RoCE cache bonding support Somnath Kotur
2015-02-19 22:02   ` [PATCH 06/30] IB/core: GID attribute should be returned from verbs API and cache API Somnath Kotur
2015-02-19 22:02   ` [PATCH 07/30] IB/core: Report gid_type and gid_ndev through sysfs Somnath Kotur
2015-02-19 22:02   ` [PATCH 08/30] IB/core: Support find sgid index using a filter function Somnath Kotur
     [not found]     ` <3f9746be-8d95-429c-945e-59b0b90a17e8-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 12:41       ` Haggai Eran
     [not found]         ` <54E5DA0D.4020002-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 12:48           ` Matan Barak
2015-02-19 22:02   ` [PATCH 09/30] IB/core: Modify ib_verbs and cma in order to use roce_gid_cache Somnath Kotur
     [not found]     ` <f91c8ed3-f6a4-4b63-85f9-870d9687a14f-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 12:52       ` Haggai Eran
     [not found]         ` <54E5DC82.1090805-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 13:22           ` Matan Barak
     [not found]             ` <54E5E381.5000105-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 14:00               ` Or Gerlitz
2015-02-19 14:37       ` Haggai Eran
     [not found]         ` <54E5F51B.8020806-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 15:24           ` Matan Barak
     [not found]             ` <54E6001F.2080304-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-22  7:37               ` Haggai Eran
2015-02-19 15:03       ` Haggai Eran
     [not found]         ` <54E5FB57.1090803-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 15:31           ` Matan Barak
     [not found]             ` <54E601B6.5000705-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-22  7:41               ` Haggai Eran
2015-02-19 15:18       ` Haggai Eran
     [not found]         ` <54E5FEDD.2080001-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 15:37           ` Matan Barak
2015-02-23  5:25       ` Devesh Sharma
     [not found]         ` <de2ee483-0c24-4951-af76-87ab3499636a-3RiH6ntJJkP8BX6JNMqfyFjyZtpTMMwT@public.gmane.org>
2015-02-23 10:17           ` Matan Barak
     [not found]             ` <54EAFE26.1070202-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-23 10:32               ` Somnath Kotur
     [not found]                 ` <df21f330-cbe1-4fc9-8611-5d781f8656a2-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-23 11:03                   ` Matan Barak
2015-02-23 16:59               ` Devesh Sharma
     [not found]                 ` <61ca6b6c-4c5b-4f75-9fd1-c24d64a6223a-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-24  8:05                   ` Matan Barak
2015-02-19 22:02   ` [PATCH 10/30] IB/core: Add gid_type to path and rdma_id_private Somnath Kotur
     [not found]     ` <0ebef7be-0586-47bf-bcc4-f3ff21ca4f3b-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 15:51       ` Haggai Eran
     [not found]         ` <54E60695.3050907-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-02-19 15:53           ` Matan Barak
2015-02-19 22:02   ` [PATCH 11/30] IB/core: Add rdma_network_type to wc Somnath Kotur
2015-02-19 22:02   ` [PATCH 12/30] IB/cma: Add configfs for rdma_cm Somnath Kotur
2015-02-19 22:02   ` [PATCH 13/30] IB/Core: Changes to the IB Core infrastructure for RoCEv2 support Somnath Kotur
2015-02-19 22:02   ` [PATCH] RDMA/ocrdma: Changes in driver to incorporate the moving of GID Table mgmt to IB/Core Somnath Kotur
     [not found]     ` <192c6b78-c0e3-4ca5-aa83-4ce6e9eb46be-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19  9:01       ` Shachar Raindel
     [not found]         ` <AM3PR05MB093504D988CF6E2C0CF97A40DC2D0-LOZWmgKjnYgQouBfZGh8ttqRiQSDpxhJvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2015-02-19  9:05           ` Somnath Kotur
2015-02-19 22:02   ` [PATCH 15/30] RDMA/ocrdma: changes to support RoCE-v2 in UD path Somnath Kotur
     [not found]     ` <7d2d787d-b849-42af-a93f-32b13ec319ba-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-21 13:13       ` Devesh Sharma
2015-02-19 22:02   ` [PATCH 16/30] RDMA/ocrdma: changes to support RoCE-v2 in RC path Somnath Kotur
2015-02-19 22:02   ` [PATCH 17/30] RDMA/ocrdma: changes to support user AH creation Somnath Kotur
2015-02-19 22:02   ` [PATCH 18/30] IB/mlx4: Remove gid table management for RoCE Somnath Kotur
     [not found]     ` <250dc054-e0c4-40b4-8855-7315489c0f58-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-22 11:41       ` Or Gerlitz
2015-02-19 22:02   ` [PATCH 19/30] IB/mlx4: Replace spin_lock with rw_semaphore Somnath Kotur
2015-02-19 22:02   ` [PATCH 20/30] IB/mlx4: Lock with RCU instead of RTNL Somnath Kotur
2015-02-19 22:02   ` [PATCH 21/30] net/mlx4: Postpone the registration of net_device Somnath Kotur
2015-02-19 22:02   ` [PATCH 22/30] IB/mlx4: Advertise RoCE support in port capabilities Somnath Kotur
2015-02-19 22:02   ` [PATCH 23/30] IB/mlx4: Implement ib_device callback - get_netdev Somnath Kotur
2015-02-19 22:02   ` [PATCH 24/30] IB/mlx4: Implement ib_device callback - modify_gid Somnath Kotur
2015-02-19 22:02   ` [PATCH 25/30] IB/mlx4: Configure device to work in RoCEv2 Somnath Kotur
2015-02-19 22:02   ` [PATCH 26/30] IB/mlx4: Translate cache gid index to real index Somnath Kotur
2015-02-19 22:02   ` [PATCH 27/30] IB/core: Initialize UD header structure with IP and UDP headers Somnath Kotur
2015-02-19 22:02   ` [PATCH 28/30] IB/mlx4: Enable send of RoCE QP1 packets with IP/UDP headers Somnath Kotur
2015-02-19 22:02   ` [PATCH 29/30] IB/mlx4: Create and use another QP1 for RoCEv2 Somnath Kotur
     [not found]     ` <7d3158cd-5b84-4f60-a705-71fca630e04a-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 16:11       ` Shachar Raindel
2015-02-19 22:02   ` [PATCH 30/30] IB/cma: Join and leave multicast groups with IGMP Somnath Kotur
     [not found]     ` <91da5137-4651-4991-852e-d57faeabe6a5-3RiH6ntJJkOPfaB/Gd0HpljyZtpTMMwT@public.gmane.org>
2015-02-19 13:56       ` Shachar Raindel
2015-02-19 10:16 [PATCH 02/30] IB/core: Add kref to IB devices Somnath Kotur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox