mem_alignment.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ================
  2. Memory alignment
  3. ================
  4. Too many problems popped up because of unnoticed misaligned memory access in
  5. kernel code lately. Therefore the alignment fixup is now unconditionally
  6. configured in for SA11x0 based targets. According to Alan Cox, this is a
  7. bad idea to configure it out, but Russell King has some good reasons for
  8. doing so on some f***ed up ARM architectures like the EBSA110. However
  9. this is not the case on many design I'm aware of, like all SA11x0 based
  10. ones.
  11. Of course this is a bad idea to rely on the alignment trap to perform
  12. unaligned memory access in general. If those access are predictable, you
  13. are better to use the macros provided by include/asm/unaligned.h. The
  14. alignment trap can fixup misaligned access for the exception cases, but at
  15. a high performance cost. It better be rare.
  16. Now for user space applications, it is possible to configure the alignment
  17. trap to SIGBUS any code performing unaligned access (good for debugging bad
  18. code), or even fixup the access by software like for kernel code. The later
  19. mode isn't recommended for performance reasons (just think about the
  20. floating point emulation that works about the same way). Fix your code
  21. instead!
  22. Please note that randomly changing the behaviour without good thought is
  23. real bad - it changes the behaviour of all unaligned instructions in user
  24. space, and might cause programs to fail unexpectedly.
  25. To change the alignment trap behavior, simply echo a number into
  26. /proc/cpu/alignment. The number is made up from various bits:
  27. === ========================================================
  28. bit behavior when set
  29. === ========================================================
  30. 0 A user process performing an unaligned memory access
  31. will cause the kernel to print a message indicating
  32. process name, pid, pc, instruction, address, and the
  33. fault code.
  34. 1 The kernel will attempt to fix up the user process
  35. performing the unaligned access. This is of course
  36. slow (think about the floating point emulator) and
  37. not recommended for production use.
  38. 2 The kernel will send a SIGBUS signal to the user process
  39. performing the unaligned access.
  40. === ========================================================
  41. Note that not all combinations are supported - only values 0 through 5.
  42. (6 and 7 don't make sense).
  43. For example, the following will turn on the warnings, but without
  44. fixing up or sending SIGBUS signals::
  45. echo 1 > /proc/cpu/alignment
  46. You can also read the content of the same file to get statistical
  47. information on unaligned access occurrences plus the current mode of
  48. operation for user space code.
  49. Nicolas Pitre, Mar 13, 2001. Modified Russell King, Nov 30, 2001.