4

I have a possibly-buggy piece of hardware and a possibly-buggy userspace driver for it that relies on the vfio-pci kernel driver. I'd like to test the driver without dealing with the hardware.

I imagine the ideal solution would be something like: run my whole stack except for the hardware (application, userspace driver, VFIO driver) and intercept everything that the VFIO driver decides to send on to the hardware. Then I could verify that the hardware is getting the right info -- resets are happening at the expected time, DMAs are going to the right addresses, etc.

I guess I'm looking for something like a mock device that will let me run userspace code underneath vfio-pci rather than running hardware. Does such a thing exist?

Patrick Collins
  • 10,306
  • 5
  • 30
  • 69

1 Answers1

1

Emulating devices has gotten impressively easy with Qemu. I've often used it to do some Linux kernel research. On Archlinux, the qemu-arch-extra comes with a bunch of machines:

$ qemu-system-arm -machine help
Supported machines are:
[..]
cubieboard           cubietech cubieboard
emcraft-sf2          SmartFusion2 SOM kit from Emcraft (M2S010)
highbank             Calxeda Highbank (ECX-1000)
imx25-pdk            ARM i.MX25 PDK board (ARM926)
integratorcp         ARM Integrator/CP (ARM926EJ-S)
kzm                  ARM KZM Emulation Baseboard (ARM1136)
lm3s6965evb          Stellaris LM3S6965EVB
lm3s811evb           Stellaris LM3S811EVB
mainstone            Mainstone II (PXA27x)
midway               Calxeda Midway (ECX-2000)
[and more...]

A good approach for your task would be to write an emulated PCI device for Qemu, and test it there.

There really isn't much to explain about it, given there are plenty of good materials on using and extending Qemu. A quick google search shows a couple good resources. This answer has some super useful hints, and here's a decent tutorial.

Ezequiel Garcia
  • 1,037
  • 8
  • 20
  • I was hoping that something existed that was usable out of the box, but I guess not. Do you have any pointers towards what it takes to stub out a device without qemu? I think I'm missing some fundamental aspect of this process. – Patrick Collins Feb 17 '18 at 03:35