mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 03:27:30 -04:00
raid6_kunit: randomize buffer alignment
Add 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. Link: https://lore.kernel.org/20260518051804.462141-19-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>
This commit is contained in:
committed by
Andrew Morton
parent
fa0c812c0a
commit
8cf0a6c4bb
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user