Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2208702rdb; Mon, 9 Oct 2023 17:16:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEY/GkcoGr/pudPrZMDtvAYF5id4qkQpSScFL3/cYsKTnrODR/izTP1GiIFnC3zSVRGegPh X-Received: by 2002:a17:902:988d:b0:1c9:b207:d412 with SMTP id s13-20020a170902988d00b001c9b207d412mr408158plp.37.1696896997998; Mon, 09 Oct 2023 17:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696896997; cv=none; d=google.com; s=arc-20160816; b=lXFCUJum6DP2Mejrwtf4+02A0kWhTpRLVYxW6JZs2J4Uvoji95KwSqkZLf71kGSbA8 9Y0Xy3ShYw+4+NxKCwiTXiynjrJd5zz4oDXAp/f3sLBBHmVuRCpQj6m11A0aQjav0SI3 B3SRB1Bqf4ERzomj49Xer7ZcWtaUfY/uwNXoEkGF5mzC2xs+Ir7WWXC5Ovjh4JIR1r7x BHoT5U+FQ3M/cGLRx8MF5XRc+kD3RdS0dnRoib2qXWyDNyJnj55AwgRpGbCzNwnQWRm9 sVr1LV/fOt2Kos88T2bzMrMAMkwmMJQbZUxulLUSntWm09jePuQ95bp6CPwVTdamNkw4 jkEw== 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=eIV/wktpjV+EeUDLeXhmhAmcuYEtVvgOWNik/7Ld4iQ=; b=DYTPL5mAzwnKTDcJADZOhxoeC/vv0L1F4fHE4IO7yY8J6ygx72mn2azmf6Yz5NMtsM TuNyj+mVP7Orcf9POi8lxZ0z39IHZ7ImtkwAAXPBQxAmz3w/xATMRLsQ/rivD0AHHqcy Cb0NXU43RaYJCnqZGoxpA7F8dqrehEVUuld8cJAbw+yIbKuEwhFWcf/AvKSvqvLgXxq1 hi/LPFDhOU/WmqYFuzsoxjXBpXNbGjX87okDHgPk7yM0VbZAEYCazamN7ycILrYB/G5C gNt20ejWOoNDKQVaZs7mvASl7yUIL5yR/Uvc5sZXUUxq6ghh3mUFN6GmOpMfqQgdpYsW Jm1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZGPVwiM2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l5-20020a170903120500b001bb0ba81053si11803721plh.50.2023.10.09.17.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 17:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZGPVwiM2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 3EB298083B5B; Mon, 9 Oct 2023 17:16:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379220AbjJJAKY (ORCPT + 99 others); Mon, 9 Oct 2023 20:10:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379191AbjJJAKV (ORCPT ); Mon, 9 Oct 2023 20:10:21 -0400 Received: from out-210.mta0.migadu.com (out-210.mta0.migadu.com [91.218.175.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 994C1BA for ; Mon, 9 Oct 2023 17:10:13 -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=1696896610; 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=ZGPVwiM2h+XunCiZLqM4FyYGsiSKjC0phq0S+wyUEtVkyO+vvaGmE0lOyAzfhgRkZqIQVI z+aLmjDpmuOiL6ag53Op+5oV0AIkM4FSmAvmbCqi/H5wKmFVEnAUYzw7h9+t++JC6EK5WG wCu/Uex1P/e7AHO9YRFh11WGzRmaLv8= 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 , David Rientjes , Vlastimil Babka , Naresh Kamboju , Roman Gushchin Subject: [PATCH v2 5/5] percpu: scoped objcg protection Date: Mon, 9 Oct 2023 17:09:29 -0700 Message-ID: <20231010000929.450702-6-roman.gushchin@linux.dev> In-Reply-To: <20231010000929.450702-1-roman.gushchin@linux.dev> References: <20231010000929.450702-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 17:16:19 -0700 (PDT) X-Spam-Level: ** 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