From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3C8FE78F59 for ; Tue, 31 Mar 2026 03:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774926287; cv=none; b=fqbIwxyeJ5YLpeAL+z8q0g1Z7HY4vra1NH5c0rGOLYuPbgAx2d5ywn64A3D9CFUxHT9l3k1y4yBX6b344HwSmWLmTuzJichwpastBS25vMFV2VuOdrHt3WCPMfngPfyC70R6OKNprEwVQBY05Mh7owycIGiIq6Es0h+rC/Aj8R4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774926287; c=relaxed/simple; bh=cvVmqCKIqLKepAb7/80JpYxt9nnAQhs9tMixAvmVgaw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zvq5wUsi1jK+GQ09F2Cu/o3GKSW2eOkd99besL6oltaP0hOb2EHNiK8EI7aEvTjMuL/FF9D+PSyRhQ/iHVvm2PzdD4w8/m5B+PVItk+U/+V095/aaYnUQAwNgH8//81xNu0JceFlbtyVeKLxwc+DO4R77uGk7v/Nq9SdfBMV8Y4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flIILcqn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="flIILcqn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85681C4CEF7; Tue, 31 Mar 2026 03:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774926286; bh=cvVmqCKIqLKepAb7/80JpYxt9nnAQhs9tMixAvmVgaw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=flIILcqnDvljYA6KkCUeMvcGhPuCzNuoPmsc+nmaIP4sbX4GrpCTV4G5GPLX5DiE7 imZ7GclJ33lI56dY9oJJBu5y2+z1gsk6l2rgrVa7fpnAMgn+39FZR/Y/d+1CZqT4Fk UpuFeymZPn772kqHgKSkqBpdHKGiJhGi/efGeYLeaSEsBbBq+IjrnHzjiMS7hdfpU1 F366BYEv7zJHVVVaRRRRee0GQIPySZEzUO8dTnqkhLfAymbkY56bj8hkPKmN7IDr9y 6oT5g6KTG0BtUalGpkzKgYfGZ6d7Q0RxGK4ILi2/lYOJo5u2zBIb2lhGsThkxpK94q 9Z5s9oUgVurcw== Date: Tue, 31 Mar 2026 12:04:44 +0900 From: "Harry Yoo (Oracle)" To: Vlastimil Babka , Andrew Morton Cc: Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH V1 2/2] lib/tests/slub_kunit: add a test case for {kmalloc,kfree}_nolock Message-ID: References: <20260330120517.104743-1-harry@kernel.org> <20260330120517.104743-3-harry@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260330120517.104743-3-harry@kernel.org> On Mon, Mar 30, 2026 at 09:05:16PM +0900, Harry Yoo (Oracle) wrote: > Testing invocation of {kmalloc,kfree}_nolock() during kmalloc() or > kfree() is tricky, and it is even harder to ensure that slowpaths are > properly tested. Lack of such testing has led to late discovery of > the bug fixed by commit a1e244a9f177 ("mm/slab: use prandom if > !allow_spin"). > > Add a slub_kunit test that allocates and frees objects in a tight loop > while a perf event triggers NMIs on the same task, invoking > {kmalloc,kfree}_nolock() from the NMI handler. > > Signed-off-by: Harry Yoo (Oracle) > --- > lib/tests/slub_kunit.c | 88 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 88 insertions(+) > > diff --git a/lib/tests/slub_kunit.c b/lib/tests/slub_kunit.c > index 848b682a2d70..2ed5f90a748a 100644 > --- a/lib/tests/slub_kunit.c > +++ b/lib/tests/slub_kunit.c > +static void test_kmalloc_kfree_nolock(struct kunit *test) > +{ > + int i, j; > + struct nmi_context ctx = { .test = test }; > + struct perf_event *event; > + bool alloc_fail = false; > + > + event = perf_event_create_kernel_counter(&nmi_hw_attr, -1, current, > + kmalloc_kfree_nolock_in_nmi, > + &ctx); > + if (IS_ERR(event)) > + kunit_skip(test, "Failed to create perf event"); > + ctx.event = event; > + perf_event_enable(ctx.event); > + for (i = 0; i < REPEAT_TIMES; i++) { > + for (j = 0; j < LOOP_SIZE; j++) { > + gfp_t gfp = (i % 2) ? 0 : __GFP_ACCOUNT; One thing sashiko pointed out [1]: '0' as gfp for kmalloc() is unnecessarily restrictive. (it's not kmalloc_nolock()!), it should be: `gfp_t gfp = (i % 2) ? GFP_KERNEL : GFP_KERNEL_ACCOUNT;` [1] https://sashiko.dev/#/patchset/20260330120517.104743-1-harry%40kernel.org -- Cheers, Harry / Hyeonggon