From nobody Wed Oct 13 09:19:07 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id EF851180004F; Wed, 13 Oct 2021 09:19:07 +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 4HTn636KRlz4sN6; Wed, 13 Oct 2021 09:19:07 +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 B594225480; Wed, 13 Oct 2021 09:19:07 +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 19D9J7gp057152; Wed, 13 Oct 2021 09:19:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19D9J74m057151; Wed, 13 Oct 2021 09:19:07 GMT (envelope-from git) Date: Wed, 13 Oct 2021 09:19:07 GMT Message-Id: <202110130919.19D9J74m057151@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: a02996804609 - stable/13 - LinuxKPI: Implement get_file_rcu() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org 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/stable/13 X-Git-Reftype: branch X-Git-Commit: a029968046090821d34b22defdbe446ed9a41b7f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=a029968046090821d34b22defdbe446ed9a41b7f commit a029968046090821d34b22defdbe446ed9a41b7f Author: Vladimir Kondratyev AuthorDate: 2021-09-29 20:12:25 +0000 Commit: Vladimir Kondratyev 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 #include #include +#include #if defined(__i386__) || defined(__amd64__) #include @@ -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);