fix: lookup_fd_rcu replaced by lookup_fdget_rcu in linux 6.7.0-rc1
[lttng-modules.git] / src / probes / lttng-uprobes.c
index b88aee13cb29a3a9d815d5302a11928f53eaa0df..edded1e960aee6a508020bb527b1912c62ce1c91 100644 (file)
  */
 
 #include <wrapper/fdtable.h>
+#include <linux/file.h>
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/namei.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/uprobes.h>
+
 #include <lttng/events.h>
 #include <lttng/events-internal.h>
 #include <lttng/tracer.h>
 #include <wrapper/irqflags.h>
 #include <ringbuffer/frontend_types.h>
-#include <wrapper/uprobes.h>
 #include <wrapper/vmalloc.h>
 
 static
@@ -42,11 +44,11 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
        {
                struct lttng_kernel_event_recorder *event_recorder =
                        container_of(event, struct lttng_kernel_event_recorder, parent);
-               struct lttng_channel *chan = event_recorder->chan;
+               struct lttng_kernel_channel_buffer *chan = event_recorder->chan;
 
-               if (unlikely(!LTTNG_READ_ONCE(chan->session->active)))
+               if (unlikely(!LTTNG_READ_ONCE(chan->parent.session->active)))
                        return 0;
-               if (unlikely(!LTTNG_READ_ONCE(chan->enabled)))
+               if (unlikely(!LTTNG_READ_ONCE(chan->parent.enabled)))
                        return 0;
                break;
        }
@@ -64,7 +66,7 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
        {
                struct lttng_kernel_event_recorder *event_recorder =
                        container_of(event, struct lttng_kernel_event_recorder, parent);
-               struct lttng_channel *chan = event_recorder->chan;
+               struct lttng_kernel_channel_buffer *chan = event_recorder->chan;
                struct lttng_kernel_ring_buffer_ctx ctx;
                int ret;
 
@@ -78,8 +80,7 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
                /* Event payload. */
                payload.ip = (unsigned long)instruction_pointer(regs);
 
-               lib_ring_buffer_align_ctx(&ctx, lttng_alignof(payload));
-               chan->ops->event_write(&ctx, &payload, sizeof(payload));
+               chan->ops->event_write(&ctx, &payload, sizeof(payload), lttng_alignof(payload));
                chan->ops->event_commit(&ctx);
                break;
        }
