2013-07-16 16:23:51

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to moduledependency.

On Tue, 2013-07-16 at 22:49 +0900, Tetsuo Handa wrote:
> Herbert Xu wrote:
> > Looks like a bug in whatever is creating the initrd as it isn't
> > including modules necessary for the boot.
>
> It turned out that it is already wrong as of creating modules.dep.
>
> # grep crc /lib/modules/3.11.0-rc1/modules.dep
> kernel/crypto/crct10dif.ko:
> kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
> kernel/lib/crc-t10dif.ko:
>
> modules.dep says
>
> (1) sd_mod.ko depends on crc-t10dif.ko
> (2) crc-t10dif.ko does not depend on crct10dif.ko

Yes, the generator of modules.dep does not seem to pick up the right
dependency.

>
> but commit 2d31e518 made crc-t10dif.ko depend on crct10dif.ko , didn't it?
>
> crct10dif.ko need to be loaded before crc-t10dif.ko is loaded, but doing
>
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 35da513..53ee0fd 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -68,6 +68,7 @@ config CRC_T10DIF
> tristate "CRC calculation for the T10 Data Integrity Field"
> select CRYPTO
> select CRYPTO_CRCT10DIF
> + depends on CRYPTO_CRCT10DIF

Herbert, seems like modules.dep generator wants explicit

- select CRYPTO_CRCT10DIF
+ depends on CRYPTO_CRCT10DIF

But it seems to me like it should have known CRC_T10DIF needs
CRYPTO_CRCT10DIF when we do
select CRYPTO_CRCT10DIF

Your thoughts?

Thanks.

Tim

> help
> This option is only needed if a module that's not in the
> kernel tree needs to calculate CRC checks for use with the
>
> causes below warning.
>
> crypto/Kconfig:379: symbol CRYPTO_CRCT10DIF is selected by CRC_T10DIF
> warning: (BLK_DEV_SD && SCSI_LPFC && SCSI_DEBUG) selects CRC_T10DIF which has unmet direct dependencies (CRYPTO_CRCT10DIF)


2013-07-17 11:52:39

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due tomoduledependency.

Tim Chen wrote:
> Herbert, seems like modules.dep generator wants explicit
>
> - select CRYPTO_CRCT10DIF
> + depends on CRYPTO_CRCT10DIF
>
> But it seems to me like it should have known CRC_T10DIF needs
> CRYPTO_CRCT10DIF when we do
> select CRYPTO_CRCT10DIF
>
> Your thoughts?

"select" cannot tell /sbin/depmod that there is dependency, for /sbin/depmod
calculates dependency by enumerating symbols in each module rather than by
parsing Kconfig files which depends on "kernel-source_files_installed = y".

Therefore, I think possible solutions are either

(a) built-in the dependent modules

# grep crc /lib/modules/3.11.0-rc1+/modules.dep
kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
kernel/lib/crc-t10dif.ko:

or

(b) embed explicit reference to the dependent module's symbols

# grep crc /lib/modules/3.11.0-rc1+/modules.dep
kernel/arch/x86/crypto/crct10dif-pclmul.ko: kernel/crypto/crct10dif.ko
kernel/crypto/crct10dif.ko:
kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko kernel/arch/x86/crypto/crct10dif-pclmul.ko kernel/crypto/crct10dif.ko
kernel/lib/crc-t10dif.ko: kernel/arch/x86/crypto/crct10dif-pclmul.ko kernel/crypto/crct10dif.ko

.

Two patches ((a) and (b) respectively) follow, but I think patch (b) will not
work unless additional change

static int __init crct10dif_intel_mod_init(void)
{
if (x86_match_cpu(crct10dif_cpu_id))
return crypto_register_shash(&alg);
return 0;
}

static void __exit crct10dif_intel_mod_fini(void)
{
if (x86_match_cpu(crct10dif_cpu_id))
crypto_unregister_shash(&alg);
}

is made, for currently crct10dif-pclmul.ko cannot be loaded on
!X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ) systems.

------------------------------------------------------------

>From d8d9b7c3e5be9c5a6198dac6fe7279ca904343a8 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Wed, 17 Jul 2013 19:45:19 +0900
Subject: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

Commit 2d31e518 "crypto: crct10dif - Wrap crc_t10dif function all to use crypto
transform framework" was added without telling that "crc-t10dif.ko depends on
crct10dif.ko". This resulted in boot failure because "sd_mod.ko depends on
crc-t10dif.ko" but "crct10dif.ko is not loaded automatically".

Fix this by changing crct10dif.ko and crct10dif-pclmul.ko from "tristate" to
"bool" so that suitable version is chosen.

Signed-off-by: Tetsuo Handa <[email protected]>
---
crypto/Kconfig | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 69ce573..dd3b79e 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -377,7 +377,7 @@ config CRYPTO_CRC32_PCLMUL
and gain better performance as compared with the table implementation.

config CRYPTO_CRCT10DIF
- tristate "CRCT10DIF algorithm"
+ bool "CRCT10DIF algorithm"
select CRYPTO_HASH
help
CRC T10 Data Integrity Field computation is being cast as
@@ -385,7 +385,7 @@ config CRYPTO_CRCT10DIF
transforms to be used if they are available.

config CRYPTO_CRCT10DIF_PCLMUL
- tristate "CRCT10DIF PCLMULQDQ hardware acceleration"
+ bool "CRCT10DIF PCLMULQDQ hardware acceleration"
depends on X86 && 64BIT && CRC_T10DIF
select CRYPTO_HASH
help
--
1.7.1

------------------------------------------------------------

>From 153e209fc9a7e1df42555829c396ee9ed53e83d0 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <[email protected]>
Date: Wed, 17 Jul 2013 20:23:15 +0900
Subject: [PATCH] [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

Commit 2d31e518 "crypto: crct10dif - Wrap crc_t10dif function all to use crypto
transform framework" was added without telling that "crc-t10dif.ko depends on
crct10dif.ko". This resulted in boot failure because "sd_mod.ko depends on
crc-t10dif.ko" but "crct10dif.ko is not loaded automatically".

Fix this by describing "crc-t10dif.ko depends on crct10dif.ko".

Signed-off-by: Tetsuo Handa <[email protected]>
---
arch/x86/crypto/crct10dif-pclmul_glue.c | 6 ++++++
lib/crc-t10dif.c | 7 +++++++
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
index 7845d7f..2964608 100644
--- a/arch/x86/crypto/crct10dif-pclmul_glue.c
+++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
@@ -149,3 +149,9 @@ MODULE_LICENSE("GPL");

MODULE_ALIAS("crct10dif");
MODULE_ALIAS("crct10dif-pclmul");
+
+/* Dummy for describing module dependency. */
+#if defined(CONFIG_CRYPTO_CRCT10DIF_PCLMUL_MODULE)
+const char crct10dif_pclmul;
+EXPORT_SYMBOL(crct10dif_pclmul);
+#endif
diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index fe3428c..376f795 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -38,6 +38,13 @@ EXPORT_SYMBOL(crc_t10dif);

static int __init crc_t10dif_mod_init(void)
{
+ /* Dummy for describing module dependency. */
+#if defined(CONFIG_CRYPTO_CRCT10DIF_PCLMUL_MODULE)
+ extern const char crct10dif_pclmul;
+ crc_t10dif_generic(crct10dif_pclmul, NULL, 0);
+#elif defined(CONFIG_CRYPTO_CRCT10DIF_MODULE)
+ crc_t10dif_generic(0, NULL, 0);
+#endif
crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
return PTR_RET(crct10dif_tfm);
}
--
1.7.1

------------------------------------------------------------

2013-07-17 16:46:36

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due tomoduledependency.

On Wed, 2013-07-17 at 20:52 +0900, Tetsuo Handa wrote:
> Tim Chen wrote:
> > Herbert, seems like modules.dep generator wants explicit
> >
> > - select CRYPTO_CRCT10DIF
> > + depends on CRYPTO_CRCT10DIF
> >
> > But it seems to me like it should have known CRC_T10DIF needs
> > CRYPTO_CRCT10DIF when we do
> > select CRYPTO_CRCT10DIF
> >
> > Your thoughts?
>
> "select" cannot tell /sbin/depmod that there is dependency, for /sbin/depmod
> calculates dependency by enumerating symbols in each module rather than by
> parsing Kconfig files which depends on "kernel-source_files_installed = y".
>
> Therefore, I think possible solutions are either
>
> (a) built-in the dependent modules
>
> # grep crc /lib/modules/3.11.0-rc1+/modules.dep
> kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
> kernel/lib/crc-t10dif.ko:

This approach will increase kernel size for those who are not using
t10dif so some people may object.
BTW, The PCLMULQDQ version does not need to be build in.

>
> or
>
> (b) embed explicit reference to the dependent module's symbols
>
> # grep crc /lib/modules/3.11.0-rc1+/modules.dep
> kernel/arch/x86/crypto/crct10dif-pclmul.ko: kernel/crypto/crct10dif.ko
> kernel/crypto/crct10dif.ko:
> kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko kernel/arch/x86/crypto/crct10dif-pclmul.ko kernel/crypto/crct10dif.ko
> kernel/lib/crc-t10dif.ko: kernel/arch/x86/crypto/crct10dif-pclmul.ko kernel/crypto/crct10dif.ko
>

Your approach is quite complicated. I think something simpler like the
following will work:

Signed-off-by: Tim Chen <[email protected]>
---
diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index fe3428c..27d6be3 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -15,7 +15,8 @@
#include <linux/init.h>
#include <crypto/hash.h>

-static struct crypto_shash *crct10dif_tfm;
+__u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len);
+static struct crypto_shash *crct10dif_tfm = crc_t10dif_generic;

