← Documents Documentation/virt/kvm/devices/xive.rst GitHub 원문 ↗

Linux 6.18.37 · 가상화 / KVM / Device

POWER9 XIVE Gen1

POWER9 XIVE TIMA·ESB mapping, source·event-queue configuration과 native-mode migration sequence입니다.

Source pathDocumentation/virt/kvm/devices/xive.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

xive.rst:1-247

POWER9 XIVE TIMA·ESB mapping, source·event-queue configuration과 native-mode migration sequence입니다.

구조체, register field, priority, error code와 migration 순서는 원문 표기를 유지했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===========================================================
4 POWER9 eXternal Interrupt Virtualization Engine (XIVE Gen1)
5 ===========================================================
6
7 Device types supported:
8 - KVM_DEV_TYPE_XIVE POWER9 XIVE Interrupt Controller generation 1
9
10 This device acts as a VM interrupt controller. It provides the KVM
11 interface to configure the interrupt sources of a VM in the underlying
12 POWER9 XIVE interrupt controller.
13
14 Only one XIVE instance may be instantiated. A guest XIVE device
15 requires a POWER9 host and the guest OS should have support for the
16 XIVE native exploitation interrupt mode. If not, it should run using
17 the legacy interrupt mode, referred as XICS (POWER7/8).
18
19 * Device Mappings
20
21 The KVM device exposes different MMIO ranges of the XIVE HW which
22 are required for interrupt management. These are exposed to the
23 guest in VMAs populated with a custom VM fault handler.
24
25 1. Thread Interrupt Management Area (TIMA)
26
27 Each thread has an associated Thread Interrupt Management context
28 composed of a set of registers. These registers let the thread
29 handle priority management and interrupt acknowledgment. The most
30 important are :
31
32 - Interrupt Pending Buffer (IPB)
33 - Current Processor Priority (CPPR)
34 - Notification Source Register (NSR)
35
36 They are exposed to software in four different pages each proposing
37 a view with a different privilege. The first page is for the
38 physical thread context and the second for the hypervisor. Only the
39 third (operating system) and the fourth (user level) are exposed the
40 guest.
41
42 2. Event State Buffer (ESB)
43
44 Each source is associated with an Event State Buffer (ESB) with
45 either a pair of even/odd pair of pages which provides commands to
46 manage the source: to trigger, to EOI, to turn off the source for
47 instance.
48
49 3. Device pass-through
50
51 When a device is passed-through into the guest, the source
52 interrupts are from a different HW controller (PHB4) and the ESB
53 pages exposed to the guest should accommodate this change.
54
55 The passthru_irq helpers, kvmppc_xive_set_mapped() and
56 kvmppc_xive_clr_mapped() are called when the device HW irqs are
57 mapped into or unmapped from the guest IRQ number space. The KVM
58 device extends these helpers to clear the ESB pages of the guest IRQ
59 number being mapped and then lets the VM fault handler repopulate.
60 The handler will insert the ESB page corresponding to the HW
61 interrupt of the device being passed-through or the initial IPI ESB
62 page if the device has being removed.
63
64 The ESB remapping is fully transparent to the guest and the OS
65 device driver. All handling is done within VFIO and the above
66 helpers in KVM-PPC.
67
68 * Groups:
69
70 1. KVM_DEV_XIVE_GRP_CTRL
71 Provides global controls on the device
72
73 Attributes:
74 1.1 KVM_DEV_XIVE_RESET (write only)
75 Resets the interrupt controller configuration for sources and event
76 queues. To be used by kexec and kdump.
77
78 Errors: none
79
80 1.2 KVM_DEV_XIVE_EQ_SYNC (write only)
81 Sync all the sources and queues and mark the EQ pages dirty. This
82 to make sure that a consistent memory state is captured when
83 migrating the VM.
84
85 Errors: none
86
87 1.3 KVM_DEV_XIVE_NR_SERVERS (write only)
88 The kvm_device_attr.addr points to a __u32 value which is the number of
89 interrupt server numbers (ie, highest possible vcpu id plus one).
90
91 Errors:
92
93 ======= ==========================================
94 -EINVAL Value greater than KVM_MAX_VCPU_IDS.
95 -EFAULT Invalid user pointer for attr->addr.
96 -EBUSY A vCPU is already connected to the device.
97 ======= ==========================================
98
99 2. KVM_DEV_XIVE_GRP_SOURCE (write only)
100 Initializes a new source in the XIVE device and mask it.
101
102 Attributes:
103 Interrupt source number (64-bit)
104
105 The kvm_device_attr.addr points to a __u64 value::
106
107 bits: | 63 .... 2 | 1 | 0
108 values: | unused | level | type
109
110 - type: 0:MSI 1:LSI
111 - level: assertion level in case of an LSI.
112
113 Errors:
114
115 ======= ==========================================
116 -E2BIG Interrupt source number is out of range
117 -ENOMEM Could not create a new source block
118 -EFAULT Invalid user pointer for attr->addr.
119 -ENXIO Could not allocate underlying HW interrupt
120 ======= ==========================================
121
122 3. KVM_DEV_XIVE_GRP_SOURCE_CONFIG (write only)
123 Configures source targeting
124
125 Attributes:
126 Interrupt source number (64-bit)
127
128 The kvm_device_attr.addr points to a __u64 value::
129
130 bits: | 63 .... 33 | 32 | 31 .. 3 | 2 .. 0
131 values: | eisn | mask | server | priority
132
133 - priority: 0-7 interrupt priority level
134 - server: CPU number chosen to handle the interrupt
135 - mask: mask flag (unused)
136 - eisn: Effective Interrupt Source Number
137
138 Errors:
139
140 ======= =======================================================
141 -ENOENT Unknown source number
142 -EINVAL Not initialized source number
143 -EINVAL Invalid priority
144 -EINVAL Invalid CPU number.
145 -EFAULT Invalid user pointer for attr->addr.
146 -ENXIO CPU event queues not configured or configuration of the
147 underlying HW interrupt failed
148 -EBUSY No CPU available to serve interrupt
149 ======= =======================================================
150
151 4. KVM_DEV_XIVE_GRP_EQ_CONFIG (read-write)
152 Configures an event queue of a CPU
153
154 Attributes:
155 EQ descriptor identifier (64-bit)
156
157 The EQ descriptor identifier is a tuple (server, priority)::
158
159 bits: | 63 .... 32 | 31 .. 3 | 2 .. 0
160 values: | unused | server | priority
161
162 The kvm_device_attr.addr points to::
163
164 struct kvm_ppc_xive_eq {
165 __u32 flags;
166 __u32 qshift;
167 __u64 qaddr;
168 __u32 qtoggle;
169 __u32 qindex;
170 __u8 pad[40];
171 };
172
173 - flags: queue flags
174 KVM_XIVE_EQ_ALWAYS_NOTIFY (required)
175 forces notification without using the coalescing mechanism
176 provided by the XIVE END ESBs.
177 - qshift: queue size (power of 2)
178 - qaddr: real address of queue
179 - qtoggle: current queue toggle bit
180 - qindex: current queue index
181 - pad: reserved for future use
182
183 Errors:
184
185 ======= =========================================
186 -ENOENT Invalid CPU number
187 -EINVAL Invalid priority
188 -EINVAL Invalid flags
189 -EINVAL Invalid queue size
190 -EINVAL Invalid queue address
191 -EFAULT Invalid user pointer for attr->addr.
192 -EIO Configuration of the underlying HW failed
193 ======= =========================================
194
195 5. KVM_DEV_XIVE_GRP_SOURCE_SYNC (write only)
196 Synchronize the source to flush event notifications
197
198 Attributes:
199 Interrupt source number (64-bit)
200
201 Errors:
202
203 ======= =============================
204 -ENOENT Unknown source number
205 -EINVAL Not initialized source number
206 ======= =============================
207
208 * VCPU state
209
210 The XIVE IC maintains VP interrupt state in an internal structure
211 called the NVT. When a VP is not dispatched on a HW processor
212 thread, this structure can be updated by HW if the VP is the target
213 of an event notification.
214
215 It is important for migration to capture the cached IPB from the NVT
216 as it synthesizes the priorities of the pending interrupts. We
217 capture a bit more to report debug information.
218
219 KVM_REG_PPC_VP_STATE (2 * 64bits)::
220
221 bits: | 63 .... 32 | 31 .... 0 |
222 values: | TIMA word0 | TIMA word1 |
223 bits: | 127 .......... 64 |
224 values: | unused |
225
226 * Migration:
227
228 Saving the state of a VM using the XIVE native exploitation mode
229 should follow a specific sequence. When the VM is stopped :
230
231 1. Mask all sources (PQ=01) to stop the flow of events.
232
233 2. Sync the XIVE device with the KVM control KVM_DEV_XIVE_EQ_SYNC to
234 flush any in-flight event notification and to stabilize the EQs. At
235 this stage, the EQ pages are marked dirty to make sure they are
236 transferred in the migration sequence.
237
238 3. Capture the state of the source targeting, the EQs configuration
239 and the state of thread interrupt context registers.
240
241 Restore is similar:
242
243 1. Restore the EQ configuration. As targeting depends on it.
244 2. Restore targeting
245 3. Restore the thread interrupt contexts
246 4. Restore the source states
247 5. Let the vCPU run
248

