How would I go about this wierd passthrough setup?

I have a NVIDIA 1070 and AMD 570. I’d like to have both on my linux system sometimes, but maintain the option to use the 1070 for passthrough on a windows VM.

The reason I want both sometimes on linux is because I want to use the 1070 for tensorflow as well as occasionally using it as an additional second GPU for obs recording where the 570 renders the game. If possible I would really rather not run a headless host as im pretty nervous about that whole idea. I’m guessing it is possible with a similar approach to single gpu passthrough.

IOMMU Groups

IOMMU Group 0:
-e 00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 1:
-e 00:01.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe GPP Bridge [1022:1453]
IOMMU Group 10:
-e 00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 59)
-e 00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51)
IOMMU Group 11:
-e 00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 0 [1022:1460]
-e 00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 1 [1022:1461]
-e 00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 2 [1022:1462]
-e 00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 3 [1022:1463]
-e 00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 4 [1022:1464]
-e 00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 5 [1022:1465]
-e 00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 6 [1022:1466]
-e 00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Data Fabric: Device 18h; Function 7 [1022:1467]
IOMMU Group 12:
-e 01:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset USB 3.1 xHCI Controller [1022:43bb] (rev 02)
-e 01:00.1 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset SATA Controller [1022:43b7] (rev 02)
-e 01:00.2 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Device [1022:43b2] (rev 02)
-e 02:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset PCIe Port [1022:43b4] (rev 02)
-e 02:01.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset PCIe Port [1022:43b4] (rev 02)
-e 02:04.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] 300 Series Chipset PCIe Port [1022:43b4] (rev 02)
-e 03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 15)
-e 04:00.0 PCI bridge [0604]: ASMedia Technology Inc. ASM1083/1085 PCIe to PCI Bridge [1b21:1080] (rev 04)
IOMMU Group 13:
-e 07:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon RX 470/480/570/570X/580/580X] [1002:67df] (rev ef)
-e 07:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon RX 580] [1002:aaf0]
IOMMU Group 14:
-e 08:00.0 Non-Essential Instrumentation [1300]: Advanced Micro Devices, Inc. [AMD] Device [1022:145a]
IOMMU Group 15:
-e 08:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Platform Security Processor [1022:1456]
IOMMU Group 16:
-e 08:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) USB 3.0 Host Controller [1022:145c]
IOMMU Group 17:
-e 09:00.0 Non-Essential Instrumentation [1300]: Advanced Micro Devices, Inc. [AMD] Device [1022:1455]
IOMMU Group 18:
-e 09:00.2 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 51)
IOMMU Group 19:
-e 09:00.3 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) HD Audio Controller [1022:1457]
IOMMU Group 2:
-e 00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 3:
-e 00:03.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 4:
-e 00:03.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe GPP Bridge [1022:1453]
IOMMU Group 5:
-e 00:04.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 6:
-e 00:07.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 7:
-e 00:07.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Internal PCIe GPP Bridge 0 to Bus B [1022:1454]
IOMMU Group 8:
-e 00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) PCIe Dummy Host Bridge [1022:1452]
IOMMU Group 9:
-e 00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 00h-0fh) Internal PCIe GPP Bridge 0 to Bus B [1022:1454]

I believe I have the correct IOMMU Groups for this kind of setup, If I place my passthrough card (1070) into slot one, it seems to be isolated on group 13. Though currently in the text above it will list as a AMD 570 since I do not have my 1070 plugged in as of writing this post.

Also my primary monitor has two input’s which might be useful. Though I think I will end up using looking glass eventually. I think what will happen is having both 1070 and 570 plugged into my primary monitor. With 570 also plugged into my secondary. I don’t think need the 1070 plugged into an actual monitor when using it for linux purposes (tensorflow/obs).

Progress so far

I have enabled virtualization and IOMMU in my bios. But not much else.

System/Setup Specs

CPU: Ryzen 7 1700
Mobo: Asus Prime b350-plus (Latest BIOS as of writing, 5220)
Ram: 16GB two slots
Storage: Plenty but will probably be using qcow not a real drive.
GPU1(Non passthrough): Asus Strix RX 570.
GPU2(Passthrough): ZOTAC GeForce GTX 1070 Mini

Monitor1: VGA, DVI (Switchable)
Monitor2: VGA

I only have 1 keyboard and mouse.

Linux Details

OS: Ubuntu 19.04
Desktop: Default gnome (3.32.1)
Uname -a: Linux codedcosmos-UBUNTU 5.0.0-29-generic #31-Ubuntu SMP Thu Sep 12 13:05:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Probably going to be asked questions

Why not just use the 1070 for main and pass through 570 for VM?
I want to have a second GPU for recording on linux. I’d also like to use my PC with linux sometimes while tensorflow is running on the other gpu.

Why not just use the 570 for main and pass through 1070 for VM?
That prevents me from using 1070 for tensorflow. I need to be able to use both on linux. It also conflicts with the dual gpu OBS thing I want to do.

Why not just dual boot?
This is more interesting and more convenient. But If I can’t get this to work then I probably will dual boot.

Although I am pretty sure this is what I want. Im still open for suggestions.

Okay, so I used to kinda do this for Resolve.

The solution is to rebind the GPU, and reset it when you want to boot the windows VM.

I don’t do this anymore, but this is the scripts I used for it back in the day:

This was for a 1070 ti on my threadripper rig.

#!/bin/bash

#echo 1 > /sys/bus/pci/devices/0000:09:00.0/remove
#echo 1 > /sys/bus/pci/devices/0000:09:00.1/remove
echo '0000:09:00.0' > /sys/bus/pci/devices/0000:09:00.0/driver/unbind
echo '10de 1b82' > /sys/bus/pci/drivers/nvidia/new_id
echo '0000:09:00.0' > /sys/bus/pci/devices/0000:09:00.0/driver/bind
sleep 1
#echo 1 > /sys/bus/pci/rescan
sleep 1

lspci -nnk -d 10de:1b82
echo '0000:09:00.0' > /sys/bus/pci/devices/0000:09:00.0/driver/unbind
modprobe vfio-pci
echo '10de 1b82' > /sys/bus/pci/drivers/vfio-pci/new_id
echo '0000:09:00.0' > /sys/bus/pci/devices/0000:09:00.0/driver/bind
sleep 1
#echo 1 > /sys/bus/pci/rescan
sleep 1

It was a bit buggy, but this should help you.