Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp321914rdg; Thu, 12 Oct 2023 06:47:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEIwNGvLU2TP0rp8EdZFspTeyxgzubMUuot38e+FL7Lebrovc/MytQ3eLSiCV/0qTzfFdT X-Received: by 2002:a05:6358:7299:b0:163:ce28:91ee with SMTP id w25-20020a056358729900b00163ce2891eemr18126460rwf.19.1697118470669; Thu, 12 Oct 2023 06:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697118470; cv=none; d=google.com; s=arc-20160816; b=BWr7XiL1Wz6572pmKmiuEvv72podRiggICxtP3dmRdJE4SwKpIFcvGZqMQ2cDTNtEi 5ek+bcYdzGPUqSLxPLRi3Ml6KgEdrGLTiwo2pkaqTGV9NuN7EEPaBYAgLnIGePrrzpJp H2f7GYnd1hcQZgPnLlFcIVU9ULtTJsWkCZZIg0DTyjNa5syPp2n1jZS+9zd/3etoO+iF Ss5vjLzUImEroNfexyKEOEIRkaOgliLgQ72wt6t3OY9GSm5FG4uqAOuLemoSboW0+tsv kYT+H2zYHlcRfKS4JX9WZ+dNLrgiSpqnZdrLUJkmHZZFzIpL2wUJira4Rv/x7wRaoYfS btLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=DuNnrzJ8TZmFHgla38IiJAHz6vdp6e7COdPQWBTgcM4=; fh=5yJCFl0E4GBItsE5gnZmBCRQCw2sx236sRuDrmal1bw=; b=HBV0Kjcy9bWaT3//C9HIMw/gjN5rLrs8pPt3NC0KNR0DpVlw/2umNpX1pS+x+jj8fm 1YLaEmwEoHYo+Rac2RZs2E/JdWTV4GlH4T47ki7cblDQYDMRiIbLAXOa5hNlCB3Xh5nk 7TuQ73ak82YNAVicOGf+wjIDXzH9ITuQye3PYgEnwLYVb9L3Sf7k9+Ob+ZBMBVBFqCU4 9+nUqROPW+5ttichDx7jdMIn/18fvwVAeVLntYNzyO4V6NHmo/vyHtWy73y+Dgf71rAH L9P1jn8P6hS4ASu1d7vN9FQt7ggPwPR1+w8CedRa+eLEPzQJ4PMOsZCYb0yU6njQXNBE kc1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="nR/y+VBz"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s21-20020a056a00195500b0068e3b121545si15158975pfk.58.2023.10.12.06.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 06:47:50 -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=@google.com header.s=20230601 header.b="nR/y+VBz"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 70B09816EBDB; Thu, 12 Oct 2023 06:47:48 -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 S1378999AbjJLNrc (ORCPT + 99 others); Thu, 12 Oct 2023 09:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379004AbjJLNrb (ORCPT ); Thu, 12 Oct 2023 09:47:31 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40DCAD6 for ; Thu, 12 Oct 2023 06:47:29 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d86766bba9fso1272847276.1 for ; Thu, 12 Oct 2023 06:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697118448; x=1697723248; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DuNnrzJ8TZmFHgla38IiJAHz6vdp6e7COdPQWBTgcM4=; b=nR/y+VBzi0jiHJNjW8yVfFrbqED5ry/ioJeRII6NAE7EZiCyYHU1UmimB5Zq6FS+l6 VdpWcYeu20nBHvfjW1Y4I1noXfmJa2jpeu0fr8BYy3gcHKx76Rs2mmlmpP3i/nz1tZpf 9YHgiUW5eiq6A2ZEarhxKxNk3QAOBxNwVyxRI3/WRmgzwf6vGkv/u/mA0gPwi8NO6q43 RlLHZZwirBfluc9CxkRH3XeGC63IfZSXOR9WX+HZAnvN++R9h72B6WzkHTfv0FsSiasd NWjaxDx7K2PvzvO+ijxEb5LChYv6uvhiacWLIt9mfYwAat6NqTkPKI6QzjL4H+NhrEEn ypiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697118448; x=1697723248; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DuNnrzJ8TZmFHgla38IiJAHz6vdp6e7COdPQWBTgcM4=; b=p1PROqFO7+RWa20np0FSqNGVGA8n7Z3fseUstvuPrv/JAf9UrmXSOtjqjcMed7dJ3c bPgG4kCGOaioYLYTnvUmUdqPFPQ5hy/OB2H3A+XcSK4Wr/5hEOdDl2bb46o3wBuWusbe 3pSOk/TlQ2rJFGjy6WWo8MHfaUVpoWrV4GIOa6bg38W8+zaz7wHX6ffmP9BrzX4rxMVQ TEFhfvMgm5zdtnsTDJfJ+8bDVmapP25aM7Ri+HEwHAmU+8gyJ19wGOU0Ia9LW3yLhz3s EZk2eP3UnZ71/PIlTGBg1j05xBBoY1/Ic6pBtb3SkPdRPyFG04cE0mObvENvj1cMOFU/ H9cQ== X-Gm-Message-State: AOJu0Yze062hlsP8TNXzOaGbmOmgyeORixC6ju34C/w+SPUqpTqd7rNP Qtawb8Kw6mek6+eLURjw4uNTJ2wgDl9FBQ== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:262e]) (user=shakeelb job=sendgmr) by 2002:a5b:5c9:0:b0:d8b:737f:8240 with SMTP id w9-20020a5b05c9000000b00d8b737f8240mr472636ybp.0.1697118448415; Thu, 12 Oct 2023 06:47:28 -0700 (PDT) Date: Thu, 12 Oct 2023 13:47:26 +0000 In-Reply-To: <20231010000929.450702-5-roman.gushchin@linux.dev> Mime-Version: 1.0 References: <20231010000929.450702-1-roman.gushchin@linux.dev> <20231010000929.450702-5-roman.gushchin@linux.dev> Message-ID: <20231012134726.kx3rcm7vkgxe3nib@google.com> Subject: Re: [PATCH v2 4/5] mm: kmem: scoped objcg protection From: Shakeel Butt To: Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Johannes Weiner , Michal Hocko , Muchun Song , Dennis Zhou , Andrew Morton , David Rientjes , Vlastimil Babka , Naresh Kamboju Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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]); Thu, 12 Oct 2023 06:47:48 -0700 (PDT) On Mon, Oct 09, 2023 at 05:09:28PM -0700, Roman Gushchin wrote: > Switch to a scope-based protection of the objcg pointer on slab/kmem > allocation paths. Instead of using the get_() semantics in the > pre-allocation hook and put the reference afterwards, let's rely > on the fact that objcg is pinned by the scope. > > It's possible because: > 1) if the objcg is received from the current task struct, the task is > keeping a reference to the objcg. > 2) if the objcg is received from an active memcg (remote charging), > the memcg is pinned by the scope and has a reference to the > corresponding objcg. > > Signed-off-by: Roman Gushchin (Cruise) Other than one nit below: Acked-by: Shakeel Butt > --- > include/linux/memcontrol.h | 6 +++++ > mm/memcontrol.c | 47 ++++++++++++++++++++++++++++++++++++-- > mm/slab.h | 10 +++----- > 3 files changed, 54 insertions(+), 9 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 277690af383d..0e53b890f063 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -1769,6 +1769,12 @@ bool mem_cgroup_kmem_disabled(void); > int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order); > void __memcg_kmem_uncharge_page(struct page *page, int order); > > +/* > + * The returned objcg pointer is safe to use without additional > + * protection within a scope, refer to the implementation for the > + * additional details. > + */ Let's add the definition of scope in the above comment as well like set_active_memcg and slab memcg hooks.