← Documents Documentation/arch/powerpc/transactional_memory.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Transactional Memory support

POWER userspace TM의 commit·rollback, signal ABI, failure cause와 POWER9 revision별 제한을 설명합니다.

Source pathDocumentation/arch/powerpc/transactional_memory.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

transactional_memory.rst:1-274

POWER TM은 `tbegin`의 checkpoint와 `tend` 사이 변경을 atomic하게 commit하거나 모두 rollback합니다. Linux ABI에서 가장 중요한 부분은 syscall의 persistent side effect, signal이 제공하는 두 register context, checkpointed stack 사용, 그리고 POWER9 revision마다 다른 HWCAP2 노출입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ============================
2 Transactional Memory support
3 ============================
4
5 POWER kernel support for this feature is currently limited to supporting
6 its use by user programs. It is not currently used by the kernel itself.
7
8 This file aims to sum up how it is supported by Linux and what behaviour you
9 can expect from your user programs.
10
11
12 Basic overview
13 ==============
14
15 Hardware Transactional Memory is supported on POWER8 processors, and is a
16 feature that enables a different form of atomic memory access. Several new
17 instructions are presented to delimit transactions; transactions are
18 guaranteed to either complete atomically or roll back and undo any partial
19 changes.
20
21 A simple transaction looks like this::
22
23 begin_move_money:
24 tbegin
25 beq abort_handler
26
27 ld r4, SAVINGS_ACCT(r3)
28 ld r5, CURRENT_ACCT(r3)
29 subi r5, r5, 1
30 addi r4, r4, 1
31 std r4, SAVINGS_ACCT(r3)
32 std r5, CURRENT_ACCT(r3)
33
34 tend
35
36 b continue
37
38 abort_handler:
39 ... test for odd failures ...
40
41 /* Retry the transaction if it failed because it conflicted with
42 * someone else: */
43 b begin_move_money
44
45
46 The 'tbegin' instruction denotes the start point, and 'tend' the end point.
47 Between these points the processor is in 'Transactional' state; any memory
48 references will complete in one go if there are no conflicts with other
49 transactional or non-transactional accesses within the system. In this
50 example, the transaction completes as though it were normal straight-line code
51 IF no other processor has touched SAVINGS_ACCT(r3) or CURRENT_ACCT(r3); an
52 atomic move of money from the current account to the savings account has been
53 performed. Even though the normal ld/std instructions are used (note no
54 lwarx/stwcx), either *both* SAVINGS_ACCT(r3) and CURRENT_ACCT(r3) will be
55 updated, or neither will be updated.
56
57 If, in the meantime, there is a conflict with the locations accessed by the
58 transaction, the transaction will be aborted by the CPU. Register and memory
59 state will roll back to that at the 'tbegin', and control will continue from
60 'tbegin+4'. The branch to abort_handler will be taken this second time; the
61 abort handler can check the cause of the failure, and retry.
62
63 Checkpointed registers include all GPRs, FPRs, VRs/VSRs, LR, CCR/CR, CTR, FPCSR
64 and a few other status/flag regs; see the ISA for details.
65
66 Causes of transaction aborts
67 ============================
68
69 - Conflicts with cache lines used by other processors
70 - Signals
71 - Context switches
72 - See the ISA for full documentation of everything that will abort transactions.
73
74
75 Syscalls
76 ========
77
78 Syscalls made from within an active transaction will not be performed and the
79 transaction will be doomed by the kernel with the failure code TM_CAUSE_SYSCALL
80 | TM_CAUSE_PERSISTENT.
81
82 Syscalls made from within a suspended transaction are performed as normal and
83 the transaction is not explicitly doomed by the kernel. However, what the
84 kernel does to perform the syscall may result in the transaction being doomed
85 by the hardware. The syscall is performed in suspended mode so any side
86 effects will be persistent, independent of transaction success or failure. No
87 guarantees are provided by the kernel about which syscalls will affect
88 transaction success.
89
90 Care must be taken when relying on syscalls to abort during active transactions
91 if the calls are made via a library. Libraries may cache values (which may
92 give the appearance of success) or perform operations that cause transaction
93 failure before entering the kernel (which may produce different failure codes).
94 Examples are glibc's getpid() and lazy symbol resolution.
95
96
97 Signals
98 =======
99
100 Delivery of signals (both sync and async) during transactions provides a second
101 thread state (ucontext/mcontext) to represent the second transactional register
102 state. Signal delivery 'treclaim's to capture both register states, so signals
103 abort transactions. The usual ucontext_t passed to the signal handler
104 represents the checkpointed/original register state; the signal appears to have
105 arisen at 'tbegin+4'.
106
107 If the sighandler ucontext has uc_link set, a second ucontext has been
108 delivered. For future compatibility the MSR.TS field should be checked to
109 determine the transactional state -- if so, the second ucontext in uc->uc_link
110 represents the active transactional registers at the point of the signal.
111
112 For 64-bit processes, uc->uc_mcontext.regs->msr is a full 64-bit MSR and its TS
113 field shows the transactional mode.
114
115 For 32-bit processes, the mcontext's MSR register is only 32 bits; the top 32
116 bits are stored in the MSR of the second ucontext, i.e. in
117 uc->uc_link->uc_mcontext.regs->msr. The top word contains the transactional
118 state TS.
119
120 However, basic signal handlers don't need to be aware of transactions
121 and simply returning from the handler will deal with things correctly:
122
123 Transaction-aware signal handlers can read the transactional register state
124 from the second ucontext. This will be necessary for crash handlers to
125 determine, for example, the address of the instruction causing the SIGSEGV.
126
127 Example signal handler::
128
129 void crash_handler(int sig, siginfo_t *si, void *uc)
130 {
131 ucontext_t *ucp = uc;
132 ucontext_t *transactional_ucp = ucp->uc_link;
133
134 if (ucp_link) {
135 u64 msr = ucp->uc_mcontext.regs->msr;
136 /* May have transactional ucontext! */
137 #ifndef __powerpc64__
138 msr |= ((u64)transactional_ucp->uc_mcontext.regs->msr) << 32;
139 #endif
140 if (MSR_TM_ACTIVE(msr)) {
141 /* Yes, we crashed during a transaction. Oops. */
142 fprintf(stderr, "Transaction to be restarted at 0x%llx, but "
143 "crashy instruction was at 0x%llx\n",
144 ucp->uc_mcontext.regs->nip,
145 transactional_ucp->uc_mcontext.regs->nip);
146 }
147 }
148
149 fix_the_problem(ucp->dar);
150 }
151
152 When in an active transaction that takes a signal, we need to be careful with
153 the stack. It's possible that the stack has moved back up after the tbegin.
154 The obvious case here is when the tbegin is called inside a function that
155 returns before a tend. In this case, the stack is part of the checkpointed
156 transactional memory state. If we write over this non transactionally or in
157 suspend, we are in trouble because if we get a tm abort, the program counter and
158 stack pointer will be back at the tbegin but our in memory stack won't be valid
159 anymore.
160
161 To avoid this, when taking a signal in an active transaction, we need to use
162 the stack pointer from the checkpointed state, rather than the speculated
163 state. This ensures that the signal context (written tm suspended) will be
164 written below the stack required for the rollback. The transaction is aborted
165 because of the treclaim, so any memory written between the tbegin and the
166 signal will be rolled back anyway.
167
168 For signals taken in non-TM or suspended mode, we use the
169 normal/non-checkpointed stack pointer.
170
171 Any transaction initiated inside a sighandler and suspended on return
172 from the sighandler to the kernel will get reclaimed and discarded.
173
174 Failure cause codes used by kernel
175 ==================================
176
177 These are defined in <asm/reg.h>, and distinguish different reasons why the
178 kernel aborted a transaction:
179
180 ====================== ================================
181 TM_CAUSE_RESCHED Thread was rescheduled.
182 TM_CAUSE_TLBI Software TLB invalid.
183 TM_CAUSE_FAC_UNAV FP/VEC/VSX unavailable trap.
184 TM_CAUSE_SYSCALL Syscall from active transaction.
185 TM_CAUSE_SIGNAL Signal delivered.
186 TM_CAUSE_MISC Currently unused.
187 TM_CAUSE_ALIGNMENT Alignment fault.
188 TM_CAUSE_EMULATE Emulation that touched memory.
189 ====================== ================================
190
191 These can be checked by the user program's abort handler as TEXASR[0:7]. If
192 bit 7 is set, it indicates that the error is considered persistent. For example
193 a TM_CAUSE_ALIGNMENT will be persistent while a TM_CAUSE_RESCHED will not.
194
195 GDB
196 ===
197
198 GDB and ptrace are not currently TM-aware. If one stops during a transaction,
199 it looks like the transaction has just started (the checkpointed state is
200 presented). The transaction cannot then be continued and will take the failure
201 handler route. Furthermore, the transactional 2nd register state will be
202 inaccessible. GDB can currently be used on programs using TM, but not sensibly
203 in parts within transactions.
204
205 POWER9
206 ======
207
208 TM on POWER9 has issues with storing the complete register state. This
209 is described in this commit::
210
211 commit 4bb3c7a0208fc13ca70598efd109901a7cd45ae7
212 Author: Paul Mackerras <paulus@ozlabs.org>
213 Date: Wed Mar 21 21:32:01 2018 +1100
214 KVM: PPC: Book3S HV: Work around transactional memory bugs in POWER9
215
216 To account for this different POWER9 chips have TM enabled in
217 different ways.
218
219 On POWER9N DD2.01 and below, TM is disabled. ie
220 HWCAP2[PPC_FEATURE2_HTM] is not set.
221
222 On POWER9N DD2.1 TM is configured by firmware to always abort a
223 transaction when tm suspend occurs. So tsuspend will cause a
224 transaction to be aborted and rolled back. Kernel exceptions will also
225 cause the transaction to be aborted and rolled back and the exception
226 will not occur. If userspace constructs a sigcontext that enables TM
227 suspend, the sigcontext will be rejected by the kernel. This mode is
228 advertised to users with HWCAP2[PPC_FEATURE2_HTM_NO_SUSPEND] set.
229 HWCAP2[PPC_FEATURE2_HTM] is not set in this mode.
230
231 On POWER9N DD2.2 and above, KVM and POWERVM emulate TM for guests (as
232 described in commit 4bb3c7a0208f), hence TM is enabled for guests
233 ie. HWCAP2[PPC_FEATURE2_HTM] is set for guest userspace. Guests that
234 makes heavy use of TM suspend (tsuspend or kernel suspend) will result
235 in traps into the hypervisor and hence will suffer a performance
236 degradation. Host userspace has TM disabled
237 ie. HWCAP2[PPC_FEATURE2_HTM] is not set. (although we make enable it
238 at some point in the future if we bring the emulation into host
239 userspace context switching).
240
241 POWER9C DD1.2 and above are only available with POWERVM and hence
242 Linux only runs as a guest. On these systems TM is emulated like on
243 POWER9N DD2.2.
244
245 Guest migration from POWER8 to POWER9 will work with POWER9N DD2.2 and
246 POWER9C DD1.2. Since earlier POWER9 processors don't support TM
247 emulation, migration from POWER8 to POWER9 is not supported there.
248
249 Kernel implementation
250 =====================
251
252 h/rfid mtmsrd quirk
253 -------------------
254
255 As defined in the ISA, rfid has a quirk which is useful in early
256 exception handling. When in a userspace transaction and we enter the
257 kernel via some exception, MSR will end up as TM=0 and TS=01 (ie. TM
258 off but TM suspended). Regularly the kernel will want change bits in
259 the MSR and will perform an rfid to do this. In this case rfid can
260 have SRR0 TM = 0 and TS = 00 (ie. TM off and non transaction) and the
261 resulting MSR will retain TM = 0 and TS=01 from before (ie. stay in
262 suspend). This is a quirk in the architecture as this would normally
263 be a transition from TS=01 to TS=00 (ie. suspend -> non transactional)
264 which is an illegal transition.
265
266 This quirk is described the architecture in the definition of rfid
267 with these lines:
268
269 if (MSR 29:31 ¬ = 0b010 | SRR1 29:31 ¬ = 0b000) then
270 MSR 29:31 <- SRR1 29:31
271
272 hrfid and mtmsrd have the same quirk.
273
274 The Linux kernel uses this quirk in its early exception handling.
275

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

