From patchwork Wed Sep 12 00:36:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 968783 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="ue1P/0p7"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 4292sv5nZdz9s3Z for ; Wed, 12 Sep 2018 10:37:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbeILFiy (ORCPT ); Wed, 12 Sep 2018 01:38:54 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:44928 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbeILFiy (ORCPT ); Wed, 12 Sep 2018 01:38:54 -0400 Received: by mail-oi0-f65.google.com with SMTP id l82-v6so277675oih.11 for ; Tue, 11 Sep 2018 17:37:04 -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=rvnurzXPfrwZHU0JSIR2o9TO71UK2OGUyq78QcrWRmM=; b=ue1P/0p7Qsuy96xLhOI15zOPB7Qv3GbQL4/wnq9s/RT8eUlAykJCJLsfJqEI7oLKSa 9dzZ8hoSB0n9/IdLfxcS9LHdDlT890jiB9PxFEsS7ypfBXM7fvjzrUSCD7CWZwAuY+f9 Qf1GREtmcfb3bSiSO6Vv2Dn6poVPRjai+szsO8HhYkBjWbWShX96THejeWhTPC3eYMZ5 uFXh5Zdw6rWRLf3+3NS5L2dG/+kI6t8amOW+hFeLW0e98wgtKQzP+K9DjG0lV6pyX9HY toKMJlAIB2W25v+nRFZK1W/uYlrl0gei9+KCrzbocLRu5g7eoXAdP+9LLmlN+/R98VdL qDmA== 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=rvnurzXPfrwZHU0JSIR2o9TO71UK2OGUyq78QcrWRmM=; b=bwGgyW9+eSjRA+mEq4MeJ7rP/s3jH0rP2246trvqm2E+wuUAl6u/TJBs1gKt8TfVft 2M5sBfYK12vkmzDnK1dEukoppjZVpPRdBLmQesq4K2JjV1moUdHVGmbyS/5q0s63jug8 DXFgzEvJLIOal7UOEuBLYImFXLY/EWBSFSFwYxAEWk43AtaohvQuG3Ur9Xs0URJ8XLHV Q0Vk5at6yJu5pvw7eLZCL8BZWO+M9bpe7NeESgC3i0LskxR/YjGifesSaaoFI6ve0tPm 6+sF1nbKuScWLkguCYjeOYlOcU6RanasTs7B54aH7/f+mnuw0HAQ2amUHXf/yoSAW0/F h+vg== X-Gm-Message-State: APzg51ACvjIhvTJIHR63aa86Gq1Z8fhIQetnT8CrHsFZZApwsB2dr6V6 ZAwKlZXzrvaQO3Sv2DfuGYA= X-Google-Smtp-Source: ANB0VdZWscVUak2b29ulevSjirKNYQU9j1ARZINK8CN3aGoqai+8cYTfmTF/KQ1T7ffv7R4yPHniWg== X-Received: by 2002:aca:90d:: with SMTP id 13-v6mr7080587oij.300.1536712624015; Tue, 11 Sep 2018 17:37:04 -0700 (PDT) Received: from allosaurus.lan ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id s145-v6sm39598850oih.16.2018.09.11.17.37.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 17:37:02 -0700 (PDT) From: Joe Stringer To: daniel@iogearbox.net Cc: netdev@vger.kernel.org, ast@kernel.org, john.fastabend@gmail.com, tgraf@suug.ch, kafai@fb.com, nitin.hande@gmail.com, mauricio.vasquez@polito.it Subject: [PATCH bpf-next 09/11] libbpf: Support loading individual progs Date: Tue, 11 Sep 2018 17:36:38 -0700 Message-Id: <20180912003640.28316-10-joe@wand.net.nz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180912003640.28316-1-joe@wand.net.nz> References: <20180912003640.28316-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 Acked-by: Alexei Starovoitov --- 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 8476da7f2720..aadf05f6bfa0 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -227,7 +227,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; @@ -1375,7 +1375,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 e3b00e23e181..40e4395f1c07 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -126,10 +126,13 @@ void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex); 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;