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
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) \
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) \
© 2016 - 2025 Red Hat, Inc.