]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
raid6: use static_call for gen_syndrom and xor_syndrom
authorChristoph Hellwig <hch@lst.de>
Mon, 18 May 2026 05:17:54 +0000 (07:17 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:24:55 +0000 (21:24 -0700)
Avoid indirect calls for P/Q parity generation.

Link: https://lore.kernel.org/20260518051804.462141-12-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Ard Biesheuvel <ardb@kernel.org> # kunit only on arm64
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Mason <clm@fb.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Sterba <dsterba@suse.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Li Nan <linan122@huawei.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Song Liu <song@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/raid/raid6/algos.c

index 30d7cb34874fb70874f8b6eb08c89c8f71a755e9..ff99202cad46950e1ca166cf1d9855d0006e2a12 100644 (file)
@@ -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;
        }