POWER Transactional Memory 지원 범위

1-11

POWER kernel의 Transactional Memory(TM) 지원은 현재 userspace program이 이 기능을 사용하도록 돕는 범위로 제한됩니다. Kernel 자체는 TM을 사용하지 않습니다.

이 문서는 Linux가 Hardware Transactional Memory를 어떻게 지원하며 userspace program에서 어떤 동작을 기대할 수 있는지 정리합니다.

Hardware Transactional Memory 기본 동작

12-65

Hardware Transactional Memory는 POWER8 processor에서 지원하며 atomic memory access의 다른 형태를 제공합니다. 새 instruction들이 transaction 경계를 표시하고, transaction은 전체가 atomic하게 완료되거나 rollback되어 중간 변경이 모두 취소됩니다.

Account 사이에서 값을 이동하는 단순 transaction 예입니다.

begin_move_money:
  tbegin
  beq   abort_handler

  ld    r4, SAVINGS_ACCT(r3)
  ld    r5, CURRENT_ACCT(r3)
  subi  r5, r5, 1
  addi  r4, r4, 1
  std   r4, SAVINGS_ACCT(r3)
  std   r5, CURRENT_ACCT(r3)

  tend

  b     continue

abort_handler:
  ... test for odd failures ...

  /* Retry the transaction if it failed because it conflicted with
   * someone else: */
  b     begin_move_money

