Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp411922lqp; Sun, 9 Jun 2024 01:41:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYplky4Gdz5eDOVUJktma0GHwNzOYleuvCarltkF5hFxTU2NLTqDIwdOEs3xWBtf8UCwsd34aq/ouCcVVPZgaJh5o6Qfb1AvVWV25ZSQ== X-Google-Smtp-Source: AGHT+IGF4XEXWp04L/c3zi4FCB0pMHp6joWX2jNSbYOLuj5YDynVGMq2LIeRRa0+bfpTxcebEXRg X-Received: by 2002:a17:903:41ca:b0:1f0:8c5e:ffdd with SMTP id d9443c01a7336-1f6d0113847mr103588725ad.4.1717922499772; Sun, 09 Jun 2024 01:41:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717922499; cv=pass; d=google.com; s=arc-20160816; b=iLXto5rmkiIAaHBLY7FRAEklh+i1+BI9gKZuS6P15d10yC0mWT++bsQmr5Q9HDS4Ek wjmXnb3btyDFiwIb6TqKa9E1tAST+jGbMQ3qx1BCZtTY84VU4zcuNVJcIn6atZP9OOvx jkBa4z12QhQbKZ9i7c3qsVkmLAEpIdOXbyGU0JnpsP/k27v/b2gnGYzwkngOITPkQ21P FzBMZLQCwAZ0gaeOsiUv4kA0pQXxQHIuM+ISSD/DFZs8PpIBEGTjPi0p6netfv28e9Gm nlpFOCxxRJe3Q5YB0d2wA8KXk+tyVTAM1AHhfhbKDiB1FHFfzKbtkW8uZ5hxiKAaz4RD 82WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UDrliNsi6qf9iZ0cJTSfrv8FntRHZmJcOSPF/U9CCyU=; fh=0A+svASQyDDdAT/pEHLSJXqMxPTGC6hn5MjH5nx5UmQ=; b=n/jXlFYlgU0RXYRY/oZrMoq5fv4NlSr6He2F/Ygt1Eke1gFGZfi6JsUycBwwyq274P W/sUGhtP0kh7Cq91Eop91PyHjXdvns4mNa9oA4tZBpN2UqqfH38TgOwEYoJpyhfFkMpk +zboWuy0HiGZMi4itC7/lClhPoGMs17sqtWkqHUqfzk7qyWFRJQd97Jwwy4g2yB5irNb ulZEYtOZ1rEdIyY/cJZg9ryV2jxOq6FX2omMLx/KbY6PTnTO46bgCPO5iJiTrpB1rQow k3UfWsRfxSHDj7JJPQ2aZU2mc6q7GUEmubRVVyFtMeuOQ16d7ea3cxQqyPhSJ2Zu37mT Gebg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=PQ8uixq9; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-207294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd823f01si43951305ad.598.2024.06.09.01.41.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 01:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=PQ8uixq9; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-207294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D1BF7282F26 for ; Sun, 9 Jun 2024 08:33:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35B686F30F; Sun, 9 Jun 2024 08:28:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="PQ8uixq9" Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE1BA5337C; Sun, 9 Jun 2024 08:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.134.164.83 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717921695; cv=none; b=bBFQM2MB6rJwgtyJvdsaG5EsmenFo2HKL8ZrqMmVd6v68zHQP+dHeakmw281fOmv5CmJuNn9gz5QM6w5FDNL82k7NBRKMOZSxD8H5wyDn+068Y/LBElPIiDtEUlKFrySyfD6b8wsmZndOX2nucMmi8AQYsIP2kLZJKP/yaXYKDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717921695; c=relaxed/simple; bh=XjSGzBEEN4R1uM6+FzoVLzsuvTNxmayPngOiT1u3sG0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=irqZFMnBerrKO9/dHkCbHAgcjTyzMDE6dZIul0kBZpPCtsoXXS//pDPBFbLde8tm6Q7mWXuQczy6gAS3dGuuR+Q5kv9WLx2RHyM6hQbV8S2O9tMPgLK2KIXGA2sGfgAoy4WSLdm8GF+Fxd0LPowO9Dc7IZmvK88Uy7yntxsGK+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr; spf=pass smtp.mailfrom=inria.fr; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b=PQ8uixq9; arc=none smtp.client-ip=192.134.164.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UDrliNsi6qf9iZ0cJTSfrv8FntRHZmJcOSPF/U9CCyU=; b=PQ8uixq9gJb8XJ5kYQyD9s/ymp/dqHay+TNM4exQnNxtZvPryBNvScc0 yKx1TUYcF+ilJUMjUqmuURKc0OVGwc7MvninM1ky5jsSke9R2PMmzcoBq 5PKM4rmRoXEoS5gWDJL6KrtSpCRSd6OHyLzDTxvaFTRnqD67aFFemBGjC w=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Julia.Lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.08,225,1712613600"; d="scan'208";a="169696909" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2024 10:27:49 +0200 From: Julia Lawall To: Pablo Neira Ayuso Cc: kernel-janitors@vger.kernel.org, Jozsef Kadlecsik , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Paul E . McKenney" , Vlastimil Babka Subject: [PATCH 14/14] netfilter: replace call_rcu by kfree_rcu for simple kmem_cache_free callback Date: Sun, 9 Jun 2024 10:27:26 +0200 Message-Id: <20240609082726.32742-15-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240609082726.32742-1-Julia.Lawall@inria.fr> References: <20240609082726.32742-1-Julia.Lawall@inria.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since SLOB was removed, it is not necessary to use call_rcu when the callback only performs kmem_cache_free. Use kfree_rcu() directly. The changes were done using the following Coccinelle semantic patch. This semantic patch is designed to ignore cases where the callback function is used in another way. // @r@ expression e; local idexpression e2; identifier cb,f; position p; @@ ( call_rcu(...,e2) | call_rcu(&e->f,cb@p) ) @r1@ type T; identifier x,r.cb; @@ cb(...) { ( kmem_cache_free(...); | T x = ...; kmem_cache_free(...,x); | T x; x = ...; kmem_cache_free(...,x); ) } @s depends on r1@ position p != r.p; identifier r.cb; @@ cb@p @script:ocaml@ cb << r.cb; p << s.p; @@ Printf.eprintf "Other use of %s at %s:%d\n" cb (List.hd p).file (List.hd p).line @depends on r1 && !s@ expression e; identifier r.cb,f; position r.p; @@ - call_rcu(&e->f,cb@p) + kfree_rcu(e,f) @r1a depends on !s@ type T; identifier x,r.cb; @@ - cb(...) { ( - kmem_cache_free(...); | - T x = ...; - kmem_cache_free(...,x); | - T x; - x = ...; - kmem_cache_free(...,x); ) - } // Signed-off-by: Julia Lawall Reviewed-by: Paul E. McKenney Reviewed-by: Vlastimil Babka --- net/netfilter/nf_conncount.c | 10 +--------- net/netfilter/nf_conntrack_expect.c | 10 +--------- net/netfilter/xt_hashlimit.c | 9 +-------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/net/netfilter/nf_conncount.c b/net/netfilter/nf_conncount.c index 8715617b02fe..587bfcb79723 100644 --- a/net/netfilter/nf_conncount.c +++ b/net/netfilter/nf_conncount.c @@ -275,14 +275,6 @@ bool nf_conncount_gc_list(struct net *net, } EXPORT_SYMBOL_GPL(nf_conncount_gc_list); -static void __tree_nodes_free(struct rcu_head *h) -{ - struct nf_conncount_rb *rbconn; - - rbconn = container_of(h, struct nf_conncount_rb, rcu_head); - kmem_cache_free(conncount_rb_cachep, rbconn); -} - /* caller must hold tree nf_conncount_locks[] lock */ static void tree_nodes_free(struct rb_root *root, struct nf_conncount_rb *gc_nodes[], @@ -295,7 +287,7 @@ static void tree_nodes_free(struct rb_root *root, spin_lock(&rbconn->list.list_lock); if (!rbconn->list.count) { rb_erase(&rbconn->node, root); - call_rcu(&rbconn->rcu_head, __tree_nodes_free); + kfree_rcu(rbconn, rcu_head); } spin_unlock(&rbconn->list.list_lock); } diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c index 21fa550966f0..9dcaef6f3663 100644 --- a/net/netfilter/nf_conntrack_expect.c +++ b/net/netfilter/nf_conntrack_expect.c @@ -367,18 +367,10 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class, } EXPORT_SYMBOL_GPL(nf_ct_expect_init); -static void nf_ct_expect_free_rcu(struct rcu_head *head) -{ - struct nf_conntrack_expect *exp; - - exp = container_of(head, struct nf_conntrack_expect, rcu); - kmem_cache_free(nf_ct_expect_cachep, exp); -} - void nf_ct_expect_put(struct nf_conntrack_expect *exp) { if (refcount_dec_and_test(&exp->use)) - call_rcu(&exp->rcu, nf_ct_expect_free_rcu); + kfree_rcu(exp, rcu); } EXPORT_SYMBOL_GPL(nf_ct_expect_put); diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 0859b8f76764..c2b9b954eb53 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -256,18 +256,11 @@ dsthash_alloc_init(struct xt_hashlimit_htable *ht, return ent; } -static void dsthash_free_rcu(struct rcu_head *head) -{ - struct dsthash_ent *ent = container_of(head, struct dsthash_ent, rcu); - - kmem_cache_free(hashlimit_cachep, ent); -} - static inline void dsthash_free(struct xt_hashlimit_htable *ht, struct dsthash_ent *ent) { hlist_del_rcu(&ent->node); - call_rcu(&ent->rcu, dsthash_free_rcu); + kfree_rcu(ent, rcu); ht->count--; } static void htable_gc(struct work_struct *work);