Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2721404rdh; Wed, 27 Sep 2023 10:36:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuQAKJnmtRHAvtt7DQ4IIB1/AW+APcryLWM4teBkt2ZD/ZT8m6Y7cCwnMRc1yA83mQ80pu X-Received: by 2002:a17:903:244d:b0:1c3:ae56:4594 with SMTP id l13-20020a170903244d00b001c3ae564594mr3003160pls.49.1695836162736; Wed, 27 Sep 2023 10:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695836162; cv=none; d=google.com; s=arc-20160816; b=zI85C13nMdfq8IIp0Z0e6PIhsFpR89ACe5IB9i7EzeeJ092uIw6+8l43S7cGzoA/vl XYG/mMnE8KK8Ve5+9a/TV4q55PF+PP1y1ZeSHzwnyQPrZpLALpPuE2QzmWP+6box19B2 NSQgYQTv4dGFCBJ7oCmFuKSGARgHdoAqlDEVlGPNEtCirgUApIP7K1RD4UHJZzmyMlGe +J3CDRtrbE6VTeZjmx49lFjfgTqA+MKf3qxIDHotpZ+U1ZDdlErWiO3rpJhE0QRbeGVY 7/FeSR5xGwU30DoeKkO96CA+KDQ53x7e4aSoGxRgtdGouuVvTJxeMF8iqfhVgW3dP5AD vH1Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j6TjL0tOzMm9uw8Y9niPXJ1ezOtPxfS6WilpL+cESRE=; fh=J+ThODwbvpIaijJ/a/gIBgC20RizoNlQ1sjxEf1nY4o=; b=ju0f98RYvLdEmAXytVjIsrKyATVwFQSMsRHIH4azppEBNBSJyFbfgM6fHLeS6X6I50 LPwXN0nj21u9j+DYayLjjmwOgMvslVoKytu1stR652NT8s8SAkuWPtj9aamfbVZs1H4k BzXSqwPLAnwWVvJraGwXw/3N2p4T/4EYwVUIKgU+UVxKK5RkRMuHX4YQ29xBlR0/aA17 y12KYqZkCgxcTBG2/SOHYh3MglF6LHj9dPBquDLXgtyWSpTMTxOCLjCn2T3qj3gNv074 MWEDDYB3uWC/ekOR2SKXac7K84NvahkVkdt7nBChwovDt+kqm7w6tdcO5Rxf4wSFEQjI FmcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="V//ihQR3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id i5-20020a170902c94500b001bdebddc2f7si17820470pla.257.2023.09.27.10.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="V//ihQR3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B944980BEB27; Wed, 27 Sep 2023 08:09:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232378AbjI0PJW (ORCPT + 99 others); Wed, 27 Sep 2023 11:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjI0PJO (ORCPT ); Wed, 27 Sep 2023 11:09:14 -0400 Received: from out-193.mta1.migadu.com (out-193.mta1.migadu.com [IPv6:2001:41d0:203:375::c1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D6811AC for ; Wed, 27 Sep 2023 08:09:07 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1695827344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j6TjL0tOzMm9uw8Y9niPXJ1ezOtPxfS6WilpL+cESRE=; b=V//ihQR3BNX8mCaIN2RHbsj24ybf5tsZR80ZurjIq/P4zdNE6/CNiqXGaUHELfnQzFCvFu ald/Rulhzhr/xKdfWTbsCyE4U6wbBWcnVys7yuOgrgVNmXQqA6dKbwvtqUzJLSfKLVSbkz VEv/GP4pB24vCqh16SVt3PIzQgO5+VI= From: Roman Gushchin To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Dennis Zhou , Andrew Morton , Roman Gushchin Subject: [PATCH rfc 5/5] percpu: scoped objcg protection Date: Wed, 27 Sep 2023 08:08:32 -0700 Message-ID: <20230927150832.335132-6-roman.gushchin@linux.dev> In-Reply-To: <20230927150832.335132-1-roman.gushchin@linux.dev> References: <20230927150832.335132-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 08:09:46 -0700 (PDT) Similar to slab and kmem, switch to a scope-based protection of the objcg pointer to avoid. Signed-off-by: Roman Gushchin (Cruise) --- mm/percpu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index a7665de8485f..f53ba692d67a 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1628,14 +1628,12 @@ static bool pcpu_memcg_pre_alloc_hook(size_t size, gfp_t gfp, if (!memcg_kmem_online() || !(gfp & __GFP_ACCOUNT)) return true; - objcg = get_obj_cgroup_from_current(); + objcg = current_obj_cgroup(); if (!objcg) return true; - if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) { - obj_cgroup_put(objcg); + if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) return false; - } *objcgp = objcg; return true; @@ -1649,6 +1647,7 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, return; if (likely(chunk && chunk->obj_cgroups)) { + obj_cgroup_get(objcg); chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg; rcu_read_lock(); @@ -1657,7 +1656,6 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, rcu_read_unlock(); } else { obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size)); - obj_cgroup_put(objcg); } } -- 2.42.0