PCILeechGen icon indicating copy to clipboard operation
PCILeechGen copied to clipboard

Device i/o error

Open platinum55 opened this issue 9 months ago • 28 comments

Hello,

thank you for the update, I was able to build the firmware without errors. However the emulated device is not functional in windows (shows I/O error, cannot be started), speedtest is not working (DMA Access)

./bin/pcileechgen check --bdf 0000:02:00.0
Checking device 0000:02:00.0...

[OK] Device found: 144d:a80a Non-Volatile memory controller
[OK] Config space readable: 4096 bytes
[OK] IOMMU is enabled
[OK] VFIO modules loaded
[OK] IOMMU group: 14
[OK] Already bound to vfio-pci

Capabilities (4):
  [01] Power Management at offset 0x40
  [05] MSI at offset 0x50
  [10] PCI Express at offset 0x70
  [11] MSI-X at offset 0xb0

Extended Capabilities (8):
  [0001] Advanced Error Reporting at offset 0x100
  [000e] Alternative Routing-ID Interpretation at offset 0x168
  [0019] Secondary PCI Express at offset 0x178
  [0026] Unknown at offset 0x198
  [0027] Unknown at offset 0x1bc
  [0018] Latency Tolerance Reporting at offset 0x214
  [001e] L1 PM Substates at offset 0x21c
  [0025] Unknown at offset 0x3a0

BARs:
  BAR0: mem64 at 0x81400000, size 16 KB

--- Board Compatibility ---
Donor Link: Unknown (4) x4
[WARN] Donor has no DSN capability (serial number won't be emulated)

Compatible boards:
  [WARN] PCIeSquirrel           xc7a35tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] ScreamerM2             xc7a35tcsg325-2 x1 (link clamped: x4 -> x1)
  [WARN] pciescreamer           xc7a35tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] EnigmaX1               xc7a75tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] CaptainDMA_M2_x1       xc7a35tcsg325-2 x1 (link clamped: x4 -> x1)
  [OK] CaptainDMA_M2_x4       xc7a35tcsg325-2 x4 (exact match)
  [WARN] CaptainDMA_35T         xc7a35tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] CaptainDMA_75T         xc7a75tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] CaptainDMA_100T        xc7a100tfgg484-2 x1 (link clamped: x4 -> x1)
  [OK] ZDMA                   xc7a100tfgg484-2 x4 (exact match)
  [WARN] GBOX                   xc7a35tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] NeTV2_35T              xc7a35tfgg484-2 x1 (link clamped: x4 -> x1)
  [WARN] NeTV2_100T             xc7a100tfgg484-2 x1 (link clamped: x4 -> x1)
  [OK] ac701_ft601            xc7a200tfbg676-2 x4 (exact match)
  [OK] acorn                  xc7a200tfbg484-3 x4 (exact match)
  [OK] litefury               xc7a100tfgg484-2 x4 (exact match)
  [WARN] sp605_ft601            xc6slx45tfgg484-2 x1 (link clamped: x4 -> x1)

Total: 17 boards

--- Check complete ---
root@rescue64:~/PCILeechGen# ./bin/pcileechgen build --bdf 0000:02:00.0 --board CaptainDMA_75T --skip-vivado
[pcileechgen] Target device: 0000:02:00.0
[pcileechgen] Stage 1: Collecting donor device data...
[donor] Read 4096 bytes from BAR0
[pcileechgen] Target board: CaptainDMA_75T (xc7a75tfgg484-2)
[pcileechgen] Output: pcileech_datastore
[pcileechgen] Device: 144d:a80a Non-Volatile memory controller (rev 00)
[pcileechgen] Config space: 4096 bytes
[pcileechgen] Capabilities: 4 standard, 8 extended
[pcileechgen] BARs: 6 (1 with content)

[build] Stage 2: Generating firmware artifacts...
[firmware] SV patches applied:
  pcileech_fifo.sv:
    -> Shadow config space: ENABLED (CFGTLP ZERO DATA -> 0)
    -> CFG_SUBSYS_VEND_ID: 0x144D
    -> CFG_SUBSYS_ID: 0xA801
    -> CFG_VEND_ID: 0x144D
    -> CFG_DEV_ID: 0xA80A
    -> CFG_REV_ID: 0x00
    -> _pcie_core_config: all IDs updated
