OFS / opae-sdk

Open Programmable Acceleration Engine
https://ofs.github.io
BSD 3-Clause "New" or "Revised" License
251 stars 84 forks source link

SRIOV VFs Fault during Multi-threaded Operation #3135

Open MaistoV opened 2 months ago

MaistoV commented 2 months ago

Enviroment setup:

Design and use case:

Using the OFSS flow, we have multiple instances of the same AFU in a flat FIM. Leveraging the thread-safety capabilities of the SRIOV stack, we wish to use such AFUs as independent VFs in a multi-threaded/process setup:

Each AFU is used in a pretty standard OPAE access pattern:

  1. We bind the target VF to the VFIO and the user with:
    • pcie_device
    • opae.io init
  2. We grub a specific AFU with OPAE APIs in C (not C++), namely:
    • fpgaPropertiesSetObjectType()
    • fpgaPropertiesSetGUID ()
    • fpgaPropertiesSetSegment ()
    • fpgaPropertiesSetBus ()
    • fpgaPropertiesSetDevice ()
    • fpgaPropertiesSetFunction ()
    • fpgaEnumerate()
    • fpgaOpen()
    • fpgaMapMMIO()
  3. We allocate two buffers:
    • with fpgaPrepareBuffer()
    • use fpgaGetIOAddress() to retrieve the addresss for the AFU
    • write such addresses either with mapped MMIO or fpgaWriteMMIO64() to AFU CSRs
  4. We start the AFU, which reads inputs from the first buffer and writes outputs to the second
  5. We wait for the AFU to complete either by polling on the status register or by mapped interrupt events on a file descriptor, i.e. with:
    • fpgaCreateEventHandle()
    • fpgaRegisterEvent()
  6. Subsequently read results from the mapped output buffer.

Issue:

We observed a systematic error operating on more than two VFs/AFUs in parallel, effectively limiting the number of usable VFs to 2. This is very problematic to us, since our system-level design relies on the multi-threaded capabilities of the OPAE/SRIOV stack.

More in detail:

We replicated the issue below on two different host setups, both featuring IOMMU, VT-d and SRIOV support over a PCIe x16 Gen 4.0 slot:

  1. Intel(R) Xeon(R) Gold 5418N HPE server host
  2. 11th Gen Intel(R) Core(TM) i9, MSI workstation

More notes

Possible issues

Judging from the beaviour above, this seems to us as a software issue. We suspect that at some level of the OPAE library / VFIO driver stack, the IOMMU mapping is compromised, i.e. writes from the AFU are not propagated in the user pages. We have inspected the source code of the OPAE library, but were not able to find a clear cause for this beaviour.

umairsiddiqui-digitek commented 1 month ago

the opae-sdk 2.12.0-5 which was released as part of OFS-2024.1 has several SRIOV/vfio fixes

https://github.com/OFS/opae-sdk/releases/tag/2.12.0-5

check this new update in opae-sdk 2.12.0-5 https://github.com/OFS/opae-sdk/compare/4cb9d59..31d4aba?diff=split&w=#diff-59969ebf5bd82fbc67352bfa9a72c999271f931f95a51842fc52bf16f127f72d

note that in OFS-2024.1, other OFS components like DFL kernel & OFS RTL were updated as well: https://github.com/orgs/OFS/discussions/62