mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: Paran Lee <p4ranlee@gmail.com>
Cc: Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	linux-kernel@vger.kernel.org, linux-mm@vger.kernel.org,
	Oliver Glitta <glittao@gmail.com>,
	Austin Kim <austindh.kim@gmail.com>
Subject: Re: [PATCH] slub: kunit catch kmem_cache_alloc failed
Date: Mon, 9 May 2022 20:20:57 +0900	[thread overview]
Message-ID: <Ynj5GZuXG6CgCUJp@hyeyoo> (raw)
In-Reply-To: <20220506045319.GA28237@DESKTOP-NK4TH6S.localdomain>

On Fri, May 06, 2022 at 01:53:19PM +0900, Paran Lee wrote:
> Catch kmem_cache_alloc failed on slub kunit test.
> 
> Signed-off-by: Paran Lee <p4ranlee@gmail.com>
> ---
>  lib/slub_kunit.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c
> index 8662dc6cb509..7b80241dd498 100644
> --- a/lib/slub_kunit.c
> +++ b/lib/slub_kunit.c
> @@ -32,6 +32,11 @@ static void test_next_pointer(struct kunit *test)
>  	struct kmem_cache *s = kmem_cache_create("TestSlub_next_ptr_free", 64, 0,
>  				SLAB_POISON, NULL);
>  	u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
> +	if (!p) {
> +		kunit_err(test, "Allocation failed: %s\n", __func__);
> +		kmem_cache_destroy(s);
> +		return;
> +	}
>  	unsigned long tmp;
>  	unsigned long *ptr_addr;
>  
> @@ -77,6 +82,11 @@ static void test_first_word(struct kunit *test)
>  	struct kmem_cache *s = kmem_cache_create("TestSlub_1th_word_free", 64, 0,
>  				SLAB_POISON, NULL);

Recently SLAB_NO_USER_FLAGS is added for test caches.
Looks like it's not based on Vlastimil's slab tree:
https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git

>  	u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
> +	if (!p) {
> +		kunit_err(test, "Allocation failed: %s\n", __func__);
> +		kmem_cache_destroy(s);
> +		return;
> +	}
>  
>  	kmem_cache_free(s, p);
>  	*p = 0x78;
> @@ -92,6 +102,11 @@ static void test_clobber_50th_byte(struct kunit *test)
>  	struct kmem_cache *s = kmem_cache_create("TestSlub_50th_word_free", 64, 0,
>  				SLAB_POISON, NULL);
>  	u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
> +	if (!p) {
> +		kunit_err(test, "Allocation failed: %s\n", __func__);
> +		kmem_cache_destroy(s);
> +		return;
> +	}
>  
>  	kmem_cache_free(s, p);
>  	p[50] = 0x9a;
> @@ -108,6 +123,11 @@ static void test_clobber_redzone_free(struct kunit *test)
>  	struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_free", 64, 0,
>  				SLAB_RED_ZONE, NULL);
>  	u8 *p = kmem_cache_alloc(s, GFP_KERNEL);
> +	if (!p) {
> +		kunit_err(test, "Allocation failed: %s\n", __func__);
> +		kmem_cache_destroy(s);
> +		return;
> +	}
>  
>  	kasan_disable_current();
>  	kmem_cache_free(s, p);
> -- 
> 2.25.1
> 

To be more paranoid kmem_cache_create() can also fail - but I'm not sure
these checks are useful for tests.

-- 
Thanks,
Hyeonggon

      parent reply	other threads:[~2022-05-09 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  4:53 Paran Lee
2022-05-06 11:45 ` kernel test robot
2022-05-09 11:20 ` Hyeonggon Yoo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ynj5GZuXG6CgCUJp@hyeyoo \
    --to=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=austindh.kim@gmail.com \
    --cc=cl@linux.com \
    --cc=glittao@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@vger.kernel.org \
    --cc=p4ranlee@gmail.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®