cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu's comments
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
PCIEM_EVENT_MMIO_READ is kept for reference on the while (head != tail) loop just to remind the user that there can be more than 1 event registered in terms of access type.
Let's say that you register your watchpoint in READ mode (I still have to change the IOCTL for that as currently is hardcoded for writes: attr.bp_type = HW_BREAKPOINT_W), then you'd be consuming PCIEM_EVENT_MMIO_READ events instead of PCIEM_EVENT_MMIO_WRITE.
The fact that the PCIEM_EVENT_MMIO_READ define is there is to help me remind me to incorporate that missing logic.
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
PCIem kinda does that, but it's down a level; in terms of, it basically pops the device on your host PCI bus, which lets real, unmodified drivers to interact with the userspace implementation of your card, no QEMU, no VM, no hypervisors.
Not saying that you can then, for instance, forward all the accesses to QEMU (Some people/orgs already have their cards defined in QEMU so it'd be a bit pointless to redefine the same stuff over and over, right?) so they're free to basically glue their QEMU stuff to PCIem in case they want to try the driver directly on the host but maintaining the functional emulation on QEMU. PCIem takes care of abstracting the accesses and whatnot with an API that tries to mimick that the cool people over at KVM do.
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
As in, PCIem is going to populate the bus with virtually the same card (At least, in terms of capabilities, vendor/product id... and whanot) so I don't see how you'd then add another layer of indirection that somehow can transparently process the unfiltered transaction stream PCIem provides to it to an actual PCIe card on the bus. I feel like there's many colliding responsabilities in this.
I would instead suggest to have some sort of behavioural model (As in, have a predefined set of data to feed from/to) and have PCIem log all the accesses your real driver does. That way the driver would have enough infrastructure not to crash and at the same time you'd get the transport layer information.
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
You basically have the kernel eventfd notify you about any access triggered (Based on your configuration), so from userspace, you have the eventfd and then you mmap the shared lock-less ring buffer that actually contains the events PCIem notifies (So you don't end up busy polling).
You basically mmap a struct pciem_shared_ring where you'll have your usual head/tail pointers.
From then on, on your main, you'd have a select() or a poll() for the eventfd; when PCIem notifies the userspace you'd check head != tail (Which means there are events to process) and you can basically do:
struct pciem_event *event = &event_ring->events[head]; atomic_thread_fence(memory_order_acquire); if (event->type == PCIEM_EVENT_MMIO_WRITE) handle_mmio_read(...);
And that's it, don't forget to update the head pointer!
I'll go and update the docs now. Hopefully this clears stuff up!
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
Usually, without actual silicon, you are pretty limited on what you can do in terms of anticipating the software that'll run.
What if you want to write a driver for it w/o having to buy auxiliary boards that act as your card? What happens if you already have a driver and want to do some security testing on it but don't have the card/don't want to use a physical one for any specific reason (Maybe some UB on the driver pokes at some register that kills the card? Just making disastrous scenarios to prove the point hah).
What if you want to add explicit failures to the card so that you can try and make the driver as tamper-proof and as fault-tolerant as possible (Think, getting the PCI card out of the bus w/o switching the computer off)?
Testing your driver functionally and/or behaviourally on CI/CD on any server (Not requiring the actual card!)?
There's quite a bunch of stuff you can do with it, thanks to being in userspace means that you can get as hacky-wacky as you want (Heck, I have a dumb-framebuffer-esque and OpenGL 1.X capable QEMU device I wanted to write a driver for fun and I used PCIem to forward the accesses to it).
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
Hopefully this is what you're searching for!
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace
PCIe prototyping is usually not something super straightforward if you don't want to pay hefty sums IME.
cakehonolulu | 1 month ago | on: Linux kernel framework for PCIe device emulation, in userspace