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

Linux 6.18.37 · 가상화 / KVM / Device

VFIO virtual device

VM이 사용하는 VFIO group·device fd를 KVM이 추적하고 sPAPR TCE를 연결하는 device ABI입니다.

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

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

1. 요약·해설

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

요약·해설

vfio.rst:1-61

VM이 사용하는 VFIO group·device fd를 KVM이 추적하고 sPAPR TCE를 연결하는 device ABI입니다.

구조체 field, ioctl, attribute, error code와 migration 수식은 원문 표기를 유지했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===================
4 VFIO virtual device
5 ===================
6
7 Device types supported:
8
9 - KVM_DEV_TYPE_VFIO
10
11 Only one VFIO instance may be created per VM. The created device
12 tracks VFIO files (group or device) in use by the VM and features
13 of those groups/devices important to the correctness and acceleration
14 of the VM. As groups/devices are enabled and disabled for use by the
15 VM, KVM should be updated about their presence. When registered with
16 KVM, a reference to the VFIO file is held by KVM.
17
18 Groups:
19 KVM_DEV_VFIO_FILE
20 alias: KVM_DEV_VFIO_GROUP
21
22 KVM_DEV_VFIO_FILE attributes:
23 KVM_DEV_VFIO_FILE_ADD: Add a VFIO file (group/device) to VFIO-KVM device
24 tracking
25
26 kvm_device_attr.addr points to an int32_t file descriptor for the
27 VFIO file.
28
29 KVM_DEV_VFIO_FILE_DEL: Remove a VFIO file (group/device) from VFIO-KVM
30 device tracking
31
32 kvm_device_attr.addr points to an int32_t file descriptor for the
33 VFIO file.
34
35 KVM_DEV_VFIO_GROUP (legacy kvm device group restricted to the handling of VFIO group fd):
36 KVM_DEV_VFIO_GROUP_ADD: same as KVM_DEV_VFIO_FILE_ADD for group fd only
37
38 KVM_DEV_VFIO_GROUP_DEL: same as KVM_DEV_VFIO_FILE_DEL for group fd only
39
40 KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE table
41 allocated by sPAPR KVM.
42 kvm_device_attr.addr points to a struct::
43
44 struct kvm_vfio_spapr_tce {
45 __s32 groupfd;
46 __s32 tablefd;
47 };
48
49 where:
50
51 - @groupfd is a file descriptor for a VFIO group;
52 - @tablefd is a file descriptor for a TCE table allocated via
53 KVM_CREATE_SPAPR_TCE.
54
55 The FILE/GROUP_ADD operation above should be invoked prior to accessing the
56 device file descriptor via VFIO_GROUP_GET_DEVICE_FD in order to support
57 drivers which require a kvm pointer to be set in their .open_device()
58 callback. It is the same for device file descriptor via character device
59 open which gets device access via VFIO_DEVICE_BIND_IOMMUFD. For such file
60 descriptors, FILE_ADD should be invoked before VFIO_DEVICE_BIND_IOMMUFD
61 to support the drivers mentioned in prior sentence as well.
62

3. 한국어 전문 번역

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

VFIO file tracking

1-34

VM당 `KVM_DEV_TYPE_VFIO` instance는 하나만 만들 수 있습니다. 이 device는 VM이 사용하는 VFIO group 또는 device file과 VM correctness·acceleration에 중요한 feature를 추적합니다.

VM에서 VFIO group·device 사용을 enable하거나 disable할 때 KVM에도 존재 여부를 갱신해야 합니다. 등록된 VFIO file은 KVM이 reference를 유지합니다.

`KVM_DEV_VFIO_FILE` attribute
Attribute동작
`KVM_DEV_VFIO_FILE_ADD``attr.addr`가 가리키는 `int32_t` VFIO group/device fd를 KVM tracking에 추가
`KVM_DEV_VFIO_FILE_DEL`같은 형식의 fd를 tracking에서 제거

Group alias는 `KVM_DEV_VFIO_GROUP`입니다.

.. SPDX-License-Identifier: GPL-2.0

===================
VFIO virtual device
===================

Device types supported:

  - KVM_DEV_TYPE_VFIO

Only one VFIO instance may be created per VM.  The created device
tracks VFIO files (group or device) in use by the VM and features
of those groups/devices important to the correctness and acceleration
of the VM.  As groups/devices are enabled and disabled for use by the
VM, KVM should be updated about their presence.  When registered with
KVM, a reference to the VFIO file is held by KVM.

Groups:
  KVM_DEV_VFIO_FILE
	alias: KVM_DEV_VFIO_GROUP

KVM_DEV_VFIO_FILE attributes:
  KVM_DEV_VFIO_FILE_ADD: Add a VFIO file (group/device) to VFIO-KVM device
	tracking

	kvm_device_attr.addr points to an int32_t file descriptor for the
	VFIO file.

  KVM_DEV_VFIO_FILE_DEL: Remove a VFIO file (group/device) from VFIO-KVM
	device tracking

	kvm_device_attr.addr points to an int32_t file descriptor for the
	VFIO file.

Legacy group와 open ordering

35-61

Legacy `KVM_DEV_VFIO_GROUP`은 VFIO group fd만 다룹니다. GROUP_ADD·GROUP_DEL은 각각 FILE_ADD·FILE_DEL과 같지만 group fd로 제한됩니다.

`KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE`는 `kvm_vfio_spapr_tce.groupfd`의 VFIO group에 `KVM_CREATE_SPAPR_TCE`로 할당한 `tablefd` guest-visible TCE table을 연결합니다.

VFIO file 등록 순서
VFIO group 또는 device file 준비KVM_DEV_VFIO_FILE_ADD 또는 legacy GROUP_ADD 호출Group 경로면 VFIO_GROUP_GET_DEVICE_FD로 device fd 획득Character-device 경로면 VFIO_DEVICE_BIND_IOMMUFD 호출VM에서 device 사용

Driver의 `.open_device()`가 KVM pointer를 필요로 할 수 있으므로 KVM tracking을 먼저 설정합니다.

Group fd로 device를 얻을 때는 `VFIO_GROUP_GET_DEVICE_FD` 전에 ADD를 호출해야 합니다. Character device open 경로에서도 `VFIO_DEVICE_BIND_IOMMUFD`보다 FILE_ADD가 먼저여야 driver callback에 KVM pointer가 설정됩니다.

KVM_DEV_VFIO_GROUP (legacy kvm device group restricted to the handling of VFIO group fd):
  KVM_DEV_VFIO_GROUP_ADD: same as KVM_DEV_VFIO_FILE_ADD for group fd only

  KVM_DEV_VFIO_GROUP_DEL: same as KVM_DEV_VFIO_FILE_DEL for group fd only

  KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE table
	allocated by sPAPR KVM.
	kvm_device_attr.addr points to a struct::

		struct kvm_vfio_spapr_tce {
			__s32	groupfd;
			__s32	tablefd;
		};

	where:

	- @groupfd is a file descriptor for a VFIO group;
	- @tablefd is a file descriptor for a TCE table allocated via
	  KVM_CREATE_SPAPR_TCE.

The FILE/GROUP_ADD operation above should be invoked prior to accessing the
device file descriptor via VFIO_GROUP_GET_DEVICE_FD in order to support
drivers which require a kvm pointer to be set in their .open_device()
callback.  It is the same for device file descriptor via character device
open which gets device access via VFIO_DEVICE_BIND_IOMMUFD.  For such file
descriptors, FILE_ADD should be invoked before VFIO_DEVICE_BIND_IOMMUFD
to support the drivers mentioned in prior sentence as well.