[build] Artifacts written to: pcileech_datastore
  - device_context.json
  - pcileech_cfgspace.coe
  - pcileech_cfgspace_writemask.coe
  - pcileech_bar_zero4k.coe
  - vivado_generate_project.tcl
  - vivado_build.tcl
  - src/
[build] Vivado synthesis skipped (--skip-vivado)

platinum55 avatar Mar 01 '26 14:03 platinum55

I assume there is simulation data missing, is the script fetching such with VFIO? So that windows can see a real and functioning device?

platinum55 avatar Mar 01 '26 15:03 platinum55

I am getting the same thing

vivado.log

this is the real device plugged in:

Image

This is the 100t

Image

btw thanks for letting us know about the other project, wasted a lot of time testing his stuff.

sthgi avatar Mar 01 '26 15:03 sthgi

thanks for the report guys. i realize this is a very annoying bug. there could be many reasons but so far i have discovered 2 bugs that could cause this:

  • broken ext cap chain: when scrubbing unsupported capabilities, the chain at 0x100 was getting zeroed out instead of properly relinked. this killed aer and other caps windows relies on.

  • bar size too large: your donor advertises 16 kb bar0 but the fpga bram is only 4kb, so any access past that got no response i/o error.

both fixed now(39649b7). get the latest and rebuild, should work. @platinum55 @sthgi

sercanarga avatar Mar 01 '26 16:03 sercanarga

Getting same thing

Here is the log let me know if you need anything else

vivado.log

I don't know if this helps I get this with the flashed 100t connected to linux machine running your project

Image

sthgi avatar Mar 01 '26 20:03 sthgi

@sthgi i have commit a new fix please check it. also the warning in the screenshot is not from the dma device but from the usb driver in your beelink mini computer.

sercanarga avatar Mar 01 '26 22:03 sercanarga

Hello,

thank you very much for your efforts! Trying the current build right now and will report back.

I see one critical error in Vivado, does this might cause the problems? It runs thru though...

[Synth 8-3321] create_clock attempting to set clock on an unknown port/pin for constraint at line 53 of /home/test/Desktop/shared/PCILeechGen/pcileech_datastore/CaptainDMA_75T/CaptainDMA_75T.gen/sources_1/ip/drom_pcie_cfgspace_writemask/drom_pcie_cfgspace_writemask_ooc.xdc.
["/home/test/Desktop/shared/PCILeechGen/pcileech_datastore/CaptainDMA_75T/CaptainDMA_75T.gen/sources_1/ip/drom_pcie_cfgspace_writemask/drom_pcie_cfgspace_writemask_ooc.xdc":53]

platinum55 avatar Mar 02 '26 02:03 platinum55

same thing on latest build

vivado.log

sthgi avatar Mar 02 '26 07:03 sthgi

@platinum55 @sthgi yes there is no critical problem in the logs you provided. please share windows pci logs (event viewer -> windows logs -> system) and device_context.json files.

sercanarga avatar Mar 02 '26 12:03 sercanarga

Hello,

here is the windows-event log:

System

  
Provider

   [ Name]  stornvme 
 
  
EventID 11

   [ Qualifiers]  49156 
 
   Version 0 
 
   Level 2 
 
   Task 0 
 
   Opcode 0 
 
   Keywords 0x80000000000000 
 
  
TimeCreated

   [ SystemTime]  2026-03-02T03:05:03.0752618Z 
 
   EventRecordID 889 
 
   Correlation 
 
  
Execution

   [ ProcessID]  4 
   [ ThreadID]  416 
 
   Channel System 
 
   Computer shepherd 
 
   Security 
 

EventData

   \Device\RaidPort2 
   0F00240001000000000000000B0004C002000000000000000000000000000000000000000000000001000000200004000B0004C0020000000000000000000000000000000000000004000000 


--------------------------------------------------------------------------------

Binary Data:


In Words

0000: 0024000F 00000001 00000000 C004000B 
0010: 00000002 00000000 00000000 00000000 
0020: 00000000 00000000 00000001 00040020 
0030: C004000B 00000002 00000000 00000000 
0040: 00000000 00000000 00000004


