]> git.lttng.org Git - lttng-modules.git/commitdiff
Fix: lookup_fdget_rcu removed in Linux 6.13.0-rc1
authorKienan Stewart <kstewart@efficios.com>
Mon, 2 Dec 2024 16:15:40 +0000 (16:15 +0000)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 10 Dec 2024 19:13:20 +0000 (14:13 -0500)
See upstream commit 8fd3395ec9051a52828fcca2328cb50a69dea8ef:

    commit 8fd3395ec9051a52828fcca2328cb50a69dea8ef
    Author: Al Viro <viro@zeniv.linux.org.uk>
    Date:   Wed Jul 31 11:49:04 2024 -0400

        get rid of ...lookup...fdget_rcu() family

        Once upon a time, predecessors of those used to do file lookup
        without bumping a refcount, provided that caller held rcu_read_lock()
        across the lookup and whatever it wanted to read from the struct
        file found.  When struct file allocation switched to SLAB_TYPESAFE_BY_RCU,
        that stopped being feasible and these primitives started to bump the
        file refcount for lookup result, requiring the caller to call fput()
        afterwards.

        But that turned them pointless - e.g.
                rcu_read_lock();
                file = lookup_fdget_rcu(fd);
                rcu_read_unlock();
        is equivalent to
                file = fget_raw(fd);
        and all callers of lookup_fdget_rcu() are of that form.  Similarly,
        task_lookup_fdget_rcu() calls can be replaced with calling fget_task().
        task_lookup_next_fdget_rcu() doesn't have direct counterparts, but
        its callers would be happier if we replaced it with an analogue that
        deals with RCU internally.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Change-Id: I98f1c617e8bd7ad9db7a9af2a1fa76c5eb26e8b8
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/wrapper/fdtable.h
include/wrapper/file_ref.h
src/lttng-abi.c

index bd03c08b945b95623837fe63fcf545619f2a072c..7807ab7fddde1819f3ad271894a3d951ae613fa8 100644 (file)
@@ -9,10 +9,17 @@
 #define _LTTNG_WRAPPER_FDTABLE_H
 
 #include <lttng/kernel-version.h>
+#include <linux/file.h>
 #include <linux/fdtable.h>
 #include <linux/sched.h>
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,13,0))
+static inline
+struct file *lttng_lookup_fdget_rcu(unsigned int fd)
+{
+       return fget_raw(fd);
+}
+#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
 static inline
 struct file *lttng_lookup_fdget_rcu(unsigned int fd)
 {
index fd2b1238d1a9655eb0b9deecfb1a5d14b5c9ec4b..b44ada09d90ad30c310134f4d45c2df7eae418e4 100644 (file)
@@ -18,10 +18,9 @@ bool lttng_file_ref_get(struct file *file)
        return file_ref_get(&file->f_ref);
 }
 
-static inline
+static inline __must_check
 bool lttng_file_ref_put(struct file *file)
 {
-       /* This is __must_check */
        return file_ref_put(&file->f_ref);
 }
 
@@ -33,7 +32,7 @@ bool lttng_file_ref_get(struct file *file)
        return true;
 }
 
-static inline
+static inline __must_check
 bool lttng_file_ref_put(struct file *file)
 {
        atomic_long_dec(&file->f_count);
index da37576087940986fa17dce784b866da806d327c..cc1ff1f43356bd27b107aeb5294b292e9bdd970d 100644 (file)
@@ -577,7 +577,9 @@ int lttng_abi_create_channel(struct file *session_file,
        return chan_fd;
 
 chan_error:
-       lttng_file_ref_put(session_file);
+       if (!lttng_file_ref_put(session_file)) {
+               ret = -EINVAL;
+       }
 refcount_error:
        fput(chan_file);
 file_error:
@@ -2450,7 +2452,9 @@ int lttng_abi_open_event_notifier_group_stream(struct file *notif_file)
        return ret;
 
 fd_error:
-       lttng_file_ref_put(notif_file);
+       if (!lttng_file_ref_put(notif_file)) {
+               /* Don't change return code */
+       }
 refcount_error:
        event_notifier_group->ops->priv->buffer_read_close(buf);
        return ret;
@@ -2777,7 +2781,9 @@ int lttng_abi_create_event_recorder_enabler(struct file *channel_file,
        return event_fd;
 
 event_error:
-       lttng_file_ref_put(channel_file);
+       if (!lttng_file_ref_put(channel_file)) {
+               ret = -EINVAL;
+       }
 refcount_error:
        fput(event_file);
 file_error:
@@ -2937,7 +2943,9 @@ int lttng_abi_create_event_counter_enabler(struct file *channel_file,
        return event_fd;
 
 event_error:
-       lttng_file_ref_put(channel_file);
+       if (!lttng_file_ref_put(channel_file)) {
+               /* Don't change return code */
+       }
 refcount_error:
        fput(event_file);
 file_error:
@@ -3190,7 +3198,9 @@ int lttng_abi_create_event_notifier(struct file *event_notifier_group_file,
        return event_notifier_fd;
 
 event_notifier_error:
-       lttng_file_ref_put(event_notifier_group_file);
+       if (!lttng_file_ref_put(event_notifier_group_file)) {
+               /* Don't change return code */
+       }
 refcount_error:
        fput(event_notifier_file);
 file_error:
@@ -3266,7 +3276,9 @@ long lttng_abi_session_create_counter(
        return counter_fd;
 
 create_error:
-       lttng_file_ref_put(session->priv->file);
+       if (!lttng_file_ref_put(session->priv->file)) {
+               /* Don't change return  code */
+       }
 refcount_error:
        fput(counter_file);
 file_error:
@@ -3362,7 +3374,9 @@ long lttng_abi_event_notifier_group_create_error_counter(
        return counter_fd;
 
 create_error:
-      lttng_file_ref_put(event_notifier_group_file);
+       if (!lttng_file_ref_put(event_notifier_group_file)) {
+               /* Don't change return code */
+       }
 refcount_error:
        fput(counter_file);
 file_error:
This page took 0.033823 seconds and 4 git commands to generate.