__u16 crc_t10dif(const unsigned char *buffer, size_t len)
{



> .
>
> Two patches ((a) and (b) respectively) follow, but I think patch (b) will not
> work unless additional change
>
> static int __init crct10dif_intel_mod_init(void)
> {
> if (x86_match_cpu(crct10dif_cpu_id))
> return crypto_register_shash(&alg);
> return 0;
> }
>
> static void __exit crct10dif_intel_mod_fini(void)
> {
> if (x86_match_cpu(crct10dif_cpu_id))
> crypto_unregister_shash(&alg);
> }
>
> is made, for currently crct10dif-pclmul.ko cannot be loaded on
> !X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ) systems.

crct10dif-pclmul.ko should not be loaded if
X86_FEATURE_PCLMULQDQ is not supported.
The module needs the cpu to have support for PCLMULQDQ.

>
> ------------------------------------------------------------
>
> >From d8d9b7c3e5be9c5a6198dac6fe7279ca904343a8 Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <[email protected]>
> Date: Wed, 17 Jul 2013 19:45:19 +0900
> Subject: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.
>
> Commit 2d31e518 "crypto: crct10dif - Wrap crc_t10dif function all to use crypto
> transform framework" was added without telling that "crc-t10dif.ko depends on
> crct10dif.ko". This resulted in boot failure because "sd_mod.ko depends on
> crc-t10dif.ko" but "crct10dif.ko is not loaded automatically".
>
> Fix this by changing crct10dif.ko and crct10dif-pclmul.ko from "tristate" to
> "bool" so that suitable version is chosen.
>
> Signed-off-by: Tetsuo Handa <[email protected]>
> ---
> crypto/Kconfig | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 69ce573..dd3b79e 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -377,7 +377,7 @@ config CRYPTO_CRC32_PCLMUL
> and gain better performance as compared with the table implementation.
>
> config CRYPTO_CRCT10DIF
> - tristate "CRCT10DIF algorithm"
> + bool "CRCT10DIF algorithm"
> select CRYPTO_HASH
> help
> CRC T10 Data Integrity Field computation is being cast as
> @@ -385,7 +385,7 @@ config CRYPTO_CRCT10DIF
> transforms to be used if they are available.
>
> config CRYPTO_CRCT10DIF_PCLMUL
> - tristate "CRCT10DIF PCLMULQDQ hardware acceleration"
> + bool "CRCT10DIF PCLMULQDQ hardware acceleration"

This is not necessary. Keep it as tristate.

> depends on X86 && 64BIT && CRC_T10DIF
> select CRYPTO_HASH
> help
> --
> 1.7.1
>
> ------------------------------------------------------------
>
> >From 153e209fc9a7e1df42555829c396ee9ed53e83d0 Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <[email protected]>
> Date: Wed, 17 Jul 2013 20:23:15 +0900
> Subject: [PATCH] [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.
>
> Commit 2d31e518 "crypto: crct10dif - Wrap crc_t10dif function all to use crypto
> transform framework" was added without telling that "crc-t10dif.ko depends on
> crct10dif.ko". This resulted in boot failure because "sd_mod.ko depends on
> crc-t10dif.ko" but "crct10dif.ko is not loaded automatically".
>
> Fix this by describing "crc-t10dif.ko depends on crct10dif.ko".
>
> Signed-off-by: Tetsuo Handa <[email protected]>
> ---
> arch/x86/crypto/crct10dif-pclmul_glue.c | 6 ++++++
> lib/crc-t10dif.c | 7 +++++++
> 2 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
> index 7845d7f..2964608 100644
> --- a/arch/x86/crypto/crct10dif-pclmul_glue.c
> +++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
> @@ -149,3 +149,9 @@ MODULE_LICENSE("GPL");
>
> MODULE_ALIAS("crct10dif");
> MODULE_ALIAS("crct10dif-pclmul");
> +
> +/* Dummy for describing module dependency. */
> +#if defined(CONFIG_CRYPTO_CRCT10DIF_PCLMUL_MODULE)
> +const char crct10dif_pclmul;
> +EXPORT_SYMBOL(crct10dif_pclmul);
> +#endif
> diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
> index fe3428c..376f795 100644
> --- a/lib/crc-t10dif.c
> +++ b/lib/crc-t10dif.c
> @@ -38,6 +38,13 @@ EXPORT_SYMBOL(crc_t10dif);
>
> static int __init crc_t10dif_mod_init(void)
> {
> + /* Dummy for describing module dependency. */
> +#if defined(CONFIG_CRYPTO_CRCT10DIF_PCLMUL_MODULE)
> + extern const char crct10dif_pclmul;
> + crc_t10dif_generic(crct10dif_pclmul, NULL, 0);
> +#elif defined(CONFIG_CRYPTO_CRCT10DIF_MODULE)
> + crc_t10dif_generic(0, NULL, 0);
> +#endif
> crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
> return PTR_RET(crct10dif_tfm);
> }

2013-07-17 20:50:16

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure duetomoduledependency.

Tim Chen wrote:
> > Therefore, I think possible solutions are either
> >
> > (a) built-in the dependent modules
> >
> > # grep crc /lib/modules/3.11.0-rc1+/modules.dep
> > kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
> > kernel/lib/crc-t10dif.ko:
>
> This approach will increase kernel size for those who are not using
> t10dif so some people may object.
> BTW, The PCLMULQDQ version does not need to be build in.

sd_mod.ko must choose one from versions available as of loading sd_mod.ko.
Although it is not needed to built-in the PCLMULQDQ version for fixing the boot
failure, it is needed to built-in the PCLMULQDQ version for getting performance
improvement when PCLMULQDQ is supported.

> Your approach is quite complicated. I think something simpler like the
> following will work:

We cannot benefit from PCLMULQDQ. Is it acceptable for you?

2013-07-17 21:53:21

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure duetomoduledependency.

On Thu, 2013-07-18 at 05:50 +0900, Tetsuo Handa wrote:
> Tim Chen wrote:
> > > Therefore, I think possible solutions are either
> > >
> > > (a) built-in the dependent modules
> > >
> > > # grep crc /lib/modules/3.11.0-rc1+/modules.dep
> > > kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
> > > kernel/lib/crc-t10dif.ko:
> >
> > This approach will increase kernel size for those who are not using
> > t10dif so some people may object.
> > BTW, The PCLMULQDQ version does not need to be build in.
>
> sd_mod.ko must choose one from versions available as of loading sd_mod.ko.
> Although it is not needed to built-in the PCLMULQDQ version for fixing the boot
> failure, it is needed to built-in the PCLMULQDQ version for getting performance
> improvement when PCLMULQDQ is supported.
>
> > Your approach is quite complicated. I think something simpler like the
> > following will work:
>
> We cannot benefit from PCLMULQDQ. Is it acceptable for you?


The following code in crct10dif-pclmul_glue.c

static const struct x86_cpu_id crct10dif_cpu_id[] = {
X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
{}
};
MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);

will put the module in the device table and get the module
loaded, as long as the cpu support PCLMULQDQ. So we should be able
to benefit.

Tim

2013-07-17 22:08:54

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure duetomoduledependency.

On Thu, 2013-07-18 at 05:50 +0900, Tetsuo Handa wrote:
> Tim Chen wrote:
> > > Therefore, I think possible solutions are either
> > >
> > > (a) built-in the dependent modules
> > >
> > > # grep crc /lib/modules/3.11.0-rc1+/modules.dep
> > > kernel/drivers/scsi/sd_mod.ko: kernel/lib/crc-t10dif.ko
> > > kernel/lib/crc-t10dif.ko:
> >
> > This approach will increase kernel size for those who are not using
> > t10dif so some people may object.
> > BTW, The PCLMULQDQ version does not need to be build in.
>
> sd_mod.ko must choose one from versions available as of loading sd_mod.ko.
> Although it is not needed to built-in the PCLMULQDQ version for fixing the boot
> failure, it is needed to built-in the PCLMULQDQ version for getting performance
> improvement when PCLMULQDQ is supported.

The code in crct10dif transform allocation:

crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0)

will allocate a t10dif crypto transform with highest priority.
So as long as the crct10dif.ko and crct10dif-pclmul.ko are loaded,
the pclmulqdq t10dif will have a higher priority and get allocated
and used.

Thanks.

Tim

>
> > Your approach is quite complicated. I think something simpler like the
> > following will work:
>
> We cannot benefit from PCLMULQDQ. Is it acceptable for you?

2013-07-18 03:47:16

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

Tim Chen wrote:
> > > Your approach is quite complicated. I think something simpler like the
> > > following will work:
> >
> > We cannot benefit from PCLMULQDQ. Is it acceptable for you?
>
>
> The following code in crct10dif-pclmul_glue.c
>
> static const struct x86_cpu_id crct10dif_cpu_id[] = {
> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> {}
> };
> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
>
> will put the module in the device table and get the module
> loaded, as long as the cpu support PCLMULQDQ. So we should be able
> to benefit.

Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?

diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
index 7845d7f..a8a95aa 100644
--- a/arch/x86/crypto/crct10dif-pclmul_glue.c
+++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
@@ -129,9 +129,10 @@ MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);

static int __init crct10dif_intel_mod_init(void)
{
+ printk(KERN_WARNING "********** Checking for X86_FEATURE_PCLMULQDQ\n");
if (!x86_match_cpu(crct10dif_cpu_id))
return -ENODEV;
-
+ printk(KERN_WARNING "********** Registering crct10dif-pclmul\n");
return crypto_register_shash(&alg);
}

As far as I tested, crct10dif-pclmul.ko will not be loaded unless manually
adding "modprobe crct10dif-pclmul" to initramfs's /init or choosing
CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.

> So as long as the crct10dif.ko and crct10dif-pclmul.ko are loaded,
> the pclmulqdq t10dif will have a higher priority and get allocated
> and used.

What I'm talking are

