From d59a7fae403f8d91b3512a559ec89432c87051a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 23 Dec 2021 03:22:27 +0100 Subject: [PATCH] module: icp: have a static 8 providers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is currently twice the amount we actually have (sha[12], skein, aes), and 512 * sizeof(void*) = 4096: 128x more than we need and a waste of most of a page in the kernel address space Plus, there's no need to actually allocate it dynamically: it's always got a static size. Put it in .data Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12901 --- module/icp/core/kcf_prov_tabs.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/module/icp/core/kcf_prov_tabs.c b/module/icp/core/kcf_prov_tabs.c index 482bd267c..79ddbec66 100644 --- a/module/icp/core/kcf_prov_tabs.c +++ b/module/icp/core/kcf_prov_tabs.c @@ -45,7 +45,7 @@ #include #include -#define KCF_MAX_PROVIDERS 512 /* max number of providers */ +#define KCF_MAX_PROVIDERS 8 /* max number of providers */ /* * Prov_tab is an array of providers which is updated when @@ -59,33 +59,25 @@ * * prov_tab entries are not updated from kcf.conf or by cryptoadm(1M). */ -static kcf_provider_desc_t **prov_tab = NULL; +static kcf_provider_desc_t *prov_tab[KCF_MAX_PROVIDERS]; static kmutex_t prov_tab_mutex; /* ensure exclusive access to the table */ static uint_t prov_tab_num = 0; /* number of providers in table */ -static uint_t prov_tab_max = KCF_MAX_PROVIDERS; void kcf_prov_tab_destroy(void) { mutex_destroy(&prov_tab_mutex); - - if (prov_tab) - kmem_free(prov_tab, prov_tab_max * - sizeof (kcf_provider_desc_t *)); } /* * Initialize a mutex and the KCF providers table, prov_tab. - * The providers table is dynamically allocated with prov_tab_max entries. + * The providers table is dynamically allocated with KCF_MAX_PROVIDERS entries. * Called from kcf module _init(). */ void kcf_prov_tab_init(void) { mutex_init(&prov_tab_mutex, NULL, MUTEX_DEFAULT, NULL); - - prov_tab = kmem_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *), - KM_SLEEP); } /* @@ -101,8 +93,6 @@ kcf_prov_tab_add_provider(kcf_provider_desc_t *prov_desc) { uint_t i; - ASSERT(prov_tab != NULL); - mutex_enter(&prov_tab_mutex); /* find free slot in providers table */ @@ -146,7 +136,6 @@ kcf_prov_tab_rem_provider(crypto_provider_id_t prov_id) { kcf_provider_desc_t *prov_desc; - ASSERT(prov_tab != NULL); ASSERT(prov_tab_num >= 0); /*