* [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support @ 2025-06-10 10:12 Chunyan Zhang 2025-06-10 10:12 ` [PATCH 1/4] raid6: riscv: Clean up unused header file inclusion Chunyan Zhang ` (5 more replies) 0 siblings, 6 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-10 10:12 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang The first two patches are fixes. The last two are for userspace raid6test support on RISC-V. The issue fixed in patch 2/4 was probably the same which was spotted by Charlie [1], I couldn't reproduce it at that time. When running raid6test in userspace on RISC-V, I saw a segmentation fault, I used gdb command to print pointer p, it was an unaccessible address. With patch 2/4, the issue didn't appear anymore. [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ Chunyan Zhang (4): raid6: riscv: clean up unused header file inclusion raid6: riscv: Fix NULL pointer dereference issue raid6: riscv: Allow code to be compiled in userspace raid6: test: add support for RISC-V lib/raid6/recov_rvv.c | 9 +----- lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- lib/raid6/rvv.h | 15 ++++++++++ lib/raid6/test/Makefile | 8 ++++++ 4 files changed, 56 insertions(+), 38 deletions(-) -- 2.34.1 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/4] raid6: riscv: Clean up unused header file inclusion 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang @ 2025-06-10 10:12 ` Chunyan Zhang 2025-06-10 10:12 ` [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue Chunyan Zhang ` (4 subsequent siblings) 5 siblings, 0 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-10 10:12 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang These two C files don't reference things defined in simd.h or types.h so remove these redundant #inclusions. Fixes: 6093faaf9593 ("raid6: Add RISC-V SIMD syndrome and recovery calculations") Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> --- lib/raid6/recov_rvv.c | 2 -- lib/raid6/rvv.c | 3 --- 2 files changed, 5 deletions(-) diff --git a/lib/raid6/recov_rvv.c b/lib/raid6/recov_rvv.c index f29303795ccf..500da521a806 100644 --- a/lib/raid6/recov_rvv.c +++ b/lib/raid6/recov_rvv.c @@ -4,9 +4,7 @@ * Author: Chunyan Zhang <zhangchunyan@iscas.ac.cn> */ -#include <asm/simd.h> #include <asm/vector.h> -#include <crypto/internal/simd.h> #include <linux/raid/pq.h> static int rvv_has_vector(void) diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c index f0887344b274..bf7d5cd659e0 100644 --- a/lib/raid6/rvv.c +++ b/lib/raid6/rvv.c @@ -9,11 +9,8 @@ * Copyright 2002-2004 H. Peter Anvin */ -#include <asm/simd.h> #include <asm/vector.h> -#include <crypto/internal/simd.h> #include <linux/raid/pq.h> -#include <linux/types.h> #include "rvv.h" #define NSIZE (riscv_v_vsize / 32) /* NSIZE = vlenb */ -- 2.34.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang 2025-06-10 10:12 ` [PATCH 1/4] raid6: riscv: Clean up unused header file inclusion Chunyan Zhang @ 2025-06-10 10:12 ` Chunyan Zhang 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-12 19:30 ` Palmer Dabbelt 2025-06-10 10:12 ` [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace Chunyan Zhang ` (3 subsequent siblings) 5 siblings, 2 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-10 10:12 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang When running the raid6 user-space test program on RISC-V QEMU, there's a segmentation fault which seems caused by accessing a NULL pointer, which is the pointer variable p/q in raid6_rvv*_gen/xor_syndrome_real(), p/q should have been equal to dptr[x], but when I use GDB command to see its value, which was 0x10 like below: " Program received signal SIGSEGV, Segmentation fault. 0x0000000000011062 in raid6_rvv2_xor_syndrome_real (disks=<optimized out>, start=0, stop=<optimized out>, bytes=4096, ptrs=<optimized out>) at rvv.c:386 (gdb) p p $1 = (u8 *) 0x10 <error: Cannot access memory at address 0x10> " The issue was found to be related with: 1) Compile optimization There's no segmentation fault if compiling the raid6test program with the optimization flag -O0. 2) The RISC-V vector command vsetvli If not used t0 as the first parameter in vsetvli, there's no segmentation fault either. This patch selects the 2nd solution to fix the issue. Fixes: 6093faaf9593 ("raid6: Add RISC-V SIMD syndrome and recovery calculations") Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> --- lib/raid6/rvv.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c index bf7d5cd659e0..b193ea176d5d 100644 --- a/lib/raid6/rvv.c +++ b/lib/raid6/rvv.c @@ -23,9 +23,9 @@ static int rvv_has_vector(void) static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { u8 **dptr = (u8 **)ptrs; - unsigned long d; - int z, z0; u8 *p, *q; + unsigned long vl, d; + int z, z0; z0 = disks - 3; /* Highest data disk */ p = dptr[z0 + 1]; /* XOR parity */ @@ -33,8 +33,9 @@ static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void ** asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ @@ -96,7 +97,7 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, { u8 **dptr = (u8 **)ptrs; u8 *p, *q; - unsigned long d; + unsigned long vl, d; int z, z0; z0 = stop; /* P/Q right side optimization */ @@ -105,8 +106,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ @@ -192,9 +194,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { u8 **dptr = (u8 **)ptrs; - unsigned long d; - int z, z0; u8 *p, *q; + unsigned long vl, d; + int z, z0; z0 = disks - 3; /* Highest data disk */ p = dptr[z0 + 1]; /* XOR parity */ @@ -202,8 +204,9 @@ static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void ** asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* @@ -284,7 +287,7 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, { u8 **dptr = (u8 **)ptrs; u8 *p, *q; - unsigned long d; + unsigned long vl, d; int z, z0; z0 = stop; /* P/Q right side optimization */ @@ -293,8 +296,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* @@ -410,9 +414,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { u8 **dptr = (u8 **)ptrs; - unsigned long d; - int z, z0; u8 *p, *q; + unsigned long vl, d; + int z, z0; z0 = disks - 3; /* Highest data disk */ p = dptr[z0 + 1]; /* XOR parity */ @@ -420,8 +424,9 @@ static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void ** asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* @@ -536,7 +541,7 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, { u8 **dptr = (u8 **)ptrs; u8 *p, *q; - unsigned long d; + unsigned long vl, d; int z, z0; z0 = stop; /* P/Q right side optimization */ @@ -545,8 +550,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* @@ -718,9 +724,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { u8 **dptr = (u8 **)ptrs; - unsigned long d; - int z, z0; u8 *p, *q; + unsigned long vl, d; + int z, z0; z0 = disks - 3; /* Highest data disk */ p = dptr[z0 + 1]; /* XOR parity */ @@ -728,8 +734,9 @@ static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void ** asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* @@ -912,7 +919,7 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, { u8 **dptr = (u8 **)ptrs; u8 *p, *q; - unsigned long d; + unsigned long vl, d; int z, z0; z0 = stop; /* P/Q right side optimization */ @@ -921,8 +928,9 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, asm volatile (".option push\n" ".option arch,+v\n" - "vsetvli t0, x0, e8, m1, ta, ma\n" + "vsetvli %0, x0, e8, m1, ta, ma\n" ".option pop\n" + : "=&r" (vl) ); /* -- 2.34.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue 2025-06-10 10:12 ` [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue Chunyan Zhang @ 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-11 3:03 ` Chunyan Zhang 2025-06-12 19:30 ` Palmer Dabbelt 1 sibling, 1 reply; 16+ messages in thread From: Palmer Dabbelt @ 2025-06-10 22:00 UTC (permalink / raw) To: zhangchunyan Cc: Paul Walmsley, aou, Alexandre Ghiti, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel, zhang.lyra On Tue, 10 Jun 2025 03:12:32 PDT (-0700), zhangchunyan@iscas.ac.cn wrote: > When running the raid6 user-space test program on RISC-V QEMU, there's a > segmentation fault which seems caused by accessing a NULL pointer, > which is the pointer variable p/q in raid6_rvv*_gen/xor_syndrome_real(), > p/q should have been equal to dptr[x], but when I use GDB command to > see its value, which was 0x10 like below: > > " > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000011062 in raid6_rvv2_xor_syndrome_real (disks=<optimized out>, start=0, stop=<optimized out>, bytes=4096, ptrs=<optimized out>) at rvv.c:386 > (gdb) p p > $1 = (u8 *) 0x10 <error: Cannot access memory at address 0x10> > " > > The issue was found to be related with: > 1) Compile optimization > There's no segmentation fault if compiling the raid6test program with > the optimization flag -O0. > 2) The RISC-V vector command vsetvli > If not used t0 as the first parameter in vsetvli, there's no > segmentation fault either. > > This patch selects the 2nd solution to fix the issue. This code is super fragile, it's got a bunch of vector asm blocks in there that aren't declaring their cobbers. At a bare minimum we should have something like diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c index 99dfa16d37c7..3c9b3fd9f2ed 100644 --- a/lib/raid6/rvv.c +++ b/lib/raid6/rvv.c @@ -17,6 +17,10 @@ #define NSIZE 16 #endif +#ifdef __riscv_vector +#error "This code must be built without compiler support for vector" +#endif + static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { u8 **dptr = (u8 **)ptrs; because it just won't work when built with a compiler that can use vector instructions. > Fixes: 6093faaf9593 ("raid6: Add RISC-V SIMD syndrome and recovery calculations") > Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > --- > lib/raid6/rvv.c | 48 ++++++++++++++++++++++++++++-------------------- > 1 file changed, 28 insertions(+), 20 deletions(-) > > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > index bf7d5cd659e0..b193ea176d5d 100644 > --- a/lib/raid6/rvv.c > +++ b/lib/raid6/rvv.c > @@ -23,9 +23,9 @@ static int rvv_has_vector(void) > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -33,8 +33,9 @@ static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > @@ -96,7 +97,7 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -105,8 +106,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > @@ -192,9 +194,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -202,8 +204,9 @@ static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -284,7 +287,7 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -293,8 +296,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -410,9 +414,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -420,8 +424,9 @@ static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -536,7 +541,7 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -545,8 +550,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -718,9 +724,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -728,8 +734,9 @@ static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -912,7 +919,7 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -921,8 +928,9 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue 2025-06-10 22:00 ` Palmer Dabbelt @ 2025-06-11 3:03 ` Chunyan Zhang 0 siblings, 0 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-11 3:03 UTC (permalink / raw) To: Palmer Dabbelt Cc: zhangchunyan, Paul Walmsley, aou, Alexandre Ghiti, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel Hi Palmer, On Wed, 11 Jun 2025 at 06:00, Palmer Dabbelt <palmer@dabbelt.com> wrote: > > On Tue, 10 Jun 2025 03:12:32 PDT (-0700), zhangchunyan@iscas.ac.cn wrote: > > When running the raid6 user-space test program on RISC-V QEMU, there's a > > segmentation fault which seems caused by accessing a NULL pointer, > > which is the pointer variable p/q in raid6_rvv*_gen/xor_syndrome_real(), > > p/q should have been equal to dptr[x], but when I use GDB command to > > see its value, which was 0x10 like below: > > > > " > > Program received signal SIGSEGV, Segmentation fault. > > 0x0000000000011062 in raid6_rvv2_xor_syndrome_real (disks=<optimized out>, start=0, stop=<optimized out>, bytes=4096, ptrs=<optimized out>) at rvv.c:386 > > (gdb) p p > > $1 = (u8 *) 0x10 <error: Cannot access memory at address 0x10> > > " > > > > The issue was found to be related with: > > 1) Compile optimization > > There's no segmentation fault if compiling the raid6test program with > > the optimization flag -O0. > > 2) The RISC-V vector command vsetvli > > If not used t0 as the first parameter in vsetvli, there's no > > segmentation fault either. > > > > This patch selects the 2nd solution to fix the issue. > > This code is super fragile, it's got a bunch of vector asm blocks in > there that aren't declaring their cobbers. At a bare minimum we should > have something like > > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > index 99dfa16d37c7..3c9b3fd9f2ed 100644 > --- a/lib/raid6/rvv.c > +++ b/lib/raid6/rvv.c > @@ -17,6 +17,10 @@ > #define NSIZE 16 > #endif > > +#ifdef __riscv_vector > +#error "This code must be built without compiler support for vector" > +#endif > + Ok, I will add this. Thanks, Chunyan > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > > because it just won't work when built with a compiler that can use > vector instructions. > > > Fixes: 6093faaf9593 ("raid6: Add RISC-V SIMD syndrome and recovery calculations") > > Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > > --- > > lib/raid6/rvv.c | 48 ++++++++++++++++++++++++++++-------------------- > > 1 file changed, 28 insertions(+), 20 deletions(-) > > > > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > > index bf7d5cd659e0..b193ea176d5d 100644 > > --- a/lib/raid6/rvv.c > > +++ b/lib/raid6/rvv.c > > @@ -23,9 +23,9 @@ static int rvv_has_vector(void) > > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > > { > > u8 **dptr = (u8 **)ptrs; > > - unsigned long d; > > - int z, z0; > > u8 *p, *q; > > + unsigned long vl, d; > > + int z, z0; > > > > z0 = disks - 3; /* Highest data disk */ > > p = dptr[z0 + 1]; /* XOR parity */ > > @@ -33,8 +33,9 @@ static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void ** > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > > @@ -96,7 +97,7 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > > { > > u8 **dptr = (u8 **)ptrs; > > u8 *p, *q; > > - unsigned long d; > > + unsigned long vl, d; > > int z, z0; > > > > z0 = stop; /* P/Q right side optimization */ > > @@ -105,8 +106,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > > @@ -192,9 +194,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > > static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > > { > > u8 **dptr = (u8 **)ptrs; > > - unsigned long d; > > - int z, z0; > > u8 *p, *q; > > + unsigned long vl, d; > > + int z, z0; > > > > z0 = disks - 3; /* Highest data disk */ > > p = dptr[z0 + 1]; /* XOR parity */ > > @@ -202,8 +204,9 @@ static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void ** > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* > > @@ -284,7 +287,7 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > > { > > u8 **dptr = (u8 **)ptrs; > > u8 *p, *q; > > - unsigned long d; > > + unsigned long vl, d; > > int z, z0; > > > > z0 = stop; /* P/Q right side optimization */ > > @@ -293,8 +296,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* > > @@ -410,9 +414,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > > static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > > { > > u8 **dptr = (u8 **)ptrs; > > - unsigned long d; > > - int z, z0; > > u8 *p, *q; > > + unsigned long vl, d; > > + int z, z0; > > > > z0 = disks - 3; /* Highest data disk */ > > p = dptr[z0 + 1]; /* XOR parity */ > > @@ -420,8 +424,9 @@ static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void ** > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* > > @@ -536,7 +541,7 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > > { > > u8 **dptr = (u8 **)ptrs; > > u8 *p, *q; > > - unsigned long d; > > + unsigned long vl, d; > > int z, z0; > > > > z0 = stop; /* P/Q right side optimization */ > > @@ -545,8 +550,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* > > @@ -718,9 +724,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > > static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > > { > > u8 **dptr = (u8 **)ptrs; > > - unsigned long d; > > - int z, z0; > > u8 *p, *q; > > + unsigned long vl, d; > > + int z, z0; > > > > z0 = disks - 3; /* Highest data disk */ > > p = dptr[z0 + 1]; /* XOR parity */ > > @@ -728,8 +734,9 @@ static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void ** > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* > > @@ -912,7 +919,7 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > > { > > u8 **dptr = (u8 **)ptrs; > > u8 *p, *q; > > - unsigned long d; > > + unsigned long vl, d; > > int z, z0; > > > > z0 = stop; /* P/Q right side optimization */ > > @@ -921,8 +928,9 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > > > > asm volatile (".option push\n" > > ".option arch,+v\n" > > - "vsetvli t0, x0, e8, m1, ta, ma\n" > > + "vsetvli %0, x0, e8, m1, ta, ma\n" > > ".option pop\n" > > + : "=&r" (vl) > > ); > > > > /* ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue 2025-06-10 10:12 ` [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue Chunyan Zhang 2025-06-10 22:00 ` Palmer Dabbelt @ 2025-06-12 19:30 ` Palmer Dabbelt 1 sibling, 0 replies; 16+ messages in thread From: Palmer Dabbelt @ 2025-06-12 19:30 UTC (permalink / raw) To: zhangchunyan Cc: Paul Walmsley, aou, Alexandre Ghiti, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel, zhang.lyra On Tue, 10 Jun 2025 03:12:32 PDT (-0700), zhangchunyan@iscas.ac.cn wrote: > When running the raid6 user-space test program on RISC-V QEMU, there's a > segmentation fault which seems caused by accessing a NULL pointer, > which is the pointer variable p/q in raid6_rvv*_gen/xor_syndrome_real(), > p/q should have been equal to dptr[x], but when I use GDB command to > see its value, which was 0x10 like below: > > " > Program received signal SIGSEGV, Segmentation fault. > 0x0000000000011062 in raid6_rvv2_xor_syndrome_real (disks=<optimized out>, start=0, stop=<optimized out>, bytes=4096, ptrs=<optimized out>) at rvv.c:386 > (gdb) p p > $1 = (u8 *) 0x10 <error: Cannot access memory at address 0x10> > " > > The issue was found to be related with: > 1) Compile optimization > There's no segmentation fault if compiling the raid6test program with > the optimization flag -O0. > 2) The RISC-V vector command vsetvli > If not used t0 as the first parameter in vsetvli, there's no > segmentation fault either. > > This patch selects the 2nd solution to fix the issue. I'm picking this one up as a fix, with a some slight commit message wording change to describe the clobber issue. It should show up on fixes soon, assuming nothing goes off the rails you can base the next version of the patch set on bc75552b80e6 ("raid6: riscv: Fix NULL pointer dereference caused by a missing clobber"). On a related note: I think we have another bug if NSIZE doesn't line up with bytes as we're not handling the tails. I'm not sure if that can happen, as I don't really know this code. Also: unless I'm missing something you can replace one one of the loads in the loop with a move, which I assume will be faster on some systems. > Fixes: 6093faaf9593 ("raid6: Add RISC-V SIMD syndrome and recovery calculations") > Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > --- > lib/raid6/rvv.c | 48 ++++++++++++++++++++++++++++-------------------- > 1 file changed, 28 insertions(+), 20 deletions(-) > > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > index bf7d5cd659e0..b193ea176d5d 100644 > --- a/lib/raid6/rvv.c > +++ b/lib/raid6/rvv.c > @@ -23,9 +23,9 @@ static int rvv_has_vector(void) > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -33,8 +33,9 @@ static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > @@ -96,7 +97,7 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -105,8 +106,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* v0:wp0, v1:wq0, v2:wd0/w20, v3:w10 */ > @@ -192,9 +194,9 @@ static void raid6_rvv1_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -202,8 +204,9 @@ static void raid6_rvv2_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -284,7 +287,7 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -293,8 +296,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -410,9 +414,9 @@ static void raid6_rvv2_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -420,8 +424,9 @@ static void raid6_rvv4_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -536,7 +541,7 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -545,8 +550,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -718,9 +724,9 @@ static void raid6_rvv4_xor_syndrome_real(int disks, int start, int stop, > static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > u8 **dptr = (u8 **)ptrs; > - unsigned long d; > - int z, z0; > u8 *p, *q; > + unsigned long vl, d; > + int z, z0; > > z0 = disks - 3; /* Highest data disk */ > p = dptr[z0 + 1]; /* XOR parity */ > @@ -728,8 +734,9 @@ static void raid6_rvv8_gen_syndrome_real(int disks, unsigned long bytes, void ** > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* > @@ -912,7 +919,7 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > { > u8 **dptr = (u8 **)ptrs; > u8 *p, *q; > - unsigned long d; > + unsigned long vl, d; > int z, z0; > > z0 = stop; /* P/Q right side optimization */ > @@ -921,8 +928,9 @@ static void raid6_rvv8_xor_syndrome_real(int disks, int start, int stop, > > asm volatile (".option push\n" > ".option arch,+v\n" > - "vsetvli t0, x0, e8, m1, ta, ma\n" > + "vsetvli %0, x0, e8, m1, ta, ma\n" > ".option pop\n" > + : "=&r" (vl) > ); > > /* ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang 2025-06-10 10:12 ` [PATCH 1/4] raid6: riscv: Clean up unused header file inclusion Chunyan Zhang 2025-06-10 10:12 ` [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue Chunyan Zhang @ 2025-06-10 10:12 ` Chunyan Zhang 2025-06-10 21:49 ` Palmer Dabbelt 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-10 10:12 ` [PATCH 4/4] raid6: test: Add support for RISC-V Chunyan Zhang ` (2 subsequent siblings) 5 siblings, 2 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-10 10:12 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang To support userspace raid6test, this patch adds __KERNEL__ ifdef for kernel header inclusions also userspace wrapper definitions to allow code to be compiled in userspace. Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> --- lib/raid6/recov_rvv.c | 7 +------ lib/raid6/rvv.c | 11 ++++------- lib/raid6/rvv.h | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/raid6/recov_rvv.c b/lib/raid6/recov_rvv.c index 500da521a806..8f2be833c015 100644 --- a/lib/raid6/recov_rvv.c +++ b/lib/raid6/recov_rvv.c @@ -4,13 +4,8 @@ * Author: Chunyan Zhang <zhangchunyan@iscas.ac.cn> */ -#include <asm/vector.h> #include <linux/raid/pq.h> - -static int rvv_has_vector(void) -{ - return has_vector(); -} +#include "rvv.h" static void __raid6_2data_recov_rvv(int bytes, u8 *p, u8 *q, u8 *dp, u8 *dq, const u8 *pbmul, diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c index b193ea176d5d..99dfa16d37c7 100644 --- a/lib/raid6/rvv.c +++ b/lib/raid6/rvv.c @@ -9,16 +9,13 @@ * Copyright 2002-2004 H. Peter Anvin */ -#include <asm/vector.h> -#include <linux/raid/pq.h> #include "rvv.h" +#ifdef __KERNEL__ #define NSIZE (riscv_v_vsize / 32) /* NSIZE = vlenb */ - -static int rvv_has_vector(void) -{ - return has_vector(); -} +#else +#define NSIZE 16 +#endif static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) { diff --git a/lib/raid6/rvv.h b/lib/raid6/rvv.h index 94044a1b707b..595dfbf95d4e 100644 --- a/lib/raid6/rvv.h +++ b/lib/raid6/rvv.h @@ -7,6 +7,21 @@ * Definitions for RISC-V RAID-6 code */ +#ifdef __KERNEL__ +#include <asm/vector.h> +#else +#define kernel_vector_begin() +#define kernel_vector_end() +#define has_vector() (1) +#endif + +#include <linux/raid/pq.h> + +static int rvv_has_vector(void) +{ + return has_vector(); +} + #define RAID6_RVV_WRAPPER(_n) \ static void raid6_rvv ## _n ## _gen_syndrome(int disks, \ size_t bytes, void **ptrs) \ -- 2.34.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace 2025-06-10 10:12 ` [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace Chunyan Zhang @ 2025-06-10 21:49 ` Palmer Dabbelt 2025-06-10 22:00 ` Palmer Dabbelt 1 sibling, 0 replies; 16+ messages in thread From: Palmer Dabbelt @ 2025-06-10 21:49 UTC (permalink / raw) To: zhangchunyan Cc: Paul Walmsley, aou, Alexandre Ghiti, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel, zhang.lyra On Tue, 10 Jun 2025 03:12:33 PDT (-0700), zhangchunyan@iscas.ac.cn wrote: > To support userspace raid6test, this patch adds __KERNEL__ ifdef for kernel > header inclusions also userspace wrapper definitions to allow code to be > compiled in userspace. > > Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > --- > lib/raid6/recov_rvv.c | 7 +------ > lib/raid6/rvv.c | 11 ++++------- > lib/raid6/rvv.h | 15 +++++++++++++++ > 3 files changed, 20 insertions(+), 13 deletions(-) > > diff --git a/lib/raid6/recov_rvv.c b/lib/raid6/recov_rvv.c > index 500da521a806..8f2be833c015 100644 > --- a/lib/raid6/recov_rvv.c > +++ b/lib/raid6/recov_rvv.c > @@ -4,13 +4,8 @@ > * Author: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > */ > > -#include <asm/vector.h> > #include <linux/raid/pq.h> > - > -static int rvv_has_vector(void) > -{ > - return has_vector(); > -} > +#include "rvv.h" > > static void __raid6_2data_recov_rvv(int bytes, u8 *p, u8 *q, u8 *dp, > u8 *dq, const u8 *pbmul, > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > index b193ea176d5d..99dfa16d37c7 100644 > --- a/lib/raid6/rvv.c > +++ b/lib/raid6/rvv.c > @@ -9,16 +9,13 @@ > * Copyright 2002-2004 H. Peter Anvin > */ > > -#include <asm/vector.h> > -#include <linux/raid/pq.h> > #include "rvv.h" > > +#ifdef __KERNEL__ > #define NSIZE (riscv_v_vsize / 32) /* NSIZE = vlenb */ > - > -static int rvv_has_vector(void) > -{ > - return has_vector(); > -} > +#else > +#define NSIZE 16 > +#endif > > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > diff --git a/lib/raid6/rvv.h b/lib/raid6/rvv.h > index 94044a1b707b..595dfbf95d4e 100644 > --- a/lib/raid6/rvv.h > +++ b/lib/raid6/rvv.h > @@ -7,6 +7,21 @@ > * Definitions for RISC-V RAID-6 code > */ > > +#ifdef __KERNEL__ > +#include <asm/vector.h> > +#else > +#define kernel_vector_begin() > +#define kernel_vector_end() > +#define has_vector() (1) This should be gated on something, as we don't have vector everywhere in userspace. We could dynamically check via hwprobe(), that's probably best? > +#endif > + > +#include <linux/raid/pq.h> > + > +static int rvv_has_vector(void) > +{ > + return has_vector(); > +} > + > #define RAID6_RVV_WRAPPER(_n) \ > static void raid6_rvv ## _n ## _gen_syndrome(int disks, \ > size_t bytes, void **ptrs) \ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace 2025-06-10 10:12 ` [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace Chunyan Zhang 2025-06-10 21:49 ` Palmer Dabbelt @ 2025-06-10 22:00 ` Palmer Dabbelt 1 sibling, 0 replies; 16+ messages in thread From: Palmer Dabbelt @ 2025-06-10 22:00 UTC (permalink / raw) To: zhangchunyan Cc: Paul Walmsley, aou, Alexandre Ghiti, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel, zhang.lyra On Tue, 10 Jun 2025 03:12:33 PDT (-0700), zhangchunyan@iscas.ac.cn wrote: > To support userspace raid6test, this patch adds __KERNEL__ ifdef for kernel > header inclusions also userspace wrapper definitions to allow code to be > compiled in userspace. > > Signed-off-by: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > --- > lib/raid6/recov_rvv.c | 7 +------ > lib/raid6/rvv.c | 11 ++++------- > lib/raid6/rvv.h | 15 +++++++++++++++ > 3 files changed, 20 insertions(+), 13 deletions(-) > > diff --git a/lib/raid6/recov_rvv.c b/lib/raid6/recov_rvv.c > index 500da521a806..8f2be833c015 100644 > --- a/lib/raid6/recov_rvv.c > +++ b/lib/raid6/recov_rvv.c > @@ -4,13 +4,8 @@ > * Author: Chunyan Zhang <zhangchunyan@iscas.ac.cn> > */ > > -#include <asm/vector.h> > #include <linux/raid/pq.h> > - > -static int rvv_has_vector(void) > -{ > - return has_vector(); > -} > +#include "rvv.h" > > static void __raid6_2data_recov_rvv(int bytes, u8 *p, u8 *q, u8 *dp, > u8 *dq, const u8 *pbmul, > diff --git a/lib/raid6/rvv.c b/lib/raid6/rvv.c > index b193ea176d5d..99dfa16d37c7 100644 > --- a/lib/raid6/rvv.c > +++ b/lib/raid6/rvv.c > @@ -9,16 +9,13 @@ > * Copyright 2002-2004 H. Peter Anvin > */ > > -#include <asm/vector.h> > -#include <linux/raid/pq.h> > #include "rvv.h" > > +#ifdef __KERNEL__ > #define NSIZE (riscv_v_vsize / 32) /* NSIZE = vlenb */ > - > -static int rvv_has_vector(void) > -{ > - return has_vector(); > -} > +#else > +#define NSIZE 16 > +#endif and looking at the code a bit more, this makes this VLS when run in userspace. So we etiher need a check for that, or to check VL in the loop. > > static void raid6_rvv1_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs) > { > diff --git a/lib/raid6/rvv.h b/lib/raid6/rvv.h > index 94044a1b707b..595dfbf95d4e 100644 > --- a/lib/raid6/rvv.h > +++ b/lib/raid6/rvv.h > @@ -7,6 +7,21 @@ > * Definitions for RISC-V RAID-6 code > */ > > +#ifdef __KERNEL__ > +#include <asm/vector.h> > +#else > +#define kernel_vector_begin() > +#define kernel_vector_end() > +#define has_vector() (1) > +#endif > + > +#include <linux/raid/pq.h> > + > +static int rvv_has_vector(void) > +{ > + return has_vector(); > +} > + > #define RAID6_RVV_WRAPPER(_n) \ > static void raid6_rvv ## _n ## _gen_syndrome(int disks, \ > size_t bytes, void **ptrs) \ ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 4/4] raid6: test: Add support for RISC-V 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang ` (2 preceding siblings ...) 2025-06-10 10:12 ` [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace Chunyan Zhang @ 2025-06-10 10:12 ` Chunyan Zhang 2025-06-10 19:23 ` [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Alexandre Ghiti 2025-07-09 15:18 ` Alexandre Ghiti 5 siblings, 0 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-10 10:12 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang From: Chunyan Zhang <zhang.lyra@gmail.com> Add RISC-V code to be compiled to allow the userspace raid6test program to be built and run on RISC-V. Signed-off-by: Chunyan Zhang <zhang.lyra@gmail.com> --- lib/raid6/test/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/raid6/test/Makefile b/lib/raid6/test/Makefile index 8f2dd2210ba8..09bbe2b14cce 100644 --- a/lib/raid6/test/Makefile +++ b/lib/raid6/test/Makefile @@ -35,6 +35,11 @@ ifeq ($(ARCH),aarch64) HAS_NEON = yes endif +ifeq ($(findstring riscv,$(ARCH)),riscv) + CFLAGS += -I../../../arch/riscv/include -DCONFIG_RISCV=1 + HAS_RVV = yes +endif + ifeq ($(findstring ppc,$(ARCH)),ppc) CFLAGS += -I../../../arch/powerpc/include HAS_ALTIVEC := $(shell printf '$(pound)include <altivec.h>\nvector int a;\n' |\ @@ -63,6 +68,9 @@ else ifeq ($(HAS_ALTIVEC),yes) vpermxor1.o vpermxor2.o vpermxor4.o vpermxor8.o else ifeq ($(ARCH),loongarch64) OBJS += loongarch_simd.o recov_loongarch_simd.o +else ifeq ($(HAS_RVV),yes) + OBJS += rvv.o recov_rvv.o + CFLAGS += -DCONFIG_RISCV_ISA_V=1 endif .c.o: -- 2.34.1 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang ` (3 preceding siblings ...) 2025-06-10 10:12 ` [PATCH 4/4] raid6: test: Add support for RISC-V Chunyan Zhang @ 2025-06-10 19:23 ` Alexandre Ghiti 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-11 2:08 ` Chunyan Zhang 2025-07-09 15:18 ` Alexandre Ghiti 5 siblings, 2 replies; 16+ messages in thread From: Alexandre Ghiti @ 2025-06-10 19:23 UTC (permalink / raw) To: Chunyan Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang Hi Chunyan, On 6/10/25 12:12, Chunyan Zhang wrote: > The first two patches are fixes. > The last two are for userspace raid6test support on RISC-V. > > The issue fixed in patch 2/4 was probably the same which was spotted by > Charlie [1], I couldn't reproduce it at that time. > > When running raid6test in userspace on RISC-V, I saw a segmentation fault, > I used gdb command to print pointer p, it was an unaccessible address. Can you give me your config, kernel and toolchain versions? I can't reproduce the segfault on my machine. Thanks for the fixes and the test, I'll take a look this week. Alex > > With patch 2/4, the issue didn't appear anymore. > > [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ > > Chunyan Zhang (4): > raid6: riscv: clean up unused header file inclusion > raid6: riscv: Fix NULL pointer dereference issue > raid6: riscv: Allow code to be compiled in userspace > raid6: test: add support for RISC-V > > lib/raid6/recov_rvv.c | 9 +----- > lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- > lib/raid6/rvv.h | 15 ++++++++++ > lib/raid6/test/Makefile | 8 ++++++ > 4 files changed, 56 insertions(+), 38 deletions(-) > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-06-10 19:23 ` [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Alexandre Ghiti @ 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-11 2:08 ` Chunyan Zhang 1 sibling, 0 replies; 16+ messages in thread From: Palmer Dabbelt @ 2025-06-10 22:00 UTC (permalink / raw) To: Alexandre Ghiti Cc: zhangchunyan, Paul Walmsley, aou, Charlie Jenkins, song, yukuai3, linux-riscv, linux-raid, linux-kernel, zhang.lyra On Tue, 10 Jun 2025 12:23:18 PDT (-0700), Alexandre Ghiti wrote: > Hi Chunyan, > > On 6/10/25 12:12, Chunyan Zhang wrote: >> The first two patches are fixes. >> The last two are for userspace raid6test support on RISC-V. >> >> The issue fixed in patch 2/4 was probably the same which was spotted by >> Charlie [1], I couldn't reproduce it at that time. >> >> When running raid6test in userspace on RISC-V, I saw a segmentation fault, >> I used gdb command to print pointer p, it was an unaccessible address. > > > Can you give me your config, kernel and toolchain versions? I can't > reproduce the segfault on my machine. It's probably going to be super fragile to reproduce. The code is just scrubbing over t0 without a clobber, so it's just going to break stuff somewhat arbitrarily. > > Thanks for the fixes and the test, I'll take a look this week. > > Alex > > >> >> With patch 2/4, the issue didn't appear anymore. >> >> [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ >> >> Chunyan Zhang (4): >> raid6: riscv: clean up unused header file inclusion >> raid6: riscv: Fix NULL pointer dereference issue >> raid6: riscv: Allow code to be compiled in userspace >> raid6: test: add support for RISC-V >> >> lib/raid6/recov_rvv.c | 9 +----- >> lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- >> lib/raid6/rvv.h | 15 ++++++++++ >> lib/raid6/test/Makefile | 8 ++++++ >> 4 files changed, 56 insertions(+), 38 deletions(-) >> ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-06-10 19:23 ` [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Alexandre Ghiti 2025-06-10 22:00 ` Palmer Dabbelt @ 2025-06-11 2:08 ` Chunyan Zhang 1 sibling, 0 replies; 16+ messages in thread From: Chunyan Zhang @ 2025-06-11 2:08 UTC (permalink / raw) To: Alexandre Ghiti Cc: Chunyan Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins, Song Liu, Yu Kuai, linux-riscv, linux-raid, linux-kernel Hi Alex, On Wed, 11 Jun 2025 at 03:23, Alexandre Ghiti <alex@ghiti.fr> wrote: > > Hi Chunyan, > > On 6/10/25 12:12, Chunyan Zhang wrote: > > The first two patches are fixes. > > The last two are for userspace raid6test support on RISC-V. > > > > The issue fixed in patch 2/4 was probably the same which was spotted by > > Charlie [1], I couldn't reproduce it at that time. > > > > When running raid6test in userspace on RISC-V, I saw a segmentation fault, > > I used gdb command to print pointer p, it was an unaccessible address. > > > Can you give me your config, kernel and toolchain versions? I can't > reproduce the segfault on my machine. I can use the below combination to reproduce: - riscv/configs/defconfig - Kernel v6.16-rc1 - Cross-compile toolchain [1] for building kernel which brings up QEMU (running Ubuntu 22.04) - Two choices for compiling raid6test program after applying patches 3-4: 1) Use toolchain [1] to cross-compile it as statically linked. 2) Compile it locally on QEMU (running Ubuntu 22.04) with local riscv gcc: root@riscv-ubuntu2204:~# gcc --version gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 Thanks, Chunyan [1] https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.05.30/riscv64-glibc-ubuntu-22.04-gcc-nightly-2025.05.30-nightly.tar.xz > > Thanks for the fixes and the test, I'll take a look this week. > > Alex > > > > > > With patch 2/4, the issue didn't appear anymore. > > > > [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ > > > > Chunyan Zhang (4): > > raid6: riscv: clean up unused header file inclusion > > raid6: riscv: Fix NULL pointer dereference issue > > raid6: riscv: Allow code to be compiled in userspace > > raid6: test: add support for RISC-V > > > > lib/raid6/recov_rvv.c | 9 +----- > > lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- > > lib/raid6/rvv.h | 15 ++++++++++ > > lib/raid6/test/Makefile | 8 ++++++ > > 4 files changed, 56 insertions(+), 38 deletions(-) > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang ` (4 preceding siblings ...) 2025-06-10 19:23 ` [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Alexandre Ghiti @ 2025-07-09 15:18 ` Alexandre Ghiti 2025-07-10 1:44 ` Chunyan Zhang 5 siblings, 1 reply; 16+ messages in thread From: Alexandre Ghiti @ 2025-07-09 15:18 UTC (permalink / raw) To: Chunyan Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins, Song Liu, Yu Kuai Cc: linux-riscv, linux-raid, linux-kernel, Chunyan Zhang Hi Chunyan, Patch 2 was merged via fixes, do you plan on resending a new version for 6.17 that takes into account Palmer's remarks? Thanks, Alex On 6/10/25 12:12, Chunyan Zhang wrote: > The first two patches are fixes. > The last two are for userspace raid6test support on RISC-V. > > The issue fixed in patch 2/4 was probably the same which was spotted by > Charlie [1], I couldn't reproduce it at that time. > > When running raid6test in userspace on RISC-V, I saw a segmentation fault, > I used gdb command to print pointer p, it was an unaccessible address. > > With patch 2/4, the issue didn't appear anymore. > > [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ > > Chunyan Zhang (4): > raid6: riscv: clean up unused header file inclusion > raid6: riscv: Fix NULL pointer dereference issue > raid6: riscv: Allow code to be compiled in userspace > raid6: test: add support for RISC-V > > lib/raid6/recov_rvv.c | 9 +----- > lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- > lib/raid6/rvv.h | 15 ++++++++++ > lib/raid6/test/Makefile | 8 ++++++ > 4 files changed, 56 insertions(+), 38 deletions(-) > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-07-09 15:18 ` Alexandre Ghiti @ 2025-07-10 1:44 ` Chunyan Zhang 2025-07-10 7:45 ` Alexandre Ghiti 0 siblings, 1 reply; 16+ messages in thread From: Chunyan Zhang @ 2025-07-10 1:44 UTC (permalink / raw) To: Alexandre Ghiti Cc: Chunyan Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins, Song Liu, Yu Kuai, linux-riscv, linux-raid, linux-kernel Hi Alex, On Wed, 9 Jul 2025 at 23:18, Alexandre Ghiti <alex@ghiti.fr> wrote: > > Hi Chunyan, > > Patch 2 was merged via fixes, do you plan on resending a new version for > 6.17 that takes into account Palmer's remarks? Yes, I'm preparing the patches these days, just haven't figured out how to set NSIZE properly for user space. I probably should split the patchset, send out one today. Thanks, Chunyan > > Thanks, > > Alex > > On 6/10/25 12:12, Chunyan Zhang wrote: > > The first two patches are fixes. > > The last two are for userspace raid6test support on RISC-V. > > > > The issue fixed in patch 2/4 was probably the same which was spotted by > > Charlie [1], I couldn't reproduce it at that time. > > > > When running raid6test in userspace on RISC-V, I saw a segmentation fault, > > I used gdb command to print pointer p, it was an unaccessible address. > > > > With patch 2/4, the issue didn't appear anymore. > > > > [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ > > > > Chunyan Zhang (4): > > raid6: riscv: clean up unused header file inclusion > > raid6: riscv: Fix NULL pointer dereference issue > > raid6: riscv: Allow code to be compiled in userspace > > raid6: test: add support for RISC-V > > > > lib/raid6/recov_rvv.c | 9 +----- > > lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- > > lib/raid6/rvv.h | 15 ++++++++++ > > lib/raid6/test/Makefile | 8 ++++++ > > 4 files changed, 56 insertions(+), 38 deletions(-) > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support 2025-07-10 1:44 ` Chunyan Zhang @ 2025-07-10 7:45 ` Alexandre Ghiti 0 siblings, 0 replies; 16+ messages in thread From: Alexandre Ghiti @ 2025-07-10 7:45 UTC (permalink / raw) To: Chunyan Zhang Cc: Chunyan Zhang, Paul Walmsley, Palmer Dabbelt, Albert Ou, Charlie Jenkins, Song Liu, Yu Kuai, linux-riscv, linux-raid, linux-kernel On 7/10/25 03:44, Chunyan Zhang wrote: > Hi Alex, > > On Wed, 9 Jul 2025 at 23:18, Alexandre Ghiti <alex@ghiti.fr> wrote: >> Hi Chunyan, >> >> Patch 2 was merged via fixes, do you plan on resending a new version for >> 6.17 that takes into account Palmer's remarks? > Yes, I'm preparing the patches these days, just haven't figured out > how to set NSIZE properly for user space. Just use hwprobe() to make sure V is supported and then csr_read(VLENB) to retrieve this value, no? > > I probably should split the patchset, send out one today. > > Thanks, > Chunyan > >> Thanks, >> >> Alex >> >> On 6/10/25 12:12, Chunyan Zhang wrote: >>> The first two patches are fixes. >>> The last two are for userspace raid6test support on RISC-V. >>> >>> The issue fixed in patch 2/4 was probably the same which was spotted by >>> Charlie [1], I couldn't reproduce it at that time. >>> >>> When running raid6test in userspace on RISC-V, I saw a segmentation fault, >>> I used gdb command to print pointer p, it was an unaccessible address. >>> >>> With patch 2/4, the issue didn't appear anymore. >>> >>> [1] https://lore.kernel.org/lkml/Z5gJ35pXI2W41QDk@ghost/ >>> >>> Chunyan Zhang (4): >>> raid6: riscv: clean up unused header file inclusion >>> raid6: riscv: Fix NULL pointer dereference issue >>> raid6: riscv: Allow code to be compiled in userspace >>> raid6: test: add support for RISC-V >>> >>> lib/raid6/recov_rvv.c | 9 +----- >>> lib/raid6/rvv.c | 62 +++++++++++++++++++++-------------------- >>> lib/raid6/rvv.h | 15 ++++++++++ >>> lib/raid6/test/Makefile | 8 ++++++ >>> 4 files changed, 56 insertions(+), 38 deletions(-) >>> ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2025-07-10 7:45 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-06-10 10:12 [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Chunyan Zhang 2025-06-10 10:12 ` [PATCH 1/4] raid6: riscv: Clean up unused header file inclusion Chunyan Zhang 2025-06-10 10:12 ` [PATCH 2/4] raid6: riscv: Fix NULL pointer dereference issue Chunyan Zhang 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-11 3:03 ` Chunyan Zhang 2025-06-12 19:30 ` Palmer Dabbelt 2025-06-10 10:12 ` [PATCH 3/4] raid6: riscv: Allow code to be compiled in userspace Chunyan Zhang 2025-06-10 21:49 ` Palmer Dabbelt 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-10 10:12 ` [PATCH 4/4] raid6: test: Add support for RISC-V Chunyan Zhang 2025-06-10 19:23 ` [PATCH 0/4] Fix a segmentation fault also add raid6test for RISC-V support Alexandre Ghiti 2025-06-10 22:00 ` Palmer Dabbelt 2025-06-11 2:08 ` Chunyan Zhang 2025-07-09 15:18 ` Alexandre Ghiti 2025-07-10 1:44 ` Chunyan Zhang 2025-07-10 7:45 ` Alexandre Ghiti
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).