2009-09-20 16:49:22

by Séguier Régis

[permalink] [raw]
Subject: Padlock SHA1 failed at boot time

Hi,

With 2.6.31, at boot time,i got this error.
The previous version i use was 2.6.31-rc6 and work fine for me.

cpuidle: using governor menu
padlock: Using VIA PadLock ACE for AES algorithm.
general protection fault: 0000 [#1] PREEMPT
last sysfs file:

Pid: 83, comm: cryptomgr_test Not tainted (2.6.31EPIA_NAB7500 #311)
CN896-8251
EIP: 0060:[<c1247ef5>] EFLAGS: 00010202 CPU: 0
EIP is at padlock_sha1_finup+0x1a2/0x1f3
EAX: 00000000 EBX: 00000003 ECX: 00000003 EDX: 00000001
ESI: f734f000 EDI: f7367c88 EBP: f7367d18 ESP: f7367c18
DS: 007b ES: 007b FS: 0000 GS: 00e0 SS: 0068
Process cryptomgr_test (pid: 83, ti=f7366000 task=f71c9460 task.ti=f7366000)
Stack:
f7367ed0 f734f000 f734eee8 f734eef0 00000000 00000000 00000000 67452301
<0> efcdab89 98badcfe 10325476 c3d2e1f0 00000000 00000000 00000000 00000000
<0> 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Call Trace:
[<c101dc1d>] ? kmap_atomic_prot+0xb5/0xc3
[<c101dc48>] ? kmap_atomic+0x1d/0x30
[<c1103f76>] ? hash_walk_next+0x43/0x7d
[<c1104ccd>] ? crypto_shash_finup+0x3d/0x57
[<c1104ed8>] ? shash_ahash_finup+0x4d/0x81
[<c1104fff>] ? shash_ahash_digest+0xb7/0xd4
[<c1105045>] ? shash_async_digest+0x29/0x3c
[<c1103bc6>] ? crypto_ahash_op+0x9a/0xb6
[<c110501c>] ? shash_async_digest+0x0/0x3c
[<c1103bff>] ? crypto_ahash_digest+0x1d/0x30
[<c110626a>] ? test_hash+0x196/0x53a
[<c10fe1fd>] ? crypto_alloc_tfm+0x51/0x96
[<c1104980>] ? crypto_alloc_shash+0x20/0x36
[<c1247fd4>] ? padlock_cra_init+0x2a/0x6a
[<c10fe16b>] ? crypto_create_tfm+0x67/0xa8
[<c1104488>] ? crypto_init_shash_ops_async+0x39/0xca
[<c110665c>] ? alg_test_hash+0x4e/0x75
[<c1107f91>] ? alg_test+0x11a/0x171
[<c1022291>] ? finish_task_switch+0x48/0x97
[<c13a80c1>] ? schedule+0x364/0x385
[<c1105614>] ? cryptomgr_test+0x0/0x48
[<c1105642>] ? cryptomgr_test+0x2e/0x48
[<c1039bbe>] ? kthread+0x6b/0x70
[<c1039b53>] ? kthread+0x0/0x70
[<c100353b>] ? kernel_thread_helper+0x7/0x10
Code: 39 c2 74 10 0f 20 c0 a8 08 74 09 0f 06 ba 01 00 00 00 eb 02 31 d2
8b 85 14 ff ff ff 8d bd 70 ff ff ff 8b b5 04 ff ff ff 8d 0c 03 <f3> 0f
a6 c8 85 d2 74 09 0f 20 c0 83 c8 08 0f 22 c0 8b 8d 00 ff
EIP: [<c1247ef5>] padlock_sha1_finup+0x1a2/0x1f3 SS:ESP 0068:f7367c18
---[ end trace 853c7a9cbb58c0f4 ]---
note: cryptomgr_test[83] exited with preempt_count 1



/proc/cpuinfo :
processor : 0
vendor_id : CentaurHauls
cpu family : 6
model : 10
model name : VIA Esther processor 1500MHz
stepping : 9
cpu MHz : 798.040
cache size : 128 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
cmov pat clflush acpi mmx fxsr sse sse2 tm nx pni est tm2 rng rng_en ace
ace_en ace2 ace2_en phe phe_en pmm pmm_en
bogomips : 1596.08
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 32 bits virtual
power management:


--
R?gis S?guier


2009-09-21 06:13:44

by Herbert Xu

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

S?guier R?gis <[email protected]> wrote:
> Hi,
>
> With 2.6.31, at boot time,i got this error.
> The previous version i use was 2.6.31-rc6 and work fine for me.
>
> cpuidle: using governor menu
> padlock: Using VIA PadLock ACE for AES algorithm.
> general protection fault: 0000 [#1] PREEMPT
> last sysfs file:
>
> Pid: 83, comm: cryptomgr_test Not tainted (2.6.31EPIA_NAB7500 #311)
> CN896-8251
> EIP: 0060:[<c1247ef5>] EFLAGS: 00010202 CPU: 0
> EIP is at padlock_sha1_finup+0x1a2/0x1f3
> EAX: 00000000 EBX: 00000003 ECX: 00000003 EDX: 00000001
> ESI: f734f000 EDI: f7367c88 EBP: f7367d18 ESP: f7367c18

This looks like an alignment fault.

Can you please try this patch? Thanks!

diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index 76cb6b3..fe007b6 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -24,6 +24,12 @@
#include <asm/i387.h>
#include "padlock.h"

+#ifdef CONFIG_64BIT
+#define STACK_ALIGN 16
+#else
+#define STACK_ALIGN 4
+#endif
+
struct padlock_sha_desc {
struct shash_desc fallback;
};
@@ -64,7 +70,8 @@ static int padlock_sha1_finup(struct shash_desc *desc, const u8 *in,
/* We can't store directly to *out as it may be unaligned. */
/* BTW Don't reduce the buffer size below 128 Bytes!
* PadLock microcode needs it that big. */
- char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT)));
+ char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
+ char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
struct sha1_state state;
unsigned int space;
@@ -128,7 +135,8 @@ static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in,
/* We can't store directly to *out as it may be unaligned. */
/* BTW Don't reduce the buffer size below 128 Bytes!
* PadLock microcode needs it that big. */
- char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT)));
+ char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
+ char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
struct sha256_state state;
unsigned int space;

