From owner-dev-commits-src-all@freebsd.org Wed Sep 29 20:27:31 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 520E167AEF9; Wed, 29 Sep 2021 20:27:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HKSbl1dtXz4q5C; Wed, 29 Sep 2021 20:27:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 17F861EBA3; Wed, 29 Sep 2021 20:27:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18TKRVEF038469; Wed, 29 Sep 2021 20:27:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18TKRUVo038468; Wed, 29 Sep 2021 20:27:30 GMT (envelope-from git) Date: Wed, 29 Sep 2021 20:27:30 GMT Message-Id: <202109292027.18TKRUVo038468@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: a81b36c6d35d - main - LinuxKPI: Implement get_file_rcu() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a81b36c6d35d74177891860b789dd02b9d1c5851 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Sep 2021 20:27:31 -0000 The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=a81b36c6d35d74177891860b789dd02b9d1c5851 commit a81b36c6d35d74177891860b789dd02b9d1c5851 Author: Vladimir Kondratyev AuthorDate: 2021-09-29 20:12:25 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-09-29 20:12:25 +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) MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D31672 --- 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 7ea33c9a0d8d..f15b9396525c 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #if defined(__i386__) || defined(__amd64__) #include @@ -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);