cleanup the RAID6 P/Q library v3
Subsystems (11)
Hi all,
this series cleans up the RAID6 P/Q library to match the recent updates to the RAID 5 XOR library and other CRC/crypto libraries. This includes providing properly documented external interfaces, hiding the internals, using static_call instead of indirect calls and turning the user space test suite into an in-kernel kunit test which is also extended to improve coverage.
Note that this changes registration so that non-priority algorithms are not registered, which greatly helps with the benchmark time at boot time. I'd like to encourage all architecture maintainers to see if they can further optimized this by registering as few as possible algorithms when there is a clear benefit in optimized or more unrolled implementations.
This series sits on top of the "cleanup the RAID5 XOR library v3" series.
A git tree is also available here:
git://git.infradead.org/users/hch/misc.git lib-raid6
Gitweb:
https://git.infradead.org/?p=users/hch/misc.git;a=shortlog;h=refs/heads/lib-raid6
Changes since v2:
- merge two patches that should have been one
- split out enforcing the 4-device minimum into a well-documented patch explaining the rationale
- drop the btrfs patch to restrict the number of devices again
- fix them module description for the kunit test
- add -I $(src) to fix out of srctree builds for architectures with headers in the architecture-specific directories
- always add the least optimized/unrolled algorithms first to keep the existing no-benchmark behavior
- drop the delayed benchmarking for now to avoid corner cases
- improve a few commit messages
Changes since v1:
- fix arm64 objdir != srcdir builds
- call the kunit module raid6_kunit.ko from the beginning
- update MAINTAINERS
- don't require preemptible context and apply the same restrictions as the merged version of the XOR API
- fix the arm64 default in Kconfig
- pick the last registered (and presumably most optimized) algorithm when benchmarking is disabled
- port over the randomization fixes from the XOR series
- misc other kunit cleanups
- require at least 4 devices for RAID6 to skip broken special cases
Diffstat:
b/Documentation/crypto/async-tx-api.rst | 4 b/MAINTAINERS | 2 b/crypto/async_tx/async_pq.c | 9 b/crypto/async_tx/async_raid6_recov.c | 9 b/drivers/dma/bcm-sba-raid.c | 1 b/drivers/md/raid5.c | 4 b/fs/btrfs/raid56.c | 8 b/include/linux/raid/pq.h | 216 ------------ b/include/linux/raid/pq_tables.h | 19 + b/lib/Kconfig | 11 b/lib/Makefile | 1 b/lib/raid/Kconfig | 33 + b/lib/raid/Makefile | 2 b/lib/raid/raid6/Makefile | 128 +++++++ b/lib/raid/raid6/algos.c | 377 ++++++++++++++++++++++ b/lib/raid/raid6/algos.h | 41 ++ b/lib/raid/raid6/arm/neon.c | 23 - b/lib/raid/raid6/arm/neon.uc | 2 b/lib/raid/raid6/arm/pq_arch.h | 21 + b/lib/raid/raid6/arm/recov_neon.c | 27 - b/lib/raid/raid6/arm/recov_neon_inner.c | 2 b/lib/raid/raid6/arm64/pq_arch.h | 1 b/lib/raid/raid6/int.uc | 10 b/lib/raid/raid6/loongarch/loongarch_simd.c | 31 - b/lib/raid/raid6/loongarch/pq_arch.h | 23 + b/lib/raid/raid6/loongarch/recov_loongarch_simd.c | 39 -- b/lib/raid/raid6/mktables.c | 28 - b/lib/raid/raid6/powerpc/altivec.uc | 32 - b/lib/raid/raid6/powerpc/pq_arch.h | 32 + b/lib/raid/raid6/powerpc/vpermxor.uc | 29 - b/lib/raid/raid6/recov.c | 62 --- b/lib/raid/raid6/riscv/pq_arch.h | 21 + b/lib/raid/raid6/riscv/recov_rvv.c | 14 b/lib/raid/raid6/riscv/rvv.h | 26 - b/lib/raid/raid6/s390/pq_arch.h | 15 b/lib/raid/raid6/s390/recov_s390xc.c | 14 b/lib/raid/raid6/s390/s390vx.uc | 15 b/lib/raid/raid6/tests/Makefile | 3 b/lib/raid/raid6/tests/raid6_kunit.c | 321 ++++++++++++++++++ b/lib/raid/raid6/x86/avx2.c | 47 -- b/lib/raid/raid6/x86/avx512.c | 57 +-- b/lib/raid/raid6/x86/mmx.c | 39 -- b/lib/raid/raid6/x86/pq_arch.h | 96 +++++ b/lib/raid/raid6/x86/recov_avx2.c | 22 - b/lib/raid/raid6/x86/recov_avx512.c | 26 - b/lib/raid/raid6/x86/recov_ssse3.c | 23 - b/lib/raid/raid6/x86/sse1.c | 49 -- b/lib/raid/raid6/x86/sse2.c | 47 -- lib/raid6/Makefile | 83 ---- lib/raid6/algos.c | 291 ---------------- lib/raid6/loongarch.h | 38 -- lib/raid6/test/.gitignore | 3 lib/raid6/test/Makefile | 156 --------- lib/raid6/test/test.c | 152 -------- lib/raid6/x86.h | 75 ---- 55 files changed, 1349 insertions(+), 1511 deletions(-)
PATCH 1/18 raid6: turn the userspace test harness into a kunit test
Currently the raid6 code can be compiled as userspace code to run the test suite. Convert that to be a kunit case with minimal changes to avoid mutating global state so that we can drop this requirement.
Note that this is not a good kunit test case yet and will need a lot more work, but that is deferred until the raid6 code is moved to it's new place, which is easier if the userspace makefile doesn't need adjustments for the new location first.
--- include/linux/raid/pq.h | 3 - lib/Kconfig | 11 +++ lib/raid6/Makefile | 2 +- lib/raid6/algos.c | 5 +- lib/raid6/recov.c | 34 --------- lib/raid6/test/Makefile | 155 +-------------------------------------- lib/raid6/test/test.c | 158 +++++++++++++++++++++------------------- 7 files changed, 101 insertions(+), 267 deletions(-)
include/linux/raid/pq.h +0 -3
@@ -144,7 +144,6 @@ extern const struct raid6_calls raid6_neonx8;/* Algorithm list */ extern const struct raid6_calls *const raid6_algos[];extern const struct raid6_recov_calls *const raid6_recov_algos[]; -int raid6_select_algo (void );/* Return values from chk_syndrome */ #define RAID6_OK 0
@@ -165,8 +164,6 @@ extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb, void **ptrs);extern void (*raid6_datap_recov)(int disks,size_t bytes,int faila,void **ptrs); -void raid6_dual_recov (int disks,size_t bytes,int faila,int failb, -void **ptrs);/* Some definitions to allow code to be compiled for testing in userspace */ #ifndef __KERNEL__
lib/Kconfig +11 -0
@@ -11,6 +11,17 @@ menu "Library routines" config RAID6_PQ tristate +config RAID6_PQ_KUNIT_TEST + tristate "KUnit tests for RAID6 PQ functions" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on RAID6_PQ + default KUNIT_ALL_TESTS + help + Unit tests for the RAID6 PQ library functions. + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N. + config RAID6_PQ_BENCHMARK bool "Automatically choose fastest RAID6 PQ functions" depends on RAID6_PQ
lib/raid6/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_RAID6_PQ) += raid6_pq.o +obj-$(CONFIG_RAID6_PQ) += raid6_pq.o test/ raid6_pq-y += algos.o recov.o tables.o int1.o int2.o int4.o \ int8.o
lib/raid6/algos.c +4 -1
@@ -19,6 +19,7 @@#include <linux/module.h> #include <linux/gfp.h> #endif +#include <kunit/visibility.h> struct raid6_calls raid6_call;EXPORT_SYMBOL_GPL (raid6_call);
@@ -86,6 +87,7 @@ const struct raid6_calls * const raid6_algos[] = { &raid6_intx1, NULL }; +EXPORT_SYMBOL_IF_KUNIT (raid6_algos);void (*raid6_2data_recov)(int ,size_t ,int ,int ,void **);EXPORT_SYMBOL_GPL (raid6_2data_recov);
@@ -119,6 +121,7 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = { &raid6_recov_intx1, NULL }; +EXPORT_SYMBOL_IF_KUNIT (raid6_recov_algos);#ifdef __KERNEL__#define RAID6_TIME_JIFFIES_LG2 4
@@ -239,7 +242,7 @@ static inline const struct raid6_calls *raid6_choose_gen(/* Try to pick the best algorithm */ /* This code uses the gfmul table as convenient data set to abuse */ -int __init raid6_select_algo (void ) +static int __init raid6_select_algo (void ) {const int disks =RAID6_TEST_DISKS ;
lib/raid6/recov.c +0 -34
@@ -99,37 +99,3 @@ const struct raid6_recov_calls raid6_recov_intx1 = { .name = "intx1", .priority = 0, }; - -#ifndef __KERNEL__ -/* Testing only */ - -/* Recover two failed blocks. */ -void raid6_dual_recov (int disks,size_t bytes,int faila,int failb,void **ptrs) -{ -if ( faila > failb ) { -int tmp = faila; - faila = failb; - failb = tmp; - } - -if ( failb == disks-1 ) { -if ( faila == disks-2 ) { -/* P+Q failure. Just rebuild the syndrome. */ - raid6_call.gen_syndrome (disks, bytes, ptrs); - }else { -/* data+Q failure. Reconstruct data from P, -then rebuild syndrome. */ -/* NOT IMPLEMENTED - equivalent to RAID-5 */ - } - }else { -if ( failb == disks-2 ) { -/* data+P failure. */ -raid6_datap_recov (disks, bytes, faila, ptrs); - }else { -/* data+data failure. */ -raid6_2data_recov (disks, bytes, faila, failb, ptrs); - } - } -} - -#endif
lib/raid6/test/Makefile +2 -153
158 lines not on this page · raw message
lib/raid6/test/test.c +83 -75
230 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 01/18] raid6: turn the userspace test harness into a kunit test
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Quoted 10 lines · On Mon, 18 May 2026 07:17:44 +0200 you wrote:
Currently the raid6 code can be compiled as userspace code to run the test suite. Convert that to be a kunit case with minimal changes to avoid mutating global state so that we can drop this requirement.
Note that this is not a good kunit test case yet and will need a lot more work, but that is deferred until the raid6 code is moved to it's new place, which is easier if the userspace makefile doesn't need adjustments for the new location first.
[...]
Here is the summary with links:
- [01/18] raid6: turn the userspace test harness into a kunit test
https://git.kernel.org/riscv/c/c4697486fc23 - [02/18] raid6: remove __KERNEL__ ifdefs https://git.kernel.org/riscv/c/3d6beb659ddf - [03/18] raid6: move to lib/raid/ https://git.kernel.org/riscv/c/3626738bc714 - [04/18] raid6: remove unused defines in pq.h https://git.kernel.org/riscv/c/06d2a66fb7c0 - [05/18] raid6: remove raid6_get_zero_page https://git.kernel.org/riscv/c/885d31423183 - [06/18] raid6: use named initializers for struct raid6_calls https://git.kernel.org/riscv/c/7e91f76a9668 - [07/18] raid6: improve the public interface https://git.kernel.org/riscv/c/35472bc6f31b - [08/18] raid6: warn when using less than four devices https://git.kernel.org/riscv/c/2790045a62eb - [09/18] raid6: hide internals (no matching commit) - [10/18] raid6: rework registration of optimized algorithms (no matching commit) - [11/18] raid6: use static_call for gen_syndrom and xor_syndrom https://git.kernel.org/riscv/c/10f4b8e2a164 - [12/18] raid6: use static_call for raid6_recov_2data and raid6_recov_datap https://git.kernel.org/riscv/c/dd83de0341da - [13/18] raid6: update top of file comments https://git.kernel.org/riscv/c/30bf04bd13a5 - [14/18] raid6_kunit: use KUNIT_CASE_PARAM https://git.kernel.org/riscv/c/2175395f76c3 - [15/18] raid6_kunit: dynamically allocate data buffers using vmalloc https://git.kernel.org/riscv/c/d67c25712fe3 - [16/18] raid6_kunit: cleanup dataptr handling https://git.kernel.org/riscv/c/562bcbfcb99b - [17/18] raid6_kunit: randomize parameters and increase limits https://git.kernel.org/riscv/c/fa0c812c0aa5 - [18/18] raid6_kunit: randomize buffer alignment https://git.kernel.org/riscv/c/8cf0a6c4bb9e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
PATCH 2/18 raid6: remove __KERNEL__ ifdefs
In reply to Christoph HellwigWith the test code ported to kernel space, none of this is required.
--- include/linux/raid/pq.h | 90 -------------------------------- lib/raid6/algos.c | 12 ----- lib/raid6/altivec.uc | 10 +--- lib/raid6/avx2.c | 2 +- lib/raid6/avx512.c | 2 +- lib/raid6/loongarch.h | 38 -------------- lib/raid6/loongarch_simd.c | 3 +- lib/raid6/mktables.c | 14 ----- lib/raid6/mmx.c | 2 +- lib/raid6/neon.c | 6 --- lib/raid6/recov_avx2.c | 2 +- lib/raid6/recov_avx512.c | 2 +- lib/raid6/recov_loongarch_simd.c | 3 +- lib/raid6/recov_neon.c | 6 --- lib/raid6/recov_ssse3.c | 2 +- lib/raid6/rvv.h | 11 +--- lib/raid6/sse1.c | 2 +- lib/raid6/sse2.c | 2 +- lib/raid6/vpermxor.uc | 7 --- lib/raid6/x86.h | 75 -------------------------- 20 files changed, 15 insertions(+), 276 deletions(-) delete mode 100644 lib/raid6/loongarch.h delete mode 100644 lib/raid6/x86.h
include/linux/raid/pq.h +0 -90
@@ -8,8 +8,6 @@#ifndef LINUX_RAID_RAID6_H #define LINUX_RAID_RAID6_H -#ifdef __KERNEL__ -#include <linux/blkdev.h> #include <linux/mm.h>
@@ -19,59 +17,6 @@ static inline void *raid6_get_zero_page(void)return page_address (ZERO_PAGE (0 )); } -#else /* ! __KERNEL__ */ -/* Used for testing in user space */ - -#include <errno.h> -#include <inttypes.h> -#include <stddef.h> -#include <string.h> -#include <sys/mman.h> -#include <sys/time.h> -#include <sys/types.h> - -/* Not standard, but glibc defines it */ -#define BITS_PER_LONG __WORDSIZE - -typedef uint8_t u8 ; -typedef uint16_t u16 ; -typedef uint32_t u32 ; -typedef uint64_t u64 ; - -#ifndef PAGE_SIZE -# define PAGE_SIZE 4096 -#endif -#ifndef PAGE_SHIFT -# define PAGE_SHIFT 12 -#endif -extern const char raid6_empty_zero_page[PAGE_SIZE ]; - -#define __init -#define __exit -#ifndef __attribute_const__ -# define __attribute_const__ __attribute__((const)) -#endif -#define noinline __attribute__((noinline)) - -#define preempt_enable () -#define preempt_disable () -#define cpu_has_feature (x) 1 -#define enable_kernel_altivec () -#define disable_kernel_altivec () - -#undef EXPORT_SYMBOL -#define EXPORT_SYMBOL (sym) -#undef EXPORT_SYMBOL_GPL -#define EXPORT_SYMBOL_GPL (sym) -#define MODULE_LICENSE (licence) -#define MODULE_DESCRIPTION (desc) -#define subsys_initcall (x) -#define module_exit (x) - -#define IS_ENABLED (x) (x) -#define CONFIG_RAID6_PQ_BENCHMARK 1 -#endif /* __KERNEL__ */ -/* Routine choices */ struct raid6_calls {void (*gen_syndrome)(int ,size_t ,void **);
@@ -165,39 +110,4 @@ extern void (*raid6_2data_recov)(int disks, size_t bytes, int faila, int failb,extern void (*raid6_datap_recov)(int disks,size_t bytes,int faila,void **ptrs); -/* Some definitions to allow code to be compiled for testing in userspace */ -#ifndef __KERNEL__ - -# define jiffies raid6_jiffies() -# define printk printf -# define pr_err (format, ...) fprintf(stderr, format, ## __VA_ARGS__) -# define pr_info (format, ...) fprintf(stdout, format, ## __VA_ARGS__) -# define GFP_KERNEL 0 -# define __get_free_pages (x, y) ((unsigned long)mmap(NULL, PAGE_SIZE << (y), \ - PROT_READ|PROT_WRITE, \ - MAP_PRIVATE|MAP_ANONYMOUS,\ - 0, 0)) -# define free_pages (x, y) munmap((void *)(x), PAGE_SIZE << (y)) - -static inline void cpu_relax (void ) -{ -/* Nothing */ -} - -#undef HZ -#define HZ 1000 -static inline uint32_t raid6_jiffies (void ) -{ -struct timeval tv; -gettimeofday (&tv,NULL ); -return tv.tv_sec*1000 + tv.tv_usec/1000 ; -} - -static inline void *raid6_get_zero_page (void ) -{ -return raid6_empty_zero_page; -} - -#endif /* ! __KERNEL__ */ -#endif /* LINUX_RAID_RAID6_H */
lib/raid6/algos.c +0 -12
@@ -12,13 +12,8 @@*/ #include <linux/raid/pq.h> -#ifndef __KERNEL__ -#include <sys/mman.h> -#include <stdio.h> -#else #include <linux/module.h> #include <linux/gfp.h> -#endif #include <kunit/visibility.h> struct raid6_calls raid6_call;
@@ -123,14 +118,7 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = { };EXPORT_SYMBOL_IF_KUNIT (raid6_recov_algos); -#ifdef __KERNEL__#define RAID6_TIME_JIFFIES_LG2 4 -#else -/* Need more time to be stable in userspace */ -#define RAID6_TIME_JIFFIES_LG2 9 -#define time_before (x, y) ((x) < (y)) -#endif -#define RAID6_TEST_DISKS 8#define RAID6_TEST_DISKS_ORDER 3
lib/raid6/altivec.uc +2 -8
@@ -27,10 +27,8 @@ #ifdef CONFIG_ALTIVEC #include <altivec.h> -#ifdef __KERNEL__ -# include <asm/cputable.h> -# include <asm/switch_to.h> -#endif /* __KERNEL__ */ +#include <asm/cputable.h> +#include <asm/switch_to.h> /* * This is the C data type to use. We use a vector of
@@ -113,11 +111,7 @@ int raid6_have_altivec(void); int raid6_have_altivec(void) { /* This assumes either all CPUs have Altivec or none does */ -# ifdef __KERNEL__ return cpu_has_feature(CPU_FTR_ALTIVEC); -# else - return 1; -# endif } #endif
lib/raid6/avx2.c +1 -1
@@ -14,7 +14,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static const struct raid6_avx2_constants { u64 x1d[4];
lib/raid6/avx512.c +1 -1
@@ -18,7 +18,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static const struct raid6_avx512_constants { u64 x1d[8];
lib/raid6/loongarch.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Copyright (C) 2023 WANG Xuerui <[email protected]> -* -* raid6/loongarch.h -* -* Definitions common to LoongArch RAID-6 code only -*/ - -#ifndef _LIB_RAID6_LOONGARCH_H -#define _LIB_RAID6_LOONGARCH_H - -#ifdef __KERNEL__ - -#include <asm/cpu-features.h> -#include <asm/fpu.h> - -#else /* for user-space testing */ - -#include <sys/auxv.h> - -/* have to supply these defines for glibc 2.37- and musl */ -#ifndef HWCAP_LOONGARCH_LSX -#define HWCAP_LOONGARCH_LSX (1 << 4) -#endif -#ifndef HWCAP_LOONGARCH_LASX -#define HWCAP_LOONGARCH_LASX (1 << 5) -#endif - -#define kernel_fpu_begin () -#define kernel_fpu_end () - -#define cpu_has_lsx (getauxval(AT_HWCAP) & HWCAP_LOONGARCH_LSX) -#define cpu_has_lasx (getauxval(AT_HWCAP) & HWCAP_LOONGARCH_LASX) - -#endif /* __KERNEL__ */ - -#endif /* _LIB_RAID6_LOONGARCH_H */
lib/raid6/loongarch_simd.c +2 -1
@@ -10,7 +10,8 @@*/ #include <linux/raid/pq.h> -#include "loongarch.h" +#include <asm/cpu-features.h> +#include <asm/fpu.h> /* * The vector algorithms are currently priority 0, which means the generic
lib/raid6/mktables.c +0 -14
@@ -56,9 +56,7 @@ int main(int argc, char *argv[])uint8_t v;uint8_t exptbl[256 ], invtbl[256 ]; -printf ("#ifdef __KERNEL__\n" );printf ("#include <linux/export.h>\n" ); -printf ("#endif\n" );printf ("#include <linux/raid/pq.h>\n" );/* Compute multiplication table */
@@ -76,9 +74,7 @@ int main(int argc, char *argv[])printf ("\t},\n" ); }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_gfmul);\n" ); -printf ("#endif\n" );/* Compute vector multiplication table */ printf("\nconst u8 __attribute__((aligned(256)))\n"
@@ -101,9 +97,7 @@ int main(int argc, char *argv[])printf ("\t},\n" ); }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_vgfmul);\n" ); -printf ("#endif\n" );/* Compute power-of-2 table (exponent) */ v =1 ;
@@ -120,9 +114,7 @@ int main(int argc, char *argv[]) } }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_gfexp);\n" ); -printf ("#endif\n" );/* Compute log-of-2 table */ printf("\nconst u8 __attribute__((aligned(256)))\n"
@@ -140,9 +132,7 @@ int main(int argc, char *argv[]) } }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_gflog);\n" ); -printf ("#endif\n" );/* Compute inverse table x^-1 == x^254 */ printf("\nconst u8 __attribute__((aligned(256)))\n"
@@ -155,9 +145,7 @@ int main(int argc, char *argv[]) } }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_gfinv);\n" ); -printf ("#endif\n" );/* Compute inv(2^x + 1) (exponent-xor-inverse) table */ printf("\nconst u8 __attribute__((aligned(256)))\n"
@@ -169,9 +157,7 @@ int main(int argc, char *argv[]) (j == 7) ? '\n' : ' '); }printf ("};\n" ); -printf ("#ifdef __KERNEL__\n" );printf ("EXPORT_SYMBOL(raid6_gfexi);\n" ); -printf ("#endif\n" );return 0 ; }
lib/raid6/mmx.c +1 -1
@@ -14,7 +14,7 @@ #ifdef CONFIG_X86_32 #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> /* Shared with raid6/sse1.c */ const struct raid6_mmx_constants {
lib/raid6/neon.c +0 -6
@@ -6,13 +6,7 @@*/ #include <linux/raid/pq.h> - -#ifdef __KERNEL__#include <asm/simd.h> -#else -#define scoped_ksimd () -#define cpu_has_neon () (1) -#endif /* * There are 2 reasons these wrappers are kept in a separate compilation unit
lib/raid6/recov_avx2.c +1 -1
@@ -5,7 +5,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static int raid6_has_avx2 (void ) {
lib/raid6/recov_avx512.c +1 -1
@@ -7,7 +7,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static int raid6_has_avx512 (void ) {
lib/raid6/recov_loongarch_simd.c +2 -1
@@ -11,7 +11,8 @@*/ #include <linux/raid/pq.h> -#include "loongarch.h" +#include <asm/cpu-features.h> +#include <asm/fpu.h> /* * Unlike with the syndrome calculation algorithms, there's no boot-time
lib/raid6/recov_neon.c +0 -6
@@ -5,14 +5,8 @@*/ #include <linux/raid/pq.h> - -#ifdef __KERNEL__#include <asm/simd.h> #include "neon.h" -#else -#define scoped_ksimd () -#define cpu_has_neon () (1) -#endif static int raid6_has_neon (void ) {
lib/raid6/recov_ssse3.c +1 -1
@@ -4,7 +4,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static int raid6_has_ssse3 (void ) {
lib/raid6/rvv.h +1 -10
@@ -7,17 +7,8 @@* Definitions for RISC-V RAID-6 code */ -#ifdef __KERNEL__ -#include <asm/vector.h> -#else -#define kernel_vector_begin () -#define kernel_vector_end () -#include <sys/auxv.h> -#include <asm/hwcap.h> -#define has_vector () (getauxval(AT_HWCAP) & COMPAT_HWCAP_ISA_V) -#endif -#include <linux/raid/pq.h> +#include <asm/vector.h> static int rvv_has_vector (void ) {
lib/raid6/sse1.c +1 -1
@@ -19,7 +19,7 @@ #ifdef CONFIG_X86_32 #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> /* Defined in raid6/mmx.c */ extern const struct raid6_mmx_constants {
lib/raid6/sse2.c +1 -1
@@ -13,7 +13,7 @@*/ #include <linux/raid/pq.h> -#include "x86.h" +#include <asm/fpu/api.h> static const struct raid6_sse_constants { u64 x1d[2];
lib/raid6/vpermxor.uc +0 -7
@@ -25,10 +25,8 @@ #include <altivec.h> #include <asm/ppc-opcode.h> -#ifdef __KERNEL__ #include <asm/cputable.h> #include <asm/switch_to.h> -#endif typedef vector unsigned char unative_t; #define NSIZE sizeof(unative_t)
@@ -85,13 +83,8 @@ int raid6_have_altivec_vpermxor(void); int raid6_have_altivec_vpermxor(void) { /* Check if arch has both altivec and the vpermxor instructions */ -# ifdef __KERNEL__ return (cpu_has_feature(CPU_FTR_ALTIVEC_COMP) && cpu_has_feature(CPU_FTR_ARCH_207S)); -# else - return 1; -#endif - } #endif
lib/raid6/x86.h deleted +0 -75
75 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 3/18 raid6: move to lib/raid/
In reply to Christoph HellwigMove the raid6 code to live in lib/raid/ with the XOR code, and change the internal organization so that each architecture has a subdirectory similar to the CRC, crypto and XOR libraries, and fix up the Makefile to only build files actually needed.
Also move the kunit test case from the history test/ subdirectory to tests/ and use the normal naming scheme for it.
---
MAINTAINERS | 2 +-
lib/Kconfig | 22 ----
lib/Makefile | 1 -
lib/raid/Kconfig | 22 ++++
lib/raid/Makefile | 2 +-
lib/{ => raid}/raid6/.gitignore | 0
lib/raid/raid6/Makefile | 122 ++++++++++++++++++
lib/{ => raid}/raid6/algos.c | 0
lib/{raid6 => raid/raid6/arm}/neon.c | 0
lib/{raid6 => raid/raid6/arm}/neon.h | 0
lib/{raid6 => raid/raid6/arm}/neon.uc | 2 +-
lib/{raid6 => raid/raid6/arm}/recov_neon.c | 2 +-
.../raid6/arm}/recov_neon_inner.c | 2 +-
lib/{ => raid}/raid6/int.uc | 0
.../raid6/loongarch}/loongarch_simd.c | 0
.../raid6/loongarch}/recov_loongarch_simd.c | 0
lib/{ => raid}/raid6/mktables.c | 0
lib/{raid6 => raid/raid6/powerpc}/altivec.uc | 4 -
lib/{raid6 => raid/raid6/powerpc}/vpermxor.uc | 3 -
lib/{ => raid}/raid6/recov.c | 0
lib/{raid6 => raid/raid6/riscv}/recov_rvv.c | 0
lib/{raid6 => raid/raid6/riscv}/rvv.c | 0
lib/{raid6 => raid/raid6/riscv}/rvv.h | 0
lib/{raid6 => raid/raid6/s390}/recov_s390xc.c | 0
lib/{raid6 => raid/raid6/s390}/s390vx.uc | 0
lib/{raid6/test => raid/raid6/tests}/Makefile | 2 -
.../test.c => raid/raid6/tests/raid6_kunit.c} | 0
lib/{ => raid}/raid6/unroll.awk | 0
lib/{raid6 => raid/raid6/x86}/avx2.c | 0
lib/{raid6 => raid/raid6/x86}/avx512.c | 0
lib/{raid6 => raid/raid6/x86}/mmx.c | 4 -
lib/{raid6 => raid/raid6/x86}/recov_avx2.c | 0
lib/{raid6 => raid/raid6/x86}/recov_avx512.c | 0
lib/{raid6 => raid/raid6/x86}/recov_ssse3.c | 0
lib/{raid6 => raid/raid6/x86}/sse1.c | 4 -
lib/{raid6 => raid/raid6/x86}/sse2.c | 0
lib/raid6/Makefile | 83 ------------
lib/raid6/test/.gitignore | 3 -
38 files changed, 149 insertions(+), 131 deletions(-)
rename lib/{ => raid}/raid6/.gitignore (100%)
create mode 100644 lib/raid/raid6/Makefile
rename lib/{ => raid}/raid6/algos.c (100%)
rename lib/{raid6 => raid/raid6/arm}/neon.c (100%)
rename lib/{raid6 => raid/raid6/arm}/neon.h (100%)
rename lib/{raid6 => raid/raid6/arm}/neon.uc (99%)
rename lib/{raid6 => raid/raid6/arm}/recov_neon.c (99%)
rename lib/{raid6 => raid/raid6/arm}/recov_neon_inner.c (99%)
rename lib/{ => raid}/raid6/int.uc (100%)
rename lib/{raid6 => raid/raid6/loongarch}/loongarch_simd.c (100%)
rename lib/{raid6 => raid/raid6/loongarch}/recov_loongarch_simd.c (100%)
rename lib/{ => raid}/raid6/mktables.c (100%)
rename lib/{raid6 => raid/raid6/powerpc}/altivec.uc (98%)
rename lib/{raid6 => raid/raid6/powerpc}/vpermxor.uc (98%)
rename lib/{ => raid}/raid6/recov.c (100%)
rename lib/{raid6 => raid/raid6/riscv}/recov_rvv.c (100%)
rename lib/{raid6 => raid/raid6/riscv}/rvv.c (100%)
rename lib/{raid6 => raid/raid6/riscv}/rvv.h (100%)
rename lib/{raid6 => raid/raid6/s390}/recov_s390xc.c (100%)
rename lib/{raid6 => raid/raid6/s390}/s390vx.uc (100%)
rename lib/{raid6/test => raid/raid6/tests}/Makefile (77%)
rename lib/{raid6/test/test.c => raid/raid6/tests/raid6_kunit.c} (100%)
rename lib/{ => raid}/raid6/unroll.awk (100%)
rename lib/{raid6 => raid/raid6/x86}/avx2.c (100%)
rename lib/{raid6 => raid/raid6/x86}/avx512.c (100%)
rename lib/{raid6 => raid/raid6/x86}/mmx.c (99%)
rename lib/{raid6 => raid/raid6/x86}/recov_avx2.c (100%)
rename lib/{raid6 => raid/raid6/x86}/recov_avx512.c (100%)
rename lib/{raid6 => raid/raid6/x86}/recov_ssse3.c (100%)
rename lib/{raid6 => raid/raid6/x86}/sse1.c (99%)
rename lib/{raid6 => raid/raid6/x86}/sse2.c (100%)
delete mode 100644 lib/raid6/Makefile
delete mode 100644 lib/raid6/test/.gitignoreMAINTAINERS +1 -1
@@ -24821,7 +24821,7 @@ F: drivers/md/md* F: drivers/md/raid* F: include/linux/raid/ F: include/uapi/linux/raid/ -F: lib/raid6/ +F: lib/raid/raid6/ SOLIDRUN CLEARFOG SUPPORT M: Russell King <[email protected]>
lib/Kconfig +0 -22
@@ -8,28 +8,6 @@ config BINARY_PRINTF menu "Library routines" -config RAID6_PQ - tristate - -config RAID6_PQ_KUNIT_TEST - tristate "KUnit tests for RAID6 PQ functions" if !KUNIT_ALL_TESTS - depends on KUNIT - depends on RAID6_PQ - default KUNIT_ALL_TESTS - help - Unit tests for the RAID6 PQ library functions. - - This is intended to help people writing architecture-specific - optimized versions. If unsure, say N. - -config RAID6_PQ_BENCHMARK - bool "Automatically choose fastest RAID6 PQ functions" - depends on RAID6_PQ - default y - help - Benchmark all available RAID6 PQ functions on init and choose the - fastest one. - config LINEAR_RANGES tristate
lib/Makefile +0 -1
@@ -167,7 +167,6 @@ obj-$(CONFIG_LZ4_DECOMPRESS) += lz4/ obj-$(CONFIG_ZSTD_COMPRESS) += zstd/ obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd/ obj-$(CONFIG_XZ_DEC) += xz/ -obj-$(CONFIG_RAID6_PQ) += raid6/ lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
lib/raid/Kconfig +22 -0
@@ -28,3 +28,25 @@ config XOR_KUNIT_TEST This is intended to help people writing architecture-specific optimized versions. If unsure, say N. + +config RAID6_PQ + tristate + +config RAID6_PQ_KUNIT_TEST + tristate "KUnit tests for RAID6 PQ functions" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on RAID6_PQ + default KUNIT_ALL_TESTS + help + Unit tests for the RAID6 PQ library functions. + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N. + +config RAID6_PQ_BENCHMARK + bool "Automatically choose fastest RAID6 PQ functions" + depends on RAID6_PQ + default y + help + Benchmark all available RAID6 PQ functions on init and choose the + fastest one.
lib/raid/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y += xor/ +obj-y += xor/ raid6/
lib/raid/raid6/.gitignore renamed from lib/raid6/.gitignore +0 -0
lib/raid/raid6/Makefile new file +122 -0
122 lines not on this page · raw message
lib/raid/raid6/algos.c renamed from lib/raid6/algos.c +0 -0
lib/raid/raid6/arm/neon.c renamed from lib/raid6/neon.c +0 -0
lib/raid/raid6/arm/neon.h renamed from lib/raid6/neon.h +0 -0
lib/raid/raid6/arm/neon.uc renamed from lib/raid6/neon.uc +1 -1
@@ -25,7 +25,7 @@ */ #include <arm_neon.h> -#include "neon.h" +#include "arm/neon.h" typedef uint8x16_t unative_t;
lib/raid/raid6/arm/recov_neon.c renamed from lib/raid6/recov_neon.c +1 -1
@@ -6,7 +6,7 @@#include <linux/raid/pq.h> #include <asm/simd.h> -#include "neon.h" +#include "arm/neon.h" static int raid6_has_neon (void ) {
lib/raid/raid6/arm/recov_neon_inner.c renamed from lib/raid6/recov_neon_inner.c +1 -1
@@ -5,7 +5,7 @@*/ #include <arm_neon.h> -#include "neon.h" +#include "arm/neon.h" #ifdef CONFIG_ARM /*
lib/raid/raid6/int.uc renamed from lib/raid6/int.uc +0 -0
lib/raid/raid6/loongarch/loongarch_simd.c renamed from lib/raid6/loongarch_simd.c +0 -0
lib/raid/raid6/loongarch/recov_loongarch_simd.c renamed from lib/raid6/recov_loongarch_simd.c +0 -0
lib/raid/raid6/mktables.c renamed from lib/raid6/mktables.c +0 -0
lib/raid/raid6/powerpc/altivec.uc renamed from lib/raid6/altivec.uc +0 -4
@@ -24,8 +24,6 @@ #include <linux/raid/pq.h> -#ifdef CONFIG_ALTIVEC - #include <altivec.h> #include <asm/cputable.h> #include <asm/switch_to.h>
@@ -122,5 +120,3 @@ const struct raid6_calls raid6_altivec$# = { "altivecx$#", 0 }; - -#endif /* CONFIG_ALTIVEC */
lib/raid/raid6/powerpc/vpermxor.uc renamed from lib/raid6/vpermxor.uc +0 -3
@@ -21,8 +21,6 @@ */ #include <linux/raid/pq.h> -#ifdef CONFIG_ALTIVEC - #include <altivec.h> #include <asm/ppc-opcode.h> #include <asm/cputable.h>
@@ -95,4 +93,3 @@ const struct raid6_calls raid6_vpermxor$# = { "vpermxor$#", 0 }; -#endif
lib/raid/raid6/recov.c renamed from lib/raid6/recov.c +0 -0
lib/raid/raid6/riscv/recov_rvv.c renamed from lib/raid6/recov_rvv.c +0 -0
lib/raid/raid6/riscv/rvv.c renamed from lib/raid6/rvv.c +0 -0
lib/raid/raid6/riscv/rvv.h renamed from lib/raid6/rvv.h +0 -0
lib/raid/raid6/s390/recov_s390xc.c renamed from lib/raid6/recov_s390xc.c +0 -0
lib/raid/raid6/s390/s390vx.uc renamed from lib/raid6/s390vx.uc +0 -0
lib/raid/raid6/tests/Makefile renamed from lib/raid6/test/Makefile +0 -2
@@ -1,5 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_RAID6_PQ_KUNIT_TEST) += raid6_kunit.o - -raid6_kunit-y += test.o
lib/raid/raid6/tests/raid6_kunit.c renamed from lib/raid6/test/test.c +0 -0
lib/raid/raid6/unroll.awk renamed from lib/raid6/unroll.awk +0 -0
lib/raid/raid6/x86/avx2.c renamed from lib/raid6/avx2.c +0 -0
lib/raid/raid6/x86/avx512.c renamed from lib/raid6/avx512.c +0 -0
lib/raid/raid6/x86/mmx.c renamed from lib/raid6/mmx.c +0 -4
@@ -11,8 +11,6 @@* MMX implementation of RAID-6 syndrome functions */ -#ifdef CONFIG_X86_32 -#include <linux/raid/pq.h> #include <asm/fpu/api.h>
@@ -135,5 +133,3 @@ const struct raid6_calls raid6_mmxx2 = {"mmxx2" , 0 }; - -#endif
lib/raid/raid6/x86/recov_avx2.c renamed from lib/raid6/recov_avx2.c +0 -0
lib/raid/raid6/x86/recov_avx512.c renamed from lib/raid6/recov_avx512.c +0 -0
lib/raid/raid6/x86/recov_ssse3.c renamed from lib/raid6/recov_ssse3.c +0 -0
lib/raid/raid6/x86/sse1.c renamed from lib/raid6/sse1.c +0 -4
@@ -16,8 +16,6 @@* worthwhile as a separate implementation. */ -#ifdef CONFIG_X86_32 -#include <linux/raid/pq.h> #include <asm/fpu/api.h>
@@ -155,5 +153,3 @@ const struct raid6_calls raid6_sse1x2 = {"sse1x2" , 1 /* Has cache hints */ }; - -#endif
lib/raid/raid6/x86/sse2.c renamed from lib/raid6/sse2.c +0 -0
lib/raid6/Makefile deleted +0 -83
83 lines not on this page · raw message
lib/raid6/test/.gitignore deleted +0 -3
@@ -1,3 +0,0 @@ -/int.uc -/neon.uc -/raid6test
Signature · 1 line
2.53.0
PATCH 4/18 raid6: remove unused defines in pq.h
In reply to Christoph HellwigThese are not used anywhere in the kernel.
--- include/linux/raid/pq.h | 6 ------ 1 file changed, 6 deletions(-)
include/linux/raid/pq.h +0 -6
@@ -90,12 +90,6 @@ extern const struct raid6_calls raid6_neonx8;extern const struct raid6_calls *const raid6_algos[];extern const struct raid6_recov_calls *const raid6_recov_algos[]; -/* Return values from chk_syndrome */ -#define RAID6_OK 0 -#define RAID6_P_BAD 1 -#define RAID6_Q_BAD 2 -#define RAID6_PQ_BAD 3 -/* Galois field tables */ extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256))); extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256)));
Signature · 1 line
2.53.0
PATCH 5/18 raid6: remove raid6_get_zero_page
In reply to Christoph HellwigJust open code it as in other places in the kernel.
--- crypto/async_tx/async_pq.c | 2 +- crypto/async_tx/async_raid6_recov.c | 4 ++-- include/linux/raid/pq.h | 6 ------ lib/raid/raid6/arm/recov_neon.c | 6 +++--- lib/raid/raid6/loongarch/recov_loongarch_simd.c | 12 ++++++------ lib/raid/raid6/recov.c | 6 +++--- lib/raid/raid6/riscv/recov_rvv.c | 6 +++--- lib/raid/raid6/s390/recov_s390xc.c | 6 +++--- lib/raid/raid6/x86/recov_avx2.c | 6 +++--- lib/raid/raid6/x86/recov_avx512.c | 6 +++--- lib/raid/raid6/x86/recov_ssse3.c | 6 +++--- 11 files changed, 30 insertions(+), 36 deletions(-)
crypto/async_tx/async_pq.c +1 -1
@@ -119,7 +119,7 @@ do_sync_gen_syndrome(struct page **blocks, unsigned int *offsets, int disks,for (i =0 ; i < disks; i++) {if (blocks[i] ==NULL ) {BUG_ON (i > disks -3 );/* P or Q can't be zero */ - srcs[i] =raid6_get_zero_page (); + srcs[i] =page_address (ZERO_PAGE (0 )); }else { srcs[i] =page_address (blocks[i]) + offsets[i];
crypto/async_tx/async_raid6_recov.c +2 -2
@@ -414,7 +414,7 @@ async_raid6_2data_recov(int disks, size_t bytes, int faila, int failb,async_tx_quiesce (&submit->depend_tx);for (i =0 ; i < disks; i++)if (blocks[i] ==NULL ) - ptrs[i] =raid6_get_zero_page (); + ptrs[i] =page_address (ZERO_PAGE (0 ));else ptrs[i] =page_address (blocks[i]) + offs[i];
@@ -497,7 +497,7 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,async_tx_quiesce (&submit->depend_tx);for (i =0 ; i < disks; i++)if (blocks[i] ==NULL ) - ptrs[i] =raid6_get_zero_page (); + ptrs[i] =page_address (ZERO_PAGE (0 ));else ptrs[i] =page_address (blocks[i]) + offs[i];
include/linux/raid/pq.h +0 -6
@@ -11,12 +11,6 @@#include <linux/blkdev.h> #include <linux/mm.h> -/* This should be const but the raid6 code is too convoluted for that. */ -static inline void *raid6_get_zero_page (void ) -{ -return page_address (ZERO_PAGE (0 )); -} -/* Routine choices */ struct raid6_calls {void (*gen_syndrome)(int ,size_t ,void **);
lib/raid/raid6/arm/recov_neon.c +3 -3
@@ -29,10 +29,10 @@ static void raid6_2data_recov_neon(int disks, size_t bytes, int faila,* delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -66,7 +66,7 @@ static void raid6_datap_recov_neon(int disks, size_t bytes, int faila,* Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/loongarch/recov_loongarch_simd.c +6 -6
@@ -43,10 +43,10 @@ static void raid6_2data_recov_lsx(int disks, size_t bytes, int faila,* delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -198,7 +198,7 @@ static void raid6_datap_recov_lsx(int disks, size_t bytes, int faila,* Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -317,10 +317,10 @@ static void raid6_2data_recov_lasx(int disks, size_t bytes, int faila,* delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -437,7 +437,7 @@ static void raid6_datap_recov_lasx(int disks, size_t bytes, int faila,* Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/recov.c +3 -3
@@ -31,10 +31,10 @@ static void raid6_2data_recov_intx1(int disks, size_t bytes, int faila,Use the dead data pages as temporary storage for delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -72,7 +72,7 @@ static void raid6_datap_recov_intx1(int disks, size_t bytes, int faila,/* Compute syndrome with zero for the missing data page Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/riscv/recov_rvv.c +3 -3
@@ -158,10 +158,10 @@ static void raid6_2data_recov_rvv(int disks, size_t bytes, int faila,* delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -196,7 +196,7 @@ static void raid6_datap_recov_rvv(int disks, size_t bytes, int faila,* Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/s390/recov_s390xc.c +3 -3
@@ -34,10 +34,10 @@ static void raid6_2data_recov_s390xc(int disks, size_t bytes, int faila,Use the dead data pages as temporary storage for delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -81,7 +81,7 @@ static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila,/* Compute syndrome with zero for the missing data page Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/x86/recov_avx2.c +3 -3
@@ -28,10 +28,10 @@ static void raid6_2data_recov_avx2(int disks, size_t bytes, int faila,Use the dead data pages as temporary storage for delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -196,7 +196,7 @@ static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,/* Compute syndrome with zero for the missing data page Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/x86/recov_avx512.c +3 -3
@@ -37,10 +37,10 @@ static void raid6_2data_recov_avx512(int disks, size_t bytes, int faila,*/ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -238,7 +238,7 @@ static void raid6_datap_recov_avx512(int disks, size_t bytes, int faila,*/ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
lib/raid/raid6/x86/recov_ssse3.c +3 -3
@@ -30,10 +30,10 @@ static void raid6_2data_recov_ssse3(int disks, size_t bytes, int faila,Use the dead data pages as temporary storage for delta p and delta q */ dp = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-2 ] = dp; dq = (u8 *)ptrs[failb]; - ptrs[failb] =raid6_get_zero_page (); + ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
@@ -203,7 +203,7 @@ static void raid6_datap_recov_ssse3(int disks, size_t bytes, int faila,/* Compute syndrome with zero for the missing data page Use the dead data page as temporary storage for delta q */ dq = (u8 *)ptrs[faila]; - ptrs[faila] =raid6_get_zero_page (); + ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; raid6_call.gen_syndrome (disks, bytes, ptrs);
Signature · 1 line
2.53.0
PATCH 6/18 raid6: use named initializers for struct raid6_calls
In reply to Christoph Hellwig--- lib/raid/raid6/arm/neon.c | 9 +++---- lib/raid/raid6/int.uc | 8 +++--- lib/raid/raid6/loongarch/loongarch_simd.c | 18 ++++++------- lib/raid/raid6/powerpc/altivec.uc | 8 +++--- lib/raid/raid6/powerpc/vpermxor.uc | 8 +++--- lib/raid/raid6/riscv/rvv.h | 9 +++---- lib/raid/raid6/s390/s390vx.uc | 10 +++---- lib/raid/raid6/x86/avx2.c | 33 ++++++++++++----------- lib/raid/raid6/x86/avx512.c | 33 ++++++++++++----------- lib/raid/raid6/x86/mmx.c | 16 +++++------ lib/raid/raid6/x86/sse1.c | 18 ++++++------- lib/raid/raid6/x86/sse2.c | 30 ++++++++++----------- 12 files changed, 95 insertions(+), 105 deletions(-)
lib/raid/raid6/arm/neon.c +4 -5
@@ -40,11 +40,10 @@ start, stop, (unsigned long)bytes, ptrs);\ } \ struct raid6_calls const raid6_neonx ## _n = { \ - raid6_neon ## _n ## _gen_syndrome, \ - raid6_neon ## _n ## _xor_syndrome, \ - raid6_have_neon, \ - "neonx" #_n, \ -0 \ + .gen_syndrome = raid6_neon ## _n ## _gen_syndrome, \ + .xor_syndrome = raid6_neon ## _n ## _xor_syndrome, \ + .valid = raid6_have_neon, \ + .name = "neonx" #_n, \ }static int raid6_have_neon (void )
lib/raid/raid6/int.uc +3 -5
@@ -139,9 +139,7 @@ static void raid6_int$#_xor_syndrome(int disks, int start, int stop, } const struct raid6_calls raid6_intx$# = { - raid6_int$#_gen_syndrome, - raid6_int$#_xor_syndrome, - NULL, /* always valid */ - "int" NSTRING "x$#", - 0 + .gen_syndrome = raid6_int$#_gen_syndrome, + .xor_syndrome = raid6_int$#_xor_syndrome, + .name = "int" NSTRING "x$#", };
lib/raid/raid6/loongarch/loongarch_simd.c +8 -10
@@ -244,11 +244,10 @@ static void raid6_lsx_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_lsx = { - raid6_lsx_gen_syndrome, - raid6_lsx_xor_syndrome, - raid6_has_lsx, -"lsx" , - .priority =0 /* see the comment near the top of the file for reason */ + .gen_syndrome = raid6_lsx_gen_syndrome, + .xor_syndrome = raid6_lsx_xor_syndrome, + .valid = raid6_has_lsx, + .name ="lsx" , };#undef NSIZE
@@ -413,11 +412,10 @@ static void raid6_lasx_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_lasx = { - raid6_lasx_gen_syndrome, - raid6_lasx_xor_syndrome, - raid6_has_lasx, -"lasx" , - .priority =0 /* see the comment near the top of the file for reason */ + .gen_syndrome = raid6_lasx_gen_syndrome, + .xor_syndrome = raid6_lasx_xor_syndrome, + .valid = raid6_has_lasx, + .name ="lasx" , };#undef NSIZE#endif /* CONFIG_CPU_HAS_LASX */
lib/raid/raid6/powerpc/altivec.uc +3 -5
@@ -114,9 +114,7 @@ int raid6_have_altivec(void) #endif const struct raid6_calls raid6_altivec$# = { - raid6_altivec$#_gen_syndrome, - NULL, /* XOR not yet implemented */ - raid6_have_altivec, - "altivecx$#", - 0 + .gen_syndrome = raid6_altivec$#_gen_syndrome, + .valid = raid6_have_altivec, + .name = "altivecx$#", };
lib/raid/raid6/powerpc/vpermxor.uc +3 -5
@@ -87,9 +87,7 @@ int raid6_have_altivec_vpermxor(void) #endif const struct raid6_calls raid6_vpermxor$# = { - raid6_vpermxor$#_gen_syndrome, - NULL, - raid6_have_altivec_vpermxor, - "vpermxor$#", - 0 + .gen_syndrome = raid6_vpermxor$#_gen_syndrome, + .valid = raid6_have_altivec_vpermxor, + .name = "vpermxor$#", };
lib/raid/raid6/riscv/rvv.h +4 -5
@@ -39,9 +39,8 @@ static int rvv_has_vector(void)kernel_vector_end (); \ } \ struct raid6_calls const raid6_rvvx ## _n = { \ - raid6_rvv ## _n ## _gen_syndrome, \ - raid6_rvv ## _n ## _xor_syndrome, \ - rvv_has_vector, \ - "rvvx" #_n, \ -0 \ + .gen_syndrome = raid6_rvv ## _n ## _gen_syndrome, \ + .xor_syndrome = raid6_rvv ## _n ## _xor_syndrome, \ + .valid = rvv_has_vector, \ + .name = "rvvx" #_n, \ }
lib/raid/raid6/s390/s390vx.uc +5 -5
@@ -127,9 +127,9 @@ static int raid6_s390vx$#_valid(void) } const struct raid6_calls raid6_s390vx$# = { - raid6_s390vx$#_gen_syndrome, - raid6_s390vx$#_xor_syndrome, - raid6_s390vx$#_valid, - "vx128x$#", - 1 + .gen_syndrome = raid6_s390vx$#_gen_syndrome, + .xor_syndrome = raid6_s390vx$#_xor_syndrome, + .valid = raid6_s390vx$#_valid, + .name = "vx128x$#", + .priority = 1, };
lib/raid/raid6/x86/avx2.c +18 -15
@@ -128,11 +128,12 @@ static void raid6_avx21_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_avx2x1 = { - raid6_avx21_gen_syndrome, - raid6_avx21_xor_syndrome, - raid6_have_avx2, -"avx2x1" , - .priority =2 /* Prefer AVX2 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx21_gen_syndrome, + .xor_syndrome = raid6_avx21_xor_syndrome, + .valid = raid6_have_avx2, + .name ="avx2x1" , +/* Prefer AVX2 over priority 1 (SSE2 and others) */ + .priority =2 , };/*
@@ -258,11 +259,12 @@ static void raid6_avx22_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_avx2x2 = { - raid6_avx22_gen_syndrome, - raid6_avx22_xor_syndrome, - raid6_have_avx2, -"avx2x2" , - .priority =2 /* Prefer AVX2 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx22_gen_syndrome, + .xor_syndrome = raid6_avx22_xor_syndrome, + .valid = raid6_have_avx2, + .name ="avx2x2" , +/* Prefer AVX2 over priority 1 (SSE2 and others) */ + .priority =2 , };#ifdef CONFIG_X86_64
@@ -461,10 +463,11 @@ static void raid6_avx24_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_avx2x4 = { - raid6_avx24_gen_syndrome, - raid6_avx24_xor_syndrome, - raid6_have_avx2, -"avx2x4" , - .priority =2 /* Prefer AVX2 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx24_gen_syndrome, + .xor_syndrome = raid6_avx24_xor_syndrome, + .valid = raid6_have_avx2, + .name ="avx2x4" , +/* Prefer AVX2 over priority 1 (SSE2 and others) */ + .priority =2 , };#endif /* CONFIG_X86_64 */
lib/raid/raid6/x86/avx512.c +18 -15
@@ -156,11 +156,12 @@ static void raid6_avx5121_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_avx512x1 = { - raid6_avx5121_gen_syndrome, - raid6_avx5121_xor_syndrome, - raid6_have_avx512, -"avx512x1" , - .priority =2 /* Prefer AVX512 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx5121_gen_syndrome, + .xor_syndrome = raid6_avx5121_xor_syndrome, + .valid = raid6_have_avx512, + .name ="avx512x1" , +/* Prefer AVX512 over priority 1 (SSE2 and others) */ + .priority =2 , };/*
@@ -313,11 +314,12 @@ static void raid6_avx5122_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_avx512x2 = { - raid6_avx5122_gen_syndrome, - raid6_avx5122_xor_syndrome, - raid6_have_avx512, -"avx512x2" , - .priority =2 /* Prefer AVX512 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx5122_gen_syndrome, + .xor_syndrome = raid6_avx5122_xor_syndrome, + .valid = raid6_have_avx512, + .name ="avx512x2" , +/* Prefer AVX512 over priority 1 (SSE2 and others) */ + .priority =2 , };#ifdef CONFIG_X86_64
@@ -551,10 +553,11 @@ static void raid6_avx5124_xor_syndrome(int disks, int start, int stop, kernel_fpu_end(); }const struct raid6_calls raid6_avx512x4 = { - raid6_avx5124_gen_syndrome, - raid6_avx5124_xor_syndrome, - raid6_have_avx512, -"avx512x4" , - .priority =2 /* Prefer AVX512 over priority 1 (SSE2 and others) */ + .gen_syndrome = raid6_avx5124_gen_syndrome, + .xor_syndrome = raid6_avx5124_xor_syndrome, + .valid = raid6_have_avx512, + .name ="avx512x4" , +/* Prefer AVX512 over priority 1 (SSE2 and others) */ + .priority =2 , };#endif
lib/raid/raid6/x86/mmx.c +6 -10
@@ -68,11 +68,9 @@ static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs) }const struct raid6_calls raid6_mmxx1 = { - raid6_mmx1_gen_syndrome, -NULL ,/* XOR not yet implemented */ - raid6_have_mmx, -"mmxx1" , -0 + .gen_syndrome = raid6_mmx1_gen_syndrome, + .valid = raid6_have_mmx, + .name ="mmxx1" , };/*
@@ -127,9 +125,7 @@ static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs) }const struct raid6_calls raid6_mmxx2 = { - raid6_mmx2_gen_syndrome, -NULL ,/* XOR not yet implemented */ - raid6_have_mmx, -"mmxx2" , -0 + .gen_syndrome = raid6_mmx2_gen_syndrome, + .valid = raid6_have_mmx, + .name ="mmxx2" , };
lib/raid/raid6/x86/sse1.c +8 -10
@@ -84,11 +84,10 @@ static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs) }const struct raid6_calls raid6_sse1x1 = { - raid6_sse11_gen_syndrome, -NULL ,/* XOR not yet implemented */ - raid6_have_sse1_or_mmxext, -"sse1x1" , -1 /* Has cache hints */ + .gen_syndrome = raid6_sse11_gen_syndrome, + .valid = raid6_have_sse1_or_mmxext, + .name ="sse1x1" , + .priority =1 ,/* Has cache hints */ };/*
@@ -147,9 +146,8 @@ static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs) }const struct raid6_calls raid6_sse1x2 = { - raid6_sse12_gen_syndrome, -NULL ,/* XOR not yet implemented */ - raid6_have_sse1_or_mmxext, -"sse1x2" , -1 /* Has cache hints */ + .gen_syndrome = raid6_sse12_gen_syndrome, + .valid = raid6_have_sse1_or_mmxext, + .name ="sse1x2" , + .priority =1 ,/* Has cache hints */ };
lib/raid/raid6/x86/sse2.c +15 -15
@@ -133,11 +133,11 @@ static void raid6_sse21_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_sse2x1 = { - raid6_sse21_gen_syndrome, - raid6_sse21_xor_syndrome, - raid6_have_sse2, -"sse2x1" , -1 /* Has cache hints */ + .gen_syndrome = raid6_sse21_gen_syndrome, + .xor_syndrome = raid6_sse21_xor_syndrome, + .valid = raid6_have_sse2, + .name ="sse2x1" , + .priority =1 ,/* Has cache hints */ };/*
@@ -263,11 +263,11 @@ static void raid6_sse22_xor_syndrome(int disks, int start, int stop, }const struct raid6_calls raid6_sse2x2 = { - raid6_sse22_gen_syndrome, - raid6_sse22_xor_syndrome, - raid6_have_sse2, -"sse2x2" , -1 /* Has cache hints */ + .gen_syndrome = raid6_sse22_gen_syndrome, + .xor_syndrome = raid6_sse22_xor_syndrome, + .valid = raid6_have_sse2, + .name ="sse2x2" , + .priority =1 ,/* Has cache hints */ };#ifdef CONFIG_X86_64
@@ -470,11 +470,11 @@ static void raid6_sse24_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_sse2x4 = { - raid6_sse24_gen_syndrome, - raid6_sse24_xor_syndrome, - raid6_have_sse2, -"sse2x4" , -1 /* Has cache hints */ + .gen_syndrome = raid6_sse24_gen_syndrome, + .xor_syndrome = raid6_sse24_xor_syndrome, + .valid = raid6_have_sse2, + .name ="sse2x4" , + .priority =1 ,/* Has cache hints */ };#endif /* CONFIG_X86_64 */
Signature · 1 line
2.53.0
PATCH 7/18 raid6: improve the public interface
In reply to Christoph HellwigStop directly calling into function pointers from users of the RAID6 PQ API, and provide exported functions with proper documentation and API guarantees asserts where applicable instead.
--- Documentation/crypto/async-tx-api.rst | 4 +- crypto/async_tx/async_pq.c | 6 +- crypto/async_tx/async_raid6_recov.c | 4 +- drivers/md/raid5.c | 4 +- fs/btrfs/raid56.c | 8 +- include/linux/raid/pq.h | 19 +-- lib/raid/raid6/algos.c | 137 +++++++++++++++++- lib/raid/raid6/arm/recov_neon.c | 4 +- .../raid6/loongarch/recov_loongarch_simd.c | 8 +- lib/raid/raid6/recov.c | 4 +- lib/raid/raid6/riscv/recov_rvv.c | 4 +- lib/raid/raid6/s390/recov_s390xc.c | 4 +- lib/raid/raid6/x86/recov_avx2.c | 4 +- lib/raid/raid6/x86/recov_avx512.c | 4 +- lib/raid/raid6/x86/recov_ssse3.c | 4 +- 15 files changed, 170 insertions(+), 48 deletions(-)
Documentation/crypto/async-tx-api.rst +2 -2
@@ -82,9 +82,9 @@ xor_val xor a series of source buffers and set a flag if the pq generate the p+q (raid6 syndrome) from a series of source buffers pq_val validate that a p and or q buffer are in sync with a given series of sources -datap (raid6_datap_recov) recover a raid6 data block and the p block +datap (raid6_recov_datap) recover a raid6 data block and the p block from the given sources -2data (raid6_2data_recov) recover 2 raid6 data blocks from the given +2data (raid6_recov_2data) recover 2 raid6 data blocks from the given sources ======== ====================================================================
crypto/async_tx/async_pq.c +3 -3
@@ -131,11 +131,11 @@ do_sync_gen_syndrome(struct page **blocks, unsigned int *offsets, int disks, } }if (submit->flags &ASYNC_TX_PQ_XOR_DST ) { -BUG_ON (!raid6_call.xor_syndrome); +BUG_ON (!raid6_can_xor_syndrome ());if (start >=0 ) - raid6_call.xor_syndrome (disks, start, stop, len, srcs); +raid6_xor_syndrome (disks, start, stop, len, srcs); }else - raid6_call.gen_syndrome (disks, len, srcs); +raid6_gen_syndrome (disks, len, srcs);async_tx_sync_epilog (submit); }
crypto/async_tx/async_raid6_recov.c +2 -2
@@ -418,7 +418,7 @@ async_raid6_2data_recov(int disks, size_t bytes, int faila, int failb,else ptrs[i] =page_address (blocks[i]) + offs[i]; -raid6_2data_recov (disks, bytes, faila, failb, ptrs); +raid6_recov_2data (disks, bytes, faila, failb, ptrs);async_tx_sync_epilog (submit);
@@ -501,7 +501,7 @@ async_raid6_datap_recov(int disks, size_t bytes, int faila,else ptrs[i] =page_address (blocks[i]) + offs[i]; -raid6_datap_recov (disks, bytes, faila, ptrs); +raid6_recov_datap (disks, bytes, faila, ptrs);async_tx_sync_epilog (submit);
drivers/md/raid5.c +2 -2
@@ -6955,7 +6955,7 @@ raid5_store_rmw_level(struct mddev *mddev, const char *page, size_t len)if (kstrtoul (page,10 , &new))return -EINVAL ; -if (new !=PARITY_DISABLE_RMW && !raid6_call.xor_syndrome) +if (new !=PARITY_DISABLE_RMW && !raid6_can_xor_syndrome ())return -EINVAL ; if (new != PARITY_DISABLE_RMW &&
@@ -7646,7 +7646,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) conf->level = mddev->new_level;if (conf->level ==6 ) { conf->max_degraded =2 ; -if (raid6_call.xor_syndrome) +if (raid6_can_xor_syndrome ()) conf->rmw_level =PARITY_ENABLE_RMW ;else conf->rmw_level =PARITY_DISABLE_RMW ;
fs/btrfs/raid56.c +4 -4
@@ -1410,7 +1410,7 @@ static void generate_pq_vertical_step(struct btrfs_raid_bio *rbio, unsigned int rbio_qstripe_paddr(rbio, sector_nr, step_nr));assert_rbio (rbio); - raid6_call.gen_syndrome (rbio->real_stripes, step, pointers); +raid6_gen_syndrome (rbio->real_stripes, step, pointers); }else {/* raid5 */ memcpy (pointers[rbio->nr_data], pointers[0 ], step);
@@ -1987,10 +1987,10 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio, }if (failb == rbio->real_stripes -2 ) { -raid6_datap_recov (rbio->real_stripes, step, +raid6_recov_datap (rbio->real_stripes, step, faila, pointers); }else { -raid6_2data_recov (rbio->real_stripes, step, +raid6_recov_2data (rbio->real_stripes, step, faila, failb, pointers); } }else {
@@ -2644,7 +2644,7 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,if (has_qstripe) {assert_rbio (rbio);/* RAID6, call the library function to fill in our P/Q. */ - raid6_call.gen_syndrome (rbio->real_stripes, step, pointers); +raid6_gen_syndrome (rbio->real_stripes, step, pointers); }else {/* RAID5. */ memcpy (pointers[nr_data], pointers[0 ], step);
include/linux/raid/pq.h +10 -9
@@ -11,6 +11,16 @@#include <linux/blkdev.h> #include <linux/mm.h> +void raid6_gen_syndrome (int disks,size_t bytes,void **ptrs); +void raid6_xor_syndrome (int disks,int start,int stop,size_t bytes, +void **ptrs); +bool raid6_can_xor_syndrome (void ); + +void raid6_recov_2data (int disks,size_t bytes,int faila,int failb, +void **ptrs); +void raid6_recov_datap (int disks,size_t bytes,int faila, +void **ptrs); +/* Routine choices */ struct raid6_calls {void (*gen_syndrome)(int ,size_t ,void **);
@@ -20,9 +30,6 @@ struct raid6_calls {int priority;/* Relative priority ranking if non-zero */ }; -/* Selected algorithm */ -extern struct raid6_calls raid6_call; -/* Various routine sets */ extern const struct raid6_calls raid6_intx1;extern const struct raid6_calls raid6_intx2;
@@ -92,10 +99,4 @@ extern const u8 raid6_gflog[256] __attribute__((aligned(256))); extern const u8 raid6_gfinv[256] __attribute__((aligned(256))); extern const u8 raid6_gfexi[256] __attribute__((aligned(256))); -/* Recovery routines */ -extern void (*raid6_2data_recov)(int disks,size_t bytes,int faila,int failb, -void **ptrs); -extern void (*raid6_datap_recov)(int disks,size_t bytes,int faila, -void **ptrs); -#endif /* LINUX_RAID_RAID6_H */
lib/raid/raid6/algos.c +129 -8
156 lines not on this page · raw message
lib/raid/raid6/arm/recov_neon.c +2 -2
@@ -35,7 +35,7 @@ static void raid6_2data_recov_neon(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -69,7 +69,7 @@ static void raid6_datap_recov_neon(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/loongarch/recov_loongarch_simd.c +4 -4
@@ -49,7 +49,7 @@ static void raid6_2data_recov_lsx(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -201,7 +201,7 @@ static void raid6_datap_recov_lsx(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
@@ -323,7 +323,7 @@ static void raid6_2data_recov_lasx(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -440,7 +440,7 @@ static void raid6_datap_recov_lasx(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/recov.c +2 -2
@@ -37,7 +37,7 @@ static void raid6_2data_recov_intx1(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -75,7 +75,7 @@ static void raid6_datap_recov_intx1(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/riscv/recov_rvv.c +2 -2
@@ -164,7 +164,7 @@ static void raid6_2data_recov_rvv(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -199,7 +199,7 @@ static void raid6_datap_recov_rvv(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks -1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/s390/recov_s390xc.c +2 -2
@@ -40,7 +40,7 @@ static void raid6_2data_recov_s390xc(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -84,7 +84,7 @@ static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/x86/recov_avx2.c +2 -2
@@ -34,7 +34,7 @@ static void raid6_2data_recov_avx2(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -199,7 +199,7 @@ static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/x86/recov_avx512.c +2 -2
@@ -43,7 +43,7 @@ static void raid6_2data_recov_avx512(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -241,7 +241,7 @@ static void raid6_datap_recov_avx512(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
lib/raid/raid6/x86/recov_ssse3.c +2 -2
@@ -36,7 +36,7 @@ static void raid6_2data_recov_ssse3(int disks, size_t bytes, int faila, ptrs[failb] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dp;
@@ -206,7 +206,7 @@ static void raid6_datap_recov_ssse3(int disks, size_t bytes, int faila, ptrs[faila] =page_address (ZERO_PAGE (0 )); ptrs[disks-1 ] = dq; - raid6_call.gen_syndrome (disks, bytes, ptrs); +raid6_gen_syndrome (disks, bytes, ptrs);/* Restore pointer table */ ptrs[faila] = dq;
Signature · 1 line
2.53.0
PATCH 8/18 raid6: warn when using less than four devices
In reply to Christoph HellwigQuoting H. Peter Anvin who came up with the RAID6 P/Q algorithm, and who wrote the initial implementation, then still part of the md driver:
The RAID-6 code has *never* supported only 3 units, and if it ever worked for *any* of the implementations it was purely by accident. Speaking as the original author I should know; this was deliberate as in some cases the degenerate case (3) would have required extra trays in the code to no user benefit.
While md never allowed less than 4 devices, btrfs does. This new warning will trigger for such file systems, but given how it already causes havoc that is a good thing. If btrfs wants to fix third, it should switch to transparently use three-way mirroring underneath, which will work as P and Q are copies of the single data device by the definition of the Linux RAID 6 P/Q algorithm.
--- include/linux/raid/pq.h | 2 ++ lib/raid/raid6/algos.c | 2 ++ 2 files changed, 4 insertions(+)
include/linux/raid/pq.h +2 -0
@@ -11,6 +11,8 @@#include <linux/blkdev.h> #include <linux/mm.h> +#define RAID6_MIN_DISKS 4 +void raid6_gen_syndrome (int disks,size_t bytes,void **ptrs);void raid6_xor_syndrome (int disks,int start,int stop,size_t bytes,void **ptrs);
lib/raid/raid6/algos.c +2 -0
@@ -42,6 +42,7 @@ void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs) {WARN_ON_ONCE (!in_task () ||irqs_disabled () ||softirq_count ());WARN_ON_ONCE (bytes &511 ); +WARN_ON_ONCE (disks <RAID6_MIN_DISKS ); raid6_call.gen_syndrome (disks, bytes, ptrs); }
@@ -77,6 +78,7 @@ void raid6_xor_syndrome(int disks, int start, int stop, size_t bytes, {WARN_ON_ONCE (!in_task () ||irqs_disabled () ||softirq_count ());WARN_ON_ONCE (bytes &511 ); +WARN_ON_ONCE (disks <RAID6_MIN_DISKS );WARN_ON_ONCE (stop < start); raid6_call.xor_syndrome (disks, start, stop, bytes, ptrs);
Signature · 1 line
2.53.0
Re: [PATCH 08/18] raid6: warn when using less than four devices
Quoted 7 lines · Christoph Hellwig
Quoting H. Peter Anvin who came up with the RAID6 P/Q algorithm, and who wrote the initial implementation, then still part of the md driver:
The RAID-6 code has *never* supported only 3 units, and if it ever worked for *any* of the implementations it was purely by accident. Speaking as the original author I should know; this was deliberate as in some cases the degenerate case (3) would have required extra trays
Stupid autocorrect. That was of course supposed to be "tests" (as in extra code paths) not "trays" :)
Quoted 8 lines
in the code to no user benefit.
While md never allowed less than 4 devices, btrfs does. This new warning will trigger for such file systems, but given how it already causes havoc that is a good thing. If btrfs wants to fix third, it should switch to transparently use three-way mirroring underneath, which will work as P and Q are copies of the single data device by the definition of the Linux RAID 6 P/Q algorithm.
For what it's worth, this is also true in the degenerate two-drive RAID-4|5 case (D = P).
-hpa
PATCH 9/18 raid6: hide internals
In reply to Christoph HellwigSplit out two new headers from the public pq.h:
- lib/raid/raid6/algos.h contains the algorithm lists private to lib/raid/raid6
- include/linux/raid/pq_tables.h contains the tables also used by async_tx providers.
The public include/linux/pq.h is now limited to the public interface for the consumers of the RAID6 PQ API.
--- crypto/async_tx/async_pq.c | 1 + crypto/async_tx/async_raid6_recov.c | 1 + drivers/dma/bcm-sba-raid.c | 1 + include/linux/raid/pq.h | 96 ++----------------- include/linux/raid/pq_tables.h | 19 ++++ lib/raid/raid6/Makefile | 2 + lib/raid/raid6/algos.c | 3 +- lib/raid/raid6/algos.h | 82 ++++++++++++++++ lib/raid/raid6/arm/neon.c | 2 +- lib/raid/raid6/arm/recov_neon.c | 2 + lib/raid/raid6/int.uc | 2 +- lib/raid/raid6/loongarch/loongarch_simd.c | 2 +- .../raid6/loongarch/recov_loongarch_simd.c | 2 + lib/raid/raid6/mktables.c | 2 +- lib/raid/raid6/powerpc/altivec.uc | 2 +- lib/raid/raid6/powerpc/vpermxor.uc | 2 +- lib/raid/raid6/recov.c | 2 + lib/raid/raid6/riscv/recov_rvv.c | 2 + lib/raid/raid6/riscv/rvv.h | 2 +- lib/raid/raid6/s390/recov_s390xc.c | 2 + lib/raid/raid6/s390/s390vx.uc | 2 +- lib/raid/raid6/tests/raid6_kunit.c | 2 +- lib/raid/raid6/x86/avx2.c | 3 +- lib/raid/raid6/x86/avx512.c | 3 +- lib/raid/raid6/x86/mmx.c | 3 +- lib/raid/raid6/x86/recov_avx2.c | 2 + lib/raid/raid6/x86/recov_avx512.c | 2 + lib/raid/raid6/x86/recov_ssse3.c | 2 + lib/raid/raid6/x86/sse1.c | 3 +- lib/raid/raid6/x86/sse2.c | 3 +- 30 files changed, 151 insertions(+), 103 deletions(-) create mode 100644 include/linux/raid/pq_tables.h create mode 100644 lib/raid/raid6/algos.h
crypto/async_tx/async_pq.c +1 -0
@@ -8,6 +8,7 @@#include <linux/module.h> #include <linux/dma-mapping.h> #include <linux/raid/pq.h> +#include <linux/raid/pq_tables.h> #include <linux/async_tx.h> #include <linux/gfp.h>
crypto/async_tx/async_raid6_recov.c +1 -0
@@ -11,6 +11,7 @@#include <linux/module.h> #include <linux/dma-mapping.h> #include <linux/raid/pq.h> +#include <linux/raid/pq_tables.h> #include <linux/async_tx.h> #include <linux/dmaengine.h>
drivers/dma/bcm-sba-raid.c +1 -0
@@ -40,6 +40,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/raid/pq.h> +#include <linux/raid/pq_tables.h> #include "dmaengine.h"
include/linux/raid/pq.h +8 -88
105 lines not on this page · raw message
include/linux/raid/pq_tables.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright 2003 H. Peter Anvin - All Rights Reserved +* +* Galois field tables for the Linux RAID6 P/Q parity algorithm. +*/ +#ifndef _LINUX_RAID_PQ_TABLES_H +#define _LINUX_RAID_PQ_TABLES_H + +#include <linux/types.h> + +extern const u8 raid6_gfmul[256][256] __attribute__((aligned(256))); +extern const u8 raid6_vgfmul[256][32] __attribute__((aligned(256))); +extern const u8 raid6_gfexp[256] __attribute__((aligned(256))); +extern const u8 raid6_gflog[256] __attribute__((aligned(256))); +extern const u8 raid6_gfinv[256] __attribute__((aligned(256))); +extern const u8 raid6_gfexi[256] __attribute__((aligned(256))); + +#endif /* _LINUX_RAID_PQ_TABLES_H */
lib/raid/raid6/Makefile +2 -0
@@ -2,6 +2,8 @@ ccflags-y += -I $(src) +ccflags-y += -I $(src) + obj-$(CONFIG_RAID6_PQ) += raid6_pq.o tests/ raid6_pq-y += algos.o tables.o
lib/raid/raid6/algos.c +2 -1
@@ -11,10 +11,11 @@* Algorithm list and algorithm selection for RAID-6 */ -#include <linux/raid/pq.h> #include <linux/module.h> #include <linux/gfp.h> +#include <linux/raid/pq.h> #include <kunit/visibility.h> +#include "algos.h" static const struct raid6_recov_calls *raid6_recov_algo;
lib/raid/raid6/algos.h new file +82 -0
82 lines not on this page · raw message
lib/raid/raid6/arm/neon.c +1 -1
@@ -5,8 +5,8 @@* Copyright (C) 2013 Linaro Ltd <[email protected]> */ -#include <linux/raid/pq.h> #include <asm/simd.h> +#include "algos.h" /* * There are 2 reasons these wrappers are kept in a separate compilation unit
lib/raid/raid6/arm/recov_neon.c +2 -0
@@ -4,8 +4,10 @@* Copyright (C) 2017 Linaro Ltd. <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> #include <asm/simd.h> +#include "algos.h" #include "arm/neon.h" static int raid6_has_neon (void )
lib/raid/raid6/int.uc +1 -1
@@ -18,7 +18,7 @@ * This file is postprocessed using unroll.awk */ -#include <linux/raid/pq.h> +#include "algos.h" /* * This is the C data type to use
lib/raid/raid6/loongarch/loongarch_simd.c +1 -1
@@ -9,9 +9,9 @@* Copyright 2002-2004 H. Peter Anvin */ -#include <linux/raid/pq.h> #include <asm/cpu-features.h> #include <asm/fpu.h> +#include "algos.h" /* * The vector algorithms are currently priority 0, which means the generic
lib/raid/raid6/loongarch/recov_loongarch_simd.c +2 -0
@@ -10,9 +10,11 @@* Author: Jim Kukunas <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> #include <asm/cpu-features.h> #include <asm/fpu.h> +#include "algos.h" /* * Unlike with the syndrome calculation algorithms, there's no boot-time
lib/raid/raid6/mktables.c +1 -1
@@ -57,7 +57,7 @@ int main(int argc, char *argv[])uint8_t exptbl[256 ], invtbl[256 ];printf ("#include <linux/export.h>\n" ); -printf ("#include <linux/raid/pq.h>\n" ); +printf ("#include \"algos.h\"\n" );/* Compute multiplication table */ printf("\nconst u8 __attribute__((aligned(256)))\n"
lib/raid/raid6/powerpc/altivec.uc +1 -1
@@ -22,7 +22,7 @@ * bracked this with preempt_disable/enable or in a lock) */ -#include <linux/raid/pq.h> +#include "algos.h" #include <altivec.h> #include <asm/cputable.h>
lib/raid/raid6/powerpc/vpermxor.uc +1 -1
@@ -20,11 +20,11 @@ * This instruction was introduced in POWER8 - ISA v2.07. */ -#include <linux/raid/pq.h> #include <altivec.h> #include <asm/ppc-opcode.h> #include <asm/cputable.h> #include <asm/switch_to.h> +#include "algos.h" typedef vector unsigned char unative_t; #define NSIZE sizeof(unative_t)
lib/raid/raid6/recov.c +2 -0
@@ -13,7 +13,9 @@* the syndrome.) */ +#include <linux/mm.h> #include <linux/raid/pq.h> +#include "algos.h" /* Recover two failed data blocks. */ static void raid6_2data_recov_intx1(int disks, size_t bytes, int faila,
lib/raid/raid6/riscv/recov_rvv.c +2 -0
@@ -4,7 +4,9 @@* Author: Chunyan Zhang <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> +#include "algos.h" #include "rvv.h" static void __raid6_2data_recov_rvv(int bytes, u8 *p, u8 *q, u8 *dp,
lib/raid/raid6/riscv/rvv.h +1 -1
@@ -7,8 +7,8 @@* Definitions for RISC-V RAID-6 code */ -#include <linux/raid/pq.h> #include <asm/vector.h> +#include "algos.h" static int rvv_has_vector (void ) {
lib/raid/raid6/s390/recov_s390xc.c +2 -0
@@ -6,7 +6,9 @@* Author(s): Martin Schwidefsky <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> +#include "algos.h" static inline void xor_block (u8 *p1,u8 *p2) {
lib/raid/raid6/s390/s390vx.uc +1 -1
@@ -12,8 +12,8 @@ */ #include <linux/cpufeature.h> -#include <linux/raid/pq.h> #include <asm/fpu.h> +#include "algos.h" #define NSIZE 16
lib/raid/raid6/tests/raid6_kunit.c +1 -1
@@ -7,7 +7,7 @@#include <kunit/test.h> #include <linux/prandom.h> -#include <linux/raid/pq.h> +#include "../algos.h" MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" );
lib/raid/raid6/x86/avx2.c +2 -1
@@ -13,8 +13,9 @@* */ -#include <linux/raid/pq.h> +#include <asm/cpufeature.h> #include <asm/fpu/api.h> +#include "algos.h" static const struct raid6_avx2_constants { u64 x1d[4];
lib/raid/raid6/x86/avx512.c +2 -1
@@ -17,8 +17,9 @@* */ -#include <linux/raid/pq.h> +#include <asm/cpufeature.h> #include <asm/fpu/api.h> +#include "algos.h" static const struct raid6_avx512_constants { u64 x1d[8];
lib/raid/raid6/x86/mmx.c +2 -1
@@ -11,8 +11,9 @@* MMX implementation of RAID-6 syndrome functions */ -#include <linux/raid/pq.h> +#include <asm/cpufeature.h> #include <asm/fpu/api.h> +#include "algos.h" /* Shared with raid6/sse1.c */ const struct raid6_mmx_constants {
lib/raid/raid6/x86/recov_avx2.c +2 -0
@@ -4,8 +4,10 @@* Author: Jim Kukunas <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> #include <asm/fpu/api.h> +#include "algos.h" static int raid6_has_avx2 (void ) {
lib/raid/raid6/x86/recov_avx512.c +2 -0
@@ -6,8 +6,10 @@* Author: Megha Dey <[email protected]> */ +#include <linux/mm.h> #include <linux/raid/pq.h> #include <asm/fpu/api.h> +#include "algos.h" static int raid6_has_avx512 (void ) {
lib/raid/raid6/x86/recov_ssse3.c +2 -0
@@ -3,8 +3,10 @@* Copyright (C) 2012 Intel Corporation */ +#include <linux/mm.h> #include <linux/raid/pq.h> #include <asm/fpu/api.h> +#include "algos.h" static int raid6_has_ssse3 (void ) {
lib/raid/raid6/x86/sse1.c +2 -1
@@ -16,8 +16,9 @@* worthwhile as a separate implementation. */ -#include <linux/raid/pq.h> +#include <asm/cpufeature.h> #include <asm/fpu/api.h> +#include "algos.h" /* Defined in raid6/mmx.c */ extern const struct raid6_mmx_constants {
lib/raid/raid6/x86/sse2.c +2 -1
@@ -12,8 +12,9 @@* */ -#include <linux/raid/pq.h> +#include <asm/cpufeature.h> #include <asm/fpu/api.h> +#include "algos.h" static const struct raid6_sse_constants { u64 x1d[2];
Signature · 1 line
2.53.0
PATCH 10/18 raid6: rework registration of optimized algorithms
In reply to Christoph HellwigReplace the static array of algorithms with a call to an architecture helper to register algorithms. This serves two purposes: it avoid having to register all algorithms in a single central place, and it removes the need for the priority field by just registering the algorithms that the architecture considers suitable for the currently running CPUs.
--- lib/raid/Kconfig | 11 + lib/raid/raid6/Makefile | 4 + lib/raid/raid6/algos.c | 303 ++++++++---------- lib/raid/raid6/algos.h | 67 +--- lib/raid/raid6/arm/neon.c | 6 - lib/raid/raid6/arm/pq_arch.h | 21 ++ lib/raid/raid6/arm/recov_neon.c | 7 - lib/raid/raid6/arm64/pq_arch.h | 1 + lib/raid/raid6/loongarch/loongarch_simd.c | 12 - lib/raid/raid6/loongarch/pq_arch.h | 23 ++ .../raid6/loongarch/recov_loongarch_simd.c | 14 - lib/raid/raid6/powerpc/altivec.uc | 10 - lib/raid/raid6/powerpc/pq_arch.h | 32 ++ lib/raid/raid6/powerpc/vpermxor.uc | 11 - lib/raid/raid6/recov.c | 2 - lib/raid/raid6/riscv/pq_arch.h | 21 ++ lib/raid/raid6/riscv/recov_rvv.c | 2 - lib/raid/raid6/riscv/rvv.h | 6 - lib/raid/raid6/s390/pq_arch.h | 15 + lib/raid/raid6/s390/recov_s390xc.c | 2 - lib/raid/raid6/s390/s390vx.uc | 7 - lib/raid/raid6/tests/raid6_kunit.c | 23 +- lib/raid/raid6/x86/avx2.c | 14 - lib/raid/raid6/x86/avx512.c | 19 -- lib/raid/raid6/x86/mmx.c | 8 - lib/raid/raid6/x86/pq_arch.h | 96 ++++++ lib/raid/raid6/x86/recov_avx2.c | 8 - lib/raid/raid6/x86/recov_avx512.c | 12 - lib/raid/raid6/x86/recov_ssse3.c | 9 - lib/raid/raid6/x86/sse1.c | 12 - lib/raid/raid6/x86/sse2.c | 15 - 31 files changed, 384 insertions(+), 409 deletions(-) create mode 100644 lib/raid/raid6/arm/pq_arch.h create mode 100644 lib/raid/raid6/arm64/pq_arch.h create mode 100644 lib/raid/raid6/loongarch/pq_arch.h create mode 100644 lib/raid/raid6/powerpc/pq_arch.h create mode 100644 lib/raid/raid6/riscv/pq_arch.h create mode 100644 lib/raid/raid6/s390/pq_arch.h create mode 100644 lib/raid/raid6/x86/pq_arch.h
lib/raid/Kconfig +11 -0
@@ -32,6 +32,17 @@ config XOR_KUNIT_TEST config RAID6_PQ tristate +# selected by architectures that provide an optimized PQ implementation +config RAID6_PQ_ARCH + depends on RAID6_PQ + default y if KERNEL_MODE_NEON # arm32/arm64 + default y if LOONGARCH + default y if ALTIVEC # powerpc + default y if RISCV_ISA_V + default y if S390 + default y if X86 + bool + config RAID6_PQ_KUNIT_TEST tristate "KUnit tests for RAID6 PQ functions" if !KUNIT_ALL_TESTS depends on KUNIT
lib/raid/raid6/Makefile +4 -0
@@ -4,6 +4,10 @@ ccflags-y += -I $(src) ccflags-y += -I $(src) +ifeq ($(CONFIG_RAID6_PQ_ARCH),y) +CFLAGS_algos.o += -I$(src)/$(SRCARCH) +endif + obj-$(CONFIG_RAID6_PQ) += raid6_pq.o tests/ raid6_pq-y += algos.o tables.o
lib/raid/raid6/algos.c +135 -168
373 lines not on this page · raw message
lib/raid/raid6/algos.h +13 -54
89 lines not on this page · raw message
lib/raid/raid6/arm/neon.c +0 -6
@@ -42,15 +42,9 @@ struct raid6_calls const raid6_neonx ## _n = { \ .gen_syndrome = raid6_neon ## _n ## _gen_syndrome, \ .xor_syndrome = raid6_neon ## _n ## _xor_syndrome, \ - .valid = raid6_have_neon, \ .name = "neonx" #_n, \ } -static int raid6_have_neon (void ) -{ -return cpu_has_neon (); -} -RAID6_NEON_WRAPPER (1 );RAID6_NEON_WRAPPER (2 );RAID6_NEON_WRAPPER (4 );
lib/raid/raid6/arm/pq_arch.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/neon.h> + +extern const struct raid6_calls raid6_neonx1; +extern const struct raid6_calls raid6_neonx2; +extern const struct raid6_calls raid6_neonx4; +extern const struct raid6_calls raid6_neonx8; +extern const struct raid6_recov_calls raid6_recov_neon; + +static __always_inline void __init arch_raid6_init(void) +{ +raid6_algo_add_default (); +if (cpu_has_neon ()) { +raid6_algo_add (&raid6_neonx1); +raid6_algo_add (&raid6_neonx2); +raid6_algo_add (&raid6_neonx4); +raid6_algo_add (&raid6_neonx8); +raid6_recov_algo_add (&raid6_recov_neon); + } +}
lib/raid/raid6/arm/recov_neon.c +0 -7
@@ -10,11 +10,6 @@#include "algos.h" #include "arm/neon.h" -static int raid6_has_neon (void ) -{ -return cpu_has_neon (); -} -static void raid6_2data_recov_neon (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -87,7 +82,5 @@ static void raid6_datap_recov_neon(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_neon = { .data2 = raid6_2data_recov_neon, .datap = raid6_datap_recov_neon, - .valid = raid6_has_neon, .name ="neon" , - .priority =10 , };
lib/raid/raid6/arm64/pq_arch.h new file +1 -0
@@ -0,0 +1 @@ +#include "arm/pq_arch.h"
lib/raid/raid6/loongarch/loongarch_simd.c +0 -12
@@ -26,11 +26,6 @@#ifdef CONFIG_CPU_HAS_LSX #define NSIZE 16 -static int raid6_has_lsx (void ) -{ -return cpu_has_lsx; -} -static void raid6_lsx_gen_syndrome (int disks,size_t bytes,void **ptrs) {u8 **dptr = (u8 **)ptrs;
@@ -246,7 +241,6 @@ static void raid6_lsx_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_lsx = { .gen_syndrome = raid6_lsx_gen_syndrome, .xor_syndrome = raid6_lsx_xor_syndrome, - .valid = raid6_has_lsx, .name ="lsx" , };
@@ -256,11 +250,6 @@ const struct raid6_calls raid6_lsx = {#ifdef CONFIG_CPU_HAS_LASX #define NSIZE 32 -static int raid6_has_lasx (void ) -{ -return cpu_has_lasx; -} -static void raid6_lasx_gen_syndrome (int disks,size_t bytes,void **ptrs) {u8 **dptr = (u8 **)ptrs;
@@ -414,7 +403,6 @@ static void raid6_lasx_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_lasx = { .gen_syndrome = raid6_lasx_gen_syndrome, .xor_syndrome = raid6_lasx_xor_syndrome, - .valid = raid6_has_lasx, .name ="lasx" , };#undef NSIZE
lib/raid/raid6/loongarch/pq_arch.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/cpu-features.h> + +extern const struct raid6_calls raid6_lsx; +extern const struct raid6_calls raid6_lasx; + +extern const struct raid6_recov_calls raid6_recov_lsx; +extern const struct raid6_recov_calls raid6_recov_lasx; + +static __always_inline void __init arch_raid6_init(void) +{ +raid6_algo_add_default (); +if (IS_ENABLED (CONFIG_CPU_HAS_LSX ) && cpu_has_lsx) +raid6_algo_add (&raid6_lsx); +if (IS_ENABLED (CONFIG_CPU_HAS_LASX ) && cpu_has_lasx) +raid6_algo_add (&raid6_lasx); + +if (IS_ENABLED (CONFIG_CPU_HAS_LASX ) && cpu_has_lasx) +raid6_recov_algo_add (&raid6_recov_lasx); +else if (IS_ENABLED (CONFIG_CPU_HAS_LSX ) && cpu_has_lsx) +raid6_recov_algo_add (&raid6_recov_lsx); +}
lib/raid/raid6/loongarch/recov_loongarch_simd.c +0 -14
@@ -24,11 +24,6 @@*/ #ifdef CONFIG_CPU_HAS_LSX -static int raid6_has_lsx (void ) -{ -return cpu_has_lsx; -} -static void raid6_2data_recov_lsx (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -291,18 +286,11 @@ static void raid6_datap_recov_lsx(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_lsx = { .data2 = raid6_2data_recov_lsx, .datap = raid6_datap_recov_lsx, - .valid = raid6_has_lsx, .name ="lsx" , - .priority =1 , };#endif /* CONFIG_CPU_HAS_LSX */ #ifdef CONFIG_CPU_HAS_LASX -static int raid6_has_lasx (void ) -{ -return cpu_has_lasx; -} -static void raid6_2data_recov_lasx (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -509,8 +497,6 @@ static void raid6_datap_recov_lasx(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_lasx = { .data2 = raid6_2data_recov_lasx, .datap = raid6_datap_recov_lasx, - .valid = raid6_has_lasx, .name ="lasx" , - .priority =2 , };#endif /* CONFIG_CPU_HAS_LASX */
lib/raid/raid6/powerpc/altivec.uc +0 -10
@@ -104,17 +104,7 @@ static void raid6_altivec$#_gen_syndrome(int disks, size_t bytes, void **ptrs) preempt_enable(); } -int raid6_have_altivec(void); -#if $# == 1 -int raid6_have_altivec(void) -{ - /* This assumes either all CPUs have Altivec or none does */ - return cpu_has_feature(CPU_FTR_ALTIVEC); -} -#endif - const struct raid6_calls raid6_altivec$# = { .gen_syndrome = raid6_altivec$#_gen_syndrome, - .valid = raid6_have_altivec, .name = "altivecx$#", };
lib/raid/raid6/powerpc/pq_arch.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/cputable.h> + +extern const struct raid6_calls raid6_altivec1; +extern const struct raid6_calls raid6_altivec2; +extern const struct raid6_calls raid6_altivec4; +extern const struct raid6_calls raid6_altivec8; +extern const struct raid6_calls raid6_vpermxor1; +extern const struct raid6_calls raid6_vpermxor2; +extern const struct raid6_calls raid6_vpermxor4; +extern const struct raid6_calls raid6_vpermxor8; + +static __always_inline void __init arch_raid6_init(void) +{ +raid6_algo_add_default (); + +/* This assumes either all CPUs have Altivec or none does */ +if (cpu_has_feature (CPU_FTR_ALTIVEC )) { +raid6_algo_add (&raid6_altivec1); +raid6_algo_add (&raid6_altivec2); +raid6_algo_add (&raid6_altivec4); +raid6_algo_add (&raid6_altivec8); + } +if (cpu_has_feature (CPU_FTR_ALTIVEC_COMP ) && +cpu_has_feature (CPU_FTR_ARCH_207S )) { +raid6_algo_add (&raid6_vpermxor1); +raid6_algo_add (&raid6_vpermxor2); +raid6_algo_add (&raid6_vpermxor4); +raid6_algo_add (&raid6_vpermxor8); + } +}
lib/raid/raid6/powerpc/vpermxor.uc +0 -11
@@ -76,18 +76,7 @@ static void raid6_vpermxor$#_gen_syndrome(int disks, size_t bytes, void **ptrs) preempt_enable(); } -int raid6_have_altivec_vpermxor(void); -#if $# == 1 -int raid6_have_altivec_vpermxor(void) -{ - /* Check if arch has both altivec and the vpermxor instructions */ - return (cpu_has_feature(CPU_FTR_ALTIVEC_COMP) && - cpu_has_feature(CPU_FTR_ARCH_207S)); -} -#endif - const struct raid6_calls raid6_vpermxor$# = { .gen_syndrome = raid6_vpermxor$#_gen_syndrome, - .valid = raid6_have_altivec_vpermxor, .name = "vpermxor$#", };
lib/raid/raid6/recov.c +0 -2
@@ -97,7 +97,5 @@ static void raid6_datap_recov_intx1(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_intx1 = { .data2 = raid6_2data_recov_intx1, .datap = raid6_datap_recov_intx1, - .valid =NULL , .name ="intx1" , - .priority =0 , };
lib/raid/raid6/riscv/pq_arch.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <asm/vector.h> + +extern const struct raid6_calls raid6_rvvx1; +extern const struct raid6_calls raid6_rvvx2; +extern const struct raid6_calls raid6_rvvx4; +extern const struct raid6_calls raid6_rvvx8; +extern const struct raid6_recov_calls raid6_recov_rvv; + +static __always_inline void __init arch_raid6_init(void) +{ +raid6_algo_add_default (); +if (has_vector ()) { +raid6_algo_add (&raid6_rvvx1); +raid6_algo_add (&raid6_rvvx2); +raid6_algo_add (&raid6_rvvx4); +raid6_algo_add (&raid6_rvvx8); +raid6_recov_algo_add (&raid6_recov_rvv); + } +}
lib/raid/raid6/riscv/recov_rvv.c +0 -2
@@ -218,7 +218,5 @@ static void raid6_datap_recov_rvv(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_rvv = { .data2 = raid6_2data_recov_rvv, .datap = raid6_datap_recov_rvv, - .valid = rvv_has_vector, .name ="rvv" , - .priority =1 , };
lib/raid/raid6/riscv/rvv.h +0 -6
@@ -10,11 +10,6 @@#include <asm/vector.h> #include "algos.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) \
@@ -41,6 +36,5 @@ static int rvv_has_vector(void) struct raid6_calls const raid6_rvvx ## _n = { \ .gen_syndrome = raid6_rvv ## _n ## _gen_syndrome, \ .xor_syndrome = raid6_rvv ## _n ## _xor_syndrome, \ - .valid = rvv_has_vector, \ .name = "rvvx" #_n, \ }
lib/raid/raid6/s390/pq_arch.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <linux/cpufeature.h> + +extern const struct raid6_calls raid6_s390vx8; +extern const struct raid6_recov_calls raid6_recov_s390xc; + +static __always_inline void __init arch_raid6_init(void) +{ +if (cpu_has_vx ()) +raid6_algo_add (&raid6_s390vx8); +else +raid6_algo_add_default (); +raid6_recov_algo_add (&raid6_recov_s390xc); +}
lib/raid/raid6/s390/recov_s390xc.c +0 -2
@@ -112,7 +112,5 @@ static void raid6_datap_recov_s390xc(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_s390xc = { .data2 = raid6_2data_recov_s390xc, .datap = raid6_datap_recov_s390xc, - .valid =NULL , .name ="s390xc" , - .priority =1 , };
lib/raid/raid6/s390/s390vx.uc +0 -7
@@ -121,15 +121,8 @@ static void raid6_s390vx$#_xor_syndrome(int disks, int start, int stop, kernel_fpu_end(&vxstate, KERNEL_VXR); } -static int raid6_s390vx$#_valid(void) -{ - return cpu_has_vx(); -} - const struct raid6_calls raid6_s390vx$# = { .gen_syndrome = raid6_s390vx$#_gen_syndrome, .xor_syndrome = raid6_s390vx$#_xor_syndrome, - .valid = raid6_s390vx$#_valid, .name = "vx128x$#", - .priority = 1, };
lib/raid/raid6/tests/raid6_kunit.c +12 -11
@@ -88,19 +88,20 @@ static void test_disks(struct kunit *test, const struct raid6_calls *calls,static void raid6_test (struct kunit *test) { -const struct raid6_calls *const *algo; -const struct raid6_recov_calls *const *ra;int i, j, p1, p2; +unsigned int r, g; -for (ra = raid6_recov_algos; *ra; ra++) { -if ((*ra)->valid && !(*ra)->valid ()) -continue ; +for (r =0 ; ; r++) { +const struct raid6_recov_calls *ra =raid6_recov_algo_find (r); -for (algo = raid6_algos; *algo; algo++) { -const struct raid6_calls *calls = *algo; +if (!ra) +break ; -if (calls->valid && !calls->valid ()) -continue ; +for (g =0 ; ; g++) { +const struct raid6_calls *calls =raid6_algo_find (g); + +if (!calls) +break ;/* Nuke syndromes */ memset (data[NDISKS -2 ],0xee ,PAGE_SIZE );
@@ -112,7 +113,7 @@ static void raid6_test(struct kunit *test)for (i =0 ; i <NDISKS -1 ; i++)for (j = i+1 ; j <NDISKS ; j++) -test_disks (test, calls, *ra, i, j); +test_disks (test, calls, ra, i, j);if (!calls->xor_syndrome)continue ;
@@ -130,7 +131,7 @@ static void raid6_test(struct kunit *test)for (i =0 ; i <NDISKS -1 ; i++)for (j = i+1 ; j <NDISKS ; j++)test_disks (test, calls, - *ra, i, j); + ra, i, j); } }
lib/raid/raid6/x86/avx2.c +0 -14
@@ -24,11 +24,6 @@ static const struct raid6_avx2_constants { 0x1d1d1d1d1d1d1d1dULL, 0x1d1d1d1d1d1d1d1dULL,}, }; -static int raid6_have_avx2 (void ) -{ -return boot_cpu_has (X86_FEATURE_AVX2 ) &&boot_cpu_has (X86_FEATURE_AVX ); -} -/* * Plain AVX2 implementation */
@@ -131,10 +126,7 @@ static void raid6_avx21_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx2x1 = { .gen_syndrome = raid6_avx21_gen_syndrome, .xor_syndrome = raid6_avx21_xor_syndrome, - .valid = raid6_have_avx2, .name ="avx2x1" , -/* Prefer AVX2 over priority 1 (SSE2 and others) */ - .priority =2 , };/*
@@ -262,10 +254,7 @@ static void raid6_avx22_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx2x2 = { .gen_syndrome = raid6_avx22_gen_syndrome, .xor_syndrome = raid6_avx22_xor_syndrome, - .valid = raid6_have_avx2, .name ="avx2x2" , -/* Prefer AVX2 over priority 1 (SSE2 and others) */ - .priority =2 , };#ifdef CONFIG_X86_64
@@ -466,9 +455,6 @@ static void raid6_avx24_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx2x4 = { .gen_syndrome = raid6_avx24_gen_syndrome, .xor_syndrome = raid6_avx24_xor_syndrome, - .valid = raid6_have_avx2, .name ="avx2x4" , -/* Prefer AVX2 over priority 1 (SSE2 and others) */ - .priority =2 , };#endif /* CONFIG_X86_64 */
lib/raid/raid6/x86/avx512.c +0 -19
@@ -30,16 +30,6 @@ static const struct raid6_avx512_constants { 0x1d1d1d1d1d1d1d1dULL, 0x1d1d1d1d1d1d1d1dULL,}, }; -static int raid6_have_avx512 (void ) -{ -return boot_cpu_has (X86_FEATURE_AVX2 ) && -boot_cpu_has (X86_FEATURE_AVX ) && -boot_cpu_has (X86_FEATURE_AVX512F ) && -boot_cpu_has (X86_FEATURE_AVX512BW ) && -boot_cpu_has (X86_FEATURE_AVX512VL ) && -boot_cpu_has (X86_FEATURE_AVX512DQ ); -} -static void raid6_avx5121_gen_syndrome (int disks,size_t bytes,void **ptrs) {u8 **dptr = (u8 **)ptrs;
@@ -159,10 +149,7 @@ static void raid6_avx5121_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx512x1 = { .gen_syndrome = raid6_avx5121_gen_syndrome, .xor_syndrome = raid6_avx5121_xor_syndrome, - .valid = raid6_have_avx512, .name ="avx512x1" , -/* Prefer AVX512 over priority 1 (SSE2 and others) */ - .priority =2 , };/*
@@ -317,10 +304,7 @@ static void raid6_avx5122_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx512x2 = { .gen_syndrome = raid6_avx5122_gen_syndrome, .xor_syndrome = raid6_avx5122_xor_syndrome, - .valid = raid6_have_avx512, .name ="avx512x2" , -/* Prefer AVX512 over priority 1 (SSE2 and others) */ - .priority =2 , };#ifdef CONFIG_X86_64
@@ -556,9 +540,6 @@ static void raid6_avx5124_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_avx512x4 = { .gen_syndrome = raid6_avx5124_gen_syndrome, .xor_syndrome = raid6_avx5124_xor_syndrome, - .valid = raid6_have_avx512, .name ="avx512x4" , -/* Prefer AVX512 over priority 1 (SSE2 and others) */ - .priority =2 , };#endif
lib/raid/raid6/x86/mmx.c +0 -8
@@ -22,12 +22,6 @@ const struct raid6_mmx_constants { 0x1d1d1d1d1d1d1d1dULL, }; -static int raid6_have_mmx (void ) -{ -/* Not really "boot_cpu" but "all_cpus" */ -return boot_cpu_has (X86_FEATURE_MMX ); -} -/* * Plain MMX implementation */
@@ -70,7 +64,6 @@ static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs)const struct raid6_calls raid6_mmxx1 = { .gen_syndrome = raid6_mmx1_gen_syndrome, - .valid = raid6_have_mmx, .name ="mmxx1" , };
@@ -127,6 +120,5 @@ static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)const struct raid6_calls raid6_mmxx2 = { .gen_syndrome = raid6_mmx2_gen_syndrome, - .valid = raid6_have_mmx, .name ="mmxx2" , };
lib/raid/raid6/x86/pq_arch.h new file +96 -0
96 lines not on this page · raw message
lib/raid/raid6/x86/recov_avx2.c +0 -8
@@ -9,12 +9,6 @@#include <asm/fpu/api.h> #include "algos.h" -static int raid6_has_avx2 (void ) -{ -return boot_cpu_has (X86_FEATURE_AVX2 ) && -boot_cpu_has (X86_FEATURE_AVX ); -} -static void raid6_2data_recov_avx2 (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -305,11 +299,9 @@ static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_avx2 = { .data2 = raid6_2data_recov_avx2, .datap = raid6_datap_recov_avx2, - .valid = raid6_has_avx2, #ifdef CONFIG_X86_64 .name ="avx2x2" , #else .name ="avx2x1" , #endif - .priority =2 , };
lib/raid/raid6/x86/recov_avx512.c +0 -12
@@ -11,16 +11,6 @@#include <asm/fpu/api.h> #include "algos.h" -static int raid6_has_avx512 (void ) -{ -return boot_cpu_has (X86_FEATURE_AVX2 ) && -boot_cpu_has (X86_FEATURE_AVX ) && -boot_cpu_has (X86_FEATURE_AVX512F ) && -boot_cpu_has (X86_FEATURE_AVX512BW ) && -boot_cpu_has (X86_FEATURE_AVX512VL ) && -boot_cpu_has (X86_FEATURE_AVX512DQ ); -} -static void raid6_2data_recov_avx512 (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -369,11 +359,9 @@ static void raid6_datap_recov_avx512(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_avx512 = { .data2 = raid6_2data_recov_avx512, .datap = raid6_datap_recov_avx512, - .valid = raid6_has_avx512, #ifdef CONFIG_X86_64 .name ="avx512x2" , #else .name ="avx512x1" , #endif - .priority =3 , };
lib/raid/raid6/x86/recov_ssse3.c +0 -9
@@ -8,13 +8,6 @@#include <asm/fpu/api.h> #include "algos.h" -static int raid6_has_ssse3 (void ) -{ -return boot_cpu_has (X86_FEATURE_XMM ) && -boot_cpu_has (X86_FEATURE_XMM2 ) && -boot_cpu_has (X86_FEATURE_SSSE3 ); -} -static void raid6_2data_recov_ssse3 (int disks,size_t bytes,int faila,int failb,void **ptrs) {
@@ -320,11 +313,9 @@ static void raid6_datap_recov_ssse3(int disks, size_t bytes, int faila,const struct raid6_recov_calls raid6_recov_ssse3 = { .data2 = raid6_2data_recov_ssse3, .datap = raid6_datap_recov_ssse3, - .valid = raid6_has_ssse3, #ifdef CONFIG_X86_64 .name ="ssse3x2" , #else .name ="ssse3x1" , #endif - .priority =1 , };
lib/raid/raid6/x86/sse1.c +0 -12
@@ -25,14 +25,6 @@ extern const struct raid6_mmx_constants {u64 x1d; } raid6_mmx_constants; -static int raid6_have_sse1_or_mmxext (void ) -{ -/* Not really boot_cpu but "all_cpus" */ -return boot_cpu_has (X86_FEATURE_MMX ) && - (boot_cpu_has (X86_FEATURE_XMM ) || -boot_cpu_has (X86_FEATURE_MMXEXT )); -} -/* * Plain SSE1 implementation */
@@ -86,9 +78,7 @@ static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs)const struct raid6_calls raid6_sse1x1 = { .gen_syndrome = raid6_sse11_gen_syndrome, - .valid = raid6_have_sse1_or_mmxext, .name ="sse1x1" , - .priority =1 ,/* Has cache hints */ };/*
@@ -148,7 +138,5 @@ static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)const struct raid6_calls raid6_sse1x2 = { .gen_syndrome = raid6_sse12_gen_syndrome, - .valid = raid6_have_sse1_or_mmxext, .name ="sse1x2" , - .priority =1 ,/* Has cache hints */ };
lib/raid/raid6/x86/sse2.c +0 -15
@@ -22,15 +22,6 @@ static const struct raid6_sse_constants { { 0x1d1d1d1d1d1d1d1dULL, 0x1d1d1d1d1d1d1d1dULL }, }; -static int raid6_have_sse2 (void ) -{ -/* Not really boot_cpu but "all_cpus" */ -return boot_cpu_has (X86_FEATURE_MMX ) && -boot_cpu_has (X86_FEATURE_FXSR ) && -boot_cpu_has (X86_FEATURE_XMM ) && -boot_cpu_has (X86_FEATURE_XMM2 ); -} -/* * Plain SSE2 implementation */
@@ -136,9 +127,7 @@ static void raid6_sse21_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_sse2x1 = { .gen_syndrome = raid6_sse21_gen_syndrome, .xor_syndrome = raid6_sse21_xor_syndrome, - .valid = raid6_have_sse2, .name ="sse2x1" , - .priority =1 ,/* Has cache hints */ };/*
@@ -266,9 +255,7 @@ static void raid6_sse22_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_sse2x2 = { .gen_syndrome = raid6_sse22_gen_syndrome, .xor_syndrome = raid6_sse22_xor_syndrome, - .valid = raid6_have_sse2, .name ="sse2x2" , - .priority =1 ,/* Has cache hints */ };#ifdef CONFIG_X86_64
@@ -473,9 +460,7 @@ static void raid6_sse24_xor_syndrome(int disks, int start, int stop,const struct raid6_calls raid6_sse2x4 = { .gen_syndrome = raid6_sse24_gen_syndrome, .xor_syndrome = raid6_sse24_xor_syndrome, - .valid = raid6_have_sse2, .name ="sse2x4" , - .priority =1 ,/* Has cache hints */ };#endif /* CONFIG_X86_64 */
Signature · 7 lines
2.53.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 11/18 raid6: use static_call for gen_syndrom and xor_syndrom
In reply to Christoph HellwigAvoid indirect calls for P/Q parity generation.
--- lib/raid/raid6/algos.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
lib/raid/raid6/algos.c +12 -6
@@ -14,6 +14,7 @@#include <linux/module.h> #include <linux/gfp.h> #include <linux/raid/pq.h> +#include <linux/static_call.h> #include <kunit/visibility.h> #include "algos.h"
@@ -23,7 +24,8 @@ static unsigned int raid6_nr_algos;static const struct raid6_recov_calls *raid6_recov_algo;/* Selected algorithm */ -static struct raid6_calls raid6_call; +DEFINE_STATIC_CALL_NULL (raid6_gen_syndrome_impl, *raid6_intx1.gen_syndrome); +DEFINE_STATIC_CALL_NULL (raid6_xor_syndrome_impl, *raid6_intx1.xor_syndrome);/** * raid6_gen_syndrome - generate RAID6 P/Q parity
@@ -48,7 +50,7 @@ void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs)WARN_ON_ONCE (bytes &511 );WARN_ON_ONCE (disks <RAID6_MIN_DISKS ); - raid6_call.gen_syndrome (disks, bytes, ptrs); +static_call (raid6_gen_syndrome_impl)(disks, bytes, ptrs); }EXPORT_SYMBOL_GPL (raid6_gen_syndrome);
@@ -85,7 +87,7 @@ void raid6_xor_syndrome(int disks, int start, int stop, size_t bytes,WARN_ON_ONCE (disks <RAID6_MIN_DISKS );WARN_ON_ONCE (stop < start); - raid6_call.xor_syndrome (disks, start, stop, bytes, ptrs); +static_call (raid6_xor_syndrome_impl)(disks, start, stop, bytes, ptrs); }EXPORT_SYMBOL_GPL (raid6_xor_syndrome);
@@ -96,7 +98,7 @@ EXPORT_SYMBOL_GPL(raid6_xor_syndrome);*/ bool raid6_can_xor_syndrome (void ) { -return !!raid6_call.xor_syndrome; +return !!static_call_query (raid6_xor_syndrome_impl); }EXPORT_SYMBOL_GPL (raid6_can_xor_syndrome);
@@ -195,7 +197,8 @@ static int raid6_choose_gen(void *(*const dptrs)[RAID6_TEST_DISKS],return -EINVAL ; } - raid6_call = *best; +static_call_update (raid6_gen_syndrome_impl, best->gen_syndrome); +static_call_update (raid6_xor_syndrome_impl, best->xor_syndrome); pr_info("raid6: using algorithm %s gen() %ld MB/s\n", best->name,
@@ -240,7 +243,10 @@ static int __init raid6_select_algo(void)if (!IS_ENABLED (CONFIG_RAID6_PQ_BENCHMARK ) || raid6_nr_algos ==1 ) {pr_info ("raid6: skipped pq benchmark and selected %s\n" , raid6_algos[raid6_nr_algos -1 ]->name); - raid6_call = *raid6_algos[raid6_nr_algos -1 ]; +static_call_update (raid6_gen_syndrome_impl, + raid6_algos[raid6_nr_algos -1 ]->gen_syndrome); +static_call_update (raid6_xor_syndrome_impl, + raid6_algos[raid6_nr_algos -1 ]->xor_syndrome);return 0 ; }
Signature · 1 line
2.53.0
PATCH 12/18 raid6: use static_call for raid6_recov_2data and raid6_recov_datap
In reply to Christoph HellwigAvoid expensive indirect calls for the recovery routines as well.
--- lib/raid/raid6/algos.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
lib/raid/raid6/algos.c +6 -2
@@ -26,6 +26,8 @@ static const struct raid6_recov_calls *raid6_recov_algo;/* Selected algorithm */ DEFINE_STATIC_CALL_NULL (raid6_gen_syndrome_impl, *raid6_intx1.gen_syndrome);DEFINE_STATIC_CALL_NULL (raid6_xor_syndrome_impl, *raid6_intx1.xor_syndrome); +DEFINE_STATIC_CALL_NULL (raid6_recov_2data_impl, *raid6_recov_intx1.data2); +DEFINE_STATIC_CALL_NULL (raid6_recov_datap_impl, *raid6_recov_intx1.datap);/** * raid6_gen_syndrome - generate RAID6 P/Q parity
@@ -126,7 +128,7 @@ void raid6_recov_2data(int disks, size_t bytes, int faila, int failb,WARN_ON_ONCE (bytes >PAGE_SIZE );WARN_ON_ONCE (failb <= faila); - raid6_recov_algo->data2 (disks, bytes, faila, failb, ptrs); +static_call (raid6_recov_2data_impl)(disks, bytes, faila, failb, ptrs); }EXPORT_SYMBOL_GPL (raid6_recov_2data);
@@ -151,7 +153,7 @@ void raid6_recov_datap(int disks, size_t bytes, int faila, void **ptrs)WARN_ON_ONCE (bytes &511 );WARN_ON_ONCE (bytes >PAGE_SIZE ); - raid6_recov_algo->datap (disks, bytes, faila, ptrs); +static_call (raid6_recov_datap_impl)(disks, bytes, faila, ptrs); }EXPORT_SYMBOL_GPL (raid6_recov_datap);
@@ -329,6 +331,8 @@ static int __init raid6_init(void)*/ if (!raid6_recov_algo) raid6_recov_algo = &raid6_recov_intx1; +static_call_update (raid6_recov_2data_impl, raid6_recov_algo->data2); +static_call_update (raid6_recov_datap_impl, raid6_recov_algo->datap);pr_info ("raid6: using %s recovery algorithm\n" , raid6_recov_algo->name);return raid6_select_algo ();
Signature · 1 line
2.53.0
PATCH 13/18 raid6: update top of file comments
In reply to Christoph HellwigDrop the pointless mention of the file name, and use standard formatting for the top of file comments.
--- lib/raid/raid6/algos.c | 8 +------- lib/raid/raid6/arm/neon.c | 2 +- lib/raid/raid6/mktables.c | 12 +++--------- lib/raid/raid6/recov.c | 14 ++++---------- lib/raid/raid6/riscv/rvv.h | 2 -- lib/raid/raid6/x86/avx2.c | 13 ++++--------- lib/raid/raid6/x86/avx512.c | 18 ++++++------------ lib/raid/raid6/x86/mmx.c | 10 ++-------- lib/raid/raid6/x86/sse1.c | 18 ++++++------------ lib/raid/raid6/x86/sse2.c | 9 +-------- 10 files changed, 28 insertions(+), 78 deletions(-)
lib/raid/raid6/algos.c +1 -7
@@ -1,12 +1,6 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* raid6/algos.c +* Copyright 2002 H. Peter Anvin - All Rights Reserved * * Algorithm list and algorithm selection for RAID-6 */
lib/raid/raid6/arm/neon.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only /* -* linux/lib/raid6/neon.c - RAID6 syndrome calculation using ARM NEON intrinsics +* RAID6 syndrome calculation using ARM NEON intrinsics * * Copyright (C) 2013 Linaro Ltd <[email protected]> */
lib/raid/raid6/mktables.c +3 -9
@@ -1,15 +1,9 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002-2007 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* mktables.c +* Copyright 2002-2007 H. Peter Anvin - All Rights Reserved * -* Make RAID-6 tables. This is a host user space program to be run at -* compile time. +* Make RAID-6 tables. This is a host user space program to be run at compile +* time. */ #include <stdio.h>
lib/raid/raid6/recov.c +4 -10
@@ -1,16 +1,10 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* raid6/recov.c +* Copyright 2002 H. Peter Anvin - All Rights Reserved * -* RAID-6 data recovery in dual failure mode. In single failure mode, -* use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct -* the syndrome.) +* RAID-6 data recovery in dual failure mode. In single failure mode, use the +* RAID-5 algorithm (or, in the case of Q failure, just reconstruct the +* syndrome.) */ #include <linux/mm.h>
lib/raid/raid6/riscv/rvv.h +0 -2
@@ -2,8 +2,6 @@/* * Copyright 2024 Institute of Software, CAS. * -* raid6/rvv.h -* * Definitions for RISC-V RAID-6 code */
lib/raid/raid6/x86/avx2.c +4 -9
@@ -1,16 +1,11 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright (C) 2012 Intel Corporation -* Author: Yuanhan Liu <[email protected]> +/* +* Copyright (C) 2012 Intel Corporation +* Author: Yuanhan Liu <[email protected]> * -* Based on sse2.c: Copyright 2002 H. Peter Anvin - All Rights Reserved +* Based on sse2.c: Copyright 2002 H. Peter Anvin - All Rights Reserved * -* ----------------------------------------------------------------------- */ - -/* * AVX2 implementation of RAID-6 syndrome functions -* */ #include <asm/cpufeature.h>
lib/raid/raid6/x86/avx512.c +6 -12
@@ -1,20 +1,14 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- -------------------------------------------------------- -* -* Copyright (C) 2016 Intel Corporation +/* +* Copyright (C) 2016 Intel Corporation * -* Author: Gayatri Kammela <[email protected]> -* Author: Megha Dey <[email protected]> +* Author: Gayatri Kammela <[email protected]> +* Author: Megha Dey <[email protected]> * -* Based on avx2.c: Copyright 2012 Yuanhan Liu All Rights Reserved -* Based on sse2.c: Copyright 2002 H. Peter Anvin - All Rights Reserved +* Based on avx2.c: Copyright 2012 Yuanhan Liu All Rights Reserved +* Based on sse2.c: Copyright 2002 H. Peter Anvin - All Rights Reserved * -* ----------------------------------------------------------------------- -*/ - -/* * AVX512 implementation of RAID-6 syndrome functions -* */ #include <asm/cpufeature.h>
lib/raid/raid6/x86/mmx.c +2 -8
@@ -1,14 +1,8 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* raid6/mmx.c +* Copyright 2002 H. Peter Anvin - All Rights Reserved * -* MMX implementation of RAID-6 syndrome functions +* MMX implementation of RAID-6 syndrome functions. */ #include <asm/cpufeature.h>
lib/raid/raid6/x86/sse1.c +6 -12
@@ -1,19 +1,13 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* raid6/sse1.c +* Copyright 2002 H. Peter Anvin - All Rights Reserved * -* SSE-1/MMXEXT implementation of RAID-6 syndrome functions +* SSE-1/MMXEXT implementation of RAID-6 syndrome functions. * -* This is really an MMX implementation, but it requires SSE-1 or -* AMD MMXEXT for prefetch support and a few other features. The -* support for nontemporal memory accesses is enough to make this -* worthwhile as a separate implementation. +* This is really an MMX implementation, but it requires SSE-1 or AMD MMXEXT for +* prefetch support and a few other features. The support for nontemporal +* memory accesses is enough to make this worthwhile as a separate +* implementation. */ #include <asm/cpufeature.h>
lib/raid/raid6/x86/sse2.c +1 -8
@@ -1,15 +1,8 @@// SPDX-License-Identifier: GPL-2.0-or-later -/* -*- linux-c -*- ------------------------------------------------------- * -* -* Copyright 2002 H. Peter Anvin - All Rights Reserved -* -* ----------------------------------------------------------------------- */ -/* -* raid6/sse2.c +* Copyright 2002 H. Peter Anvin - All Rights Reserved * * SSE-2 implementation of RAID-6 syndrome functions -* */ #include <asm/cpufeature.h>
Signature · 1 line
2.53.0
PATCH 14/18 raid6_kunit: use KUNIT_CASE_PARAM
In reply to Christoph HellwigThe raid6 test combines various generation and recovery algorithms. Use KUNIT_CASE_PARAM and provide a generator that iterates over the possible combinations instead of looping inside a single test instance.
--- lib/raid/raid6/tests/raid6_kunit.c | 120 ++++++++++++++++------------- 1 file changed, 68 insertions(+), 52 deletions(-)
lib/raid/raid6/tests/raid6_kunit.c +68 -52
@@ -21,6 +21,15 @@ static char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); static char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); static char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +struct test_args { +unsigned int recov_idx; +const struct raid6_recov_calls *recov; +unsigned int gen_idx; +const struct raid6_calls *gen; +}; + +static struct test_args args; +static void makedata (int start,int stop) {int i;
@@ -43,9 +52,10 @@ static char member_type(int d) } } -static void test_disks (struct kunit *test,const struct raid6_calls *calls, -const struct raid6_recov_calls *ra,int faila,int failb) +static void test_recover (struct kunit *test,int faila,int failb) { +const struct test_args *ta = test->param_value; +memset (recovi,0xf0 ,PAGE_SIZE );memset (recovj,0xba ,PAGE_SIZE );
@@ -61,25 +71,23 @@ static void test_disks(struct kunit *test, const struct raid6_calls *calls, goto skip;/* P+Q failure. Just rebuild the syndrome. */ - calls->gen_syndrome (NDISKS ,PAGE_SIZE , dataptrs); + ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , dataptrs); }else if (failb ==NDISKS -2 ) {/* data+P failure. */ - ra->datap (NDISKS ,PAGE_SIZE , faila, dataptrs); + ta->recov->datap (NDISKS ,PAGE_SIZE , faila, dataptrs); }else {/* data+data failure. */ - ra->data2 (NDISKS ,PAGE_SIZE , faila, failb, dataptrs); + ta->recov->data2 (NDISKS ,PAGE_SIZE , faila, failb, dataptrs); }KUNIT_EXPECT_MEMEQ_MSG (test, data[faila], recovi,PAGE_SIZE , -"algo=%-8s/%-8s faila miscompared: %3d[%c] (failb=%3d[%c])\n" , - calls->name, ra->name, - faila,member_type (faila), - failb,member_type (failb)); +"faila miscompared: %3d[%c] (failb=%3d[%c])\n" , + faila,member_type (faila), + failb,member_type (failb));KUNIT_EXPECT_MEMEQ_MSG (test, data[failb], recovj,PAGE_SIZE , -"algo=%-8s/%-8s failb miscompared: %3d[%c] (faila=%3d[%c])\n" , - calls->name, ra->name, - failb,member_type (failb), - faila,member_type (faila)); +"failb miscompared: %3d[%c] (faila=%3d[%c])\n" , + failb,member_type (failb), + faila,member_type (faila)); skip: dataptrs[faila] = data[faila];
@@ -88,58 +96,66 @@ static void test_disks(struct kunit *test, const struct raid6_calls *calls,static void raid6_test (struct kunit *test) { +const struct test_args *ta = test->param_value;int i, j, p1, p2; -unsigned int r, g; - -for (r =0 ; ; r++) { -const struct raid6_recov_calls *ra =raid6_recov_algo_find (r); - -if (!ra) -break ; - -for (g =0 ; ; g++) { -const struct raid6_calls *calls =raid6_algo_find (g); - -if (!calls) -break ; -/* Nuke syndromes */ -memset (data[NDISKS -2 ],0xee ,PAGE_SIZE ); -memset (data[NDISKS -1 ],0xee ,PAGE_SIZE ); +/* Nuke syndromes */ +memset (data[NDISKS -2 ],0xee ,PAGE_SIZE ); +memset (data[NDISKS -1 ],0xee ,PAGE_SIZE ); -/* Generate assumed good syndrome */ - calls->gen_syndrome (NDISKS ,PAGE_SIZE , - (void **)&dataptrs); +/* Generate assumed good syndrome */ + ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , (void **)&dataptrs); -for (i =0 ; i <NDISKS -1 ; i++) -for (j = i+1 ; j <NDISKS ; j++) -test_disks (test, calls, ra, i, j); +for (i =0 ; i <NDISKS -1 ; i++) +for (j = i +1 ; j <NDISKS ; j++) +test_recover (test, i, j); -if (!calls->xor_syndrome) -continue ; +if (!ta->gen->xor_syndrome) +return ; -for (p1 =0 ; p1 <NDISKS -2 ; p1++) -for (p2 = p1; p2 <NDISKS -2 ; p2++) { +for (p1 =0 ; p1 <NDISKS -2 ; p1++) { +for (p2 = p1; p2 <NDISKS -2 ; p2++) { +/* Simulate rmw run */ + ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , + (void **)&dataptrs); +makedata (p1, p2); + ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , + (void **)&dataptrs); -/* Simulate rmw run */ - calls->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - (void **)&dataptrs); -makedata (p1, p2); - calls->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - (void **)&dataptrs); +for (i =0 ; i <NDISKS -1 ; i++) +for (j = i +1 ; j <NDISKS ; j++) +test_recover (test, i, j); + } + } +} -for (i =0 ; i <NDISKS -1 ; i++) -for (j = i+1 ; j <NDISKS ; j++) -test_disks (test, calls, - ra, i, j); - } +static const void *raid6_gen_params (struct kunit *test,const void *prev, +char *desc) +{ +if (!prev) { +memset (&args,0 ,sizeof (args)); +next_algo: + args.recov_idx =0 ; + args.gen =raid6_algo_find (args.gen_idx); +if (!args.gen) +return NULL ; + } - } +if (args.recov) + args.recov_idx++; + args.recov =raid6_recov_algo_find (args.recov_idx); +if (!args.recov) { + args.gen_idx++; + goto next_algo; } + +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"gen=%s recov=%s" , + args.gen->name, args.recov->name); +return &args; }static struct kunit_case raid6_test_cases[] = { -KUNIT_CASE (raid6_test), +KUNIT_CASE_PARAM (raid6_test, raid6_gen_params), {}, };
Signature · 1 line
2.53.0
PATCH 15/18 raid6_kunit: dynamically allocate data buffers using vmalloc
In reply to Christoph HellwigUse vmalloc for the data buffers instead of using static .data allocations. This provides for better out of bounds checking and avoids wasting kernel memory after the test has run. vmalloc is used instead of kmalloc to provide for better out of bounds access checking as in other kunit tests.
--- lib/raid/raid6/tests/raid6_kunit.c | 77 ++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 15 deletions(-)
lib/raid/raid6/tests/raid6_kunit.c +62 -15
@@ -7,19 +7,20 @@#include <kunit/test.h> #include <linux/prandom.h> +#include <linux/vmalloc.h> #include "../algos.h" MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" );#define RAID6_KUNIT_SEED 42 +#define RAID6_KUNIT_MAX_FAILURES 2#define NDISKS 16/* Including P and Q */ static struct rnd_state rng;static void *dataptrs[NDISKS ]; -static char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); -static char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); -static char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +static void *test_buffers[NDISKS ]; +static void *test_recov_buffers[RAID6_KUNIT_MAX_FAILURES ];struct test_args {unsigned int recov_idx;
@@ -35,8 +36,8 @@ static void makedata(int start, int stop)int i;for (i = start; i <= stop; i++) { -prandom_bytes_state (&rng, data[i],PAGE_SIZE ); - dataptrs[i] = data[i]; +prandom_bytes_state (&rng, test_buffers[i],PAGE_SIZE ); + dataptrs[i] = test_buffers[i]; } }
@@ -55,12 +56,13 @@ static char member_type(int d)static void test_recover (struct kunit *test,int faila,int failb) {const struct test_args *ta = test->param_value; +int i; -memset (recovi,0xf0 ,PAGE_SIZE ); -memset (recovj,0xba ,PAGE_SIZE ); +for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) +memset (test_recov_buffers[i],0xf0 ,PAGE_SIZE ); - dataptrs[faila] = recovi; - dataptrs[failb] = recovj; + dataptrs[faila] = test_recov_buffers[0 ]; + dataptrs[failb] = test_recov_buffers[1 ];if (failb ==NDISKS -1 ) {/*
@@ -80,18 +82,20 @@ static void test_recover(struct kunit *test, int faila, int failb) ta->recov->data2 (NDISKS ,PAGE_SIZE , faila, failb, dataptrs); } -KUNIT_EXPECT_MEMEQ_MSG (test, data[faila], recovi,PAGE_SIZE , +KUNIT_EXPECT_MEMEQ_MSG (test, test_buffers[faila], test_recov_buffers[0 ], +PAGE_SIZE ,"faila miscompared: %3d[%c] (failb=%3d[%c])\n" , faila,member_type (faila), failb,member_type (failb)); -KUNIT_EXPECT_MEMEQ_MSG (test, data[failb], recovj,PAGE_SIZE , +KUNIT_EXPECT_MEMEQ_MSG (test, test_buffers[failb], test_recov_buffers[1 ], +PAGE_SIZE ,"failb miscompared: %3d[%c] (faila=%3d[%c])\n" , failb,member_type (failb), faila,member_type (faila)); skip: - dataptrs[faila] = data[faila]; - dataptrs[failb] = data[failb]; + dataptrs[faila] = test_buffers[faila]; + dataptrs[failb] = test_buffers[failb]; }static void raid6_test (struct kunit *test)
@@ -100,8 +104,8 @@ static void raid6_test(struct kunit *test)int i, j, p1, p2;/* Nuke syndromes */ -memset (data[NDISKS -2 ],0xee ,PAGE_SIZE ); -memset (data[NDISKS -1 ],0xee ,PAGE_SIZE ); +memset (test_buffers[NDISKS -2 ],0xee ,PAGE_SIZE ); +memset (test_buffers[NDISKS -1 ],0xee ,PAGE_SIZE );/* Generate assumed good syndrome */ ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , (void **)&dataptrs);
@@ -161,15 +165,58 @@ static struct kunit_case raid6_test_cases[] = {static int raid6_suite_init (struct kunit_suite *suite) { +int i; +prandom_seed_state (&rng,RAID6_KUNIT_SEED ); + +/* +* Allocate the test buffer using vmalloc() with a page-aligned length +* so that it is immediately followed by a guard page. This allows +* buffer overreads to be detected, even in assembly code. +*/ +for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) { + test_recov_buffers[i] =vmalloc (PAGE_SIZE ); +if (!test_recov_buffers[i]) + goto out_free_recov_buffers; + } +for (i =0 ; i <NDISKS ; i++) { + test_buffers[i] =vmalloc (PAGE_SIZE ); +if (!test_buffers[i]) + goto out_free_buffers; + } +makedata (0 ,NDISKS -1 ); +return 0 ; + +out_free_buffers: +for (i =0 ; i <NDISKS ; i++) +vfree (test_buffers[i]); +memset (test_buffers,0 ,sizeof (test_buffers)); +out_free_recov_buffers: +for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) +vfree (test_recov_buffers[i]); +memset (test_recov_buffers,0 ,sizeof (test_recov_buffers)); +return -ENOMEM ; +} + +static void raid6_suite_exit (struct kunit_suite *suite) +{ +int i; + +for (i =0 ; i <NDISKS ; i++) +vfree (test_buffers[i]); +memset (test_buffers,0 ,sizeof (test_buffers)); +for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) +vfree (test_recov_buffers[i]); +memset (test_recov_buffers,0 ,sizeof (test_recov_buffers)); }static struct kunit_suite raid6_test_suite = { .name ="raid6" , .test_cases = raid6_test_cases, .suite_init = raid6_suite_init, + .suite_exit = raid6_suite_exit, };kunit_test_suite (raid6_test_suite);
Signature · 1 line
2.53.0
PATCH 16/18 raid6_kunit: cleanup dataptr handling
In reply to Christoph HellwigMove the global dataptr array into test_recover() as all sites that fill data or parity can use test_buffers directly, and this localized the override for the failed slots to the recovery testing routine.
--- lib/raid/raid6/tests/raid6_kunit.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
lib/raid/raid6/tests/raid6_kunit.c +7 -12
@@ -18,7 +18,6 @@ MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");#define NDISKS 16/* Including P and Q */ static struct rnd_state rng; -static void *dataptrs[NDISKS ];static void *test_buffers[NDISKS ];static void *test_recov_buffers[RAID6_KUNIT_MAX_FAILURES ];
@@ -35,10 +34,8 @@ static void makedata(int start, int stop) {int i; -for (i = start; i <= stop; i++) { +for (i = start; i <= stop; i++)prandom_bytes_state (&rng, test_buffers[i],PAGE_SIZE ); - dataptrs[i] = test_buffers[i]; - } }static char member_type (int d)
@@ -56,11 +53,13 @@ static char member_type(int d)static void test_recover (struct kunit *test,int faila,int failb) {const struct test_args *ta = test->param_value; +void *dataptrs[NDISKS ];int i;for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++)memset (test_recov_buffers[i],0xf0 ,PAGE_SIZE ); +memcpy (dataptrs, test_buffers,sizeof (dataptrs)); dataptrs[faila] = test_recov_buffers[0 ]; dataptrs[failb] = test_recov_buffers[1 ];
@@ -70,7 +69,7 @@ static void test_recover(struct kunit *test, int faila, int failb)* is equivalent to a RAID-5 failure (XOR, then recompute Q). */ if (faila !=NDISKS -2 ) - goto skip; +return ;/* P+Q failure. Just rebuild the syndrome. */ ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , dataptrs);
@@ -92,10 +91,6 @@ static void test_recover(struct kunit *test, int faila, int failb)"failb miscompared: %3d[%c] (faila=%3d[%c])\n" , failb,member_type (failb), faila, member_type(faila)); - -skip: - dataptrs[faila] = test_buffers[faila]; - dataptrs[failb] = test_buffers[failb]; }static void raid6_test (struct kunit *test)
@@ -108,7 +103,7 @@ static void raid6_test(struct kunit *test)memset (test_buffers[NDISKS -1 ],0xee ,PAGE_SIZE );/* Generate assumed good syndrome */ - ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , (void **)&dataptrs); + ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , test_buffers);for (i =0 ; i <NDISKS -1 ; i++)for (j = i +1 ; j <NDISKS ; j++)
@@ -121,10 +116,10 @@ static void raid6_test(struct kunit *test)for (p2 = p1; p2 <NDISKS -2 ; p2++) {/* Simulate rmw run */ ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - (void **)&dataptrs); + test_buffers);makedata (p1, p2); ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - (void **)&dataptrs); + test_buffers);for (i =0 ; i <NDISKS -1 ; i++)for (j = i +1 ; j <NDISKS ; j++)
Signature · 1 line
2.53.0
PATCH 17/18 raid6_kunit: randomize parameters and increase limits
In reply to Christoph HellwigThe current test has double-quadratic behavior in the selection for the updated ("XORed") disks, and in the selection of updated pointers, which makes scaling it to more tests difficult. At the same time it only ever tests with the maximum number of disks, which leaves a coverage hole for smaller ones.
Fix this by randomizing the total number, failed disks and regions to update, and increasing the upper number of tests disks.
--- lib/raid/raid6/tests/raid6_kunit.c | 189 ++++++++++++++++++++--------- 1 file changed, 131 insertions(+), 58 deletions(-)
lib/raid/raid6/tests/raid6_kunit.c +131 -58
@@ -8,18 +8,21 @@#include <kunit/test.h> #include <linux/prandom.h> #include <linux/vmalloc.h> +#include <linux/raid/pq.h> #include "../algos.h" MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" );#define RAID6_KUNIT_SEED 42 +#define RAID6_KUNIT_NUM_TEST_ITERS 10 +#define RAID6_KUNIT_MAX_BUFFERS 64/* Including P and Q */ #define RAID6_KUNIT_MAX_FAILURES 2 - -#define NDISKS 16/* Including P and Q */ +#define RAID6_KUNIT_MAX_BYTES PAGE_SIZEstatic struct rnd_state rng; -static void *test_buffers[NDISKS ]; +static void *test_buffers[RAID6_KUNIT_MAX_BUFFERS ];static void *test_recov_buffers[RAID6_KUNIT_MAX_FAILURES ]; +static size_t test_buflen;struct test_args {unsigned int recov_idx;
@@ -30,102 +33,171 @@ struct test_args {static struct test_args args; +static u32 rand32 (void ) +{ +return prandom_u32_state (&rng); +} + +/* Generate a random length that is a multiple of 512. */ +static unsigned int random_length (unsigned int max_length) +{ +return round_up ((rand32 () % max_length) +1 ,512 ); +} + +static unsigned int random_nr_buffers (void ) +{ +return (rand32 () % (RAID6_KUNIT_MAX_BUFFERS - (RAID6_MIN_DISKS -1 ))) + +RAID6_MIN_DISKS ; +} +static void makedata (int start,int stop) {int i;for (i = start; i <= stop; i++) -prandom_bytes_state (&rng, test_buffers[i],PAGE_SIZE ); +prandom_bytes_state (&rng, test_buffers[i], test_buflen); } -static char member_type (int d) +static char member_type (unsigned int nr_buffers,int d) { -switch (d) { -case NDISKS -2 : +if (d == nr_buffers -2 )return 'P' ; -case NDISKS -1 : +if (d == nr_buffers -1 )return 'Q' ; -default : -return 'D' ; - } +return 'D' ; } -static void test_recover (struct kunit *test,int faila,int failb) +static void test_recover_one (struct kunit *test,unsigned int nr_buffers, +unsigned int len,int faila,int failb) {const struct test_args *ta = test->param_value; -void *dataptrs[NDISKS ]; +void *dataptrs[RAID6_KUNIT_MAX_BUFFERS ];int i; +if (faila > failb) +swap (faila, failb); +for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) -memset (test_recov_buffers[i],0xf0 ,PAGE_SIZE ); +memset (test_recov_buffers[i],0xf0 , test_buflen);memcpy (dataptrs, test_buffers,sizeof (dataptrs)); dataptrs[faila] = test_recov_buffers[0 ]; dataptrs[failb] = test_recov_buffers[1 ]; -if (failb ==NDISKS -1 ) { +if (failb == nr_buffers -1 ) {/* * We don't implement the data+Q failure scenario, since it * is equivalent to a RAID-5 failure (XOR, then recompute Q). */ -if (faila !=NDISKS -2 ) +if (WARN_ON_ONCE (faila != nr_buffers -2 ))return ;/* P+Q failure. Just rebuild the syndrome. */ - ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , dataptrs); - }else if (failb ==NDISKS -2 ) { + ta->gen->gen_syndrome (nr_buffers, len, dataptrs); + }else if (failb == nr_buffers -2 ) {/* data+P failure. */ - ta->recov->datap (NDISKS ,PAGE_SIZE , faila, dataptrs); + ta->recov->datap (nr_buffers, len, faila, dataptrs); }else {/* data+data failure. */ - ta->recov->data2 (NDISKS ,PAGE_SIZE , faila, failb, dataptrs); + ta->recov->data2 (nr_buffers, len, faila, failb, dataptrs); }KUNIT_EXPECT_MEMEQ_MSG (test, test_buffers[faila], test_recov_buffers[0 ], -PAGE_SIZE , -"faila miscompared: %3d[%c] (failb=%3d[%c])\n" , - faila,member_type (faila), - failb,member_type (failb)); + len, +"faila miscompared: %3d[%c] buffers %u len %u (failb=%3d[%c])\n" , + faila,member_type (nr_buffers, faila), + nr_buffers, len, + failb,member_type (nr_buffers, failb));KUNIT_EXPECT_MEMEQ_MSG (test, test_buffers[failb], test_recov_buffers[1 ], -PAGE_SIZE , -"failb miscompared: %3d[%c] (faila=%3d[%c])\n" , - failb,member_type (failb), - faila,member_type (faila)); + len, +"failb miscompared: %3d[%c] buffers %u len %u (faila=%3d[%c])\n" , + failb,member_type (nr_buffers, failb), + nr_buffers, len, + faila,member_type (nr_buffers, faila)); } -static void raid6_test (struct kunit *test) +static void test_recover (struct kunit *test,unsigned int nr_buffers, +unsigned int len) +{ +unsigned int nr_data = nr_buffers -2 ; +int iterations, i; + +/* Test P+Q recovery */ +test_recover_one (test, nr_buffers, len, nr_data, nr_buffers -1 ); + +/* Test data+P recovery */ +for (i =0 ; i < nr_buffers -2 ; i++) +test_recover_one (test, nr_buffers, len, i, nr_data); + +/* Double data failure is impossible with a single data disk */ +if (nr_data ==1 ) +return ; + +/* Test data+data recovery using random sampling */ + iterations = nr_buffers *2 ;/* should provide good enough coverage */ +for (i =0 ; i < iterations; i++) { +int faila =rand32 () % nr_data, failb; + +do { + failb =rand32 () % nr_data; + }while (failb == faila); + +test_recover_one (test, nr_buffers, len, faila, failb); + } +} + +/* Simulate rmw run */ +static void test_rmw_one (struct kunit *test,unsigned int nr_buffers, +unsigned int len,int p1,int p2) {const struct test_args *ta = test->param_value; -int i, j, p1, p2; + + ta->gen->xor_syndrome (nr_buffers, p1, p2, len, test_buffers); +makedata (p1, p2); + ta->gen->xor_syndrome (nr_buffers, p1, p2, len, test_buffers); +test_recover (test, nr_buffers, len); +} + +static void test_rmw (struct kunit *test,unsigned int nr_buffers, +unsigned int len) +{ +int iterations = nr_buffers /2 , i; + +for (i =0 ; i < iterations; i++) { +int p1 =rand32 () % (nr_buffers -2 ); +int p2 =rand32 () % (nr_buffers -2 ); + +if (p2 < p1) +swap (p1, p2); +test_rmw_one (test, nr_buffers, len, p1, p2); + } +} + +static void raid6_test_one (struct kunit *test) +{ +const struct test_args *ta = test->param_value; +unsigned int nr_buffers =random_nr_buffers (); +unsigned int len =random_length (RAID6_KUNIT_MAX_BYTES );/* Nuke syndromes */ -memset (test_buffers[NDISKS -2 ],0xee ,PAGE_SIZE ); -memset (test_buffers[NDISKS -1 ],0xee ,PAGE_SIZE ); +memset (test_buffers[nr_buffers -2 ],0xee , test_buflen); +memset (test_buffers[nr_buffers -1 ],0xee , test_buflen);/* Generate assumed good syndrome */ - ta->gen->gen_syndrome (NDISKS ,PAGE_SIZE , test_buffers); + ta->gen->gen_syndrome (nr_buffers, len, test_buffers); -for (i =0 ; i <NDISKS -1 ; i++) -for (j = i +1 ; j <NDISKS ; j++) -test_recover (test, i, j); +test_recover (test, nr_buffers, len); -if (!ta->gen->xor_syndrome) -return ; +if (ta->gen->xor_syndrome) +test_rmw (test, nr_buffers, len); +} -for (p1 =0 ; p1 <NDISKS -2 ; p1++) { -for (p2 = p1; p2 <NDISKS -2 ; p2++) { -/* Simulate rmw run */ - ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - test_buffers); -makedata (p1, p2); - ta->gen->xor_syndrome (NDISKS , p1, p2,PAGE_SIZE , - test_buffers); - -for (i =0 ; i <NDISKS -1 ; i++) -for (j = i +1 ; j <NDISKS ; j++) -test_recover (test, i, j); - } - } +static void raid6_test (struct kunit *test) +{ +int i; + +for (i =0 ; i <RAID6_KUNIT_NUM_TEST_ITERS ; i++) +raid6_test_one (test); } static const void *raid6_gen_params(struct kunit *test, const void *prev,
@@ -169,23 +241,24 @@ static int raid6_suite_init(struct kunit_suite *suite)* so that it is immediately followed by a guard page. This allows * buffer overreads to be detected, even in assembly code. */ + test_buflen =round_up (RAID6_KUNIT_MAX_BYTES ,PAGE_SIZE );for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++) { - test_recov_buffers[i] =vmalloc (PAGE_SIZE ); + test_recov_buffers[i] =vmalloc (test_buflen);if (!test_recov_buffers[i]) goto out_free_recov_buffers; } -for (i =0 ; i <NDISKS ; i++) { - test_buffers[i] =vmalloc (PAGE_SIZE ); +for (i =0 ; i <RAID6_KUNIT_MAX_BUFFERS ; i++) { + test_buffers[i] =vmalloc (test_buflen);if (!test_buffers[i]) goto out_free_buffers; } -makedata (0 ,NDISKS -1 ); +makedata (0 ,RAID6_KUNIT_MAX_BUFFERS -1 );return 0 ; out_free_buffers: -for (i =0 ; i <NDISKS ; i++) +for (i =0 ; i <RAID6_KUNIT_MAX_BUFFERS ; i++)vfree (test_buffers[i]);memset (test_buffers,0 ,sizeof (test_buffers)); out_free_recov_buffers:
@@ -199,7 +272,7 @@ static void raid6_suite_exit(struct kunit_suite *suite) {int i; -for (i =0 ; i <NDISKS ; i++) +for (i =0 ; i <RAID6_KUNIT_MAX_BUFFERS ; i++)vfree (test_buffers[i]);memset (test_buffers,0 ,sizeof (test_buffers));for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++)
Signature · 1 line
2.53.0
PATCH 18/18 raid6_kunit: randomize buffer alignment
In reply to Christoph HellwigAdd code to add random alignment to the buffers to test the case where they are not page aligned, and to move the buffers to the end of the allocation so that they are next to the vmalloc guard page.
This does not include the recovery buffers as the recovery requires page alignment.
--- lib/raid/raid6/tests/raid6_kunit.c | 41 +++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-)
lib/raid/raid6/tests/raid6_kunit.c +35 -6
@@ -21,6 +21,7 @@ MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");static struct rnd_state rng;static void *test_buffers[RAID6_KUNIT_MAX_BUFFERS ]; +static void *aligned_buffers[RAID6_KUNIT_MAX_BUFFERS ];static void *test_recov_buffers[RAID6_KUNIT_MAX_FAILURES ];static size_t test_buflen;
@@ -50,6 +51,14 @@ static unsigned int random_nr_buffers(void)RAID6_MIN_DISKS ; } +/* Generate a random alignment that is a multiple of 64. */ +static unsigned int random_alignment (unsigned int max_alignment) +{ +if (max_alignment ==0 ) +return 0 ; +return (rand32 () % (max_alignment +1 )) & ~63 ; +} +static void makedata (int start,int stop) {int i;
@@ -80,7 +89,7 @@ static void test_recover_one(struct kunit *test, unsigned int nr_buffers,for (i =0 ; i <RAID6_KUNIT_MAX_FAILURES ; i++)memset (test_recov_buffers[i],0xf0 , test_buflen); -memcpy (dataptrs, test_buffers,sizeof (dataptrs)); +memcpy (dataptrs, aligned_buffers,sizeof (dataptrs)); dataptrs[faila] = test_recov_buffers[0 ]; dataptrs[failb] = test_recov_buffers[1 ];
@@ -102,13 +111,13 @@ static void test_recover_one(struct kunit *test, unsigned int nr_buffers, ta->recov->data2 (nr_buffers, len, faila, failb, dataptrs); } -KUNIT_EXPECT_MEMEQ_MSG (test, test_buffers[faila], test_recov_buffers[0 ], +KUNIT_EXPECT_MEMEQ_MSG (test, aligned_buffers[faila], dataptrs[faila], len,"faila miscompared: %3d[%c] buffers %u len %u (failb=%3d[%c])\n" , faila,member_type (nr_buffers, faila), nr_buffers, len, failb,member_type (nr_buffers, failb)); - KUNIT_EXPECT_MEMEQ_MSG(test, test_buffers[failb], test_recov_buffers[1], + KUNIT_EXPECT_MEMEQ_MSG(test, aligned_buffers[failb], dataptrs[failb], len, "failb miscompared: %3d[%c] buffers %u len %u (faila=%3d[%c])\n", failb, member_type(nr_buffers, failb),
@@ -152,9 +161,9 @@ static void test_rmw_one(struct kunit *test, unsigned int nr_buffers, {const struct test_args *ta = test->param_value; - ta->gen->xor_syndrome (nr_buffers, p1, p2, len, test_buffers); + ta->gen->xor_syndrome (nr_buffers, p1, p2, len, aligned_buffers);makedata (p1, p2); - ta->gen->xor_syndrome (nr_buffers, p1, p2, len, test_buffers); + ta->gen->xor_syndrome (nr_buffers, p1, p2, len, aligned_buffers);test_recover (test, nr_buffers, len); }
@@ -178,13 +187,33 @@ static void raid6_test_one(struct kunit *test)const struct test_args *ta = test->param_value;unsigned int nr_buffers =random_nr_buffers ();unsigned int len =random_length (RAID6_KUNIT_MAX_BYTES ); +unsigned int max_alignment; +int i;/* Nuke syndromes */ memset (test_buffers[nr_buffers -2 ],0xee , test_buflen);memset (test_buffers[nr_buffers -1 ],0xee , test_buflen); +/* +* If we're not using the entire buffer size, inject randomize alignment +* into the buffer. +*/ + max_alignment =RAID6_KUNIT_MAX_BYTES - len; +if (rand32 () %2 ==0 ) { +/* Use random alignments mod 64 */ +for (i =0 ; i < nr_buffers; i++) + aligned_buffers[i] = test_buffers[i] + +random_alignment (max_alignment); + }else { +/* Go up to the guard page, to catch buffer overreads */ +unsigned int align = test_buflen - len; + +for (i =0 ; i < nr_buffers; i++) + aligned_buffers[i] = test_buffers[i] + align; + } +/* Generate assumed good syndrome */ - ta->gen->gen_syndrome (nr_buffers, len, test_buffers); + ta->gen->gen_syndrome (nr_buffers, len, aligned_buffers);test_recover (test, nr_buffers, len);
Signature · 1 line
2.53.0
Andrew Morton
maintainerQuoted 6 lines · On Mon, 18 May 2026 07:17:43 +0200 Christoph Hellwig <[email protected]> wrote:
this series cleans up the RAID6 P/Q library to match the recent updates to the RAID 5 XOR library and other CRC/crypto libraries. This includes providing properly documented external interfaces, hiding the internals, using
static_callinstead of indirect calls and turning the user space test suite into an in-kernel kunit test which is also extended to improve coverage.
Cool, I'll add this to mm.git's mm-nonmm-unstable branch for some linux-next testing.
AI review found quite a lot to talk about:
https://sashiko.dev/#/patchset/[email protected]
Quoted 5 lines · Andrew Morton
Cool, I'll add this to mm.git's mm-nonmm-unstable branch for some linux-next testing.
AI review found quite a lot to talk about:
https://sashiko.dev/#/patchset/[email protected]
Not a lot of it is very useful, though:
raid6: turn the userspace test harness into a kunit test
- complains about basically adding need_resched, which we've decided we won't do now that we have lazy preempt. This is probably going to come up in lots of places because of the old training data
raid6: use named initializers for struct raid6_calls
- whining about keeping totally pointless comments
raid6: warn when using less than four devices
- complains about warning for btrfs which is clearly documented as the outcome in the commit log
- and also complaining that the enforcement isn't hard enough, but the WARN_ON is the best we can do here
raid6: rework registration of optimized algorithms
- less registration causing less kunit coverage: that's intentional as it keeps testing time down and similar to other arch optimized tests in crc and crypto code. It also doesn't really reduce coverage as before this series there was none.
raid6: use static_call for gen_syndrom and xor_syndrom
- doesn't seem to know that bool fails when an initcall fails
raid6_kunit: use KUNIT_CASE_PARAM
- whining about the code style. I don't really like it either, but the kunit case stuff is a mess
There are a few somewhat useful things, though.
raid6: hide internals
- yes, the -I is duplicate and should be fixed
raid6: rework registration of optimized algorithms
- avx2 instead of avx512 is probably the right thing for no benchmarking, but if it was intentional (it wasn't), that should be document. So I'll just switch back to the previous version to keep the state of the art
Quoted 7 lines · Christoph Hellwig
raid6: rework registration of optimized algorithms
- avx2 instead of avx512 is probably the right thing for no benchmarking, but if it was intentional (it wasn't), that should be document. So I'll just switch back to the previous version to keep the state of the art
It is unlikely to be the right thing *going forward*, though.
The very unfortunate performance inversion is likely model-specific. It is one of those things where you largely would have to have a list of quirks :(
-hpa
Quoted 9 lines · H. Peter Anvin
Quoted 7 lines · Christoph Hellwig
raid6: rework registration of optimized algorithms
- avx2 instead of avx512 is probably the right thing for no benchmarking, but if it was intentional (it wasn't), that should be document. So I'll just switch back to the previous version to keep the state of the art
Quoted 4 lines
It is unlikely to be the right thing *going forward*, though.
The very unfortunate performance inversion is likely model-specific. It is one of those things where you largely would have to have a list of quirks :(
Note that the default is still to benchmark the implementations. This is just about the case where the user explicitly disabled that benchmark-based selection.
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · H. Peter Anvin
Quoted 7 lines · Christoph Hellwig
raid6: rework registration of optimized algorithms
- avx2 instead of avx512 is probably the right thing for no benchmarking, but if it was intentional (it wasn't), that should be document. So I'll just switch back to the previous version to keep the state of the art
Quoted 9 lines
Quoted 4 lines
It is unlikely to be the right thing *going forward*, though.
The very unfortunate performance inversion is likely model-specific. It is one of those things where you largely would have to have a list of quirks :(
Note that the default is still to benchmark the implementations. This is just about the case where the user explicitly disabled that benchmark-based selection.
The real issue though is that the benchmarking isn't really helpful, either.
It has to do with power across the whole chip, so it perversely enough depends on what *else* is going on...
Quoted 3 lines · H. Peter Anvin
The real issue though is that the benchmarking isn't really helpful, either.
It has to do with power across the whole chip, so it perversely enough depends on what *else* is going on...
Yes. And preferences might matter if this is just a file server or something running a real workload as well. But I don't really have a good answer to that.