In Bytes

0000: 0F 00 24 00 01 00 00 00   ..$.....
0008: 00 00 00 00 0B 00 04 C0   .......À
0010: 02 00 00 00 00 00 00 00   ........
0018: 00 00 00 00 00 00 00 00   ........
0020: 00 00 00 00 00 00 00 00   ........
0028: 01 00 00 00 20 00 04 00   .... ...
0030: 0B 00 04 C0 02 00 00 00   ...À....
0038: 00 00 00 00 00 00 00 00   ........
0040: 00 00 00 00 00 00 00 00   ........
0048: 04 00 00 00               ....

device_context.json: //removed @sercanarga

Thanks again for your efforts! <3 Much appreciated!

platinum55 avatar Mar 02 '26 16:03 platinum55

@platinum55 thank you for sharing the logs. this is a total challange and don't worry i enjoy dealing with it. the stornvme error makes sense. what's happening is:

the nvme driver loads fine and sees your device, but then it tries to start the controller by poking some registers in bar0. since the fpga just has static memory there (not a real nvme controller), the driver never gets the "ready" signal back and gives up. That's what kills dma access too windows puts the whole device in an error state after that.

i just pushed a fix that should help. it pre-loads the bar0 memory with the right values so the driver sees the controller as already running. also fixed a couple of config space mismatches (payload size, extended tags) that could cause issues.

could you pull the latest and rebuild?

after you test it, let me know: what does device manager show - still "code 10" or something different? does speedtest work? if it's still not working, grab the new stornvme event log again (event viewer -> windows logs -> system -> filter by "stornvme")

sercanarga avatar Mar 02 '26 16:03 sercanarga

@platinum55 @sthgi yes there is no critical problem in the logs you provided. please share windows pci logs (event viewer -> windows logs -> system) and device_context.json files.

device_context.json

There is no logs in the windows event logs system. I cleared it then once i flashed I refreshed and there was nothing in it.

sthgi avatar Mar 03 '26 13:03 sthgi

@sthgi got it. two bugs with your renesas xhci. no event logs is expected for xhci btw, that's normal.

pull latest and rebuild. and please share event logs and context

sercanarga avatar Mar 03 '26 16:03 sercanarga

Hello, sadly it still shows error in windows, here is the current event log:

event.log
Provider

   [ Name]  stornvme 
 
  
EventID 11

   [ Qualifiers]  49156 
 
   Version 0 
 
   Level 2 
 
   Task 0 
 
   Opcode 0 
 
   Keywords 0x80000000000000 
 
  
TimeCreated

   [ SystemTime]  2026-03-03T05:20:14.4064486Z 
 
   EventRecordID 4215 
 
   Correlation 
 
  
Execution

   [ ProcessID]  4 
   [ ThreadID]  280 
 
   Channel System 
 
   Computer shepherd 
 
   Security 
 

EventData

   \Device\RaidPort2 
   0F00240001000000000000000B0004C002000000000000000000000000000000000000000000000001000000200004000B0004C0020000000000000000000000000000000000000004000000 


--------------------------------------------------------------------------------

Binary Data:


In Words

0000: 0024000F 00000001 00000000 C004000B 
0010: 00000002 00000000 00000000 00000000 
0020: 00000000 00000000 00000001 00040020 
0030: C004000B 00000002 00000000 00000000 
0040: 00000000 00000000 00000004


In Bytes

0000: 0F 00 24 00 01 00 00 00   ..$.....
0008: 00 00 00 00 0B 00 04 C0   .......À
0010: 02 00 00 00 00 00 00 00   ........
0018: 00 00 00 00 00 00 00 00   ........
0020: 00 00 00 00 00 00 00 00   ........
0028: 01 00 00 00 20 00 04 00   .... ...
0030: 0B 00 04 C0 02 00 00 00   ...À....
0038: 00 00 00 00 00 00 00 00   ........
0040: 00 00 00 00 00 00 00 00   ........
0048: 04 00 00 00               ....

Where exactly do you see in there the reason? Just interested in learning this stuff :)

platinum55 avatar Mar 03 '26 16:03 platinum55

