Switch to single argument kvfree_rcu() API
Subsystems (28)
Uladzislau Rezki (Sony)
maintainercover Switch to single argument kvfree_rcu() API
Hi!
This is an attempt to replace places in the Linux kernel for using single argument of kvfree_rcu() API. In short, a single argument API allows something like below:
<snip>
void *ptr = kvmalloc(some_bytes, GFP_KERNEL);
if (ptr)
kvfree_rcu(ptr);<snip>
i.e. to free a pointer after a grace period of object that does not have any rcu_head field inside its structure. Due to lacking of such mechanism users just do:
<snip>
synchronize_rcu();
kfree(p);<snip>
if they do not want to have an rcu_head element in their data. Thus this series replaces mentioned places to go with the single argument API.
It is based on the 5.16.0-rc2 also it can be applied on Paul's latest RCU "dev" branch.
Thanks!
Uladzislau Rezki (2):
ext4: Switch to kvfree_rcu() API
fs: nfs: sysfs: Switch to kvfree_rcu() API
Uladzislau Rezki (Sony) (7):
ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu() API
drivers: Switch to kvfree_rcu() API
x86/mm: Switch to kvfree_rcu() API
net/tipc: Switch to kvfree_rcu() API
net/core: Switch to kvfree_rcu() API
module: Switch to kvfree_rcu() API
tracing: Switch to kvfree_rcu() API
arch/x86/mm/mmio-mod.c | 6 ++-- drivers/block/drbd/drbd_nl.c | 9 ++---- drivers/block/drbd/drbd_receiver.c | 6 ++-- drivers/block/drbd/drbd_state.c | 3 +- drivers/block/rnbd/rnbd-srv.c | 3 +- drivers/crypto/nx/nx-common-pseries.c | 3 +- drivers/infiniband/hw/hfi1/sdma.c | 3 +- drivers/ipack/carriers/tpci200.c | 3 +- drivers/mfd/dln2.c | 6 ++-- drivers/misc/vmw_vmci/vmci_context.c | 6 ++-- drivers/misc/vmw_vmci/vmci_event.c | 3 +- .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +- .../net/ethernet/mellanox/mlx5/core/en/qos.c | 3 +- .../ethernet/mellanox/mlx5/core/fpga/tls.c | 3 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +- drivers/scsi/device_handler/scsi_dh_alua.c | 3 +- drivers/scsi/device_handler/scsi_dh_rdac.c | 3 +- drivers/staging/fwserial/fwserial.c | 3 +- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------- fs/ext4/super.c | 5 ++- fs/nfs/sysfs.c | 7 ++--- kernel/module.c | 3 +- kernel/trace/trace_osnoise.c | 3 +- kernel/trace/trace_probe.c | 3 +- net/core/sysctl_net_core.c | 3 +- net/tipc/crypto.c | 3 +- 28 files changed, 37 insertions(+), 96 deletions(-)
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 1/9 ext4: Switch to kvfree_rcu() API
From: Uladzislau Rezki <[email protected]>
Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- fs/ext4/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/super.c +1 -2
@@ -1886,8 +1886,7 @@ static int clear_qf_name(struct super_block *sb, int qtype) return -1; }rcu_assign_pointer (sbi->s_qf_names[qtype],NULL ); -synchronize_rcu (); -kfree (old_qname); +kvfree_rcu (old_qname);return 1 ; }#endif
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 2/9 ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)The ext4_kvfree_array_rcu() function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain any rcu_head filed.
To do so, it requires to allocate some extra memory for a special structure that has an rcu_head filed and pointer one where a freed memory is attached. Finally call_rcu() API is invoked.
Since we have a single argument of kvfree_rcu() API, we can easily replace all that tricky code by one single call that does the same but in more efficient way.
--- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------------------- fs/ext4/super.c | 2 +- 4 files changed, 4 insertions(+), 32 deletions(-)
fs/ext4/ext4.h +0 -1
@@ -3089,7 +3089,6 @@ extern int ext4_generic_delete_entry(struct inode *dir,extern bool ext4_empty_dir (struct inode *inode);/* resize.c */ -extern void ext4_kvfree_array_rcu (void *to_free);extern int ext4_group_add (struct super_block *sb,struct ext4_new_group_data *input); extern int ext4_group_extend(struct super_block *sb,
fs/ext4/mballoc.c +1 -1
@@ -3109,7 +3109,7 @@ int ext4_mb_alloc_groupinfo(struct super_block *sb, ext4_group_t ngroups)rcu_assign_pointer (sbi->s_group_info, new_groupinfo); sbi->s_group_info_size = size /sizeof (*sbi->s_group_info);if (old_groupinfo) -ext4_kvfree_array_rcu (old_groupinfo); +kvfree_rcu (old_groupinfo);ext4_debug ("allocated s_groupinfo array for %d meta_bg's\n" , sbi->s_group_info_size);return 0 ;
fs/ext4/resize.c +2 -29
@@ -17,33 +17,6 @@#include "ext4_jbd2.h" -struct ext4_rcu_ptr { -struct rcu_head rcu; -void *ptr; -}; - -static void ext4_rcu_ptr_callback (struct rcu_head *head) -{ -struct ext4_rcu_ptr *ptr; - - ptr = container_of(head, struct ext4_rcu_ptr, rcu); -kvfree (ptr->ptr); -kfree (ptr); -} - -void ext4_kvfree_array_rcu (void *to_free) -{ -struct ext4_rcu_ptr *ptr =kzalloc (sizeof (*ptr),GFP_KERNEL ); - -if (ptr) { - ptr->ptr = to_free; -call_rcu (&ptr->rcu, ext4_rcu_ptr_callback); -return ; - } -synchronize_rcu (); -kvfree (to_free); -} -int ext4_resize_begin (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -906,7 +879,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, n_group_desc[gdb_num] = gdb_bh;rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu (o_group_desc);lock_buffer (EXT4_SB (sb)->s_sbh);le16_add_cpu (&es->s_reserved_gdt_blocks,-1 );
@@ -969,7 +942,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb,rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu (o_group_desc);return err; }
fs/ext4/super.c +1 -1
@@ -2759,7 +2759,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)rcu_assign_pointer (sbi->s_flex_groups, new_groups); sbi->s_flex_groups_allocated = size;if (old_groups) -ext4_kvfree_array_rcu (old_groups); +kvfree_rcu (old_groups);return 0 ; }
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 3/9 fs: nfs: sysfs: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)From: Uladzislau Rezki <[email protected]>
Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- fs/nfs/sysfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfs/sysfs.c +3 -4
@@ -113,10 +113,9 @@ static ssize_t nfs_netns_identifier_store(struct kobject *kobj,if (!p)return -ENOMEM ; old =rcu_dereference_protected (xchg (&c->identifier, (char __rcu *)p),1 ); -if (old) { -synchronize_rcu (); -kfree (old); - } +if (old) +kvfree_rcu (old); +return count; }
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 5/9 x86/mm: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- arch/x86/mm/mmio-mod.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/mm/mmio-mod.c +2 -4
@@ -307,10 +307,8 @@ static void iounmap_trace_core(volatile void __iomem *addr) not_enabled:spin_unlock_irq (&trace_lock); -if (found_trace) { -synchronize_rcu ();/* unregister_kmmio_probe() requirement */ -kfree (found_trace); - } +if (found_trace) +kvfree_rcu (found_trace);/* unregister_kmmio_probe() requirement */ }void mmiotrace_iounmap (volatile void __iomem *addr)
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 6/9 net/tipc: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- net/tipc/crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/tipc/crypto.c +1 -2
@@ -2391,8 +2391,7 @@ static void tipc_crypto_work_rx(struct work_struct *work) resched = true;break ;default : -synchronize_rcu (); -kfree (rx->skey); +kvfree_rcu (rx->skey); rx->skey =NULL ;break ; }
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 4/9 drivers: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- drivers/block/drbd/drbd_nl.c | 9 +++------ drivers/block/drbd/drbd_receiver.c | 6 ++---- drivers/block/drbd/drbd_state.c | 3 +-- drivers/block/rnbd/rnbd-srv.c | 3 +-- drivers/crypto/nx/nx-common-pseries.c | 3 +-- drivers/infiniband/hw/hfi1/sdma.c | 3 +-- drivers/ipack/carriers/tpci200.c | 3 +-- drivers/mfd/dln2.c | 6 ++---- drivers/misc/vmw_vmci/vmci_context.c | 6 ++---- drivers/misc/vmw_vmci/vmci_event.c | 3 +-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/en/qos.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c | 3 +-- drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +-- drivers/scsi/device_handler/scsi_dh_alua.c | 3 +-- drivers/scsi/device_handler/scsi_dh_rdac.c | 3 +-- drivers/staging/fwserial/fwserial.c | 3 +-- 17 files changed, 22 insertions(+), 44 deletions(-)
drivers/block/drbd/drbd_nl.c +3 -6
@@ -1679,8 +1679,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)drbd_send_sync_param (peer_device); } -synchronize_rcu (); -kfree (old_disk_conf); +kvfree_rcu (old_disk_conf);kfree (old_plan);mod_timer (&device->request_timer, jiffies +HZ ); goto success;
@@ -2511,8 +2510,7 @@ int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info)mutex_unlock (&connection->resource->conf_update);mutex_unlock (&connection->data.mutex); -synchronize_rcu (); -kfree (old_net_conf); +kvfree_rcu (old_net_conf);if (connection->cstate >=C_WF_REPORT_PARAMS ) {struct drbd_peer_device *peer_device;
@@ -2925,8 +2923,7 @@ int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info) new_disk_conf->disk_size = (sector_t )rs.resize_size;rcu_assign_pointer (device->ldev->disk_conf, new_disk_conf);mutex_unlock (&device->resource->conf_update); -synchronize_rcu (); -kfree (old_disk_conf); +kvfree_rcu (old_disk_conf); new_disk_conf =NULL ; }
drivers/block/drbd/drbd_receiver.c +2 -4
@@ -3799,8 +3799,7 @@ static int receive_protocol(struct drbd_connection *connection, struct packet_indrbd_info (connection,"peer data-integrity-alg: %s\n" , integrity_alg[0 ] ? integrity_alg :"(none)" ); -synchronize_rcu (); -kfree (old_net_conf); +kvfree_rcu (old_net_conf);return 0 ; disconnect_rcu_unlock:
@@ -4168,8 +4167,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_inforcu_assign_pointer (device->ldev->disk_conf, new_disk_conf);mutex_unlock (&connection->resource->conf_update); -synchronize_rcu (); -kfree (old_disk_conf); +kvfree_rcu (old_disk_conf);drbd_info (device,"Peer sets u_size to %lu sectors (old: %lu)\n" , (unsigned long )p_usize, (unsigned long )my_usize);
drivers/block/drbd/drbd_state.c +1 -2
@@ -2071,8 +2071,7 @@ static int w_after_conn_state_ch(struct drbd_work *w, int unused)conn_free_crypto (connection);mutex_unlock (&connection->resource->conf_update); -synchronize_rcu (); -kfree (old_conf); +kvfree_rcu (old_conf); }if (ns_max.susp_fen) {
drivers/block/rnbd/rnbd-srv.c +1 -2
@@ -808,8 +808,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, free_srv_sess_dev:xa_erase (&srv_sess->index_idr, srv_sess_dev->device_id); -synchronize_rcu (); -kfree (srv_sess_dev); +kvfree_rcu (srv_sess_dev); srv_dev_put:if (open_msg->access_mode !=RNBD_ACCESS_RO ) {mutex_lock (&srv_dev->lock);
drivers/crypto/nx/nx-common-pseries.c +1 -2
@@ -1061,8 +1061,7 @@ static int nx842_probe(struct vio_dev *viodev,rcu_assign_pointer (devdata, new_devdata);spin_unlock_irqrestore (&devdata_mutex, flags); -synchronize_rcu (); -kfree (old_devdata); +kvfree_rcu (old_devdata);of_reconfig_notifier_register (&nx842_of_nb);
drivers/infiniband/hw/hfi1/sdma.c +1 -2
@@ -1292,8 +1292,7 @@ void sdma_clean(struct hfi1_devdata *dd, size_t num_engines)sdma_map_free (rcu_access_pointer (dd->sdma_map));RCU_INIT_POINTER (dd->sdma_map,NULL );spin_unlock_irq (&dd->sde_map_lock); -synchronize_rcu (); -kfree (dd->per_sdma); +kvfree_rcu (dd->per_sdma); dd->per_sdma =NULL ;if (dd->sdma_rht) {
drivers/ipack/carriers/tpci200.c +1 -2
@@ -180,8 +180,7 @@ static int tpci200_free_irq(struct ipack_device *dev) slot_irq = tpci200->slots[dev->slot].irq;/* uninstall handler */ RCU_INIT_POINTER (tpci200->slots[dev->slot].irq,NULL ); -synchronize_rcu (); -kfree (slot_irq); +kvfree_rcu (slot_irq);mutex_unlock (&tpci200->mutex);return 0 ; }
drivers/mfd/dln2.c +2 -4
@@ -179,10 +179,8 @@ void dln2_unregister_event_cb(struct platform_device *pdev, u16 id)spin_unlock_irqrestore (&dln2->event_cb_lock, flags); -if (found) { -synchronize_rcu (); -kfree (i); - } +if (found) +kvfree_rcu (i); }EXPORT_SYMBOL (dln2_unregister_event_cb);
drivers/misc/vmw_vmci/vmci_context.c +2 -4
@@ -687,10 +687,8 @@ int vmci_ctx_remove_notification(u32 context_id, u32 remote_cid) }spin_unlock (&context->lock); -if (found) { -synchronize_rcu (); -kfree (notifier); - } +if (found) +kvfree_rcu (notifier);vmci_ctx_put (context);
drivers/misc/vmw_vmci/vmci_event.c +1 -2
@@ -209,8 +209,7 @@ int vmci_event_unsubscribe(u32 sub_id)if (!s)return VMCI_ERROR_NOT_FOUND ; -synchronize_rcu (); -kfree (s); +kvfree_rcu (s);return VMCI_SUCCESS ; }
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +1 -2
@@ -7190,8 +7190,7 @@ static void remove_one(struct pci_dev *pdev) }pci_release_regions (pdev);kfree (adapter->mbox_log); -synchronize_rcu (); -kfree (adapter); +kvfree_rcu (adapter); }/* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
drivers/net/ethernet/mellanox/mlx5/core/en/qos.c +1 -2
@@ -388,8 +388,7 @@ static int mlx5e_qos_alloc_queues(struct mlx5e_priv *priv, struct mlx5e_channels sqs =rcu_replace_pointer (chs->c[i]->qos_sqs,NULL ,lockdep_is_held (&priv->state_lock)); -synchronize_rcu ();/* Sync with NAPI. */ -kvfree (sqs); +kvfree_rcu (sqs);/* Sync with NAPI. */ }return -ENOMEM ; }
drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c +1 -2
@@ -253,7 +253,7 @@ static void mlx5_fpga_tls_send_teardown_cmd(struct mlx5_core_dev *mdev,MLX5_SET (tls_cmd, cmd, swid, swid);mlx5_fpga_tls_flow_to_cmd (flow, cmd); -kfree (flow); +kvfree_rcu (flow); buf->sg[0 ].data = cmd; buf->sg[0 ].size =MLX5_TLS_COMMAND_SIZE ;
@@ -283,7 +283,6 @@ void mlx5_fpga_tls_del_flow(struct mlx5_core_dev *mdev, u32 swid,return ; } -synchronize_rcu ();/* before kfree(flow) */ mlx5_fpga_tls_send_teardown_cmd (mdev, flow, swid, flags); }
drivers/net/ethernet/mellanox/mlxsw/core.c +1 -2
@@ -2190,8 +2190,7 @@ void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,if (!rxl_item)return ;list_del_rcu (&rxl_item->list); -synchronize_rcu (); -kfree (rxl_item); +kvfree_rcu (rxl_item); }EXPORT_SYMBOL (mlxsw_core_rx_listener_unregister);
drivers/scsi/device_handler/scsi_dh_alua.c +1 -2
@@ -1238,8 +1238,7 @@ static void alua_bus_detach(struct scsi_device *sdev)kref_put (&pg->kref, release_port_group); } sdev->handler_data =NULL ; -synchronize_rcu (); -kfree (h); +kvfree_rcu (h); }static struct scsi_device_handler alua_dh = {
drivers/scsi/device_handler/scsi_dh_rdac.c +1 -2
@@ -782,8 +782,7 @@ static void rdac_bus_detach( struct scsi_device *sdev ) }spin_unlock (&list_lock); sdev->handler_data =NULL ; -synchronize_rcu (); -kfree (h); +kvfree_rcu (h); }static struct scsi_device_handler rdac_dh = {
drivers/staging/fwserial/fwserial.c +1 -2
@@ -2116,8 +2116,7 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)if (port)fwserial_release_port (port, true); -synchronize_rcu (); -kfree (peer); +kvfree_rcu (peer); }/**
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 7/9 net/core: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- net/core/sysctl_net_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/sysctl_net_core.c +1 -2
@@ -141,8 +141,7 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write, lockdep_is_held(&flow_limit_update_mutex));if (cur && !cpumask_test_cpu (i, mask)) {RCU_INIT_POINTER (sd->flow_limit,NULL ); -synchronize_rcu (); -kfree (cur); +kvfree_rcu (cur); }else if (!cur &&cpumask_test_cpu (i, mask)) { cur =kzalloc_node (len,GFP_KERNEL ,cpu_to_node (i));
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 9/9 tracing: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- kernel/trace/trace_osnoise.c | 3 +-- kernel/trace/trace_probe.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
kernel/trace/trace_osnoise.c +1 -2
@@ -138,8 +138,7 @@ static void osnoise_unregister_instance(struct trace_array *tr)if (!found)return ; -synchronize_rcu (); -kfree (inst); +kvfree_rcu (inst); }/*
kernel/trace/trace_probe.c +1 -2
@@ -1138,8 +1138,7 @@ int trace_probe_remove_file(struct trace_probe *tp,return -ENOENT ;list_del_rcu (&link->list); -synchronize_rcu (); -kfree (link); +kvfree_rcu (link);if (list_empty (&tp->event->files))trace_probe_clear_flag (tp,TP_FLAG_TRACE );
Signature · 1 line
2.30.2
Uladzislau Rezki (Sony)
maintainerPATCH 8/9 module: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Instead of invoking a synchronize_rcu() to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
--- kernel/module.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/module.c +1 -2
@@ -4150,8 +4150,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod);dynamic_debug_remove (mod, info->debug); -synchronize_rcu (); -kfree (mod->args); +kvfree_rcu (mod->args); free_arch_cleanup:cfi_cleanup (mod);module_arch_cleanup (mod);
Signature · 1 line
2.30.2
Re: [PATCH 5/9] x86/mm: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 6 lines · On Wed, 24 Nov 2021 12:03:04 +0100 "Uladzislau Rezki (Sony)"…
arch/x86/mm/mmio-mod.c +0
-0@@ -307,10 +307,8 @@ static void iounmap_trace_core(volatile void __iomem *addr)
arch/x86/mm/mmio-mod.c static void iounmap_trace_core(volatile void __iomem *addr) · line 313
Quoted 10 lines
arch/x86/mm/mmio-mod.c +2
-4not_enabled:spin_unlock_irq (&trace_lock); -if (found_trace) { -synchronize_rcu ();/* unregister_kmmio_probe() requirement */ -kfree (found_trace); - } +if (found_trace) +kvfree_rcu (found_trace);/* unregister_kmmio_probe() requirement */ }
This is the first I've seen kvfree_rcu() (that I actually noticed/remember, I'm sure I probably was Cc'd on some patches). And I find the comment around it very confusing:
Specifically:
* kvfree_rcu(ptr);
*
* where @ptr is a pointer to kvfree().
The above suggests that you should pass a pointer to the actual function kvfree to kvfree_rcu(), which is not what I believe is to be done.
i.e. kvfree_rcu(kvfree) ???
Perhaps rewrite that to say:
* where @ptr is the pointer to be freed by kvfree().
?
Other than that, the patch looks fine to me.
-- Steve
Steven Rostedt
maintainerRe: [PATCH 5/9] x86/mm: Switch to kvfree_rcu() API
Quoted 3 lines · On Wed, 24 Nov 2021 09:58:03 -0500 Steven Rostedt <[email protected]> wrote:
Other than that, the patch looks fine to me.
This was suppose to be for patch 9/9:
[PATCH 9/9] tracing: Switch to kvfree_rcu() API
I replied to the wrong patch.
-- Steve
Re: [PATCH 9/9] tracing: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 7 lines · On Wed, 24 Nov 2021 12:03:08 +0100 "Uladzislau Rezki (Sony)"…
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.CC Steven Rostedt <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>---
Replying to the correct patch this time.
-- Steve
Uladzislau Rezki
maintainerRe: [PATCH 5/9] x86/mm: Switch to kvfree_rcu() API
In reply to Steven RostedtQuoted 15 lines
This is the first I've seen
kvfree_rcu()(that I actually noticed/remember, I'm sure I probably was Cc'd on some patches). And I find the comment around it very confusing:Specifically:
*
kvfree_rcu(ptr);
*
* where @ptr is a pointer tokvfree().The above suggests that you should pass a pointer to the actual function kvfree to
kvfree_rcu(), which is not what I believe is to be done.
Quoted 7 lines
i.e.
kvfree_rcu(kvfree)???Perhaps rewrite that to say:
* where @ptr is the pointer to be freed by
kvfree().?
Indeed. I will fix that by sending a patch to change a description to be less confusing :)
Quoted 5 lines
Other than that, the patch looks fine to me.
I will place your "Acked-by" to 9/9 one.
Thanks!
Signature · 1 line
Uladzislau Rezki
Uladzislau Rezki
maintainerRe: [PATCH 9/9] tracing: Switch to kvfree_rcu() API
In reply to Steven RostedtQuoted 8 lines
Quoted 4 lines · On Wed, 24 Nov 2021 12:03:08 +0100 "Uladzislau Rezki (Sony)"…
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
Quoted 8 lines
Quoted 3 lines
CC Steven Rostedt <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>---
Replying to the correct patch this time.
Thanks!
Signature · 1 line
Uladzislau Rezki
Re: [PATCH 4/9] drivers: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 27 lines · Uladzislau Rezki (Sony)
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.CC Philipp Reisner <[email protected]>CC "Md. Haris Iqbal" <[email protected]>CC Herbert Xu <[email protected]>CC Mike Marciniszyn <[email protected]>CC Samuel Iglesias Gonsalvez <[email protected]>CC Lee Jones <[email protected]>CC Jorgen Hansen <[email protected]>CC Raju Rangoju <[email protected]>CC Saeed Mahameed <[email protected]>CC Boris Pismenny <[email protected]>CC Jiri Pirko <[email protected]>CC "James E.J. Bottomley" <[email protected]>CC Greg Kroah-Hartman <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- drivers/block/drbd/drbd_nl.c | 9 +++------ drivers/block/drbd/drbd_receiver.c | 6 ++---- drivers/block/drbd/drbd_state.c | 3 +-- drivers/block/rnbd/rnbd-srv.c | 3 +-- drivers/crypto/nx/nx-common-pseries.c | 3 +-- drivers/infiniband/hw/hfi1/sdma.c | 3 +-- drivers/ipack/carriers/tpci200.c | 3 +--
Quoted 1 line
drivers/mfd/dln2.c | 6 ++----
I'm not an expert in this API, but the premise and changes to MFD seem fine at first glance:
Quoted 10 lines
drivers/misc/vmw_vmci/vmci_context.c | 6 ++---- drivers/misc/vmw_vmci/vmci_event.c | 3 +-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/en/qos.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c | 3 +-- drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +-- drivers/scsi/device_handler/scsi_dh_alua.c | 3 +-- drivers/scsi/device_handler/scsi_dh_rdac.c | 3 +-- drivers/staging/fwserial/fwserial.c | 3 +-- 17 files changed, 22 insertions(+), 44 deletions(-)
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Marciniszyn, Mike
Acked-byRE: [PATCH 4/9] drivers: Switch to kvfree_rcu() API
Quoted 8 lines
Subject: Re: [PATCH 4/9] drivers: Switch to
kvfree_rcu()APIQuoted 4 lines · Uladzislau Rezki (Sony)
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
+-- > > drivers/infiniband/hw/hfi1/sdma.c | 3 +--
The sdma portion of the change looks good!
Mike
Uladzislau Rezki
maintainerRe: [PATCH 4/9] drivers: Switch to kvfree_rcu() API
In reply to Lee JonesQuoted 30 lines · Lee Jones
Quoted 26 lines · Uladzislau Rezki (Sony)
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.CC Philipp Reisner <[email protected]>CC "Md. Haris Iqbal" <[email protected]>CC Herbert Xu <[email protected]>CC Mike Marciniszyn <[email protected]>CC Samuel Iglesias Gonsalvez <[email protected]>CC Lee Jones <[email protected]>CC Jorgen Hansen <[email protected]>CC Raju Rangoju <[email protected]>CC Saeed Mahameed <[email protected]>CC Boris Pismenny <[email protected]>CC Jiri Pirko <[email protected]>CC "James E.J. Bottomley" <[email protected]>CC Greg Kroah-Hartman <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- drivers/block/drbd/drbd_nl.c | 9 +++------ drivers/block/drbd/drbd_receiver.c | 6 ++---- drivers/block/drbd/drbd_state.c | 3 +-- drivers/block/rnbd/rnbd-srv.c | 3 +-- drivers/crypto/nx/nx-common-pseries.c | 3 +-- drivers/infiniband/hw/hfi1/sdma.c | 3 +-- drivers/ipack/carriers/tpci200.c | 3 +--
Quoted 7 lines
Quoted 1 line
drivers/mfd/dln2.c | 6 ++----I'm not an expert in this API, but the premise and changes to MFD seem fine at first glance:
Acked-by Lee Jones <[email protected]>
Thanks!
--
Uladzislau Rezki
Re: [PATCH 8/9] module: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Hi,
Quoted 15 lines · Uladzislau Rezki (Sony)
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.CC Luis Chamberlain <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- kernel/module.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)kernel/module.c +0
-0
kernel/module.c static int load_module(struct load_info *info, const char __user *uargs, · line 4156
Quoted 9 lines
kernel/module.c +1
-2@@ -4150,8 +4150,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod);dynamic_debug_remove (mod, info->debug); -synchronize_rcu (); -kfree (mod->args); +kvfree_rcu (mod->args); free_arch_cleanup:cfi_cleanup (mod);module_arch_cleanup (mod);
hm, if I am not missing something, synchronize_rcu() is not really connected to kfree(mod->args) there. synchronize_rcu() was added a long time ago when kernel/module.c removed stop_machine() from the code and replaced it with RCU to protect (at least?) mod->list. You can find list_del_rcu(&mod->list) a couple of lines below.
And yes, one could ask how this all works. The error/cleanup sequence in load_module() is a giant mess... well, load_module() is a mess too, but the error path is really not nice.
Miroslav
Re: [PATCH 8/9] module: Switch to kvfree_rcu() API
Quoted 10 lines · Miroslav Benes
Quoted 10 lines
kernel/module.c +1
-2@@ -4150,8 +4150,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod);dynamic_debug_remove (mod, info->debug); -synchronize_rcu (); -kfree (mod->args); +kvfree_rcu (mod->args); free_arch_cleanup:
Quoted 8 lines
kernel/module.c static int load_module(struct load_info *info, const char __user *uargs, · line 4156
Quoted 2 lines
kernel/module.c +0
-0cfi_cleanup (mod);module_arch_cleanup (mod);hm, if I am not missing something,
synchronize_rcu()is not really connected tokfree(mod->args)there.synchronize_rcu()was added a long time ago whenkernel/module.cremovedstop_machine()from the code and replaced it with RCU to protect (at least?)mod->list. You can findlist_del_rcu(&mod->list)a couple of lines below.
so instead synchronize_rcu() + kfree() you could do call_rcu(&mod->args->rcu, kfree()) but since you have no RCU-head around in args you wait for the grace period and then invoke kfree.
kvfree_rcu() is somehow like call_rcu() + kfree() but without the needed RCU-head.
So you avoid waiting for the grace period but mod->args is freed later, after as expected.
Quoted 3 lines
And yes, one could ask how this all works. The error/cleanup sequence in
load_module()is a giant mess... well,load_module()is a mess too, but the error path is really not nice.
Well, spring is coming :)
Quoted 1 line
Miroslav
Sebastian
Uladzislau Rezki
maintainerRe: [PATCH 8/9] module: Switch to kvfree_rcu() API
Quoted 29 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Miroslav Benes
Quoted 10 lines
kernel/module.c +1
-2@@ -4150,8 +4150,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod);dynamic_debug_remove (mod, info->debug); -synchronize_rcu (); -kfree (mod->args); +kvfree_rcu (mod->args); free_arch_cleanup:Quoted 8 lines
kernel/module.c static int load_module(struct load_info *info, const char __user *uargs, · line 4156
Quoted 2 lines
kernel/module.c +0
-0cfi_cleanup (mod);module_arch_cleanup (mod);hm, if I am not missing something,
synchronize_rcu()is not really connected tokfree(mod->args)there.synchronize_rcu()was added a long time ago whenkernel/module.cremovedstop_machine()from the code and replaced it with RCU to protect (at least?)mod->list. You can findlist_del_rcu(&mod->list)a couple of lines below.so instead
synchronize_rcu()+kfree()you could docall_rcu(&mod->args->rcu, kfree())but since you have no RCU-head around in args you wait for the grace period and then invoke kfree.
kvfree_rcu()is somehow likecall_rcu()+kfree()but without the needed RCU-head.
So you avoid waiting for the grace period butmod->argsis freed later, after as expected.
Quoted 6 lines
Quoted 3 lines
And yes, one could ask how this all works. The error/cleanup sequence in
load_module()is a giant mess... well,load_module()is a mess too, but the error path is really not nice.Well, spring is coming :)
Indeed that error path sequence is terrible. I will double check if that synchronize_rcu() + kfree() is related to any RCU protection and freeing.
If it is not i will drop this patch.
Thanks!
--
Vlad Rezki
Uladzislau Rezki
maintainerRe: [PATCH 8/9] module: Switch to kvfree_rcu() API
Quoted 34 lines · Uladzislau Rezki
Quoted 33 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Miroslav Benes
Quoted 10 lines
kernel/module.c +1
-2@@ -4150,8 +4150,7 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod);dynamic_debug_remove (mod, info->debug); -synchronize_rcu (); -kfree (mod->args); +kvfree_rcu (mod->args); free_arch_cleanup:Quoted 8 lines
kernel/module.c static int load_module(struct load_info *info, const char __user *uargs, · line 4156
Quoted 2 lines
kernel/module.c +0
-0cfi_cleanup (mod);module_arch_cleanup (mod);hm, if I am not missing something,
synchronize_rcu()is not really connected tokfree(mod->args)there.synchronize_rcu()was added a long time ago whenkernel/module.cremovedstop_machine()from the code and replaced it with RCU to protect (at least?)mod->list. You can findlist_del_rcu(&mod->list)a couple of lines below.so instead
synchronize_rcu()+kfree()you could docall_rcu(&mod->args->rcu, kfree())but since you have no RCU-head around in args you wait for the grace period and then invoke kfree.
kvfree_rcu()is somehow likecall_rcu()+kfree()but without the needed RCU-head.
So you avoid waiting for the grace period butmod->argsis freed later, after as expected.Quoted 3 lines
And yes, one could ask how this all works. The error/cleanup sequence in
load_module()is a giant mess... well,load_module()is a mess too, but the error path is really not nice.
Quoted 8 lines
Quoted 2 lines
Well, spring is coming :)
Indeed that error path sequence is terrible. I will double check if that
synchronize_rcu()+kfree()is related to any RCU protection and freeing.If it is not i will drop this patch.
OK, that kfree has nothing to do with RCU protection:
<snip>
commit 6526c534b2677ca601b7b92851437feb041d02a1
Author: Rusty Russell <[email protected]> Date: Thu Aug 5 12:59:10 2010 -0600
module: move module args strndup_user to just before use
Instead of copying and allocating the args and storing it in load_info, we can just allocate them right before we need them.
<snip>
so, i will drop my patch, since the intention is not to free a ptr after a grace period.
Thank you for the review!
--
Vlad Rezki
Uladzislau Rezki
maintainerRe: [PATCH 1/9] ext4: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 30 lines · Uladzislau Rezki (Sony)
From: Uladzislau Rezki <[email protected]>
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.CC "Theodore Ts'o" <[email protected]>Signed-off-by Uladzislau Rezki <[email protected]>--- fs/ext4/super.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/ext4/super.c +1
-3@@ -1886,8 +1886,7 @@ static int clear_qf_name(struct super_block *sb, int qtype) return -1; }rcu_assign_pointer (sbi->s_qf_names[qtype],NULL ); -synchronize_rcu (); -kfree (old_qname); +kvfree_rcu (old_qname);return 1 ; }#endif --2.30.2
Signature · 1 line
Uladzislau Rezki
Uladzislau Rezki
maintainerRe: [PATCH 2/9] ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 120 lines · Uladzislau Rezki (Sony)
The
ext4_kvfree_array_rcu()function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain anyrcu_headfiled.To do so, it requires to allocate some extra memory for a special structure that has an
rcu_headfiled and pointer one where a freed memory is attached. Finallycall_rcu()API is invoked.Since we have a single argument of
kvfree_rcu()API, we can easily replace all that tricky code by one single call that does the same but in more efficient way.CC "Theodore Ts'o" <[email protected]>Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------------------- fs/ext4/super.c | 2 +- 4 files changed, 4 insertions(+), 32 deletions(-)fs/ext4/ext4.h +0
-1@@ -3089,7 +3089,6 @@ extern int ext4_generic_delete_entry(struct inode *dir,extern bool ext4_empty_dir (struct inode *inode);/* resize.c */ -extern void ext4_kvfree_array_rcu (void *to_free);extern int ext4_group_add (struct super_block *sb,struct ext4_new_group_data *input); extern int ext4_group_extend(struct super_block *sb,fs/ext4/mballoc.c +1
-1@@ -3109,7 +3109,7 @@ int ext4_mb_alloc_groupinfo(struct super_block *sb, ext4_group_t ngroups)rcu_assign_pointer (sbi->s_group_info, new_groupinfo); sbi->s_group_info_size = size /sizeof (*sbi->s_group_info);if (old_groupinfo) -ext4_kvfree_array_rcu (old_groupinfo); +kvfree_rcu (old_groupinfo);ext4_debug ("allocated s_groupinfo array for %d meta_bg's\n" , sbi->s_group_info_size);return 0 ;fs/ext4/resize.c +2
-29@@ -17,33 +17,6 @@#include "ext4_jbd2.h" -struct ext4_rcu_ptr { -struct rcu_head rcu; -void *ptr; -}; - -static void ext4_rcu_ptr_callback (struct rcu_head *head) -{ -struct ext4_rcu_ptr *ptr; - - ptr = container_of(head, struct ext4_rcu_ptr, rcu); -kvfree (ptr->ptr); -kfree (ptr); -} - -void ext4_kvfree_array_rcu (void *to_free) -{ -struct ext4_rcu_ptr *ptr =kzalloc (sizeof (*ptr),GFP_KERNEL ); - -if (ptr) { - ptr->ptr = to_free; -call_rcu (&ptr->rcu, ext4_rcu_ptr_callback); -return ; - } -synchronize_rcu (); -kvfree (to_free); -} -int ext4_resize_begin (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);@@ -906,7 +879,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, n_group_desc[gdb_num] = gdb_bh;rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu (o_group_desc);lock_buffer (EXT4_SB (sb)->s_sbh);le16_add_cpu (&es->s_reserved_gdt_blocks,-1 );@@ -969,7 +942,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb,rcu_assign_pointer (EXT4_SB (sb)->s_group_desc, n_group_desc);EXT4_SB (sb)->s_gdb_count++; -ext4_kvfree_array_rcu (o_group_desc); +kvfree_rcu (o_group_desc);return err; }fs/ext4/super.c +1
-2@@ -2759,7 +2759,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)rcu_assign_pointer (sbi->s_flex_groups, new_groups); sbi->s_flex_groups_allocated = size;if (old_groups) -ext4_kvfree_array_rcu (old_groups); +kvfree_rcu (old_groups);return 0 ; } --2.30.2
Signature · 1 line
Uladzislau Rezki
Jason Gunthorpe
maintainerRe: [PATCH 4/9] drivers: Switch to kvfree_rcu() API
In reply to Uladzislau Rezki (Sony)Quoted 3 lines · Uladzislau Rezki (Sony)
Instead of invoking a
synchronize_rcu()to free a pointer after a grace period we can directly make use of new API that does the same but in more efficient way.
It isn't entirely new, kfree_rcu() has been around for ages and any of these call sites could have made use of it if they wanted. The kvfree_rcu() just adds the twist of transparently allocating memory.
We really must ask in each case why the original author didn't use kfree_rcu()..
Quoted 9 lines
drivers/block/drbd/drbd_nl.c | 9 +++------ drivers/block/drbd/drbd_receiver.c | 6 ++---- drivers/block/drbd/drbd_state.c | 3 +-- drivers/block/rnbd/rnbd-srv.c | 3 +-- drivers/crypto/nx/nx-common-pseries.c | 3 +-- drivers/infiniband/hw/hfi1/sdma.c | 3 +-- drivers/ipack/carriers/tpci200.c | 3 +-- drivers/mfd/dln2.c | 6 ++---- drivers/misc/vmw_vmci/vmci_context.c | 6 ++----
Quoted 8 lines
drivers/misc/vmw_vmci/vmci_event.c | 3 +-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/en/qos.c | 3 +-- drivers/net/ethernet/mellanox/mlx5/core/fpga/tls.c | 3 +-- drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +-- drivers/scsi/device_handler/scsi_dh_alua.c | 3 +-- drivers/scsi/device_handler/scsi_dh_rdac.c | 3 +-- drivers/staging/fwserial/fwserial.c | 3 +--
These all need to be split to single patches and ack'ed by experts.
drivers/block/drbd/drbd_nl.c int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) · line 1683
Quoted 11 lines
drivers/block/drbd/drbd_nl.c +2
-2+++ b/drivers/block/drbd/drbd_nl.c@@ -1679,8 +1679,7 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)drbd_send_sync_param (peer_device); } -synchronize_rcu (); -kfree (old_disk_conf); +kvfree_rcu (old_disk_conf);kfree (old_plan);
For instance, this, how do you know that old_plan isn't also RCU protected?
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c static void remove_one(struct pci_dev *pdev) · line 7194
Quoted 11 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +2
-2+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c@@ -7190,8 +7190,7 @@ static void remove_one(struct pci_dev *pdev) }pci_release_regions (pdev);kfree (adapter->mbox_log); -synchronize_rcu (); -kfree (adapter); +kvfree_rcu (adapter); }
And this, for instance, just looks crazy! There is only one RCU region in this file and it is not protecting an adaptor pointer, it is protecting a netdev. No idea what this is trying to do today even.
Each case needs to be audited to make sure the synchronize_rcu() is only protecting the kfree and not other things as well. It is tricky stuff.
I see you got an Ack for the infiniband peice, so feel free to send that file to the linux-rdma list.
Jason