Skip to content

Commit 4399404

Browse files
mhiramatrostedt
authored andcommitted
kprobes: Fix build errors with CONFIG_KRETPROBES=n
Max Filippov reported: When building kernel with CONFIG_KRETPROBES=n kernel/kprobes.c compilation fails with the following messages: kernel/kprobes.c: In function ‘recycle_rp_inst’: kernel/kprobes.c:1273:32: error: implicit declaration of function ‘get_kretprobe’ kernel/kprobes.c: In function ‘kprobe_flush_task’: kernel/kprobes.c:1299:35: error: ‘struct task_struct’ has no member named ‘kretprobe_instances’ This came from the commit d741bf4 ("kprobes: Remove kretprobe hash") which introduced get_kretprobe() and kretprobe_instances member in task_struct when CONFIG_KRETPROBES=y, but did not make recycle_rp_inst() and kprobe_flush_task() depending on CONFIG_KRETPORBES. Since those functions are only used for kretprobe, move those functions into #ifdef CONFIG_KRETPROBE area. Link: https://lkml.kernel.org/r/165163539094.74407.3838114721073251225.stgit@devnote2 Reported-by: Max Filippov <jcmvbkbc@gmail.com> Fixes: d741bf4 ("kprobes: Remove kretprobe hash") Cc: "Naveen N . Rao" <naveen.n.rao@linux.ibm.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Cc: "David S . Miller" <davem@davemloft.net> Cc: Peter Zijlstra <peterz@infradead.org> Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Tested-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent b27f266 commit 4399404

2 files changed

Lines changed: 72 additions & 74 deletions

File tree

include/linux/kprobes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void unregister_kretprobe(struct kretprobe *rp);
424424
int register_kretprobes(struct kretprobe **rps, int num);
425425
void unregister_kretprobes(struct kretprobe **rps, int num);
426426

427-
#ifdef CONFIG_KRETPROBE_ON_RETHOOK
427+
#if defined(CONFIG_KRETPROBE_ON_RETHOOK) || !defined(CONFIG_KRETPROBES)
428428
#define kprobe_flush_task(tk) do {} while (0)
429429
#else
430430
void kprobe_flush_task(struct task_struct *tk);

kernel/kprobes.c

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,79 +1257,6 @@ void kprobe_busy_end(void)
12571257
preempt_enable();
12581258
}
12591259

