From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933286AbcBBP2c (ORCPT ); Tue, 2 Feb 2016 10:28:32 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:36090 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933125AbcBBP22 (ORCPT ); Tue, 2 Feb 2016 10:28:28 -0500 Subject: Re: [PATCH v1 1/8] kasan: Change the behavior of kmalloc_large_oob_right test To: Andrew Morton , Alexander Potapenko References: <35b553cafcd5b77838aeaf5548b457dfa09e30cf.1453918525.git.glider@google.com> <20160201213427.f428b08d.akpm@linux-foundation.org> Cc: adech.fo@gmail.com, cl@linux.com, dvyukov@google.com, rostedt@goodmis.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org From: Andrey Ryabinin Message-ID: <56B0CB60.1080506@gmail.com> Date: Tue, 2 Feb 2016 18:29:36 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20160201213427.f428b08d.akpm@linux-foundation.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/02/2016 08:34 AM, Andrew Morton wrote: > On Wed, 27 Jan 2016 19:25:06 +0100 Alexander Potapenko wrote: > >> depending on which allocator (SLAB or SLUB) is being used >> >> ... >> >> --- a/lib/test_kasan.c >> +++ b/lib/test_kasan.c >> @@ -68,7 +68,22 @@ static noinline void __init kmalloc_node_oob_right(void) >> static noinline void __init kmalloc_large_oob_right(void) >> { >> char *ptr; >> - size_t size = KMALLOC_MAX_CACHE_SIZE + 10; >> + size_t size; >> + >> + if (KMALLOC_MAX_CACHE_SIZE == KMALLOC_MAX_SIZE) { >> + /* >> + * We're using the SLAB allocator. Allocate a chunk that fits >> + * into a slab. >> + */ >> + size = KMALLOC_MAX_CACHE_SIZE - 256; >> + } else { >> + /* >> + * KMALLOC_MAX_SIZE > KMALLOC_MAX_CACHE_SIZE. >> + * We're using the SLUB allocator. Allocate a chunk that does >> + * not fit into a slab to trigger the page allocator. >> + */ >> + size = KMALLOC_MAX_CACHE_SIZE + 10; >> + } > > This seems a weird way of working out whether we're using SLAB or SLUB. > > Can't we use, umm, #ifdef CONFIG_SLAB? If not that then let's cook up > something standardized rather than a weird just-happens-to-work like > this. > Actually it would be simpler to not use KMALLOC_MAX_CACHE_SIZE at all. Simply replace it with 2 or 3 PAGE_SIZEs.