`tbegin`은 시작점, `tend`는 끝점을 나타냅니다. 이 사이에서 processor는 Transactional state이며, system의 다른 transactional 또는 non-transactional access와 conflict가 없으면 memory reference가 한 번에 완료됩니다.

예제에서 다른 processor가 `SAVINGS_ACCT(r3)`나 `CURRENT_ACCT(r3)`를 건드리지 않았다면 normal straight-line code처럼 완료되어 current account에서 savings account로 값이 atomic하게 이동합니다. 일반 `ld`/`std`를 사용하고 `lwarx`/`stwcx`를 쓰지 않아도 두 account가 모두 update되거나 둘 다 update되지 않습니다.

접근한 location과 conflict가 발생하면 CPU가 transaction을 abort합니다. Register와 memory state는 `tbegin` 시점으로 rollback되고 control은 `tbegin+4`에서 계속됩니다. 두 번째 실행에서는 `abort_handler` branch가 선택되며 handler가 failure cause를 검사하고 retry할 수 있습니다.

Checkpoint 대상에는 모든 GPR, FPR, VR/VSR, LR, CCR/CR, CTR, FPCSR와 일부 status/flag register가 포함됩니다. 세부 목록은 ISA를 따라야 합니다.

Transaction commit 또는 rollback
`tbegin` checkpointTransactional `ld`/`std`Conflict 없음`tend`Atomic commit
`tbegin` checkpointTransactional `ld`/`std`Conflict 발생Register/memory rollback`tbegin+4``abort_handler`