(1) Since mkinitramfs is unable to know that crct10dif-pclmul.ko has higher
priority than crct10dif.ko , mkinitramfs will not include
"modprobe crct10dif-pclmul" line in the generated initramfs.

(2) In order to get benefit from PCLMULQDQ, users have to manually make sure
that "modprobe crct10dif-pclmul" is called before crc-t10dif.ko (which is
loaded before sd_mod.ko is loaded) is loaded by their initramfs's /init
script.

(3) The cause of (1) is that crct10dif-pclmul.ko will not be loaded
automatically unless choosing CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.

(4) The cause of (3) is that modules.dep does not describe that users will
benefit by loading crct10dif-pclmul.ko before loading crc-t10dif.ko .

(5) Currently crct10dif-pclmul.ko cannot be loaded if PCLMULQDQ is not
supported. This leads to boot failure (since sd_mod.ko cannot be loaded)
if modules.dep says that "crct10dif-pclmul.ko is required by
crc-t10dif.ko".

(6) To solve (4) and (5), modules.dep should say "crct10dif-pclmul.ko is
preferred for crc-t10dif.ko but is not required by crc-t10dif.ko".
But there is no such mechanism. Thus, currently available choice is
"allow loading crct10dif-pclmul.ko even if PCLMULQDQ is not supported"
or "ignore errors by built-in the crct10dif-pclmul.ko module".

My patch (b) seems to be complicated but is required in order to solve (4)
without asking users to manually add "modprobe crct10dif-pclmul" into their
initramfs. If we choose patch (b) rather than patch (a), we need to solve (5).

2013-07-18 20:59:58

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Thu, 2013-07-18 at 12:47 +0900, Tetsuo Handa wrote:
> Tim Chen wrote:
> > > > Your approach is quite complicated. I think something simpler like the
> > > > following will work:
> > >
> > > We cannot benefit from PCLMULQDQ. Is it acceptable for you?
> >
> >
> > The following code in crct10dif-pclmul_glue.c
> >
> > static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > {}
> > };
> > MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> >
> > will put the module in the device table and get the module
> > loaded, as long as the cpu support PCLMULQDQ. So we should be able
> > to benefit.
>
> Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
> Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?

The code:

static const struct x86_cpu_id crct10dif_cpu_id[] = {
X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
{}
};
MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);

causes the following line to be added to modules.alias file:

alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul

This should cause udev to load the crct10dif_pclml module when cpu
support the PCLMULQDQ (feature code 0081). I did my testing during
development on 3.10 and the module was indeed loaded.

However, I found that the following commit under 3.11-rc1 broke
the mechanism after some bisection.

commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
Author: Rafael J. Wysocki <[email protected]>
Date: Fri May 3 00:26:22 2013 +0200

ACPI / processor: Use common hotplug infrastructure

Split the ACPI processor driver into two parts, one that is
non-modular, resides in the ACPI core and handles the enumeration
and hotplug of processors and one that implements the rest of the
existing processor driver functionality.

Rafael, can you check and see if this can be fixed so those optimized
crypto modules for Intel cpu that support them can be loaded?

Herbert, we had a discussion earlier on a separate issue regarding the
module load order. We wanted to load all supported crypto t10dif modules
before the crc-t10dif module. You mentioned that the MODULE_ALIAS also
need some fixing and wonder if those changes have been merged into
3.11-rc1? See https://lkml.org/lkml/2013/5/21/216 . Theoretically, that
fix should also get all the crypto modules support t10dif be loaded.

Thanks.

Tim

>
> diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
> index 7845d7f..a8a95aa 100644
> --- a/arch/x86/crypto/crct10dif-pclmul_glue.c
> +++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
> @@ -129,9 +129,10 @@ MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
>
> static int __init crct10dif_intel_mod_init(void)
> {
> + printk(KERN_WARNING "********** Checking for X86_FEATURE_PCLMULQDQ\n");
> if (!x86_match_cpu(crct10dif_cpu_id))
> return -ENODEV;
> -
> + printk(KERN_WARNING "********** Registering crct10dif-pclmul\n");
> return crypto_register_shash(&alg);
> }
>
> As far as I tested, crct10dif-pclmul.ko will not be loaded unless manually
> adding "modprobe crct10dif-pclmul" to initramfs's /init or choosing
> CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.
>
> > So as long as the crct10dif.ko and crct10dif-pclmul.ko are loaded,
> > the pclmulqdq t10dif will have a higher priority and get allocated
> > and used.
>
> What I'm talking are
>
> (1) Since mkinitramfs is unable to know that crct10dif-pclmul.ko has higher
> priority than crct10dif.ko , mkinitramfs will not include
> "modprobe crct10dif-pclmul" line in the generated initramfs.
>
> (2) In order to get benefit from PCLMULQDQ, users have to manually make sure
> that "modprobe crct10dif-pclmul" is called before crc-t10dif.ko (which is
> loaded before sd_mod.ko is loaded) is loaded by their initramfs's /init
> script.
>
> (3) The cause of (1) is that crct10dif-pclmul.ko will not be loaded
> automatically unless choosing CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.
>
> (4) The cause of (3) is that modules.dep does not describe that users will
> benefit by loading crct10dif-pclmul.ko before loading crc-t10dif.ko .
>
> (5) Currently crct10dif-pclmul.ko cannot be loaded if PCLMULQDQ is not
> supported. This leads to boot failure (since sd_mod.ko cannot be loaded)
> if modules.dep says that "crct10dif-pclmul.ko is required by
> crc-t10dif.ko".
>
> (6) To solve (4) and (5), modules.dep should say "crct10dif-pclmul.ko is
> preferred for crc-t10dif.ko but is not required by crc-t10dif.ko".
> But there is no such mechanism. Thus, currently available choice is
> "allow loading crct10dif-pclmul.ko even if PCLMULQDQ is not supported"
> or "ignore errors by built-in the crct10dif-pclmul.ko module".
>
> My patch (b) seems to be complicated but is required in order to solve (4)
> without asking users to manually add "modprobe crct10dif-pclmul" into their
> initramfs. If we choose patch (b) rather than patch (a), we need to solve (5).
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2013-07-18 22:17:19

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On 7/18/2013 11:00 PM, Tim Chen wrote:
> On Thu, 2013-07-18 at 12:47 +0900, Tetsuo Handa wrote:
>> Tim Chen wrote:
>>>>> Your approach is quite complicated. I think something simpler like the
>>>>> following will work:
>>>> We cannot benefit from PCLMULQDQ. Is it acceptable for you?
>>>
>>> The following code in crct10dif-pclmul_glue.c
>>>
>>> static const struct x86_cpu_id crct10dif_cpu_id[] = {
>>> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
>>> {}
>>> };
>>> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
>>>
>>> will put the module in the device table and get the module
>>> loaded, as long as the cpu support PCLMULQDQ. So we should be able
>>> to benefit.
>> Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
>> Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?
> The code:
>
> static const struct x86_cpu_id crct10dif_cpu_id[] = {
> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> {}
> };
> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
>
> causes the following line to be added to modules.alias file:
>
> alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
>
> This should cause udev to load the crct10dif_pclml module when cpu
> support the PCLMULQDQ (feature code 0081). I did my testing during
> development on 3.10 and the module was indeed loaded.
>
> However, I found that the following commit under 3.11-rc1 broke
> the mechanism after some bisection.
>
> commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> Author: Rafael J. Wysocki <[email protected]>
> Date: Fri May 3 00:26:22 2013 +0200
>
> ACPI / processor: Use common hotplug infrastructure
>
> Split the ACPI processor driver into two parts, one that is
> non-modular, resides in the ACPI core and handles the enumeration
> and hotplug of processors and one that implements the rest of the
> existing processor driver functionality.
>
> Rafael, can you check and see if this can be fixed so those optimized
> crypto modules for Intel cpu that support them can be loaded?

I think this is an ordering issue between udev startup and the time when
devices are registered.

I wonder what happens if you put those modules into the initramfs image?

Rafael


> Herbert, we had a discussion earlier on a separate issue regarding the
> module load order. We wanted to load all supported crypto t10dif modules
> before the crc-t10dif module. You mentioned that the MODULE_ALIAS also
> need some fixing and wonder if those changes have been merged into
> 3.11-rc1? See https://lkml.org/lkml/2013/5/21/216 . Theoretically, that
> fix should also get all the crypto modules support t10dif be loaded.
>
> Thanks.
>
> Tim
>
>> diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
>> index 7845d7f..a8a95aa 100644
>> --- a/arch/x86/crypto/crct10dif-pclmul_glue.c
>> +++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
>> @@ -129,9 +129,10 @@ MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
>>
>> static int __init crct10dif_intel_mod_init(void)
>> {
>> + printk(KERN_WARNING "********** Checking for X86_FEATURE_PCLMULQDQ\n");
>> if (!x86_match_cpu(crct10dif_cpu_id))
>> return -ENODEV;
>> -
>> + printk(KERN_WARNING "********** Registering crct10dif-pclmul\n");
>> return crypto_register_shash(&alg);
>> }
>>
>> As far as I tested, crct10dif-pclmul.ko will not be loaded unless manually
>> adding "modprobe crct10dif-pclmul" to initramfs's /init or choosing
>> CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.
>>
>>> So as long as the crct10dif.ko and crct10dif-pclmul.ko are loaded,
>>> the pclmulqdq t10dif will have a higher priority and get allocated
>>> and used.
>> What I'm talking are
>>
>> (1) Since mkinitramfs is unable to know that crct10dif-pclmul.ko has higher
>> priority than crct10dif.ko , mkinitramfs will not include
>> "modprobe crct10dif-pclmul" line in the generated initramfs.
>>
>> (2) In order to get benefit from PCLMULQDQ, users have to manually make sure
>> that "modprobe crct10dif-pclmul" is called before crc-t10dif.ko (which is
>> loaded before sd_mod.ko is loaded) is loaded by their initramfs's /init
>> script.
>>
>> (3) The cause of (1) is that crct10dif-pclmul.ko will not be loaded
>> automatically unless choosing CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y.
>>
>> (4) The cause of (3) is that modules.dep does not describe that users will
>> benefit by loading crct10dif-pclmul.ko before loading crc-t10dif.ko .
>>
>> (5) Currently crct10dif-pclmul.ko cannot be loaded if PCLMULQDQ is not
>> supported. This leads to boot failure (since sd_mod.ko cannot be loaded)
>> if modules.dep says that "crct10dif-pclmul.ko is required by
>> crc-t10dif.ko".
>>
>> (6) To solve (4) and (5), modules.dep should say "crct10dif-pclmul.ko is
>> preferred for crc-t10dif.ko but is not required by crc-t10dif.ko".
>> But there is no such mechanism. Thus, currently available choice is
>> "allow loading crct10dif-pclmul.ko even if PCLMULQDQ is not supported"
>> or "ignore errors by built-in the crct10dif-pclmul.ko module".
>>
>> My patch (b) seems to be complicated but is required in order to solve (4)
>> without asking users to manually add "modprobe crct10dif-pclmul" into their
>> initramfs. If we choose patch (b) rather than patch (a), we need to solve (5).
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
z siedziba w Gdansku
ul. Slowackiego 173
80-298 Gdansk