3. 한국어 전문 번역

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

XIVE device와 MMIO mapping

1-67

`KVM_DEV_TYPE_XIVE`는 POWER9 XIVE generation 1 interrupt controller를 guest VM에 제공합니다. Instance는 VM당 하나이며 host가 POWER9이고 guest OS가 XIVE native exploitation mode를 지원해야 합니다. 지원하지 않으면 POWER7/8 legacy XICS mode를 사용합니다.

KVM device는 interrupt management에 필요한 XIVE hardware MMIO range를 custom VM fault handler가 채우는 VMA로 guest에 노출합니다.

XIVE guest mapping
Mapping역할
TIMAThread Interrupt Management Area. IPB, CPPR, NSR로 priority와 interrupt acknowledgment 관리
ESBSource별 even/odd page pair로 trigger, EOI, source off command 제공
Pass-through ESBPHB4 device source에 맞춰 guest IRQ의 ESB page를 physical device interrupt page로 remap

Thread context와 source state를 guest가 제어하는 MMIO 영역입니다.

TIMA는 physical thread, hypervisor, operating-system, user privilege view 네 page를 가지며 guest에는 세 번째 OS page와 네 번째 user page만 노출됩니다.

Pass-through mapping 때 `kvmppc_xive_set_mapped()`·`kvmppc_xive_clr_mapped()`가 guest IRQ의 기존 ESB page를 clear하고 fault handler가 physical device HW interrupt ESB 또는 device 제거 뒤 초기 IPI ESB를 다시 삽입합니다. 이 remapping은 guest와 OS driver에 투명하며 VFIO와 KVM-PPC가 처리합니다.

