Whamcloud - gitweb
LU-12678 lnet: make "struct lnet_lnd" always "const". 32/36832/3
authorMr NeilBrown <neilb@suse.de>
Sun, 24 Nov 2019 23:00:50 +0000 (10:00 +1100)
committerOleg Drokin <green@whamcloud.com>
Thu, 23 Jan 2020 05:31:39 +0000 (05:31 +0000)
Every place where "struct lnet_lnd" appears, "const" is
added in front. Now all those structs can be in read-only
memory which is generally more secure.

Linux-commit 07499855083e ("lnet: make "struct lnet_lnd"
                            always "const".")

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I54a73d5b12de8c6b9a98182577c3c30d05c00222
Reviewed-on: https://review.whamcloud.com/36832
Reviewed-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Reviewed-by: Chris Horn <hornc@cray.com>
Reviewed-by: Amir Shehata <ashehata@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/lnet/lib-lnet.h
lnet/include/lnet/lib-types.h
lnet/klnds/gnilnd/gnilnd.c
lnet/klnds/o2iblnd/o2iblnd.c
lnet/klnds/socklnd/socklnd.c
lnet/lnet/api-ni.c
lnet/lnet/lo.c

index 413813a..75387fb 100644 (file)
@@ -544,7 +544,7 @@ lnet_net2rnethash(__u32 net)
                ((1U << the_lnet.ln_remote_nets_hbits) - 1)];
 }
 
-extern struct lnet_lnd the_lolnd;
+extern const struct lnet_lnd the_lolnd;
 extern int avoid_asym_router_failure;
 
 extern unsigned int lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number);
@@ -832,8 +832,8 @@ struct page *lnet_kvaddr_to_page(unsigned long vaddr);
 int lnet_cpt_of_md(struct lnet_libmd *md, unsigned int offset);
 
 unsigned int lnet_get_lnd_timeout(void);
-void lnet_register_lnd(struct lnet_lnd *lnd);
-void lnet_unregister_lnd(struct lnet_lnd *lnd);
+void lnet_register_lnd(const struct lnet_lnd *lnd);
+void lnet_unregister_lnd(const struct lnet_lnd *lnd);
 
 int lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
                 __u32 local_ip, __u32 peer_ip, int peer_port, struct net *ns);
index 703251e..c5d6b2b 100644 (file)
@@ -399,7 +399,7 @@ struct lnet_net {
        bool                    net_tunables_set;
 
        /* procedural interface */
-       struct lnet_lnd         *net_lnd;
+       const struct lnet_lnd   *net_lnd;
 
        /* list of NIs on this net */
        struct list_head        net_ni_list;
@@ -1110,7 +1110,7 @@ struct lnet {
        /* uniquely identifies this ni in this epoch */
        __u64                           ln_interface_cookie;
        /* registered LNDs */
-       struct lnet_lnd                 *ln_lnds[NUM_LNDS];
+       const struct lnet_lnd           *ln_lnds[NUM_LNDS];
 
        /* test protocol compatibility flags */
        int                             ln_testprotocompat;
index 90ee025..a197c99 100644 (file)
@@ -25,7 +25,7 @@
 #include "gnilnd.h"
 
 /* Primary entry points from LNET.  There are no guarantees against reentrance. */
-struct lnet_lnd the_kgnilnd = {
+const struct lnet_lnd the_kgnilnd = {
        .lnd_type       = GNILND,
        .lnd_startup    = kgnilnd_startup,
        .lnd_shutdown   = kgnilnd_shutdown,
index 3437f30..f2966d7 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "o2iblnd.h"
 
-static struct lnet_lnd the_o2iblnd;
+static const struct lnet_lnd the_o2iblnd;
 
 struct kib_data kiblnd_data;
 
@@ -3354,7 +3354,7 @@ failed:
        return -ENETDOWN;
 }
 
-static struct lnet_lnd the_o2iblnd = {
+static const struct lnet_lnd the_o2iblnd = {
        .lnd_type       = O2IBLND,
        .lnd_startup    = kiblnd_startup,
        .lnd_shutdown   = kiblnd_shutdown,
index 2393e01..a9907c5 100644 (file)
@@ -40,7 +40,7 @@
 #include "socklnd.h"
 #include <linux/inetdevice.h>
 
-static struct lnet_lnd the_ksocklnd;
+static const struct lnet_lnd the_ksocklnd;
 struct ksock_nal_data ksocknal_data;
 
 static struct ksock_interface *
@@ -2797,7 +2797,7 @@ static void __exit ksocklnd_exit(void)
        lnet_unregister_lnd(&the_ksocklnd);
 }
 
-static struct lnet_lnd the_ksocklnd = {
+static const struct lnet_lnd the_ksocklnd = {
        .lnd_type               = SOCKLND,
        .lnd_startup            = ksocknal_startup,
        .lnd_shutdown           = ksocknal_shutdown,
index d298f46..2ccbecc 100644 (file)
@@ -800,9 +800,9 @@ static void lnet_assert_wire_constants(void)
        BUILD_BUG_ON((int)sizeof(((struct lnet_ping_info *)0)->pi_ni) != 0);
 }
 
-static struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
+static const struct lnet_lnd *lnet_find_lnd_by_type(__u32 type)
 {
-       struct lnet_lnd *lnd;
+       const struct lnet_lnd *lnd;
 
        /* holding lnd mutex */
        if (type >= NUM_LNDS)
@@ -821,7 +821,7 @@ lnet_get_lnd_timeout(void)
 EXPORT_SYMBOL(lnet_get_lnd_timeout);
 
 void
-lnet_register_lnd(struct lnet_lnd *lnd)
+lnet_register_lnd(const struct lnet_lnd *lnd)
 {
        mutex_lock(&the_lnet.ln_lnd_mutex);
 
@@ -837,7 +837,7 @@ lnet_register_lnd(struct lnet_lnd *lnd)
 EXPORT_SYMBOL(lnet_register_lnd);
 
 void
-lnet_unregister_lnd(struct lnet_lnd *lnd)
+lnet_unregister_lnd(const struct lnet_lnd *lnd)
 {
        mutex_lock(&the_lnet.ln_lnd_mutex);
 
@@ -2274,7 +2274,7 @@ lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
        int                     rc;
        int                     ni_count = 0;
        __u32                   lnd_type;
-       struct lnet_lnd *lnd;
+       const struct lnet_lnd  *lnd;
        int                     peer_timeout =
                net->net_tunables.lct_peer_timeout;
        int                     maxtxcredits =
index 4f0ec8b..6b881fc 100644 (file)
@@ -103,7 +103,7 @@ lolnd_startup(struct lnet_ni *ni)
        return (0);
 }
 
-struct lnet_lnd the_lolnd = {
+const struct lnet_lnd the_lolnd = {
        .lnd_type       = LOLND,
        .lnd_startup    = lolnd_startup,
        .lnd_shutdown   = lolnd_shutdown,