Hi,
klange wrote:
SpyderTL wrote:
There's not a lot of benefit to detecting the VM host, but you should probably focus on detecting and handling the specific PCI devices that those VMs expose on the PCI bus.
So instead of writing custom VirtualBox code, you should probably be writing custom code for detecting and handling the VirtualBox Video Card, the VirtualBox Mouse/Tablet, the VirtualBox Network Card, etc.
Detecting the VirtualBox, Bochs, VMWare, etc. hosts makes about as much sense as detecting whether your OS is running on a Dell, or HP, or Alienware Laptop...
Definitely this. There's no good reason to detect the VMs. Detect the hardware instead! QEMU can emulate several different kinds of graphical hardware. Its current default in recent releases (from the past several years) is the "Bochs VBE" virtual card, which shows up as an easily-identified PCI device (and has a very simple interface for modesetting). Bochs also defaults to this (obviously, if you didn't catch it from the name; though it won't show up as a PCI device unless you specifically set it up as such), as does VirtualBox. But QEMU supports other cards - including its old default of a Cirrus VGA card, and newer options like virtio-gpu, but also the VMware SVGA interface (which VirtualBox can also emulate with some obtuse and rather hidden options). Detecting VMs in itself doesn't even get you anything if those VMs can implement different hardware depending on their configuration.
It's not so much that there's no good reason to detect VMs; it's just that those good reasons are unrelated and rarely have anything to do with video.
The main reason to detect VMs is so that you can work around the VM's quirks (in the same way that you might detect a real CPU so that you can work around its CPU errata) and so that you don't accidentally do the reverse (assume that errata for a real CPU effects a virtual CPU that happens to give you the same info from CPUID). Of course this applies to all hardware - any device emulated by a VM might have slight differences compared to a real device with the same identification or the same device in a different VM.
For some examples (from memory); for Bochs, there's no "F00F" or FPU bugs when emulating a Pentium chip (and I'd expect it's immune to flaws like Rowhammer, Spectre and Meltdown), the floppy drives don't need delays to get the motor up to speed and don't need the "retry 3+ times before you take a read error seriously" stuff, when emulating a PCI Cirrus Logic video card the video ROM behaves like an ISA card's ROM and can't be controlled via. a BAR in the device's PCI configuration space, there's no performance monitoring counters (too expensive to emulate), there's no power management (even when emulating modern CPUs), etc.
Cheers,
Brendan