From patchwork Wed May 9 21:07:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 911189 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=wand.net.nz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QBsqVHmJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40h87t4S7rz9s1w for ; Thu, 10 May 2018 07:07:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965670AbeEIVHh (ORCPT ); Wed, 9 May 2018 17:07:37 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:38386 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965458AbeEIVHd (ORCPT ); Wed, 9 May 2018 17:07:33 -0400 Received: by mail-oi0-f66.google.com with SMTP id k17-v6so32798280oih.5 for ; Wed, 09 May 2018 14:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=t8IY6P0fyXLfXaBhuEPqTRqONn3RW3m3CGEFv4gFuBA=; b=QBsqVHmJbcXTmNYSTL15BM+2xW8waYLgNmD00WSR8gJi99vQ663jDMxvLhT8XWHXIA aT3TN054KSvyWL/xB2EiBlZ+lsXOLF3nKsKmCatv8vHLEcga8eQiUjldKurEbeuB4en7 BCmFbu3tFB9MdwASK3mSXIV8VVlL04Bi9V4jy5eKVOPwC8G9YDUtB0BVokkfFBJoGuKW 3NOnmrFtzJlwhYk0Zoc4rl22rfM0B8WuZ+dOUXTH7UFzwUIJzGTSnd2g5lPPC9vlCFzv NjVtX+rHh7xkddbEOqU6taxUzcV1a0ZT0nwUCBYH8/r7c7eCFUViry9IBj22HQt587aw C7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=t8IY6P0fyXLfXaBhuEPqTRqONn3RW3m3CGEFv4gFuBA=; b=TO9EpUEmMw9RgKeq+xvF6nyRaqs1l9XSbFbxMMb3xNtMxxGp3s74aQNQao7KmoWGLv 9EmuR9kKOU7zp0kfNWuT52d5kvRlq0nkjzIbhLzLaIaETFCCN6Clm9DLZv03qxqsWxPd ZryDwKHMwowaxFK8h4rMEsVUGkVyZkVI/M7NLqauGmMLIOMDjP68U7RtMP4X7HNjn0MZ WWoSxLSWIcZ5tauY68mk0MEfNa+hajXzezUVXkF4EVSGzYV4IEtXPIn/i0Si9e9zh0GP plPnsY+J+cLOd1eXcFovwieHav9WPVuATKgMEnydSUXas2BRgJR8UmQywcVeKZ8LjWxJ MVJg== X-Gm-Message-State: ALQs6tCjD2GnEc6jgsGN/DXcGWT/53tReBCeQX3UUWvmwQdJSptNhoKL 3CTitAYocb5CAGwRVEce9sU= X-Google-Smtp-Source: AB8JxZogocsIxaRD4xGXC/c2zhp8ZJFzxFdnL43ybzcNG0tLM1rLnZ67xSD0WDFRQNUPw0p9IheAcQ== X-Received: by 2002:aca:a803:: with SMTP id r3-v6mr6410640oie.200.1525900052953; Wed, 09 May 2018 14:07:32 -0700 (PDT) Received: from allosaurus.lan ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id h125-v6sm13612921oic.54.2018.05.09.14.07.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 14:07:32 -0700 (PDT) From: Joe Stringer To: daniel@iogearbox.net Cc: netdev@vger.kernel.org, ast@kernel.org, john.fastabend@gmail.com, kafai@fb.com Subject: [RFC bpf-next 09/11] libbpf: Support loading individual progs Date: Wed, 9 May 2018 14:07:07 -0700 Message-Id: <20180509210709.7201-10-joe@wand.net.nz> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180509210709.7201-1-joe@wand.net.nz> References: <20180509210709.7201-1-joe@wand.net.nz> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Allow the individual program load to be invoked. This will help with testing, where a single ELF may contain several sections, some of which denote subprograms that are expected to fail verification, along with some which are expected to pass verification. By allowing programs to be iterated and individually loaded, each program can be independently checked against its expected verification result. Signed-off-by: Joe Stringer --- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7bcdca13083a..04e3754bcf30 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -268,7 +268,7 @@ struct bpf_object { }; #define obj_elf_valid(o) ((o)->efile.elf) -static void bpf_program__unload(struct bpf_program *prog) +void bpf_program__unload(struct bpf_program *prog) { int i; @@ -1338,7 +1338,7 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type, return ret; } -static int +int bpf_program__load(struct bpf_program *prog, char *license, u32 kern_version) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 197f9ce2248c..c07e9969e4ed 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -112,10 +112,13 @@ void *bpf_program__priv(struct bpf_program *prog); const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); +int bpf_program__load(struct bpf_program *prog, char *license, + u32 kern_version); int bpf_program__fd(struct bpf_program *prog); int bpf_program__pin_instance(struct bpf_program *prog, const char *path, int instance); int bpf_program__pin(struct bpf_program *prog, const char *path); +void bpf_program__unload(struct bpf_program *prog); struct bpf_insn;