Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp927388ybc; Tue, 19 Nov 2019 11:32:37 -0800 (PST) X-Google-Smtp-Source: APXvYqz3L9RIasuQQOyqGHekOzAHmcdgarRP+vB+3QKFfY+NMrn89sYjTvBOQ/i8ZCJnGa2yonBV X-Received: by 2002:a17:906:a457:: with SMTP id cb23mr36605348ejb.191.1574191957636; Tue, 19 Nov 2019 11:32:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574191957; cv=none; d=google.com; s=arc-20160816; b=PuJ33s6prCOnWFyptc4LCdudW9KxdFnfx3vKgEwve3JoF/gzsEBDKfSabRncCFG/7W wWYCLx42aEI+IBBVMheSbAfj+nbipjDQykmc4DcnzM0W1d5LlJs/5riwNLqaVpyfT1Ss +nM7TeKr+7QMoA/fJeE61OT5e52SfBDE7SqhFVIqZAz+xwEyCzLBBKVoMKjQkJb/0VNG 5i88bPPSLJlQMPGebSm8qLUzqBN/sAmjhJJq1DpO0KB+OUdUVevMesV1OlJNAGYu3mxo CVSn8ldHAFaoUFdUNSkdGkCwBj8t2Cad4zqQI6vp4vsHuzy5EcrnIgUaQtv+Bs6KSrVG nyJQ== 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=+lN+OnV/OGJwrxgrmDkzu2oxVw2ucT8UYsYGvvebriE=; b=LGg/tyRVSok89bfCfU3s1pMwsZbTnb/RuQFQzUsVvxIVJyMWgIPrR1/QSRez4BKO3P N3/UkFwJAQ4NMYLq92COzuGwaAxVfvB35xc4k8M3x+LXRPYzdXph54rJyP5Jeol/1D4R usgYnHdUHJtQa1Wgkm/p3LCVmen2JCYxCZlM1SEHsqem9CbtKSdmNP+6eoVYOwzlpNnd Uotd3JQoea2uzjVXL1YyMDIi/MUKP0vMhBaZEcWKeAMirZlwlXCW2G9wOARucri5/fta 7RiN8jNXPueRgi2kCBwtjhazHE7xfo/ksqGzwcYrbw/uKKTdgg/6sEy+vWHfxRI0siMW nGKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NM4XR6WW; 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 q2si14553447eju.229.2019.11.19.11.32.13; Tue, 19 Nov 2019 11:32:37 -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=NM4XR6WW; 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 S1727556AbfKSTbE (ORCPT + 99 others); Tue, 19 Nov 2019 14:31:04 -0500 Received: from mail-qk1-f202.google.com ([209.85.222.202]:51092 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727512AbfKSTbC (ORCPT ); Tue, 19 Nov 2019 14:31:02 -0500 Received: by mail-qk1-f202.google.com with SMTP id a13so14228236qkc.17 for ; Tue, 19 Nov 2019 11:31:01 -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=+lN+OnV/OGJwrxgrmDkzu2oxVw2ucT8UYsYGvvebriE=; b=NM4XR6WWNRFmctuup2sP4jTFMScoszHL0nwBVfSPrvc1hbAKi1GXF75Ngf634ArcMF llrHQtDYx0UjImSHtxD2z9RK5M1KdBOeTVIsUWTIJZXbSmvem3sEHxWz27I1vig7o6ea VGrW2X6jeyynS7LkI/0IcRJpnIfRUR4qZujUzTbdeLb89zD+6oS12LzXAzEpLIILR9fo fBWk7Uc1JfRL5AB5szAXP4ag4PvOx7nIIniJVo83+U4X9Pvu9tfMRx58vTGi1A6wFJC6 a9JFAzmx8xpL+V+rgG6cNcLTHH/03nuozbgzj1cmsV7swyn/p39g2aO7cSkrinAK3ope Y4Xg== 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=+lN+OnV/OGJwrxgrmDkzu2oxVw2ucT8UYsYGvvebriE=; b=EnyEI9aRcclFJeTf9wgc7PTbSlH0YNrv0T7MCWdVMsXL+JkGzTakbBrxNTCP/mKy3/ ULpNJVn2fQGu+znB6NMhAY90N9VbDmnk/x8lKFuWVDGLG7+eycr8K6YE//Q7DVPJEEZv uI/bMJ2AcU7U3YjYL2OotZWzz4zGDsPKfmo7YhjnYuEV+vkjpY7dR3NlGbtpFFbTBraH 16Y3Fqq1/3BJzsushOOqrFtgjqzO6rmo0ILv6jdxLcL+bDrDKEA8Ss8PytNjlDc7Rgmb Qhv9TWtyvgTqSqfJbL3Yt40/o96ZJh0Hjy6kRfYHaXfHDuAgD6ILPTJRfVqtFDiYbOXC /+ow== X-Gm-Message-State: APjAAAWuZEH8b9Op6N8W0NoYKeWXnvrkXEVMrxQh3xMFjUUfY/5dOvnM yza1mptKM4UdVkdxWc68V/bVGygRqNmn X-Received: by 2002:ac8:783:: with SMTP id l3mr34181632qth.257.1574191861009; Tue, 19 Nov 2019 11:31:01 -0800 (PST) Date: Tue, 19 Nov 2019 11:30:34 -0800 In-Reply-To: <20191119193036.92831-1-brianvv@google.com> Message-Id: <20191119193036.92831-8-brianvv@google.com> Mime-Version: 1.0 References: <20191119193036.92831-1-brianvv@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH v2 bpf-next 7/9] libbpf: add libbpf support to batch ops From: Brian Vazquez To: 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..9acd9309b47b3 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 *in_batch, void *out_batch, __u32 *count, + __u64 elem_flags, __u64 flags) +{ + return bpf_map_batch_common(BPF_MAP_DELETE_BATCH, fd, in_batch, + out_batch, NULL, 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..3ec63384400f1 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 *in_batch, void *out_batch, + __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 8ddc2c40e482d..56462fea66f74 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -207,4 +207,8 @@ LIBBPF_0.0.6 { bpf_program__size; btf__find_by_name_kind; libbpf_find_vmlinux_btf_id; + bpf_map_delete_batch; + bpf_map_lookup_and_delete_batch; + bpf_map_lookup_batch; + bpf_map_update_batch; } LIBBPF_0.0.5; -- 2.24.0.432.g9d3f5f5b63-goog