diff options
| author | George Kennedy <george.kennedy@oracle.com> | 2022-09-09 18:49:22 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-09-21 11:46:22 +0200 |
| commit | 799171eb67633beabfe4f86022c58de3a796f1b4 (patch) | |
| tree | 8f6b46d59cbcc2c1d8a75f282d966dc6f21b9991 | |
| parent | 0ef784044111a4853c31d6865f4ad54c2369fd8b (diff) | |
vm/qemu: support VFs > 8
Syzkaller currently only supports 8 (0-7) pass-through VFs.
Add support for VFs > 8 by incrementing the Device # and
resetting the VF # to zero when INDEX modulo 8 = zero.
Introduce "{{FN%8}}" to trigger this support.
Ex: vfio-pci,host=31:0a.{{FN%8}}
Signed-off-by: George Kennedy <george.kennedy@oracle.com>
| -rw-r--r-- | vm/qemu/qemu.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go index e57c755c3..f5e50c087 100644 --- a/vm/qemu/qemu.go +++ b/vm/qemu/qemu.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -42,6 +43,7 @@ type Config struct { // "{{INDEX}}" is replaced with 0-based index of the VM (from 0 to Count-1). // "{{TEMPLATE}}" is replaced with the path to a copy of workdir/template dir. // "{{TCP_PORT}}" is replaced with a random free TCP port + // "{{FN%8}}" is replaced with PCI BDF (Function#%8) and PCI BDF Dev# += index/8 QemuArgs string `json:"qemu_args"` // Location of the kernel for injected boot (e.g. arch/x86/boot/bzImage, optional). // This is passed to QEMU as the -kernel option. @@ -540,6 +542,26 @@ func (inst *instance) boot() error { return nil } +// "vfio-pci,host=BN:DN.{{FN%8}},addr=0x11". +func handleVfioPciArg(arg string, index int) string { + if !strings.Contains(arg, "{{FN%8}}") { + return arg + } + if index > 7 { + re := regexp.MustCompile(`vfio-pci,host=[a-bA-B0-9]+(:[a-bA-B0-9]{1,8}).{{FN%8}},[^:.,]+$`) + matches := re.FindAllStringSubmatch(arg, -1) + if len(matches[0]) != 2 { + return arg + } + submatch := matches[0][1] + dnSubmatch, _ := strconv.ParseInt(submatch[1:], 16, 64) + devno := dnSubmatch + int64(index/8) + arg = strings.ReplaceAll(arg, submatch, fmt.Sprintf(":%02x", devno)) + } + arg = strings.ReplaceAll(arg, "{{FN%8}}", fmt.Sprint(index%8)) + return arg +} + func splitArgs(str, templateDir string, index int) (args []string) { for _, arg := range strings.Split(str, " ") { if arg == "" { @@ -547,6 +569,7 @@ func splitArgs(str, templateDir string, index int) (args []string) { } arg = strings.ReplaceAll(arg, "{{INDEX}}", fmt.Sprint(index)) arg = strings.ReplaceAll(arg, "{{TEMPLATE}}", templateDir) + arg = handleVfioPciArg(arg, index) const tcpPort = "{{TCP_PORT}}" if strings.Contains(arg, tcpPort) { arg = strings.ReplaceAll(arg, tcpPort, fmt.Sprint(vmimpl.UnusedTCPPort())) |
