Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5540357ybl; Tue, 14 Jan 2020 10:37:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwPVYku49TC/nHjPTepeIPx+fdYPceFFISlj8zOjlFwOWDU2hO85Qi5iVQniprR2E9iuAK2 X-Received: by 2002:aca:f484:: with SMTP id s126mr16849527oih.48.1579027069244; Tue, 14 Jan 2020 10:37:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579027069; cv=none; d=google.com; s=arc-20160816; b=msA5VtTlaruCBeV1YCW1ynd2y/hs4Oy3qsnArlwOA3dhz+IKdonIJbENmzUM4G0iLN XnApeL+WRUMJTRd3Fa8UiybefGFlA84hmSWFX0RCjTVzcKCQmA4pLLIqBAIZkFNSP8lw iOHLgsk2D5dM299RjE/ptnwSOkOE/CgPCptWhGCEDlO2O49iqULZVzkJml6WEUHsDJ+P QpqHaKVRUMFZ6heh+Z/nT29BiiWE5Z5YFohH9sRPkfxqbIGP0RWcENy1TFhtGj36yVdp dJhf9MNjMe4FjCJ5oUggOVPAznjGot2TQRLPtgQMLz1ADVnTiK+iSJD4NNonKGL5q/n5 iYOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=h0zBvJjpzgwK67F0RVeLSWa1LpfeS/py8/GHMZRGeeQ=; b=pECV5B6lbNul+iY2kT3r+/b/BJTp6eXGe+9FXy0KQmHKWErwc6L8a3xQAGKgv9mBJt aQbUa6oYVzkeYQy0gKpF7l87wxxChbCkB8/QWp4iYvxJWZSkI4O5wyblp0jvGbCttX2U Hije0gd5mK6FMpFJmcYbkH+CqRD9WSV8IXX/dN1FaXlLiST3s3YgcXidJ5NoZrhU7atm gvAEKJ+h/F5Pn/IbhJcCNbHvoPQBH/hno1s+Hpk2rVeHdihyrwOraAlIZNt7RPvQEQNi 01nFUmmDePnnjcBr0MqlXc6qUnNV9LxCh5LXxOxDTYT/SiW1P0VMEIDIi59bVlFehFLN rE1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LEUPaR4f; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a15si8800056otq.83.2020.01.14.10.37.38; Tue, 14 Jan 2020 10:37:49 -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=@gmail.com header.s=20161025 header.b=LEUPaR4f; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728757AbgANSgw (ORCPT + 99 others); Tue, 14 Jan 2020 13:36:52 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:44201 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbgANSgw (ORCPT ); Tue, 14 Jan 2020 13:36:52 -0500 Received: by mail-qt1-f194.google.com with SMTP id t3so13335342qtr.11; Tue, 14 Jan 2020 10:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h0zBvJjpzgwK67F0RVeLSWa1LpfeS/py8/GHMZRGeeQ=; b=LEUPaR4f1Z3WcSuOoq1PxBaZG1mAx+z3vRXwJlTT8EJCU24AOglgH5v/VdMHlbTvlg rORVQe1GNuxAZOCTWc6Fw6ks+RvUBb4pll4BVvmuLcu7DbMWYZ8R9fIFMKRevwx6WIrP ArX5im+jSYJ3Nrf+aZpVIOvXOYfxROh0YD1itotDirLNRcggdIvZEeP55NvCMMfkP61Y dPKI3MCZrLCJudy9go8quE4JAVGWXsFKOKLJD3wW7RZwCpOCEf5g7M4OwByiTekbYoc+ oT8gO8sUSmPHBMlE3yl4DPRjdd/N2kt4PXcOo8/leUm7Kgfo9/nZH+NyuwRSFA2hK8i3 5nvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h0zBvJjpzgwK67F0RVeLSWa1LpfeS/py8/GHMZRGeeQ=; b=qk5UTpQwkee4HRXTY6NmtGFV1jCYrbIwhv75XhYJqCCwP5IXdTBjPrX5Zx4G1sR1UH Kc7RRWNpt2BW/qFRt9jSqxPGSehj6xzQPBMpDLohe86LNm1SDSraUSt0vRc82zQAYAXq wTu6lLflp8nLFO9Vtk45V+jbULelradr78pxGojnAeOW2GWtKJO6zzvq7qJdSwi6evXh cfUKkz5HWlp+zyIXasuS1uDil34QjoLrg15QLV19TAMcB2WNCt0vuXDTK21P1PYAJDgE K7V6MnS0h+U91WnB86vGtKmVVa3QwIjLprkNYPMV1kF+MXeeSI29vizhD15iS7n7Q0VF FzNw== X-Gm-Message-State: APjAAAVy5MfNfMpLxZngTn5Uc28fMrwJif5ZXpngmPZ9uwK4VJPreLJw zEfhuvSuJUca0rUnGO2rTmJtqAlDdfG5YBSDcTg= X-Received: by 2002:ac8:4050:: with SMTP id j16mr4865708qtl.171.1579027011156; Tue, 14 Jan 2020 10:36:51 -0800 (PST) MIME-Version: 1.0 References: <20200114164614.47029-1-brianvv@google.com> <20200114164614.47029-9-brianvv@google.com> In-Reply-To: <20200114164614.47029-9-brianvv@google.com> From: Andrii Nakryiko Date: Tue, 14 Jan 2020 10:36:40 -0800 Message-ID: Subject: Re: [PATCH v4 bpf-next 7/9] libbpf: add libbpf support to batch ops To: Brian Vazquez Cc: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Yonghong Song , Stanislav Fomichev , Petar Penkov , Willem de Bruijn , open list , Networking , bpf 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 On Tue, Jan 14, 2020 at 8:46 AM Brian Vazquez wrote: > > 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 | 60 ++++++++++++++++++++++++++++++++++++++++ > tools/lib/bpf/bpf.h | 22 +++++++++++++++ > tools/lib/bpf/libbpf.map | 4 +++ > 3 files changed, 86 insertions(+) > > diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c > index 500afe478e94a..12ce8d275f7dc 100644 > --- a/tools/lib/bpf/bpf.c > +++ b/tools/lib/bpf/bpf.c > @@ -452,6 +452,66 @@ 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, > + const struct bpf_map_batch_opts *opts) > +{ > + union bpf_attr attr = {}; > + int ret; > + > + if (!OPTS_VALID(opts, bpf_map_batch_opts)) > + return -EINVAL; > + > + 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 = OPTS_GET(opts, elem_flags, 0); > + attr.batch.flags = OPTS_GET(opts, flags, 0); > + > + ret = sys_bpf(cmd, &attr, sizeof(attr)); > + if (count) > + *count = attr.batch.count; what if syscall failed, do you still want to assign *count then? > + > + return ret; > +} > + [...]