From patchwork Wed Apr 26 18:24:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Frederic Sowa X-Patchwork-Id: 755591 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wCpQp486dz9s8W for ; Thu, 27 Apr 2017 04:25:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=stressinduktion.org header.i=@stressinduktion.org header.b="XUzRTcZR"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="RI4K024A"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933528AbdDZSZD (ORCPT ); Wed, 26 Apr 2017 14:25:03 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:48037 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933328AbdDZSYz (ORCPT ); Wed, 26 Apr 2017 14:24:55 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 8E2F321D0F; Wed, 26 Apr 2017 14:24:44 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Wed, 26 Apr 2017 14:24:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= stressinduktion.org; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=FK61aj9fVOiYzpyUGrqYG4HxbD4K1kQId11RpcVcs 9Q=; b=XUzRTcZRFI5SvZ6OD1DhpDRN7+d9daTwStFxpWxaDByUDjKYC3OyizCzL rMeqpofKeyqUoFoOQUKxG7NlgkXhlkpVNq1yW269vCyMCljZ/rvCAsqtGK6YJcxV wG+sXEHB8tJwt/EbeRsRFU2nfL1q6XM21GF/V4eT1yLLd4qyvQsa7MGakGdy87Nn yayTCLHmBH5dH3NJth0iJLolGnO+oWylpgka2phlG5Y+M6XZ3JwVHnu+UtAAtiIt U5/cajTDDrxrD+wZdPiVFJnuq7inDP5Fier7EAkoJ/fr1EN/mI2Xi8boi/AwXIzI PQ7rZ13MVU6Dq0pjpfNaLFnWLrwiQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=FK61aj9fVOiYzpyUGrqYG4HxbD4K1kQId11RpcVcs 9Q=; b=RI4K024AHfCBMj/ToD6K+Wo7ELal09gfbWWy1eVYvgzhyCPb00rTwD0rI GqWGHTkHQmsstgfmi7L7N91i5pwNzynv3QH4a1jKdHHOMUaYKAD+Dh2Q0n69zfbW umlJkDxavrLENeHKC+y8604awbJyEWiFvmtrfTYO23cZrO+8ulxo970dGu9noRKS /MOmx1Gb+Zso3L3Nob/yDlD4eMZtKJh+/pHUJzsypP6HRp96a0Ib5svdnE6/WwEC XA2zj2m1DRjwfDwm9Fneq721JUweF52zbPoT0z7apNGm57gEeDJCuwEhinRVroOR YwopsoDIux+OaQLiXx/N6RqMHxq9A== X-ME-Sender: X-Sasl-enc: 9AIAo2dCTqFV6y7DbV1b1vQ9+swLTVT3MLvEl6mHcaS7 1493231083 Received: from m.localhost.localhost (unknown [213.55.211.100]) by mail.messagingengine.com (Postfix) with ESMTPA id 901DA7E0A4; Wed, 26 Apr 2017 14:24:42 -0400 (EDT) From: Hannes Frederic Sowa To: netdev@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.com, jbenc@redhat.com, aconole@bytheb.org Subject: [PATCH net-next 5/6] bpf: add skeleton for procfs printing of bpf_progs Date: Wed, 26 Apr 2017 20:24:18 +0200 Message-Id: <20170426182419.14574-6-hannes@stressinduktion.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170426182419.14574-1-hannes@stressinduktion.org> References: <20170426182419.14574-1-hannes@stressinduktion.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Hannes Frederic Sowa --- kernel/bpf/core.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 048e2d79718a16..3ba175a24e971a 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -32,6 +32,9 @@ #include #include +#include +#include + #include /* Registers */ @@ -488,6 +491,93 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type, return ret; } +/* ebpf procfs implementation */ + +static struct proc_dir_entry *ebpf_proc_dir; + +static void *ebpf_proc_start(struct seq_file *s, loff_t *pos) + __acquires(RCU_BH) +{ + struct bpf_prog_aux *aux; + loff_t off = 0; + + rcu_read_lock(); + + if (*pos == 0) + return SEQ_START_TOKEN; + + list_for_each_entry_rcu(aux, &bpf_progs, bpf_progs_head) + if (++off == *pos) + return aux; + + return NULL; +} + +static void *ebpf_proc_next(struct seq_file *s, void *v, loff_t *pos) +{ + struct bpf_prog_aux *aux; + + ++*pos; + + if (v == SEQ_START_TOKEN) + return list_first_or_null_rcu(&bpf_progs, struct bpf_prog_aux, + bpf_progs_head); + + aux = v; + return list_next_or_null_rcu(&bpf_progs, + &aux->bpf_progs_head, + struct bpf_prog_aux, + bpf_progs_head); +} + +static void ebpf_proc_stop(struct seq_file *s, void *v) + __releases(RCU_BH) +{ + rcu_read_unlock(); +} + +static int ebpf_proc_show(struct seq_file *s, void *v) +{ + if (v == SEQ_START_TOKEN) { + seq_printf(s, "# tag\n"); + return 0; + } + + return 0; +} + +static const struct seq_operations ebpf_seq_ops = { + .start = ebpf_proc_start, + .next = ebpf_proc_next, + .stop = ebpf_proc_stop, + .show = ebpf_proc_show, +}; + +static int ebpf_proc_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &ebpf_seq_ops); +} + +static const struct file_operations ebpf_proc_operations = { + .open = ebpf_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +static int __init ebpf_proc_init(void) +{ + ebpf_proc_dir = proc_mkdir("bpf", NULL); + if (!ebpf_proc_dir) + return 0; + proc_create("programs", 0400, ebpf_proc_dir, &ebpf_proc_operations); + return 0; +} + +device_initcall(ebpf_proc_init); + +/* end of bpf proc inmplementation */ + struct bpf_binary_header * bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, unsigned int alignment,