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 D7237C25B78 for ; Tue, 28 May 2024 05:09:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40DB26B0089; Tue, 28 May 2024 01:09:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39A2F6B008A; Tue, 28 May 2024 01:09:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2378B6B0093; Tue, 28 May 2024 01:09:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 046D46B0089 for ; Tue, 28 May 2024 01:09:40 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A36E41A0287 for ; Tue, 28 May 2024 05:09:40 +0000 (UTC) X-FDA: 82166626920.10.75F4B3B Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by imf07.hostedemail.com (Postfix) with ESMTP id 3574840010 for ; Tue, 28 May 2024 05:09:37 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=inria.fr header.s=dc header.b=VLMZWgZU; spf=pass (imf07.hostedemail.com: domain of julia.lawall@inria.fr designates 192.134.164.104 as permitted sender) smtp.mailfrom=julia.lawall@inria.fr; dmarc=pass (policy=none) header.from=inria.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716872978; h=from:from:sender: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=hbb1TYxZuIfpukL9pRvV5HWVRdLiVb6cBG0WH8XBuNk=; b=BPaUEi2xO4FBmwc/jgrsM2um5Vl6YKDBSedSBVSt5RLQyYjQEx5Q2RmR8+obusiIwQAEiW 7/vYdabFoKToUqJvDr/kVu1tTsJOX45qRUgdINdwkvgik2zq+7Tg/oBFiYfmPd43qWKUzv BpZ02rkXLmnVBuBuAHTpstVYZ9NwsBo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716872978; a=rsa-sha256; cv=none; b=hEybBmIYZXSv8V009MGPA4lBaccAbOEqaaaEiBJIP6j/+dJLhia1Pat4T4gVA03b5syC22 PLtL57b6ZgwOFwNiCWhh/TLbX7/iC58unVsVWNjE0MZXNcHVJ45aC29WpOjWKM3+z2xajJ x3IuMR0WNNU3FoB4MXc2C64DaU38OfU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=inria.fr header.s=dc header.b=VLMZWgZU; spf=pass (imf07.hostedemail.com: domain of julia.lawall@inria.fr designates 192.134.164.104 as permitted sender) smtp.mailfrom=julia.lawall@inria.fr; dmarc=pass (policy=none) header.from=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=hbb1TYxZuIfpukL9pRvV5HWVRdLiVb6cBG0WH8XBuNk=; b=VLMZWgZUSAenFhYkmk5aYHI5d6fMdv0vFlmGNB1MqiqmxvgiZHNyWDrx xskENNF6aS0eBdTXzqzn71lJa4cPwQaPcQ3wXWa0H8mbWwefzy3cdTx6R YTC3IuGqV6OApM2H0gaM09Nswu8j5buRYSJXjxcXwTOsbNWIQ73grCHhx s=; X-IronPort-AV: E=Sophos;i="6.08,194,1712613600"; d="scan'208";a="88117195" Received: from 231.85.89.92.rev.sfr.net (HELO hadrien) ([92.89.85.231]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 07:09:36 +0200 Date: Tue, 28 May 2024 07:09:35 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: "Paul E. McKenney" 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 In-Reply-To: <2a64cf68-2189-4553-88c9-fd73784c22ff@paulmck-laptop> Message-ID: References: <68b85796-c674-4691-936a-2051849f4692@suse.cz> <6b7e3ed9-d974-cb3b-6839-a6b7cf5f5a36@inria.fr> <2a64cf68-2189-4553-88c9-fd73784c22ff@paulmck-laptop> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspam-User: X-Stat-Signature: g3qyyzk36umx4si3543cz66p4r6fmco6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3574840010 X-HE-Tag: 1716872977-48691 X-HE-Meta: U2FsdGVkX18lz5k9s5u0M5FeufQBtPCpVAW6D0W/bUhUQS318v7k3Xntq8pPWXWRc+87jeagCTH76rFodyobsc08K2mAl0gSlJeKSstUJeIXeXswZ9jOGMdu0uI8kC7816Cv0cLI/kSX3WmQrfLr/18GpXzRtHFqRwYromfBrVwrHuUEV+Fm8Bw5AiF8XTEB8aDC6oScBTpW8y8/P2PnZX8Tg7/VhowB5NH5ag6UalRX4tqkaUuHKSG00RaLF+zwWEuARO0EjxWDD+H3+CfPgs1SdaU7wucgcACIergQ9bEdSwESAE9Kp3N8k1HztP1TO1AQLUGdy9umF1kIXjJijxX/QoaTOAsnqOcR2BeeQcTu2L58+oQSdcNC0TWbumus9XXiUmfBg0yGuGU0MAQPgaQIk/nORcd8TsOfnuoyJXFIwEAgOWcYdiQy3aHnykKxyoV4G0oVBosGBD9qhw6nlznghBogLRHPeffs5p0wDJkd8oJbqH6UjDhLs4H1+H8WWSg7GLy+Zjd2iE9QJmQ7Bd5H6WHZlYxm5Q2cGlrHMmXQ078XUiardL5iLtdJUotVggCdqoajRrzIObkokafMrRpYvUQUGqKrfqAz9wSqzb05IZNQ89grrQy0eJU97thl+peDXAyP31nG/9QSp2Sv0yRYuELrTYj6nMZiOkNChYkOltvH6J7h/Rn4sE3KyY5dDaFbgEUmTnAst9pWPzaHIwA/bMsHHgdFMw1r0e+IC7yqtibOxVScOprHoVNP8BP0XE2csTezcukpVJFOWmzN2Xl6fnJ0I/jvxefpDrzFnWZrI6wnTd1HDXRa29GCa1JPYHRUM7/STW3wwS97nTnWhq4RiETYUNvmsDmnEoA5RGc9HcnuUcBzdk/F5ssKieApNJTLsPPiwHdjNO0TZHq9TbqHNfGZ7g1U0ebov6AFRdcjMvv0Mg985LEPTvBuudPimRTGp4uaiV3fD0Ukmlh 0neIwFMO /KTzABCTHUv60eLeP9rqqcm3JqYxCWiUgXtrORfNvYSiQnTmPTiGgUe2LLAJs9lUVRYeqpXCPSLzrWE7I9TtJWPtG572qbXebtQOoVzUVlflNg+hSo8ZqH/QXQDzvS5KWInozQnOknxUIIlvDX/4/isGtJmTRo2vzRNOf+SNQMDOfv9NWlQA1Aq9w86fcKPI1lfrU+Pc2pQJoMYJt5ZHUo4Vg6QA0rhPkmzsUqhcAiq0ZX8fCt3VVMfu+bTX2TZPxdg+PXKtaHCpAZM0Qh9OI7q7kLjeKJZ7TfZU9 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, 27 May 2024, Paul E. McKenney wrote: > 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(). OK. I'll send a patch for your review accordingly. If everything looks fine, I will send the patches to the maintainers. julia > > > 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); > > } > > > > /** >