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

Device: Forbid CDI GPU hotplugging #14031

Merged
Merged
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
26 changes: 26 additions & 0 deletions lxd/device/gpu_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/canonical/lxd/lxd/storage/filesystem"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/logger"
)

const gpuDRIDevPath = "/dev/dri"
Expand Down Expand Up @@ -598,6 +599,31 @@ func (d *gpuPhysical) stopCDIDevices(configDevices cdi.ConfigDevices, runConf *d
return nil
}

// CanHotPlug returns whether the device can be managed whilst the instance is running.
// CDI GPU are not hotpluggable because the configuration of a CDI GPU requires a LXC hook that
// is only run at instance start. A classic GPU device can be hotplugged.
func (d *gpuPhysical) CanHotPlug() bool {
if d.inst.Type() == instancetype.Container {
if d.config["id"] != "" {
// Check if the id of the device match a CDI format.
cdiID, err := cdi.ToCDI(d.config["id"])
if err != nil {
d.logger.Error("Failed to parse CDI ID when hotplugging", logger.Ctx{"err": err})
return false
}

if !cdiID.Empty() {
d.logger.Warn("Hotplugging CDI devices is not supported", logger.Ctx{"id": d.config["id"]})
return false
}
}

return true
}

return false
}

// Stop is run when the device is removed from the instance.
func (d *gpuPhysical) Stop() (*deviceConfig.RunConfig, error) {
runConf := deviceConfig.RunConfig{
Expand Down
Loading