Sad Rejonowy Gdansk Polnoc w Gdansku,
VII Wydzial Gospodarczy Krajowego Rejestru Sadowego,
numer KRS 101882

NIP 957-07-52-316
Kapital zakladowy 200.000 zl

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

2013-07-18 23:08:11

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, 2013-07-19 at 00:17 +0200, Rafael J. Wysocki wrote:
> On 7/18/2013 11:00 PM, Tim Chen wrote:
> > On Thu, 2013-07-18 at 12:47 +0900, Tetsuo Handa wrote:
> >> Tim Chen wrote:
> >>>>> Your approach is quite complicated. I think something simpler like the
> >>>>> following will work:
> >>>> We cannot benefit from PCLMULQDQ. Is it acceptable for you?
> >>>
> >>> The following code in crct10dif-pclmul_glue.c
> >>>
> >>> static const struct x86_cpu_id crct10dif_cpu_id[] = {
> >>> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> >>> {}
> >>> };
> >>> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> >>>
> >>> will put the module in the device table and get the module
> >>> loaded, as long as the cpu support PCLMULQDQ. So we should be able
> >>> to benefit.
> >> Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
> >> Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?
> > The code:
> >
> > static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > {}
> > };
> > MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> >
> > causes the following line to be added to modules.alias file:
> >
> > alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
> >
> > This should cause udev to load the crct10dif_pclml module when cpu
> > support the PCLMULQDQ (feature code 0081). I did my testing during
> > development on 3.10 and the module was indeed loaded.
> >
> > However, I found that the following commit under 3.11-rc1 broke
> > the mechanism after some bisection.
> >
> > commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> > Author: Rafael J. Wysocki <[email protected]>
> > Date: Fri May 3 00:26:22 2013 +0200
> >
> > ACPI / processor: Use common hotplug infrastructure
> >
> > Split the ACPI processor driver into two parts, one that is
> > non-modular, resides in the ACPI core and handles the enumeration
> > and hotplug of processors and one that implements the rest of the
> > existing processor driver functionality.
> >
> > Rafael, can you check and see if this can be fixed so those optimized
> > crypto modules for Intel cpu that support them can be loaded?
>
> I think this is an ordering issue between udev startup and the time when
> devices are registered.

Something that can be fixed?

>
> I wonder what happens if you put those modules into the initramfs image?

Under initramfs image's /lib/modules/3.11.0-rc1/kernel/arch/x86/crypto
directory? Any files in /lib/modules/3.11.0-rc1/modules.* need to be
modified?

Tim

2013-07-18 23:44:40

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On 07/18/2013 03:17 PM, Rafael J. Wysocki wrote:
>>
>> alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
>>
>> This should cause udev to load the crct10dif_pclml module when cpu
>> support the PCLMULQDQ (feature code 0081). I did my testing during
>> development on 3.10 and the module was indeed loaded.
>>
>> However, I found that the following commit under 3.11-rc1 broke
>> the mechanism after some bisection.
>>
>> commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
>> Author: Rafael J. Wysocki <[email protected]>
>> Date: Fri May 3 00:26:22 2013 +0200
>>
>> ACPI / processor: Use common hotplug infrastructure
>> Split the ACPI processor driver into two parts, one that is
>> non-modular, resides in the ACPI core and handles the enumeration
>> and hotplug of processors and one that implements the rest of the
>> existing processor driver functionality.
>> Rafael, can you check and see if this can be fixed so those
>> optimized
>> crypto modules for Intel cpu that support them can be loaded?
>
> I think this is an ordering issue between udev startup and the time when
> devices are registered.
>
> I wonder what happens if you put those modules into the initramfs image?
>

OK, this bothers me on some pretty deep level... a set of changes
exclusively in drivers/acpi breaking functionality which had nothing to
do with ACPI, specifically CPU-feature-based module loading.

Please let me know what the investigation comes up with, or if I need to
get more directly involved.

-hpa

2013-07-19 12:57:33

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Thursday, July 18, 2013 04:44:20 PM H. Peter Anvin wrote:
> On 07/18/2013 03:17 PM, Rafael J. Wysocki wrote:
> >>
> >> alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
> >>
> >> This should cause udev to load the crct10dif_pclml module when cpu
> >> support the PCLMULQDQ (feature code 0081). I did my testing during
> >> development on 3.10 and the module was indeed loaded.
> >>
> >> However, I found that the following commit under 3.11-rc1 broke
> >> the mechanism after some bisection.
> >>
> >> commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> >> Author: Rafael J. Wysocki <[email protected]>
> >> Date: Fri May 3 00:26:22 2013 +0200
> >>
> >> ACPI / processor: Use common hotplug infrastructure
> >> Split the ACPI processor driver into two parts, one that is
> >> non-modular, resides in the ACPI core and handles the enumeration
> >> and hotplug of processors and one that implements the rest of the
> >> existing processor driver functionality.
> >> Rafael, can you check and see if this can be fixed so those
> >> optimized
> >> crypto modules for Intel cpu that support them can be loaded?
> >
> > I think this is an ordering issue between udev startup and the time when
> > devices are registered.
> >
> > I wonder what happens if you put those modules into the initramfs image?
> >
>
> OK, this bothers me on some pretty deep level... a set of changes
> exclusively in drivers/acpi breaking functionality which had nothing to
> do with ACPI, specifically CPU-feature-based module loading.

Well, they are not exclusively in drivers/acpi, they are in drivers/base/cpu.c
too and that most likely is the responsible part.

> Please let me know what the investigation comes up with, or if I need to
> get more directly involved.

I will.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-19 12:53:38

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Thursday, July 18, 2013 04:08:14 PM Tim Chen wrote:
> On Fri, 2013-07-19 at 00:17 +0200, Rafael J. Wysocki wrote:
> > On 7/18/2013 11:00 PM, Tim Chen wrote:
> > > On Thu, 2013-07-18 at 12:47 +0900, Tetsuo Handa wrote:
> > >> Tim Chen wrote:
> > >>>>> Your approach is quite complicated. I think something simpler like the
> > >>>>> following will work:
> > >>>> We cannot benefit from PCLMULQDQ. Is it acceptable for you?
> > >>>
> > >>> The following code in crct10dif-pclmul_glue.c
> > >>>
> > >>> static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > >>> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > >>> {}
> > >>> };
> > >>> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> > >>>
> > >>> will put the module in the device table and get the module
> > >>> loaded, as long as the cpu support PCLMULQDQ. So we should be able
> > >>> to benefit.
> > >> Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
> > >> Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?
> > > The code:
> > >
> > > static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > > X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > > {}
> > > };
> > > MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> > >
> > > causes the following line to be added to modules.alias file:
> > >
> > > alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
> > >
> > > This should cause udev to load the crct10dif_pclml module when cpu
> > > support the PCLMULQDQ (feature code 0081). I did my testing during
> > > development on 3.10 and the module was indeed loaded.
> > >
> > > However, I found that the following commit under 3.11-rc1 broke
> > > the mechanism after some bisection.
> > >
> > > commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> > > Author: Rafael J. Wysocki <[email protected]>
> > > Date: Fri May 3 00:26:22 2013 +0200
> > >
> > > ACPI / processor: Use common hotplug infrastructure
> > >
> > > Split the ACPI processor driver into two parts, one that is
> > > non-modular, resides in the ACPI core and handles the enumeration
> > > and hotplug of processors and one that implements the rest of the
> > > existing processor driver functionality.
> > >
> > > Rafael, can you check and see if this can be fixed so those optimized
> > > crypto modules for Intel cpu that support them can be loaded?
> >
> > I think this is an ordering issue between udev startup and the time when
> > devices are registered.
>
> Something that can be fixed?

I'm sure it can be fixes, but I'm not sure whether it's a udev bug or real
breakage in the kernel yet. I need to figure out that part.

> > I wonder what happens if you put those modules into the initramfs image?
>
> Under initramfs image's /lib/modules/3.11.0-rc1/kernel/arch/x86/crypto
> directory? Any files in /lib/modules/3.11.0-rc1/modules.* need to be
> modified?

No, you shouldn't need to modify any files, just please try to make your
mkinitrd (or whatever else you use) put the modules you'd like to be
autoloaded into the image.

