From: Wengang Wang Date: Fri, 31 Oct 2014 02:58:07 +0000 (+0800) Subject: RDS: add module parameter to allow module unload or not X-Git-Tag: v4.1.12-92~293^2^2~21 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=72ca48ed813be68ae3ea96fa0a292adada386a03;p=users%2Fjedix%2Flinux-maple.git RDS: add module parameter to allow module unload or not orabug: 19665303 This patch adds the following feature to ib_ipoib, rds_rdma, ib_core and mlx4_core. Adds a module parameter "module_unload_allowed". If the parameter is 1(the default value), moudles can be unloaded(same behavior as before); other- wise if it's 0, the module is not allowed to be unloaded. The paramter can't be changed when module is loaded until the module is unloaded(if it can be). default values: ib_ipoib: 1 for YES rds_rdma: 0 for NO ib_core: 1 for YES mlx4_core: 0 for NO Signed-off-by: Wengang Wang Acked-by: Joe Jin Acked-by: Todd Vierling Acked-by: Yuval Shaia Signed-off-by: Guangyu Sun (cherry picked from commit cf1a00039e6fea116e9ea7c82f55ee3ee5319cec) Conflicts: drivers/infiniband/core/device.c drivers/infiniband/ulp/ipoib/ipoib_main.c drivers/net/ethernet/mellanox/mlx4/main.c --- diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 18c1ece765f2..928e31f40f87 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -46,6 +46,11 @@ MODULE_AUTHOR("Roland Dreier"); MODULE_DESCRIPTION("core kernel InfiniBand API"); MODULE_LICENSE("Dual BSD/GPL"); +int unload_allowed __read_mostly = 1; + +module_param_named(module_unload_allowed, unload_allowed, int, 0444); +MODULE_PARM_DESC(module_unload_allowed, "Allow this module to be unloaded or not (default 1 for YES)"); + struct ib_client_data { struct list_head list; struct ib_client *client; @@ -733,6 +738,8 @@ int ib_find_pkey(struct ib_device *device, } EXPORT_SYMBOL(ib_find_pkey); +#define MODULE_NAME "ib_core" + static int __init ib_core_init(void) { int ret; @@ -759,6 +766,12 @@ static int __init ib_core_init(void) goto err_nl; } + if (!unload_allowed) { + printk(KERN_NOTICE "Module %s locked in memory until next boot\n", + MODULE_NAME); + __module_get(THIS_MODULE); + } + return 0; err_nl: diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c index 9e1b203d756d..798e4922e575 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -60,6 +60,10 @@ MODULE_VERSION(DRV_VERSION); int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE; int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE; +int unload_allowed __read_mostly = 1; + +module_param_named(module_unload_allowed, unload_allowed, int, 0444); +MODULE_PARM_DESC(module_unload_allowed, "Allow this module to be unloaded or not (default 1 for YES)"); module_param_named(send_queue_size, ipoib_sendq_size, int, 0444); MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue"); @@ -1748,6 +1752,8 @@ static void ipoib_remove_one(struct ib_device *device) kfree(dev_list); } +#define MODULE_NAME "ib_ipoib" + static int __init ipoib_init_module(void) { int ret; @@ -1799,6 +1805,12 @@ static int __init ipoib_init_module(void) if (ret) goto err_client; + if (!unload_allowed) { + printk(KERN_NOTICE "Module %s locked in memory until next boot\n", + MODULE_NAME); + __module_get(THIS_MODULE); + } + return 0; err_client: diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index ced5ecab5aa7..d9b70138bef6 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -65,6 +65,10 @@ MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); #endif /* CONFIG_MLX4_DEBUG */ +int unload_allowed __read_mostly; +module_param_named(module_unload_allowed, unload_allowed, int, 0444); +MODULE_PARM_DESC(module_unload_allowed, "Allow this module to be unloaded or not (default 0 for NO)"); + #ifdef CONFIG_PCI_MSI static int msi_x = 1; @@ -3720,6 +3724,8 @@ static int __init mlx4_verify_params(void) return 0; } +#define MODULE_NAME "mlx4_core" + static int __init mlx4_init(void) { int ret; @@ -3733,6 +3739,11 @@ static int __init mlx4_init(void) return -ENOMEM; ret = pci_register_driver(&mlx4_driver); + if (!ret && !unload_allowed) { + printk(KERN_NOTICE "Module %s locked in memory until next boot\n", + MODULE_NAME); + __module_get(THIS_MODULE); + } if (ret < 0) destroy_workqueue(mlx4_wq); return ret < 0 ? ret : 0; diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index 00d88a5696df..7e3fc7526c50 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c @@ -45,6 +45,11 @@ static struct rdma_cm_id *rds_iw_listen_id; +int unload_allowed __read_mostly; + +module_param_named(module_unload_allowed, unload_allowed, int, 0444); +MODULE_PARM_DESC(module_unload_allowed, "Allow this module to be unloaded or not (default 0 for NO)"); + int rds_rdma_resolve_to_ms[] = {1000, 1000, 2000, 4000, 5000}; int rds_rdma_cm_event_handler(struct rdma_cm_id *cm_id, @@ -337,6 +342,8 @@ static void rds_rdma_listen_stop(void) } } +#define MODULE_NAME "rds_rdma" + int rds_rdma_init(void) { int ret; @@ -353,6 +360,12 @@ int rds_rdma_init(void) if (ret) goto err_ib_init; + if (!unload_allowed) { + printk(KERN_NOTICE "Module %s locked in memory until next boot\n", + MODULE_NAME); + __module_get(THIS_MODULE); + } + goto out; err_ib_init: