From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 527B93033DE; Tue, 12 May 2026 05:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778563544; cv=none; b=tHo6qm/cTVSVz4ncLy4bx6897RT9LCKZj+ZPzD/nyFeymRGK0fGsKO7YOCwu1HrwjnWbwxOG9zOJ259hR2XOiGsgxwK5bo2VJcUvCatue9FtUTPT6JjOU0VTj4q91a78OfX/AUVuLsAEFvX9CscaWX+d0lCShHKZnQt4uCxU06o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778563544; c=relaxed/simple; bh=eV9B5M5ab5h2w+O/rqLHjGjiwOtsdCjuifF4hOEBmpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sb1k46Z3B/oAncQG9+L5sKfg3j288AHSC5pzEhy2smosyetK6qrvpPm40Oixw/WDHxjjOYBjpZMYGSSb8alGGsjknbaeHTHtn1Ml88sf9+s8Jhk67zJosMUXBFveyJUIu4YMiWfiBmTwsB23Px/p0gr9A4+ZLiBY8nXMgpMHUdk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=P4eoRFDX; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="P4eoRFDX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=vl+5mowQ+IWT1EcswY0gHPiW2UKDQbjNZxRcxx/c7vs=; b=P4eoRFDXfUg+guOXW5a420ZkIg HzEjY12fqFbJjg7rIYbq/1j4rI5j5QjXDg7wwjvZuktffMZq0+hD4Y9Yd7rmywZsSNq1VV+ZCkaFH 11aLh1v6lnQLp4FDt6uaX00LDKmz9BgoZOFt8KaZc38j/vGT6HsKTS1MbpeKbEkY/bWSZxmwnsiMj 2M2lLDNgXcJFfZxl9hrXLRORIdbnF0U3arYUIUMCHOHmlgNbLGWhIMQxUTDW0EHMFh+KYYqOPNz4b NXiDz2fRGbZDLZb0X/zbTW5TK3QyWIYbrqZPB8RLRdvu+BqMVLIjaGVGwilnzUN+rHZ8C5oY9ULr+ m4lzLRWg==; Received: from 2a02-8389-2341-5b80-decc-1a96-daaa-a2cc.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:decc:1a96:daaa:a2cc] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMfca-0000000FckH-298U; Tue, 12 May 2026 05:25:32 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Huacai Chen , WANG Xuerui , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Herbert Xu , Dan Williams , Chris Mason , David Sterba , Arnd Bergmann , Song Liu , Yu Kuai , Li Nan , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-crypto@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-arch@vger.kernel.org, linux-raid@vger.kernel.org Subject: [PATCH 15/19] raid6_kunit: dynamically allocate data buffers using vmalloc Date: Tue, 12 May 2026 07:20:55 +0200 Message-ID: <20260512052230.2947683-16-hch@lst.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260512052230.2947683-1-hch@lst.de> References: <20260512052230.2947683-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Use 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. Signed-off-by: Christoph Hellwig --- lib/raid/raid6/tests/raid6_kunit.c | 77 ++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/lib/raid/raid6/tests/raid6_kunit.c b/lib/raid/raid6/tests/raid6_kunit.c index f55b081b6b13..a4b65ccc9d20 100644 --- a/lib/raid/raid6/tests/raid6_kunit.c +++ b/lib/raid/raid6/tests/raid6_kunit.c @@ -7,19 +7,20 @@ #include #include +#include #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); -- 2.53.0