@@ -102,7 +103,7 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
 static const struct lttng_kernel_event_field *event_fields[] = {
        lttng_kernel_static_event_field("ip",
                lttng_kernel_static_type_integer_from_type(unsigned long, __BYTE_ORDER, 16),
-               false, false, false),
+               false, false),
 };
 
 static const struct lttng_kernel_tracepoint_class tp_class = {
@@ -114,35 +115,7 @@ static const struct lttng_kernel_tracepoint_class tp_class = {
  * Create event description.
  */
 static
-int lttng_create_uprobe_event(const char *name, struct lttng_kernel_event_recorder *event_recorder)
-{
-       struct lttng_kernel_event_desc *desc;
-       int ret;
-
-       desc = kzalloc(sizeof(*desc), GFP_KERNEL);
-       if (!desc)
-               return -ENOMEM;
-       desc->tp_class = &tp_class;
-       desc->event_name = kstrdup(name, GFP_KERNEL);
-       if (!desc->event_name) {
-               ret = -ENOMEM;
-               goto error_str;
-       }
-       desc->owner = THIS_MODULE;
-       event_recorder->priv->parent.desc = desc;
-
-       return 0;
-
-error_str:
-       kfree(desc);
-       return ret;
-}
-
-/*
- * Create event_notifier description.
- */
-static
-int lttng_create_uprobe_event_notifier(const char *name, struct lttng_kernel_event_notifier *event_notifier)
+int lttng_create_uprobe_event(const char *name, struct lttng_kernel_event_common *event)
 {
        struct lttng_kernel_event_desc *desc;
        int ret;
@@ -157,7 +130,7 @@ int lttng_create_uprobe_event_notifier(const char *name, struct lttng_kernel_eve
                goto error_str;
        }
        desc->owner = THIS_MODULE;
-       event_notifier->priv->parent.desc = desc;
+       event->priv->desc = desc;
 
        return 0;
 
@@ -181,7 +154,7 @@ static struct inode *get_inode_from_fd(int fd)
         * Returns the file backing the given fd. Needs to be done inside an RCU
         * critical section.
         */
-       file = lttng_lookup_fd_rcu(fd);
+       file = lttng_lookup_fdget_rcu(fd);
        if (file == NULL) {
                printk(KERN_WARNING "LTTng: Cannot access file backing the fd(%d)\n", fd);
                inode = NULL;
@@ -192,8 +165,11 @@ static struct inode *get_inode_from_fd(int fd)
        inode = igrab(file->f_path.dentry->d_inode);
        if (inode == NULL)
                printk(KERN_WARNING "LTTng: Cannot grab a reference on the inode.\n");
+
 error:
        rcu_read_unlock();
+       if (file)
+               fput(file);
        return inode;
 }
 
@@ -230,7 +206,7 @@ int lttng_uprobes_add_callsite(struct lttng_uprobe *uprobe,
                goto register_error;
        }
 
-       ret = wrapper_uprobe_register(uprobe->inode,
+       ret = uprobe_register(uprobe->inode,
                      uprobe_handler->offset, &uprobe_handler->up_consumer);
        if (ret) {
                printk(KERN_WARNING "LTTng: Error registering probe on inode %lu "
@@ -277,51 +253,28 @@ inode_error:
        return ret;
 }
 
-int lttng_uprobes_register_event(const char *name, int fd, struct lttng_kernel_event_recorder *event_recorder)
+int lttng_uprobes_register_event(const char *name, int fd, struct lttng_kernel_event_common *event)
 {
        int ret = 0;
 
-       ret = lttng_create_uprobe_event(name, event_recorder);
+       ret = lttng_create_uprobe_event(name, event);
        if (ret)
                goto error;
 
-       ret = lttng_uprobes_register(&event_recorder->priv->parent.u.uprobe, fd);
+       ret = lttng_uprobes_register(&event->priv->u.uprobe, fd);
        if (ret)
                goto register_error;
 
        return 0;
 
 register_error:
-       kfree(event_recorder->priv->parent.desc->event_name);
-       kfree(event_recorder->priv->parent.desc);
+       kfree(event->priv->desc->event_name);
+       kfree(event->priv->desc);
 error:
        return ret;
 }
 EXPORT_SYMBOL_GPL(lttng_uprobes_register_event);
 
-int lttng_uprobes_register_event_notifier(const char *name, int fd,
-               struct lttng_kernel_event_notifier *event_notifier)
-{
-       int ret = 0;
-
-       ret = lttng_create_uprobe_event_notifier(name, event_notifier);
-       if (ret)
-               goto error;
-
-       ret = lttng_uprobes_register(&event_notifier->priv->parent.u.uprobe, fd);
-       if (ret)
-               goto register_error;
-
-       return 0;
-
-register_error:
-       kfree(event_notifier->priv->parent.desc->event_name);
-       kfree(event_notifier->priv->parent.desc);
-error:
-       return ret;
-}
-EXPORT_SYMBOL_GPL(lttng_uprobes_register_event_notifier);
-
 static
 void lttng_uprobes_unregister(struct inode *inode, struct list_head *head)
 {
@@ -332,29 +285,23 @@ void lttng_uprobes_unregister(struct inode *inode, struct list_head *head)
         * and free the struct.
         */
        list_for_each_entry_safe(iter, tmp, head, node) {
-               wrapper_uprobe_unregister(inode, iter->offset, &iter->up_consumer);
+               uprobe_unregister(inode, iter->offset, &iter->up_consumer);
                list_del(&iter->node);
                kfree(iter);
        }
 }
 
-void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event_recorder)
+void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event)
 {
-       lttng_uprobes_unregister(event_recorder->priv->parent.u.uprobe.inode, &event_recorder->priv->parent.u.uprobe.head);
+       lttng_uprobes_unregister(event->priv->u.uprobe.inode, &event->priv->u.uprobe.head);
 }
 EXPORT_SYMBOL_GPL(lttng_uprobes_unregister_event);
 
-void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier)
-{
-       lttng_uprobes_unregister(event_notifier->priv->parent.u.uprobe.inode, &event_notifier->priv->parent.u.uprobe.head);
-}
-EXPORT_SYMBOL_GPL(lttng_uprobes_unregister_event_notifier);
-
-void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event_recorder)
+void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event)
 {
-       iput(event_recorder->priv->parent.u.uprobe.inode);
-       kfree(event_recorder->priv->parent.desc->event_name);
-       kfree(event_recorder->priv->parent.desc);
+       iput(event->priv->u.uprobe.inode);
+       kfree(event->priv->desc->event_name);
+       kfree(event->priv->desc);
 }
 EXPORT_SYMBOL_GPL(lttng_uprobes_destroy_event_private);
 
This page took 0.027122 seconds and 4 git commands to generate.