Skip to content

Commit

Permalink
module: icp: remove unused me_mutex
Browse files Browse the repository at this point in the history
It only needs to be locked if dynamic changes can occur. They can't.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#12901
  • Loading branch information
nabijaczleweli authored and andrewc12 committed Sep 23, 2022
1 parent 437c460 commit 0c7af52
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 24 deletions.
3 changes: 0 additions & 3 deletions module/icp/core/kcf_callprov.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ kcf_get_mech_provider(crypto_mech_type_t mech_type, kcf_mech_entry_t **mepp,
if (mepp != NULL)
*mepp = me;

mutex_enter(&me->me_mutex);

/* Is there a provider? */
if (pd == NULL && (mdesc = me->me_sw_prov) != NULL) {
pd = mdesc->pm_prov_desc;
Expand All @@ -130,6 +128,5 @@ kcf_get_mech_provider(crypto_mech_type_t mech_type, kcf_mech_entry_t **mepp,
} else
KCF_PROV_REFHOLD(pd);

mutex_exit(&me->me_mutex);
return (pd);
}
12 changes: 0 additions & 12 deletions module/icp/core/kcf_mech_tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ kcf_destroy_mech_tabs(void)
for (class = KCF_FIRST_OPSCLASS; class <= KCF_LAST_OPSCLASS; class++) {
max = kcf_mech_tabs_tab[class].met_size;
me_tab = kcf_mech_tabs_tab[class].met_tab;
for (i = 0; i < max; i++)
mutex_destroy(&(me_tab[i].me_mutex));
}
}

Expand Down Expand Up @@ -176,8 +174,6 @@ kcf_init_mech_tabs(void)
int max = kcf_mech_tabs_tab[class].met_size;
me_tab = kcf_mech_tabs_tab[class].met_tab;
for (int i = 0; i < max; i++) {
mutex_init(&(me_tab[i].me_mutex), NULL,
MUTEX_DEFAULT, NULL);
if (me_tab[i].me_name[0] != 0) {
me_tab[i].me_mechid = KCF_MECHID(class, i);
(void) mod_hash_insert(kcf_mech_hash,
Expand Down Expand Up @@ -242,22 +238,19 @@ kcf_create_mech_entry(kcf_ops_class_t class, const char *mechname)
size = kcf_mech_tabs_tab[class].met_size;

while (i < size) {
mutex_enter(&(me_tab[i].me_mutex));
if (me_tab[i].me_name[0] == 0) {
/* Found an empty spot */
(void) strlcpy(me_tab[i].me_name, mechname,
CRYPTO_MAX_MECH_NAME);
me_tab[i].me_name[CRYPTO_MAX_MECH_NAME-1] = '\0';
me_tab[i].me_mechid = KCF_MECHID(class, i);

mutex_exit(&(me_tab[i].me_mutex));
/* Add the new mechanism to the hash table */
(void) mod_hash_insert(kcf_mech_hash,
(mod_hash_key_t)me_tab[i].me_name,
(mod_hash_val_t)&(me_tab[i].me_mechid));
break;
}
mutex_exit(&(me_tab[i].me_mutex));
i++;
}

Expand Down Expand Up @@ -353,7 +346,6 @@ kcf_add_mech_provider(short mech_indx,
* Add new kcf_prov_mech_desc at the front of HW providers
* chain.
*/
mutex_enter(&mech_entry->me_mutex);
if (mech_entry->me_sw_prov != NULL) {
/*
* There is already a provider for this mechanism.
Expand All @@ -377,7 +369,6 @@ kcf_add_mech_provider(short mech_indx,
*/
mech_entry->me_sw_prov = prov_mech;
}
mutex_exit(&mech_entry->me_mutex);

*pmdpp = prov_mech;

Expand Down Expand Up @@ -425,16 +416,13 @@ kcf_remove_mech_provider(const char *mech_name, kcf_provider_desc_t *prov_desc)
return;
}

mutex_enter(&mech_entry->me_mutex);
if (mech_entry->me_sw_prov == NULL ||
mech_entry->me_sw_prov->pm_prov_desc != prov_desc) {
/* not the provider for this mechanism */
mutex_exit(&mech_entry->me_mutex);
return;
}
prov_mech = mech_entry->me_sw_prov;
mech_entry->me_sw_prov = NULL;
mutex_exit(&mech_entry->me_mutex);

/* free entry */
KCF_PROV_REFRELE(prov_mech->pm_prov_desc);
Expand Down
9 changes: 1 addition & 8 deletions module/icp/core/kcf_prov_tabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,17 @@ kcf_get_sw_prov(crypto_mech_type_t mech_type, kcf_provider_desc_t **pd,
if (kcf_get_mech_entry(mech_type, &me) != KCF_SUCCESS)
return (CRYPTO_MECHANISM_INVALID);

/*
* Get the provider for this mechanism.
* Lock the mech_entry until we grab the 'pd'.
*/
mutex_enter(&me->me_mutex);

/* Get the provider for this mechanism. */
if (me->me_sw_prov == NULL ||
(*pd = me->me_sw_prov->pm_prov_desc) == NULL) {
/* no provider for this mechanism */
if (log_warn)
cmn_err(CE_WARN, "no provider for \"%s\"\n",
me->me_name);
mutex_exit(&me->me_mutex);
return (CRYPTO_MECH_NOT_SUPPORTED);
}

KCF_PROV_REFHOLD(*pd);
mutex_exit(&me->me_mutex);

if (mep != NULL)
*mep = me;
Expand Down
1 change: 0 additions & 1 deletion module/icp/include/sys/crypto/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ typedef struct kcf_prov_mech_desc {
typedef struct kcf_mech_entry {
crypto_mech_name_t me_name; /* mechanism name */
crypto_mech_type_t me_mechid; /* Internal id for mechanism */
kmutex_t me_mutex; /* access protection */
kcf_prov_mech_desc_t *me_sw_prov; /* provider */
} kcf_mech_entry_t;

Expand Down

0 comments on commit 0c7af52

Please sign in to comment.