Conflict 유무에 따라 전체 memory update가 commit되거나 checkpoint state로 되돌아갑니다.

Transaction abort 원인

66-74
  • 다른 processor가 사용하는 cache line과의 conflict
  • Signal delivery
  • Context switch
  • 그 밖의 전체 abort 조건은 ISA에 정의됨

Transaction 안의 syscall

75-96

Active transaction 안에서 요청한 syscall은 실행되지 않습니다. Kernel은 `TM_CAUSE_SYSCALL | TM_CAUSE_PERSISTENT` failure code로 transaction을 doomed 상태로 만듭니다.

Suspended transaction 안의 syscall은 정상 수행되며 kernel이 transaction을 명시적으로 doomed 상태로 만들지 않습니다. 다만 syscall 구현 과정의 kernel 동작 때문에 hardware가 transaction을 doomed 상태로 만들 수 있습니다.

Syscall은 suspended mode에서 수행되므로 side effect는 transaction의 성공이나 실패와 무관하게 persistent합니다. 어떤 syscall이 transaction 성공에 영향을 주는지는 kernel이 보장하지 않습니다.

Library를 통해 호출할 때 active transaction의 syscall abort에 의존하면 주의해야 합니다. Library가 값을 cache하여 성공처럼 보이게 하거나 kernel 진입 전에 transaction failure를 일으켜 다른 failure code가 나올 수 있습니다. 예로 glibc의 `getpid()`와 lazy symbol resolution이 있습니다.

