@@ -19,6 +19,7 @@ DRIVER_VERSION=${DRIVER_VERSION:?"Missing driver version"}
1919DRIVER_RESET_RETRIES=10
2020DELAY_BEFORE_VF_CREATION=${DELAY_BEFORE_VF_CREATION:- 15}
2121RUN_DIR=/run/nvidia
22+ NVIDIA_MODULE_PARAMS=()
2223
2324# Mount the driver rootfs into the run directory with the exception of sysfs.
2425_mount_rootfs () {
@@ -64,14 +65,52 @@ _set_fw_search_path() {
6465 echo -n " $nv_fw_search_path " > $fw_path_config_file
6566}
6667
68+ # For each kernel module configuration file mounted into the container,
69+ # parse the file contents and extract the custom module parameters that
70+ # are to be passed as input to 'modprobe'.
71+ #
72+ # Assumptions:
73+ # - Configuration file is named nvidia.conf
74+ # - Configuration file is mounted inside the container at /drivers.
75+ # - Each line in the file contains at least one parameter, where parameters on the same line
76+ # are space delimited. It is up to the user to properly format the file to ensure
77+ # the correct set of parameters are passed to 'modprobe'.
78+ _get_module_params () {
79+ local base_path=" /drivers"
80+ # nvidia
81+ if [ -f " ${base_path} /nvidia.conf" ]; then
82+ while IFS=" " read -r param || [ -n " $param " ]; do
83+ NVIDIA_MODULE_PARAMS+=(" $param " )
84+ done < " ${base_path} /nvidia.conf"
85+ echo " Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]} "
86+ fi
87+ }
88+
6789_install_driver () {
6890 local tmp_dir=$( mktemp -d)
6991
7092 sh NVIDIA-Linux-${DRIVER_ARCH} -${DRIVER_VERSION} -vgpu-kvm.run --ui=none --no-questions --tmpdir ${tmp_dir} --no-systemd
7193}
7294
73- # Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
95+ # Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
7496_load_driver () {
97+ # Unload modules if they're already loaded so we can reload with custom parameters
98+ if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
99+ echo " NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
100+ rmmod nvidia_vgpu_vfio 2> /dev/null || true
101+ rmmod nvidia 2> /dev/null || true
102+ fi
103+
104+ echo " Parsing kernel module parameters..."
105+ _get_module_params
106+
107+ echo " Loading NVIDIA driver kernel modules..."
108+ set -o xtrace +o nounset
109+ modprobe nvidia " ${NVIDIA_MODULE_PARAMS[@]} "
110+ modprobe nvidia_vgpu_vfio
111+ set +o xtrace -o nounset
112+
113+ # Start vGPU daemons
75114 /usr/bin/nvidia-vgpud
76115 /usr/bin/nvidia-vgpu-mgr &
77116
0 commit comments