From patchwork Tue Nov 20 00:06:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikita V. Shirokov" X-Patchwork-Id: 1000197 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=tehnerd.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tehnerd-com.20150623.gappssmtp.com header.i=@tehnerd-com.20150623.gappssmtp.com header.b="SkwShB9e"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42zQxQ5nD2z9s6w for ; Tue, 20 Nov 2018 11:07:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732226AbeKTKdR (ORCPT ); Tue, 20 Nov 2018 05:33:17 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:52165 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbeKTKdQ (ORCPT ); Tue, 20 Nov 2018 05:33:16 -0500 Received: by mail-it1-f194.google.com with SMTP id x19so857685itl.1 for ; Mon, 19 Nov 2018 16:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tehnerd-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4/+PXiaQ86RH/wh5BAVUvSEW0nBbN4uWGmJXJuWYk/Y=; b=SkwShB9eCe0P7ZuCynwAcwUg/3LpYv8AqjlynpGroDtocqJajz3QlgTzOEaYOjayRY b0I/x1q4kWacr5fBKOrXEps2OchKES9MjBZmfk3Nvxj9kCOdl5q57Yef5hkIpyHbMjUL hJgNP2qUM/cRUoE03jOqYX6oSOUl7Pcu6Wzz/JQPQfXFb+HqgvKQD+ZxGqiQkIv8ElUi eHtnlwharor+KoW7S14UwpDMvp+PhgTuMGp6knFh0mkjjclZrY0uw7lvjayF0+I+p7KF XLnVtmHaTEUF4SCG7dzxa4FQUfZjPovI3cztZcxq0QTV32sDsBEBbiQAQw1yo2gExIRr iiQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4/+PXiaQ86RH/wh5BAVUvSEW0nBbN4uWGmJXJuWYk/Y=; b=sxIdj22Ha9jH9H71Xzq4xY4m6SooHCKeh4OdMIlGVxiSOIz/bO/RQslAWE6L3eH+th dzyBo+f7MH1EDrHig8vWiiQxR5RtYsAwUBDfEhrFIPvh0PD8cmtU5O6wkPYZR6ttQlTI eb00IGF34cv73rTDVutPPS9Nf5x0jB8kFHka69IMuAxMlfC6gTE3iLcZBFwwG9d15/fb 8X9EgVKpu9EzwjKg/jDyjZru4ks+TBSD0L96FPq5vmemKnG28dQD8GTwGz1mIRgG3IHu VWPn1jhKPYLPOrbVOASXZpfIuF8cdPm/lvMDqtd/D0wrJXdn2S0SWiue08T8eOf8Ikxp LsKA== X-Gm-Message-State: AA+aEWbLvUCG3bU0ILtPSOUrfEpPIA5mjZekr26f1eDWmVA64/A0rjIS uPyhRDkh1xPeCFfRhooI0YnIIg== X-Google-Smtp-Source: AFSGD/Uiki3LgDsBq1T4HZ+OnoB9DO53N5ccsqkjuaWlFBZLPNciXPi6AJ0ARh0kmGmIbV/XAkY6pw== X-Received: by 2002:a24:b518:: with SMTP id v24mr245080ite.159.1542672424122; Mon, 19 Nov 2018 16:07:04 -0800 (PST) Received: from maindev.thefacebook.com ([199.201.64.131]) by smtp.gmail.com with ESMTPSA id 186-v6sm15201588itl.23.2018.11.19.16.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 16:07:03 -0800 (PST) From: "Nikita V. Shirokov" To: Alexei Starovoitov , Daniel Borkmann , Jakub Kicinski Cc: netdev@vger.kernel.org, "Nikita V. Shirokov" Subject: [PATCH bpf-next 1/2] bpf: adding support for map in map in libbpf Date: Mon, 19 Nov 2018 16:06:25 -0800 Message-Id: <20181120000626.16825-2-tehnerd@tehnerd.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20181120000626.16825-1-tehnerd@tehnerd.com> References: <20181120000626.16825-1-tehnerd@tehnerd.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org idea is pretty simple. for specified map (pointed by struct bpf_map) we would provide descriptor of already loaded map, which is going to be used as a prototype for inner map. proposed workflow: 1) open bpf's object (bpf_object__open) 2) create bpf's map which is going to be used as a prototype 3) find (by name) map-in-map which you want to load and update w/ descriptor of inner map w/ a new helper from this patch 4) load bpf program w/ bpf_object__load inner_map_fd is ignored by any other maps asidef from (hash|array) of maps Signed-off-by: Nikita V. Shirokov --- tools/lib/bpf/libbpf.c | 7 +++++++ tools/lib/bpf/libbpf.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index a01eb9584e52..a2ee1b1a93b6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -163,6 +163,7 @@ struct bpf_map { char *name; size_t offset; int map_ifindex; + int inner_map_fd; struct bpf_map_def def; __u32 btf_key_type_id; __u32 btf_value_type_id; @@ -1146,6 +1147,7 @@ bpf_object__create_maps(struct bpf_object *obj) create_attr.btf_fd = 0; create_attr.btf_key_type_id = 0; create_attr.btf_value_type_id = 0; + create_attr.inner_map_fd = map->inner_map_fd; if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) { create_attr.btf_fd = btf__fd(obj->btf); @@ -2562,6 +2564,11 @@ void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex) map->map_ifindex = ifindex; } +void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd) +{ + map->inner_map_fd = fd; +} + static struct bpf_map * __bpf_map__iter(struct bpf_map *m, struct bpf_object *obj, int i) { diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index b1686a787102..7cb00cd41789 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -293,6 +293,8 @@ LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path); +LIBBPF_API void bpf_map__add_inner_map_fd(struct bpf_map *map, const int fd); + LIBBPF_API long libbpf_get_error(const void *ptr); struct bpf_prog_load_attr {