Page MenuHomeFreeBSD

bhyve: add hook for PCI header of passthru devices
ClosedPublic

Authored by corvink on Nov 16 2021, 12:23 PM.
Tags
Referenced Files
Unknown Object (File)
Fri, Dec 13, 10:03 PM
Unknown Object (File)
Sat, Dec 7, 7:50 AM
Unknown Object (File)
Sat, Dec 7, 1:22 AM
Unknown Object (File)
Tue, Dec 3, 6:30 AM
Unknown Object (File)
Tue, Dec 3, 6:27 AM
Unknown Object (File)
Tue, Dec 3, 5:41 AM
Unknown Object (File)
Tue, Dec 3, 5:07 AM
Unknown Object (File)
Sun, Dec 1, 12:41 PM

Details

Summary
Most register of the PCI header are either constant values or require
emulation anyway. The command and status register are the only exception which
require hardware access. So, we're adding an emulation handler for all
other register.

As this emulation handler will be reused by some future features like
GPU passthrough, we directly export it.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 50614
Build 47505: arc lint + arc unit

Event Timeline

corvink edited the summary of this revision. (Show Details)
corvink added reviewers: jhb, markj.
usr.sbin/bhyve/pci_passthru.c
599

Humm, I would maybe just use int or u_int instead of uint32_t for config register addresses throughout? The new function hooks all use int.

599

I would maybe use int or u_int instead of uint32_t for PCI config space addresses? If you really wanted a fixed-width type, uint16_t would be the most accurate, but a simple int is what the new function hooks use already.

Also, I would maybe use i <= PCIR_MAXLAT instead of adding a new constant.

606

Humm, is it really safe to read all these as individual bytes? I would be tempted to read things like BARs as 32-bit values as I'm not sure if all hardware is going to tolerate byte reads?

646

80 cols?

873

Maybe "Default PCI config registers to accessing the config register of the physical device."

875–876

The whitespace seems inconsistent here and in the clauses below?

877

Newlines before comments.

Also, I would maybe reword this somewhat to be more like "Emulate most PCI header registers",

938

How is this handled now? Seems like you need to add a new call to set emulated hooks for this range when this value is true?

944

()'s around the "argument" to return

955

Hummm, shouldn't these be handled by setting the ranges for these config registers to the emulated hooks earlier?

That is, I guess you need custom handlers for write, but having passthru_cfgwrite_msicap seems more consistent with the change you are making here?

958

I think it would be beneficial for this patch to move this into a separate function.

  • split patch into multiple
corvink retitled this revision from bhyve: use handlers for cfg reads/writes of passthru devices to bhyve: add hook for PCI header of passthru devices.
corvink edited the summary of this revision. (Show Details)
usr.sbin/bhyve/pci_passthru.c
882

But now we don't emulate accesses to fields below PCIR_BAR(0)?

usr.sbin/bhyve/pci_passthru.c
882

I should improve my commit message.

Except the command and status register, the PCI header contains fixed values or values which require emulation anyways. So, IMHO, we should always emulate the whole PCI header. It makes the code simpler and avoids hardware accesses.

PCIR_CAP_PTR is always emulated. So, we can remove one LEGACY_SUPPORT define.

  • remove static from emulation handler to properly export them
markj added inline comments.
usr.sbin/bhyve/pci_passthru.c
600
601
This revision is now accepted and ready to land.Apr 11 2023, 8:05 PM