.. SPDX-License-Identifier: GPL-2.0

===========================================================
POWER9 eXternal Interrupt Virtualization Engine (XIVE Gen1)
===========================================================

Device types supported:
  - KVM_DEV_TYPE_XIVE     POWER9 XIVE Interrupt Controller generation 1

This device acts as a VM interrupt controller. It provides the KVM
interface to configure the interrupt sources of a VM in the underlying
POWER9 XIVE interrupt controller.

Only one XIVE instance may be instantiated. A guest XIVE device
requires a POWER9 host and the guest OS should have support for the
XIVE native exploitation interrupt mode. If not, it should run using
the legacy interrupt mode, referred as XICS (POWER7/8).

* Device Mappings

  The KVM device exposes different MMIO ranges of the XIVE HW which
  are required for interrupt management. These are exposed to the
  guest in VMAs populated with a custom VM fault handler.

  1. Thread Interrupt Management Area (TIMA)

  Each thread has an associated Thread Interrupt Management context
  composed of a set of registers. These registers let the thread
  handle priority management and interrupt acknowledgment. The most
  important are :

      - Interrupt Pending Buffer     (IPB)
      - Current Processor Priority   (CPPR)
      - Notification Source Register (NSR)

  They are exposed to software in four different pages each proposing
  a view with a different privilege. The first page is for the
  physical thread context and the second for the hypervisor. Only the
  third (operating system) and the fourth (user level) are exposed the
  guest.

  2. Event State Buffer (ESB)

  Each source is associated with an Event State Buffer (ESB) with
  either a pair of even/odd pair of pages which provides commands to
  manage the source: to trigger, to EOI, to turn off the source for
  instance.

  3. Device pass-through

  When a device is passed-through into the guest, the source
  interrupts are from a different HW controller (PHB4) and the ESB
  pages exposed to the guest should accommodate this change.

  The passthru_irq helpers, kvmppc_xive_set_mapped() and
  kvmppc_xive_clr_mapped() are called when the device HW irqs are
  mapped into or unmapped from the guest IRQ number space. The KVM
  device extends these helpers to clear the ESB pages of the guest IRQ
  number being mapped and then lets the VM fault handler repopulate.
  The handler will insert the ESB page corresponding to the HW
  interrupt of the device being passed-through or the initial IPI ESB
  page if the device has being removed.

  The ESB remapping is fully transparent to the guest and the OS
  device driver. All handling is done within VFIO and the above
  helpers in KVM-PPC.

