Skip to contentSkip to conversation

crypto: algboss - Avoid spurious modprobe on LOADED

PATCH In review Herbert Xu 3 participants 6 messages Apr 7, 2020 – Apr 16, 2020

Subsystems (2)
lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

As it stands when any algorithm finishes testing a notification is generated which triggers an unnecessary modprobe because algboss returns NOTIFY_DONE instead of NOTIFY_OK (this denotes an event that is not handled properly).

This patch changes the return value in algboss so that we don't do an unnecessary modprobe.

crypto/algboss.c +1 -1
index 527b44d0af21..01feb8234053 100644
@@ -275,7 +275,7 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
 	case CRYPTO_MSG_ALG_REGISTER:
 		return cryptomgr_schedule_test(data);
 	case CRYPTO_MSG_ALG_LOADED:
-		break;
+		return NOTIFY_OK;
 	}
 
 	return NOTIFY_DONE;
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#1 lore raw
Quoted 9 lines · Herbert Xu

As it stands when any algorithm finishes testing a notification is generated which triggers an unnecessary modprobe because algboss returns NOTIFY_DONE instead of NOTIFY_OK (this denotes an event that is not handled properly).

This patch changes the return value in algboss so that we don't do an unnecessary modprobe.

Needs a Fixes tag?

Fixes dd8b083f9a5e ("crypto: api - Introduce notifier for new crypto algorithms")
Cc <[email protected]> # v4.20+
Quoted 6 lines
crypto/algboss.c +0 -0
index 527b44d0af21..01feb8234053 100644

crypto/algboss.c static int cryptomgr_notify(struct notifier_block *this, unsigned long msg, · line 281

Quoted 8 lines
crypto/algboss.c +1 -1
@@ -275,7 +275,7 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
 	case CRYPTO_MSG_ALG_REGISTER:
 		return cryptomgr_schedule_test(data);
 	case CRYPTO_MSG_ALG_LOADED:
-		break;
+		return NOTIFY_OK;
 	}
 
 	return NOTIFY_DONE;

It's hard to remember the difference between NOTIFY_OK and NOTIFY_DONE. Isn't it wrong to call request_module() in the first place for a message that "cryptomgr" doesn't care about? Wouldn't the following make more sense?:

crypto/algapi.c +1 -1
index 69605e21af92..849254d7e627 100644
@@ -403,7 +403,7 @@ static void crypto_wait_for_test(struct crypto_larval *larval)
 	err = wait_for_completion_killable(&larval->completion);
 	WARN_ON(err);
 	if (!err)
-		crypto_probing_notify(CRYPTO_MSG_ALG_LOADED, larval);
+		crypto_notify(CRYPTO_MSG_ALG_LOADED, larval);
 
 out:
 	crypto_larval_kill(&larval->alg);
author maintainer
#2 lore raw
Quoted 5 lines · Eric Biggers

Needs a Fixes tag?

Fixes dd8b083f9a5e ("crypto: api - Introduce notifier for new crypto algorithms")
Cc <[email protected]> # v4.20+

Ah thanks, I had thought this was an ancient bug and therefore the fixes wouldn't have been that useful. The fact that it is a recent introduction means that we definitely should have the tags.

Quoted 12 lines
Quoted 12 lines
crypto/algboss.c +1 -1
index 527b44d0af21..01feb8234053 100644
@@ -275,7 +275,7 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
 	case CRYPTO_MSG_ALG_REGISTER:
 		return cryptomgr_schedule_test(data);
 	case CRYPTO_MSG_ALG_LOADED:
-		break;
+		return NOTIFY_OK;
 	}
 
Quoted 5 lines

crypto/algboss.c static int cryptomgr_notify(struct notifier_block *this, unsigned long msg, · line 281

Quoted 1 line
crypto/algboss.c +0 -0
 	return NOTIFY_DONE;

It's hard to remember the difference between NOTIFY_OK and NOTIFY_DONE. Isn't it wrong to call request_module() in the first place for a message that "cryptomgr" doesn't care about? Wouldn't the following make more sense?:

Good point. Yes we can and should do that here. Can you post a patch for this please?

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw

PATCH v2 1/1 crypto: algapi - Avoid spurious modprobe on LOADED

From: Eric Biggers <[email protected]>

Currently after any algorithm is registered and tested, there's an unnecessary request_module("cryptomgr") even if it's already loaded. Also, CRYPTO_MSG_ALG_LOADED is sent twice, and thus if the algorithm is "crct10dif", lib/crc-t10dif.c replaces the tfm twice rather than once.

This occurs because CRYPTO_MSG_ALG_LOADED is sent using crypto_probing_notify(), which tries to load "cryptomgr" if the notification is not handled (NOTIFY_DONE). This doesn't make sense because "cryptomgr" doesn't handle this notification.

Fix this by using crypto_notify() instead of crypto_probing_notify().

Fixes dd8b083f9a5e ("crypto: api - Introduce notifier for new crypto algorithms")
Cc <[email protected]> # v4.20+
Cc Martin K. Petersen <[email protected]>
---
 crypto/algapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/algapi.c +1 -1
index 69605e21af92..849254d7e627 100644
@@ -403,7 +403,7 @@ static void crypto_wait_for_test(struct crypto_larval *larval)
 	err = wait_for_completion_killable(&larval->completion);
 	WARN_ON(err);
 	if (!err)
-		crypto_probing_notify(CRYPTO_MSG_ALG_LOADED, larval);
+		crypto_notify(CRYPTO_MSG_ALG_LOADED, larval);
 
 out:
 	crypto_larval_kill(&larval->alg);
Signature · 1 line
2.26.0
Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] crypto: algapi - Avoid spurious modprobe on LOADED

Eric,

Quoted 6 lines

Currently after any algorithm is registered and tested, there's an unnecessary request_module("cryptomgr") even if it's already loaded. Also, CRYPTO_MSG_ALG_LOADED is sent twice, and thus if the algorithm is "crct10dif", lib/crc-t10dif.c replaces the tfm twice rather than once.

Quoted 6 lines

This occurs because CRYPTO_MSG_ALG_LOADED is sent using crypto_probing_notify(), which tries to load "cryptomgr" if the notification is not handled (NOTIFY_DONE). This doesn't make sense because "cryptomgr" doesn't handle this notification.

Fix this by using crypto_notify() instead of crypto_probing_notify().

Looks good to me.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author maintainer
#5 lore raw

Re: [PATCH v2] crypto: algapi - Avoid spurious modprobe on LOADED

In reply to Eric Biggers
Quoted 14 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Currently after any algorithm is registered and tested, there's an unnecessary request_module("cryptomgr") even if it's already loaded. Also, CRYPTO_MSG_ALG_LOADED is sent twice, and thus if the algorithm is "crct10dif", lib/crc-t10dif.c replaces the tfm twice rather than once.

This occurs because CRYPTO_MSG_ALG_LOADED is sent using crypto_probing_notify(), which tries to load "cryptomgr" if the notification is not handled (NOTIFY_DONE). This doesn't make sense because "cryptomgr" doesn't handle this notification.

Fix this by using crypto_notify() instead of crypto_probing_notify().

Quoted 8 lines
Fixes dd8b083f9a5e ("crypto: api - Introduce notifier for new crypto algorithms")
Cc <[email protected]> # v4.20+
Cc Martin K. Petersen <[email protected]>
---
 crypto/algapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt