get_file_rcu() grabs a file if the file->f_count is not zero[1].
[1] https://elixir.bootlin.com/linux/v5.14-rc1/source/include/linux/fs.h#L968
Required by drm-kmod 5.6
Differential D31672
LinuxKPI: Implement get_file_rcu() wulf on Aug 24 2021, 11:48 PM. Authored by Tags None Referenced Files
Details get_file_rcu() grabs a file if the file->f_count is not zero[1]. [1] https://elixir.bootlin.com/linux/v5.14-rc1/source/include/linux/fs.h#L968 Required by drm-kmod 5.6
Diff Detail
Event Timeline
Comment Actions add rcu_barrier()-s to file close handler to wait for RCU callbacks
Comment Actions May be call kfree_rcu() with struct rcu_head embedded into struct linux_file?
Comment Actions It works for me both ways: with and without the barrier. Comment Actions Wait for a grace period when anonymous file is closed with fput(). As this case happens in drm-kmod very frequently, free memory allocated Comment Actions Are you sure this works, that other structure pointers inside the Linux file structure won't be accessed and will also need to be freed by RCU? Comment Actions If I understand Linux code correctly, one must execute get_file_rcu() with RCU read lock taken[1] before access to any other structure member. [1] https://elixir.bootlin.com/linux/v5.15-rc2/source/drivers/gpu/drm/i915/gem/i915_gem_mman.c#L874 Comment Actions Hi, The problem is that the refcount mechanism access f->_file->f_count . You need to free both "f" and "_file" using kfree_rcu() for this to work. What was the problem with the previous version of this patch? Performance? --HPS Comment Actions Somehow I overlooked that. Reverted.
It missed support for files allocated with shmem_file_setup() and anon_inode_getfile(). They both have filp->_file equal to NULL, so I left kfree_rcu here. Comment Actions Yes, it is partial. kfree_rcu in linux_file_free() is new as compared with old version. |