2019-05-29 23:57:49 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-07-14 19:20:37 +00:00
|
|
|
/*
|
|
|
|
* asynchronous raid6 recovery self test
|
|
|
|
* Copyright (c) 2009, Intel Corporation.
|
|
|
|
*
|
|
|
|
* based on drivers/md/raid6test/test.c:
|
|
|
|
* Copyright 2002-2007 H. Peter Anvin
|
|
|
|
*/
|
|
|
|
#include <linux/async_tx.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2011-06-16 11:01:34 +00:00
|
|
|
#include <linux/mm.h>
|
2009-07-14 19:20:37 +00:00
|
|
|
#include <linux/random.h>
|
2011-05-27 18:41:48 +00:00
|
|
|
#include <linux/module.h>
|
2009-07-14 19:20:37 +00:00
|
|
|
|
|
|
|
#undef pr
|
|
|
|
#define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
|
|
|
|
|
2013-11-13 19:22:26 +00:00
|
|
|
#define NDISKS 64 /* Including P and Q */
|
2009-07-14 19:20:37 +00:00
|
|
|
|
|
|
|
static struct page *dataptrs[NDISKS];
|
2020-08-20 13:22:10 +00:00
|
|
|
unsigned int dataoffs[NDISKS];
|
2009-09-17 04:03:29 +00:00
|
|
|
static addr_conv_t addr_conv[NDISKS];
|
2009-07-14 19:20:37 +00:00
|
|
|
static struct page *data[NDISKS+3];
|
|
|
|
static struct page *spare;
|
|
|
|
static struct page *recovi;
|
|
|
|
static struct page *recovj;
|
|
|
|
|
|
|
|
static void callback(void *param)
|
|
|
|
{
|
|
|
|
struct completion *cmp = param;
|
|
|
|
|
|
|
|
complete(cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void makedata(int disks)
|
|
|
|
{
|
2013-04-29 23:21:24 +00:00
|
|
|
int i;
|
2009-07-14 19:20:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < disks; i++) {
|
2022-10-05 15:49:46 +00:00
|
|
|
get_random_bytes(page_address(data[i]), PAGE_SIZE);
|
2009-07-14 19:20:37 +00:00
|
|
|
dataptrs[i] = data[i];
|
2020-08-20 13:22:10 +00:00
|
|
|
dataoffs[i] = 0;
|
2009-07-14 19:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char disk_type(int d, int disks)
|
|
|
|
{
|
|
|
|
if (d == disks - 2)
|
|
|
|
return 'P';
|
|
|
|
else if (d == disks - 1)
|
|
|
|
return 'Q';
|
|
|
|
else
|
|
|
|
return 'D';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recover two failed blocks. */
|
2020-08-20 13:22:10 +00:00
|
|
|
static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb,
|
|
|
|
struct page **ptrs, unsigned int *offs)
|
2009-07-14 19:20:37 +00:00
|
|
|
{
|
|
|
|
struct async_submit_ctl submit;
|
|
|
|
struct completion cmp;
|
|
|
|
struct dma_async_tx_descriptor *tx = NULL;
|
|
|
|
enum sum_check_flags result = ~0;
|
|
|
|
|
|
|
|
if (faila > failb)
|
|
|
|
swap(faila, failb);
|
|
|
|
|
|
|
|
if (failb == disks-1) {
|
|
|
|
if (faila == disks-2) {
|
|
|
|
/* P+Q failure. Just rebuild the syndrome. */
|
|
|
|
init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_gen_syndrome(ptrs, offs,
|
|
|
|
disks, bytes, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
} else {
|
2018-06-01 20:20:16 +00:00
|
|
|
struct page *blocks[NDISKS];
|
2009-07-14 19:20:37 +00:00
|
|
|
struct page *dest;
|
|
|
|
int count = 0;
|
|
|
|
int i;
|
|
|
|
|
2018-06-01 20:20:16 +00:00
|
|
|
BUG_ON(disks > NDISKS);
|
|
|
|
|
2009-07-14 19:20:37 +00:00
|
|
|
/* data+Q failure. Reconstruct data from P,
|
|
|
|
* then rebuild syndrome
|
|
|
|
*/
|
|
|
|
for (i = disks; i-- ; ) {
|
|
|
|
if (i == faila || i == failb)
|
|
|
|
continue;
|
|
|
|
blocks[count++] = ptrs[i];
|
|
|
|
}
|
|
|
|
dest = ptrs[faila];
|
|
|
|
init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, NULL,
|
|
|
|
NULL, NULL, addr_conv);
|
|
|
|
tx = async_xor(dest, blocks, 0, count, bytes, &submit);
|
|
|
|
|
|
|
|
init_async_submit(&submit, 0, tx, NULL, NULL, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_gen_syndrome(ptrs, offs,
|
|
|
|
disks, bytes, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (failb == disks-2) {
|
|
|
|
/* data+P failure. */
|
|
|
|
init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_raid6_datap_recov(disks, bytes,
|
2020-08-20 13:22:11 +00:00
|
|
|
faila, ptrs, offs, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
} else {
|
|
|
|
/* data+data failure. */
|
|
|
|
init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_raid6_2data_recov(disks, bytes,
|
2020-08-20 13:22:11 +00:00
|
|
|
faila, failb, ptrs, offs, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
init_completion(&cmp);
|
|
|
|
init_async_submit(&submit, ASYNC_TX_ACK, tx, callback, &cmp, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_syndrome_val(ptrs, offs,
|
|
|
|
disks, bytes, &result, spare, 0, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
async_tx_issue_pending(tx);
|
|
|
|
|
|
|
|
if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0)
|
|
|
|
pr("%s: timeout! (faila: %d failb: %d disks: %d)\n",
|
|
|
|
__func__, faila, failb, disks);
|
|
|
|
|
|
|
|
if (result != 0)
|
|
|
|
pr("%s: validation failure! faila: %d failb: %d sum_check_flags: %x\n",
|
|
|
|
__func__, faila, failb, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_disks(int i, int j, int disks)
|
|
|
|
{
|
|
|
|
int erra, errb;
|
|
|
|
|
|
|
|
memset(page_address(recovi), 0xf0, PAGE_SIZE);
|
|
|
|
memset(page_address(recovj), 0xba, PAGE_SIZE);
|
|
|
|
|
|
|
|
dataptrs[i] = recovi;
|
|
|
|
dataptrs[j] = recovj;
|
|
|
|
|
2020-08-20 13:22:10 +00:00
|
|
|
raid6_dual_recov(disks, PAGE_SIZE, i, j, dataptrs, dataoffs);
|
2009-07-14 19:20:37 +00:00
|
|
|
|
|
|
|
erra = memcmp(page_address(data[i]), page_address(recovi), PAGE_SIZE);
|
|
|
|
errb = memcmp(page_address(data[j]), page_address(recovj), PAGE_SIZE);
|
|
|
|
|
|
|
|
pr("%s(%d, %d): faila=%3d(%c) failb=%3d(%c) %s\n",
|
|
|
|
__func__, i, j, i, disk_type(i, disks), j, disk_type(j, disks),
|
|
|
|
(!erra && !errb) ? "OK" : !erra ? "ERRB" : !errb ? "ERRA" : "ERRAB");
|
|
|
|
|
|
|
|
dataptrs[i] = data[i];
|
|
|
|
dataptrs[j] = data[j];
|
|
|
|
|
|
|
|
return erra || errb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test(int disks, int *tests)
|
|
|
|
{
|
|
|
|
struct dma_async_tx_descriptor *tx;
|
|
|
|
struct async_submit_ctl submit;
|
|
|
|
struct completion cmp;
|
|
|
|
int err = 0;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
recovi = data[disks];
|
|
|
|
recovj = data[disks+1];
|
|
|
|
spare = data[disks+2];
|
|
|
|
|
|
|
|
makedata(disks);
|
|
|
|
|
|
|
|
/* Nuke syndromes */
|
|
|
|
memset(page_address(data[disks-2]), 0xee, PAGE_SIZE);
|
|
|
|
memset(page_address(data[disks-1]), 0xee, PAGE_SIZE);
|
|
|
|
|
|
|
|
/* Generate assumed good syndrome */
|
|
|
|
init_completion(&cmp);
|
|
|
|
init_async_submit(&submit, ASYNC_TX_ACK, NULL, callback, &cmp, addr_conv);
|
2020-08-20 13:22:10 +00:00
|
|
|
tx = async_gen_syndrome(dataptrs, dataoffs, disks, PAGE_SIZE, &submit);
|
2009-07-14 19:20:37 +00:00
|
|
|
async_tx_issue_pending(tx);
|
|
|
|
|
|
|
|
if (wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000)) == 0) {
|
|
|
|
pr("error: initial gen_syndrome(%d) timed out\n", disks);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr("testing the %d-disk case...\n", disks);
|
|
|
|
for (i = 0; i < disks-1; i++)
|
|
|
|
for (j = i+1; j < disks; j++) {
|
|
|
|
(*tests)++;
|
|
|
|
err += test_disks(i, j, disks);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-15 03:36:15 +00:00
|
|
|
static int __init raid6_test(void)
|
2009-07-14 19:20:37 +00:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int tests = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NDISKS+3; i++) {
|
|
|
|
data[i] = alloc_page(GFP_KERNEL);
|
|
|
|
if (!data[i]) {
|
|
|
|
while (i--)
|
|
|
|
put_page(data[i]);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the 4-disk and 5-disk cases are special for the recovery code */
|
|
|
|
if (NDISKS > 4)
|
|
|
|
err += test(4, &tests);
|
|
|
|
if (NDISKS > 5)
|
|
|
|
err += test(5, &tests);
|
2009-12-17 20:55:38 +00:00
|
|
|
/* the 11 and 12 disk cases are special for ioatdma (p-disabled
|
|
|
|
* q-continuation without extended descriptor)
|
|
|
|
*/
|
|
|
|
if (NDISKS > 12) {
|
|
|
|
err += test(11, &tests);
|
|
|
|
err += test(12, &tests);
|
|
|
|
}
|
2013-11-13 19:22:26 +00:00
|
|
|
|
2022-02-21 22:31:18 +00:00
|
|
|
/* the 24 disk case is special for ioatdma as it is the boundary point
|
2013-11-13 19:22:26 +00:00
|
|
|
* at which it needs to switch from 8-source ops to 16-source
|
|
|
|
* ops for continuation (assumes DMA_HAS_PQ_CONTINUE is not set)
|
|
|
|
*/
|
|
|
|
if (NDISKS > 24)
|
|
|
|
err += test(24, &tests);
|
|
|
|
|
2009-07-14 19:20:37 +00:00
|
|
|
err += test(NDISKS, &tests);
|
|
|
|
|
|
|
|
pr("\n");
|
|
|
|
pr("complete (%d tests, %d failure%s)\n",
|
|
|
|
tests, err, err == 1 ? "" : "s");
|
|
|
|
|
|
|
|
for (i = 0; i < NDISKS+3; i++)
|
|
|
|
put_page(data[i]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-15 03:36:15 +00:00
|
|
|
static void __exit raid6_test_exit(void)
|
2009-07-14 19:20:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when compiled-in wait for drivers to load first (assumes dma drivers
|
2022-02-21 22:31:18 +00:00
|
|
|
* are also compiled-in)
|
2009-07-14 19:20:37 +00:00
|
|
|
*/
|
|
|
|
late_initcall(raid6_test);
|
|
|
|
module_exit(raid6_test_exit);
|
|
|
|
MODULE_AUTHOR("Dan Williams <dan.j.williams@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("asynchronous RAID-6 recovery self tests");
|
|
|
|
MODULE_LICENSE("GPL");
|