Skip to content

Commit

Permalink
Making PCI passthrough devices appear on dedicated PCI buses
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Shaposhnik <rvs@zededa.com>
  • Loading branch information
rvs committed May 13, 2021
1 parent ac3865f commit c236071
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 39 deletions.
20 changes: 16 additions & 4 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ const qemuDiskTemplate = `
driver = "virtio-9p-pci"
fsdev = "fsdev{{.DiskID}}"
mount_tag = "share_dir"
addr = "{{.PCIId}}"
addr = "{{printf "0x%x" .PCIId}}"
{{else}}
[device "pci.{{.PCIId}}"]
driver = "pcie-root-port"
port = "1{{.PCIId}}"
chassis = "{{.PCIId}}"
bus = "pcie.0"
addr = "{{.PCIId}}"
addr = "{{printf "0x%x" .PCIId}}"
[drive "drive-virtio-disk{{.DiskID}}"]
file = "{{.FileLocation}}"
Expand Down Expand Up @@ -277,7 +277,7 @@ const qemuNetTemplate = `
chassis = "{{.PCIId}}"
bus = "pcie.0"
multifunction = "on"
addr = "{{.PCIId}}"
addr = "{{printf "0x%x" .PCIId}}"
[netdev "hostnet{{.NetID}}"]
type = "tap"
Expand All @@ -295,9 +295,19 @@ const qemuNetTemplate = `
`

const qemuPciPassthruTemplate = `
[device "pci.{{.PCIId}}"]
driver = "pcie-root-port"
port = "1{{.PCIId}}"
chassis = "{{.PCIId}}"
bus = "pcie.0"
multifunction = "on"
addr = "{{printf "0x%x" .PCIId}}"
[device]
driver = "vfio-pci"
host = "{{.PciShortAddr}}"
bus = "pci.{{.PCIId}}"
addr = "0x0"
{{- if .Xvga }}
x-vga = "on"
{{- end -}}
Expand Down Expand Up @@ -559,9 +569,10 @@ func (ctx kvmContext) CreateDomConfig(domainName string, config types.DomainConf
}
if len(pciAssignments) != 0 {
pciPTContext := struct {
PCIId int
PciShortAddr string
Xvga bool
}{PciShortAddr: "", Xvga: false}
}{PCIId: netContext.PCIId, PciShortAddr: "", Xvga: false}

t, _ = template.New("qemuPciPT").Parse(qemuPciPassthruTemplate)
for _, pa := range pciAssignments {
Expand All @@ -576,6 +587,7 @@ func (ctx kvmContext) CreateDomConfig(domainName string, config types.DomainConf
return logError("can't write PCI Passthrough to config file %s (%v)", file.Name(), err)
}
pciPTContext.Xvga = false
pciPTContext.PCIId = pciPTContext.PCIId + 1
}
}
if len(serialAssignments) != 0 {
Expand Down
Loading

0 comments on commit c236071

Please sign in to comment.