LinuxKPI: Implement get_file_rcu()

get_file_rcu() grabs a file if the file->f_count is not zero.

Required by drm-kmod 5.6

Reviewed by:	hselasky, manu (previous version)
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D31672
This commit is contained in:
Vladimir Kondratyev 2021-09-29 23:12:25 +03:00
parent ab4ed843a3
commit a81b36c6d3
2 changed files with 12 additions and 1 deletions

View File

@ -108,6 +108,8 @@ struct linux_file {
/* pointer to associated character device, if any */
struct linux_cdev *f_cdev;
struct rcu_head rcu;
};
#define file linux_file
@ -254,6 +256,13 @@ get_file(struct linux_file *f)
return (f);
}
static inline bool
get_file_rcu(struct linux_file *f)
{
return (refcount_acquire_if_not_zero(
f->_file == NULL ? &f->f_count : &f->_file->f_count));
}
static inline struct inode *
igrab(struct inode *inode)
{

View File

@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$");
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/wait_bit.h>
#include <linux/rcupdate.h>
#if defined(__i386__) || defined(__amd64__)
#include <asm/smp.h>
@ -472,7 +473,7 @@ linux_file_free(struct linux_file *filp)
if (filp->_file == NULL) {
if (filp->f_shmem != NULL)
vm_object_deallocate(filp->f_shmem);
kfree(filp);
kfree_rcu(filp, rcu);
} else {
/*
* The close method of the character device or file
@ -1538,6 +1539,7 @@ linux_file_close(struct file *file, struct thread *td)
ldev = filp->f_cdev;
if (ldev != NULL)
linux_cdev_deref(ldev);
linux_synchronize_rcu(RCU_TYPE_REGULAR);
kfree(filp);
return (error);