XIVE control, source와 event queue

68-207
XIVE global control
Attribute동작
`KVM_DEV_XIVE_RESET`Source와 event queue configuration reset; kexec·kdump용
`KVM_DEV_XIVE_EQ_SYNC`모든 source·queue sync, in-flight notification flush, migration을 위해 EQ page dirty 표시
`KVM_DEV_XIVE_NR_SERVERS``__u32` interrupt server 수. max 초과 `-EINVAL`, bad pointer `-EFAULT`, vCPU 연결 뒤 `-EBUSY`

Migration과 server topology를 제어합니다.

`KVM_DEV_XIVE_GRP_SOURCE`는 새 source를 initialize하고 mask합니다. Attribute number가 interrupt source이고 `addr`의 64-bit 값에서 bit 0 type은 MSI=0·LSI=1, bit 1 level은 LSI assertion level입니다.

XIVE source-create error
Error조건
`-E2BIG`Source number 범위 밖
`-ENOMEM`새 source block 생성 실패
`-EFAULT`잘못된 pointer
`-ENXIO`Underlying HW interrupt 할당 실패

Underlying HW interrupt까지 할당합니다.

`KVM_DEV_XIVE_GRP_SOURCE_CONFIG`의 64-bit 값은 bit 2:0 priority, 31:3 server, bit 32 mask, 63:33 effective interrupt source number(EISN)를 encode합니다. Priority는 0~7이고 server는 interrupt를 처리할 CPU number입니다.

XIVE source-config error
Error조건
`-ENOENT`Unknown source
`-EINVAL`미초기화 source, invalid priority 또는 CPU
`-EFAULT`잘못된 pointer
`-ENXIO`CPU event queue 미구성 또는 HW interrupt config 실패
`-EBUSY`Interrupt를 맡을 CPU 없음

Targeting configuration 검증입니다.

`KVM_DEV_XIVE_GRP_EQ_CONFIG` identifier는 bit 31:3 server와 bit 2:0 priority tuple입니다. `kvm_ppc_xive_eq`는 flags, queue-size power `qshift`, real address `qaddr`, current toggle과 index를 보존합니다.

