Skip to content

Commit

Permalink
Add gpu static passthrough cases vfio_net_boot for both VM and TD
Browse files Browse the repository at this point in the history
Signed-off-by: Farrah Chen <[email protected]>
  • Loading branch information
fanchen2 committed Dec 23, 2024
1 parent eafb835 commit 38818ab
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
21 changes: 21 additions & 0 deletions KVM/qemu/deps/run_cuda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#/bin/sh
ret=0
cd /home/cuda-samples/Samples/0_Introduction || ret=1
if [ $ret -ne 0 ]; then
echo "Cuda samples not found, please make sure /home/cuda-samples/Samples/0_Introduction is installed and built "
exit 1
fi
folder="matrixMul matrixMulDrv matrixMulDynlinkJIT vectorAdd vectorAddDrv vectorAddMMAP vectorAdd_nvrtc"
echo "Start cuda test ----------------"
for i in $folder; do
echo "Start test $i ----------------"
cd $i
./$i || ret=1
cd ../
if [ $ret -ne 0 ]; then
echo "Cuda test $i fail"
exit $ret
else
echo "Cuda test $i pass"
fi
done
105 changes: 105 additions & 0 deletions KVM/qemu/tests/vfio_gpu_boot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/python3

# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2024 Intel Corporation

# Author: Farrah Chen <[email protected]>
#
# History: June. 2024 - Farrah Chen - creation

from virttest import error_context, utils_net, env_process
from virttest import data_dir as virttest_data_dir

from avocado.utils import process
from avocado.core import exceptions
from provider import hostdev
from provider.hostdev import utils as hostdev_utils
from provider.hostdev.dev_setup import hostdev_setup

import os


@error_context.context_aware
def run(test, params, env):
"""
Assign host devices to VM and do ping test.
:param test: QEMU test object.
:type test: avocado_vt.test.VirtTest
:param params: Dictionary with the test parameters.
:type params: virttest.utils_params.Params
:param env: Dictionary with test environment.
:type env: virttest.utils_env.Env
"""
def run_cuda_sample():
#Copy cuda test scripts to guest
file_name = "run_cuda.sh"
guest_dir = "/tmp/"
deps_dir = virttest_data_dir.get_deps_dir()
host_file = os.path.join(deps_dir, file_name)
guest_file = guest_dir + file_name
vm.copy_files_to(host_file, guest_dir)
# session.sendline("$SHELL " + guest_file)
result = session.cmd_status(guest_file)
if result:
test.fail("Cuda test fail")
else:
test.log.info("Cuda test pass")

error_context.context("Start GPU passthrough test", test.log.info)
timeout = params.get_numeric("login_timeout", 240)
vm_type = params.get("vm_secure_guest_type")
vm_name = params['main_vm']
if not params.get("vm_hostdev_iommufd") and vm_type == "tdx":
dma_entry_limit_cmd = params.get("dma_cmd")
status = process.system(dma_entry_limit_cmd, shell=True)
if status:
raise exceptions.TestError("Failed to increase dma_entry_limit.")
with hostdev_setup(params) as params:
hostdev_driver = params.get("vm_hostdev_driver", "vfio-pci")
assignment_type = params.get("hostdev_assignment_type")
available_pci_slots = hostdev_utils.get_pci_by_dev_type(
assignment_type, "display", hostdev_driver
)
# Create VM first
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
vm_hostdevs = vm.params.objects("vm_hostdevs")
pci_slots = []
error_context.base_context(f"Setting hostdevs for {vm.name}", test.log.info)
for dev in vm_hostdevs:
pci_slot = available_pci_slots.pop(0)
vm.params[f"vm_hostdev_host_{dev}"] = pci_slot
pci_slots.append(pci_slot)
vm.create(params=vm.params)
vm.verify_alive()
vm.params["vm_hostdev_slots"] = pci_slots
session = vm.wait_for_login(timeout=timeout)

# Check GPU in guest
try:
error_context.context("Check GPU BDF and driver in guest", test.log.info)
if session:
# Check GPU BDF and driver in guest
gpu_device_check_cmd = params.get("gpu_device_check_cmd")
result = session.cmd_status(gpu_device_check_cmd)
if result:
test.fail("GPU can't be found or with incorrect driver, please install GPU driver in guest image")
else:
test.log.info("GPU found with correct driver in guest")
# Check GPU status in guest
gpu_status_check_cmd = params.get("gpu_status_check_cmd")
result = session.cmd_status(gpu_status_check_cmd)
if result:
test.fail("GPU status check fail")
else:
test.log.info("GPU status check pass")
# Run cuda samples in guest
guest_operation = params.get("guest_operation")
if guest_operation:
test.log.info("Run %s in guest ", guest_operation)
locals_var = locals()
locals_var[guest_operation]()
session.close()
finally:
vm.destroy()
28 changes: 28 additions & 0 deletions KVM/qemu/vfio_gpu_boot.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- vfio_gpu_boot:
virt_test_type = qemu
type = vfio_gpu_boot
start_vm = no
# Special host pci slots to be configured
# setup_hostdev_slots = 0000:00:00.1
hostdev_bind_driver = vfio-pci
vm_hostdev_driver = vfio-pci
vms = "vm1"
vm_hostdevs = hostdev1
hostdev_assignment_type = pf
gpu_device_check_cmd = "lspci -k -s `lspci|grep NV|awk '{print $1}'`|grep 'Kernel driver in use'|grep nvidia"
gpu_status_check_cmd = "nvidia-smi|grep `lspci|grep NV|awk '{print $1}'`"
guest_operation = run_cuda_sample
variants:
- nvidia:
variants:
- @default:
dma_cmd = "echo 0x200000 > /sys/module/vfio_iommu_type1/parameters/dma_entry_limit"
- iommufd:
vm_hostdev_iommufd = iommufd0
variants:
- vm:
- tdvm:
vm_secure_guest_type = tdx
machine_type_extra_params = "kernel-irqchip=split"
auto_cpu_model = "no"
cpu_model = "host"

0 comments on commit 38818ab

Please sign in to comment.