Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp358943rdb; Sat, 30 Sep 2023 07:15:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuhi8GFrUX7Hg1ll7XiwKFzeoBcw7bF2gCBWLlOOMVWuWUOxf//wqVUYObk7gKf6YImrix X-Received: by 2002:a05:6a20:560b:b0:163:ab2b:bddd with SMTP id ir11-20020a056a20560b00b00163ab2bbdddmr1136021pzc.27.1696083314385; Sat, 30 Sep 2023 07:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696083314; cv=none; d=google.com; s=arc-20160816; b=0A4Zf8EvyA6P7CVPNPjTp5wBh0myyQpFgyh8seAou44/dcaYOpixQZK4ke+tY2B4Bj 4Dc1EZRB1FetqJfYBXqPHxX8EYjtsw9ubnom5uCPwr20g8wTf8G1TZ0pD8NhmeOcbXCs 6pv0wwlevOXU5r4i3A+eCqiaTg4I6xT1DP/GKYZkm2OlAUqmP4qrpAZJxtpuCMqrB6FR gL0B48ByVsA/5rbxDquccpMOiVr23BmOkc4HtRIlgBvIuJ6luqFja11NVoFtVaZBYkmL hm8t8E6Y2bUC/5Aq+ZO/bFeclFx6aVPraiUITfNzlelmo8LrRLPegLLsP5JURjdCQFGu QTkg== 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=GrOh8lyhpWnv6fQ7PEuyh7hTNeBQucAMexY2PVem5IM=; b=PIdeoT1umN5InJ+Q+MET/F/19nQuRE9vJ9MjbYzDW6a+g37N5E0382TlCRELVFT3h+ 2qLy59nhNHRJ04OYHltugd2rkWnB0xAM2F0ABXZv/LcJsfi4D8T2b/o+WiQ9M0AX9Qd5 6W0L62b2vbq93FYaqBC2Uu7/soov+bJayWSuDZG//SEQTOWDFXK0ZI7qxDIKVLwDVVU5 aBuEfH1qtydBJV9RlcBvYEVVo37GiYdoBukkf16i3nJ3lgVsnUcJQ5B4pwZu1+dDqc9h 7ckYjkOfb7a9bGmim2APzHgxS0gc7gOxO9IKwB1y7TUVYXPxrk6/PU/02FFXIBnnps9C +6dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=odkLZGFv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h11-20020a63574b000000b0057828b85ae3si23062561pgm.439.2023.09.30.07.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 07:15:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=odkLZGFv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 0103B81BF327; Fri, 29 Sep 2023 11:02:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233862AbjI2SBo (ORCPT + 99 others); Fri, 29 Sep 2023 14:01:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233728AbjI2SBj (ORCPT ); Fri, 29 Sep 2023 14:01:39 -0400 Received: from out-194.mta0.migadu.com (out-194.mta0.migadu.com [91.218.175.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD7E01B7 for ; Fri, 29 Sep 2023 11:01:29 -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=1696010488; 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=odkLZGFvcc5TTuJvilLKehHXRk/B6mY4ABoJ1wkhqpX6hgrcQG2DXR/Xkyfy/HGnDasNt6 5JRdpKxIA1lbfyIu/AkdURXUJc8ZL7aiQApQLkXhhdoWIzk+PAht+vVeY3dVj+R1otYNom anh+3HHhyLLzhbFfFWBmw6+6M0/vXGg= 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 , Roman Gushchin Subject: [PATCH v1 5/5] percpu: scoped objcg protection Date: Fri, 29 Sep 2023 11:00:55 -0700 Message-ID: <20230929180056.1122002-6-roman.gushchin@linux.dev> In-Reply-To: <20230929180056.1122002-1-roman.gushchin@linux.dev> References: <20230929180056.1122002-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Fri, 29 Sep 2023 11:02: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