Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5588018pxb; Mon, 28 Mar 2022 14:37:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl24+SLL1L/9k6C4cG3EZFmSzjnbt+cPG9NXTUMyTsGgDqvUYhJamRrZUc+e1Lol4QhBSP X-Received: by 2002:a05:6870:e38c:b0:dd:a559:6543 with SMTP id x12-20020a056870e38c00b000dda5596543mr597618oad.89.1648503429315; Mon, 28 Mar 2022 14:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648503429; cv=none; d=google.com; s=arc-20160816; b=I5jiyhJ+QAklOjFDlE645Sa0iDW6MKsEK/piuiDL8bFtxdFKL8hBjTf90R4H54lVul JDh2+ONiF2B821VwOkwfd7z8ja5W+j63l7yxEtN/d3okco7r2PdzoDv98f0PNkrwoK4N XI+Jwip2UsBzJpyTeR4ED/a0KIPUweil0XSYnuhW2yYQOnzyVyfmGkGH3fhBKG3GFhkq DyLr8MLzaJJoFQMi1iHmNt9hv78TxO692rpc/ETNWzUfENeSIXTG737IS94KZku0j0OC HgcAxljmPn8CT6GMH+roV/2qYDVnSNyFYGZmkL4aXB3BP0w6qEw+4U3PfWALUrEpmZY8 7+4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=OWWkThZzG6fg+LvXYQeO6VrIXNOo2Za760j3Jl9Casc=; b=B2OqiA9fdPu+aFKhljjzmGE2j1KweLRctQ8Q/iCQZwQOYj4G9AppGM4JMxSB969MSF acTwitceiF+zowWoyvH/R0tCBlkDizFBkqLUZV9nUAGcNhg7h1uuCLZJCO1oFh5wOoBS n6UB9rsnjwKi2F/GCVASjxTIr4n0ot67zB544BoVsXeglhZB52ur6hp6fS8Lk+BXgAax HVccpOKiv4d+CJxAAH9DnEHHfdXXhob0QLHqG5CEEo8NSxtfm7FTwIsqzKPHE8zuSAWn EI0Mfj5PdGR3FRMJ9Lf0qb9m2cDjF2WU0hVhJMalcqTRSYUSPbMf/jzQL5eXkOj7kGgS V9Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YJ+SNrGd; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cv26-20020a056870c69a00b000ddb1d1c320si10679181oab.101.2022.03.28.14.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:37:09 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=YJ+SNrGd; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D2968BF06; Mon, 28 Mar 2022 14:14:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243232AbiC1Nak (ORCPT + 99 others); Mon, 28 Mar 2022 09:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243213AbiC1Naf (ORCPT ); Mon, 28 Mar 2022 09:30:35 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B11D3260B for ; Mon, 28 Mar 2022 06:28:54 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id gb19so14065696pjb.1 for ; Mon, 28 Mar 2022 06:28:54 -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=ylncudV9PDPaqX/k/mRdrAY3kkgcGphzsYn2ppkp54gLrAzlZthdI7wOVU+c81chR9 d1TzBLT1eGnrjlUU2IE8riDmVRskKDrW/jmxmwQ+Yp06F90Vm32t8T9+FulEjrF4AeEd p7ZOQTpfjBr6xxHhiy3hfOocE3/ZNWjLrFIDcjUw6lO/uLpRLLO3THAN6tctOSPicP0y JK8D4M+GHupdUoCmu0wkI0p2XEBpPcabUecQx3cb3yNRB3vjCBNvtXrhXRfnuBKnFuwv fFHy7Vv0lz9BTbW6db1cDYy6ATeJdsVKyxiuP3S0QixHyzmXLwNvju8Pph6PFGWctyf2 c9bg== X-Gm-Message-State: AOAM533qRmf92pJKB+qMPDEg/+g+/qrjXe/66SLwN07yDwD4KQHNlWEf lo8Asg79N0DA0ObAacfQ2DDzlA== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 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 . 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]; -- 2.11.0