Signal delivery와 두 register state

97-126

Transaction 중 synchronous 또는 asynchronous signal을 전달할 때 두 번째 transactional register state를 나타내는 `ucontext`/`mcontext`가 추가됩니다. Signal delivery는 `treclaim`으로 두 register state를 capture하므로 transaction을 abort합니다.

Signal handler에 전달되는 일반 `ucontext_t`는 checkpointed/original register state를 나타내며, signal이 `tbegin+4`에서 발생한 것처럼 보입니다.

Handler의 `ucontext`에 `uc_link`가 set되어 있으면 두 번째 `ucontext`가 전달된 것입니다. Forward compatibility를 위해 `MSR.TS` field를 검사해 transactional state인지 확인해야 합니다. Transactional state라면 `uc->uc_link`가 signal 발생 시점의 active transactional register를 나타냅니다.

64-bit process에서는 `uc->uc_mcontext.regs->msr`가 full 64-bit MSR이며 TS field가 transactional mode를 표시합니다.

32-bit process의 mcontext MSR은 32-bit뿐이므로 상위 32 bit가 두 번째 ucontext의 `uc->uc_link->uc_mcontext.regs->msr`에 저장됩니다. Transactional state TS는 이 upper word에 있습니다.

기본 signal handler는 transaction을 알 필요가 없고 handler에서 단순히 return하면 정상 처리됩니다. 반면 crash handler처럼 SIGSEGV를 일으킨 instruction address를 알아야 하는 transaction-aware handler는 두 번째 ucontext의 transactional register state를 읽어야 합니다.

TM signal context 구성
Signal in active transaction`treclaim`Transaction abortPrimary `ucontext_t`Checkpointed state at `tbegin+4`
`uc_link` presentSecond `ucontext`Active transactional registers
32-bit processSecond context MSR upper word`MSR.TS`

Checkpointed state는 기본 ucontext에, signal 시점의 speculative state는 uc_link의 두 번째 ucontext에 들어갑니다.

Transaction-aware signal handler 예

127-151

다음 원문 예제는 `uc_link`의 두 번째 context와 `MSR_TM_ACTIVE(msr)`를 검사하여 transaction restart address와 실제 crash instruction address를 구분합니다.

  void crash_handler(int sig, siginfo_t *si, void *uc)
  {
    ucontext_t *ucp = uc;
    ucontext_t *transactional_ucp = ucp->uc_link;

    if (ucp_link) {
      u64 msr = ucp->uc_mcontext.regs->msr;
      /* May have transactional ucontext! */
#ifndef __powerpc64__
      msr |= ((u64)transactional_ucp->uc_mcontext.regs->msr) << 32;
#endif
      if (MSR_TM_ACTIVE(msr)) {
         /* Yes, we crashed during a transaction.  Oops. */
 fprintf(stderr, "Transaction to be restarted at 0x%llx, but "
                         "crashy instruction was at 0x%llx\n",
                         ucp->uc_mcontext.regs->nip,
                         transactional_ucp->uc_mcontext.regs->nip);
      }
    }

    fix_the_problem(ucp->dar);
  }

