Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5590924pxb; Mon, 28 Mar 2022 14:39:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlesU2/ob8j8zMzjdw9OFXCJJTGmTernsEMERdFQaJ4JVcXRLCwfc/CxEYjzsz4j8ZsEQX X-Received: by 2002:a17:90a:690c:b0:1c7:b15b:e363 with SMTP id r12-20020a17090a690c00b001c7b15be363mr1118830pjj.137.1648503579904; Mon, 28 Mar 2022 14:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648503579; cv=none; d=google.com; s=arc-20160816; b=F0bqsq3nRUF43wzUOaEm/JFHfhccmxTixgSpLbM6uVX9fDYVvTi9hMX95ONMHGA4pE k0DOQ5hZPgFe1mBVEY9LUA8Npc9Gmrhsv9K7UqRoXBI58Pc3PH8a0KRI6/qWlnQclGMi m0h99EctK3OOmV83LPJxn3djk9ff4tn+IDt+hAtPwVwXQby8PKvEJG89B4M3R5DukB1B Nx3zcfyjUlnjGI6AX1Faixx94Dlka9n2eS4yN8XbxlIey3pW7B3OVwBUvKrBCGvWVK5g oCVBSpHRz6trnLOzdji6sWgnmRz1bllGTY+CnPYvv7S6/03fB5lVEBEzdHK2kUs/ffNo kcRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=HI+dsvmjaN/rkGaZbNLF+cKlPT7DGdpfJYFLeEXc0Ts=; b=irpV36AByieh8xiP4zVDWc19bGVFVM9Qkm/AuI261u47ayIKa4NESIaiCFAcibtG8p zjiCPIf0VfPd9eyTI88hoPCtvwTmtQyLo3DF7eLuKqZHf4XbCvz+0zc6jFuvb7FjYQRb tuMcI2c1zUHPmXq4JBWnN3F7Ez8AvdVh5NNQxNvrI6k/NR8BJzSe7+hk3rlhcbjbh/wB ZWn3VKwP4A5QVklzJ5thUe9JCXan04Erjuq4CRIrs51dsLc/SDG/9K5TAna8YKsZ8i96 gvwm8fore1AVIwdPxdtGEpvcOAfhMYz4gTOT5KymtkdX0RWpktiNhlxza5XsC1RS05Mk LeGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=jpOSnpVG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pj13-20020a17090b4f4d00b001bd14e03064si674126pjb.60.2022.03.28.14.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=jpOSnpVG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43940954BF; Mon, 28 Mar 2022 14:16:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245690AbiC1T20 (ORCPT + 99 others); Mon, 28 Mar 2022 15:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245699AbiC1T1u (ORCPT ); Mon, 28 Mar 2022 15:27:50 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734785E767 for ; Mon, 28 Mar 2022 12:26:09 -0700 (PDT) Date: Mon, 28 Mar 2022 12:26:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1648495567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HI+dsvmjaN/rkGaZbNLF+cKlPT7DGdpfJYFLeEXc0Ts=; b=jpOSnpVGPf5/gLaSmGsNc0vn5N+hBHUR9ky2eGwEPwKeNEvqUDPzzpVpElXTK/7f/6q5Le tMd6dnJTD9Q1coxYQspQN9x0xJsA/tLuqTgnm4C8ado5C/3SWuMh6pO0nLk9xPmTr7SYeL 5NECd/RNfvdD7AVIFQwhXx4BEP33vzU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Muchun Song Cc: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com Subject: Re: [PATCH v2] mm: kfence: fix objcgs vector allocation Message-ID: References: <20220328132843.16624-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220328132843.16624-1-songmuchun@bytedance.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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, Mar 28, 2022 at 09:28:43PM +0800, Muchun Song wrote: > If the kfence object is allocated to be used for objects vector, then > this slot of the pool eventually being occupied permanently since > the vector is never freed. The solutions could be 1) freeing vector > when the kfence object is freed or 2) allocating all vectors statically. > Since the memory consumption of object vectors is low, it is better to > chose 2) to fix the issue and it is also can reduce overhead of vectors > allocating in the future. > > Fixes: d3fb45f370d9 ("mm, kfence: insert KFENCE hooks for SLAB") > Signed-off-by: Muchun Song > --- > v2: > - Fix compiler error reported by kernel test robot . Reviewed-by: Roman Gushchin LGTM, thanks! > > mm/kfence/core.c | 11 ++++++++++- > mm/kfence/kfence.h | 3 +++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index 13128fa13062..d4c7978cd75e 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -555,6 +555,8 @@ static bool __init kfence_init_pool(void) > * enters __slab_free() slow-path. > */ > for (i = 0; i < KFENCE_POOL_SIZE / PAGE_SIZE; i++) { > + struct slab *slab = page_slab(&pages[i]); > + > if (!i || (i % 2)) > continue; > > @@ -562,7 +564,11 @@ static bool __init kfence_init_pool(void) > if (WARN_ON(compound_head(&pages[i]) != &pages[i])) > goto err; > > - __SetPageSlab(&pages[i]); > + __folio_set_slab(slab_folio(slab)); > +#ifdef CONFIG_MEMCG > + slab->memcg_data = (unsigned long)&kfence_metadata[i / 2 - 1].objcg | > + MEMCG_DATA_OBJCGS; > +#endif We can probably put CONFIG_MEMCG_KMEM here, but it doesn't matter that much. In the long run we should get rid of CONFIG_MEMCG_KMEM anyway.