--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2009-09-21 07:49:50

by Séguier Régis

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

Herbert Xu a ?crit :
> S?guier R?gis <[email protected]> wrote:
>
>> Hi,
>>
>> With 2.6.31, at boot time,i got this error.
>> The previous version i use was 2.6.31-rc6 and work fine for me.
>>
>> cpuidle: using governor menu
>> padlock: Using VIA PadLock ACE for AES algorithm.
>> general protection fault: 0000 [#1] PREEMPT
>> last sysfs file:
>>
>> Pid: 83, comm: cryptomgr_test Not tainted (2.6.31EPIA_NAB7500 #311)
>> CN896-8251
>> EIP: 0060:[<c1247ef5>] EFLAGS: 00010202 CPU: 0
>> EIP is at padlock_sha1_finup+0x1a2/0x1f3
>> EAX: 00000000 EBX: 00000003 ECX: 00000003 EDX: 00000001
>> ESI: f734f000 EDI: f7367c88 EBP: f7367d18 ESP: f7367c18
>>
>
> This looks like an alignment fault.
>
> Can you please try this patch? Thanks!
>
> diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
> index 76cb6b3..fe007b6 100644
> --- a/drivers/crypto/padlock-sha.c
> +++ b/drivers/crypto/padlock-sha.c
> @@ -24,6 +24,12 @@
> #include <asm/i387.h>
> #include "padlock.h"
>
> +#ifdef CONFIG_64BIT
> +#define STACK_ALIGN 16
> +#else
> +#define STACK_ALIGN 4
> +#endif
> +
> struct padlock_sha_desc {
> struct shash_desc fallback;
> };
> @@ -64,7 +70,8 @@ static int padlock_sha1_finup(struct shash_desc *desc, const u8 *in,
> /* We can't store directly to *out as it may be unaligned. */
> /* BTW Don't reduce the buffer size below 128 Bytes!
> * PadLock microcode needs it that big. */
> - char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT)));
> + char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
> + char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
> struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
> struct sha1_state state;
> unsigned int space;
> @@ -128,7 +135,8 @@ static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in,
> /* We can't store directly to *out as it may be unaligned. */
> /* BTW Don't reduce the buffer size below 128 Bytes!
> * PadLock microcode needs it that big. */
> - char result[128] __attribute__ ((aligned(PADLOCK_ALIGNMENT)));
> + char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
> + char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
> struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
> struct sha256_state state;
> unsigned int space;
>
>
it's good for me now.

