From patchwork Thu Feb 27 21:17:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B941924 for ; Thu, 27 Feb 2020 21:45:53 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 341D724690 for ; Thu, 27 Feb 2020 21:45:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 341D724690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id E63A434B0E8; Thu, 27 Feb 2020 13:36:29 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id E00B83489A1 for ; Thu, 27 Feb 2020 13:21:17 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id 0D5C991DA; Thu, 27 Feb 2020 16:18:20 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 0C2F646D; Thu, 27 Feb 2020 16:18:20 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:17:23 -0500 Message-Id: <1582838290-17243-576-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 575/622] lnet: prepare to make lnet_lnd const. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Mr NeilBrown Preferred practice is for structs containing function pointers to be 'const'. Such structs are generally tempting attack vectors, and making them const allows linux to place them in read-only memory, thus reducing the attack surface. 'struct lnet_lnd' is mostly function pointers, but contains one writable field - a list_head. Rather than keeping registered lnds in a linked-list, we can place them in an array indexed by type - type numbers are at most 15 so this is not a burden. With these changes, no part of an lnet_lnd is ever modified. WC-bug-id: https://jira.whamcloud.com/browse/LU-12678 Lustre-commit: 87a6bd0766da ("LU-12678 lnet: prepare to make lnet_lnd const.") Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/36830 Reviewed-by: James Simmons Reviewed-by: Serguei Smirnov Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- include/linux/lnet/lib-types.h | 6 ++---- include/uapi/linux/lnet/nidstr.h | 2 ++ net/lnet/lnet/api-ni.c | 29 +++++++++++++++-------------- net/lnet/lnet/lo.c | 1 - 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/linux/lnet/lib-types.h b/include/linux/lnet/lib-types.h index 02ac5df..99ed87a 100644 --- a/include/linux/lnet/lib-types.h +++ b/include/linux/lnet/lib-types.h @@ -46,6 +46,7 @@ #include #include #include +#include /* Max payload size */ #define LNET_MAX_PAYLOAD LNET_MTU @@ -244,9 +245,6 @@ struct lnet_test_peer { struct lnet_ni; /* forward ref */ struct lnet_lnd { - /* fields managed by portals */ - struct list_head lnd_list; /* stash in the LND table */ - /* fields initialised by the LND */ u32 lnd_type; @@ -1133,7 +1131,7 @@ struct lnet { /* uniquely identifies this ni in this epoch */ u64 ln_interface_cookie; /* registered LNDs */ - struct list_head ln_lnds; + struct lnet_lnd *ln_lnds[NUM_LNDS]; /* test protocol compatibility flags */ int ln_testprotocompat; diff --git a/include/uapi/linux/lnet/nidstr.h b/include/uapi/linux/lnet/nidstr.h index 43ec232..958ca8d 100644 --- a/include/uapi/linux/lnet/nidstr.h +++ b/include/uapi/linux/lnet/nidstr.h @@ -53,6 +53,8 @@ enum { /*MXLND = 12, removed v2_7_50_0-34-g8be9e41 */ GNILND = 13, GNIIPLND = 14, + + NUM_LNDS }; struct list_head; diff --git a/net/lnet/lnet/api-ni.c b/net/lnet/lnet/api-ni.c index 0020ffd..cd95bdd 100644 --- a/net/lnet/lnet/api-ni.c +++ b/net/lnet/lnet/api-ni.c @@ -734,12 +734,12 @@ static void lnet_assert_wire_constants(void) struct lnet_lnd *lnd; /* holding lnd mutex */ - list_for_each_entry(lnd, &the_lnet.ln_lnds, lnd_list) { - if (lnd->lnd_type == type) - return lnd; - } + if (type >= NUM_LNDS) + return NULL; + lnd = the_lnet.ln_lnds[type]; + LASSERT(!lnd || lnd->lnd_type == type); - return NULL; + return lnd; } unsigned int @@ -757,7 +757,7 @@ static void lnet_assert_wire_constants(void) LASSERT(libcfs_isknown_lnd(lnd->lnd_type)); LASSERT(!lnet_find_lnd_by_type(lnd->lnd_type)); - list_add_tail(&lnd->lnd_list, &the_lnet.ln_lnds); + the_lnet.ln_lnds[lnd->lnd_type] = lnd; CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type)); @@ -772,7 +772,7 @@ static void lnet_assert_wire_constants(void) LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd); - list_del(&lnd->lnd_list); + the_lnet.ln_lnds[lnd->lnd_type] = NULL; CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type)); mutex_unlock(&the_lnet.ln_lnd_mutex); @@ -2429,7 +2429,6 @@ int lnet_lib_init(void) } the_lnet.ln_refcount = 0; - INIT_LIST_HEAD(&the_lnet.ln_lnds); INIT_LIST_HEAD(&the_lnet.ln_net_zombie); INIT_LIST_HEAD(&the_lnet.ln_msg_resend); @@ -2459,16 +2458,18 @@ int lnet_lib_init(void) * * \pre lnet_lib_init() called with success. * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls. + * + * As this happens at module-unload, all lnds must already be unloaded, + * so they must already be unregistered. */ void lnet_lib_exit(void) { - struct lnet_lnd *lnd; - LASSERT(!the_lnet.ln_refcount); + int i; - while ((lnd = list_first_entry_or_null(&the_lnet.ln_lnds, - struct lnet_lnd, - lnd_list)) != NULL) - lnet_unregister_lnd(lnd); + LASSERT(!the_lnet.ln_refcount); + lnet_unregister_lnd(&the_lolnd); + for (i = 0; i < NUM_LNDS; i++) + LASSERT(!the_lnet.ln_lnds[i]); lnet_destroy_locks(); } diff --git a/net/lnet/lnet/lo.c b/net/lnet/lnet/lo.c index 350495f..c19a5b5 100644 --- a/net/lnet/lnet/lo.c +++ b/net/lnet/lnet/lo.c @@ -93,7 +93,6 @@ } struct lnet_lnd the_lolnd = { - .lnd_list = LIST_HEAD_INIT(the_lolnd.lnd_list), .lnd_type = LOLND, .lnd_startup = lolnd_startup, .lnd_shutdown = lolnd_shutdown,