@@ -95,10 +95,6 @@ struct kprobe_insn_page {
95
95
char slot_used [];
96
96
};
97
97
98
- #define KPROBE_INSN_PAGE_SIZE (slots ) \
99
- (offsetof(struct kprobe_insn_page, slot_used) + \
100
- (sizeof(char) * (slots)))
101
-
102
98
static int slots_per_page (struct kprobe_insn_cache * c )
103
99
{
104
100
return PAGE_SIZE /(c -> insn_size * sizeof (kprobe_opcode_t ));
@@ -175,7 +171,7 @@ kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c)
175
171
goto retry ;
176
172
177
173
/* All out of space. Need to allocate a new page. */
178
- kip = kmalloc (KPROBE_INSN_PAGE_SIZE ( slots_per_page (c )), GFP_KERNEL );
174
+ kip = kmalloc (struct_size ( kip , slot_used , slots_per_page (c )), GFP_KERNEL );
179
175
if (!kip )
180
176
goto out ;
181
177
@@ -206,29 +202,29 @@ static bool collect_one_slot(struct kprobe_insn_page *kip, int idx)
206
202
{
207
203
kip -> slot_used [idx ] = SLOT_CLEAN ;
208
204
kip -> nused -- ;
209
- if (kip -> nused == 0 ) {
205
+ if (kip -> nused != 0 )
206
+ return false;
207
+
208
+ /*
209
+ * Page is no longer in use. Free it unless
210
+ * it's the last one. We keep the last one
211
+ * so as not to have to set it up again the
212
+ * next time somebody inserts a probe.
213
+ */
214
+ if (!list_is_singular (& kip -> list )) {
210
215
/*
211
- * Page is no longer in use. Free it unless
212
- * it's the last one. We keep the last one
213
- * so as not to have to set it up again the
214
- * next time somebody inserts a probe.
216
+ * Record perf ksymbol unregister event before removing
217
+ * the page.
215
218
*/
216
- if (!list_is_singular (& kip -> list )) {
217
- /*
218
- * Record perf ksymbol unregister event before removing
219
- * the page.
220
- */
221
- perf_event_ksymbol (PERF_RECORD_KSYMBOL_TYPE_OOL ,
222
- (unsigned long )kip -> insns , PAGE_SIZE , true,
223
- kip -> cache -> sym );
224
- list_del_rcu (& kip -> list );
225
- synchronize_rcu ();
226
- kip -> cache -> free (kip -> insns );
227
- kfree (kip );
228
- }
229
- return true;
219
+ perf_event_ksymbol (PERF_RECORD_KSYMBOL_TYPE_OOL ,
220
+ (unsigned long )kip -> insns , PAGE_SIZE , true,
221
+ kip -> cache -> sym );
222
+ list_del_rcu (& kip -> list );
223
+ synchronize_rcu ();
224
+ kip -> cache -> free (kip -> insns );
225
+ kfree (kip );
230
226
}
231
- return false ;
227
+ return true ;
232
228
}
233
229
234
230
static int collect_garbage_slots (struct kprobe_insn_cache * c )
@@ -353,8 +349,8 @@ struct kprobe_insn_cache kprobe_optinsn_slots = {
353
349
/* .insn_size is initialized later */
354
350
.nr_garbage = 0 ,
355
351
};
356
- #endif
357
- #endif
352
+ #endif /* CONFIG_OPTPROBES */
353
+ #endif /* __ARCH_WANT_KPROBES_INSN_SLOT */
358
354
359
355
/* We have preemption disabled.. so it is safe to use __ versions */
360
356
static inline void set_kprobe_instance (struct kprobe * kp )
@@ -1543,7 +1539,7 @@ static int check_ftrace_location(struct kprobe *p)
1543
1539
if (ftrace_location (addr ) == addr ) {
1544
1540
#ifdef CONFIG_KPROBES_ON_FTRACE
1545
1541
p -> flags |= KPROBE_FLAG_FTRACE ;
1546
- #else /* !CONFIG_KPROBES_ON_FTRACE */
1542
+ #else
1547
1543
return - EINVAL ;
1548
1544
#endif
1549
1545
}
@@ -1725,28 +1721,29 @@ static struct kprobe *__disable_kprobe(struct kprobe *p)
1725
1721
if (unlikely (orig_p == NULL ))
1726
1722
return ERR_PTR (- EINVAL );
1727
1723
1728
- if (!kprobe_disabled (p )) {
1729
- /* Disable probe if it is a child probe */
1730
- if (p != orig_p )
1731
- p -> flags |= KPROBE_FLAG_DISABLED ;
1724
+ if (kprobe_disabled (p ))
1725
+ return orig_p ;
1732
1726
1733
- /* Try to disarm and disable this/parent probe */
1734
- if (p == orig_p || aggr_kprobe_disabled (orig_p )) {
1735
- /*
1736
- * Don't be lazy here. Even if 'kprobes_all_disarmed'
1737
- * is false, 'orig_p' might not have been armed yet.
1738
- * Note arm_all_kprobes() __tries__ to arm all kprobes
1739
- * on the best effort basis.
1740
- */
1741
- if (!kprobes_all_disarmed && !kprobe_disabled (orig_p )) {
1742
- ret = disarm_kprobe (orig_p , true);
1743
- if (ret ) {
1744
- p -> flags &= ~KPROBE_FLAG_DISABLED ;
1745
- return ERR_PTR (ret );
1746
- }
1727
+ /* Disable probe if it is a child probe */
1728
+ if (p != orig_p )
1729
+ p -> flags |= KPROBE_FLAG_DISABLED ;
1730
+
1731
+ /* Try to disarm and disable this/parent probe */
1732
+ if (p == orig_p || aggr_kprobe_disabled (orig_p )) {
1733
+ /*
1734
+ * Don't be lazy here. Even if 'kprobes_all_disarmed'
1735
+ * is false, 'orig_p' might not have been armed yet.
1736
+ * Note arm_all_kprobes() __tries__ to arm all kprobes
1737
+ * on the best effort basis.
1738
+ */
1739
+ if (!kprobes_all_disarmed && !kprobe_disabled (orig_p )) {
1740
+ ret = disarm_kprobe (orig_p , true);
1741
+ if (ret ) {
1742
+ p -> flags &= ~KPROBE_FLAG_DISABLED ;
1743
+ return ERR_PTR (ret );
1747
1744
}
1748
- orig_p -> flags |= KPROBE_FLAG_DISABLED ;
1749
1745
}
1746
+ orig_p -> flags |= KPROBE_FLAG_DISABLED ;
1750
1747
}
1751
1748
1752
1749
return orig_p ;
0 commit comments