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 D48FE32F74B for ; Thu, 13 Nov 2025 08:40:58 +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=1763023260; cv=none; b=Nkwo61vwma0/PA4QrInId8bLUwwRBc9Ec/YK3tSSIyW3h4PVnTyZPxxyq40x3nzOm8kls5DXnGlcKbHTm3AjK7PhzJyIpUL1UyV1qW5B+Nh/SOpuxsm0cESh+2J/4OV/RdFs2w5FAN7L3iDVUn4pYuC7ObDQPcgMAnQrWLYMX+E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763023260; c=relaxed/simple; bh=WyMkx2kTLz5v44kEossbyjUr4nkyF0rQkvz2CEaj/fs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hPSofpE7zEwCiVlpjcnkuE6l2IygMm6DuHi0ZvnCgBzdGn28Xk6/qj2KrHtsQpAvSVt7UsEVDRLA75m8RT5E6cFiH+E4hLrK/SMaaSOMsSXMRFYKETipXILp3nwTQtrO69T9lUmpTSosJrr9bUGPG6OR1q4lZ1lTE3p8q+y9TD4= 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=pSAt6uXD; 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="pSAt6uXD" 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=8Bi/XPLfLPitz3QFgeWKraJXa3JEmVmi80D2Ta/Izrs=; b=pSAt6uXDuV54wYKSjed0vjd2l0 Ow3XeFxH55qemFo4LisNTpjDSMqYRHyiKJFN0tN5MPyRtpOtvAaKDhLa3ADkSACzqW3Ydgv9Q2AjE PW1VJGNcFEyFqt5VtNWeFAvNpSsv2QGN2YeWJHptkrncTNGSpHQ7r3jcMpmxXpdUvuYdIfv3De629 H9n8ZM+obWkoXZC4aPnJcZ6jUrxd8M7nsiYkFKV2KIHJbpoT5a/EdO7RniUh18WmuQ/XFIoi+rgXl G2O9CFV41dEGE9WyvbUWFzQRLjSUbSuBegagFiCwXFb9iIZVKOb3KJMUatT97i0UwU3D2TFF7PfRy zHdCSH8A==; Received: from 2a02-8389-2341-5b80-d601-7564-c2e0-491c.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d601:7564:c2e0:491c] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vJSsx-0000000A7Qj-1Vux; Thu, 13 Nov 2025 08:40:55 +0000 From: Christoph Hellwig To: Vlastimil Babka , Andrew Morton Cc: Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Zi Yan , Eric Biggers , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] mempool: add error injection support Date: Thu, 13 Nov 2025 09:39:45 +0100 Message-ID: <20251113084022.1255121-5-hch@lst.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251113084022.1255121-1-hch@lst.de> References: <20251113084022.1255121-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@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 Add a call to should_fail_ex that forces mempool to actually allocate from the pool to stress the mempool implementation when enabled through debugfs. By default should_fail{,_ex} prints a very verbose stack trace that clutters the kernel log, slows down execution and triggers the kernel bug detection in xfstests. Pass FAULT_NOWARN and print a single-line message notating the caller instead so that full tests can be run with fault injection. Signed-off-by: Christoph Hellwig Acked-by: Vlastimil Babka --- mm/mempool.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mm/mempool.c b/mm/mempool.c index 1f4701713203..5cf59779cc3d 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -9,7 +9,7 @@ * started by Ingo Molnar, Copyright (C) 2001 * debugging by David Rientjes, Copyright (C) 2015 */ - +#include #include #include #include @@ -20,6 +20,15 @@ #include #include "slab.h" +static DECLARE_FAULT_ATTR(fail_mempool_alloc); + +static int __init mempool_faul_inject_init(void) +{ + return PTR_ERR_OR_ZERO(fault_create_debugfs_attr("fail_mempool_alloc", + NULL, &fail_mempool_alloc)); +} +late_initcall(mempool_faul_inject_init); + #ifdef CONFIG_SLUB_DEBUG_ON static void poison_error(mempool_t *pool, void *element, size_t size, size_t byte) @@ -404,9 +413,15 @@ void *mempool_alloc_noprof(mempool_t *pool, gfp_t gfp_mask) gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO); repeat_alloc: + if (should_fail_ex(&fail_mempool_alloc, 1, FAULT_NOWARN)) { + pr_info("forcing mempool usage for %pS\n", + (void *)_RET_IP_); + element = NULL; + } else { + element = pool->alloc(gfp_temp, pool->pool_data); + } - element = pool->alloc(gfp_temp, pool->pool_data); - if (likely(element != NULL)) + if (likely(element)) return element; spin_lock_irqsave(&pool->lock, flags); -- 2.47.3