From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755297AbbCBQFN (ORCPT ); Mon, 2 Mar 2015 11:05:13 -0500 Received: from mga02.intel.com ([134.134.136.20]:4200 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754954AbbCBQBw (ORCPT ); Mon, 2 Mar 2015 11:01:52 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,676,1418112000"; d="scan'208";a="461370916" From: Tom Zanussi To: rostedt@goodmis.org Cc: masami.hiramatsu.pt@hitachi.com, namhyung@kernel.org, andi@firstfloor.org, ast@plumgrid.com, linux-kernel@vger.kernel.org, Tom Zanussi Subject: [PATCH 10/15] bpf: Make tracing_map use kmalloc/kfree_notrace() Date: Mon, 2 Mar 2015 10:01:03 -0600 Message-Id: <4f981027146713e6f31ef3c12375658c9e76c317.1425310176.git.tom.zanussi@linux.intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to prevent any kmallocs that could be invoked from within a tracepoint handler from being traced, in order to prevent recursion. For tracing maps, this means the allocation of the map elements (maps themselves along with their associated buckets, etc, are never allocated in the context of a tracepoint handler, so we don't need to worry about them). We also want the matching kfrees to remain untraced as well. With this, we should be able to use maps when tracing kmalloc, which otherwise would lock up the machine. Signed-off-by: Tom Zanussi --- kernel/bpf/hashtab.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 6f349ad..308ef47 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -200,6 +200,15 @@ find_first_elem: return -ENOENT; } +/* Use this instead of kfree_rcu() for notrace-kfreeing + * kmalloc_notrace()'d elements, to avoid creating a + * kfree_rcu_notrace() */ +static void kfree_htab_elem(struct rcu_head *head) +{ + struct htab_elem *elem = container_of(head, struct htab_elem, rcu); + kfree_notrace(elem); +} + /* Called from syscall or from eBPF program */ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags) @@ -218,7 +227,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, WARN_ON_ONCE(!rcu_read_lock_held()); /* allocate new element outside of lock */ - l_new = kmalloc(htab->elem_size, GFP_ATOMIC); + l_new = kmalloc_notrace(htab->elem_size, GFP_ATOMIC); if (!l_new) return -ENOMEM; @@ -262,7 +271,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, hlist_add_head_rcu(&l_new->hash_node, head); if (l_old) { hlist_del_rcu(&l_old->hash_node); - kfree_rcu(l_old, rcu); + call_rcu(&l_old->rcu, kfree_htab_elem); } else { htab->count++; } @@ -271,7 +280,7 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, return 0; err: spin_unlock_irqrestore(&htab->lock, flags); - kfree(l_new); + kfree_notrace(l_new); return ret; } @@ -311,7 +320,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key) free_client_elem(htab, l); hlist_del_rcu(&l->hash_node); htab->count--; - kfree_rcu(l, rcu); + call_rcu(&l->rcu, kfree_htab_elem); ret = 0; } @@ -332,7 +341,7 @@ static void delete_all_elements(struct bpf_htab *htab) free_client_elem(htab, l); hlist_del_rcu(&l->hash_node); htab->count--; - kfree(l); + kfree_notrace(l); } } } -- 1.9.3