video: tegra: nvmap: Fix f_count for Linux v6.13

In Linux v6.13, 'f_count' has been replaced by 'f_ref' in the 'file'
structure. Use conftest to detect if 'f_ref' is present and update the
NVMAP driver accordingly.

Please note that in most cases we can simply use the 'file_count' macro
for getting the count and this has been supported since Linux v2.6.

Bug 4991705

Change-Id: I3ccaf88bd6c3dca5b364205cf03a577945f62092
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3260939
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Ketan Patil <ketanp@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
This commit is contained in:
Jon Hunter
2024-10-10 10:16:07 +01:00
parent cb2e183b22
commit b34e2f9554
5 changed files with 29 additions and 8 deletions

View File

@@ -495,7 +495,11 @@ found:
goto fail; goto fail;
BUG_ON(!h->dmabuf->file); BUG_ON(!h->dmabuf->file);
/* This is same as get_dma_buf() if file->f_count was non-zero */ /* This is same as get_dma_buf() if file->f_count was non-zero */
#if defined(NV_FILE_STRUCT_HAS_F_REF) /* Linux v6.13 */
if (file_ref_get(&h->dmabuf->file->f_ref) == 0)
#else
if (atomic_long_inc_not_zero(&h->dmabuf->file->f_count) == 0) if (atomic_long_inc_not_zero(&h->dmabuf->file->f_count) == 0)
#endif
goto fail; goto fail;
mutex_unlock(&h->lock); mutex_unlock(&h->lock);
@@ -788,7 +792,7 @@ void nvmap_free_handle_from_fd(struct nvmap_client *client,
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf; dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf;
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }

View File

@@ -94,7 +94,7 @@ int nvmap_ioctl_getfd(struct file *filp, void __user *arg)
if (!ret && !IS_ERR_OR_NULL(handle)) { if (!ret && !IS_ERR_OR_NULL(handle)) {
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }
@@ -171,7 +171,7 @@ alloc_op_done:
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf; dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf;
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }
@@ -313,7 +313,7 @@ out:
if (!ret && !IS_ERR_OR_NULL(handle)) { if (!ret && !IS_ERR_OR_NULL(handle)) {
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }
@@ -411,7 +411,7 @@ out:
if (!err) { if (!err) {
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }
@@ -1052,7 +1052,7 @@ exit:
mutex_lock(&handle->lock); mutex_lock(&handle->lock);
dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf; dmabuf = is_ro ? handle->dmabuf_ro : handle->dmabuf;
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }
@@ -1238,7 +1238,7 @@ out:
if (!ret && !IS_ERR_OR_NULL(handle)) if (!ret && !IS_ERR_OR_NULL(handle))
trace_refcount_dup_handle(handle, dmabuf, trace_refcount_dup_handle(handle, dmabuf,
atomic_read(&handle->ref), atomic_read(&handle->ref),
atomic_long_read(&dmabuf->file->f_count), file_count(dmabuf->file),
is_ro ? "RO" : "RW"); is_ro ? "RO" : "RW");
if (!IS_ERR(ref)) if (!IS_ERR(ref))

View File

@@ -350,7 +350,7 @@ unlock:
if (!ret) { if (!ret) {
mutex_lock(&h->lock); mutex_lock(&h->lock);
if (dmabuf && dmabuf->file) { if (dmabuf && dmabuf->file) {
dmabuf_ref = atomic_long_read(&dmabuf->file->f_count); dmabuf_ref = file_count(dmabuf->file);
} else { } else {
dmabuf_ref = 0; dmabuf_ref = 0;
} }

View File

@@ -128,6 +128,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += ethtool_ops_get_set_ringparam_has_ringpara
NV_CONFTEST_FUNCTION_COMPILE_TESTS += ethtool_ops_get_set_rxfh_has_rxfh_param_args NV_CONFTEST_FUNCTION_COMPILE_TESTS += ethtool_ops_get_set_rxfh_has_rxfh_param_args
NV_CONFTEST_FUNCTION_COMPILE_TESTS += fd_empty NV_CONFTEST_FUNCTION_COMPILE_TESTS += fd_empty
NV_CONFTEST_FUNCTION_COMPILE_TESTS += fd_file NV_CONFTEST_FUNCTION_COMPILE_TESTS += fd_file
NV_CONFTEST_FUNCTION_COMPILE_TESTS += file_struct_has_f_ref
NV_CONFTEST_FUNCTION_COMPILE_TESTS += folio_entire_mapcount NV_CONFTEST_FUNCTION_COMPILE_TESTS += folio_entire_mapcount
NV_CONFTEST_FUNCTION_COMPILE_TESTS += genpd_xlate_t_has_const_of_phandle_args NV_CONFTEST_FUNCTION_COMPILE_TESTS += genpd_xlate_t_has_const_of_phandle_args
NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_file_rcu_has_double_ptr_file_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_file_rcu_has_double_ptr_file_arg

View File

@@ -7280,6 +7280,22 @@ compile_test() {
compile_check_conftest "$CODE" "NV_FD_FILE_PRESENT" "" "functions" compile_check_conftest "$CODE" "NV_FD_FILE_PRESENT" "" "functions"
;; ;;
file_struct_has_f_ref)
#
# Determine if 'struct file' has the 'f_ref' member.
#
# Commit 90ee6ed776c0 ("fs: port files to file_ref") replaced the
# 'f_count' member of 'struct file' with 'f_ref' in Linux v6.13.
#
CODE="
#include <linux/fs.h>
int conftest_file_struct_has_f_ref(void) {
return offsetof(struct file, f_ref);
}"
compile_check_conftest "$CODE" "NV_FILE_STRUCT_HAS_F_REF" "" "types"
;;
folio_entire_mapcount) folio_entire_mapcount)
# #
# Determine if function folio_entire_mapcount() is present. # Determine if function folio_entire_mapcount() is present.