Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5555736ybl; Tue, 14 Jan 2020 10:55:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwfB916CIHgrrwvxNEIDZqPtCYeQdAYmpzgqHT2TzSSv5prM3xW0ZgAvlKh+SXgWqy6H8K7 X-Received: by 2002:a05:6808:3c2:: with SMTP id o2mr18204781oie.145.1579028113704; Tue, 14 Jan 2020 10:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579028113; cv=none; d=google.com; s=arc-20160816; b=Xu4NykyEJcTkYduYpjLO9U7NH146qCW2Sji94EZmv/R0V7L6Xmax+FL4yd6PToPs2g 2xw+9aAWjfAeWG7bOrZjUoYrUcy02B38N5EtPHD62P3R1vCLxuUO4hMK06KtWw9LBomE laJhEaX84+vYPO41I2U1RGBVzvtwmQ2mz1AomFWqTmgx/mEZ0n2h2Hn0mZea/OZizytr MT2Qdv1N4VfNOdyEKwXU59rZGYqZSEtKimMLfcfhB7xRFw5v7vLSSLHkzMrl2G7eaR4R ZMCRuP+KkirAOqDqwH2r4ZjBXGQdSYJmpXWWY1YHczQFx/BXOEgt8EEi/MYpiZDR+Rla I/eg== 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=FR9lhCYEbw12H0zeobUybUOQGm2CoSvzvFRxTVTYgPU=; b=PhO0buhHvMkQCQcp1XgFEEjBHd3JkhetYLIOqm1+vd/5NiUTg7YDDbKuykjArKvB+V KVjmh/DO1fxUAjyqH64Az1EjrCtmqDRWh535FdT4QfdJnniKwZKMHTjkENjMXvt931Id pUE1BJleVGcqGNH2zKgO/du8ZGIrhdkDvwhziEFyDgmRNTlMdNg7ypPOP7JNQsfVG4q0 rDQ3D4D6FQ92oWP40d+/0RrjIAreRITfuXc+xiOTUm+lTLlXnDfEOaAqrbq/ktx/M0V1 4JGiMO+5d6jLonV5kHO4P8HrFnqk7jqCeiiQgfAlfjKXlhdjlcgSwjckxZVAc8/dJc3y xYJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sWhN4A1j; 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 38si9634032otj.136.2020.01.14.10.55.02; Tue, 14 Jan 2020 10:55:13 -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=sWhN4A1j; 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 S1728777AbgANSyB (ORCPT + 99 others); Tue, 14 Jan 2020 13:54:01 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:45828 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgANSyB (ORCPT ); Tue, 14 Jan 2020 13:54:01 -0500 Received: by mail-qk1-f194.google.com with SMTP id x1so13109547qkl.12 for ; Tue, 14 Jan 2020 10:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FR9lhCYEbw12H0zeobUybUOQGm2CoSvzvFRxTVTYgPU=; b=sWhN4A1jJF4zgCnuuE5MvnlwpdRSGb5ico9T3aDZ5KVbTDha/ZNXBr4OzGPVv1W4u4 tPz+4LZCRuC6dGCMw/qdT5wxChox1sGnbGmwwTuiFG3KCWEf+YaHUwD/1PI5a3HlFCeK dvl/mvQmsKoIpfv803qf8biN8MP72s0uuFWGQzKc1cIo/52Mi1EhgtZjOSY0IqwtVETi Z0HU5wvFqcUxXEaOHTQoqOU9fZis1x2p3ayPvgs4iN8elUrp9k7n8eCn4BpmRnA/z7wb 0vXLk0ZbZwDBTr4NrkKE83d4lE1ythYkAgjmMIw17D/rAwUOk26JkBQL+c0+czvy79Xw 1FNQ== 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=FR9lhCYEbw12H0zeobUybUOQGm2CoSvzvFRxTVTYgPU=; b=g55J/9uDskRSrTohKstJOH455e17ESFbFvOlNL8qYRzDWaV5O5lgqrhFds3XnpUmo3 o2h+P8EvihxRyRXeE69ixF/MVejBx4b0QCqrmT3/oCGm4AYgC73TqZ/QYfzFoctvzhfm eG5nYp8ZnmQwUItLoLps/z3PC+WgMBqr2h3PlBFoA8NL9pV+pLVaFkCRgLMrd4ssSWAq oosHA5DKwPPzwMJGw+8mzCuwwRdq+0lSjw78ylnGP2p75gsMufYtSxnsbSz20MTyGKm3 do6UgAF6Yhxo2/CgG4ljQMKXFAEk6kgpEd67azBiMPkByoL15D0FENS4ipfeuFEYJlXR rk7g== X-Gm-Message-State: APjAAAXB8rL1JhU5+vQVd+ONKc3rd9xgiihDWMcHGQTqPNKaoz4EWEia b0fU1oY8TeHMxh+WqDX+FV4j3/RvRq/cky0B8FkVuQ== X-Received: by 2002:a05:620a:997:: with SMTP id x23mr18899493qkx.143.1579028040132; Tue, 14 Jan 2020 10:54:00 -0800 (PST) MIME-Version: 1.0 References: <20200114164614.47029-1-brianvv@google.com> <20200114164614.47029-9-brianvv@google.com> In-Reply-To: From: Brian Vazquez Date: Tue, 14 Jan 2020 10:53:48 -0800 Message-ID: Subject: Re: [PATCH v4 bpf-next 7/9] libbpf: add libbpf support to batch ops To: Andrii Nakryiko 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 10:36 AM Andrii Nakryiko wrote: > > 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? Hi Andrii, thanks for taking a look. attr.batch.count should report the number of entries correctly processed before finding and error, an example could be when you provided a buffer for 3 entries and the map only has 1, ret is going to be -ENOENT meaning that you traversed the map and you still want to assign *count. That being said, the condition 'if (count)' is wrong and I think it should be removed. > > > + > > + return ret; > > +} > > + > > [...]