XIVE EQ field
Field의미
`flags``KVM_XIVE_EQ_ALWAYS_NOTIFY` 필수; END ESB coalescing 없이 항상 notification
`qshift`2의 거듭제곱 queue size
`qaddr`Queue real address
`qtoggle`Current queue toggle bit
`qindex`Current queue index
`pad[40]`미래 확장용 reserved

Event queue migration state입니다.

EQ config에서 invalid CPU는 `-ENOENT`; priority·flag·size·address 오류는 `-EINVAL`; bad pointer는 `-EFAULT`; HW config 실패는 `-EIO`입니다.

`KVM_DEV_XIVE_GRP_SOURCE_SYNC`는 source number를 받아 event notification을 flush합니다. Unknown source는 `-ENOENT`, 미초기화 source는 `-EINVAL`입니다.

* Groups:

1. KVM_DEV_XIVE_GRP_CTRL
     Provides global controls on the device

  Attributes:
    1.1 KVM_DEV_XIVE_RESET (write only)
    Resets the interrupt controller configuration for sources and event
    queues. To be used by kexec and kdump.

    Errors: none

    1.2 KVM_DEV_XIVE_EQ_SYNC (write only)
    Sync all the sources and queues and mark the EQ pages dirty. This
    to make sure that a consistent memory state is captured when
    migrating the VM.

    Errors: none

    1.3 KVM_DEV_XIVE_NR_SERVERS (write only)
    The kvm_device_attr.addr points to a __u32 value which is the number of
    interrupt server numbers (ie, highest possible vcpu id plus one).

    Errors:

      =======  ==========================================
      -EINVAL  Value greater than KVM_MAX_VCPU_IDS.
      -EFAULT  Invalid user pointer for attr->addr.
      -EBUSY   A vCPU is already connected to the device.
      =======  ==========================================

2. KVM_DEV_XIVE_GRP_SOURCE (write only)
     Initializes a new source in the XIVE device and mask it.

  Attributes:
    Interrupt source number  (64-bit)

  The kvm_device_attr.addr points to a __u64 value::

    bits:     | 63   ....  2 |   1   |   0
    values:   |    unused    | level | type

  - type:  0:MSI 1:LSI
  - level: assertion level in case of an LSI.

  Errors:

    =======  ==========================================
    -E2BIG   Interrupt source number is out of range
    -ENOMEM  Could not create a new source block
    -EFAULT  Invalid user pointer for attr->addr.
    -ENXIO   Could not allocate underlying HW interrupt
    =======  ==========================================

3. KVM_DEV_XIVE_GRP_SOURCE_CONFIG (write only)
     Configures source targeting

  Attributes:
    Interrupt source number  (64-bit)

  The kvm_device_attr.addr points to a __u64 value::

    bits:     | 63   ....  33 |  32  | 31 .. 3 |  2 .. 0
    values:   |    eisn       | mask |  server | priority

  - priority: 0-7 interrupt priority level
  - server: CPU number chosen to handle the interrupt
  - mask: mask flag (unused)
  - eisn: Effective Interrupt Source Number

  Errors:

    =======  =======================================================
    -ENOENT  Unknown source number
    -EINVAL  Not initialized source number
    -EINVAL  Invalid priority
    -EINVAL  Invalid CPU number.
    -EFAULT  Invalid user pointer for attr->addr.
    -ENXIO   CPU event queues not configured or configuration of the
	     underlying HW interrupt failed
    -EBUSY   No CPU available to serve interrupt
    =======  =======================================================