That's only something I'd like to know at this point, though, not a
"workaround" or something like that.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-19 14:39:26

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Friday, July 19, 2013 03:03:36 PM Rafael J. Wysocki wrote:
> On Thursday, July 18, 2013 04:08:14 PM Tim Chen wrote:
> > On Fri, 2013-07-19 at 00:17 +0200, Rafael J. Wysocki wrote:
> > > On 7/18/2013 11:00 PM, Tim Chen wrote:
> > > > On Thu, 2013-07-18 at 12:47 +0900, Tetsuo Handa wrote:
> > > >> Tim Chen wrote:
> > > >>>>> Your approach is quite complicated. I think something simpler like the
> > > >>>>> following will work:
> > > >>>> We cannot benefit from PCLMULQDQ. Is it acceptable for you?
> > > >>>
> > > >>> The following code in crct10dif-pclmul_glue.c
> > > >>>
> > > >>> static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > > >>> X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > > >>> {}
> > > >>> };
> > > >>> MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> > > >>>
> > > >>> will put the module in the device table and get the module
> > > >>> loaded, as long as the cpu support PCLMULQDQ. So we should be able
> > > >>> to benefit.
> > > >> Excuse me, how can crct10dif-pclmul.ko get loaded automatically?
> > > >> Did you test CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m with below debug message?
> > > > The code:
> > > >
> > > > static const struct x86_cpu_id crct10dif_cpu_id[] = {
> > > > X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
> > > > {}
> > > > };
> > > > MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
> > > >
> > > > causes the following line to be added to modules.alias file:
> > > >
> > > > alias x86cpu:vendor:*:family:*:model:*:feature:*0081* crct10dif_pclmul
> > > >
> > > > This should cause udev to load the crct10dif_pclml module when cpu
> > > > support the PCLMULQDQ (feature code 0081). I did my testing during
> > > > development on 3.10 and the module was indeed loaded.
> > > >
> > > > However, I found that the following commit under 3.11-rc1 broke
> > > > the mechanism after some bisection.
> > > >
> > > > commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> > > > Author: Rafael J. Wysocki <[email protected]>
> > > > Date: Fri May 3 00:26:22 2013 +0200
> > > >
> > > > ACPI / processor: Use common hotplug infrastructure
> > > >
> > > > Split the ACPI processor driver into two parts, one that is
> > > > non-modular, resides in the ACPI core and handles the enumeration
> > > > and hotplug of processors and one that implements the rest of the
> > > > existing processor driver functionality.
> > > >
> > > > Rafael, can you check and see if this can be fixed so those optimized
> > > > crypto modules for Intel cpu that support them can be loaded?
> > >
> > > I think this is an ordering issue between udev startup and the time when
> > > devices are registered.
> >
> > Something that can be fixed?
>
> I'm sure it can be fixes, but I'm not sure whether it's a udev bug or real
> breakage in the kernel yet. I need to figure out that part.

OK

I wonder if the appended patch makes the issue go away for you?

Rafael


---
drivers/acpi/acpi_platform.c | 24 +++++++++++++-----------
drivers/acpi/acpi_processor.c | 14 ++++----------
drivers/acpi/processor_driver.c | 26 ++++++++++++++------------
3 files changed, 31 insertions(+), 33 deletions(-)

Index: linux-pm/drivers/acpi/acpi_processor.c
===================================================================
--- linux-pm.orig/drivers/acpi/acpi_processor.c
+++ linux-pm/drivers/acpi/acpi_processor.c
@@ -397,20 +397,14 @@ static int __cpuinit acpi_processor_add(
result = -ENODEV;
goto err;
}
-
- result = acpi_bind_one(dev, pr->handle);
- if (result)
- goto err;
-
pr->dev = dev;
dev->offline = pr->flags.need_hotplug_init;

- /* Trigger the processor driver's .probe() if present. */
- if (device_attach(dev) >= 0)
- return 1;
+ result = acpi_create_platform_device(device, id);
+ if (result > 0)
+ return result;

- dev_err(dev, "Processor driver could not be attached\n");
- acpi_unbind_one(dev);
+ dev_err(dev, "Unable to create processor platform device\n");

