@@ -19,6 +19,8 @@ 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=()
23+ MODPROBE_CONFIG_DIR=" /etc/modprobe.d"
2224
2325# Mount the driver rootfs into the run directory with the exception of sysfs.
2426_mount_rootfs () {
@@ -64,14 +66,59 @@ _set_fw_search_path() {
6466 echo -n " $nv_fw_search_path " > $fw_path_config_file
6567}
6668
69+ # For each kernel module configuration file mounted into the container,
70+ # parse the file contents and extract the custom module parameters that
71+ # are to be passed as input to 'modprobe'.
72+ #
73+ # Assumptions:
74+ # - Configuration file is named nvidia.conf
75+ # - Configuration file is mounted inside the container at /drivers.
76+ # - Each line in the file contains at least one parameter, where parameters on the same line
77+ # are space delimited. It is up to the user to properly format the file to ensure
78+ # the correct set of parameters are passed to 'modprobe'.
79+ _get_module_params () {
80+ local base_path=" /drivers"
81+ # nvidia
82+ if [ -f " ${base_path} /nvidia.conf" ]; then
83+ while IFS=" " read -r param || [ -n " $param " ]; do
84+ NVIDIA_MODULE_PARAMS+=(" $param " )
85+ done < " ${base_path} /nvidia.conf"
86+ echo " Module parameters provided for nvidia: ${NVIDIA_MODULE_PARAMS[@]} "
87+ fi
88+ }
89+
6790_install_driver () {
6891 local tmp_dir=$( mktemp -d)
6992
7093 sh NVIDIA-Linux-${DRIVER_ARCH} -${DRIVER_VERSION} -vgpu-kvm.run --ui=none --no-questions --tmpdir ${tmp_dir} --no-systemd
7194}
7295
73- # Currently _install_driver() takes care of loading nvidia modules. Just need to start necessary vgpu daemons
96+ _create_module_params_conf () {
97+ echo " Parsing kernel module parameters..."
98+ _get_module_params
99+
100+ if [ ${# NVIDIA_MODULE_PARAMS[@]} -gt 0 ]; then
101+ echo " Configuring nvidia module parameters in ${MODPROBE_CONFIG_DIR} /nvidia.conf"
102+ echo " options nvidia ${NVIDIA_MODULE_PARAMS[@]} " > ${MODPROBE_CONFIG_DIR} /nvidia.conf
103+ fi
104+ }
105+
106+ # Load NVIDIA driver kernel modules with custom parameters and start vGPU daemons
74107_load_driver () {
108+ # Unload modules if they're already loaded so we can reload with custom parameters
109+ if [ -f /sys/module/nvidia_vgpu_vfio/refcnt ] || [ -f /sys/module/nvidia/refcnt ]; then
110+ echo " NVIDIA modules already loaded by installer, unloading to apply custom parameters..."
111+ rmmod nvidia_vgpu_vfio 2> /dev/null || true
112+ rmmod nvidia 2> /dev/null || true
113+ fi
114+
115+ echo " Loading NVIDIA driver kernel modules..."
116+ set -o xtrace +o nounset
117+ modprobe nvidia
118+ modprobe nvidia_vgpu_vfio
119+ set +o xtrace -o nounset
120+
121+ # Start vGPU daemons
75122 /usr/bin/nvidia-vgpud
76123 /usr/bin/nvidia-vgpu-mgr &
77124
@@ -193,6 +240,7 @@ init() {
193240 _unmount_rootfs
194241 _create_dev_char_directory
195242 _set_fw_search_path
243+ _create_module_params_conf
196244 _install_driver
197245 _load_driver || exit 1
198246 _mount_rootfs
0 commit comments