X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fprobes%2Flttng-uprobes.c;h=b6531a71e16df3938e364023c9d767319f71f2c6;hb=17806c46f59eba37b32bde6543bd5017d154b42d;hp=c44ed4f8da511349cd911faafa8440c3e49170a0;hpb=196bfc6a04f069e57803c9a2a18f2528394ceacd;p=lttng-modules.git diff --git a/src/probes/lttng-uprobes.c b/src/probes/lttng-uprobes.c index c44ed4f8..b6531a71 100644 --- a/src/probes/lttng-uprobes.c +++ b/src/probes/lttng-uprobes.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -27,128 +28,107 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs * { struct lttng_uprobe_handler *uprobe_handler = container_of(uc, struct lttng_uprobe_handler, up_consumer); - struct lttng_event *event = uprobe_handler->u.event; - struct lttng_probe_ctx lttng_probe_ctx = { + struct lttng_kernel_event_common *event = uprobe_handler->event; + struct lttng_kernel_probe_ctx lttng_probe_ctx = { .event = event, .interruptible = !lttng_regs_irqs_disabled(regs), }; - struct lttng_channel *chan = event->chan; - struct lib_ring_buffer_ctx ctx; - int ret; - struct { unsigned long ip; } payload; - if (unlikely(!LTTNG_READ_ONCE(chan->session->active))) - return 0; - if (unlikely(!LTTNG_READ_ONCE(chan->enabled))) - return 0; - if (unlikely(!LTTNG_READ_ONCE(event->enabled))) - return 0; - - lib_ring_buffer_ctx_init(&ctx, chan->chan, <tng_probe_ctx, - sizeof(payload), lttng_alignof(payload), -1); + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + { + struct lttng_kernel_event_recorder *event_recorder = + container_of(event, struct lttng_kernel_event_recorder, parent); + struct lttng_kernel_channel_buffer *chan = event_recorder->chan; + + if (unlikely(!LTTNG_READ_ONCE(chan->parent.session->active))) + return 0; + if (unlikely(!LTTNG_READ_ONCE(chan->parent.enabled))) + return 0; + break; + } + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + break; + default: + WARN_ON_ONCE(1); + } - ret = chan->ops->event_reserve(&ctx, event->id); - if (ret < 0) + if (unlikely(!LTTNG_READ_ONCE(event->enabled))) return 0; - /* Event payload. */ - payload.ip = (unsigned long)instruction_pointer(regs); + switch (event->type) { + case LTTNG_KERNEL_EVENT_TYPE_RECORDER: + { + struct lttng_kernel_event_recorder *event_recorder = + container_of(event, struct lttng_kernel_event_recorder, parent); + struct lttng_kernel_channel_buffer *chan = event_recorder->chan; + struct lttng_kernel_ring_buffer_ctx ctx; + int ret; - lib_ring_buffer_align_ctx(&ctx, lttng_alignof(payload)); - chan->ops->event_write(&ctx, &payload, sizeof(payload)); - chan->ops->event_commit(&ctx); - return 0; -} + lib_ring_buffer_ctx_init(&ctx, event_recorder, + sizeof(payload), lttng_alignof(payload), <tng_probe_ctx); -static -int lttng_uprobes_event_notifier_handler_pre(struct uprobe_consumer *uc, struct pt_regs *regs) -{ - struct lttng_uprobe_handler *uprobe_handler = - container_of(uc, struct lttng_uprobe_handler, up_consumer); - struct lttng_event_notifier *event_notifier = uprobe_handler->u.event_notifier; - struct lttng_kernel_notifier_ctx notif_ctx; + ret = chan->ops->event_reserve(&ctx); + if (ret < 0) + return 0; - if (unlikely(!READ_ONCE(event_notifier->enabled))) - return 0; + /* Event payload. */ + payload.ip = (unsigned long)instruction_pointer(regs); - notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture); - event_notifier->send_notification(event_notifier, NULL, NULL, ¬if_ctx); - return 0; -} - -/* - * Create event description. - */ -static -int lttng_create_uprobe_event(const char *name, struct lttng_event *event) -{ - struct lttng_event_desc *desc; - struct lttng_event_field *fields; - int ret; - - desc = kzalloc(sizeof(*event->desc), GFP_KERNEL); - if (!desc) - return -ENOMEM; - desc->name = kstrdup(name, GFP_KERNEL); - if (!desc->name) { - ret = -ENOMEM; - goto error_str; + chan->ops->event_write(&ctx, &payload, sizeof(payload), lttng_alignof(payload)); + chan->ops->event_commit(&ctx); + break; } - - desc->nr_fields = 1; - desc->fields = fields = - kzalloc(1 * sizeof(struct lttng_event_field), GFP_KERNEL); - - if (!desc->fields) { - ret = -ENOMEM; - goto error_fields; + case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: + { + struct lttng_kernel_event_notifier *event_notifier = + container_of(event, struct lttng_kernel_event_notifier, parent); + struct lttng_kernel_notification_ctx notif_ctx; + + notif_ctx.eval_capture = LTTNG_READ_ONCE(event_notifier->eval_capture); + event_notifier->notification_send(event_notifier, NULL, NULL, ¬if_ctx); + break; + } + default: + WARN_ON_ONCE(1); } - fields[0].name = "ip"; - fields[0].type.atype = atype_integer; - 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; - return 0; - -error_fields: - kfree(desc->name); -error_str: - kfree(desc); - return ret; } +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), +}; + +static const struct lttng_kernel_tracepoint_class tp_class = { + .nr_fields = ARRAY_SIZE(event_fields), + .fields = event_fields, +}; + /* - * Create event_notifier description. + * Create event description. */ static -int lttng_create_uprobe_event_notifier(const char *name, struct lttng_event_notifier *event_notifier) +int lttng_create_uprobe_event(const char *name, struct lttng_kernel_event_common *event) { - struct lttng_event_desc *desc; + struct lttng_kernel_event_desc *desc; int ret; - desc = kzalloc(sizeof(*event_notifier->desc), GFP_KERNEL); + desc = kzalloc(sizeof(*desc), GFP_KERNEL); if (!desc) return -ENOMEM; - desc->name = kstrdup(name, GFP_KERNEL); - if (!desc->name) { + desc->tp_class = &tp_class; + desc->event_name = kstrdup(name, GFP_KERNEL); + if (!desc->event_name) { ret = -ENOMEM; goto error_str; } - - desc->nr_fields = 0; - desc->owner = THIS_MODULE; - event_notifier->desc = desc; + event->priv->desc = desc; return 0; @@ -191,7 +171,7 @@ error: static int lttng_uprobes_add_callsite(struct lttng_uprobe *uprobe, - struct lttng_kernel_event_callsite __user *callsite, + struct lttng_kernel_abi_event_callsite __user *callsite, int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs), void *priv_data) { @@ -213,7 +193,7 @@ int lttng_uprobes_add_callsite(struct lttng_uprobe *uprobe, /* Ensure the memory we just allocated don't notify page faults. */ wrapper_vmalloc_sync_mappings(); - uprobe_handler->u.event = priv_data; + uprobe_handler->event = priv_data; uprobe_handler->up_consumer.handler = handler; ret = copy_from_user(&uprobe_handler->offset, &callsite->u.uprobe.offset, sizeof(uint64_t)); @@ -241,22 +221,14 @@ end: return ret; } -int lttng_uprobes_event_add_callsite(struct lttng_event *event, - struct lttng_kernel_event_callsite __user *callsite) +int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event, + struct lttng_kernel_abi_event_callsite __user *callsite) { - return lttng_uprobes_add_callsite(&event->u.uprobe, callsite, + return lttng_uprobes_add_callsite(&event->priv->u.uprobe, callsite, lttng_uprobes_event_handler_pre, event); } EXPORT_SYMBOL_GPL(lttng_uprobes_event_add_callsite); -int lttng_uprobes_event_notifier_add_callsite(struct lttng_event_notifier *event_notifier, - struct lttng_kernel_event_callsite __user *callsite) -{ - return lttng_uprobes_add_callsite(&event_notifier->u.uprobe, callsite, - lttng_uprobes_event_notifier_handler_pre, event_notifier); -} -EXPORT_SYMBOL_GPL(lttng_uprobes_event_notifier_add_callsite); - static int lttng_uprobes_register(struct lttng_uprobe *uprobe, int fd) { @@ -276,7 +248,7 @@ inode_error: return ret; } -int lttng_uprobes_register_event(const char *name, int fd, struct lttng_event *event) +int lttng_uprobes_register_event(const char *name, int fd, struct lttng_kernel_event_common *event) { int ret = 0; @@ -284,43 +256,20 @@ int lttng_uprobes_register_event(const char *name, int fd, struct lttng_event *e if (ret) goto error; - ret = lttng_uprobes_register(&event->u.uprobe, fd); + ret = lttng_uprobes_register(&event->priv->u.uprobe, fd); if (ret) goto register_error; return 0; register_error: - kfree(event->desc->name); - kfree(event->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_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->u.uprobe, fd); - if (ret) - goto register_error; - - return 0; - -register_error: - kfree(event_notifier->desc->name); - kfree(event_notifier->desc); -error: - return ret; -} -EXPORT_SYMBOL_GPL(lttng_uprobes_register_event_notifier); - static void lttng_uprobes_unregister(struct inode *inode, struct list_head *head) { @@ -335,34 +284,27 @@ void lttng_uprobes_unregister(struct inode *inode, struct list_head *head) list_del(&iter->node); kfree(iter); } - } -void lttng_uprobes_unregister_event(struct lttng_event *event) +void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event) { - lttng_uprobes_unregister(event->u.uprobe.inode, &event->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_event_notifier *event_notifier) -{ - lttng_uprobes_unregister(event_notifier->u.uprobe.inode, &event_notifier->u.uprobe.head); -} -EXPORT_SYMBOL_GPL(lttng_uprobes_unregister_event_notifier); - -void lttng_uprobes_destroy_event_private(struct lttng_event *event) +void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event) { - iput(event->u.uprobe.inode); - kfree(event->desc->name); - kfree(event->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); -void lttng_uprobes_destroy_event_notifier_private(struct lttng_event_notifier *event_notifier) +void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier) { - iput(event_notifier->u.uprobe.inode); - kfree(event_notifier->desc->name); - kfree(event_notifier->desc); + iput(event_notifier->priv->parent.u.uprobe.inode); + kfree(event_notifier->priv->parent.desc->event_name); + kfree(event_notifier->priv->parent.desc); } EXPORT_SYMBOL_GPL(lttng_uprobes_destroy_event_notifier_private);