Skip to contentSkip to conversation

kprobes: core logic of eraly kprobes

RFC PATCH Hillf Danton 2 participants 5 messages Jan 7, 2015 – Jan 8, 2015

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines
(quoted diff) +4 -0
+struct early_kprobe_slot {
+	struct optimized_kprobe op;
+};
+

[...]

Quoted 3 lines

/* Free optimized instructions and optimized_kprobe */
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot);

[2] How is it implemented? In subsequent patches?

Review

Quoted 12 lines

static void free_aggr_kprobe(struct kprobe *p)
{

(quoted diff) +4 -1
 	struct optimized_kprobe *op;
+	struct early_kprobe_slot *ep;
 
 	op = container_of(p, struct optimized_kprobe, kp);
 	arch_remove_optimized_kprobe(op);
 	arch_remove_kprobe(p);
-	kfree(op);
+	ep = container_of(op, struct early_kprobe_slot, op);
+	if (likely(!ek_free_early_kprobe(ep)))
+		kfree(op);

[1] s/op/ep/ yes?

Quoted 2 lines

}

[...]

Review

Quoted 3 lines
(quoted diff) +3 -0
+#else
+static int register_early_kprobe(struct kprobe *p) { return -ENOSYS; }
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot) { return 0; }

[3] Compile-able with CONFIG_EARLY_KPROBES enabled?

Quoted 4 lines
(quoted diff) +2 -1
+static void convert_early_kprobes(void) {};
+#endif
--

1.8.4

#1 lore raw
Quoted 7 lines · Hillf Danton
Quoted 5 lines
(quoted diff) +4 -0
+struct early_kprobe_slot {
+	struct optimized_kprobe op;
+};
+

[...]

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

/* Free optimized instructions and optimized_kprobe */
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot);

[2] How is it implemented? In subsequent patches?

It is implemented using macro. Please see patch 7/11 and

DEFINE_EKPROBE_ALLOC_OPS(struct early_kprobe_slot, early_kprobe, static);

following.

Quoted 5 lines
Quoted 5 lines

static void free_aggr_kprobe(struct kprobe *p)
{

(quoted diff) +1 -0
 	struct optimized_kprobe *op;
+	struct early_kprobe_slot *ep;
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +3 -1
 	op = container_of(p, struct optimized_kprobe, kp);
 	arch_remove_optimized_kprobe(op);
 	arch_remove_kprobe(p);
-	kfree(op);
+	ep = container_of(op, struct early_kprobe_slot, op);
+	if (likely(!ek_free_early_kprobe(ep)))
+		kfree(op);

[1] s/op/ep/ yes?

Which one? Do you mean kfree(op) --> kfree(ep)?

If ek_free_early_kprobe(ep) fail (not in early_kprobe area defined by DEFINE_EKPROBE_ALLOC_OPS), then this is a normal aggr probe, allocated using kzalloc() as struct optimized_kprobe, see alloc_aggr_kprobe(). So kfree corresponding op structure.

If ek_free_early_kprobe(ep) success, then this is an struct early_kprobe_slot and allocated statically.

Quoted 8 lines
Quoted 2 lines

}

[...]

Review

Quoted 3 lines
(quoted diff) +3 -0
+#else
+static int register_early_kprobe(struct kprobe *p) { return -ENOSYS; }
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot) { return 0; }

[3] Compile-able with CONFIG_EARLY_KPROBES enabled?

These empty functions are for CONFIG_EARLY_KPROBES disabled. They won't be compiled when CONFIG_EARLY_KPROBES=y. I have tested both cases on x86 and ARM.

Quoted 6 lines
Quoted 5 lines
(quoted diff) +2 -1
+static void convert_early_kprobes(void) {};
+#endif
--

1.8.4

Thanks.

#2 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
(quoted diff) +4 -0
+struct early_kprobe_slot {
+	struct optimized_kprobe op;
+};
+

[...]

Quoted 3 lines

/* Free optimized instructions and optimized_kprobe */
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot);

Quoted 7 lines
Quoted 2 lines

[2] How is it implemented? In subsequent patches?

It is implemented using macro. Please see patch 7/11 and

DEFINE_EKPROBE_ALLOC_OPS(struct early_kprobe_slot, early_kprobe, static);

What is the reason that it is listed in C file, given that it is done in H already?

#3 lore raw
Quoted 10 lines · Hillf Danton
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
(quoted diff) +4 -0
+struct early_kprobe_slot {
+	struct optimized_kprobe op;
+};
+

[...]

Quoted 3 lines

/* Free optimized instructions and optimized_kprobe */
+static int ek_free_early_kprobe(struct early_kprobe_slot *slot);

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

[2] How is it implemented? In subsequent patches?

It is implemented using macro. Please see patch 7/11 and

DEFINE_EKPROBE_ALLOC_OPS(struct early_kprobe_slot, early_kprobe, static);

What is the reason that it is listed in C file, given that it is done in H already?

This macro defines an array and a bitmap, not only declare them. In addition, the functions defined by it are used only in this specific .c file.

If there are not only one .c files use it, I think patch 7 can be improved:

#define DEFINE_EKPROBE_AREA(__t, __static) \
__static __t __ek_##__name##_slots[NR_EARLY_KPROBES_SLOTS]; \
__static unsigned long __ek_##__name##_bitmap[EARLY_KPROBES_BITMAP_SZ];

#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
DEFINE_EKPROBE_AREA(__t, __static) \
__DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
static inline __t *ek_alloc_##__name(void) \
{ \
...

In .h file(s):
DEFINE_EKPROBE_ALLOC_OPS(struct early_kprobe_slot, early_kprobe, extern)

In .c file:
DEFINE_EKPROBE_AREA(__t, )

What do you think?

#4 lore raw
Quoted 18 lines

This macro defines an array and a bitmap, not only declare them. In addition, the functions defined by it are used only in this specific .c file.

If there are not only one .c files use it, I think patch 7 can be improved:

#define DEFINE_EKPROBE_AREA(__t, __static) \
__static __t __ek_##__name##_slots[NR_EARLY_KPROBES_SLOTS]; \
__static unsigned long __ek_##__name##_bitmap[EARLY_KPROBES_BITMAP_SZ];

#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
DEFINE_EKPROBE_AREA(__t, __static) \
__DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
static inline __t *ek_alloc_##__name(void) \
{ \
...

Quoted 8 lines

In .h file(s):
DEFINE_EKPROBE_ALLOC_OPS(struct early_kprobe_slot, early_kprobe, extern)

In .c file:
DEFINE_EKPROBE_AREA(__t, )

What do you think?

Looks like rocket science;-)