X-Git-Url: http://git.liburcu.org/?p=lttng-modules.git;a=blobdiff_plain;f=probes%2Flttng-uprobes.c;h=c29e18144d181381ec05ffd11a3547f9f0880e8a;hp=1f549c2f34bb14660c3513953a5711c9aaddd693;hb=2459130397d7e7eecc44a5f06a39d65c78257eef;hpb=56377c91f874d50ea03d1f3f4698c77f69cbf83c diff --git a/probes/lttng-uprobes.c b/probes/lttng-uprobes.c index 1f549c2f..c29e1814 100644 --- a/probes/lttng-uprobes.c +++ b/probes/lttng-uprobes.c @@ -1,4 +1,5 @@ -/* +/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) + * * probes/lttng-uprobes.c * * LTTng uprobes integration module. @@ -6,37 +7,27 @@ * Copyright (C) 2013 Yannick Brosseau * Copyright (C) 2009-2012 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include +#include #include #include #include +#include #include #include #include -#include +#include #include #include static int lttng_uprobes_handler_pre(struct uprobe_consumer *uc, struct pt_regs *regs) { - struct lttng_event *event = - container_of(uc, struct lttng_event, u.uprobe.up_consumer); + struct lttng_uprobe_handler *uprobe_handler = + container_of(uc, struct lttng_uprobe_handler, up_consumer); + struct lttng_event *event = uprobe_handler->event; struct lttng_probe_ctx lttng_probe_ctx = { .event = event, .interruptible = !lttng_regs_irqs_disabled(regs), @@ -49,11 +40,11 @@ int lttng_uprobes_handler_pre(struct uprobe_consumer *uc, struct pt_regs *regs) unsigned long ip; } payload; - if (unlikely(!ACCESS_ONCE(chan->session->active))) + if (unlikely(!READ_ONCE(chan->session->active))) return 0; - if (unlikely(!ACCESS_ONCE(chan->enabled))) + if (unlikely(!READ_ONCE(chan->enabled))) return 0; - if (unlikely(!ACCESS_ONCE(event->enabled))) + if (unlikely(!READ_ONCE(event->enabled))) return 0; lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, @@ -64,7 +55,7 @@ int lttng_uprobes_handler_pre(struct uprobe_consumer *uc, struct pt_regs *regs) return 0; /* Event payload. */ - payload.ip = regs->ip; + payload.ip = (unsigned long)instruction_pointer(regs); lib_ring_buffer_align_ctx(&ctx, lttng_alignof(payload)); chan->ops->event_write(&ctx, &payload, sizeof(payload)); @@ -101,12 +92,12 @@ int lttng_create_uprobe_event(const char *name, struct lttng_event *event) } fields[0].name = "ip"; fields[0].type.atype = atype_integer; - fields[0].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); - fields[0].type.u.basic.integer.reverse_byte_order = 0; - fields[0].type.u.basic.integer.base = 16; - fields[0].type.u.basic.integer.encoding = lttng_encode_none; + fields[0].type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + fields[0].type.u.integer.signedness = lttng_is_signed_type(unsigned long); + fields[0].type.u.integer.reverse_byte_order = 0; + fields[0].type.u.integer.base = 16; + fields[0].type.u.integer.encoding = lttng_encode_none; desc->owner = THIS_MODULE; event->desc = desc; @@ -151,12 +142,59 @@ error: return inode; } -int lttng_uprobes_register(const char *name, - int fd, - uint64_t offset, - struct lttng_event *event) +int lttng_uprobes_add_callsite(struct lttng_event *event, + struct lttng_kernel_event_callsite __user *callsite) { - int ret; + int ret = 0; + struct lttng_uprobe_handler *uprobe_handler; + + if (!event) { + ret = -EINVAL; + goto end; + } + + uprobe_handler = kzalloc(sizeof(struct lttng_uprobe_handler), GFP_KERNEL); + if (!uprobe_handler) { + printk(KERN_WARNING "Error allocating uprobe_uprobe_handlers"); + ret = -ENOMEM; + goto end; + } + + /* Ensure the memory we just allocated don't trigger page faults. */ + wrapper_vmalloc_sync_mappings(); + + uprobe_handler->event = event; + uprobe_handler->up_consumer.handler = lttng_uprobes_handler_pre; + + ret = copy_from_user(&uprobe_handler->offset, &callsite->u.uprobe.offset, sizeof(uint64_t)); + if (ret) { + goto register_error; + } + + ret = wrapper_uprobe_register(event->u.uprobe.inode, + uprobe_handler->offset, &uprobe_handler->up_consumer); + if (ret) { + printk(KERN_WARNING "Error registering probe on inode %lu " + "and offset 0x%llx\n", event->u.uprobe.inode->i_ino, + uprobe_handler->offset); + ret = -1; + goto register_error; + } + + list_add(&uprobe_handler->node, &event->u.uprobe.head); + + return ret; + +register_error: + kfree(uprobe_handler); +end: + return ret; +} +EXPORT_SYMBOL_GPL(lttng_uprobes_add_callsite); + +int lttng_uprobes_register(const char *name, int fd, struct lttng_event *event) +{ + int ret = 0; struct inode *inode; ret = lttng_create_uprobe_event(name, event); @@ -169,29 +207,11 @@ int lttng_uprobes_register(const char *name, ret = -EBADF; goto inode_error; } - - memset(&event->u.uprobe.up_consumer, 0, - sizeof(event->u.uprobe.up_consumer)); - - event->u.uprobe.up_consumer.handler = lttng_uprobes_handler_pre; event->u.uprobe.inode = inode; - event->u.uprobe.offset = offset; + INIT_LIST_HEAD(&event->u.uprobe.head); - /* Ensure the memory we just allocated don't trigger page faults. */ - wrapper_vmalloc_sync_all(); - ret = wrapper_uprobe_register(event->u.uprobe.inode, - event->u.uprobe.offset, - &event->u.uprobe.up_consumer); - if (ret) { - printk(KERN_WARNING "Error registering probe on inode %lu " - "and offset %llu\n", event->u.uprobe.inode->i_ino, - event->u.uprobe.offset); - goto register_error; - } return 0; -register_error: - iput(event->u.uprobe.inode); inode_error: kfree(event->desc->name); kfree(event->desc); @@ -202,9 +222,18 @@ EXPORT_SYMBOL_GPL(lttng_uprobes_register); void lttng_uprobes_unregister(struct lttng_event *event) { - wrapper_uprobe_unregister(event->u.uprobe.inode, - event->u.uprobe.offset, - &event->u.uprobe.up_consumer); + struct lttng_uprobe_handler *iter, *tmp; + + /* + * Iterate over the list of handler, remove each handler from the list + * and free the struct. + */ + list_for_each_entry_safe(iter, tmp, &event->u.uprobe.head, node) { + wrapper_uprobe_unregister(event->u.uprobe.inode, iter->offset, + &iter->up_consumer); + list_del(&iter->node); + kfree(iter); + } } EXPORT_SYMBOL_GPL(lttng_uprobes_unregister);