Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp664694rdb; Thu, 19 Oct 2023 15:55:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHp1Jm2NZ3A8jZ3Q40WkgBu+CewVT73qg8atCaYDKZBZ16IOvD9BYzwrywYR2r99pDs8pk X-Received: by 2002:a05:6a20:958d:b0:161:3120:e872 with SMTP id iu13-20020a056a20958d00b001613120e872mr191648pzb.20.1697756130264; Thu, 19 Oct 2023 15:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697756130; cv=none; d=google.com; s=arc-20160816; b=MDWjTtPQpHWoJHwJHNR6iE/Q8avrbmicjfpvhbI1nUf/3sQ5xPUjDYeTwR86qVUtdv QMXBUZlTZAkmMOckJoQodB+MR/a7JyP2prYRJEFYv4T5+Px3xn4PRPaiJBRkRorDSIfW QKwWyDUoIX7kG27065lqrboGonE0H2/ZFB4MKPkoOJnG3wNJeWnXSDil0iegmC7gVIul kaZp8D3HneTH23Un6tyqWFoWH8qYhW/VMyfLrb7H1g41xmaW6s9IdngSPuuUhHyJFg54 oM+0qV3PvdMmxwk8CYFKlzsr0bCuVVZ1SW2+135Dmm7q88GA8wq7v7M/xNu9eV4SOEH0 Qwsg== 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=BnzSFyH1H48PSMDn7iqVZlFC9YDx4r15eixWsUbXpKs=; fh=0sD7u+6ZeVLabXSJ0/ta2yf8mUfUXWwh1sJBhHvFyso=; b=OPX/MTnnw2APqYslJBrwG/zP/VLgGrQZL1JngJpOsBYCulnqcQmotcxVSjCoTJbNht KL3gQoeKrywN00fo1OLKCENQOfEbP9ZfILpDd1U/UY75e6mpzLxHdkAxb1OVJZwFtxPb zzFJ6lwby/6YkWAP8Ijq33r544R75omTACEWEDYrW3xuPOW0ogvMqtLEi7qMDbmpb/2r aPfY22ZHM3mXqV0p6IlYnsqHhJXQdvKo+DT23iO/1HhCTaheQm0DOBM2DdblwhepCmoI hmw62bMNCBZpfO8tEfqKCgejrNjSih1euYBpo3Eciw05X4YwZxDeyLxB1NwjeXWv2A/6 4oyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JnrPJVXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a23-20020a637057000000b00578db6172fdsi531400pgn.325.2023.10.19.15.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 15:55:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JnrPJVXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id DBBAF81EE383; Thu, 19 Oct 2023 15:55:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346702AbjJSWyi (ORCPT + 99 others); Thu, 19 Oct 2023 18:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346741AbjJSWy3 (ORCPT ); Thu, 19 Oct 2023 18:54:29 -0400 Received: from out-197.mta0.migadu.com (out-197.mta0.migadu.com [IPv6:2001:41d0:1004:224b::c5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 227D2126 for ; Thu, 19 Oct 2023 15:54:25 -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=1697756064; 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=BnzSFyH1H48PSMDn7iqVZlFC9YDx4r15eixWsUbXpKs=; b=JnrPJVXCVoN8MXZPI6RkQGBCNH63eYwmUrhXUzgISfnhW0IuWEsi18lYzeeVWxfLpgH4GW AMLpenUkuseR/R6nGzgHYvx/b8MQBc71GCbNQ7H4HmhTQkLQ3nhzStsySvA+ZV2v2EjjBo skR/Nl40nvBP7E2e2M3bFod11TDnBcY= From: Roman Gushchin To: Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Dennis Zhou , David Rientjes , Vlastimil Babka , Naresh Kamboju , Roman Gushchin Subject: [PATCH v5 5/6] percpu: scoped objcg protection Date: Thu, 19 Oct 2023 15:53:45 -0700 Message-ID: <20231019225346.1822282-6-roman.gushchin@linux.dev> In-Reply-To: <20231019225346.1822282-1-roman.gushchin@linux.dev> References: <20231019225346.1822282-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 15:55:28 -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) Tested-by: Naresh Kamboju Acked-by: Shakeel Butt Reviewed-by: Vlastimil Babka --- 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