← Documents Documentation/arch/x86/x86_64/fred.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Flexible Return and Event Delivery (FRED)

FRED event delivery, ERETU/ERETS, LKGS와 stack-level semantics를 설명합니다.

Source pathDocumentation/arch/x86/x86_64/fred.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

fred.rst:1-96

FRED는 IDT/IRET 경로를 낮은 latency의 event delivery와 `ERETU`·`ERETS` return으로 대체하고 full supervisor/user context를 atomic하게 전환합니다.

`LKGS`는 kernel GS를 건드리지 않고 `IA32_KERNEL_GS_BASE`를 관리하며, 전용 stack을 쓰는 level 0~3이 nonreentrant IST를 대체합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =========================================
4 Flexible Return and Event Delivery (FRED)
5 =========================================
6
7 Overview
8 ========
9
10 The FRED architecture defines simple new transitions that change
11 privilege level (ring transitions). The FRED architecture was
12 designed with the following goals:
13
14 1) Improve overall performance and response time by replacing event
15 delivery through the interrupt descriptor table (IDT event
16 delivery) and event return by the IRET instruction with lower
17 latency transitions.
18
19 2) Improve software robustness by ensuring that event delivery
20 establishes the full supervisor context and that event return
21 establishes the full user context.
22
23 The new transitions defined by the FRED architecture are FRED event
24 delivery and, for returning from events, two FRED return instructions.
25 FRED event delivery can effect a transition from ring 3 to ring 0, but
26 it is used also to deliver events incident to ring 0. One FRED
27 instruction (ERETU) effects a return from ring 0 to ring 3, while the
28 other (ERETS) returns while remaining in ring 0. Collectively, FRED
29 event delivery and the FRED return instructions are FRED transitions.
30
31 In addition to these transitions, the FRED architecture defines a new
32 instruction (LKGS) for managing the state of the GS segment register.
33 The LKGS instruction can be used by 64-bit operating systems that do
34 not use the new FRED transitions.
35
36 Furthermore, the FRED architecture is easy to extend for future CPU
37 architectures.
38
39 Software based event dispatching
40 ================================
41
42 FRED operates differently from IDT in terms of event handling. Instead
43 of directly dispatching an event to its handler based on the event
44 vector, FRED requires the software to dispatch an event to its handler
45 based on both the event's type and vector. Therefore, an event dispatch
46 framework must be implemented to facilitate the event-to-handler
47 dispatch process. The FRED event dispatch framework takes control
48 once an event is delivered, and employs a two-level dispatch.
49
50 The first level dispatching is event type based, and the second level
51 dispatching is event vector based.
52
53 Full supervisor/user context
54 ============================
55
56 FRED event delivery atomically save and restore full supervisor/user
57 context upon event delivery and return. Thus it avoids the problem of
58 transient states due to %cr2 and/or %dr6, and it is no longer needed
59 to handle all the ugly corner cases caused by half baked entry states.
60
61 FRED allows explicit unblock of NMI with new event return instructions
62 ERETS/ERETU, avoiding the mess caused by IRET which unconditionally
63 unblocks NMI, e.g., when an exception happens during NMI handling.
64
65 FRED always restores the full value of %rsp, thus ESPFIX is no longer
66 needed when FRED is enabled.
67
68 LKGS
69 ====
70
71 LKGS behaves like the MOV to GS instruction except that it loads the
72 base address into the IA32_KERNEL_GS_BASE MSR instead of the GS
73 segment’s descriptor cache. With LKGS, it ends up with avoiding
74 mucking with kernel GS, i.e., an operating system can always operate
75 with its own GS base address.
76
77 Because FRED event delivery from ring 3 and ERETU both swap the value
78 of the GS base address and that of the IA32_KERNEL_GS_BASE MSR, plus
79 the introduction of LKGS instruction, the SWAPGS instruction is no
80 longer needed when FRED is enabled, thus is disallowed (#UD).
81
82 Stack levels
83 ============
84
85 4 stack levels 0~3 are introduced to replace the nonreentrant IST for
86 event handling, and each stack level should be configured to use a
87 dedicated stack.
88
89 The current stack level could be unchanged or go higher upon FRED
90 event delivery. If unchanged, the CPU keeps using the current event
91 stack. If higher, the CPU switches to a new event stack specified by
92 the MSR of the new stack level, i.e., MSR_IA32_FRED_RSP[123].
93
94 Only execution of a FRED return instruction ERET[US], could lower the
95 current stack level, causing the CPU to switch back to the stack it was
96 on before a previous event delivery that promoted the stack level.
97

3. 한국어 전문 번역

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

FRED transition과 목표

1-38

이 문서는 `SPDX-License-Identifier: GPL-2.0`으로 배포됩니다. Flexible Return and Event Delivery(FRED) architecture는 privilege level을 바꾸는 단순한 새 transition, 즉 ring transition을 정의합니다.

FRED architecture는 다음 목표로 설계되었습니다.

  • interrupt descriptor table을 통한 event delivery(IDT event delivery)와 `IRET` instruction의 event return을 latency가 더 낮은 transition으로 대체해 전체 performance와 response time을 개선합니다.
  • event delivery가 full supervisor context를 확립하고 event return이 full user context를 확립하도록 보장해 software robustness를 높입니다.

FRED가 정의하는 새 transition은 FRED event delivery와 event에서 돌아오기 위한 두 FRED return instruction입니다. event delivery는 ring 3에서 ring 0으로 전환할 수 있으며 ring 0에서 발생한 event를 전달하는 데도 사용합니다.

`ERETU`는 ring 0에서 ring 3으로 return하고 `ERETS`는 ring 0에 머문 채 return합니다. FRED event delivery와 두 return instruction을 통틀어 FRED transition이라고 합니다.

FRED architecture는 transition 외에도 GS segment register state를 관리하는 새 `LKGS` instruction을 정의합니다. 새 FRED transition을 사용하지 않는 64-bit operating system도 `LKGS`를 사용할 수 있습니다.

FRED architecture는 향후 CPU architecture에 맞게 쉽게 확장할 수 있습니다.

software 기반 two-level dispatch

39-52

FRED의 event handling은 IDT와 다릅니다. event vector만으로 handler에 직접 dispatch하는 대신 software가 event type과 vector를 모두 사용해 handler를 선택해야 합니다.

따라서 event-to-handler dispatch를 지원하는 framework가 필요합니다. FRED event dispatch framework는 event가 전달되면 control을 넘겨받아 two-level dispatch를 수행합니다. 첫 level은 event type, 두 번째 level은 event vector를 기준으로 합니다.

full supervisor/user context

53-67

FRED event delivery와 return은 full supervisor/user context를 atomic하게 save하고 restore합니다. 따라서 `%cr2` 또는 `%dr6` 때문에 생기는 transient state 문제를 피하며 불완전한 entry state가 만드는 까다로운 corner case를 처리할 필요가 없습니다.

FRED는 새 return instruction `ERETS`와 `ERETU`로 NMI를 명시적으로 unblock할 수 있습니다. NMI handling 도중 exception이 발생한 경우처럼 `IRET`이 NMI를 무조건 unblock해서 생기는 복잡성을 피합니다.

FRED는 `%rsp`의 full value를 항상 restore하므로 FRED가 활성화되면 ESPFIX가 필요하지 않습니다.

LKGS와 GS base 관리

68-81

`LKGS`는 GS로의 `MOV` instruction처럼 동작하지만 base address를 GS segment descriptor cache가 아니라 `IA32_KERNEL_GS_BASE` MSR에 load합니다. operating system은 `LKGS`를 사용해 kernel GS를 변경하지 않고 자체 GS base address를 계속 사용할 수 있습니다.

ring 3에서의 FRED event delivery와 `ERETU`는 GS base address와 `IA32_KERNEL_GS_BASE` MSR 값을 서로 swap합니다. 여기에 `LKGS`가 도입되어 FRED 활성화 시 `SWAPGS`가 더 이상 필요하지 않으므로 `#UD`로 금지됩니다.

재진입 가능한 stack level

82-96

event handling에서 nonreentrant IST를 대체하기 위해 stack level 0~3 네 개를 도입하며 각 level은 전용 stack을 사용하도록 구성해야 합니다.

FRED event delivery 때 현재 stack level은 유지되거나 높아질 수 있습니다. 그대로면 CPU가 현재 event stack을 계속 사용하고, 높아지면 새 stack level의 MSR인 `MSR_IA32_FRED_RSP[123]`가 지정하는 새 event stack으로 전환합니다.

FRED return instruction `ERET[US]`를 실행할 때만 현재 stack level을 낮출 수 있습니다. 이때 CPU는 이전 event delivery가 stack level을 올리기 전에 사용하던 stack으로 돌아갑니다.