@platinum55 i decoded your event log binary data - here's what's going on and how i got there.

the binary payload is an srb (scsi request block) error record from storport. the key parts:

0xC004000B - ntstatus error code meaning "nvme command timed out" retrycount = 4 - the driver tried 4 times, gave up each time srb status = 0x01 - request never completed you can decode these yourself by reading the bytes in little-endian and matching ntstatus codes from the windows sdk (ntstatus.h).

the fpga pretends to be an nvme controller by presenting the right config space and pre-loading bar0 registers (CSTS.RDY=1, CC.EN=1). this is enough for windows to enumerate the device. but when stornvme.sys actually tries to create queues and send nvme commands via dma - there's nobody home. the fpga is a dma engine, not a real storage controller. commands go unanswered, driver times out, eventid 11.

pcileech dma works at the pcie tlp level, completely independent of the nvme driver stack. these errors are harmless noise.

can you confirm: does dma access work? what does device manager show? (code 10 or something else?) if dma works, you can safely ignore these events. if not, share your device_context.json and i'll check the config space.

sercanarga avatar Mar 03 '26 17:03 sercanarga

@sthgi got it. two bugs with your renesas xhci. no event logs is expected for xhci btw, that's normal.

pull latest and rebuild. and please share event logs and context

device_context.json

vivado.log

Same error 10 and dma doesnt work

sthgi avatar Mar 03 '26 18:03 sthgi

@sthgi

checked your files. vivado build is clean, config space looks good. no issues on the firmware generation side. error code 10 is normal - the fpga can't actually run usb, so the xhci driver fails to start. that's expected.

but dma should work even with error 10. pcileech doesn't go through the windows driver, it works at the pcie level directly. if dma is also broken, it's probably not a config issue.

can you check: what does pcileech.exe testmemreadwrite output? does the device show up in device manager? are you flashing the right file? (pcileech_100t484_x1_top.bin)

sercanarga avatar Mar 03 '26 18:03 sercanarga

@sthgi

checked your files. vivado build is clean, config space looks good. no issues on the firmware generation side. error code 10 is normal - the fpga can't actually run usb, so the xhci driver fails to start. that's expected.

but dma should work even with error 10. pcileech doesn't go through the windows driver, it works at the pcie level directly. if dma is also broken, it's probably not a config issue.

can you check: what does pcileech.exe testmemreadwrite output? does the device show up in device manager? are you flashing the right file? (pcileech_100t484_x1_top.bin)

Image Image

yes flashed pcileech_100t484_x1_top.bin

This is what the real device looks like

Image

sthgi avatar Mar 03 '26 18:03 sthgi

@sthgi hmm. invalid parameters... did another set of updates. pull and try again. looks like we're pretty close to a solution

sercanarga avatar Mar 03 '26 19:03 sercanarga

@sercanarga yes, Error 10 ... can we achieve that the device is showing as functional? I saw in this vibe-coded-project that older versions were collection traffic with MemProcFS (I guess it was MMIO Traffic) to emulate the original handshakes(?) so that the driver thinks the device is responding. I also saw that Vivado supports "simdata", maybe you could add such a feature?

Will do more tests tomorrow, DMA Access was working from linux and from windows with another tool (lone tester did not work):

lone tester windows:

[i] Vmm Version: 5.8.25.145
[i] Leechcore Version: 2.16.11.62
DEVICE: FPGA: Enigma X1 PCIe gen2 x1 [250,10,500] [v4.14,0600] [ASYNC,NORM,FWCUST]
FPGA: TINY PCIe TLP algrithm auto-selected!
[CORE]     Initialization Failed. Unable to locate valid DTB. #2
VmmProc: Unable to auto-identify operating system.
         Specify PageDirectoryBase (DTB/CR3) in -dtb option if value if known.
         If arm64 dump, specify architecture: -arch arm64
[CORE]     Failed to initialize.

[CORE]     SHUTDOWN COMPLETED (0000021400408040).
[CORE]       TIME: 2026-03-02 22:05:28 UTC.
[CORE]       RUNTIME: 0s.

[FAIL] VMM INIT FAILED.

