From 1895a25dfedc048deac79eb6ffe0659a5bcae1af Mon Sep 17 00:00:00 2001 From: Joji Mekkattuparamban Date: Thu, 13 Jun 2024 18:09:24 -0700 Subject: [PATCH 1/4] feat: vfio-manager graphics mode Signed-off-by: Joji Mekkattuparamban --- assets/state-vfio-manager/0400_configmap.yaml | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/assets/state-vfio-manager/0400_configmap.yaml b/assets/state-vfio-manager/0400_configmap.yaml index bf333bb92..61359d527 100644 --- a/assets/state-vfio-manager/0400_configmap.yaml +++ b/assets/state-vfio-manager/0400_configmap.yaml @@ -94,6 +94,12 @@ data: echo "unbinding device $gpu" unbind_from_driver $gpu + #for graphics mode, we need to unbind the auxiliary device as well + aux_dev=$(get_graphics_aux_dev "$gpu") + if [ "$aux_dev" != "NONE" ]; then + echo "gpu $gpu is in graphics mode aux_dev $aux_dev" + unbind_from_driver "$aux_dev" + fi } unbind_all() { @@ -106,13 +112,9 @@ data: done } - bind_device() { + bind_pci_device() { local gpu=$1 - if ! is_nvidia_gpu_device $gpu; then - return 0 - fi - if ! is_bound_to_vfio $gpu; then unbind_from_other_driver $gpu echo "binding device $gpu" @@ -123,6 +125,35 @@ data: fi } + get_graphics_aux_dev() { + local gpu=$1 + device_class_file=$(readlink -f "/sys/bus/pci/devices/$gpu/class") + device_class=$(cat "$device_class_file") + if [ "$device_class" == "0x030000" ]; then + aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') + echo "$aux_dev" + else + echo "NONE" + fi + } + + bind_device() { + local gpu=$1 + + if ! is_nvidia_gpu_device $gpu; then + echo "device $gpu is not a gpu!" + return 0 + fi + + bind_pci_device "$gpu" + #for graphics mode, we need to bind the auxiliary device as well + aux_dev=$(get_graphics_aux_dev "$gpu") + if [ "$aux_dev" != "NONE" ]; then + echo "gpu $gpu is in graphics mode aux_dev $aux_dev" + bind_pci_device "$aux_dev" + fi + } + bind_all() { for dev in /sys/bus/pci/devices/*; do read vendor < $dev/vendor From 3c58080ea69022f0d206bf207fcaf262b4b5af96 Mon Sep 17 00:00:00 2001 From: Joji Mekkattuparamban Date: Tue, 25 Jun 2024 11:04:21 -0700 Subject: [PATCH 2/4] chore: address review comment Signed-off-by: Joji Mekkattuparamban --- assets/state-vfio-manager/0400_configmap.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/state-vfio-manager/0400_configmap.yaml b/assets/state-vfio-manager/0400_configmap.yaml index 61359d527..6ac0a7d0c 100644 --- a/assets/state-vfio-manager/0400_configmap.yaml +++ b/assets/state-vfio-manager/0400_configmap.yaml @@ -127,14 +127,15 @@ data: get_graphics_aux_dev() { local gpu=$1 + aux_dev="NONE" device_class_file=$(readlink -f "/sys/bus/pci/devices/$gpu/class") device_class=$(cat "$device_class_file") if [ "$device_class" == "0x030000" ]; then - aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') - echo "$aux_dev" - else - echo "NONE" + if ls "/sys/bus/pci/devices/$gpu" | grep consumer >& /dev/null; then + aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') + fi fi + echo "$aux_dev" } bind_device() { From 5ac3d7d5e26cdcf03dda3c711a41bd2eff6c510f Mon Sep 17 00:00:00 2001 From: Joji Mekkattuparamban Date: Tue, 25 Jun 2024 11:37:51 -0700 Subject: [PATCH 3/4] add more checks Signed-off-by: Joji Mekkattuparamban --- assets/state-vfio-manager/0400_configmap.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/state-vfio-manager/0400_configmap.yaml b/assets/state-vfio-manager/0400_configmap.yaml index 6ac0a7d0c..aa330ccbb 100644 --- a/assets/state-vfio-manager/0400_configmap.yaml +++ b/assets/state-vfio-manager/0400_configmap.yaml @@ -127,15 +127,23 @@ data: get_graphics_aux_dev() { local gpu=$1 - aux_dev="NONE" device_class_file=$(readlink -f "/sys/bus/pci/devices/$gpu/class") device_class=$(cat "$device_class_file") if [ "$device_class" == "0x030000" ]; then if ls "/sys/bus/pci/devices/$gpu" | grep consumer >& /dev/null; then aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') + if [ "$device_class" == "" ]; then + echo "NONE" + return + fi + + if ls "/sys/bus/pci/devices/$aux_dev/" >& /dev/null; then + echo "$aux_dev" + return + fi fi fi - echo "$aux_dev" + echo "NONE" } bind_device() { From 348139854e7ebb56bdaf5d741ae3dff1c44aff26 Mon Sep 17 00:00:00 2001 From: Joji Mekkattuparamban Date: Tue, 25 Jun 2024 14:31:49 -0700 Subject: [PATCH 4/4] address review comments Signed-off-by: Joji Mekkattuparamban --- assets/state-vfio-manager/0400_configmap.yaml | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/assets/state-vfio-manager/0400_configmap.yaml b/assets/state-vfio-manager/0400_configmap.yaml index aa330ccbb..85df8f8ca 100644 --- a/assets/state-vfio-manager/0400_configmap.yaml +++ b/assets/state-vfio-manager/0400_configmap.yaml @@ -129,20 +129,24 @@ data: local gpu=$1 device_class_file=$(readlink -f "/sys/bus/pci/devices/$gpu/class") device_class=$(cat "$device_class_file") - if [ "$device_class" == "0x030000" ]; then - if ls "/sys/bus/pci/devices/$gpu" | grep consumer >& /dev/null; then - aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') - if [ "$device_class" == "" ]; then - echo "NONE" - return - fi + if [ "$device_class" != "0x030000" ]; then + echo "NONE" + return + fi - if ls "/sys/bus/pci/devices/$aux_dev/" >& /dev/null; then - echo "$aux_dev" - return - fi + if ls "/sys/bus/pci/devices/$gpu" | grep consumer >& /dev/null; then + aux_dev=$(ls "/sys/bus/pci/devices/$gpu" | grep consumer | awk -Fconsumer:pci: '{print $2}') + if [ "$aux_dev" == "" ]; then + echo "NONE" + return + fi + + if ls "/sys/bus/pci/devices/$aux_dev/" >& /dev/null; then + echo "$aux_dev" + return fi fi + echo "NONE" }