From nobody Fri Jun 19 17:59:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B8E5C4332F for ; Thu, 31 Mar 2022 08:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233142AbiCaImP (ORCPT ); Thu, 31 Mar 2022 04:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbiCaImO (ORCPT ); Thu, 31 Mar 2022 04:42:14 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE371F6F1A; Thu, 31 Mar 2022 01:40:26 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1648716024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Gjd+dbhFmrBLNB/9TKNS+UOHcvb+YXKxRkGJlSXZ+Tw=; b=SNknQRMaIDmyxd6oN5iXxs3eXvXhPLSnioo7N0kQXqV0Phb5RdHweKFC3vVD0tGSuBn0Kv xPvS31sPQoh0yuaDJYF9FieeW9zCvVucER8X3/M01ojzNDzDcf2MiKIE3bOPCpo7DXwROu OGCS/uQs3oo50FkVzKLSKxC//Vs/pLg= Date: Thu, 31 Mar 2022 11:40:23 +0300 MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vasily Averin Subject: [PATCH nft] nft: memcg accounting for dynamically allocated objects To: Pablo Neira Ayuso Cc: kernel@openvz.org, Jozsef Kadlecsik , Florian Westphal , netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Roman Gushchin References: Content-Language: en-US In-Reply-To: Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" nft_*.c files whose NFT_EXPR_STATEFUL flag is set on need to use __GFP_ACCOUNT flag for objects that are dynamically allocated from the packet path. Such objects are allocated inside .init() or .clone() callbacks of struct nft_expr_ops executed in task context while processing netlink messages. In addition, this patch adds accounting to nft_set_elem_expr_clone() used for the same purposes. Signed-off-by: Vasily Averin Acked-by: Roman Gushchin --- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nft_connlimit.c | 4 ++-- net/netfilter/nft_counter.c | 4 ++-- net/netfilter/nft_last.c | 4 ++-- net/netfilter/nft_limit.c | 4 ++-- net/netfilter/nft_quota.c | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 04be94236a34..e01241151ef7 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5447,7 +5447,7 @@ int nft_set_elem_expr_clone(const struct nft_ctx *ctx= , struct nft_set *set, int err, i, k; =20 for (i =3D 0; i < set->num_exprs; i++) { - expr =3D kzalloc(set->exprs[i]->ops->size, GFP_KERNEL); + expr =3D kzalloc(set->exprs[i]->ops->size, GFP_KERNEL_ACCOUNT); if (!expr) goto err_expr; =20 diff --git a/net/netfilter/nft_connlimit.c b/net/netfilter/nft_connlimit.c index 3362417ebfdb..9c2146aac59e 100644 --- a/net/netfilter/nft_connlimit.c +++ b/net/netfilter/nft_connlimit.c @@ -77,7 +77,7 @@ static int nft_connlimit_do_init(const struct nft_ctx *ct= x, invert =3D true; } =20 - priv->list =3D kmalloc(sizeof(*priv->list), GFP_KERNEL); + priv->list =3D kmalloc(sizeof(*priv->list), GFP_KERNEL_ACCOUNT); if (!priv->list) return -ENOMEM; =20 @@ -214,7 +214,7 @@ static int nft_connlimit_clone(struct nft_expr *dst, co= nst struct nft_expr *src) struct nft_connlimit *priv_dst =3D nft_expr_priv(dst); struct nft_connlimit *priv_src =3D nft_expr_priv(src); =20 - priv_dst->list =3D kmalloc(sizeof(*priv_dst->list), GFP_ATOMIC); + priv_dst->list =3D kmalloc(sizeof(*priv_dst->list), GFP_ATOMIC | __GFP_AC= COUNT); if (!priv_dst->list) return -ENOMEM; =20 diff --git a/net/netfilter/nft_counter.c b/net/netfilter/nft_counter.c index f179e8c3b0ca..040a697d96b3 100644 --- a/net/netfilter/nft_counter.c +++ b/net/netfilter/nft_counter.c @@ -62,7 +62,7 @@ static int nft_counter_do_init(const struct nlattr * cons= t tb[], struct nft_counter __percpu *cpu_stats; struct nft_counter *this_cpu; =20 - cpu_stats =3D alloc_percpu(struct nft_counter); + cpu_stats =3D alloc_percpu_gfp(struct nft_counter, GFP_KERNEL_ACCOUNT); if (cpu_stats =3D=3D NULL) return -ENOMEM; =20 @@ -235,7 +235,7 @@ static int nft_counter_clone(struct nft_expr *dst, cons= t struct nft_expr *src) =20 nft_counter_fetch(priv, &total); =20 - cpu_stats =3D alloc_percpu_gfp(struct nft_counter, GFP_ATOMIC); + cpu_stats =3D alloc_percpu_gfp(struct nft_counter, GFP_ATOMIC | __GFP_ACC= OUNT); if (cpu_stats =3D=3D NULL) return -ENOMEM; =20 diff --git a/net/netfilter/nft_last.c b/net/netfilter/nft_last.c index 4f745a409d34..4cf4f6349855 100644 --- a/net/netfilter/nft_last.c +++ b/net/netfilter/nft_last.c @@ -30,7 +30,7 @@ static int nft_last_init(const struct nft_ctx *ctx, const= struct nft_expr *expr, u64 last_jiffies; int err; =20 - last =3D kzalloc(sizeof(*last), GFP_KERNEL); + last =3D kzalloc(sizeof(*last), GFP_KERNEL_ACCOUNT); if (!last) return -ENOMEM; =20 @@ -105,7 +105,7 @@ static int nft_last_clone(struct nft_expr *dst, const s= truct nft_expr *src) { struct nft_last_priv *priv_dst =3D nft_expr_priv(dst); =20 - priv_dst->last =3D kzalloc(sizeof(*priv_dst->last), GFP_ATOMIC); + priv_dst->last =3D kzalloc(sizeof(*priv_dst->last), GFP_ATOMIC | __GFP_AC= COUNT); if (!priv_dst->last) return -ENOMEM; =20 diff --git a/net/netfilter/nft_limit.c b/net/netfilter/nft_limit.c index a726b623963d..d7779d5f3cbb 100644 --- a/net/netfilter/nft_limit.c +++ b/net/netfilter/nft_limit.c @@ -90,7 +90,7 @@ static int nft_limit_init(struct nft_limit_priv *priv, priv->rate); } =20 - priv->limit =3D kmalloc(sizeof(*priv->limit), GFP_KERNEL); + priv->limit =3D kmalloc(sizeof(*priv->limit), GFP_KERNEL_ACCOUNT); if (!priv->limit) return -ENOMEM; =20 @@ -144,7 +144,7 @@ static int nft_limit_clone(struct nft_limit_priv *priv_= dst, priv_dst->burst =3D priv_src->burst; priv_dst->invert =3D priv_src->invert; =20 - priv_dst->limit =3D kmalloc(sizeof(*priv_dst->limit), GFP_ATOMIC); + priv_dst->limit =3D kmalloc(sizeof(*priv_dst->limit), GFP_ATOMIC | __GFP_= ACCOUNT); if (!priv_dst->limit) return -ENOMEM; =20 diff --git a/net/netfilter/nft_quota.c b/net/netfilter/nft_quota.c index f394a0b562f6..2def4d92a170 100644 --- a/net/netfilter/nft_quota.c +++ b/net/netfilter/nft_quota.c @@ -90,7 +90,7 @@ static int nft_quota_do_init(const struct nlattr * const = tb[], return -EOPNOTSUPP; } =20 - priv->consumed =3D kmalloc(sizeof(*priv->consumed), GFP_KERNEL); + priv->consumed =3D kmalloc(sizeof(*priv->consumed), GFP_KERNEL_ACCOUNT); if (!priv->consumed) return -ENOMEM; =20 @@ -236,7 +236,7 @@ static int nft_quota_clone(struct nft_expr *dst, const = struct nft_expr *src) { struct nft_quota *priv_dst =3D nft_expr_priv(dst); =20 - priv_dst->consumed =3D kmalloc(sizeof(*priv_dst->consumed), GFP_ATOMIC); + priv_dst->consumed =3D kmalloc(sizeof(*priv_dst->consumed), GFP_ATOMIC | = __GFP_ACCOUNT); if (!priv_dst->consumed) return -ENOMEM; =20 --=20 2.31.1