Skip to content

Commit

Permalink
vfio: Extend VFIO test
Browse files Browse the repository at this point in the history
Extend the VFIO test to check for any VFIO device not only
for network devices.

Fixes: kata-containers#5728
  • Loading branch information
zvonkok committed Jul 21, 2023
1 parent b2a2392 commit b3c95e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ install_extra_tools() {
main() {
local setup_type="default"

# Travis only needs a very basic setup
# github-actions only needs a very basic setup
set +o nounset
[ "$TRAVIS" = "true" ] && setup_type="minimal"
[ -n "$GITHUB_ACTION" ] && setup_type="minimal"
set -o nounset

[ "$setup_type" = "default" ] && bash -f "${cidir}/install_go.sh" -p -f
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ jobs:
runs-on: ubuntu-20.04
env:
GO111MODULE: off
TRAVIS: "true"
TRAVIS_BRANCH: ${{ github.base_ref }}
TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
TRAVIS_PULL_REQUEST_SHA : ${{ github.event.pull_request.head.sha }}
GITHUB_USER : ${{ secrets.GITHUB_USER }}
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
steps:
Expand All @@ -32,10 +28,6 @@ jobs:
gopath_org=$(go env GOPATH)/src/github.com/kata-containers/
mkdir -p ${gopath_org}
ln -s ${PWD} ${gopath_org}
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST_BRANCH: ${TRAVIS_PULL_REQUEST_BRANCH}"
echo "TRAVIS_PULL_REQUEST_SHA: ${TRAVIS_PULL_REQUEST_SHA}"
echo "TRAVIS: ${TRAVIS}"
- name: Set env
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') }}
run: |
Expand All @@ -47,10 +39,6 @@ jobs:
with:
fetch-depth: 0
path: ./src/github.com/${{ github.repository }}
- name: Setup travis references
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') }}
run: |
echo "TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = \"/\" } ; { print $3 }')}"
- name: Install dependencies
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') }}
run: |
Expand Down
25 changes: 19 additions & 6 deletions functional/vfio/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ HYPERVISOR=
MACHINE_TYPE=
IMAGE_TYPE=

# Option to choose an alternative PCI device for the VFIO test
VFIO_PCI_CLASS=${VFIO_PCI_CLASS:-"Ethernet controller"}
VFIO_PCI_NAME=${VFIO_PCI_NAME:-"Virtio network device"}
VFIO_CHECK_GUEST_KERNEL=${VFIO_CHECK_GUEST_KERNEL:-"ip a | grep \"eth\" || die \"Missing VFIO network interface\""}
VFIO_HOTPLUG=${VFIO_HOTPLUG:-"bridge-port"}
VFIO_CHECK_NUM_DEVICES=${VFIO_CHECK_NUM_DEVICES:-"2"}

cleanup() {
clean_env_ctr
sudo rm -rf "${tmp_data_dir}"

[ -n "${host_pci}" ] && sudo driverctl unset-override "${host_pci}"
# some devices fail if no previous driver being bound
[ -n "${host_pci}" ] && sudo driverctl --noprobe unset-override "${host_pci}"
}

host_pci_addr() {
lspci -D | grep "Ethernet controller" | grep "Virtio network device" | tail -1 | cut -d' ' -f1
lspci -D | grep "${VFIO_PCI_CLASS}" | grep "${VFIO_PCI_NAME}" | tail -1 | cut -d' ' -f1
}

get_vfio_path() {
Expand Down Expand Up @@ -87,7 +94,7 @@ check_guest_kernel() {
# For vfio_mode=guest-kernel, the device should be bound to
# the guest kernel's native driver. To check this has worked,
# we look for an ethernet device named 'eth*'
get_ctr_cmd_output "${container_id}" ip a | grep "eth" || die "Missing VFIO network interface"
get_ctr_cmd_output "${container_id}" ash -c "${VFIO_CHECK_GUEST_KERNEL}"
}

check_vfio() {
Expand All @@ -113,8 +120,8 @@ check_vfio() {
# There should be two devices in the IOMMU group: the ethernet
# device we care about, plus the PCIe to PCI bridge device
devs="$(get_ctr_cmd_output "${cid}" ls /sys/kernel/iommu_groups/"${group}"/devices)"
if [ $(echo "${devs}" | wc -w) != "2" ] ; then
die "Expected exactly two devices got: ${devs}"
if [ $(echo "${devs}" | wc -w) != ${VFIO_CHECK_NUM_DEVICES} ] ; then
die "Expected exactly ${VFIO_CHECK_NUM_DEVICES} device(s) got: ${devs}"
fi

# The bridge device will always sort first, because it is on
Expand Down Expand Up @@ -193,6 +200,12 @@ setup_configuration_file() {
fi
fi

if [ "${VFIO_HOTPLUG}" = "root-port" ]; then
sed -i 's|^#hotplug_vfio_on_root_bus.*|hotplug_vfio = "root-port"|g' "${kata_config_file}"
sed -i 's|^#pcie_root_port.*|pcie_root_port = 4|g' "${kata_config_file}"
cat "${kata_config_file}" | grep -v '#' | grep -v '^$'
fi

if [ -n "${SANDBOX_CGROUP_ONLY}" ]; then
sed -i 's|^sandbox_cgroup_only.*|sandbox_cgroup_only='${SANDBOX_CGROUP_ONLY}'|g' "${kata_config_file}"
fi
Expand Down

0 comments on commit b3c95e1

Please sign in to comment.