All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime.
@ 2016-04-29 10:07 Richard W.M. Jones
  2016-04-29 10:07 ` Richard W.M. Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Richard W.M. Jones @ 2016-04-29 10:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: corbet, herbert, davem, linux-doc, linux-crypto

I'm trying to reduce the time taken in the kernel in initcalls, with
my aim being to reduce the current ~700ms spent in initcalls before
userspace, down to something like 100ms.  All times on my Broadwell-U
laptop, under virtualization.  The purpose of this is to be able to
launch VMs around containers with minimal overhead, like Intel Clear
Containers, but using standard distro kernels and qemu.

Currently the kernel spends 28ms (on my laptop) running crypto
algorithm self-tests.  Although it's possibe to disable these at
compile time, Fedora kernel maintainers want to maintain a single
kernel image for all uses.

So this commit adds a runtime flag which callers can set to skip the
self-tests in the fast container/virtualization case.

Rich.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime.
  2016-04-29 10:07 [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime Richard W.M. Jones
@ 2016-04-29 10:07 ` Richard W.M. Jones
  2016-04-29 10:59   ` Stephan Mueller
  0 siblings, 1 reply; 4+ messages in thread
From: Richard W.M. Jones @ 2016-04-29 10:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: corbet, herbert, davem, linux-doc, linux-crypto

Running self-tests for a short-lived KVM VM takes 28ms on my laptop.
This commit adds a flag 'cryptomgr.notests' which allows them to be
disabled.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 Documentation/kernel-parameters.txt | 3 +++
 crypto/testmgr.c                    | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 0b3de80..d4d5fb7 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -826,6 +826,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			It will be ignored when crashkernel=X,high is not used
 			or memory reserved is below 4G.
 
+	cryptomgr.notests
+                        [KNL] Disable crypto self-tests
+
 	cs89x0_dma=	[HW,NET]
 			Format: <dma>
 
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index b86883a..dc613f2 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -35,6 +35,10 @@
 
 #include "internal.h"
 
+static bool notests;
+module_param(notests, bool, 0644);
+MODULE_PARM_DESC(notests, "disable crypto self-tests");
+
 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
 
 /* a perfect nop */
@@ -3868,6 +3872,11 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
 	int j;
 	int rc;
 
+	if (notests) {
+		pr_info("alg: self-tests disabled\n");
+		return 0;
+	}
+
 	alg_test_descs_check_order();
 
 	if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime.
  2016-04-29 10:07 ` Richard W.M. Jones
@ 2016-04-29 10:59   ` Stephan Mueller
  2016-04-29 11:04     ` Richard W.M. Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Stephan Mueller @ 2016-04-29 10:59 UTC (permalink / raw)
  To: Richard W.M. Jones
  Cc: linux-kernel, corbet, herbert, davem, linux-doc, linux-crypto

Am Freitag, 29. April 2016, 11:07:43 schrieb Richard W.M. Jones:

Hi Richard,

> Running self-tests for a short-lived KVM VM takes 28ms on my laptop.
> This commit adds a flag 'cryptomgr.notests' which allows them to be
> disabled.
> 
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
>  Documentation/kernel-parameters.txt | 3 +++
>  crypto/testmgr.c                    | 9 +++++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/Documentation/kernel-parameters.txt
> b/Documentation/kernel-parameters.txt index 0b3de80..d4d5fb7 100644
> --- a/Documentation/kernel-parameters.txt
> +++ b/Documentation/kernel-parameters.txt
> @@ -826,6 +826,9 @@ bytes respectively. Such letter suffixes can also be
> entirely omitted. It will be ignored when crashkernel=X,high is not used
>  			or memory reserved is below 4G.
> 
> +	cryptomgr.notests
> +                        [KNL] Disable crypto self-tests
> +
>  	cs89x0_dma=	[HW,NET]
>  			Format: <dma>
> 
> diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> index b86883a..dc613f2 100644
> --- a/crypto/testmgr.c
> +++ b/crypto/testmgr.c
> @@ -35,6 +35,10 @@
> 
>  #include "internal.h"
> 
> +static bool notests;
> +module_param(notests, bool, 0644);
> +MODULE_PARM_DESC(notests, "disable crypto self-tests");
> +
>  #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
> 
>  /* a perfect nop */
> @@ -3868,6 +3872,11 @@ int alg_test(const char *driver, const char *alg, u32
> type, u32 mask) int j;
>  	int rc;
> 
> +	if (notests) {

What about if (!fips_enabled && notests) ?

I am not sure whether the kernel should prevent mistakes in user space. A 
mistake would be when setting fips=1 and notests=1 as the FIPS mode mandates 
the self tests.

> +		pr_info("alg: self-tests disabled\n");
> +		return 0;
> +	}
> +
>  	alg_test_descs_check_order();
> 
>  	if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {


Ciao
Stephan
-- 
| Nimm das Recht weg -                                             |
|  was ist dann der Staat noch anderes als eine große Räuberbande? |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime.
  2016-04-29 10:59   ` Stephan Mueller
@ 2016-04-29 11:04     ` Richard W.M. Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2016-04-29 11:04 UTC (permalink / raw)
  To: Stephan Mueller
  Cc: linux-kernel, corbet, herbert, davem, linux-doc, linux-crypto

On Fri, Apr 29, 2016 at 12:59:57PM +0200, Stephan Mueller wrote:
> Am Freitag, 29. April 2016, 11:07:43 schrieb Richard W.M. Jones:
> 
> Hi Richard,
[...]
> > +	if (notests) {
> 
> What about if (!fips_enabled && notests) ?
>
> I am not sure whether the kernel should prevent mistakes in user space. A 
> mistake would be when setting fips=1 and notests=1 as the FIPS mode mandates 
> the self tests.

(Sorry, I just posted v2 before I saw this message.)  I saw the FIPS
stuff and thought about that.  Should we prevent mistakes like that?
I really don't know.

Rich.

> > +		pr_info("alg: self-tests disabled\n");
> > +		return 0;
> > +	}
> > +
> >  	alg_test_descs_check_order();
> > 
> >  	if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
> 
> 
> Ciao
> Stephan
> -- 
> | Nimm das Recht weg -                                             |
> |  was ist dann der Staat noch anderes als eine große Räuberbande? |

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-29 11:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-29 10:07 [PATCH] crypto: Add a flag allowing the self-tests to be disabled at runtime Richard W.M. Jones
2016-04-29 10:07 ` Richard W.M. Jones
2016-04-29 10:59   ` Stephan Mueller
2016-04-29 11:04     ` Richard W.M. Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.