shopt -s nullglob for g in `find /sys/kernel/iommu_groups/* -maxdepth 0 -type d | sort -V`; do echo"IOMMU Group ${g##*/}:" for d in$g/devices/*; do echo -e "\t$(lspci -nns ${d##*/})" done; done;
# 结果
IOMMU Group 16: 08:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Upstream Port of PCI Express Switch [1002:1478] (rev c1) IOMMU Group 17: 09:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Downstream Port of PCI Express Switch [1002:1479] IOMMU Group 18: 0a:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 [Radeon RX 6800/6800 XT / 6900 XT] [1002:73bf] (rev c1) IOMMU Group 19: 0a:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21/23 HDMI/DP Audio Controller [1002:ab28] IOMMU Group 20: 0a:00.2 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD/ATI] Device [1002:73a6] IOMMU Group 21: 0a:00.3 Serial bus controller [0c80]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 USB [1002:73a4]
if [ $OBJECT == "miloo" ] || [ $OBJECT == "mod" ] || [ $OBJECT == "work" ]; then case"$OPERATION"in "prepare") systemctl start libvirt-nosleep@"$OBJECT" 2>&1 | tee -a /var/log/libvirt/custom_hooks.log /bin/vfio-startup.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log ;;
"release") systemctl stop libvirt-nosleep@"$OBJECT" 2>&1 | tee -a /var/log/libvirt/custom_hooks.log /bin/vfio-teardown.sh 2>&1 | tee -a /var/log/libvirt/custom_hooks.log ;; esac fi
worisur /etc/libvirt/hooks # cat vfio-startup.sh #!/bin/bash # Helpful to read output when debugging set -x
long_delay=10 medium_delay=5 short_delay=1 echo"Beginning of startup!"
function stop_display_manager_if_running { # Stop dm using systemd ifcommand -v systemctl; then if systemctl is-active --quiet "$1.service" ; then echo$1 >> /tmp/vfio-store-display-manager systemctl stop "$1.service" fi
while systemctl is-active --quiet "$1.service" ; do sleep"${medium_delay}" done
return fi
# Stop dm using runit ifcommand -v sv; then if sv status $1 ; then echo$1 >> /tmp/vfio-store-display-manager sv stop $1 fi fi }
# Stop currently running display manager iftest -e "/tmp/vfio-store-display-manager" ; then rm -f /tmp/vfio-store-display-manager fi
# Unbind VTconsoles if currently bound (adapted from https://www.kernel.org/doc/Documentation/fb/fbcon.txt) iftest -e "/tmp/vfio-bound-consoles" ; then rm -f /tmp/vfio-bound-consoles fi for (( i = 0; i < 16; i++)) do iftest -x /sys/class/vtconsole/vtcon${i}; then if [ `cat /sys/class/vtconsole/vtcon${i}/name | grep -c "frame buffer"` \ = 1 ]; then echo 0 > /sys/class/vtconsole/vtcon${i}/bind echo"Unbinding console ${i}" echo$i >> /tmp/vfio-bound-consoles fi fi done
# Unbind EFI-Framebuffer iftest -e "/tmp/vfio-is-nvidia" ; then rm -f /tmp/vfio-is-nvidia fi
if lsmod | grep "nvidia" &> /dev/null ; then echo"true" >> /tmp/vfio-is-nvidia echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind fi