Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtual/openstack: configure VFIO with NIOMMU by default #257

Merged
merged 1 commit into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bindata/scripts/load-kmod.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/sh
# chroot /host/ modprobe $1
kmod_name=$(tr "-" "_" <<< $1)
kmod_args="${@:2}"
EmilienM marked this conversation as resolved.
Show resolved Hide resolved
chroot /host/ lsmod | grep "^$1" >& /dev/null

if [ $? -eq 0 ]
then
# NOTE: We do not check if the module is loaded with specific options
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
# so a manual reload is required if the module is loaded with
# new or different options.
echo "Module $kmod_name already loaded; no change will be applied..."
EmilienM marked this conversation as resolved.
Show resolved Hide resolved
exit 0
else
chroot /host/ modprobe $kmod_name
chroot /host/ modprobe $kmod_name $kmod_args
fi
10 changes: 10 additions & 0 deletions pkg/plugins/virtual/virtual_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func (p *VirtualPlugin) Apply() error {
glog.Infof("virtual-plugin Apply(): desiredState=%v", p.DesireState.Spec)

if p.LoadVfioDriver == loading {
// In virtual deployments of Kubernetes where the underlying virtualization platform does not support a virtualized iommu
// the VFIO PCI driver needs to be loaded with a special flag.
// This is the case for OpenStack deployments where the underlying virtualization platform is KVM.
// NOTE: if VFIO was already loaded for some reason, we will not try to load it again with the new options.
kernelArgs := "enable_unsafe_noiommu_mode=1"
if err := utils.LoadKernelModule("vfio", kernelArgs); err != nil {
glog.Errorf("virtual-plugin Apply(): fail to load vfio kmod: %v", err)
return err
}

if err := utils.LoadKernelModule("vfio_pci"); err != nil {
glog.Errorf("virtual-plugin Apply(): fail to load vfio_pci kmod: %v", err)
return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,13 @@ func getVfInfo(pciAddr string, devices []*ghw.PCIDevice) sriovnetworkv1.VirtualF
return vf
}

func LoadKernelModule(name string) error {
glog.Infof("LoadKernelModule(): try to load kernel module %s", name)
cmd := exec.Command("/bin/sh", scriptsPath, name)
func LoadKernelModule(name string, args ...string) error {
glog.Infof("LoadKernelModule(): try to load kernel module %s with arguments '%s'", name, args)
cmdArgs := strings.Join(args, " ")
cmd := exec.Command("/bin/sh", scriptsPath, name, cmdArgs)
err := cmd.Run()
if err != nil {
glog.Errorf("LoadKernelModule(): fail to load kernel module %s: %v", name, err)
glog.Errorf("LoadKernelModule(): fail to load kernel module %s with arguments '%s': %v", name, args, err)
return err
}
return nil
Expand Down