Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Oct 2021 09:19:07 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a02996804609 - stable/13 - LinuxKPI: Implement get_file_rcu()
Message-ID:  <202110130919.19D9J74m057151@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=a029968046090821d34b22defdbe446ed9a41b7f

commit a029968046090821d34b22defdbe446ed9a41b7f
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-09-29 20:12:25 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2021-10-13 08:57:46 +0000

    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)
    Differential revision:  https://reviews.freebsd.org/D31672
    
    (cherry picked from commit a81b36c6d35d74177891860b789dd02b9d1c5851)
---
 sys/compat/linuxkpi/common/include/linux/fs.h | 9 +++++++++
 sys/compat/linuxkpi/common/src/linux_compat.c | 4 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/fs.h b/sys/compat/linuxkpi/common/include/linux/fs.h
index 38911c276216..eaf806b6732c 100644
--- a/sys/compat/linuxkpi/common/include/linux/fs.h
+++ b/sys/compat/linuxkpi/common/include/linux/fs.h
@@ -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)
 {
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 217c4081c603..7315a2671ead 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -89,6 +89,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>
@@ -471,7 +472,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
@@ -1537,6 +1538,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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110130919.19D9J74m057151>