This is the sample workspace. We wrote the sample project and its bugs. The findings are real review output. On your own install, this list shows your repositories.
Breakspec posts these findings as comments on the pull request on GitHub. This page keeps the history of each review.
Reproduced in simulation, rerun by Breakspec: an agent wrote a testbench and Breakspec ran it again and saw the reported output. Hazard shown in simulation, rerun by Breakspec: the rerun showed a condition that can fail on hardware, and no wrong value. Confirmed by reading the code, not run: a second agent checked the code and no simulation ran. Raised by a reviewer, not examined: one AI reviewer raised it and nothing checked it. A reviewer is one of Breakspec's AI agents.
Severity: P0: must be fixed before merging. P1: a real defect in the changed code. P2: a correctness problem worth fixing. P3: minor.
No transfer ever runs: - The driver's CTRL writes never reach CTRL, so START never pulses and every axon_dma_submit/axon_dma_wait ends in AXON_ERR_TIMEOUT. - Bit 0 of each write sets IRQ_MASK, and CTRL.irq_en is never set, so the interrupt is also suppressed.
| 5 | #define AXON_ID_VALUE 0xA407D3A0u |
| 6 | |
| 7 | #define AXON_REG_ID 0x00u |
| 8 | #define AXON_REG_VERSION 0x04u |
| 9 | #define AXON_REG_CTRL 0x10u |
| 10 | #define AXON_REG_STATUS 0x18u |
| 11 | #define AXON_REG_BYTES_DONE 0x1Cu |
| 12 | #define AXON_REG_DESC_ADDR 0x20u |
| 13 | #define AXON_REG_IRQ_STAT 0x28u |
I tried to refute this and could not. The RTL is the source of truth (spec section 2), and it puts IRQ_MASK and CTRL at different offsets from the firmware header: - rtl/axon_regs_pkg.sv:11-12 defines ADDR_IRQ_MASK = 8'h10 and ADDR_CTRL = 8'h14. - docs/axon_dma_spec.md:21 (rev 1.5) says the same, and :17-18 says the package is canonical and axon_regs.h must match it bit for bit. - fw/include/axon_regs.h:9 still has AXON_REG_CTRL 0x10u and has no IRQ_MASK define. Nothing shifts or translates the address on the way: - axon_hal.h passes a plain offset. - axon_dma_top.sv wires wr_addr straight into axon_regs. - There is no other definition and no conditional compilation. In rtl/axon_regs.sv:51 a write to 0x10 does only `irq_mask <= wr_data[0]`. So every CTRL write from fw/src/axon_dma.c:11, 12 and 25 lands on IRQ_MASK: - START (bit 0) sets irq_mask to 1. - start_pulse never fires. - ctrl.irq_en is never set. - irq stays 0 because of `irq_stat & ctrl.irq_en & ~irq_mask`. A minimal iverilog test that drives axon_regs with the header's offsets and replays axon_dma_init and axon_dma_submit confirms all of this. Related finding: the CTRL bit positions also disagree. The header has IRQ_EN at bit 2 and SG_EN at bit 3. ctrl_reg_t in the package has sg_en at [2] and irq_en at [3]. So fixing only the offset would still enable scatter-gather instead of the IRQ in init.
$ iverilog -g2012 -o sim.vvp ../../../../../../../rtl/axon_regs_pkg.sv ../../../../../../../rtl/axon_regs.sv tb.sv [exit code 0]
$ vvp sim.vvp VCD info: dumpfile wave.vcd opened for output. after submit: start_pulse_count=0 ctrl=0x00000000 irq_mask=1 desc_addr=0x10000000 after done: irq_stat=1 irq=0 BUG: CTRL.start never pulsed; write went to IRQ_MASK (irq_mask=1) tb.sv:56: $finish called at 120000 (1ps) [exit code 0]
| 1 | // Drives rtl/axon_regs.sv with the offsets/bits from fw/include/axon_regs.h, |
| 2 | // replaying axon_dma_init() and axon_dma_submit(). |
| 3 | `timescale 1ns/1ps |
| 4 | module tb; |
| 5 | // Values copied from fw/include/axon_regs.h |
| 6 | localparam [7:0] FW_AXON_REG_CTRL = 8'h10; |
| 7 | localparam [7:0] FW_AXON_REG_DESC_ADDR = 8'h20; |
| 8 | localparam [31:0] FW_CTRL_START = 32'h1; |
| 9 | localparam [31:0] FW_CTRL_SOFT_RST = 32'h2; |
| 10 | localparam [31:0] FW_CTRL_IRQ_EN = 32'h4; |
| 11 | localparam [31:0] FW_CTRL_SG_EN = 32'h8; |
| 12 | |
| 13 | logic clk_axi = 0, rst_n = 0; |
| 14 | logic wr_en = 0, rd_en = 0; |
| 15 | logic [7:0] wr_addr = 0, rd_addr = 0; |
| 16 | logic [31:0] wr_data = 0, rd_data; |
| 17 | axon_regs_pkg::ctrl_reg_t ctrl; |
| 18 | logic [31:0] desc_addr; |
| 19 | logic start_pulse, irq; |
| 20 | logic done_sync = 0; |
| 21 | integer start_seen = 0; |
| 22 | |
| 23 | always #4 clk_axi = ~clk_axi; |
| 24 | always @(posedge clk_axi) if (start_pulse) start_seen = start_seen + 1; |
| 25 | |
| 26 | axon_regs dut ( |
| 27 | .clk_axi(clk_axi), .rst_n(rst_n), |
| 28 | .wr_en(wr_en), .wr_addr(wr_addr), .wr_data(wr_data), |
| 29 | .rd_en(rd_en), .rd_addr(rd_addr), .rd_data(rd_data), |
| 30 | .ctrl(ctrl), .desc_addr(desc_addr), .start_pulse(start_pulse), |
| 31 | .busy_sync(1'b0), .done_sync(done_sync), .err_sync(1'b0), |
| 32 | .bytes_done(32'd0), .irq(irq)); |
| 33 | |
| 34 | task automatic w(input [7:0] a, input [31:0] d); |
| 35 | @(negedge clk_axi); wr_en = 1; wr_addr = a; wr_data = d; |
| 36 | @(negedge clk_axi); wr_en = 0; |
| 37 | endtask |
| 38 | |
| 39 | initial begin |
| 40 | $dumpfile("wave.vcd"); |
| 41 | $dumpvars(0, tb); |
| 42 | repeat (2) @(negedge clk_axi); rst_n = 1; |
| 43 | // axon_dma_init() |
| 44 | w(FW_AXON_REG_CTRL, FW_CTRL_SOFT_RST); |
| 45 | w(FW_AXON_REG_CTRL, FW_CTRL_IRQ_EN); |
| 46 | // axon_dma_submit() with sg_count != 0 |
| 47 | w(FW_AXON_REG_DESC_ADDR, 32'h1000_0000); |
| 48 | w(FW_AXON_REG_CTRL, FW_CTRL_IRQ_EN | FW_CTRL_START | FW_CTRL_SG_EN); |
| 49 | repeat (2) @(negedge clk_axi); |
| 50 | $display("after submit: start_pulse_count=%0d ctrl=0x%08h irq_mask=%0b desc_addr=0x%08h", |
| 51 | start_seen, ctrl, dut.irq_mask, desc_addr); |
| 52 | // simulate a completion anyway, check irq |
| 53 | done_sync = 1; repeat (3) @(negedge clk_axi); |
| 54 | $display("after done: irq_stat=%0b irq=%0b", dut.irq_stat, irq); |
| 55 | if (start_seen == 0) $display("BUG: CTRL.start never pulsed; write went to IRQ_MASK (irq_mask=%0b)", dut.irq_mask); |
| 56 | $finish; |
| 57 | end |
| 58 | endmodule |
cd $WORK && iverilog -g2012 -o sim.vvp ../../../../../../../rtl/axon_regs_pkg.sv ../../../../../../../rtl/axon_regs.sv tb.sv && vvp sim.vvp
When firmware enables interrupts with AXON_CTRL_IRQ_EN, hardware sets sg_en instead, so the completion interrupt never fires. When firmware asks for scatter-gather with AXON_CTRL_SG_EN, hardware sets irq_en instead, so chaining stays off. Both interrupt delivery and scatter-gather selection are broken for every driver built against axon_regs.h.
| 16 | localparam logic [7:0] ADDR_IRQ_STAT = 8'h28; // W1C |
| 17 | |
| 18 | typedef struct packed { |
| 19 | logic [27:0] rsvd; |
| 20 | logic irq_en; // [3] |
| 21 | logic sg_en; // [2] follow next_idx chain |
| 22 | logic soft_rst; // [1] |
| 23 | logic start; // [0] self-clearing |
| 24 | } ctrl_reg_t; |
I tried to refute this and could not. There is only one definition of ctrl_reg_t, in rtl/axon_regs_pkg.sv:18-24, and it is not behind any conditional compilation. In a SystemVerilog packed struct the first field listed is the most significant, so after rsvd[27:0] the field irq_en lands on bit 3 and sg_en on bit 2. The in-line comments say the same ([3] and [2]). The package header (line 3) calls it 'the canonical contract for fw/include/axon_regs.h'. That header defines AXON_CTRL_IRQ_EN as (1u << 2) and AXON_CTRL_SG_EN as (1u << 3) at lines 17-18, and fw/src/axon_dma.c:12,20,22 really writes those values. In rtl/axon_regs.sv:47 the whole wr_data word is stored into ctrl with no bit remapping. Line 78 then gates irq with ctrl.irq_en, which is bit 3. docs/axon_dma_spec.md does not give bit positions, so nothing documents the RTL order as intended. I simulated axon_regs with iverilog: writing the firmware IRQ_EN value (0x4) set sg_en=1 and irq_en=0, and irq stayed 0 after a DMA completed. Writing the firmware SG_EN value (0x8) set irq_en=1 and sg_en=0. The CTRL address mismatch (RTL 0x14 vs firmware 0x10) is a separate problem; this bit-order mismatch remains even after that is fixed.
$ iverilog -g2012 -o sim $REPO/rtl/axon_regs_pkg.sv $REPO/rtl/axon_regs.sv tb.sv [exit code 0]
$ vvp sim VCD info: dumpfile wave.vcd opened for output. wrote fw IRQ_EN (0x00000004): ctrl=0x00000004 irq_en=0 sg_en=1 after done: irq_stat=1 irq=0 (expected 1) wrote fw SG_EN (0x00000008): ctrl=0x00000008 irq_en=1 sg_en=0 irq=1 (fw did not ask for IRQ_EN) tb.sv:41: $finish called at 80000 (1ps) [exit code 0]
| 1 | `timescale 1ns/1ps |
| 2 | module tb; |
| 3 | logic clk = 0, rst_n = 0; |
| 4 | logic wr_en = 0, rd_en = 0; |
| 5 | logic [7:0] wr_addr = 0, rd_addr = 0; |
| 6 | logic [31:0] wr_data = 0, rd_data; |
| 7 | axon_regs_pkg::ctrl_reg_t ctrl; |
| 8 | logic [31:0] desc_addr; |
| 9 | logic start_pulse, irq; |
| 10 | logic done_sync = 0; |
| 11 | wire ctrl_irq_en = ctrl.irq_en; |
| 12 | wire ctrl_sg_en = ctrl.sg_en; |
| 13 | localparam logic [31:0] FW_IRQ_EN = 32'h1 << 2; // fw/include/axon_regs.h |
| 14 | localparam logic [31:0] FW_SG_EN = 32'h1 << 3; |
| 15 | |
| 16 | axon_regs dut(.clk_axi(clk), .rst_n(rst_n), .wr_en(wr_en), .wr_addr(wr_addr), |
| 17 | .wr_data(wr_data), .rd_en(rd_en), .rd_addr(rd_addr), .rd_data(rd_data), |
| 18 | .ctrl(ctrl), .desc_addr(desc_addr), .start_pulse(start_pulse), |
| 19 | .busy_sync(1'b0), .done_sync(done_sync), .err_sync(1'b0), |
| 20 | .bytes_done(32'd0), .irq(irq)); |
| 21 | |
| 22 | always #5 clk = ~clk; |
| 23 | |
| 24 | initial begin |
| 25 | $dumpfile("wave.vcd"); |
| 26 | $dumpvars(0, tb); |
| 27 | #12 rst_n = 1; |
| 28 | // firmware writes AXON_CTRL_IRQ_EN to the RTL's CTRL address |
| 29 | @(negedge clk); wr_en = 1; wr_addr = axon_regs_pkg::ADDR_CTRL; wr_data = FW_IRQ_EN; |
| 30 | @(negedge clk); wr_en = 0; |
| 31 | $display("wrote fw IRQ_EN (0x%08h): ctrl=0x%08h irq_en=%0b sg_en=%0b", FW_IRQ_EN, ctrl, ctrl.irq_en, ctrl.sg_en); |
| 32 | // a DMA completes |
| 33 | done_sync = 1; |
| 34 | @(negedge clk); @(negedge clk); |
| 35 | $display("after done: irq_stat=%0b irq=%0b (expected 1)", dut.irq_stat, irq); |
| 36 | @(negedge clk); wr_en = 1; wr_addr = axon_regs_pkg::ADDR_CTRL; wr_data = FW_SG_EN; |
| 37 | @(negedge clk); wr_en = 0; |
| 38 | $display("wrote fw SG_EN (0x%08h): ctrl=0x%08h irq_en=%0b sg_en=%0b", FW_SG_EN, ctrl, ctrl.irq_en, ctrl.sg_en); |
| 39 | @(negedge clk); |
| 40 | $display("irq=%0b (fw did not ask for IRQ_EN)", irq); |
| 41 | $finish; |
| 42 | end |
| 43 | endmodule |
cd $WORK && iverilog -g2012 -o sim $REPO/rtl/axon_regs_pkg.sv $REPO/rtl/axon_regs.sv tb.sv && vvp sim
Any descriptor with len >= 64 KiB is silently cut down to len mod 65536, and the engine still reports done with err = 0. The upper len bits are read as a nonzero sg_count, while the firmware sg_count field is ignored. The 69632-byte transfer in fw/tests/dma_smoke.c moves only 4096 bytes. The spec 3.1 contract between firmware and RTL is broken.
| 13 | uint32_t dst_addr; |
| 14 | uint32_t len; /* bytes, multiple of 4 */ |
| 15 | uint16_t flags; |
| 16 | uint16_t next_idx; |
| 17 | uint32_t sg_count; /* scatter-gather segments that follow */ |
| 18 | }; |
| 19 | |
| 20 | _Static_assert(sizeof(struct axon_dma_desc) == 20, "descriptor size"); |
| 21 |
| 7 | typedef struct packed { |
| 8 | logic [15:0] next_idx; // byte 14 |
| 9 | logic [15:0] flags; // byte 12 |
| 10 | logic [15:0] sg_count; // byte 10: scatter-gather segments that follow |
| 11 | logic [15:0] len; // byte 8: segment length in bytes (max 64 KiB) |
| 12 | logic [31:0] dst_addr; // byte 4 |
| 13 | logic [31:0] src_addr; // byte 0 |
| 14 | } dma_desc_t; |
| 15 |
I tried to refute this and could not. There is only one definition on each side: fw/include/axon_desc.h:11-18 and rtl/axon_desc_pkg.sv:7-14. No conditional compilation or generated copies are involved. docs/axon_dma_spec.md section 3.1 says firmware's struct axon_dma_desc must have the same size, offsets and widths as axon_desc_pkg::dma_desc_t, and both source files say they must match each other. The two layouts disagree: - Firmware: src@0 u32, dst@4 u32, len@8 u32, flags@12 u16, next_idx@14 u16, sg_count@16 u32. That is 20 bytes, and the _Static_assert at line 20 checks for 20. - RTL packed struct (lsb at byte 0): src@0, dst@4, len@8 as 16 bits, sg_count@10 as 16 bits, flags@12, next_idx@14. That is 16 bytes, and DESC_WORDS=4. What happens at runtime: - axon_dma_engine.sv fetches 4 words and builds desc_q = {w3,w2,w1,w0}, so the RTL decodes the firmware's 32-bit len word as len[15:0] plus sg_count[15:0]. - The firmware sg_count at byte 16 is written by axon_mem_write(sizeof *desc = 20) but the engine never fetches it. - axon_dma_submit (fw/src/axon_dma.c:18) only checks len != 0 and len % 4 == 0. Nothing enforces the new 64 KiB limit. - dma_smoke.c uses len = 69632 (0x11000). The RTL sees len = 0x1000 (4096) and sg_count = 1, then reports done with err = 0 after moving 4096 bytes. I reproduced this by running the real engine RTL against a memory image laid out exactly like the firmware struct. One part of the original claim is speculative: the engine as it stands does not chain descriptors, so the 'wrong stride for the next descriptor' effect cannot be observed yet. I am rating this P1 rather than P0 because the 64 KiB smoke test would catch it.
$ iverilog -g2012 -o sim.vvp $REPO/rtl/axon_desc_pkg.sv $REPO/rtl/sync_fifo.sv $REPO/rtl/axon_dma_engine.sv tb.sv [exit code 0]
$ vvp sim.vvp VCD info: dumpfile wave.vcd opened for output. fw len=69632 rtl desc_q.len=4096 rtl desc_q.sg_count=1 flags=0003 next_idx=0 done=1 err=0 bytes_done=4096 (expected 69632) sizeof fw struct=20 bytes, rtl DESC_WORDS*4=16 bytes tb.sv:44: $finish called at 4158000 (1ps) [exit code 0]
| 1 | `timescale 1ns/1ps |
| 2 | // Firmware lays out struct axon_dma_desc (20 bytes) as in dma_smoke.c; |
| 3 | // the RTL engine fetches 4 words and decodes them as dma_desc_t. |
| 4 | module tb; |
| 5 | logic clk_core = 0, rst_n = 0, start = 0; |
| 6 | always #2 clk_core = ~clk_core; |
| 7 | logic mem_rd; |
| 8 | logic [31:0] mem_addr, mem_rdata; |
| 9 | logic [31:0] out_data; logic out_valid; |
| 10 | logic busy, done, err; |
| 11 | logic [31:0] bytes_done; |
| 12 | axon_desc_pkg::dma_desc_t desc_q; |
| 13 | logic [31:0] mem [0:7]; |
| 14 | logic [15:0] desc_len, desc_sg_count; |
| 15 | assign desc_len = desc_q.len; |
| 16 | assign desc_sg_count = desc_q.sg_count; |
| 17 | |
| 18 | axon_dma_engine dut ( |
| 19 | .clk_core(clk_core), .rst_n(rst_n), .start(start), .desc_addr(32'h1000), |
| 20 | .mem_rd(mem_rd), .mem_addr(mem_addr), .mem_rdata(mem_rdata), |
| 21 | .out_data(out_data), .out_valid(out_valid), .out_ready(1'b1), |
| 22 | .busy(busy), .done(done), .err(err), .bytes_done(bytes_done), .desc_q(desc_q)); |
| 23 | |
| 24 | always_ff @(posedge clk_core) mem_rdata <= mem[(mem_addr - 32'h1000) >> 2]; |
| 25 | |
| 26 | initial begin |
| 27 | $dumpfile("wave.vcd"); |
| 28 | $dumpvars(0, tb); |
| 29 | // little-endian image of fw struct axon_dma_desc from dma_smoke.c |
| 30 | mem[0] = 32'h0010_0000; // src_addr @0 |
| 31 | mem[1] = 32'h0020_0000; // dst_addr @4 |
| 32 | mem[2] = 32'd69632; // len (u32) @8 |
| 33 | mem[3] = {16'd0, 16'h0003}; // next_idx @14, flags @12 |
| 34 | mem[4] = 32'd0; // sg_count (u32) @16, never fetched |
| 35 | mem[5] = 0; mem[6] = 0; mem[7] = 0; |
| 36 | #10 rst_n = 1; |
| 37 | @(posedge clk_core); start <= 1; @(posedge clk_core); start <= 0; |
| 38 | wait (done); |
| 39 | @(posedge clk_core); |
| 40 | $display("fw len=%0d rtl desc_q.len=%0d rtl desc_q.sg_count=%0d flags=%h next_idx=%0d", |
| 41 | mem[2], desc_q.len, desc_q.sg_count, desc_q.flags, desc_q.next_idx); |
| 42 | $display("done=%0b err=%0b bytes_done=%0d (expected 69632)", done, err, bytes_done); |
| 43 | $display("sizeof fw struct=20 bytes, rtl DESC_WORDS*4=%0d bytes", axon_desc_pkg::DESC_WORDS*4); |
| 44 | $finish; |
| 45 | end |
| 46 | initial begin #2000000 $display("TIMEOUT"); $finish; end |
| 47 | endmodule |
cd $WORK && iverilog -g2012 -o sim.vvp $REPO/rtl/axon_desc_pkg.sv $REPO/rtl/sync_fifo.sv $REPO/rtl/axon_dma_engine.sv tb.sv && vvp sim.vvp
Under back-to-back traffic, which the header comment says this design supports, a write and read in the same cycle while full leaves count one below the real occupancy. full deasserts too early, the next write overwrites an unread entry, and accepted words are silently lost or come out in the wrong order. The embedded a_ptr_count invariant also fails.
| 35 | mem[wptr] <= wdata; |
| 36 | wptr <= wptr + 1'b1; |
| 37 | end |
| 38 | if (do_rd) rptr <= rptr + 1'b1; |
| 39 | case ({cnt_wr, do_rd}) |
| 40 | 2'b10: count <= count + 1'b1; |
| 41 | 2'b01: count <= count - 1'b1; |
| 42 | default: count <= count; |
| 43 | endcase |
In rtl/sync_fifo.sv, line 24 accepts a write when full if a read happens in the same cycle: do_wr = wr_en && (!full || rd_en). That matches the header comment on lines 2-3, so the full-FIFO write is intended. But the count update on lines 39-43 is keyed on cnt_wr = wr_en && !full (line 26), not on do_wr. So when the FIFO is full and wr_en and rd_en are both set, mem[wptr] is written and both pointers advance, yet the case value is 2'b01 and count goes down by one. Count and pointers then disagree, which breaks the module's own FORMAL assertion a_ptr_count (wptr == rptr + count). full drops even though every slot holds unread data, so the next write overwrites an unread entry. I found nothing that hides this: there is no other definition and no conditional compilation around the logic, and the comment states the intent outright. I checked it with a small iverilog testbench. Fill with 1..4 (full=1, count=4). Write 5 and read in the same cycle: count=3, full=0, wptr=1, rptr=1 (expected count=4, full=1). Write 6: it lands in slot 1, overwriting the unread word 2. Draining then returns 6,3,4,5 instead of 2,3,4,5,6. Word 2 is lost and the order is wrong.
$ iverilog -g2012 -o sim tb.sv $REPO/rtl/sync_fifo.sv [exit code 0]
$ vvp sim VCD info: dumpfile wave.vcd opened for output. after fill: full=1 count=4 wptr=0 rptr=0 after wr+rd on full: full=0 count=3 wptr=1 rptr=1 (expect count=4 full=1) after extra write: count=4 wptr=2 rptr=1 read 6 read 3 read 4 read 5 tb.sv:22: $finish called at 120 (1s) [exit code 0]
| 1 | module tb; |
| 2 | logic clk=0, rst_n=0, wr_en=0, rd_en=0; logic [31:0] wdata=0, rdata; logic full, empty; |
| 3 | sync_fifo #(.W(32),.DEPTH(4)) dut(.*); |
| 4 | always #5 clk = ~clk; |
| 5 | integer i; |
| 6 | initial begin |
| 7 | $dumpfile("wave.vcd"); $dumpvars(0, tb); |
| 8 | #12 rst_n = 1; |
| 9 | for (i=1;i<=4;i++) begin @(negedge clk); wr_en=1; wdata=i; end |
| 10 | @(negedge clk); wr_en=0; |
| 11 | $display("after fill: full=%0d count=%0d wptr=%0d rptr=%0d", full, dut.count, dut.wptr, dut.rptr); |
| 12 | // simultaneous write+read while full |
| 13 | wr_en=1; rd_en=1; wdata=5; |
| 14 | @(negedge clk); wr_en=0; rd_en=0; |
| 15 | $display("after wr+rd on full: full=%0d count=%0d wptr=%0d rptr=%0d (expect count=4 full=1)", full, dut.count, dut.wptr, dut.rptr); |
| 16 | // another write accepted because full dropped: overwrites unread entry |
| 17 | wr_en=1; wdata=6; @(negedge clk); wr_en=0; |
| 18 | $display("after extra write: count=%0d wptr=%0d rptr=%0d", dut.count, dut.wptr, dut.rptr); |
| 19 | // drain |
| 20 | while (!empty) begin $display("read %0d", rdata); rd_en=1; @(negedge clk); end |
| 21 | rd_en=0; |
| 22 | $finish; |
| 23 | end |
| 24 | endmodule |
cd $WORK && iverilog -g2012 -o sim tb.sv $REPO/rtl/sync_fifo.sv && vvp sim
Firmware or host polling BYTES_DONE during a transfer can read a torn value (a mix of old and new bits) or a metastable one. That gives wrong progress numbers, possibly non-monotonic or far off. The design also violates the spec's CDC rule, so CDC lint and sign-off will flag it. Data movement and the done/err/irq path are not affected.
| 47 | .start_pulse (start_axi), |
| 48 | .busy_sync (busy_axi), |
| 49 | .done_sync (done_axi), |
| 50 | .err_sync (err_axi), |
| 51 | .bytes_done (bytes_done), |
| 52 | .irq (irq) |
| 53 | ); |
| 54 | |
| 55 | // clk_axi -> clk_core |
| 66 | ADDR_VERSION: rd_data <= AXON_VERSION; |
| 67 | ADDR_IRQ_MASK: rd_data <= {31'd0, irq_mask}; |
| 68 | ADDR_CTRL: rd_data <= ctrl; |
| 69 | ADDR_STATUS: rd_data <= status; |
| 70 | ADDR_BYTES_DONE: rd_data <= bytes_done; |
| 71 | ADDR_DESC_ADDR: rd_data <= desc_addr; |
| 72 | ADDR_IRQ_STAT: rd_data <= {31'd0, irq_stat}; |
| 73 | default: rd_data <= 32'd0; |
| 74 | endcase |
I tried to refute this and could not. - **The spec rule:** docs/axon_dma_spec.md section 1 says every signal crossing between clk_core and clk_axi must go through cdc_sync2 or cdc_pulse, or be qualified by a synchronized strobe while held stable. - **Where the counter lives:** in rtl/axon_dma_engine.sv, bytes_done is a 32-bit flop on clk_core. It is incremented by 4 on every out_valid && out_ready (line 69) and cleared on start (line 75). - **How it reaches the register file:** rtl/axon_dma_top.sv declares it at line 33 and wires it from the engine (line 83) straight into u_regs (line 51). Nothing sits in between. In the same file, busy, done and err each go through cdc_sync2 (lines 65-67), so the author clearly knew the rule applied. - **How it is read:** rtl/axon_regs.sv runs entirely on clk_axi and registers it with `ADDR_BYTES_DONE: rd_data <= bytes_done;` (line 70). The read is not gated by done_sync or any other strobe, so firmware can read it at any time, including mid-transfer. Polling progress mid-transfer is the stated purpose of the register (spec 2.1: "for progress reporting"). - **Mitigations I looked for and did not find:** no `ifdef`, no generated variant, no alternative definition, and no comment documenting a quasi-static assumption. The engine's comment only covers busy and done ("Registered so the status bits are glitch-free into the clk_axi synchronizers"). The `desc_addr` input is marked as quasi-static and sampled on start, but bytes_done gets no such treatment. - **Clock relationship:** the spec periods are 8 ns and 4 ns, but the spec treats the clocks as separate domains that need synchronizers, so this is a real crossing. - **What changes at once:** each increment of 4 can flip many bits together. One observed step was 0x7C to 0x84, w
$ iverilog -g2012 -o sim.vvp ../../../../../../../rtl/axon_regs_pkg.sv ../../../../../../../rtl/axon_desc_pkg.sv ../../../../../../../rtl/cdc_sync.sv ../../../../../../../rtl/sync_fifo.sv ../../../../../../../rtl/axon_regs.sv ../../../../../../../rtl/axon_dma_engine.sv ../../../../../../../rtl/axon_dma_top.sv tb.sv [exit code 0]
$ vvp sim.vvp VCD info: dumpfile wave.vcd opened for output. t=228.00 ns: clk_axi captures BYTES_DONE while bytes_done changed 0.45 ns earlier (now 0x00000074) t=236.00 ns: clk_axi captures BYTES_DONE while bytes_done changed 0.25 ns earlier (now 0x0000007c) t=244.00 ns: clk_axi captures BYTES_DONE while bytes_done changed 0.05 ns earlier (now 0x00000084) final bytes_done=256 reads=60 capture-edge hazards=3 bytes_done path into u_regs: direct wire from clk_core flop, no cdc_sync2/cdc_pulse/strobe tb.sv:69: $finish called at 544000 (1ps) [exit code 0]
| 1 | // Shows that axon_regs samples the clk_core bytes_done counter directly on |
| 2 | // clk_axi (no synchronizer, no qualifying strobe), so the counter changes |
| 3 | // right at clk_axi capture edges while BYTES_DONE is being read. |
| 4 | `timescale 1ns/1ps |
| 5 | module tb; |
| 6 | logic clk_axi = 0, clk_core = 0, rst_n = 0; |
| 7 | logic wr_en = 0, rd_en = 0; |
| 8 | logic [7:0] wr_addr = 0, rd_addr = 0; |
| 9 | logic [31:0] wr_data = 0, rd_data; |
| 10 | logic irq, mem_rd, out_valid; |
| 11 | logic [31:0] mem_addr, mem_rdata, out_data; |
| 12 | |
| 13 | always #4 clk_axi = ~clk_axi; // 8 ns |
| 14 | always #2.05 clk_core = ~clk_core; // ~4 ns, asynchronous to clk_axi |
| 15 | |
| 16 | // descriptor memory, 1-cycle latency: src=0x100, dst=0x200, len=256 |
| 17 | always_ff @(posedge clk_core) |
| 18 | if (mem_rd) case (mem_addr[3:2]) |
| 19 | 2'd0: mem_rdata <= 32'h0000_0100; |
| 20 | 2'd1: mem_rdata <= 32'h0000_0200; |
| 21 | 2'd2: mem_rdata <= 32'h0000_0100; // sg_count=0, len=256 |
| 22 | default: mem_rdata <= 32'h0; |
| 23 | endcase |
| 24 | |
| 25 | axon_dma_top dut ( |
| 26 | .clk_axi(clk_axi), .clk_core(clk_core), .rst_n(rst_n), |
| 27 | .wr_en(wr_en), .wr_addr(wr_addr), .wr_data(wr_data), |
| 28 | .rd_en(rd_en), .rd_addr(rd_addr), .rd_data(rd_data), .irq(irq), |
| 29 | .mem_rd(mem_rd), .mem_addr(mem_addr), .mem_rdata(mem_rdata), |
| 30 | .out_data(out_data), .out_valid(out_valid), .out_ready(1'b1)); |
| 31 | |
| 32 | // Track when the clk_core-driven counter last changed. |
| 33 | realtime last_change = -100.0; |
| 34 | always @(dut.bytes_done) last_change = $realtime; |
| 35 | |
| 36 | integer reads = 0, hazards = 0; |
| 37 | localparam realtime SETUP = 0.5; // ns, generous window |
| 38 | always @(posedge clk_axi) begin |
| 39 | if (rd_en && rd_addr == axon_regs_pkg::ADDR_BYTES_DONE) begin |
| 40 | reads = reads + 1; |
| 41 | // #0 lets same-timestep clk_core updates land first |
| 42 | #0; |
| 43 | if ($realtime - last_change < SETUP) begin |
| 44 | hazards = hazards + 1; |
| 45 | if (hazards <= 5) |
| 46 | $display("t=%0.2f ns: clk_axi captures BYTES_DONE while bytes_done changed %0.2f ns earlier (now 0x%08h)", |
| 47 | $realtime, $realtime - last_change, dut.bytes_done); |
| 48 | end |
| 49 | end |
| 50 | end |
| 51 | |
| 52 | task automatic w(input [7:0] a, input [31:0] d); |
| 53 | @(negedge clk_axi); wr_en = 1; wr_addr = a; wr_data = d; |
| 54 | @(negedge clk_axi); wr_en = 0; |
| 55 | endtask |
| 56 | |
| 57 | initial begin |
| 58 | $dumpfile("wave.vcd"); |
| 59 | $dumpvars(0, tb); |
| 60 | repeat (3) @(negedge clk_axi); rst_n = 1; |
| 61 | w(axon_regs_pkg::ADDR_DESC_ADDR, 32'h0000_1000); |
| 62 | w(axon_regs_pkg::ADDR_CTRL, 32'h1); |
| 63 | // poll BYTES_DONE every clk_axi cycle while the transfer runs |
| 64 | @(negedge clk_axi); rd_en = 1; rd_addr = axon_regs_pkg::ADDR_BYTES_DONE; |
| 65 | repeat (60) @(negedge clk_axi); |
| 66 | rd_en = 0; |
| 67 | $display("final bytes_done=%0d reads=%0d capture-edge hazards=%0d", dut.bytes_done, reads, hazards); |
| 68 | $display("bytes_done path into u_regs: direct wire from clk_core flop, no cdc_sync2/cdc_pulse/strobe"); |
| 69 | $finish; |
| 70 | end |
| 71 | endmodule |
cd $WORK && iverilog -g2012 -o sim.vvp ../../../../../../../rtl/axon_regs_pkg.sv ../../../../../../../rtl/axon_desc_pkg.sv ../../../../../../../rtl/cdc_sync.sv ../../../../../../../rtl/sync_fifo.sv ../../../../../../../rtl/axon_regs.sv ../../../../../../../rtl/axon_dma_engine.sv ../../../../../../../rtl/axon_dma_top.sv tb.sv && vvp sim.vvp
A slow but live transfer can be queued up to retries+1 (4) times, so the destination buffer is written repeatedly, which breaks non-idempotent transfers (for example ones whose source changes or that move data out of a FIFO). Because each retry waits only on the newest tag, completions of earlier copies are ignored and never consumed. submit() can raise TimeoutError even though the transfer actually finished, which misleads callers and can trigger yet another submission at a higher level.
| 36 | if desc.length <= 0 or desc.length % 4: |
| 37 | raise ValueError("length must be a positive multiple of 4") |
| 38 | for attempt in range(self.retries + 1): |
| 39 | try: |
| 40 | tag = self._ring.push(desc) |
| 41 | return self._ring.wait(tag, timeout=self.timeout_s) |
| 42 | except TimeoutError: |
| 43 | log.warning("DMA submit timed out, retrying (%d)", attempt + 1) |
| 44 | raise TimeoutError(f"transfer did not complete after {self.retries + 1} attempts") |
Static reading of host/axon_host/client.py:38-44 confirms the claim. Inside the retry loop, every attempt calls `tag = self._ring.push(desc)` (line 40) and then `wait(tag, timeout=self.timeout_s)` (line 41). When a TimeoutError is caught (line 42), the code only logs and loops, so the next attempt pushes the same descriptor again and gets a new tag. Nothing cancels, drains or re-waits the earlier tag, and the CommandRing Protocol (lines 20-25) has no cancel or abort method that could do it. The Protocol docstring says push() 'queues a descriptor', so the ring owns every pushed copy, and a timeout from wait() does not remove it. I looked for reasons to refute this and found none: - Neither the spec (docs/axon_dma_spec.md) nor the README nor any comment mentions retry, cancel, idempotency or timeout semantics. - The only test (host/tests/test_client.py) uses a FakeRing that never times out, so the retry path is untested. - There is no other definition of submit. The flaw is worse than the report says. Take a transfer that needs longer than one 0.5 s window but less than two: - Attempt 1 times out. Attempt 2 pushes tag 2 and waits only on tag 2. - Tag 1 completes during that wait, but nobody observes it. - Each later push restarts the clock, so all 4 attempts can time out. In that case submit() raises TimeoutError even though the transfer completed, and the engine still runs up to 4 copies, all writing dst_addr. The earlier completions are never consumed either. With the default timeout_s=0.5 and retries=3, a merely slow transfer can reach this path. I wrote a Python model (repro.py) to show it, but the sandbox would not run python3. I did not substitute a C transliteration because it would only test my copy of the logic. The code path is short and deterministic, so the static argument is enough. Reproduction not achieved: I could not demonstrate this in simulation. The bug is in pure Python host code (host/axon_host/client.py lines 38-44, AxonClient.submit), not in any RTL. iverilog, verilator, GHDL and the other tools can only run RTL, so they cannot execute the repository's Python unmodified. A Verilog or C copy of the retry loop would only test my copy of the logic, not the project's code, so I did not write
No simulation was run for this finding. A second reviewer confirmed it by reading the code above.
The engine is told to follow a descriptor chain in memory whose bounds were never checked. A caller can make the DMA engine walk or write outside the intended buffers.
| 17 | { |
| 18 | if (desc->len == 0 || (desc->len & 3u)) |
| 19 | return AXON_ERR_INVAL; |
| 20 | uint32_t ctrl = AXON_CTRL_IRQ_EN | AXON_CTRL_START; |
| 21 | if (desc->sg_count) |
| 22 | ctrl |= AXON_CTRL_SG_EN; |
| 23 | axon_mem_write(desc_bus_addr, desc, sizeof *desc); |
| 24 | axon_write32(AXON_REG_DESC_ADDR, desc_bus_addr); |
| 25 | axon_write32(AXON_REG_CTRL, ctrl); |
Model review (anthropic:claude-sonnet-5-5, lens: security). Not executed; treat as a lead until a check reproduces it.
No simulation was run for this finding. The code above is what the reviewer pointed at.