Random corruption on SpacemiT K1 (and K3) with RVV

Aurelien Jarno aurelien at aurel32.net
Wed Nov 11 08:24:17 PST 2026


[resent with a better compression to get it accepted on the list]

Hi Kevin,

On 2026-11-11 09:12, kevin zhang wrote:
> Hi, Aurelien,
> 
> Thank you for your continued efforts.
> 
> On 11/5/2026 5:35 AM, Aurelien Jarno wrote:
> > Hi,
> > 
> > I have finally been able to capture the last few exceptions happening
> > for one event where the vectored user copy code is corrupting data. That
> > was on the SpacemiT K1.
> > 
> > I added a hook to handle_exception(), activated only when
> > __asm_vector_usercopy_sum_enabled is running, and recording CPU state at
> > the beginning of the exception, in per-CPU 16-entry tables.
> > On the OpenSBI side, I also instrumented sbi_trap_handler() to log the
> > CAUSE_MISALIGNED_LOAD and CAUSE_LOAD_ACCESS cases. This only fires
> > during the kernel boot when it tries to measure speed of unaligned
> > accesses.
> > 
> > The case I captured was a 4096-byte long copy, from 0x2a883310
> > (userland) to 0xffffffd701e54000 (kernel), presumably from a write
> > syscall. The copy is considered successful, i.e it exits with a0=0. That
> > said after the copy, the source and the destination start to differ
> > after the first 16 bytes, at address 0xffffffd701e54010.
> > 
> > The copy started on CPU 5 and ended on CPU 5, and there was only a
> > single exception between the start and the end, so it wasn't
> > rescheduled.
> > 
> > The exception happened with epc=0xffffffff80e09204, which corresponds to
> > the location of the "vle8.v v0,(a1)" instruction. I recorded:
> > - cause=0xd
> > - badaddr=0x2a883410
> > - a0=0xffffffd701e54100
> > - a1=0x2a883410
> > - a2=0xf00
> > - vl=0x100
> > - vstart=0x0
> > - vtype=0xc3
> > 
> > As you can see, the exception happened during the second iteration of
> > the loop. It is not clear to me why the first iteration didn't trigger a
> > page fault, as both 0x2a883310 and 0x2a883410 are on the same 4k page. I
> > have also logged the content of v0 at the time of the exception, and I
> > can clearly see that only the first 16 bytes (out of 32 bytes) got
> > loaded during the previous iteration. Its content matches the error
> > reported by GNU as on the userland side.
> From the information you provided, the issue does indeed seem quite strange.
> Could you please share your debug patch with me? I'll try to further locate
> and analyze the issue on my side.

Please find attached the patch used on top of v7.3. It is not very clean 
as it was only done for debug purpose and grew organically. I have also 
attached the kernel config I used, based on the Debian one (hence the 
many modules that are useless for the K1).

With the patch, the issue is happening way more rarely, it took me more 
than one week building blender in a loop to get a failure. During that
time I also caught 2 failures not linked to the usercopy code, but still 
causing GCC to fail in a similar way than on the K3, and as the Fedora 
guys also experience:

https://forge.fedoraproject.org/riscv/planning/issues/36

Regards
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien at aurel32.net                     http://aurel32.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: k1.debug-vector.patch
Type: text/x-diff
Size: 9477 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20261111/02bd939f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: config.7.3-k1.xz
Type: application/x-xz
Size: 55104 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20261111/02bd939f/attachment.xz>


More information about the linux-riscv mailing list