예제의 identifier와 indentation은 원문 그대로 보존했습니다. 구현 시 실제 선언과 field 접근을 사용 중인 ABI header에 맞춰 검토해야 합니다.

Signal frame과 checkpointed stack

152-173

Active transaction에서 signal을 받을 때는 stack을 주의해야 합니다. `tbegin` 뒤 stack이 위로 되돌아갔을 수 있습니다. 대표적으로 function 안에서 `tbegin`을 실행한 뒤 `tend` 전에 function이 return한 경우 stack 자체가 checkpointed transactional memory state의 일부입니다.

이 stack을 non-transactional mode나 suspended mode에서 덮어쓴 뒤 TM abort가 발생하면 program counter와 stack pointer는 `tbegin`으로 돌아가지만 memory의 stack 내용은 더 이상 유효하지 않습니다.

이를 피하려면 active transaction의 signal frame은 speculative state가 아니라 checkpointed state의 stack pointer를 사용해야 합니다. 그러면 TM suspended 상태에서 기록하는 signal context가 rollback에 필요한 stack 아래에 배치됩니다. `treclaim`으로 transaction이 abort되므로 `tbegin`과 signal 사이의 memory write는 어차피 rollback됩니다.

Non-TM 또는 suspended mode에서 받은 signal은 normal/non-checkpointed stack pointer를 사용합니다. Signal handler 내부에서 시작한 transaction이 handler return 시점에 suspended 상태라면 kernel이 reclaim하여 폐기합니다.

Active TM signal stack 선택
Speculative stack pointer사용하지 않음TM abort 시 invalid stack 위험
Checkpointed stack pointerSignal context 기록`treclaim`안전한 rollback
Non-TM / suspendedNormal stack pointer

Signal frame은 rollback 뒤에도 유효해야 하므로 checkpointed stack pointer 아래에 기록합니다.

Kernel transaction failure cause code

174-194

Kernel이 transaction을 abort한 원인을 구분하는 code는 `<asm/reg.h>`에 정의됩니다.

Kernel TM failure causes
Cause의미Persistence
`TM_CAUSE_RESCHED`Thread가 reschedule됨Non-persistent
`TM_CAUSE_TLBI`Software TLB invalidation상황에 따름
`TM_CAUSE_FAC_UNAV`FP/VEC/VSX unavailable trap상황에 따름
`TM_CAUSE_SYSCALL`Active transaction에서 syscallPersistent와 함께 사용
`TM_CAUSE_SIGNAL`Signal delivery상황에 따름
`TM_CAUSE_MISC`현재 사용하지 않음N/A
`TM_CAUSE_ALIGNMENT`Alignment faultPersistent
`TM_CAUSE_EMULATE`Memory를 건드린 emulation상황에 따름

원문 표의 cause symbol과 의미, persistent 예를 보존했습니다.

Userspace abort handler는 `TEXASR[0:7]`에서 cause를 확인할 수 있습니다. Bit 7이 set되면 persistent error입니다. 예를 들어 `TM_CAUSE_ALIGNMENT`는 persistent이고 `TM_CAUSE_RESCHED`는 persistent가 아닙니다.

GDB와 ptrace 제한

195-204

현재 GDB와 ptrace는 TM-aware가 아닙니다. Transaction 중 stop하면 checkpointed state가 제시되어 transaction이 막 시작된 것처럼 보입니다.

이 상태에서는 transaction을 계속할 수 없고 failure handler 경로를 타며, 두 번째 transactional register state에도 접근할 수 없습니다. GDB로 TM program 자체를 다룰 수는 있지만 transaction 내부를 의미 있게 debug할 수는 없습니다.

POWER9 revision별 TM 동작

205-248

