Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: GPL-2.0-or-later
source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
function cleanup_devices() {
local device_bdf
local device_dir
for device_bdf in "$@"; do
device_dir=${DEVICES_DIR}/${device_bdf}
if [ -f ${device_dir}/vfio-pci ]; then
unbind ${device_bdf} vfio-pci
fi
if [ -f ${device_dir}/driver_override ]; then
clear_driver_override ${device_bdf}
fi
if [ -f ${device_dir}/driver ]; then
bind ${device_bdf} $(cat ${device_dir}/driver)
fi
if [ -f ${device_dir}/sriov_numvfs ]; then
set_sriov_numvfs ${device_bdf} $(cat ${device_dir}/sriov_numvfs)
fi
rm -rf ${device_dir}
done
}
function main() {
if [ $# = 0 ]; then
cleanup_devices $(ls ${DEVICES_DIR})
rmdir ${DEVICES_DIR}
else
cleanup_devices "$@"
fi
}
main "$@"
+42
View File
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: GPL-2.0-or-later
readonly DEVICES_DIR="${TMPDIR:-/tmp}/vfio-selftests-devices"
function write_to() {
# Unfortunately set -x does not show redirects so use echo to manually
# tell the user what commands are being run.
echo "+ echo \"${2}\" > ${1}"
echo "${2}" > ${1}
}
function get_driver() {
if [ -L /sys/bus/pci/devices/${1}/driver ]; then
basename $(readlink -m /sys/bus/pci/devices/${1}/driver)
fi
}
function bind() {
write_to /sys/bus/pci/drivers/${2}/bind ${1}
}
function unbind() {
write_to /sys/bus/pci/drivers/${2}/unbind ${1}
}
function set_sriov_numvfs() {
write_to /sys/bus/pci/devices/${1}/sriov_numvfs ${2}
}
function get_sriov_numvfs() {
if [ -f /sys/bus/pci/devices/${1}/sriov_numvfs ]; then
cat /sys/bus/pci/devices/${1}/sriov_numvfs
fi
}
function set_driver_override() {
write_to /sys/bus/pci/devices/${1}/driver_override ${2}
}
function clear_driver_override() {
set_driver_override ${1} ""
}
+16
View File
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-or-later
source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
function main() {
local device_bdfs=$(ls ${DEVICES_DIR})
if [ -z "${device_bdfs}" ]; then
echo "No devices found, skipping."
exit 4
fi
"$@" ${device_bdfs}
}
main "$@"
+48
View File
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: GPL-2.0-or-later
set -e
source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
function main() {
local device_bdf
local device_dir
local numvfs
local driver
if [ $# = 0 ]; then
echo "usage: $0 segment:bus:device.function ..." >&2
exit 1
fi
for device_bdf in "$@"; do
test -d /sys/bus/pci/devices/${device_bdf}
device_dir=${DEVICES_DIR}/${device_bdf}
if [ -d "${device_dir}" ]; then
echo "${device_bdf} has already been set up, exiting."
exit 0
fi
mkdir -p ${device_dir}
numvfs=$(get_sriov_numvfs ${device_bdf})
if [ "${numvfs}" ]; then
set_sriov_numvfs ${device_bdf} 0
echo ${numvfs} > ${device_dir}/sriov_numvfs
fi
driver=$(get_driver ${device_bdf})
if [ "${driver}" ]; then
unbind ${device_bdf} ${driver}
echo ${driver} > ${device_dir}/driver
fi
set_driver_override ${device_bdf} vfio-pci
touch ${device_dir}/driver_override
bind ${device_bdf} vfio-pci
touch ${device_dir}/vfio-pci
done
}
main "$@"