err:
free_cpumask_var(pr->throttling.shared_cpu_map);
Index: linux-pm/drivers/acpi/acpi_platform.c
===================================================================
--- linux-pm.orig/drivers/acpi/acpi_platform.c
+++ linux-pm/drivers/acpi/acpi_platform.c
@@ -52,7 +52,7 @@ int acpi_create_platform_device(struct a
struct platform_device_info pdevinfo;
struct resource_list_entry *rentry;
struct list_head resource_list;
- struct resource *resources;
+ struct resource *resources = NULL;
int count;

/* If the ACPI node already has a physical device attached, skip it. */
@@ -61,20 +61,22 @@ int acpi_create_platform_device(struct a

INIT_LIST_HEAD(&resource_list);
count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
- if (count <= 0)
+ if (count < 0) {
return 0;
+ } else if (count > 0) {
+ resources = kmalloc(count * sizeof(struct resource),
+ GFP_KERNEL);
+ if (!resources) {
+ dev_err(&adev->dev, "No memory for resources\n");
+ acpi_dev_free_resource_list(&resource_list);
+ return -ENOMEM;
+ }
+ count = 0;
+ list_for_each_entry(rentry, &resource_list, node)
+ resources[count++] = rentry->res;

- resources = kmalloc(count * sizeof(struct resource), GFP_KERNEL);
- if (!resources) {
- dev_err(&adev->dev, "No memory for resources\n");
acpi_dev_free_resource_list(&resource_list);
- return -ENOMEM;
}
- count = 0;
- list_for_each_entry(rentry, &resource_list, node)
- resources[count++] = rentry->res;
-
- acpi_dev_free_resource_list(&resource_list);

memset(&pdevinfo, 0, sizeof(pdevinfo));
/*
Index: linux-pm/drivers/acpi/processor_driver.c
===================================================================
--- linux-pm.orig/drivers/acpi/processor_driver.c
+++ linux-pm/drivers/acpi/processor_driver.c
@@ -36,6 +36,7 @@
#include <linux/cpuidle.h>
#include <linux/slab.h>
#include <linux/acpi.h>
+#include <linux/platform_device.h>

#include <acpi/processor.h>

@@ -54,8 +55,8 @@ MODULE_AUTHOR("Paul Diefenbaugh");
MODULE_DESCRIPTION("ACPI Processor Driver");
MODULE_LICENSE("GPL");

-static int acpi_processor_start(struct device *dev);
-static int acpi_processor_stop(struct device *dev);
+static int acpi_processor_start(struct platform_device *pdev);
+static int acpi_processor_stop(struct platform_device *pdev);

static const struct acpi_device_id processor_device_ids[] = {
{ACPI_PROCESSOR_OBJECT_HID, 0},
@@ -64,10 +65,11 @@ static const struct acpi_device_id proce
};
MODULE_DEVICE_TABLE(acpi, processor_device_ids);

-static struct device_driver acpi_processor_driver = {
- .name = "processor",
- .bus = &cpu_subsys,
- .acpi_match_table = processor_device_ids,
+static struct platform_driver acpi_processor_driver = {
+ .driver = {
+ .name = "processor",
+ .acpi_match_table = processor_device_ids,
+ },
.probe = acpi_processor_start,
.remove = acpi_processor_stop,
};
@@ -222,22 +224,22 @@ static __cpuinit int __acpi_processor_st
return result;
}

-static int __cpuinit acpi_processor_start(struct device *dev)
+static int __cpuinit acpi_processor_start(struct platform_device *pdev)
{
struct acpi_device *device;

- if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
+ if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &device))
return -ENODEV;

return __acpi_processor_start(device);
}

-static int acpi_processor_stop(struct device *dev)
+static int acpi_processor_stop(struct platform_device *pdev)
{
struct acpi_device *device;
struct acpi_processor *pr;

- if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
+ if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &device))
return 0;

acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
@@ -271,7 +273,7 @@ static int __init acpi_processor_driver_
if (acpi_disabled)
return 0;

- result = driver_register(&acpi_processor_driver);
+ result = platform_driver_register(&acpi_processor_driver);
if (result < 0)
return result;

@@ -292,7 +294,7 @@ static void __exit acpi_processor_driver
acpi_thermal_cpufreq_exit();
unregister_hotcpu_notifier(&acpi_cpu_notifier);
acpi_processor_syscore_exit();
- driver_unregister(&acpi_processor_driver);
+ platform_driver_unregister(&acpi_processor_driver);
}

module_init(acpi_processor_driver_init);

2013-07-19 18:08:49

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, 2013-07-19 at 16:49 +0200, Rafael J. Wysocki wrote:
> > > > > This should cause udev to load the crct10dif_pclml module when cpu
> > > > > support the PCLMULQDQ (feature code 0081). I did my testing during
> > > > > development on 3.10 and the module was indeed loaded.
> > > > >
> > > > > However, I found that the following commit under 3.11-rc1 broke
> > > > > the mechanism after some bisection.
> > > > >
> > > > > commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> > > > > Author: Rafael J. Wysocki <[email protected]>
> > > > > Date: Fri May 3 00:26:22 2013 +0200
> > > > >
> > > > > ACPI / processor: Use common hotplug infrastructure
> > > > >
> > > > > Split the ACPI processor driver into two parts, one that is
> > > > > non-modular, resides in the ACPI core and handles the enumeration
> > > > > and hotplug of processors and one that implements the rest of the
> > > > > existing processor driver functionality.
> > > > >
> > > > > Rafael, can you check and see if this can be fixed so those optimized
> > > > > crypto modules for Intel cpu that support them can be loaded?
> > > >
> > > > I think this is an ordering issue between udev startup and the time when
> > > > devices are registered.
> > >
> > > Something that can be fixed?
> >
> > I'm sure it can be fixes, but I'm not sure whether it's a udev bug or real
> > breakage in the kernel yet. I need to figure out that part.
>
> OK
>
> I wonder if the appended patch makes the issue go away for you?
>

Rafael, the patch did fix the cpu feature based module loading issue.
Thanks for your quick response.

Herbert, the patch below should fix the boot failure issue.

I also added the change to rename crct10dif.c to crct10dif_generic.c
and added MODULE_ALIAS(crct10dif) to crct10dif_generic.c.
This was according to our discussion:
https://lkml.org/lkml/2013/5/21/216

However, when I have the

CONFIG_CRYPTO_CRCT10DIF=y
CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
CONFIG_CRC_T10DIF=y

combination, the crc-t10dif library function was still
initialized before the crct10dif-pclmul.ko was loaded,
leading to the generic version being used. This
is also one of Tetsuo's concerns. In theory, loading
the generic version should also load the pclmul version as
they have the same MODULE_ALIAS, before crc-t10dif library
try to allocate the crypto transform.

Something else that I'm missing and need to be changed?

I will be away for a week without internet access so my
response will be slow.

Thanks.

Tim

Signed-off-by: Tim Chen <[email protected]>
---
Fix boot failure as crc-t10dif library may not cause crct10dif.ko
containing the generic algorithm to be loaded.

Rename crct10dif.c to crct10dif_generic.c and add module alias.
This should load all the modules supporting crct10dif algorithm
at the same time.
---
crypto/Makefile | 2 +-
crypto/{crct10dif.c => crct10dif_generic.c} | 1 +
lib/crc-t10dif.c | 3 ++-
3 files changed, 4 insertions(+), 2 deletions(-)
rename crypto/{crct10dif.c => crct10dif_generic.c} (99%)

diff --git a/crypto/Makefile b/crypto/Makefile
index 2d5ed08..3fd76fa 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -83,7 +83,7 @@ obj-$(CONFIG_CRYPTO_ZLIB) += zlib.o
obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
obj-$(CONFIG_CRYPTO_CRC32) += crc32.o
-obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif.o
+obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_generic.o
obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
obj-$(CONFIG_CRYPTO_LZO) += lzo.o
obj-$(CONFIG_CRYPTO_LZ4) += lz4.o
diff --git a/crypto/crct10dif.c b/crypto/crct10dif_generic.c
similarity index 99%
rename from crypto/crct10dif.c
rename to crypto/crct10dif_generic.c
index 92aca96..45a9acd 100644
--- a/crypto/crct10dif.c
+++ b/crypto/crct10dif_generic.c
@@ -176,3 +176,4 @@ module_exit(crct10dif_mod_fini);
MODULE_AUTHOR("Tim Chen <[email protected]>");
MODULE_DESCRIPTION("T10 DIF CRC calculation.");
MODULE_LICENSE("GPL");
+MODULE_ALIAS(crct10dif);
diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index d102d83..37b3eb4 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -15,7 +15,8 @@
#include <linux/init.h>
#include <crypto/hash.h>

-static struct crypto_shash *crct10dif_tfm;
+__u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len);
+static struct crypto_shash *crct10dif_tfm = crc_t10dif_generic;

__u16 crc_t10dif(const unsigned char *buffer, size_t len)
{
--
1.7.11.7

2013-07-19 21:38:04

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Friday, July 19, 2013 11:08:49 AM Tim Chen wrote:
> On Fri, 2013-07-19 at 16:49 +0200, Rafael J. Wysocki wrote:
> > > > > > This should cause udev to load the crct10dif_pclml module when cpu
> > > > > > support the PCLMULQDQ (feature code 0081). I did my testing during
> > > > > > development on 3.10 and the module was indeed loaded.
> > > > > >
> > > > > > However, I found that the following commit under 3.11-rc1 broke
> > > > > > the mechanism after some bisection.
> > > > > >
> > > > > > commit ac212b6980d8d5eda705864fc5a8ecddc6d6eacc
> > > > > > Author: Rafael J. Wysocki <[email protected]>
> > > > > > Date: Fri May 3 00:26:22 2013 +0200
> > > > > >
> > > > > > ACPI / processor: Use common hotplug infrastructure
> > > > > >
> > > > > > Split the ACPI processor driver into two parts, one that is
> > > > > > non-modular, resides in the ACPI core and handles the enumeration
> > > > > > and hotplug of processors and one that implements the rest of the
> > > > > > existing processor driver functionality.
> > > > > >
> > > > > > Rafael, can you check and see if this can be fixed so those optimized
> > > > > > crypto modules for Intel cpu that support them can be loaded?
> > > > >
> > > > > I think this is an ordering issue between udev startup and the time when
> > > > > devices are registered.
> > > >
> > > > Something that can be fixed?
> > >
> > > I'm sure it can be fixes, but I'm not sure whether it's a udev bug or real
> > > breakage in the kernel yet. I need to figure out that part.
> >
> > OK
> >
> > I wonder if the appended patch makes the issue go away for you?
> >
>
> Rafael, the patch did fix the cpu feature based module loading issue.
> Thanks for your quick response.

Alas, this is not the one I'd like to apply.

With that patch applied, new device objects are created to avoid binding the
processor driver directly to the cpu system device objects, because that
apparently confuses udev and it starts to ignore the cpu modalias once the
driver has been bound to any of those objects.

I've verified in the meantime that this indeed is the case.

A link to the patch in question: https://patchwork.kernel.org/patch/2830561/

Greg, I asked you some time ago whether or not it was possible for udev to stop
autoloading modules that matched the cpu modalias after a driver had been bound
to the cpu system device objects and you said "no". However, this time I can
say with certainty that that really is the case. So, the question now is
whether or not we can do anything in the kernel to avoid that confusion in udev
instead of applying the patch linked above (which is beyond ugly in my not so
humble opinion)?

Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-19 23:16:30

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, Jul 19, 2013 at 11:38:04PM +0200, Rafael J. Wysocki wrote:
> Alas, this is not the one I'd like to apply.
>
> With that patch applied, new device objects are created to avoid binding the
> processor driver directly to the cpu system device objects, because that
> apparently confuses udev and it starts to ignore the cpu modalias once the
> driver has been bound to any of those objects.
>
> I've verified in the meantime that this indeed is the case.
>
> A link to the patch in question: https://patchwork.kernel.org/patch/2830561/
>
> Greg, I asked you some time ago whether or not it was possible for udev to stop
> autoloading modules that matched the cpu modalias after a driver had been bound
> to the cpu system device objects and you said "no". However, this time I can
> say with certainty that that really is the case. So, the question now is
> whether or not we can do anything in the kernel to avoid that confusion in udev
> instead of applying the patch linked above (which is beyond ugly in my not so
> humble opinion)?

udev isn't doing any module loading, 'modprobe' is just being called for
any new module alias that shows up in the system, and all of the drivers
that match it then get loaded.

How is it a problem if a module is attempted to be loaded that is
already loaded? How is it a problem if a different module is loaded for
a device already bound to a driver? Both of those should be total
"no-ops" for the kernel.

But, I don't know anything about the cpu code, how is loading a module
causing problems? That sounds like it needs to be fixes, as any root
user can load modules whenever they want, you can't protect the kernel
from doing that.

thanks,

greg k-h

2013-07-19 23:21:09

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On 07/19/2013 04:16 PM, Greg Kroah-Hartman wrote:
>
> udev isn't doing any module loading, 'modprobe' is just being called for
> any new module alias that shows up in the system, and all of the drivers
> that match it then get loaded.
>
> How is it a problem if a module is attempted to be loaded that is
> already loaded? How is it a problem if a different module is loaded for
> a device already bound to a driver? Both of those should be total
> "no-ops" for the kernel.
>
> But, I don't know anything about the cpu code, how is loading a module
> causing problems? That sounds like it needs to be fixes, as any root
> user can load modules whenever they want, you can't protect the kernel
> from doing that.
>

The issue here seems to be the dynamic binding nature of the crypto
subsystem. When something needs crypto, it will request the appropriate
crypto module (e.g. crct10dif), which may race with detecting a specific
hardware accelerator based on CPUID or device information (e.g.
crct10dif_pclmul).

RAID has effectively the same issue, and we just "solved" it by
compiling in all the accelerators into the top-level module.

-hpa


2013-07-19 23:24:59

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, Jul 19, 2013 at 04:21:09PM -0700, H. Peter Anvin wrote:
>
> The issue here seems to be the dynamic binding nature of the crypto
> subsystem. When something needs crypto, it will request the appropriate
> crypto module (e.g. crct10dif), which may race with detecting a specific
> hardware accelerator based on CPUID or device information (e.g.
> crct10dif_pclmul).
>
> RAID has effectively the same issue, and we just "solved" it by
> compiling in all the accelerators into the top-level module.

I think for crypto the simplest solution is to not do CPUID-based
loading. Then crypto users will simply load the module alias which
causes modprobe to load all modules providing that alias.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2013-07-19 23:26:01

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, Jul 19, 2013 at 04:21:09PM -0700, H. Peter Anvin wrote:
> On 07/19/2013 04:16 PM, Greg Kroah-Hartman wrote:
> >
> > udev isn't doing any module loading, 'modprobe' is just being called for
> > any new module alias that shows up in the system, and all of the drivers
> > that match it then get loaded.
> >
> > How is it a problem if a module is attempted to be loaded that is
> > already loaded? How is it a problem if a different module is loaded for
> > a device already bound to a driver? Both of those should be total
> > "no-ops" for the kernel.
> >
> > But, I don't know anything about the cpu code, how is loading a module
> > causing problems? That sounds like it needs to be fixes, as any root
> > user can load modules whenever they want, you can't protect the kernel
> > from doing that.
> >
>
> The issue here seems to be the dynamic binding nature of the crypto
> subsystem. When something needs crypto, it will request the appropriate
> crypto module (e.g. crct10dif), which may race with detecting a specific
> hardware accelerator based on CPUID or device information (e.g.
> crct10dif_pclmul).
>
> RAID has effectively the same issue, and we just "solved" it by
> compiling in all the accelerators into the top-level module.

Then there's nothing to be done in udev or kmod, right?

greg k-h

2013-07-19 23:28:21

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On 07/19/2013 04:26 PM, Greg Kroah-Hartman wrote:
>>
>> RAID has effectively the same issue, and we just "solved" it by
>> compiling in all the accelerators into the top-level module.
>
> Then there's nothing to be done in udev or kmod, right?
>

I don't know.

-hpa

2013-07-19 23:37:13

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Sat, 2013-07-20 at 09:24 +1000, Herbert Xu wrote:
> On Fri, Jul 19, 2013 at 04:21:09PM -0700, H. Peter Anvin wrote:
> >
> > The issue here seems to be the dynamic binding nature of the crypto
> > subsystem. When something needs crypto, it will request the appropriate
> > crypto module (e.g. crct10dif), which may race with detecting a specific
> > hardware accelerator based on CPUID or device information (e.g.
> > crct10dif_pclmul).
> >
> > RAID has effectively the same issue, and we just "solved" it by
> > compiling in all the accelerators into the top-level module.
>
> I think for crypto the simplest solution is to not do CPUID-based
> loading. Then crypto users will simply load the module alias which
> causes modprobe to load all modules providing that alias.
>
> Cheers,

Herbert,

I've tried the module alias approach (see my earlier mail with patch)
but it didn't seem to load things properly. Can you check to see if
there's anything I did incorrectly.

Tim


2013-07-19 23:50:46

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Friday, July 19, 2013 04:16:30 PM Greg Kroah-Hartman wrote:
> On Fri, Jul 19, 2013 at 11:38:04PM +0200, Rafael J. Wysocki wrote:
> > Alas, this is not the one I'd like to apply.
> >
> > With that patch applied, new device objects are created to avoid binding the
> > processor driver directly to the cpu system device objects, because that
> > apparently confuses udev and it starts to ignore the cpu modalias once the
> > driver has been bound to any of those objects.
> >
> > I've verified in the meantime that this indeed is the case.
> >
> > A link to the patch in question: https://patchwork.kernel.org/patch/2830561/
> >
> > Greg, I asked you some time ago whether or not it was possible for udev to stop
> > autoloading modules that matched the cpu modalias after a driver had been bound
> > to the cpu system device objects and you said "no". However, this time I can
> > say with certainty that that really is the case. So, the question now is
> > whether or not we can do anything in the kernel to avoid that confusion in udev
> > instead of applying the patch linked above (which is beyond ugly in my not so
> > humble opinion)?
>
> udev isn't doing any module loading, 'modprobe' is just being called for
> any new module alias that shows up in the system, and all of the drivers
> that match it then get loaded.

The problem is that that doesn't happen when a driver is bound to the
cpu system device objects. modprobe is just not called for modules that
match the cpu modalias in that case.

If I call modprobe manually for any of the modules in question, it loads
and works no problem.

> How is it a problem if a module is attempted to be loaded that is
> already loaded? How is it a problem if a different module is loaded for
> a device already bound to a driver? Both of those should be total
> "no-ops" for the kernel.

Precisely, but that's not what happens in practice, hence my question.

The situation is this:

- With 3.11-rc1 modules that match the CPU modalias are not loaded
automatically (that is, modprobe is not called for them by udev) after
the processor module is loaded.
- With 3.10 they are loaded automatically at any time.
- With the patch at https://patchwork.kernel.org/patch/2830561/ on top of
3.11-rc1 the situation is the same as for 3.10.

Therefore we have a kernel regression from 3.10 (with respect to the existing
user space which is udev) in 3.11-rc1 3.10 and the patch at
https://patchwork.kernel.org/patch/2830561/ makes that regression go away.

However, that patch is totally voodoo programming, so I wonder if there is any
saner alternative or we really need to do voodoo programming in the kernel to
work around udev's confusion.

> But, I don't know anything about the cpu code, how is loading a module
> causing problems? That sounds like it needs to be fixes, as any root
> user can load modules whenever they want, you can't protect the kernel
> from doing that.

Yes, that needs to be fixed, but I don't know *why* it is a problem in the
first place. I'd like to understand what's going on, because I don't
right now.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-20 01:31:01

by Tim Chen

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, 2013-07-19 at 16:37 -0700, Tim Chen wrote:
> On Sat, 2013-07-20 at 09:24 +1000, Herbert Xu wrote:
> > On Fri, Jul 19, 2013 at 04:21:09PM -0700, H. Peter Anvin wrote:
> > >
> > > The issue here seems to be the dynamic binding nature of the crypto
> > > subsystem. When something needs crypto, it will request the appropriate
> > > crypto module (e.g. crct10dif), which may race with detecting a specific
> > > hardware accelerator based on CPUID or device information (e.g.
> > > crct10dif_pclmul).
> > >
> > > RAID has effectively the same issue, and we just "solved" it by
> > > compiling in all the accelerators into the top-level module.
> >
> > I think for crypto the simplest solution is to not do CPUID-based
> > loading. Then crypto users will simply load the module alias which
> > causes modprobe to load all modules providing that alias.
> >
> > Cheers,
>
> Herbert,
>
> I've tried the module alias approach (see my earlier mail with patch)
> but it didn't seem to load things properly. Can you check to see if
> there's anything I did incorrectly.
>
> Tim

I fixed a missing request_module statement in crct10dif library.
So now things work if I have the following config:

CONFIG_CRYPTO_CRCT10DIF=m
CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
CONFIG_CRC_T10DIF=m

However, when I have the library and generic algorithm compiled in,
I do not see the PCLMULQDQ version loaded.

CONFIG_CRYPTO_CRCT10DIF=y
CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
CONFIG_CRC_T10DIF=y

Perhaps I am initiating the crct10dif library at a really early
stage when things are compiled in, where the module is not in
initramfs? In that case, perhaps we should only allow
PCLMUL version to be compiled in
and not exist as a module?

Here's the patch I tried:

Signed-off-by: Tim Chen <[email protected]>
---
arch/x86/crypto/crct10dif-pclmul_glue.c | 8 +-------
crypto/Makefile | 2 +-
crypto/{crct10dif.c => crct10dif_generic.c} | 1 +
lib/crc-t10dif.c | 1 +
4 files changed, 4 insertions(+), 8 deletions(-)
rename crypto/{crct10dif.c => crct10dif_generic.c} (99%)

diff --git a/arch/x86/crypto/crct10dif-pclmul_glue.c b/arch/x86/crypto/crct10dif-pclmul_glue.c
index 7845d7f..7ad5f09 100644
--- a/arch/x86/crypto/crct10dif-pclmul_glue.c
+++ b/arch/x86/crypto/crct10dif-pclmul_glue.c
@@ -121,15 +121,9 @@ static struct shash_alg alg = {
}
};

-static const struct x86_cpu_id crct10dif_cpu_id[] = {
- X86_FEATURE_MATCH(X86_FEATURE_PCLMULQDQ),
- {}
-};
-MODULE_DEVICE_TABLE(x86cpu, crct10dif_cpu_id);
-
static int __init crct10dif_intel_mod_init(void)
{
- if (!x86_match_cpu(crct10dif_cpu_id))
+ if (!cpu_has_pclmulqdq)
return -ENODEV;

return crypto_register_shash(&alg);
diff --git a/crypto/Makefile b/crypto/Makefile
index 2d5ed08..3fd76fa 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -83,7 +83,7 @@ obj-$(CONFIG_CRYPTO_ZLIB) += zlib.o
obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
obj-$(CONFIG_CRYPTO_CRC32) += crc32.o
-obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif.o
+obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_generic.o
obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o
obj-$(CONFIG_CRYPTO_LZO) += lzo.o
obj-$(CONFIG_CRYPTO_LZ4) += lz4.o
diff --git a/crypto/crct10dif.c b/crypto/crct10dif_generic.c
similarity index 99%
rename from crypto/crct10dif.c
rename to crypto/crct10dif_generic.c
index 92aca96..c960a95 100644
--- a/crypto/crct10dif.c
+++ b/crypto/crct10dif_generic.c
@@ -176,3 +176,4 @@ module_exit(crct10dif_mod_fini);
MODULE_AUTHOR("Tim Chen <[email protected]>");
MODULE_DESCRIPTION("T10 DIF CRC calculation.");
MODULE_LICENSE("GPL");
+MODULE_ALIAS("crct10dif");
diff --git a/lib/crc-t10dif.c b/lib/crc-t10dif.c
index fe3428c..d8cd353 100644
--- a/lib/crc-t10dif.c
+++ b/lib/crc-t10dif.c
@@ -38,6 +38,7 @@ EXPORT_SYMBOL(crc_t10dif);

static int __init crc_t10dif_mod_init(void)
{
+ request_module("crct10dif");
crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
return PTR_RET(crct10dif_tfm);
}
--
1.7.11.7

2013-07-20 02:20:54

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to moduledependency.

Tim Chen wrote:
> On Fri, 2013-07-19 at 16:37 -0700, Tim Chen wrote:
> > Herbert,
> >
> > I've tried the module alias approach (see my earlier mail with patch)
> > but it didn't seem to load things properly. Can you check to see if
> > there's anything I did incorrectly.
> >
> > Tim
>
> I fixed a missing request_module statement in crct10dif library.
> So now things work if I have the following config:
>
> CONFIG_CRYPTO_CRCT10DIF=m
> CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
> CONFIG_CRC_T10DIF=m
>
> However, when I have the library and generic algorithm compiled in,
> I do not see the PCLMULQDQ version loaded.
>
> CONFIG_CRYPTO_CRCT10DIF=y
> CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
> CONFIG_CRC_T10DIF=y
>
> Perhaps I am initiating the crct10dif library at a really early
> stage when things are compiled in, where the module is not in
> initramfs? In that case, perhaps we should only allow
> PCLMUL version to be compiled in
> and not exist as a module?

I think that use of request_module("crct10dif") does not help loading
crct10dif-pclmul.ko when CONFIG_CRC_T10DIF=y CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m ,
for there is no / directory (note that the initramfs is not yet mounted as /
for loading modules which are not in vmlinux) when any module_init() functions
which are in vmlinux are called.

2013-07-20 03:06:29

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Saturday, July 20, 2013 02:00:44 AM Rafael J. Wysocki wrote:
> On Friday, July 19, 2013 04:16:30 PM Greg Kroah-Hartman wrote:
> > On Fri, Jul 19, 2013 at 11:38:04PM +0200, Rafael J. Wysocki wrote:
> > > Alas, this is not the one I'd like to apply.
> > >
> > > With that patch applied, new device objects are created to avoid binding the
> > > processor driver directly to the cpu system device objects, because that
> > > apparently confuses udev and it starts to ignore the cpu modalias once the
> > > driver has been bound to any of those objects.
> > >
> > > I've verified in the meantime that this indeed is the case.
> > >
> > > A link to the patch in question: https://patchwork.kernel.org/patch/2830561/
> > >
> > > Greg, I asked you some time ago whether or not it was possible for udev to stop
> > > autoloading modules that matched the cpu modalias after a driver had been bound
> > > to the cpu system device objects and you said "no". However, this time I can
> > > say with certainty that that really is the case. So, the question now is
> > > whether or not we can do anything in the kernel to avoid that confusion in udev
> > > instead of applying the patch linked above (which is beyond ugly in my not so
> > > humble opinion)?
> >
> > udev isn't doing any module loading, 'modprobe' is just being called for
> > any new module alias that shows up in the system, and all of the drivers
> > that match it then get loaded.
>
> The problem is that that doesn't happen when a driver is bound to the
> cpu system device objects. modprobe is just not called for modules that
> match the cpu modalias in that case.
>
> If I call modprobe manually for any of the modules in question, it loads
> and works no problem.

OK, I know what's up. udev has no rule that would allow it to load stuff on
the basis of MODALIAS if DRIVER is set in the event properties.

So, the following rule needs to be added to udev rules for things to work
as before:

DRIVER=="processor", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"

To be precise, I added a file called 80-drivers.rules to /etc/udev/rules.d/
with the following contents:

ACTION=="remove", GOTO="drivers_end"

DRIVER=="processor", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"

LABEL="drivers_end"

but I'm not sure how to propagate this to the udev maintainers.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-20 05:30:21

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Fri, Jul 19, 2013 at 06:31:04PM -0700, Tim Chen wrote:
>
> However, when I have the library and generic algorithm compiled in,
> I do not see the PCLMULQDQ version loaded.
>
> CONFIG_CRYPTO_CRCT10DIF=y
> CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
> CONFIG_CRC_T10DIF=y

That is completely expected. I don't really think we need to
do anything about this case. After all, if the admin wants to
use the optimised version for CRC_T10DIF then they could simply
compile that in as well.

Cheers,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2013-07-20 05:56:06

by Tetsuo Handa

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to moduledependency.

Herbert Xu wrote:
> On Fri, Jul 19, 2013 at 06:31:04PM -0700, Tim Chen wrote:
> >
> > However, when I have the library and generic algorithm compiled in,
> > I do not see the PCLMULQDQ version loaded.
> >
> > CONFIG_CRYPTO_CRCT10DIF=y
> > CONFIG_CRYPTO_CRCT10DIF_PCLMUL=m
> > CONFIG_CRC_T10DIF=y
>
> That is completely expected. I don't really think we need to
> do anything about this case. After all, if the admin wants to
> use the optimised version for CRC_T10DIF then they could simply
> compile that in as well.
>

Wow! ;-)

But I'd expect something like

static int __init crc_t10dif_mod_init(void)
{
+#if !defined(CONFIG_CRC_T10DIF_MODULE) && defined(CONFIG_CRYPTO_CRCT10DIF_PCLMUL_MODULE)
+ printk(KERN_WARNING "Consider CONFIG_CRYPTO_CRCT10DIF_PCLMUL=y for better performance\n");
+#endif
crct10dif_tfm = crypto_alloc_shash("crct10dif", 0, 0);
return PTR_RET(crct10dif_tfm);
}

because the admin might not be aware of this implication.

2013-07-20 09:41:58

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Saturday, July 20, 2013 05:06:29 AM Rafael J. Wysocki wrote:
> On Saturday, July 20, 2013 02:00:44 AM Rafael J. Wysocki wrote:
> > On Friday, July 19, 2013 04:16:30 PM Greg Kroah-Hartman wrote:
> > > On Fri, Jul 19, 2013 at 11:38:04PM +0200, Rafael J. Wysocki wrote:
> > > > Alas, this is not the one I'd like to apply.
> > > >
> > > > With that patch applied, new device objects are created to avoid binding the
> > > > processor driver directly to the cpu system device objects, because that
> > > > apparently confuses udev and it starts to ignore the cpu modalias once the
> > > > driver has been bound to any of those objects.
> > > >
> > > > I've verified in the meantime that this indeed is the case.
> > > >
> > > > A link to the patch in question: https://patchwork.kernel.org/patch/2830561/
> > > >
> > > > Greg, I asked you some time ago whether or not it was possible for udev to stop
> > > > autoloading modules that matched the cpu modalias after a driver had been bound
> > > > to the cpu system device objects and you said "no". However, this time I can
> > > > say with certainty that that really is the case. So, the question now is
> > > > whether or not we can do anything in the kernel to avoid that confusion in udev
> > > > instead of applying the patch linked above (which is beyond ugly in my not so
> > > > humble opinion)?
> > >
> > > udev isn't doing any module loading, 'modprobe' is just being called for
> > > any new module alias that shows up in the system, and all of the drivers
> > > that match it then get loaded.
> >
> > The problem is that that doesn't happen when a driver is bound to the
> > cpu system device objects. modprobe is just not called for modules that
> > match the cpu modalias in that case.
> >
> > If I call modprobe manually for any of the modules in question, it loads
> > and works no problem.
>
> OK, I know what's up. udev has no rule that would allow it to load stuff on
> the basis of MODALIAS if DRIVER is set in the event properties.
>
> So, the following rule needs to be added to udev rules for things to work
> as before:
>
> DRIVER=="processor", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"
>
> To be precise, I added a file called 80-drivers.rules to /etc/udev/rules.d/

Well, that wasn't a good idea, because the original 80-drivers.rules didn't
work then, but I renamed the new file (in /etc/udev/rules.d/) to 80-cpu.rules
and put this line (alone) into it:

ACTION="add", SUBSYSTEM=="cpu", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"

After that change everything works happily again.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-07-20 11:01:43

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3.11-rc1] crypto: Fix boot failure due to module dependency.

On Saturday, July 20, 2013 11:51:55 AM Rafael J. Wysocki wrote:
> On Saturday, July 20, 2013 05:06:29 AM Rafael J. Wysocki wrote:
> > On Saturday, July 20, 2013 02:00:44 AM Rafael J. Wysocki wrote:
> > > On Friday, July 19, 2013 04:16:30 PM Greg Kroah-Hartman wrote:
> > > > On Fri, Jul 19, 2013 at 11:38:04PM +0200, Rafael J. Wysocki wrote:
> > > > > Alas, this is not the one I'd like to apply.
> > > > >
> > > > > With that patch applied, new device objects are created to avoid binding the
> > > > > processor driver directly to the cpu system device objects, because that
> > > > > apparently confuses udev and it starts to ignore the cpu modalias once the
> > > > > driver has been bound to any of those objects.
> > > > >
> > > > > I've verified in the meantime that this indeed is the case.
> > > > >
> > > > > A link to the patch in question: https://patchwork.kernel.org/patch/2830561/
> > > > >
> > > > > Greg, I asked you some time ago whether or not it was possible for udev to stop
> > > > > autoloading modules that matched the cpu modalias after a driver had been bound
> > > > > to the cpu system device objects and you said "no". However, this time I can
> > > > > say with certainty that that really is the case. So, the question now is
> > > > > whether or not we can do anything in the kernel to avoid that confusion in udev
> > > > > instead of applying the patch linked above (which is beyond ugly in my not so
> > > > > humble opinion)?
> > > >
> > > > udev isn't doing any module loading, 'modprobe' is just being called for
> > > > any new module alias that shows up in the system, and all of the drivers
> > > > that match it then get loaded.
> > >
> > > The problem is that that doesn't happen when a driver is bound to the
> > > cpu system device objects. modprobe is just not called for modules that
> > > match the cpu modalias in that case.
> > >
> > > If I call modprobe manually for any of the modules in question, it loads
> > > and works no problem.
> >
> > OK, I know what's up. udev has no rule that would allow it to load stuff on
> > the basis of MODALIAS if DRIVER is set in the event properties.
> >
> > So, the following rule needs to be added to udev rules for things to work
> > as before:
> >
> > DRIVER=="processor", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"
> >
> > To be precise, I added a file called 80-drivers.rules to /etc/udev/rules.d/
>
> Well, that wasn't a good idea, because the original 80-drivers.rules didn't
> work then, but I renamed the new file (in /etc/udev/rules.d/) to 80-cpu.rules
> and put this line (alone) into it:
>
> ACTION="add", SUBSYSTEM=="cpu", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"

I made a mistake in the above, which should be:

ACTION=="add", SUBSYSTEM=="cpu", ENV{MODALIAS}=="?*", IMPORT{builtin}="kmod load $env{MODALIAS}"

sorry about that.

> After that change everything works happily again.

Thanks,
Rafael


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.