Tested, works fine.

I found in some manual that when using aligned without a specific size,
then "it will be aligned to the largest strict alignment for any natural
type (that is, integral or real) that can be handled on the target
machine."

Which is 8 for the Xscale ;)

Regards
Ronen Shitrit

-----Original Message-----
From: Herbert Xu [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 23, 2006 1:37 PM
To: Ronen Shitrit
Cc: [email protected]
Subject: Re: alignment exception on MD5 code.

On Sun, Jan 22, 2006 at 02:13:49PM +0200, Ronen Shitrit wrote:
> For example the Xscale datasheet defines:
> " Both LDRD and STRD instructions will generate an alignment exception
> when the address bits [2:0] = 0b100."
> 
> LDRD and STRD are load/store double instructions, and they are used
when
> using an u64 variable in C code, when compiling with the latest CSL
> compiler with the new ARM EABI.

Thanks for the info.  I'll apply the following patch to the crypto tree.
Could you please make sure the __aligned__ operator does the right thing
on your arch?

Cheers,
-- 
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
--
diff --git a/crypto/api.c b/crypto/api.c
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -148,24 +148,28 @@ static unsigned int crypto_ctxsize(struc
 {
        unsigned int len;
 
+       len = alg->cra_alignmask;
+       if (len < crypto_tfm_ctx_alignment())
+               len = 0;
+
        switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
        default:
                BUG();
 
        case CRYPTO_ALG_TYPE_CIPHER:
-               len = crypto_cipher_ctxsize(alg, flags);
+               len += crypto_cipher_ctxsize(alg, flags);
                break;
                
        case CRYPTO_ALG_TYPE_DIGEST:
-               len = crypto_digest_ctxsize(alg, flags);
+               len += crypto_digest_ctxsize(alg, flags);
                break;
                
        case CRYPTO_ALG_TYPE_COMPRESS:
-               len = crypto_compress_ctxsize(alg, flags);
+               len += crypto_compress_ctxsize(alg, flags);
                break;
        }
 
-       return len + alg->cra_alignmask;
+       return len;
 }
 
 struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -284,7 +284,11 @@ aes_hw_extkey_available(uint8_t key_len)
 
 static inline struct aes_ctx *aes_ctx(void *ctx)
 {
-       return (struct aes_ctx *)ALIGN((unsigned long)ctx,
PADLOCK_ALIGNMENT);
+       unsigned long align = PADLOCK_ALIGNMENT;
+
+       if (align <= crypto_tfm_ctx_alignment())
+               align = 1;
+       return (struct aes_ctx *)ALIGN((unsigned long)ctx, align);
 }
 
 static int
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -229,6 +229,8 @@ struct crypto_tfm {
        } crt_u;
        
        struct crypto_alg *__crt_alg;
+
+       char __crt_ctx[] __attribute__ ((__aligned__));
 };
 
 /* 
@@ -301,7 +303,13 @@ static inline unsigned int crypto_tfm_al
 
 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
 {
-       return (void *)&tfm[1];
+       return tfm->__crt_ctx;
+}
+
+static inline unsigned int crypto_tfm_ctx_alignment(void)
+{
+       struct crypto_tfm *tfm;
+       return __alignof__(tfm->__crt_ctx);
 }
 
 /*
-
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to