[lxc-devel] [lxd/master] VM: Moves built-in GPU device to 0x5.0x address prefix

tomponline on Github lxc-bot at linuxcontainers.org
Wed Jun 10 15:13:10 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1532 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200610/dc4cc30c/attachment.bin>
-------------- next part --------------
From 1c7efa58ce2cea0f13ac5f0dabbd2ce46a1559fa Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 10 Jun 2020 16:08:35 +0100
Subject: [PATCH 1/2] lxd/instance/drivers/driver/qemu: Integrates built in GPU
 device PCI range with future passthrough GPU devices

Reserves the 0x5.0x address prefix for up to 8 GPU devices.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_qemu.go | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index b4f19fd9d7..b12bb68730 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1591,6 +1591,7 @@ func (vm *qemu) generateQemuConfigFile(devConfs []*deviceConfig.RunConfig, fdFil
 	// of each type to be added.
 	nicIndex := 0
 	diskIndex := 0
+	gpuIndex := 0
 	chassisIndex := 5 // Internal devices defined in the templates use indexes 1-4.
 
 	err = vm.addConfDriveConfig(sb, diskIndex)
@@ -1599,6 +1600,14 @@ func (vm *qemu) generateQemuConfigFile(devConfs []*deviceConfig.RunConfig, fdFil
 	}
 	diskIndex++ // The config drive is a 9p device which uses a PCIe function so increment index.
 
+	// GPU for console.
+	err = vm.addVGAConfig(sb, chassisIndex, gpuIndex)
+	if err != nil {
+		return "", err
+	}
+	gpuIndex++     // The built in GPU device uses a PCIe function so increment index.
+	chassisIndex++ // The built in GPU device uses a root port so increment index.
+
 	bootIndexes, err := vm.deviceBootPriorities()
 	if err != nil {
 		return "", errors.Wrap(err, "Error calculating boot indexes")
@@ -1638,12 +1647,6 @@ func (vm *qemu) generateQemuConfigFile(devConfs []*deviceConfig.RunConfig, fdFil
 		}
 	}
 
-	// GPU for console.
-	err = vm.addVGAConfig(sb, chassisIndex)
-	if err != nil {
-		return "", err
-	}
-
 	// Write the agent mount config.
 	agentMountJSON, err := json.Marshal(agentMounts)
 	if err != nil {
@@ -1689,10 +1692,11 @@ func (vm *qemu) addVsockConfig(sb *strings.Builder) error {
 }
 
 // addVGAConfig adds the qemu config required for setting up the host->VM vsock socket.
-func (vm *qemu) addVGAConfig(sb *strings.Builder, chassisIndex int) error {
+func (vm *qemu) addVGAConfig(sb *strings.Builder, chassisIndex int, gpuIndex int) error {
 	return qemuVGA.Execute(sb, map[string]interface{}{
 		"architecture": vm.architectureName,
 		"chassisIndex": chassisIndex,
+		"gpuIndex":     gpuIndex,
 	})
 }
 

From aa38c3d8385b45e5120a6d5196d643e10843c55a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 10 Jun 2020 16:10:04 +0100
Subject: [PATCH 2/2] lxd/instance/drivers/driver/qemu/templates: Updates built
 in GPU device to use GPU address range prefix

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_qemu_templates.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lxd/instance/drivers/driver_qemu_templates.go b/lxd/instance/drivers/driver_qemu_templates.go
index 69e80ac8cc..be1b982057 100644
--- a/lxd/instance/drivers/driver_qemu_templates.go
+++ b/lxd/instance/drivers/driver_qemu_templates.go
@@ -177,10 +177,11 @@ var qemuVGA = template.Must(template.New("qemuVGA").Parse(`
 {{if eq .architecture "x86_64" "aarch64" -}}
 [device "qemu_pcie{{.chassisIndex}}"]
 driver = "pcie-root-port"
-port = "0x4"
+port = "0x{{.gpuIndex}}"
 chassis = "{{.chassisIndex}}"
 bus = "pcie.0"
-addr = "0x4.0x1"
+addr = "0x5.0x{{.gpuIndex}}"
+multifunction = "on"
 {{- end }}
 
 [device "dev-qemu_vga"]


More information about the lxc-devel mailing list