Skip to content

Commit e3bf14b

Browse files
jgunthorpedledford
authored andcommitted
rdma: Autoload netlink client modules
If a message comes in and we do not have the client in the table, then try to load the module supplying that client using MODULE_ALIAS to find it. This duplicates the scheme seen in other netlink muxes (eg nfnetlink). Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 1eb5be0 commit e3bf14b

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

drivers/infiniband/core/cma.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,5 +4537,7 @@ static void __exit cma_cleanup(void)
45374537
destroy_workqueue(cma_wq);
45384538
}
45394539

4540+
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_RDMA_CM, 1);
4541+
45404542
module_init(cma_init);
45414543
module_exit(cma_cleanup);

drivers/infiniband/core/device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,5 +1252,7 @@ static void __exit ib_core_cleanup(void)
12521252
destroy_workqueue(ib_wq);
12531253
}
12541254

1255+
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4);
1256+
12551257
module_init(ib_core_init);
12561258
module_exit(ib_core_cleanup);

drivers/infiniband/core/iwcm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,5 +1200,7 @@ static void __exit iw_cm_cleanup(void)
12001200
iwpm_exit(RDMA_NL_IWCM);
12011201
}
12021202

1203+
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_IWCM, 2);
1204+
12031205
module_init(iw_cm_init);
12041206
module_exit(iw_cm_cleanup);

drivers/infiniband/core/netlink.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ static bool is_nl_valid(unsigned int type, unsigned int op)
8484
return false;
8585

8686
cb_table = rdma_nl_types[type].cb_table;
87+
#ifdef CONFIG_MODULES
88+
if (!cb_table) {
89+
mutex_unlock(&rdma_nl_mutex);
90+
request_module("rdma-netlink-subsys-%d", type);
91+
mutex_lock(&rdma_nl_mutex);
92+
cb_table = rdma_nl_types[type].cb_table;
93+
}
94+
#endif
95+
8796
if (!cb_table || (!cb_table[op].dump && !cb_table[op].doit))
8897
return false;
8998
return true;

drivers/infiniband/core/nldev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33+
#include <linux/module.h>
3334
#include <net/netlink.h>
3435
#include <rdma/rdma_netlink.h>
3536

@@ -320,3 +321,5 @@ void __exit nldev_exit(void)
320321
{
321322
rdma_nl_unregister(RDMA_NL_NLDEV);
322323
}
324+
325+
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_NLDEV, 5);

include/rdma/rdma_netlink.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ enum rdma_nl_flags {
1717
RDMA_NL_ADMIN_PERM = 1 << 0,
1818
};
1919

20+
/* Define this module as providing netlink services for NETLINK_RDMA, with
21+
* index _index. Since the client indexes were setup in a uapi header as an
22+
* enum and we do no want to change that, the user must supply the expanded
23+
* constant as well and the compiler checks they are the same.
24+
*/
25+
#define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \
26+
static inline void __chk_##_index(void) \
27+
{ \
28+
BUILD_BUG_ON(_index != _val); \
29+
} \
30+
MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
31+
2032
/**
2133
* Register client in RDMA netlink.
2234
* @index: Index of the added client

0 commit comments

Comments
 (0)