Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp93613ybl; Wed, 11 Dec 2019 14:36:40 -0800 (PST) X-Google-Smtp-Source: APXvYqx/JELPhFukuNL0Zj7LPH1oKHuWbkfS2EpEq4gFehw0uAJ9FCa/46BFkb5C3x1kFfwKLImg X-Received: by 2002:a9d:470a:: with SMTP id a10mr4517756otf.370.1576103800318; Wed, 11 Dec 2019 14:36:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576103800; cv=none; d=google.com; s=arc-20160816; b=cQqxWQxUrXWe7jmWPgWwz3M0uqG8IgQ5GQVP+uZveL9TtZWupXNv977xCYoA6QJd2Z WpOI6AlSu2sTw/e+Uj0dQceYQ0AnQop68OpVLrl8PuM6BAj/ZZ17VbcdbUdlYqrHZxCq 4UO1RewLe8dE4WeNciUvRLCyyNTZAXdKC/8CpZ1tvVmYUGxRvTXlO6bK4+JKFH71ZEpp YWzsHFgikHfveCtFV1l4aIH1yPzsgpwXjbOLfBR0OFbpZw/XT/HuRHIFYp2ladBrIOkY BbUoctqKImVVosoeRwcnfRV6/J4hsongFU+jJPE/2ejcQ/TrMrIsLsr5nIO6bunyHkyT goCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=lQpyK5Eg7lGx+o3sbDMKqWXZbBnjtobMbtVvJLV8vuU=; b=eln3Hq3fKlXmtOBTlfK2BDQoTUw1WENU1Qg4yG47sYzgR9hzKRbiWeHNoIey/RqLMG BZVwD0T9X2a59FvqZXbQlKZNRxotV8vkshxO/jcUI0DlW5tnxKQplV+p1Lzj07wYLY5a kwEfRlRr+EJ14bmeVtc7VOhEZAExIxu6i/xWt0+fUYyFu6ojif1IyrIsma5nxjdcBTby sPFaM92dTMw6tSwjutwEz2K4DU9A1nO2nsw9Z+YNisLXCqS9sjRfCU0awV1gxPZ8nTqz xnJsgMmXRJpFpKOp6LeFUGFqmqh7m2+tCQ6GnfV3E19qSgiRw16sHedmqIF51o/LAMhN J1sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=i6KUnPrg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18si2244982otj.114.2019.12.11.14.36.27; Wed, 11 Dec 2019 14:36:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=i6KUnPrg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbfLKWer (ORCPT + 99 others); Wed, 11 Dec 2019 17:34:47 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:54286 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727096AbfLKWeo (ORCPT ); Wed, 11 Dec 2019 17:34:44 -0500 Received: by mail-pl1-f201.google.com with SMTP id a11so182697plp.21 for ; Wed, 11 Dec 2019 14:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lQpyK5Eg7lGx+o3sbDMKqWXZbBnjtobMbtVvJLV8vuU=; b=i6KUnPrg8wS8fz1OC/0FVlYjiKjXkPYU2ZAHAZqB4Kmj5Oa3h1CHwnILOk3hE97Auq yTVD2FtQL7GPkCAp3bU5NTy5AAYCPRjxRRLnBeI7nrHwYzYOOTj5hxX+lTPOzSW0yLLK SHABMziL+UoyOWehbOiYQRz7zzcY9P1ItJLZXrx3cdiFnW3FTVtwlNks6rCnlF2VUCE4 LNZqp9hdmkSYTRSPO/w2VCySJAK+vOLKfFr23i8p3gnhRrz7uOAcro2a2YD1CvuwgUSj dZW9ZXNcOUTBFSKyA8yQMnip0xj9M07c7/NCe4rNhYTQF6k2aJ4BxRN0wbDu4xolfAaK qTTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lQpyK5Eg7lGx+o3sbDMKqWXZbBnjtobMbtVvJLV8vuU=; b=WENcEXGt4vJYAWqLbsTI1jFMLCUvPs3+6ccT/la9kXX0rxrUXPp2T4I+94M+nfkNxj CU3fc3xjqQ+2RWew2hFe7KeKnZMbX3leG+tGXqtJGdkxiaOQU4fSLi+d0v2jqHWvo6gK 2rxAmB+fj82474FTCnYaOkRVLz9Df+9QUg2ufgw6aH3DQvoXkGdVU74jvIQvKyVnzNUs RQsZrZ+JEArO5WfHr1I+l+MqDXkp2zsSBSOd5UhUfOsmPBg4sMIkX8W45MFv/8AktXnH ze5+CXgH7PB0zwXwiB08mvw5ZNDgOpHPX04N9ud86xrejkct0J7prANLzHMr0dFcREtC VVVg== X-Gm-Message-State: APjAAAUyumSNp2vczbXlCDeHZVVeyMCbo+JlqCxajjSLTSVs4J6K8i2B GaG4fnQ5uH9BJ49M9WSdi6DUM/QXLEQO X-Received: by 2002:a63:197:: with SMTP id 145mr6915703pgb.11.1576103683551; Wed, 11 Dec 2019 14:34:43 -0800 (PST) Date: Wed, 11 Dec 2019 14:33:41 -0800 In-Reply-To: <20191211223344.165549-1-brianvv@google.com> Message-Id: <20191211223344.165549-9-brianvv@google.com> Mime-Version: 1.0 References: <20191211223344.165549-1-brianvv@google.com> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog Subject: [PATCH v3 bpf-next 08/11] libbpf: add libbpf support to batch ops From: Brian Vazquez To: Brian Vazquez , Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: Yonghong Song , Stanislav Fomichev , Petar Penkov , Willem de Bruijn , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yonghong Song Added four libbpf API functions to support map batch operations: . int bpf_map_delete_batch( ... ) . int bpf_map_lookup_batch( ... ) . int bpf_map_lookup_and_delete_batch( ... ) . int bpf_map_update_batch( ... ) Signed-off-by: Yonghong Song --- tools/lib/bpf/bpf.c | 61 ++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/bpf.h | 14 +++++++++ tools/lib/bpf/libbpf.map | 4 +++ 3 files changed, 79 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 98596e15390fb..933a36a33d5a0 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -443,6 +443,67 @@ int bpf_map_freeze(int fd) return sys_bpf(BPF_MAP_FREEZE, &attr, sizeof(attr)); } +static int bpf_map_batch_common(int cmd, int fd, void *in_batch, + void *out_batch, void *keys, void *values, + __u32 *count, __u64 elem_flags, + __u64 flags) +{ + union bpf_attr attr = {}; + int ret; + + memset(&attr, 0, sizeof(attr)); + attr.batch.map_fd = fd; + attr.batch.in_batch = ptr_to_u64(in_batch); + attr.batch.out_batch = ptr_to_u64(out_batch); + attr.batch.keys = ptr_to_u64(keys); + attr.batch.values = ptr_to_u64(values); + if (count) + attr.batch.count = *count; + attr.batch.elem_flags = elem_flags; + attr.batch.flags = flags; + + ret = sys_bpf(cmd, &attr, sizeof(attr)); + if (count) + *count = attr.batch.count; + + return ret; +} + +int bpf_map_delete_batch(int fd, void *keys, __u32 *count, + __u64 elem_flags, __u64 flags) +{ + return bpf_map_batch_common(BPF_MAP_DELETE_BATCH, fd, NULL, + NULL, keys, NULL, count, + elem_flags, flags); +} + +int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch, void *keys, + void *values, __u32 *count, + __u64 elem_flags, __u64 flags) +{ + return bpf_map_batch_common(BPF_MAP_LOOKUP_BATCH, fd, in_batch, + out_batch, keys, values, count, + elem_flags, flags); +} + +int bpf_map_lookup_and_delete_batch(int fd, void *in_batch, void *out_batch, + void *keys, void *values, + __u32 *count, __u64 elem_flags, + __u64 flags) +{ + return bpf_map_batch_common(BPF_MAP_LOOKUP_AND_DELETE_BATCH, + fd, in_batch, out_batch, keys, values, + count, elem_flags, flags); +} + +int bpf_map_update_batch(int fd, void *keys, void *values, __u32 *count, + __u64 elem_flags, __u64 flags) +{ + return bpf_map_batch_common(BPF_MAP_UPDATE_BATCH, + fd, NULL, NULL, keys, values, + count, elem_flags, flags); +} + int bpf_obj_pin(int fd, const char *pathname) { union bpf_attr attr; diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 3c791fa8e68e8..51c577393ec48 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -126,6 +126,20 @@ LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key, LIBBPF_API int bpf_map_delete_elem(int fd, const void *key); LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key); LIBBPF_API int bpf_map_freeze(int fd); +LIBBPF_API int bpf_map_delete_batch(int fd, void *keys, + __u32 *count, __u64 elem_flags, + __u64 flags); +LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch, + void *keys, void *values, __u32 *count, + __u64 elem_flags, __u64 flags); +LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch, + void *out_batch, void *keys, + void *values, __u32 *count, + __u64 elem_flags, __u64 flags); +LIBBPF_API int bpf_map_update_batch(int fd, void *keys, void *values, + __u32 *count, __u64 elem_flags, + __u64 flags); + LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); LIBBPF_API int bpf_obj_get(const char *pathname); LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd, diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 495df575f87f8..4efbf25888eb0 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -210,4 +210,8 @@ LIBBPF_0.0.6 { } LIBBPF_0.0.5; LIBBPF_0.0.7 { + bpf_map_delete_batch; + bpf_map_lookup_and_delete_batch; + bpf_map_lookup_batch; + bpf_map_update_batch; } LIBBPF_0.0.6; -- 2.24.1.735.g03f4e72817-goog