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 2A0FDC433F5 for ; Mon, 28 Mar 2022 01:53:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A502F8D0002; Sun, 27 Mar 2022 21:53:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A00798D0001; Sun, 27 Mar 2022 21:53:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C8F08D0002; Sun, 27 Mar 2022 21:53:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 7A1188D0001 for ; Sun, 27 Mar 2022 21:53:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3EA8CA32AA for ; Mon, 28 Mar 2022 01:53:20 +0000 (UTC) X-FDA: 79292122560.27.8B738EA Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by imf22.hostedemail.com (Postfix) with ESMTP id 0C292C0029 for ; Mon, 28 Mar 2022 01:53:18 +0000 (UTC) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-2e5e176e1b6so133233157b3.13 for ; Sun, 27 Mar 2022 18:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ld6gg90UxBewd5EuGKuXKzT3kPcWyc890roNOgvWpfk=; b=5h4Rr7Cxj8cXXW8wb+j0jqJ/+Tk37Wv78eprkSxBXIZ5n57eqyJPv6fvnWo0y+kDq9 yFFV1uIFMQmTsZczXyoU3t/U0n2UDVBaAtW5ZBltiQ+KDK1mp6RiTy1BSCN9Hlwke1MG Xed05ry/fZyrvE6Wpzkn7WqLi9SZAB7jOdx/cWbSP84BP2+UWis0XNYchFwFGLTRJgZZ QwXNexHoVXd+3DjEio4oPOVYbLFAfOlOjfqHc+BpE2H4lzKPJKINjHhZhe/4s+vLPeRP pYfwlVKvDmow3zL0HveL743Xxm4bhwPuFlk9fWPq+61gdMGzbmA1JGQNnD2+ofRU67ZR gKBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ld6gg90UxBewd5EuGKuXKzT3kPcWyc890roNOgvWpfk=; b=YCiUWyOQXAUJWrypuQOngl0Nv2afBUoHTlnIfW2JFYDfVsjysrwtavcNHJ8zOI7V5p mz6PYvRP8kQOsJTXS8mvXvl2349ZuxWp1OEtxhWDHCULCqZQzPtZhOd9zL+7hN7s+izj JuAe6a0cmZWu3fWuPOvLRLUwp/HPwru2IL5cVIkLY8GPxGf1MXJymNwzOCzuW2thDZW3 jYRw3Q2PCpIdKaEQY1LsXWwa4KmXe9otRmY1FC0g1K38cojCUXlsdoNZehCLscfRQJ6C Ax5NGmDKKIb37F7u/gRPortTpnHIInBANJa7ITKWrt+i9ZBZ+yOWsVFh0cErww4Cm4ki keJw== X-Gm-Message-State: AOAM532Gl9TDat7t2cLG7VlUk58Tu+f5kqV9dxpCir8SdAmCuT7P5vse LQg/rZ4jRiioLXpfU8E5DPcyAdR5UcFxG9UrItrayA== X-Google-Smtp-Source: ABdhPJxYugzqwYygfRvHynhLC1/y3UEtpQG+g+Vx00P+G+LPRSrHTxtSoTXnS8V1aBHStCTQzJ52zfmvBCz0y9N1JKA= X-Received: by 2002:a81:897:0:b0:2e5:f3b2:f6de with SMTP id 145-20020a810897000000b002e5f3b2f6demr23165273ywi.141.1648432398131; Sun, 27 Mar 2022 18:53:18 -0700 (PDT) MIME-Version: 1.0 References: <20220327051853.57647-1-songmuchun@bytedance.com> <20220327051853.57647-2-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Mon, 28 Mar 2022 09:52:40 +0800 Message-ID: Subject: Re: [PATCH 2/2] mm: kfence: fix objcgs vector allocation To: Marco Elver Cc: Linus Torvalds , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , kasan-dev , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 8wja3cfscojydxr369s39kaj93zysr7s Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5h4Rr7Cx; spf=pass (imf22.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.128.177 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0C292C0029 X-HE-Tag: 1648432398-432066 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 Mon, Mar 28, 2022 at 1:31 AM Marco Elver wrote: > > On Sun, 27 Mar 2022 at 07:19, 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 > > --- > > mm/kfence/core.c | 3 +++ > > mm/kfence/kfence.h | 1 + > > 2 files changed, 4 insertions(+) > > Thanks for this -- mostly looks good. Minor comments below + also > please fix what the test robot reported. Will do. > > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > > index 13128fa13062..9976b3f0d097 100644 > > --- a/mm/kfence/core.c > > +++ b/mm/kfence/core.c > > @@ -579,9 +579,11 @@ static bool __init kfence_init_pool(void) > > } > > > > for (i = 0; i < CONFIG_KFENCE_NUM_OBJECTS; i++) { > > + struct slab *slab = virt_to_slab(addr); > > struct kfence_metadata *meta = &kfence_metadata[i]; > > > > /* Initialize metadata. */ > > + slab->memcg_data = (unsigned long)&meta->objcg | MEMCG_DATA_OBJCGS; > > Maybe just move it to kfence_guarded_alloc(), see "/* Set required > slab fields */", where similar initialization on slab is done. But slab->memcg_data is special since it is only needed to be initialized once. I think it is better move it to the place where __SetPageSlab(&pages[i]) is. What do you think? > > > INIT_LIST_HEAD(&meta->list); > > raw_spin_lock_init(&meta->lock); > > meta->state = KFENCE_OBJECT_UNUSED; > > @@ -938,6 +940,7 @@ void __kfence_free(void *addr) > > { > > struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); > > > > + KFENCE_WARN_ON(meta->objcg); > > This holds true for both SLAB and SLUB, right? (I think it does, but > just double-checking.) Right. Thanks.