Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4444225rwb; Mon, 21 Nov 2022 07:41:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf71PC8TwPE/zoE06ljkzpASlI3vJMIPkjZI1uidr3ZgzOnVZOOPnrweItjUvz3TLy36mZRD X-Received: by 2002:a05:6a00:410b:b0:56b:dc84:7783 with SMTP id bu11-20020a056a00410b00b0056bdc847783mr4158195pfb.35.1669045271040; Mon, 21 Nov 2022 07:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669045271; cv=none; d=google.com; s=arc-20160816; b=S7fiF2tsUEok9rNoFlvFNddADCU2OigEK5UdZUaBhWLkwcC7XFfK1btFrvJW1T3n/k glzsFTj6U361UnSwIviEuqlNBOIE+/dSRRWgO3dwOwL2dDW4h1cIw0yvgk1wL0nJn7jL qI0i45esZsGn6NAlIOPcB2az+YRQTxSW+bh0e0Po5e8JWAvhrEbpgTLOEVrA2RhHcSF+ vt4kXIYtGbTlOVKznx3fxTOwZ/ZiiWGIBB+CzBHtikjd8mmKSFa2c+MgFBBjLr5CH9C+ DKf06Oq8gmZLPlKZ7pUhGoowA1vpWl9tH7AR/Z3tGnRtLzo6qDimmoQyqBnUqS8XMtAa VVOA== 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=j4iomL/SuFm2qP/FaY1uaLFvnC19GQTDr6IrFZRdHZA=; b=H301ezTqJtoT8aiJQLamareJ9OKeNsxqx675LZRWmn+GKLvENpqsjOT8ZzkurRxgjk RL8xCYDmMVxgRyu8vTei6r20xpdq2OJ/fdFJRj4L8FQqsGw0XFohcFdaC9CRHen7sx0b AsKrycDSlng7iVfw8VnvCItKE8/llb9xR619GwkkLQnC+jZ2ASuP8nk8LaNKoUPansC8 KGVqmVZo/aChwsLeCiePAYCnJWOjQ9cugbRmEspXWdnkrjseivLl1f2J3rlP/VPiG7MI TqD1bASiXvyo3cRxduh1w8c9cTH0WbuPezNscahXwF1VEz4/GN7Z7y54aom4+ygWt2UA SXpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RFEzHslJ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a170903234700b001869b2c5f47si12709220plh.326.2022.11.21.07.40.56; Mon, 21 Nov 2022 07:41:11 -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=@gmail.com header.s=20210112 header.b=RFEzHslJ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbiKUPTV (ORCPT + 91 others); Mon, 21 Nov 2022 10:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiKUPTD (ORCPT ); Mon, 21 Nov 2022 10:19:03 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FDB6CFEAB for ; Mon, 21 Nov 2022 07:15:44 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id w3-20020a17090a460300b00218524e8877so12232495pjg.1 for ; Mon, 21 Nov 2022 07:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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=j4iomL/SuFm2qP/FaY1uaLFvnC19GQTDr6IrFZRdHZA=; b=RFEzHslJIPr3wKkoXOuVeTeiw7UtPt5iy5zU7+rfoTjUVr5qRjm/PWz/WqsxtxgOPj OPeYqCwIyS8doJX7QqnN8iDuTn2mDni7CkcEQerTHSevzpnozoEU2JEeGuiKLQrx8cd5 85Fp6Y18uvvpYhRlVgLTipbyHch+XnBQFxiEt2A2uhAU9Xu+qu22MrbmoDg6+WsSn/wt xliA6Zt2TEqaGoXTAM+0xFRuJavVmM6B5YCmKiYZovnJQoNY5X1KOEnTOltkKGd2vsc+ dddElnLPRCpen9DrgzTCdahGQhI94ZDiQm6KX7pmHCEjowj05LW7E/EoNKT4a3CqjLiQ GZxw== 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=j4iomL/SuFm2qP/FaY1uaLFvnC19GQTDr6IrFZRdHZA=; b=mmmEXIybaDeSmqXXppn+542ivv8Ovvil8pZzcQjc2A5C4JiOBU5J8dpZyPGtHykfVq fmX3iXe8YJz6jQRHG/uuBDQyizZHn1UcWpLj1KXAAGWYvYIvzgKsEY8qRyLsNIXcJRxE 52clZ4TAbR3LgK1YkEyauUvTIe0z8Fro6XR+v2OZCiX47rM/+LjagXN3yfNQ/BRUCCG0 uHRjrLx6nk38jpgyZnX31AD8k36txP5jDXsChqqfH+TYq0ksbdLFpjWJA2IFSf2nZCqt j9lMpTSfNQZWCfFqNerPu361FsdnkLNR8jwV/LEQRohhuaRwqapZkuQpEFb/BbolEyGm mXDA== X-Gm-Message-State: ANoB5pkq63p6lZ3CsxUl48q0Iul3DF6s4PLcNdTTqW5KTGvOo/ksJV3b uNWbbBj7x102CiqWl13fWWinZKdq3v0sTi/vbQQ9StW3WBQ= X-Received: by 2002:a17:90a:5883:b0:218:f84:3f98 with SMTP id j3-20020a17090a588300b002180f843f98mr27389810pji.238.1669043743578; Mon, 21 Nov 2022 07:15:43 -0800 (PST) MIME-Version: 1.0 References: <20221121135024.1655240-1-feng.tang@intel.com> <20221121135024.1655240-2-feng.tang@intel.com> In-Reply-To: <20221121135024.1655240-2-feng.tang@intel.com> From: Andrey Konovalov Date: Mon, 21 Nov 2022 16:15:32 +0100 Message-ID: Subject: Re: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check To: Feng Tang Cc: Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Vincenzo Frascino , linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Mon, Nov 21, 2022 at 2:53 PM Feng Tang wrote: > > Use new is_kmalloc_cache() to simplify the code of checking whether > a kmem_cache is a kmalloc cache. > > Signed-off-by: Feng Tang Hi Feng, Nice simplification! > --- > include/linux/kasan.h | 9 --------- > mm/kasan/common.c | 9 ++------- > mm/slab_common.c | 1 - > 3 files changed, 2 insertions(+), 17 deletions(-) > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index dff604912687..fc46f5d6f404 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -102,7 +102,6 @@ struct kasan_cache { > int alloc_meta_offset; > int free_meta_offset; > #endif > - bool is_kmalloc; > }; We can go even further here, and only define the kasan_cache struct and add the kasan_info field to kmem_cache when CONFIG_KASAN_GENERIC is enabled. > > void __kasan_unpoison_range(const void *addr, size_t size); > @@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page, > return false; > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache); > -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - if (kasan_enabled()) > - __kasan_cache_create_kmalloc(cache); > -} > - > void __kasan_poison_slab(struct slab *slab); > static __always_inline void kasan_poison_slab(struct slab *slab) > { > @@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, > bool init) {} > static inline bool kasan_unpoison_pages(struct page *page, unsigned int order, > bool init) { return false; } > -static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} > static inline void kasan_poison_slab(struct slab *slab) {} > static inline void kasan_unpoison_object_data(struct kmem_cache *cache, > void *object) {} > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 1f30080a7a4c..f7e0e5067e7a 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) > KASAN_PAGE_FREE, init); > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - cache->kasan_info.is_kmalloc = true; > -} > - > void __kasan_poison_slab(struct slab *slab) > { > struct page *page = slab_page(slab); > @@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, > kasan_unpoison(tagged_object, cache->object_size, init); > > /* Save alloc info (if possible) for non-kmalloc() allocations. */ > - if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) > kasan_save_alloc_info(cache, tagged_object, flags); > > return tagged_object; > @@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, > * Save alloc info (if possible) for kmalloc() allocations. > * This also rewrites the alloc info when called from kasan_krealloc(). > */ > - if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) > kasan_save_alloc_info(cache, (void *)object, flags); > > /* Keep the tag that was set by kasan_slab_alloc(). */ > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 8276022f0da4..a5480d67f391 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, > > create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset, > usersize); > - kasan_cache_create_kmalloc(s); > list_add(&s->list, &slab_caches); > s->refcount = 1; > return s; > -- > 2.34.1 >