POWER9 TM에는 complete register state 저장 문제가 있습니다. 원문은 이를 우회한 commit을 제시합니다.

commit 4bb3c7a0208fc13ca70598efd109901a7cd45ae7
Author: Paul Mackerras <paulus@ozlabs.org>
Date:   Wed Mar 21 21:32:01 2018 +1100
KVM: PPC: Book3S HV: Work around transactional memory bugs in POWER9

이 차이 때문에 POWER9 chip revision마다 TM enable 방식이 다릅니다.

POWER9 TM 지원 matrix
ProcessorModeHWCAP2동작
POWER9N DD2.01 이하Disabled`PPC_FEATURE2_HTM` clearTM을 사용할 수 없음
POWER9N DD2.1No suspend`PPC_FEATURE2_HTM_NO_SUSPEND` set, `PPC_FEATURE2_HTM` clear`tsuspend`와 kernel exception이 transaction을 abort/rollback
POWER9N DD2.2 이상 guestHypervisor emulation`PPC_FEATURE2_HTM` setKVM/POWERVM이 TM을 emulate하며 suspend 사용 시 trap 비용 발생
POWER9C DD1.2 이상Guest-only emulation`PPC_FEATURE2_HTM` setPOWERVM guest에서 POWER9N DD2.2와 같은 방식

POWER9N/POWER9C revision과 userspace HWCAP2 노출, emulation 동작을 비교합니다.

POWER9N DD2.1에서는 firmware가 TM suspend 시 항상 abort하도록 구성합니다. `tsuspend`와 kernel exception은 transaction을 abort하고 rollback하며 exception 자체는 발생하지 않습니다. TM suspend를 enable한 sigcontext도 kernel이 거부합니다.

POWER9N DD2.2 이상에서는 KVM과 POWERVM이 guest TM을 emulate합니다. Guest userspace에는 `HWCAP2[PPC_FEATURE2_HTM]`이 set되지만 TM suspend를 많이 사용하면 hypervisor trap 때문에 성능이 저하됩니다. Host userspace에는 현재 TM이 disabled이며 향후 host context-switch emulation이 추가되면 달라질 수 있습니다.

POWER9C DD1.2 이상은 POWERVM에서만 제공되어 Linux는 guest로 실행되고 POWER9N DD2.2와 같이 TM을 emulate합니다.

POWER8 guest를 POWER9로 migration하는 것은 TM emulation이 있는 POWER9N DD2.2와 POWER9C DD1.2에서 가능합니다. 더 이른 POWER9 processor에는 emulation이 없어 지원되지 않습니다.

Kernel의 h/rfid mtmsrd quirk 사용

249-274

ISA의 `rfid` quirk는 early exception handling에 유용합니다. Userspace transaction에서 exception으로 kernel에 들어오면 MSR은 `TM=0`, `TS=01`, 즉 TM은 off지만 suspended 상태가 됩니다.

Kernel이 MSR bit를 바꾸기 위해 `rfid`를 수행하면서 SRR0에 `TM=0`, `TS=00`을 지정해도 결과 MSR은 이전의 `TM=0`, `TS=01`을 유지할 수 있습니다. 보통 `TS=01`에서 `TS=00`으로 가는 suspend-to-non-transactional 전이는 illegal이지만 architecture가 이 경우를 quirk로 허용합니다.

Architecture의 `rfid` 정의는 다음 조건으로 이를 설명합니다.

if (MSR 29:31 ¬ = 0b010 | SRR1 29:31 ¬ = 0b000) then
   MSR 29:31 <- SRR1 29:31

`hrfid`와 `mtmsrd`에도 같은 quirk가 있으며 Linux kernel은 early exception handling에서 이를 사용합니다.

rfid TM state quirk
Exception entry`MSR TM=0, TS=01``rfid` with `SRR1 TS=00`Quirk 적용`MSR TS=01` 유지
`hrfid` / `mtmsrd`같은 quirk

SRR1이 non-transactional state를 요청해도 조건에 따라 기존 suspended state가 유지됩니다.