Thanks.
--
R?gis S?guier

2009-09-22 01:56:08

by Herbert Xu

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

On Mon, Sep 21, 2009 at 09:49:52AM +0200, S?guier R?gis wrote:
>
> it's good for me now.

Thanks for confirming! I'll push it with this changelog

crypto: padlock-sha - Fix stack alignment

The PadLock hardware requires the output buffer for SHA to be
128-bit aligned. We currentply place the buffer on the stack,
and ask gcc to align it to 128 bits. That doesn't work on i386
because the kernel stack is only aligned to 32 bits. This patch
changes the code to align the buffer by hand so that the hardware
doesn't fault on unaligned buffers.

Reported-by: S?guier R?gis <[email protected]>
Tested-by: S?guier R?gis <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2009-09-22 17:17:14

by Herbert Xu

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

Herbert Xu <[email protected]> wrote:
>
> crypto: padlock-sha - Fix stack alignment
>
> The PadLock hardware requires the output buffer for SHA to be
> 128-bit aligned. We currentply place the buffer on the stack,
> and ask gcc to align it to 128 bits. That doesn't work on i386
> because the kernel stack is only aligned to 32 bits. This patch
> changes the code to align the buffer by hand so that the hardware
> doesn't fault on unaligned buffers.
>
> Reported-by: S?guier R?gis <[email protected]>
> Tested-by: S?guier R?gis <[email protected]>
> Signed-off-by: Herbert Xu <[email protected]>

For the record I modified the patch slightly to ensure that
we get the minimum alignment from gcc.

diff --git a/drivers/crypto/padlock-sha.c b/drivers/crypto/padlock-sha.c
index fe007b6..0af8057 100644
--- a/drivers/crypto/padlock-sha.c
+++ b/drivers/crypto/padlock-sha.c
@@ -70,7 +70,8 @@ static int padlock_sha1_finup(struct shash_desc *desc, const u8 *in,
/* We can't store directly to *out as it may be unaligned. */
/* BTW Don't reduce the buffer size below 128 Bytes!
* PadLock microcode needs it that big. */
- char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
+ char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+ ((aligned(STACK_ALIGN)));
char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
struct sha1_state state;
@@ -135,7 +136,8 @@ static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in,
/* We can't store directly to *out as it may be unaligned. */
/* BTW Don't reduce the buffer size below 128 Bytes!
* PadLock microcode needs it that big. */
- char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN];
+ char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__
+ ((aligned(STACK_ALIGN)));
char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
struct sha256_state state;

--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2009-09-22 17:34:17

by Séguier Régis

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

Herbert Xu a ?crit :
> Herbert Xu <[email protected]> wrote:
>
>> crypto: padlock-sha - Fix stack alignment
>>
>> The PadLock hardware requires the output buffer for SHA to be
>> 128-bit aligned. We currentply place the buffer on the stack,
>> and ask gcc to align it to 128 bits. That doesn't work on i386
>> because the kernel stack is only aligned to 32 bits. This patch
>> changes the code to align the buffer by hand so that the hardware
>> doesn't fault on unaligned buffers.
>>
>> Reported-by: S?guier R?gis <[email protected]>
>> Tested-by: S?guier R?gis <[email protected]>
>> Signed-off-by: Herbert Xu <[email protected]>
>>
>
> For the record I modified the patch slightly to ensure that
> we get the minimum alignment from gcc
Ok, tested, good for me.

Just, not important, my mail is not [email protected] but
[email protected] for the changelog.

--
R?gis S?guier

2009-09-23 05:27:58

by Herbert Xu

[permalink] [raw]
Subject: Re: Padlock SHA1 failed at boot time

On Tue, Sep 22, 2009 at 07:34:17PM +0200, S?guier R?gis wrote:
>
> Ok, tested, good for me.

Thanks!

> Just, not important, my mail is not [email protected] but
> [email protected] for the changelog.

Sorry! But look on the bright side, at least you won't get spammed
because of this :)
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt