← Documents Documentation/arch/arm64/asymmetric-32bit.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Asymmetric 32-bit SoCs

일부 CPU만 AArch32 EL0를 지원하는 Armv9 SoC의 opt-in, execve affinity 복원, deadline·cpuset·hotplug·KVM·NOHZ 제약을 설명합니다.

Source pathDocumentation/arch/arm64/asymmetric-32bit.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

asymmetric-32bit.rst:1-163

`allow_mismatched_32bit_el0`는 전환기 SoC에서 32-bit binary를 실행하게 하지만 CPU affinity를 동적으로 제한하므로 userspace에 완전히 투명하지 않습니다. Recompile이나 emulation이 가능하다면 그 방법이 더 안정적입니다.

32-bit execve affinity 결정
32-bit execve현재 mask의 AArch32 subset비어 있지 않음subset 적용 + 이전 mask 저장
Subset 없음cpuset ancestor 검색AArch32 subset 적용실패 시 전체 capable CPU
후속 64-bit execve저장 mask 복원 시도실패 시 현재 affinity 유지

현재 mask에서 시작해 cpuset ancestor와 전체 capable CPU 집합으로 단계적으로 fallback합니다.

비대칭 32-bit의 주요 제약
영역정책
sysfs`aarch32_el0`에 발견된 capable CPU를 누적
SCHED_DEADLINE별도 root domain 권장
CPU hotplug첫 capable CPU offline 금지
KVMGuest 32-bit EL0 미광고, 잘못된 진입은 FAIL_ENTRY
NOHZ FULLAdaptive-ticks CPU를 64-bit 전용 취급

CPU capability 차이가 각 subsystem의 정책으로 드러납니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ======================
2 Asymmetric 32-bit SoCs
3 ======================
4
5 Author: Will Deacon <will@kernel.org>
6
7 This document describes the impact of asymmetric 32-bit SoCs on the
8 execution of 32-bit (``AArch32``) applications.
9
10 Date: 2021-05-17
11
12 Introduction
13 ============
14
15 Some Armv9 SoCs suffer from a big.LITTLE misfeature where only a subset
16 of the CPUs are capable of executing 32-bit user applications. On such
17 a system, Linux by default treats the asymmetry as a "mismatch" and
18 disables support for both the ``PER_LINUX32`` personality and
19 ``execve(2)`` of 32-bit ELF binaries, with the latter returning
20 ``-ENOEXEC``. If the mismatch is detected during late onlining of a
21 64-bit-only CPU, then the onlining operation fails and the new CPU is
22 unavailable for scheduling.
23
24 Surprisingly, these SoCs have been produced with the intention of
25 running legacy 32-bit binaries. Unsurprisingly, that doesn't work very
26 well with the default behaviour of Linux.
27
28 It seems inevitable that future SoCs will drop 32-bit support
29 altogether, so if you're stuck in the unenviable position of needing to
30 run 32-bit code on one of these transitionary platforms then you would
31 be wise to consider alternatives such as recompilation, emulation or
32 retirement. If neither of those options are practical, then read on.
33
34 Enabling kernel support
35 =======================
36
37 Since the kernel support is not completely transparent to userspace,
38 allowing 32-bit tasks to run on an asymmetric 32-bit system requires an
39 explicit "opt-in" and can be enabled by passing the
40 ``allow_mismatched_32bit_el0`` parameter on the kernel command-line.
41
42 For the remainder of this document we will refer to an *asymmetric
43 system* to mean an asymmetric 32-bit SoC running Linux with this kernel
44 command-line option enabled.
45
46 Userspace impact
47 ================
48
49 32-bit tasks running on an asymmetric system behave in mostly the same
50 way as on a homogeneous system, with a few key differences relating to
51 CPU affinity.
52
53 sysfs
54 -----
55
56 The subset of CPUs capable of running 32-bit tasks is described in
57 ``/sys/devices/system/cpu/aarch32_el0`` and is documented further in
58 Documentation/ABI/testing/sysfs-devices-system-cpu.
59
60 **Note:** CPUs are advertised by this file as they are detected and so
61 late-onlining of 32-bit-capable CPUs can result in the file contents
62 being modified by the kernel at runtime. Once advertised, CPUs are never
63 removed from the file.
64
65 ``execve(2)``
66 -------------
67
68 On a homogeneous system, the CPU affinity of a task is preserved across
69 ``execve(2)``. This is not always possible on an asymmetric system,
70 specifically when the new program being executed is 32-bit yet the
71 affinity mask contains 64-bit-only CPUs. In this situation, the kernel
72 determines the new affinity mask as follows:
73
74 1. If the 32-bit-capable subset of the affinity mask is not empty,
75 then the affinity is restricted to that subset and the old affinity
76 mask is saved. This saved mask is inherited over ``fork(2)`` and
77 preserved across ``execve(2)`` of 32-bit programs.
78
79 **Note:** This step does not apply to ``SCHED_DEADLINE`` tasks.
80 See `SCHED_DEADLINE`_.
81
82 2. Otherwise, the cpuset hierarchy of the task is walked until an
83 ancestor is found containing at least one 32-bit-capable CPU. The
84 affinity of the task is then changed to match the 32-bit-capable
85 subset of the cpuset determined by the walk.
86
87 3. On failure (i.e. out of memory), the affinity is changed to the set
88 of all 32-bit-capable CPUs of which the kernel is aware.
89
90 A subsequent ``execve(2)`` of a 64-bit program by the 32-bit task will
91 invalidate the affinity mask saved in (1) and attempt to restore the CPU
92 affinity of the task using the saved mask if it was previously valid.
93 This restoration may fail due to intervening changes to the deadline
94 policy or cpuset hierarchy, in which case the ``execve(2)`` continues
95 with the affinity unchanged.
96
97 Calls to ``sched_setaffinity(2)`` for a 32-bit task will consider only
98 the 32-bit-capable CPUs of the requested affinity mask. On success, the
99 affinity for the task is updated and any saved mask from a prior
100 ``execve(2)`` is invalidated.
101
102 ``SCHED_DEADLINE``
103 ------------------
104
105 Explicit admission of a 32-bit deadline task to the default root domain
106 (e.g. by calling ``sched_setattr(2)``) is rejected on an asymmetric
107 32-bit system unless admission control is disabled by writing -1 to
108 ``/proc/sys/kernel/sched_rt_runtime_us``.
109
110 ``execve(2)`` of a 32-bit program from a 64-bit deadline task will
111 return ``-ENOEXEC`` if the root domain for the task contains any
112 64-bit-only CPUs and admission control is enabled. Concurrent offlining
113 of 32-bit-capable CPUs may still necessitate the procedure described in
114 `execve(2)`_, in which case step (1) is skipped and a warning is
115 emitted on the console.
116
117 **Note:** It is recommended that a set of 32-bit-capable CPUs are placed
118 into a separate root domain if ``SCHED_DEADLINE`` is to be used with
119 32-bit tasks on an asymmetric system. Failure to do so is likely to
120 result in missed deadlines.
121
122 Cpusets
123 -------
124
125 The affinity of a 32-bit task on an asymmetric system may include CPUs
126 that are not explicitly allowed by the cpuset to which it is attached.
127 This can occur as a result of the following two situations:
128
129 - A 64-bit task attached to a cpuset which allows only 64-bit CPUs
130 executes a 32-bit program.
131
132 - All of the 32-bit-capable CPUs allowed by a cpuset containing a
133 32-bit task are offlined.
134
135 In both of these cases, the new affinity is calculated according to step
136 (2) of the process described in `execve(2)`_ and the cpuset hierarchy is
137 unchanged irrespective of the cgroup version.
138
139 CPU hotplug
140 -----------
141
142 On an asymmetric system, the first detected 32-bit-capable CPU is
143 prevented from being offlined by userspace and any such attempt will
144 return ``-EPERM``. Note that suspend is still permitted even if the
145 primary CPU (i.e. CPU 0) is 64-bit-only.
146
147 KVM
148 ---
149
150 Although KVM will not advertise 32-bit EL0 support to any vCPUs on an
151 asymmetric system, a broken guest at EL1 could still attempt to execute
152 32-bit code at EL0. In this case, an exit from a vCPU thread in 32-bit
153 mode will return to host userspace with an ``exit_reason`` of
154 ``KVM_EXIT_FAIL_ENTRY`` and will remain non-runnable until successfully
155 re-initialised by a subsequent ``KVM_ARM_VCPU_INIT`` operation.
156
157 NOHZ FULL
158 ---------
159
160 To avoid perturbing an adaptive-ticks CPU (specified using
161 ``nohz_full=``) when a 32-bit task is forcefully migrated, these CPUs
162 are treated as 64-bit-only when support for asymmetric 32-bit systems
163 is enabled.
164

3. 한국어 전문 번역

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

문서 정보와 적용 대상

1-11

문서 제목은 `Asymmetric 32-bit SoCs`, 작성자는 Will Deacon `<will@kernel.org>`, 날짜는 `2021-05-17`입니다.

비대칭 32-bit SoC가 32-bit, 즉 `AArch32` application 실행에 주는 영향을 설명합니다.

기본 Linux 동작과 대안

12-33

일부 Armv9 SoC에는 CPU 일부만 32-bit user application을 실행할 수 있는 big.LITTLE 결함이 있습니다. Linux는 기본적으로 이 비대칭을 mismatch로 취급해 `PER_LINUX32` personality와 32-bit ELF binary의 `execve(2)`를 모두 비활성화하며, 후자는 `-ENOEXEC`을 반환합니다.

64-bit 전용 CPU를 늦게 online하는 중 mismatch를 감지하면 online 작업이 실패하고 새 CPU를 scheduling에 사용할 수 없습니다.

이런 SoC가 legacy 32-bit binary 실행을 목적으로 만들어졌지만 Linux 기본 동작과는 잘 맞지 않습니다. 향후 SoC는 32-bit 지원을 완전히 제거할 가능성이 높으므로 전환기 platform에서 32-bit code를 실행해야 한다면 recompilation, emulation 또는 retirement를 먼저 고려해야 합니다. 모두 현실적이지 않을 때만 아래 opt-in을 사용하십시오.

Kernel 지원 활성화

34-45

Kernel 지원은 userspace에 완전히 투명하지 않으므로 비대칭 32-bit 시스템에서 32-bit task 실행을 허용하려면 명시적으로 opt-in해야 합니다. Kernel command line에 `allow_mismatched_32bit_el0`를 전달합니다.

이 문서의 나머지 부분에서 asymmetric system은 이 command-line option을 활성화한 채 Linux를 실행하는 비대칭 32-bit SoC를 뜻합니다.

Userspace 영향과 sysfs

46-64

Asymmetric system의 32-bit task는 대체로 homogeneous system과 같지만 CPU affinity와 관련된 몇 가지 중요한 차이가 있습니다.

32-bit task를 실행할 수 있는 CPU subset은 `/sys/devices/system/cpu/aarch32_el0`에 표시하며 `Documentation/ABI/testing/sysfs-devices-system-cpu`에 자세히 문서화되어 있습니다.

CPU는 발견되는 즉시 이 file에 추가됩니다. 32-bit capable CPU를 늦게 online하면 runtime에 내용이 바뀔 수 있지만, 한 번 표시한 CPU는 file에서 제거하지 않습니다.

execve(2)와 CPU affinity

65-101

Homogeneous system에서는 `execve(2)` 전후에 task의 CPU affinity가 유지됩니다. Asymmetric system에서 새 program은 32-bit인데 affinity mask에 64-bit 전용 CPU가 포함된 경우에는 그대로 유지할 수 없습니다. Kernel은 새 affinity mask를 다음 순서로 정합니다.

  • 1. 현재 affinity mask에서 32-bit capable CPU subset이 비어 있지 않으면 그 subset으로 affinity를 제한하고 기존 mask를 저장합니다. 저장한 mask는 `fork(2)`로 상속되고 32-bit program의 `execve(2)`를 거쳐 보존됩니다. 이 단계는 `SCHED_DEADLINE` task에는 적용하지 않습니다.
  • 2. 그렇지 않으면 task의 cpuset hierarchy를 올라가며 32-bit capable CPU를 하나 이상 포함한 ancestor를 찾습니다. 그 cpuset에서 32-bit capable subset을 구해 task affinity로 설정합니다.
  • 3. Out-of-memory 같은 실패가 발생하면 kernel이 알고 있는 모든 32-bit capable CPU의 집합으로 affinity를 바꿉니다.

32-bit task가 나중에 64-bit program을 `execve(2)`하면 1단계에서 저장한 mask를 무효화하고, 이전에 유효했다면 그 mask로 task의 CPU affinity 복원을 시도합니다. 그 사이 deadline policy나 cpuset hierarchy가 바뀌어 복원에 실패할 수 있으며, 이때 `execve(2)`는 affinity를 바꾸지 않고 계속됩니다.

32-bit task에 대한 `sched_setaffinity(2)`는 요청 mask의 32-bit capable CPU만 고려합니다. 성공하면 task affinity를 갱신하고 이전 `execve(2)`가 저장한 mask를 무효화합니다.

SCHED_DEADLINE

102-121

비대칭 32-bit 시스템에서 32-bit deadline task를 기본 root domain에 명시적으로 admission하는 작업, 예를 들어 `sched_setattr(2)` 호출은 admission control을 끄지 않은 한 거부됩니다. Admission control은 `/proc/sys/kernel/sched_rt_runtime_us`에 `-1`을 써서 끌 수 있습니다.

64-bit deadline task가 32-bit program을 `execve(2)`할 때 task의 root domain에 64-bit 전용 CPU가 하나라도 있고 admission control이 켜져 있으면 `-ENOEXEC`을 반환합니다. 32-bit capable CPU를 동시에 offline하는 상황에서는 앞의 `execve(2)` 절차가 여전히 필요할 수 있으며, 이때 1단계를 건너뛰고 console에 warning을 출력합니다.

Asymmetric system에서 32-bit task와 `SCHED_DEADLINE`을 함께 사용하려면 32-bit capable CPU 집합을 별도 root domain에 두기를 권장합니다. 그렇지 않으면 deadline을 놓칠 가능성이 큽니다.

Cpuset

122-138

Asymmetric system의 32-bit task affinity에는 연결된 cpuset이 명시적으로 허용하지 않은 CPU가 포함될 수 있습니다. 다음 두 상황에서 발생합니다.

  • 64-bit CPU만 허용하는 cpuset에 연결된 64-bit task가 32-bit program을 실행합니다.
  • 32-bit task를 포함한 cpuset이 허용하던 32-bit capable CPU가 모두 offline됩니다.

두 경우 모두 앞 `execve(2)` 절차의 2단계에 따라 새 affinity를 계산합니다. Cgroup version과 관계없이 cpuset hierarchy 자체는 바뀌지 않습니다.

CPU hotplug

139-146

Asymmetric system에서 처음 감지한 32-bit capable CPU는 userspace가 offline할 수 없으며 시도하면 `-EPERM`을 반환합니다. Primary CPU인 CPU 0이 64-bit 전용이어도 suspend는 허용됩니다.

KVM

147-156

KVM은 asymmetric system의 어떤 vCPU에도 32-bit EL0 지원을 알리지 않습니다. 그래도 손상된 EL1 guest가 EL0에서 32-bit code 실행을 시도할 수 있습니다.

이 경우 32-bit mode의 vCPU thread에서 exit하면 host userspace에 `exit_reason`이 `KVM_EXIT_FAIL_ENTRY`인 상태로 돌아오며, 뒤의 `KVM_ARM_VCPU_INIT` 작업이 성공적으로 다시 초기화할 때까지 실행할 수 없습니다.

NOHZ FULL

157-163

32-bit task를 강제로 migrate할 때 `nohz_full=`로 지정한 adaptive-ticks CPU를 방해하지 않도록, asymmetric 32-bit 지원이 활성화되면 이 CPU들을 64-bit 전용으로 취급합니다.