4. KVM_DEV_XIVE_GRP_EQ_CONFIG (read-write)
     Configures an event queue of a CPU

  Attributes:
    EQ descriptor identifier (64-bit)

  The EQ descriptor identifier is a tuple (server, priority)::

    bits:     | 63   ....  32 | 31 .. 3 |  2 .. 0
    values:   |    unused     |  server | priority

  The kvm_device_attr.addr points to::

    struct kvm_ppc_xive_eq {
	__u32 flags;
	__u32 qshift;
	__u64 qaddr;
	__u32 qtoggle;
	__u32 qindex;
	__u8  pad[40];
    };

  - flags: queue flags
      KVM_XIVE_EQ_ALWAYS_NOTIFY (required)
	forces notification without using the coalescing mechanism
	provided by the XIVE END ESBs.
  - qshift: queue size (power of 2)
  - qaddr: real address of queue
  - qtoggle: current queue toggle bit
  - qindex: current queue index
  - pad: reserved for future use

  Errors:

    =======  =========================================
    -ENOENT  Invalid CPU number
    -EINVAL  Invalid priority
    -EINVAL  Invalid flags
    -EINVAL  Invalid queue size
    -EINVAL  Invalid queue address
    -EFAULT  Invalid user pointer for attr->addr.
    -EIO     Configuration of the underlying HW failed
    =======  =========================================

5. KVM_DEV_XIVE_GRP_SOURCE_SYNC (write only)
     Synchronize the source to flush event notifications

  Attributes:
    Interrupt source number  (64-bit)

  Errors:

    =======  =============================
    -ENOENT  Unknown source number
    -EINVAL  Not initialized source number
    =======  =============================

XIVE vCPU NVT state

208-225

XIVE interrupt controller는 VP interrupt state를 NVT internal structure에 유지합니다. VP가 hardware thread에 dispatch되지 않은 동안에도 event target이면 hardware가 NVT를 갱신할 수 있습니다.

Migration은 pending interrupt priority를 합성하는 NVT cached IPB를 반드시 포착해야 합니다. `KVM_REG_PPC_VP_STATE`는 128-bit 중 하위 64-bit에 TIMA word0과 word1을 각각 32-bit로 저장하고 상위 64-bit는 unused입니다.

KVM_REG_PPC_VP_STATE
Bit
31:0TIMA word1
63:32TIMA word0
127:64Unused

2 x 64-bit register의 사용 field입니다.

* VCPU state

  The XIVE IC maintains VP interrupt state in an internal structure
  called the NVT. When a VP is not dispatched on a HW processor
  thread, this structure can be updated by HW if the VP is the target
  of an event notification.

  It is important for migration to capture the cached IPB from the NVT
  as it synthesizes the priorities of the pending interrupts. We
  capture a bit more to report debug information.

  KVM_REG_PPC_VP_STATE (2 * 64bits)::

    bits:     |  63  ....  32  |  31  ....  0  |
    values:   |   TIMA word0   |   TIMA word1  |
    bits:     | 127       ..........       64  |
    values:   |            unused              |

XIVE migration sequence

226-247
XIVE save sequence
모든 source를 PQ=01로 maskKVM_DEV_XIVE_EQ_SYNC로 in-flight notification flush와 EQ 안정화·dirty 표시Source targeting state 저장EQ configuration 저장Thread interrupt context register 저장

VM을 멈춘 뒤 event flow와 queue state를 안정화합니다.

XIVE restore sequence
EQ configuration 복원Source targeting 복원Thread interrupt context 복원Source state 복원vCPU 실행

Targeting이 EQ에 의존하므로 queue부터 복원합니다.

* Migration:

  Saving the state of a VM using the XIVE native exploitation mode
  should follow a specific sequence. When the VM is stopped :

  1. Mask all sources (PQ=01) to stop the flow of events.

  2. Sync the XIVE device with the KVM control KVM_DEV_XIVE_EQ_SYNC to
  flush any in-flight event notification and to stabilize the EQs. At
  this stage, the EQ pages are marked dirty to make sure they are
  transferred in the migration sequence.

  3. Capture the state of the source targeting, the EQs configuration
  and the state of thread interrupt context registers.

  Restore is similar:

  1. Restore the EQ configuration. As targeting depends on it.
  2. Restore targeting
  3. Restore the thread interrupt contexts
  4. Restore the source states
  5. Let the vCPU run