Files
pve_toss_notes/08.PVE开启硬件直通功能.md
T
2023-03-03 16:37:07 +08:00

4.5 KiB
Raw Blame History

1.修改系统Grub参数

参考官方文档 qm_pci_passthroughPci passthrough 开启 PVE 硬件直通功能。

使用 SSH 工具登录到 PVE 服务器,编辑系统 Grub 的配置文件 /etc/default/grub

## 编辑 Grub 配置文件
nano /etc/default/grub

nano 编辑器对话框中修改 GRUB_CMDLINE_LINUX_DEFAULT 参数,注意命令中间的空格:

## Intel 处理器添加参数
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

根据官方文档的说明,AMD 处理器下硬件直通功能将会自动打开,否则需要手动修改 Grub 配置文件:

## AMD 处理器添加参数
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt"

修改并保存后,需要更新系统 Grub :

## 更新系统 Grub
update-grub

2.加载系统内核模块

修改系统 /etc/modules 配置文件,增加必要的系统模块:

## 编辑系统配置文件
nano /etc/modules

在配置文件末尾输入以下内容:

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

将配置文件保存,并重启 PVE 服务器。

PVE 服务器重启完成后,再次使用 SSH 工具登录,并使用以下命令检查硬件直通状态:

## 检查系统硬件直通状态
dmesg | grep -e DMAR -e IOMMU -e AMD-Vi

检查 IOMMUDirected I/OInterrupt Remapping 的启用状态。

N5105 处理器示例输出如下:

[    0.016437] ACPI: DMAR 0x00000000787BF000 000088 (v02 INTEL  EDK2     00000002      01000013)
[    0.016472] ACPI: Reserving DMAR table memory at [mem 0x787bf000-0x787bf087]
[    0.052437] DMAR: IOMMU enabled
[    0.144431] DMAR: Host address width 39
[    0.144432] DMAR: DRHD base: 0x000000fed90000 flags: 0x0
[    0.144439] DMAR: dmar0: reg_base_addr fed90000 ver 4:0 cap 1c0000c40660462 ecap 49e2ff0505e
[    0.144441] DMAR: DRHD base: 0x000000fed91000 flags: 0x1
[    0.144446] DMAR: dmar1: reg_base_addr fed91000 ver 1:0 cap d2008c40660462 ecap f050da
[    0.144449] DMAR: RMRR base: 0x0000007b800000 end: 0x0000007fbfffff
[    0.144452] DMAR-IR: IOAPIC id 2 under DRHD base  0xfed91000 IOMMU 1
[    0.144453] DMAR-IR: HPET id 0 under DRHD base 0xfed91000
[    0.144454] DMAR-IR: Queued invalidation will be enabled to support x2apic and Intr-remapping.
[    0.146335] DMAR-IR: Enabled IRQ remapping in x2apic mode
[    0.333509] pci 0000:00:02.0: DMAR: Skip IOMMU disabling for graphics
[    0.410824] DMAR: No ATSR found
[    0.410824] DMAR: No SATC found
[    0.410826] DMAR: IOMMU feature fl1gp_support inconsistent
[    0.410827] DMAR: IOMMU feature pgsel_inv inconsistent
[    0.410829] DMAR: IOMMU feature nwfs inconsistent
[    0.410829] DMAR: IOMMU feature pds inconsistent
[    0.410830] DMAR: IOMMU feature eafs inconsistent
[    0.410831] DMAR: IOMMU feature prs inconsistent
[    0.410831] DMAR: IOMMU feature nest inconsistent
[    0.410832] DMAR: IOMMU feature mts inconsistent
[    0.410832] DMAR: IOMMU feature sc_support inconsistent
[    0.410833] DMAR: IOMMU feature dev_iotlb_support inconsistent
[    0.410835] DMAR: dmar0: Using Queued invalidation
[    0.410838] DMAR: dmar1: Using Queued invalidation
[    0.412755] DMAR: Intel(R) Virtualization Technology for Directed I/O

检查系统 IOMMU 分组:

## 检查 IOMMU group
find /sys/kernel/iommu_groups/ -type l

示例输出如下:

/sys/kernel/iommu_groups/7/devices/0000:00:1c.4
/sys/kernel/iommu_groups/15/devices/0000:04:00.0
/sys/kernel/iommu_groups/5/devices/0000:00:17.0
/sys/kernel/iommu_groups/13/devices/0000:02:00.0
/sys/kernel/iommu_groups/3/devices/0000:00:14.2
/sys/kernel/iommu_groups/3/devices/0000:00:14.0
/sys/kernel/iommu_groups/11/devices/0000:00:1f.0
/sys/kernel/iommu_groups/11/devices/0000:00:1f.5
/sys/kernel/iommu_groups/11/devices/0000:00:1f.3
/sys/kernel/iommu_groups/11/devices/0000:00:1f.4
/sys/kernel/iommu_groups/1/devices/0000:00:02.0
/sys/kernel/iommu_groups/8/devices/0000:00:1c.5
/sys/kernel/iommu_groups/16/devices/0000:05:00.0
/sys/kernel/iommu_groups/6/devices/0000:00:1c.0
/sys/kernel/iommu_groups/14/devices/0000:03:00.0
/sys/kernel/iommu_groups/4/devices/0000:00:16.0
/sys/kernel/iommu_groups/12/devices/0000:01:00.0
/sys/kernel/iommu_groups/2/devices/0000:00:04.0
/sys/kernel/iommu_groups/10/devices/0000:00:1c.7
/sys/kernel/iommu_groups/0/devices/0000:00:00.0
/sys/kernel/iommu_groups/9/devices/0000:00:1c.6