Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp764348rwb; Tue, 29 Nov 2022 05:12:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JLVGll9NJ5wYo9Q6zBjqdUuRN4oNagWlkKZR//jtzYFySKyJVsb2UpvX5MF2/iy6hdVp5 X-Received: by 2002:a17:906:d281:b0:782:7790:f132 with SMTP id ay1-20020a170906d28100b007827790f132mr32081526ejb.649.1669727536577; Tue, 29 Nov 2022 05:12:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669727536; cv=none; d=google.com; s=arc-20160816; b=g1rKmVKdrnhTxH7jlZ/cJ36O/XsRtxkupRBJB5E+n544A9mF1qg0ASSMD7AWmxVKl5 g2iawaUiv6fguJG6TrwvJsstu+yjZ1obXd7oZ9wxM2dukWLaYr4/TpShQQ6LQSbKT8at 8b/ylVpmwbiFBJ25GeOq70MYMk5vRQeQ2OFfn19bjY2abM8jM/Lqp6HwnCQnM0f8Oq64 +dlrh5vMBJk3p4etNkYJjLWkbcpUdltMehlPnI1B6USRCn9zFs0dq/gcXvyMoTAlW1gf UxoMRaW2ysivz9J/hxVX5hBlukJ5pNltmxt8uM4ubQC4W5eMlUluVyJ+lZduvkwQEBrO GIuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eQ2q70MxmrOTbyY/3idcvpot4MIQOw6xbYQRAtAnHRk=; b=BdQ9Tkd926tQujSGpz9weI2kxs3gmiFbKxr4HGtqX7wa4Y0uM2qfu/Gd/IEX/b3YTt F8WkD804M/aqa7W/2hkcPee3FnEAV2mraVfsfbhewpEh9ekwzyPRxeBJjZWc/rhSnblq i+pAJI4M4uZrKlA8aFAaanl+sNHms5qlq1mxoJEOkyaGgme0AuB2RxdyxXDGj6bfHct+ rhfNc5sDQBseKqyZoz2s1FMpCzATyrQ8ONPZVqsIkjlngZCsf8ezSOOqYfws9Tru1Wsr Dm4YvaNOEbg13ESN6fPB5ZoS1C/Ca37RVIJp9Pc94UMP4cg9lKDA/p6oLCGdS0npPBdm qd/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=k2CNqn4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a05640242cd00b004587e99bcc2si13703901edc.383.2022.11.29.05.11.56; Tue, 29 Nov 2022 05:12:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=k2CNqn4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbiK2M5H (ORCPT + 84 others); Tue, 29 Nov 2022 07:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232297AbiK2M4x (ORCPT ); Tue, 29 Nov 2022 07:56:53 -0500 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20AA960EBC for ; Tue, 29 Nov 2022 04:56:52 -0800 (PST) Received: by mail-yb1-xb2e.google.com with SMTP id o127so1821098yba.5 for ; Tue, 29 Nov 2022 04:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eQ2q70MxmrOTbyY/3idcvpot4MIQOw6xbYQRAtAnHRk=; b=k2CNqn4mmj4GxHren8t1/WpNcwnKbVDjdcpLv/RrGu2RoN9vE8ISGcNpmGrZUgp4x6 Pl3bgYcY5wHW3oNo/keuSbf9CYoAyPCy5gvbAATXwgkvlFVnte370kxzSxozhMrV70N9 54bb4mbKdDeALTNypg9O7h5clw2O+BOLf9O5Bh/evHwxwHwdgtrIpXLZejf3XCie9DLp z46XKJL3U2KAdzHAAI0ki2IjRsKDKTdEiA0ffrm/Q17I3YEwBtn4mI8K28phKEHjt9vc Tzwu2o0PyOR3EmYssrhwKDEyU/w/wO9BcrMeHUIajjRrW9JtAUx7pxuQDdqEP8gay66H gBxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eQ2q70MxmrOTbyY/3idcvpot4MIQOw6xbYQRAtAnHRk=; b=gxqAwFNgDWOgvs49n+IXjkzQ323stXlL3NuWRMH7GCgPvxU8hcJAnKmrU0WNtu+hKt ROmxj44KFXaB4GgF6q2ZZfuBt/9Yweydou+GeI2PM9z4XdM9od+2UuCJclacDSXKPoM2 F7NK0n7iXDpQSEZn39XQlYoGZKVqiyWc+1T5cKB8FYo+4L+55mBNJhcaIL3un1eewmXi qrJcSMXtm/B9s4s07bei7MEvM9fjvke435tSmjVlnqWJHEqgmwD8udift4sPY80s+z8a rrRer7h7A8SmNQIrwKZYHm8c2WaD8qY0XTUJzeVd0Xvxhf8rEv7+3fEtzc00JJ3diGel 9y2g== X-Gm-Message-State: ANoB5pn9S1SKdnVvKr0FMBORJhPEZn9Qr6sqIi3z0sfK4C0GFSN20GZw 8C7hKoJVO4EKztzid/n7goCnGPg4zN3CvLvoCbSFpA== X-Received: by 2002:a25:e749:0:b0:6f1:9eb8:76d4 with SMTP id e70-20020a25e749000000b006f19eb876d4mr24173229ybh.143.1669726611154; Tue, 29 Nov 2022 04:56:51 -0800 (PST) MIME-Version: 1.0 References: <20221129063358.3012362-1-feng.tang@intel.com> <20221129063358.3012362-2-feng.tang@intel.com> <67e6ebce-f8cc-7d28-5e85-8a3909c2d180@suse.cz> In-Reply-To: From: Marco Elver Date: Tue, 29 Nov 2022 13:56:15 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] mm/slub, kunit: Add a test case for kmalloc redzone check To: Feng Tang Cc: Vlastimil Babka , Andrew Morton , Oliver Glitta , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 Nov 2022 at 13:53, Feng Tang wrote: > > On Tue, Nov 29, 2022 at 08:02:51PM +0800, Vlastimil Babka wrote: > > On 11/29/22 12:48, Marco Elver wrote: > > > On Tue, 29 Nov 2022 at 12:01, Vlastimil Babka wrote: > > >> > > >> On 11/29/22 10:31, Marco Elver wrote: > > >> > On Tue, 29 Nov 2022 at 07:37, Feng Tang wrote: > > > > > >> For SLAB_SKIP_KFENCE, we could also add the flag after creation to avoid > > >> this trouble? After all there is a sysfs file to control it at runtime > > >> anyway (via skip_kfence_store()). > > >> In that case patch 1 would have to wrap kmem_cache_create() and the flag > > >> addition with a new function to avoid repeating. That function could also be > > >> adding SLAB_NO_USER_FLAGS to kmem_cache_create(), instead of the #define > > >> DEFAULT_FLAGS. > > > > > > I wouldn't overcomplicate it, all we need is a way to say "this flag > > > should not be used directly" - and only have it available via an > > > indirect step. Availability via sysfs is one such step. > > > > > > And for tests, there are 2 options: > > > > > > 1. we could provide a function "kmem_cache_set_test_flags(cache, > > > gfp_flags)" and define SLAB_TEST_FLAGS (which would include > > > SLAB_SKIP_KFENCE). This still allows to set it generally, but should > > > make abuse less likely due to the "test" in the name of that function. > > > > > > 2. just set it directly, s->flags |= SLAB_SKIP_KFENCE. > > > > > > If you're fine with #2, that seems simplest and would be my preference. > > > > Yeah, that's what I meant. But slub_kunit.c could still have own internal > > cache creation function so the "|SLAB_NO_USER_FLAGS" and "s->flags |= > > SLAB_SKIP_KFENCE" is not repeated X times. > > I just quickly tried adding a new wrapper, like > > struct kmem_cache *debug_kmem_cache_create(const char *name, unsigned int size, > unsigned int align, slab_flags_t flags, > void (*ctor)(void *), slab_flags_t debug_flags); > > and found that, IIUC, both SLAB_KMALLOC and SLAB_NO_USER are creation > time flag, while SLAB_SKIP_KFENCE is an allocation runtime flag which > could be set after creation. > > So how about use the initial suggestion from Vlastimil to set the > SKIP_KFENCE flag through an internal wrapper in slub_kunit.c? > > /* Only for debug and test use, to skip kfence allocation */ > static inline void kmem_cache_skip_kfence(struct kmem_cache *s) > { > s->flags |= SLAB_SKIP_KFENCE; > } Yes, that's fine - as long as it's local to slub_kunit.c, this seems very reasonable. Thanks, -- Marco