1260-
#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1261-
static void free_rp_inst_rcu(struct rcu_head *head)
1262-
{
1263-
struct kretprobe_instance *ri = container_of(head, struct kretprobe_instance, rcu);
1264-
1265-
if (refcount_dec_and_test(&ri->rph->ref))
1266-
kfree(ri->rph);
1267-
kfree(ri);
1268-
}
1269-
NOKPROBE_SYMBOL(free_rp_inst_rcu);
1270-
1271-
static void recycle_rp_inst(struct kretprobe_instance *ri)
1272-
{
1273-
struct kretprobe *rp = get_kretprobe(ri);
1274-
1275-
if (likely(rp))
1276-
freelist_add(&ri->freelist, &rp->freelist);
1277-
else
1278-
call_rcu(&ri->rcu, free_rp_inst_rcu);
1279-
}
1280-
NOKPROBE_SYMBOL(recycle_rp_inst);
1281-
1282-
/*
1283-
* This function is called from delayed_put_task_struct() when a task is
1284-
* dead and cleaned up to recycle any kretprobe instances associated with
1285-
* this task. These left over instances represent probed functions that
1286-
* have been called but will never return.
1287-
*/
1288-
void kprobe_flush_task(struct task_struct *tk)
1289-
{
1290-
struct kretprobe_instance *ri;
1291-
struct llist_node *node;
1292-
1293-
/* Early boot, not yet initialized. */
1294-
if (unlikely(!kprobes_initialized))
1295-
return;
1296-
1297-
kprobe_busy_begin();
1298-
1299-
node = __llist_del_all(&tk->kretprobe_instances);
1300-
while (node) {
1301-
ri = container_of(node, struct kretprobe_instance, llist);
1302-
node = node->next;
1303-
1304-
recycle_rp_inst(ri);
1305-
}
1306-
1307-
kprobe_busy_end();
1308-
}
1309-
NOKPROBE_SYMBOL(kprobe_flush_task);
1310-
1311-
static inline void free_rp_inst(struct kretprobe *rp)
1312-
{
1313-
struct kretprobe_instance *ri;
1314-
struct freelist_node *node;
1315-
int count = 0;
1316-
1317-
node = rp->freelist.head;
1318-
while (node) {
1319-
ri = container_of(node, struct kretprobe_instance, freelist);
1320-
node = node->next;
1321-
1322-
kfree(ri);
1323-
count++;
1324-
}
1325-
1326-
if (refcount_sub_and_test(count, &rp->rph->ref)) {
1327-
kfree(rp->rph);
1328-
rp->rph = NULL;
1329-
}
1330-
}
1331-
#endif /* !CONFIG_KRETPROBE_ON_RETHOOK */
1332-
13331260
/* Add the new probe to 'ap->list'. */
13341261
static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
13351262
{
@@ -1928,6 +1855,77 @@ static struct notifier_block kprobe_exceptions_nb = {
19281855
#ifdef CONFIG_KRETPROBES
19291856

19301857
#if !defined(CONFIG_KRETPROBE_ON_RETHOOK)
1858+
static void free_rp_inst_rcu(struct rcu_head *head)
1859+
{
1860+
struct kretprobe_instance *ri = container_of(head, struct kretprobe_instance, rcu);
1861+
1862+
if (refcount_dec_and_test(&ri->rph->ref))
1863+
kfree(ri->rph);
1864+
kfree(ri);
1865+
}
1866+
NOKPROBE_SYMBOL(free_rp_inst_rcu);
1867+
1868+
static void recycle_rp_inst(struct kretprobe_instance *ri)
1869+
{
1870+
struct kretprobe *rp = get_kretprobe(ri);
1871+
1872+
if (likely(rp))
1873+
freelist_add(&ri->freelist, &rp->freelist);
1874+
else
1875+
call_rcu(&ri->rcu, free_rp_inst_rcu);
1876+
}
1877+
NOKPROBE_SYMBOL(recycle_rp_inst);
1878+
1879+
/*
1880+
* This function is called from delayed_put_task_struct() when a task is
1881+
* dead and cleaned up to recycle any kretprobe instances associated with
1882+
* this task. These left over instances represent probed functions that
1883+
* have been called but will never return.
1884+
*/
1885+
void kprobe_flush_task(struct task_struct *tk)
1886+
{
1887+
struct kretprobe_instance *ri;
1888+
struct llist_node *node;
1889+
1890+
/* Early boot, not yet initialized. */
1891+
if (unlikely(!kprobes_initialized))
1892+
return;
1893+
1894+
kprobe_busy_begin();
1895+
1896+
node = __llist_del_all(&tk->kretprobe_instances);
1897+
while (node) {
1898+
ri = container_of(node, struct kretprobe_instance, llist);
1899+
node = node->next;
1900+
1901+
recycle_rp_inst(ri);
1902+
}
1903+
1904+
kprobe_busy_end();
1905+
}
1906+
NOKPROBE_SYMBOL(kprobe_flush_task);
1907+
1908+
static inline void free_rp_inst(struct kretprobe *rp)
1909+
{
1910+
struct kretprobe_instance *ri;
1911+
struct freelist_node *node;
1912+
int count = 0;
1913+
1914+
node = rp->freelist.head;
1915+
while (node) {
1916+
ri = container_of(node, struct kretprobe_instance, freelist);
1917+
node = node->next;
1918+
1919+
kfree(ri);
1920+
count++;
1921+
}
1922+
1923+
if (refcount_sub_and_test(count, &rp->rph->ref)) {
1924+
kfree(rp->rph);
1925+
rp->rph = NULL;
1926+
}
1927+
}
1928+
19311929
/* This assumes the 'tsk' is the current task or the is not running. */
19321930
static kprobe_opcode_t *__kretprobe_find_ret_addr(struct task_struct *tsk,
19331931
struct llist_node **cur)

0 commit comments

Comments
 (0)