tagged-pointers.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. =========================================
  2. Tagged virtual addresses in AArch64 Linux
  3. =========================================
  4. Author: Will Deacon <will.deacon@arm.com>
  5. Date : 12 June 2013
  6. This document briefly describes the provision of tagged virtual
  7. addresses in the AArch64 translation system and their potential uses
  8. in AArch64 Linux.
  9. The kernel configures the translation tables so that translations made
  10. via TTBR0 (i.e. userspace mappings) have the top byte (bits 63:56) of
  11. the virtual address ignored by the translation hardware. This frees up
  12. this byte for application use.
  13. Passing tagged addresses to the kernel
  14. --------------------------------------
  15. All interpretation of userspace memory addresses by the kernel assumes
  16. an address tag of 0x00, unless the application enables the AArch64
  17. Tagged Address ABI explicitly
  18. (Documentation/arm64/tagged-address-abi.rst).
  19. This includes, but is not limited to, addresses found in:
  20. - pointer arguments to system calls, including pointers in structures
  21. passed to system calls,
  22. - the stack pointer (sp), e.g. when interpreting it to deliver a
  23. signal,
  24. - the frame pointer (x29) and frame records, e.g. when interpreting
  25. them to generate a backtrace or call graph.
  26. Using non-zero address tags in any of these locations when the
  27. userspace application did not enable the AArch64 Tagged Address ABI may
  28. result in an error code being returned, a (fatal) signal being raised,
  29. or other modes of failure.
  30. For these reasons, when the AArch64 Tagged Address ABI is disabled,
  31. passing non-zero address tags to the kernel via system calls is
  32. forbidden, and using a non-zero address tag for sp is strongly
  33. discouraged.
  34. Programs maintaining a frame pointer and frame records that use non-zero
  35. address tags may suffer impaired or inaccurate debug and profiling
  36. visibility.
  37. Preserving tags
  38. ---------------
  39. When delivering signals, non-zero tags are not preserved in
  40. siginfo.si_addr unless the flag SA_EXPOSE_TAGBITS was set in
  41. sigaction.sa_flags when the signal handler was installed. This means
  42. that signal handlers in applications making use of tags cannot rely
  43. on the tag information for user virtual addresses being maintained
  44. in these fields unless the flag was set.
  45. Due to architecture limitations, bits 63:60 of the fault address
  46. are not preserved in response to synchronous tag check faults
  47. (SEGV_MTESERR) even if SA_EXPOSE_TAGBITS was set. Applications should
  48. treat the values of these bits as undefined in order to accommodate
  49. future architecture revisions which may preserve the bits.
  50. For signals raised in response to watchpoint debug exceptions, the
  51. tag information will be preserved regardless of the SA_EXPOSE_TAGBITS
  52. flag setting.
  53. Non-zero tags are never preserved in sigcontext.fault_address
  54. regardless of the SA_EXPOSE_TAGBITS flag setting.
  55. The architecture prevents the use of a tagged PC, so the upper byte will
  56. be set to a sign-extension of bit 55 on exception return.
  57. This behaviour is maintained when the AArch64 Tagged Address ABI is
  58. enabled.
  59. Other considerations
  60. --------------------
  61. Special care should be taken when using tagged pointers, since it is
  62. likely that C compilers will not hazard two virtual addresses differing
  63. only in the upper byte.