the other dma tester was working but seems to be slower than expected: windows:

 Memory Map:
 START              END               #PAGES


 Current Action: Probing Memory
 Access Mode:    Normal
 Progress:       4096 / 4096 (100%)
 Speed:          85 MB/s
 Address:        0x0000000100000000
 Pages read:     0 / 1048576 (0%)
 Pages failed:   1048576 (100%)
Memory Probe: Completed.

under linux I got full speed (I assume):

Memory Map:
 START              END               #PAGES
 0000000000000000 - 00000000e01fffff  000e0200
 00000000fc880000 - 00000000fc8a7fff  00000028
 00000000fc900000 - 00000000fc9fffff  00000100
 00000000fca10000 - 00000000fca1ffff  00000010
 00000000fca30000 - 00000000fca3ffff  00000010
 00000000fcb00000 - 00000000fcb09fff  0000000a
 00000000fcc00000 - 00000000fcc00fff  00000001
 00000000fcc03000 - 00000000fcc0cfff  0000000a
 00000000fcc0e000 - 00000000fcc13fff  00000006
 00000000fcc15000 - 00000000fcc17fff  00000003
 00000000fcc19000 - 00000000fcc1bfff  00000003
 00000000fcc1e000 - 00000000fcc21fff  00000004
 00000000fcc24000 - 00000000fcc30fff  0000000d
 00000000fcc32000 - 00000000fcc3bfff  0000000a
 00000000fcc3d000 - 00000000fcc3efff  00000002
 00000000fcc41000 - 00000000fcc45fff  00000005
 00000000fcc49000 - 00000000fcc4afff  00000002
 00000000fcc58000 - 00000000fcc58fff  00000001
 00000000fcc5a000 - 00000000fcc5efff  00000005
 00000000fcc68000 - 00000000fcc68fff  00000001
 00000000fcc6a000 - 00000000fcc6afff  00000001
 00000000fcc6c000 - 00000000fcc6cfff  00000001
 00000000fcc70000 - 00000000fcc71fff  00000002
 00000000fcc73000 - 00000000fcc73fff  00000001
 00000000fce00000 - 00000000fce01fff  00000002
 00000000fce03000 - 00000000fce03fff  00000001
 00000000fcf00000 - 00000000fcf03fff  00000004
 00000000fd010000 - 00000000fd01ffff  00000010
 00000000fd030000 - 00000000fd03ffff  00000010
 00000000fd210000 - 00000000fd212fff  00000003
 00000000fd214000 - 00000000fd217fff  00000004
 00000000fd219000 - 00000000fd21dfff  00000005
 00000000fd21f000 - 00000000fd21ffff  00000001
 00000000fd230000 - 00000000fd234fff  00000005
 00000000fd236000 - 00000000fd23cfff  00000007
 00000000fd23e000 - 00000000fd23ffff  00000002
 00000000fec00000 - 00000000fec01fff  00000002
 00000000fec10000 - 00000000fec10fff  00000001
 00000000fed00000 - 00000000fed00fff  00000001
 00000000fed80000 - 00000000fed81fff  00000002
 00000000fedc0000 - 00000000fedc0fff  00000001
 00000000fedc2000 - 00000000fedcffff  0000000e
 00000000fedd5000 - 00000000fedd5fff  00000001
 0000000100000000 - 000000082f37ffff  0072f380

 Current Action: Probing Memory
 Access Mode:    Normal
 Progress:       33523 / 33523 (100%)
 Speed:          403 MB/s
 Address:        0x000000082F380000
 Pages read:     8451953 / 8582016 (98%)
 Pages failed:   130063 (1%)

platinum55 avatar Mar 03 '26 21:03 platinum55

@platinum55 linux results (403 mb/s) confirm everything works on the hardware side. the windows issues all stem from code 10 when windows sees that error it disables bus master, so the fpga can't do any dma reads. that's why pcileech can't find dtb and the other tool shows 100% failed pages.

just pushed a comprehensive xhci bar0 fix that clamps all register offsets within the 4kb bram. should eliminate code 10. can you regenerate firmware and test on windows again?

re simdata/mmio replay interesting idea but shouldn't be needed, static bar patching covers what the driver needs. let's see how this fix goes first

sercanarga avatar Mar 03 '26 21:03 sercanarga