From patchwork Mon Mar 28 13:28:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12793610 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 E3CFBC43217 for ; Mon, 28 Mar 2022 13:28:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 547EA8D0002; Mon, 28 Mar 2022 09:28:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F7108D0001; Mon, 28 Mar 2022 09:28:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BEB98D0002; Mon, 28 Mar 2022 09:28:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 2E4458D0001 for ; Mon, 28 Mar 2022 09:28:57 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DBE2C22C3F for ; Mon, 28 Mar 2022 13:28:56 +0000 (UTC) X-FDA: 79293875472.02.82DE242 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf05.hostedemail.com (Postfix) with ESMTP id 9325410003B for ; Mon, 28 Mar 2022 13:28:55 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id p4-20020a17090ad30400b001c7ca87c05bso9930914pju.1 for ; Mon, 28 Mar 2022 06:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OWWkThZzG6fg+LvXYQeO6VrIXNOo2Za760j3Jl9Casc=; b=YJ+SNrGdPbhG4Hdu+QgUc3szEdJT3mDr8DxEK55+jCssVQl5LAtgnqYl7dDc1hxx72 E01D4AiZLzZjp8GCBW3fvMPVo0flIAsxQ/LH8AjMkw9afKRmTc5WhcMNdkNW7c5/sd8w BOWWAMUa0AFgyRoyUFLqveHBP0coEgUWNmOBkn5B2gmGQRrEu2Us0wH4BKWuv8nVrq6S 5mX+2jjqLhUod3xvd9gE2n8ysUQNlUL7CHZTWe+hEyYCscxyojVix5wFhpp9MLV/4WfH 2TebjWFsXuUYPDzXlT0BKuPF9e/dGp729BwpG1QBuVcNW6IfOd2EjChUbsyi+gvMsXv9 dwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OWWkThZzG6fg+LvXYQeO6VrIXNOo2Za760j3Jl9Casc=; b=Hp+lgUoevH9bKdJ6BjdRPb7aqwSspboE6siRGdO0hrSoRcc7SiAA9CYSZzwAXKbq0y pcedenrVrhAnlimkdKwnQWMABwoTpYX04RkZWdgbdPHbzWyiIrWXvEX8IAdVR9mJsjMX 76DZy17UxnMZcDyyFZgNbR8T7sma5o0nkogD0eVJ4R7PTHhP4d2lQAVsmEjY9+lj0gVt YGO+zPAL9v1AfUDZZ9ougnwZANXqYivviZ7QO1qUhD3mLJ+oR+07HrSGhqX4tf89211E YmAWAIokcBY0jB+POVV28qV93iZIEnSyOVSsPHP8m2SGeuoJqiXCeYg29M+MkXCF38PY 2+8g== X-Gm-Message-State: AOAM530B9ejq61ATT9kehmniU78+uQF6pH3jPqa4NeJ+FGENhJvIMJO5 3BCzGeGivLN4sPBz4f4xy+a4Dw== X-Google-Smtp-Source: ABdhPJzAlGHI/Kia99wHVmm5tvWLa5lQ97WbqD5zyvwlynxzhx1bxi7GFshiphoDnCUj+TsAFpBliA== X-Received: by 2002:a17:902:d48e:b0:154:b6a:9ff with SMTP id c14-20020a170902d48e00b001540b6a09ffmr26164352plg.2.1648474134256; Mon, 28 Mar 2022 06:28:54 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id m7-20020a056a00080700b004fb28fafc4csm9980936pfk.97.2022.03.28.06.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 06:28:54 -0700 (PDT) From: Muchun Song To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, Muchun Song Subject: [PATCH v2] mm: kfence: fix objcgs vector allocation Date: Mon, 28 Mar 2022 21:28:43 +0800 Message-Id: <20220328132843.16624-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-Stat-Signature: in3q3o9r4u4tehnyq3fekpe6g6giapoc Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YJ+SNrGd; spf=pass (imf05.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.54 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: 9325410003B X-HE-Tag: 1648474135-982587 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: 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 Reviewed-by: Marco Elver Reviewed-by: Roman Gushchin --- v2: - Fix compiler error reported by kernel test robot . 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 } /* @@ -938,6 +944,9 @@ void __kfence_free(void *addr) { struct kfence_metadata *meta = addr_to_metadata((unsigned long)addr); +#ifdef CONFIG_MEMCG + KFENCE_WARN_ON(meta->objcg); +#endif /* * If the objects of the cache are SLAB_TYPESAFE_BY_RCU, defer freeing * the object, as the object page may be recycled for other-typed diff --git a/mm/kfence/kfence.h b/mm/kfence/kfence.h index 2a2d5de9d379..9a6c4b1b12a8 100644 --- a/mm/kfence/kfence.h +++ b/mm/kfence/kfence.h @@ -89,6 +89,9 @@ struct kfence_metadata { struct kfence_track free_track; /* For updating alloc_covered on frees. */ u32 alloc_stack_hash; +#ifdef CONFIG_MEMCG + struct obj_cgroup *objcg; +#endif }; extern struct kfence_metadata kfence_metadata[CONFIG_KFENCE_NUM_OBJECTS];