Subject: Re: Seeing new kernel unaligned access messages in linux-next on ia64

From: Andreas Schwab <[email-masked]>
Date: Wed, 24 Mar 2010 23:47:24 +0100

Jan Engelhardt <[email-masked]> writes:

> Using a temporary and memcpying it off would normally fix this,
> as in the patch below. During testing however, I still get
> unaligned messages even with the patch - and I would not know
> what causes this.

The memcpy will not fix the alignment issue because the copy operation
is fully equivalent to a direct assignment, and the compiler can still
take advantage of the known alignment of the types.  You have to
explicitly tell the compiler about the reduced alignment guarantee.

> In fact, adding a printks magically fixes it. (Bug in gcc-4.4-sparc
> compiler?)
>
>  	memcpy(v, &a, sizeof(a));
> +       printk(KERN_INFO "v=%p a=%p\n", v, &a);

Presumably the extended lifetime of the variables caused the compiler to
use a different expansion for memcpy which is less dependent on
alignment.

Andreas.

-- 
Andreas Schwab, [email-masked]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."