From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41B2CC25B74 for ; Mon, 27 May 2024 21:48:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A15526B007B; Mon, 27 May 2024 17:48:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C5166B0083; Mon, 27 May 2024 17:48:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88D786B0085; Mon, 27 May 2024 17:48:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6EBD46B007B for ; Mon, 27 May 2024 17:48:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8E731615C9 for ; Mon, 27 May 2024 21:48:42 +0000 (UTC) X-FDA: 82165515684.09.E4AB4F1 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 4F3B710000A for ; Mon, 27 May 2024 21:48:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RYfkXGT0; spf=pass (imf14.hostedemail.com: domain of "SRS0=XY0/=M6=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=XY0/=M6=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716846520; h=from:from:sender:reply-to: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ErORbYzvKUSyDcB4d92mqinjlqiwXMalzYNC5j1fgms=; b=nVhGvrQ3Qzy+m4D1QXyRuFfB6jJ5gjurblrVLVmcb3MyBqP7JqtPt6+dZ8zX5rFkMbr0LC +PuCX56YAeqqaiq+mX7XDa/L2RCDgNfnbspQDZOLSEj9jaVUZE2RZUV5zlPkQ0+FMt/1ms Or+EjgiNbbInsXo2fMCkt8ljOxO8Jiw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RYfkXGT0; spf=pass (imf14.hostedemail.com: domain of "SRS0=XY0/=M6=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=XY0/=M6=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716846520; a=rsa-sha256; cv=none; b=B/jos03QloVwdk0E2wA6aA9t8MfbDhRB01NjcamhU8Scj6ETAWXOcwzLPkt/c7bXe1gh+L B1C17rW5Kioh+nyIzAcciui99KrEY3wKpGzbDuoTNxV4T2LT+SPt3DgZLE2qydFZPfu403 GKICKrlYHoD+eRf1M0o/JJq4smXhAoQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 754CCCE10C9; Mon, 27 May 2024 21:48:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3E97C2BBFC; Mon, 27 May 2024 21:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716846513; bh=7DzU3WfDOyqKx6+sboxpDsr3KOvdgZrKamCVzoiQLBQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=RYfkXGT0Fha+rO2AeZkwkwl70kRi5kkkPptwwBDeIomzkh+TRAcyKvJiTED4Aod9/ SprXZIxQ1kUroH6M865ys+dmTiSmZOIlV28xBFz9FlPeu5MWJu+SfNRBGPYSLPvYCw C9g6yzfKTrG6Y0ZMtiVqTwhWho8CXT12Vf7MQyA5ZPbihv2xSxlxJpGnNiIQ76Cg3Z 2O5866awdLcA9J5ZlCqc4O3659/K7uazY4i43YXyYE9ZVjt4jix+HHF7mlsvTWoUMG rHKUKVMDf39D9p2KzMAgt2bZkj6cQ8pt+AyIhwrwxi2tkcQr5DDi1U0t4qby28OhzP Q8tYLixxX601Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5762ECE0EE1; Mon, 27 May 2024 14:48:33 -0700 (PDT) Date: Mon, 27 May 2024 14:48:33 -0700 From: "Paul E. McKenney" To: Julia Lawall Cc: Vlastimil Babka , "linux-mm@kvack.org" , RCU , cocci@inria.fr, qiang.zhang1211@gmail.com Subject: Re: [cocci] patch idea: convert trivial call_rcu users to kfree_rcu Message-ID: <2a64cf68-2189-4553-88c9-fd73784c22ff@paulmck-laptop> Reply-To: paulmck@kernel.org References: <68b85796-c674-4691-936a-2051849f4692@suse.cz> <6b7e3ed9-d974-cb3b-6839-a6b7cf5f5a36@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4F3B710000A X-Stat-Signature: q5gfn8ic3imwm5srqef6mwdysr4i1386 X-Rspam-User: X-HE-Tag: 1716846518-558616 X-HE-Meta: U2FsdGVkX19nA+HDfbLO4WStpgfRY9pWi9iPVYEJMlUKxm+UHlyVm3aIRGspBuSHf/+Hi+r+7XUzf6XEqICo7Mdj6GauLdvXkKiLIlaV/9kljPhikPkDHLDY4Xd+ZzIuyQCXrMbgLMAAnY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e5dR5huZeQjfzeSEw7WlMVgaj0D/Vo0iTfUdcjS/rSILfzg9t6WdPcj7BQzX1M/mxImAQ7uj2Q1++dg1PEJPXEIy7fpmkw6hvOVQMOuGm17MrulwKwZRuuAlTowwkDAeIJ/QtLjGiEdM5bADgxlGhPChOguquUsC3S8qBuiSbeyBcytbzwtuY4EvBfJx8FyZ96KbgSpRAB2Au+uOFRFVnAT8ptKQYFXdTDyUEWaVm9F3dLjPAyfe6hN6fu3RS00E71y9Rwyco0GQDnz7pl9FchUxuuposJUJRn+siax1KeUaJUT4exM4HVrc6nR7KF+PhzHDCY1N7yikV5xtnZz5YaYEsI05iavlXWwbCtOG2iRbOJBuWTqI8iuRYyTAHR6BpIMXCS6Z8rQVCxsGR3MbUIryiC/vZXR9d85sIsISvO4UaaBjTxnUx4E7RqZgMiu9el6BqveHr22L16PXCZ3xqfo4Up X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, May 27, 2024 at 10:43:08PM +0200, Julia Lawall wrote: > > > On Mon, 27 May 2024, Paul E. McKenney wrote: > > > On Mon, May 27, 2024 at 10:13:40AM +0200, Julia Lawall wrote: > > > > > > > > > On Mon, 27 May 2024, Vlastimil Babka wrote: > > > > > > > Hi, > > > > > > > > one bit from LSF/MM discussions is that there might be call_rcu users with a > > > > callback that only does a kmem_cache_free() to a specific cache. Since SLOB > > > > was removed, it's always ok to use kfree() and thus also kfree_rcu() on > > > > allocations from kmem_cache_alloc() in addition to kmalloc(). Thus, such > > > > call_rcu() users might be simplified to kfree_rcu(). I found some cases > > > > semi-manually, but I'd expect coccinelle could help here so if anyone wants > > > > to take this task, feel free to. > > > > > > Thanks for the suggestion! I will try to look into it. > > > > Thank you both! > > I found the following functions. Do you want some other information, such > as where they are called from? Thank you! > Ignore the -s at the beginning of some lines. Those are for emphasis. not > to suggest to remove the code. Well, the idea is to remove not only those lines, but the functions containing them as well. ;-) Then each call_rcu() function becomes kfree_rcu(). > I checked that the functions are only used in calls to call_rcu. Good point, I had forgotten about that possibility! > Without more effort, Coccinelle only looks for functions defined in the > same file. Here are the functions that are passed to call_rcu where the > function is not defined in the same file: > > need definition for audit_free_rule_rcu > need definition for __i915_gem_free_object_rcu > need definition for io_eventfd_ops > need definition for ip_vs_dest_dst_rcu_free > need definition for __put_task_struct_rcu_cb > need definition for radix_tree_node_rcu_free > > They all do something more, although radix_tree_node_rcu_free doesn't do > much more (some memsets). Those might be important in order to handle the possibility of readers holding a reference to a given block of memory across the time that it is freed and then reallocated, but I cannot say for sure. In most cases, the reinitialization at reallocation time suffices. Thanx, Paul > julia > > diff -u -p /home/jll/linux/drivers/net/wireguard/allowedips.c /tmp/nothing/drivers/net/wireguard/allowedips.c > --- /home/jll/linux/drivers/net/wireguard/allowedips.c > +++ /tmp/nothing/drivers/net/wireguard/allowedips.c > @@ -50,7 +50,6 @@ static void push_rcu(struct allowedips_n > > static void node_free_rcu(struct rcu_head *rcu) > { > - kmem_cache_free(node_cache, container_of(rcu, struct allowedips_node, rcu)); > } > > static void root_free_rcu(struct rcu_head *rcu) > diff -u -p /home/jll/linux/fs/ecryptfs/dentry.c /tmp/nothing/fs/ecryptfs/dentry.c > --- /home/jll/linux/fs/ecryptfs/dentry.c > +++ /tmp/nothing/fs/ecryptfs/dentry.c > @@ -53,8 +53,6 @@ struct kmem_cache *ecryptfs_dentry_info_ > > static void ecryptfs_dentry_free_rcu(struct rcu_head *head) > { > - kmem_cache_free(ecryptfs_dentry_info_cache, > - container_of(head, struct ecryptfs_dentry_info, rcu)); > } > > /** > diff -u -p /home/jll/linux/kernel/fork.c /tmp/nothing/kernel/fork.c > --- /home/jll/linux/kernel/fork.c > +++ /tmp/nothing/kernel/fork.c > @@ -378,7 +378,6 @@ static struct kmem_cache *thread_stack_c > > static void thread_stack_free_rcu(struct rcu_head *rh) > { > - kmem_cache_free(thread_stack_cache, rh); > } > > static void thread_stack_delayed_free(struct task_struct *tsk) > diff -u -p /home/jll/linux/kernel/workqueue.c /tmp/nothing/kernel/workqueue.c > --- /home/jll/linux/kernel/workqueue.c > +++ /tmp/nothing/kernel/workqueue.c > @@ -5024,8 +5024,6 @@ fail: > > static void rcu_free_pwq(struct rcu_head *rcu) > { > - kmem_cache_free(pwq_cache, > - container_of(rcu, struct pool_workqueue, rcu)); > } > > /* > diff -u -p /home/jll/linux/net/ipv4/inetpeer.c /tmp/nothing/net/ipv4/inetpeer.c > --- /home/jll/linux/net/ipv4/inetpeer.c > +++ /tmp/nothing/net/ipv4/inetpeer.c > @@ -130,7 +130,6 @@ static struct inet_peer *lookup(const st > > static void inetpeer_free_rcu(struct rcu_head *head) > { > - kmem_cache_free(peer_cachep, container_of(head, struct inet_peer, rcu)); > } > > /* perform garbage collect on all items stacked during a lookup */ > diff -u -p /home/jll/linux/net/ipv6/xfrm6_tunnel.c /tmp/nothing/net/ipv6/xfrm6_tunnel.c > --- /home/jll/linux/net/ipv6/xfrm6_tunnel.c > +++ /tmp/nothing/net/ipv6/xfrm6_tunnel.c > @@ -180,8 +180,6 @@ EXPORT_SYMBOL(xfrm6_tunnel_alloc_spi); > > static void x6spi_destroy_rcu(struct rcu_head *head) > { > - kmem_cache_free(xfrm6_tunnel_spi_kmem, > - container_of(head, struct xfrm6_tunnel_spi, rcu_head)); > } > > static void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr) > diff -u -p /home/jll/linux/security/security.c /tmp/nothing/security/security.c > --- /home/jll/linux/security/security.c > +++ /tmp/nothing/security/security.c > @@ -1599,7 +1599,6 @@ static void inode_free_by_rcu(struct rcu > /* > * The rcu head is at the start of the inode blob > */ > - kmem_cache_free(lsm_inode_cache, head); > } > > /**