All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/slub, kunit: Make slub_kunit pass even when SLAB_RED_ZONE flag is set
@ 2022-03-16 14:38 Hyeonggon Yoo
  2022-03-16 22:11 ` Vlastimil Babka
  0 siblings, 1 reply; 8+ messages in thread
From: Hyeonggon Yoo @ 2022-03-16 14:38 UTC (permalink / raw)
  To: linux-mm
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Roman Gushchin, 42.hyeyoo,
	Oliver Glitta

Testcase test_next_pointer in slub_kunit fails when SLAB_RED_ZONE flag
is globally set. This is because on_freelist() cuts corrupted freelist
chain and does not update cut objects' redzone to SLUB_RED_ACTIVE.

When the test validates a slab that whose freelist is cut, it expects
redzone of objects unreachable by freelist is set to SLUB_RED_ACTIVE.
And it reports "Left Redzone overritten" error because the expectation
failed.

This patch makes slub_kunit expect two more errors for reporting and
fixing red overwritten error when SLAB_RED_ZONE flag is set.

The test passes on slub_debug and slub_debug=Z after this patch.

Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
 lib/slub_kunit.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c
index 8662dc6cb509..7cf1fb5a7fde 100644
--- a/lib/slub_kunit.c
+++ b/lib/slub_kunit.c
@@ -45,21 +45,36 @@ static void test_next_pointer(struct kunit *test)
 	 * Expecting three errors.
 	 * One for the corrupted freechain and the other one for the wrong
 	 * count of objects in use. The third error is fixing broken cache.
+	 *
+	 * When flag SLUB_RED_ZONE is set, we expect two more errors for reporting
+	 * and fixing overwritten redzone error. This two errors are detected
+	 * because SLUB cuts corrupted freelist in on_freelist(), but does not
+	 * update its redzone to SLUB_RED_ACTIVE.
 	 */
 	validate_slab_cache(s);
-	KUNIT_EXPECT_EQ(test, 3, slab_errors);
+
+	if (s->flags & SLAB_RED_ZONE)
+		KUNIT_EXPECT_EQ(test, 5, slab_errors);
+	else
+		KUNIT_EXPECT_EQ(test, 3, slab_errors);
 
 	/*
 	 * Try to repair corrupted freepointer.
 	 * Still expecting two errors. The first for the wrong count
 	 * of objects in use.
 	 * The second error is for fixing broken cache.
+	 *
+	 * When SLUB_RED_ZONE flag is set, we expect two more errors
+	 * for same reason as above.
 	 */
 	*ptr_addr = tmp;
 	slab_errors = 0;
 
 	validate_slab_cache(s);
-	KUNIT_EXPECT_EQ(test, 2, slab_errors);
+	if (s->flags & SLAB_RED_ZONE)
+		KUNIT_EXPECT_EQ(test, 4, slab_errors);
+	else
+		KUNIT_EXPECT_EQ(test, 2, slab_errors);
 
 	/*
 	 * Previous validation repaired the count of objects in use.
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-06  8:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 14:38 [PATCH] mm/slub, kunit: Make slub_kunit pass even when SLAB_RED_ZONE flag is set Hyeonggon Yoo
2022-03-16 22:11 ` Vlastimil Babka
2022-03-17  7:06   ` Hyeonggon Yoo
2022-03-17  8:10   ` [PATCH] mm/slub, kunit: Make slub_kunit unaffected by global slub debugging flags Hyeonggon Yoo
2022-04-05 10:58     ` Vlastimil Babka
2022-04-06  6:00       ` [PATCH v2] mm/slub, kunit: Make slub_kunit unaffected by user specified flags Hyeonggon Yoo
2022-04-06  8:17         ` Vlastimil Babka
2022-04-06  6:06       ` [PATCH] mm/slub, kunit: Make slub_kunit unaffected by global slub debugging flags Hyeonggon Yoo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.