From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D180AC4321E for ; Wed, 30 Nov 2022 09:26:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FA706B0078; Wed, 30 Nov 2022 04:26:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AAF46B007B; Wed, 30 Nov 2022 04:26:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 473526B007D; Wed, 30 Nov 2022 04:26:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 38F236B0078 for ; Wed, 30 Nov 2022 04:26:02 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0B5FD141037 for ; Wed, 30 Nov 2022 09:26:02 +0000 (UTC) X-FDA: 80189576964.26.68BA8D1 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf30.hostedemail.com (Postfix) with ESMTP id A6A5E8000D for ; Wed, 30 Nov 2022 09:26:01 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id b11so15172556pjp.2 for ; Wed, 30 Nov 2022 01:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TyJDDvQfeBb1GezHTkEwABeQFr6KK0pjnwnX5KAKxeg=; b=VYtBzJfydNprTCCyGjvSmq2UTPhRtCyEM+GYH3ITzI0kz1LzU38rjc4HNh7eMcTvkn X0NQpBCzxsFcCT2ki5WQXUSmjnkIP3Eg/ALHNonI+eNxpuIV6CBEM0j8tm8z1iIEaN7g 6zcKPmXhuHV0HfKCaUPinFddN6vqk/37Ff1LF4ogXL2tIbJg5HQHHiW/y/ATv3TT1Rsf n4RPsURVcttAjBL/EmBnSM8Zu4Yhpk6NnLdOXzs952NRo2ZG30a/RcBJy+iwcqPeHcxu r2VHAMKM6MElynNf6Cfx8cQ8xz7oXg0Fag11t1Alz3045obcUuVp0COnZhcx0HL0eUQm MRhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TyJDDvQfeBb1GezHTkEwABeQFr6KK0pjnwnX5KAKxeg=; b=EuGifY6bvcxFVnq6UIccYnXcd46U2ZvHSgNjj0Kc5br37MF+qGRDlZBk69s15z5tBn /eH07krS46at0cykSDcaprj9NvsWhEbNkDzCc0m7fQBv7GIb7nycbQm23xTduwIlsV7f 71oi3r9X06uwHrNjtUVOIeX+CTCFCusLsmDeDewk335h/gAzEPL7cHvtqPgOC2zZg/vf TEYCAndq/vhZdHokFaw7Y0ysyyujBboWUwzMT6jLFIDjrwSDCuUlvflgdo36gAQrDCi+ 8SdiM6pCXON2JakPpJq8098NgHSKKNaluTtPsT/DNFNTgX1fi36FF2nJguuivKc4oMU8 aHSg== X-Gm-Message-State: ANoB5pkoYhuyDDZv6ex5jbKoPQohOy4tgmZzAdCro/AS+dmURqUHGa1P H2iWQbOig6slOW941yqLfrw= X-Google-Smtp-Source: AA0mqf4oI2QKPut3fSn0Z5fZ4t3zbzf+pNIa00ryxVxejW3LTRP4t9O+dRs3TIeX/GvXbvRHUPS6ig== X-Received: by 2002:a17:902:ccce:b0:185:4880:91cd with SMTP id z14-20020a170902ccce00b00185488091cdmr41401879ple.130.1669800360563; Wed, 30 Nov 2022 01:26:00 -0800 (PST) Received: from hyeyoo ([114.29.91.56]) by smtp.gmail.com with ESMTPSA id 21-20020a621615000000b00575f348aa3esm375326pfw.122.2022.11.30.01.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 01:25:59 -0800 (PST) Date: Wed, 30 Nov 2022 18:25:54 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Feng Tang Cc: Vlastimil Babka , Marco Elver , Andrew Morton , Oliver Glitta , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] mm/slub, kunit: add SLAB_SKIP_KFENCE flag for cache creation Message-ID: References: <20221130085451.3390992-1-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221130085451.3390992-1-feng.tang@intel.com> ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VYtBzJfy; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669800361; a=rsa-sha256; cv=none; b=hmpucEc2arLGBCtQypGCeAYWM5VGwF7GVKvMC396x3AmcQb0yg6s2IpoIrlJoMIhHM7rpA /7u/CT7ceHFgqcc4uzelEmgs25cMvjXp/YAOsXmYoOOBGGcZGRZTyRWt/pFvdYjeNqG8gF yT9HVHrvwektustNitUeB4h8A8/Z+kY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669800361; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TyJDDvQfeBb1GezHTkEwABeQFr6KK0pjnwnX5KAKxeg=; b=dYkwZUpyH9y3HuhqX5xp1ZpPKKTDOw7m0XQPvd7ZBy1wLao9DmcBvA8qKuEZ6yFaG3HR7Y 4LpOTqHGZyTeEGbgp48NCgSlWo5+mwpF0ZdLHtp9zAyPMXJNXtTZ6VXBX59Bc+NVYLtrrj vdFlghIhxKlilH8v1UoDl9MheZG7znY= Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VYtBzJfy; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Stat-Signature: 4zn6dnq64nymfefc1piuti7ytyu1p6ak X-Rspamd-Queue-Id: A6A5E8000D X-Rspam-User: X-HE-Tag: 1669800361-606513 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 30, 2022 at 04:54:50PM +0800, Feng Tang wrote: > When kfence is enabled, the buffer allocated from the test case > could be from a kfence pool, and the operation could be also > caught and reported by kfence first, causing the case to fail. > > With default kfence setting, this is very difficult to be triggered. > By changing CONFIG_KFENCE_NUM_OBJECTS from 255 to 16383, and > CONFIG_KFENCE_SAMPLE_INTERVAL from 100 to 5, the allocation from > kfence did hit 7 times in different slub_kunit cases out of 900 > times of boot test. > > To avoid this, initially we tried is_kfence_address() to check this > and repeated allocation till finding a non-kfence address. Vlastimil > Babka suggested SLAB_SKIP_KFENCE flag could be used to achieve this, > and better add a wrapper function for simplifying cache creation. > > Signed-off-by: Feng Tang > --- > Changelog: > > since v2: > * Don't make SKIP_KFENCE an allowd flag for cache creation, and > solve a bug of failed cache creation issue (Marco Elver) > * Add a wrapper cache creation function to simplify code > including SKIP_KFENCE handling (Vlastimil Babka) > > lib/slub_kunit.c | 35 +++++++++++++++++++++++++---------- > 1 file changed, 25 insertions(+), 10 deletions(-) > > diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c > index 7a0564d7cb7a..5b0c8e7eb6dc 100644 > --- a/lib/slub_kunit.c > +++ b/lib/slub_kunit.c > @@ -9,10 +9,25 @@ > static struct kunit_resource resource; > static int slab_errors; > > +/* > + * Wrapper function for kmem_cache_create(), which reduces 2 parameters: > + * 'align' and 'ctor', and sets SLAB_SKIP_KFENCE flag to avoid getting an > + * object from kfence pool, where the operation could be caught by both > + * our test and kfence sanity check. > + */ > +static struct kmem_cache *test_kmem_cache_create(const char *name, > + unsigned int size, slab_flags_t flags) > +{ > + struct kmem_cache *s = kmem_cache_create(name, size, 0, > + (flags | SLAB_NO_USER_FLAGS), NULL); > + s->flags |= SLAB_SKIP_KFENCE; > + return s; > +} > + > static void test_clobber_zone(struct kunit *test) > { > - struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_alloc", 64, 0, > - SLAB_RED_ZONE|SLAB_NO_USER_FLAGS, NULL); > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_RZ_alloc", 64, > + SLAB_RED_ZONE); > u8 *p = kmem_cache_alloc(s, GFP_KERNEL); > > kasan_disable_current(); > @@ -29,8 +44,8 @@ static void test_clobber_zone(struct kunit *test) > #ifndef CONFIG_KASAN > static void test_next_pointer(struct kunit *test) > { > - struct kmem_cache *s = kmem_cache_create("TestSlub_next_ptr_free", 64, 0, > - SLAB_POISON|SLAB_NO_USER_FLAGS, NULL); > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_next_ptr_free", > + 64, SLAB_POISON); > u8 *p = kmem_cache_alloc(s, GFP_KERNEL); > unsigned long tmp; > unsigned long *ptr_addr; > @@ -74,8 +89,8 @@ static void test_next_pointer(struct kunit *test) > > static void test_first_word(struct kunit *test) > { > - struct kmem_cache *s = kmem_cache_create("TestSlub_1th_word_free", 64, 0, > - SLAB_POISON|SLAB_NO_USER_FLAGS, NULL); > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_1th_word_free", > + 64, SLAB_POISON); > u8 *p = kmem_cache_alloc(s, GFP_KERNEL); > > kmem_cache_free(s, p); > @@ -89,8 +104,8 @@ static void test_first_word(struct kunit *test) > > static void test_clobber_50th_byte(struct kunit *test) > { > - struct kmem_cache *s = kmem_cache_create("TestSlub_50th_word_free", 64, 0, > - SLAB_POISON|SLAB_NO_USER_FLAGS, NULL); > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_50th_word_free", > + 64, SLAB_POISON); > u8 *p = kmem_cache_alloc(s, GFP_KERNEL); > > kmem_cache_free(s, p); > @@ -105,8 +120,8 @@ static void test_clobber_50th_byte(struct kunit *test) > > static void test_clobber_redzone_free(struct kunit *test) > { > - struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_free", 64, 0, > - SLAB_RED_ZONE|SLAB_NO_USER_FLAGS, NULL); > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_RZ_free", 64, > + SLAB_RED_ZONE); > u8 *p = kmem_cache_alloc(s, GFP_KERNEL); > > kasan_disable_current(); > -- > 2.34.1 > Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> -- Thanks, Hyeonggon