요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=========================================
Tagged virtual addresses in AArch64 Linux
=========================================
Author: Will Deacon <will.deacon@arm.com>
Date : 12 June 2013
This document briefly describes the provision of tagged virtual
addresses in the AArch64 translation system and their potential uses
in AArch64 Linux.
The kernel configures the translation tables so that translations made
via TTBR0 (i.e. userspace mappings) have the top byte (bits 63:56) of
the virtual address ignored by the translation hardware. This frees up
this byte for application use.
Passing tagged addresses to the kernel
--------------------------------------
All interpretation of userspace memory addresses by the kernel assumes
an address tag of 0x00, unless the application enables the AArch64
Tagged Address ABI explicitly
(Documentation/arch/arm64/tagged-address-abi.rst).
This includes, but is not limited to, addresses found in:
- pointer arguments to system calls, including pointers in structures
passed to system calls,
- the stack pointer (sp), e.g. when interpreting it to deliver a
signal,
- the frame pointer (x29) and frame records, e.g. when interpreting
them to generate a backtrace or call graph.
Using non-zero address tags in any of these locations when the
userspace application did not enable the AArch64 Tagged Address ABI may
result in an error code being returned, a (fatal) signal being raised,
or other modes of failure.
For these reasons, when the AArch64 Tagged Address ABI is disabled,
passing non-zero address tags to the kernel via system calls is
forbidden, and using a non-zero address tag for sp is strongly
discouraged.
Programs maintaining a frame pointer and frame records that use non-zero
address tags may suffer impaired or inaccurate debug and profiling
visibility.
Preserving tags
---------------
When delivering signals, non-zero tags are not preserved in
siginfo.si_addr unless the flag SA_EXPOSE_TAGBITS was set in
sigaction.sa_flags when the signal handler was installed. This means
that signal handlers in applications making use of tags cannot rely
on the tag information for user virtual addresses being maintained
in these fields unless the flag was set.
If FEAT_MTE_TAGGED_FAR (Armv8.9) is supported, bits 63:60 of the fault address
are preserved in response to synchronous tag check faults (SEGV_MTESERR)
otherwise not preserved even if SA_EXPOSE_TAGBITS was set.
Applications should interpret the values of these bits based on
the support for the HWCAP3_MTE_FAR. If the support is not present,
the values of these bits should be considered as undefined otherwise valid.
For signals raised in response to watchpoint debug exceptions, the
tag information will be preserved regardless of the SA_EXPOSE_TAGBITS
flag setting.
Non-zero tags are never preserved in sigcontext.fault_address
regardless of the SA_EXPOSE_TAGBITS flag setting.
The architecture prevents the use of a tagged PC, so the upper byte will
be set to a sign-extension of bit 55 on exception return.
This behaviour is maintained when the AArch64 Tagged Address ABI is
enabled.
Other considerations
--------------------
Special care should be taken when using tagged pointers, since it is
likely that C compilers will not hazard two virtual addresses differing
only in the upper byte.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Tagged virtual address 배치
1-18저자: Will Deacon, 2013-06-12. 이 문서는 AArch64 translation system의 tagged virtual address 제공 방식과 Linux에서의 잠재적 용도를 설명합니다.
Kernel은 `TTBR0`, 즉 userspace mapping의 translation에서 virtual address top byte(bit 63:56)를 hardware가 무시하도록 table을 설정합니다. 따라서 application이 이 byte를 tag 용도로 사용할 수 있습니다.
Kernel에 tagged address 전달
19-52Application이 `Documentation/arch/arm64/tagged-address-abi.rst`의 AArch64 Tagged Address ABI를 명시적으로 enable하지 않으면 kernel은 모든 userspace memory address의 tag를 `0x00`으로 가정합니다.
| 주소 위치 | Kernel이 해석하는 예 |
|---|---|
| System-call pointer | 직접 argument와 syscall structure 안의 pointer |
| Stack pointer `sp` | Signal 전달을 위해 stack을 해석할 때 |
| Frame pointer `x29`와 frame record | Backtrace나 call graph 생성 |
ABI를 enable하지 않은 상태에서 이 위치에 non-zero tag를 쓰면 error, fatal signal 또는 다른 실패가 가능합니다. 따라서 syscall로 전달하는 것은 금지되고 `sp`에 쓰는 것도 강하게 권장되지 않습니다. Frame pointer와 frame record에 tag를 쓰면 debugging·profiling 가시성이 손상되거나 부정확할 수 있습니다.
Signal에서 tag 보존
53-83| 경로 | Tag 보존 규칙 |
|---|---|
| `siginfo.si_addr` | Handler 설치 시 `sigaction.sa_flags`에 `SA_EXPOSE_TAGBITS`가 있어야 non-zero tag 보존 |
| `SEGV_MTESERR` | `FEAT_MTE_TAGGED_FAR`(Armv8.9)와 `HWCAP3_MTE_FAR`가 있으면 fault address bit 63:60 유효, 없으면 undefined |
| Watchpoint debug exception | `SA_EXPOSE_TAGBITS`와 무관하게 tag 보존 |
| `sigcontext.fault_address` | `SA_EXPOSE_TAGBITS`와 무관하게 non-zero tag를 절대 보존하지 않음 |
Architecture는 tagged PC를 허용하지 않으므로 exception return 때 upper byte를 bit 55의 sign extension으로 설정합니다. 이 규칙은 Tagged Address ABI를 enable해도 유지됩니다.
기타 고려 사항
84-89Tagged pointer를 사용할 때는 각별히 주의해야 합니다. C compiler가 upper byte만 다른 두 virtual address 사이의 hazard를 인식한다고 기대하기 어렵기 때문입니다.
요약과 해설
tagged-pointers.rst:1-89AArch64는 userspace address의 bit 63:56을 translation에서 무시하지만 kernel ABI는 별도 opt-in 전에는 tag 0을 전제로 합니다. Signal interface도 `SA_EXPOSE_TAGBITS`, MTE FAR 지원, fault 종류에 따라 tag 보존 범위가 다릅니다.
Application tag가 hardware translation과 kernel ABI를 통과하는 과정입니다.
Fault 정보가 tag를 유지하는 조건입니다.