Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5576153ybl; Tue, 14 Jan 2020 11:14:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxMb5FQSGz/Ab8T+gG3JZgjHEqLfZL13MxopfmmtNZOgQFzAKjNyTj6C+jMuF3VWMFSR0Hc X-Received: by 2002:aca:cdd6:: with SMTP id d205mr17305820oig.90.1579029299198; Tue, 14 Jan 2020 11:14:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579029299; cv=none; d=google.com; s=arc-20160816; b=P5fMpy6IP0jT/O2WRbuT4mrgDkdRuAwK/QBM2JjOYPu5iw8y8lpmD62AY4EI6O59qH wsVjjYc9FgZnP8P5mv9z1Rs12ZQY2SrFajIsSWKDvYXYB3sVM0zrWkO/lkbcMhdiCux4 thcdbL5y8Xi7eHpyoFPvtQ9fJVHPBe5GhARXXdwuW5mEDX3XCtSHW5m4YC92hLsdkrCM Gf1+dnsdxy9ksRsdSjAO9Odi4J2TlM7R0MtnI8iq1CyP/ztBHY+Avcw/YOAEFYr9yDtV +c9DM0ReFt0IFWn/U0IL81zgvT5n/SwkrDgga+eZ6A18RXo6BRGIw6YVxDBU6QKLLuaY Wh/A== 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=MFqB+06rBeER++BRySglojh7CJB3/vJLed3nR17srZY=; b=m/Fe1S+yevxQ26GYEk+NExipUOeEtUPePGMEzzVEWu6gE4UXTKS+pyDgYLf5pJeLvw /L2c8oxOxTIvqJSRfkG7evk8miVRk8c3hk/sf7NSjYi4PImbDAh9rXlgks/F/+stJMux ysRYV6cdXYHeLLo/NJ2Hg7qCYOCSrNLZtwnc0LljTpQ0a5718HjkiUskrKI7KsjKqwQf PysYfLgLIkxiQFgHJssUxamb8NdNQGpdjJDeXsDaJQk8oElzuC6a6U6xrWD5rk/CcfZ6 /9QUeZbbYl3s2s0hPlIsVA/8cc3myq9xP9N+0t/LOTTzlvB1y/7QYQlzgRdRRoAFEkF4 3YqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cr1uy4rA; 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 m24si8746090otn.67.2020.01.14.11.14.47; Tue, 14 Jan 2020 11:14:59 -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=Cr1uy4rA; 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 S1728834AbgANTN7 (ORCPT + 99 others); Tue, 14 Jan 2020 14:13:59 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:44886 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbgANTN7 (ORCPT ); Tue, 14 Jan 2020 14:13:59 -0500 Received: by mail-qt1-f196.google.com with SMTP id t3so13446288qtr.11; Tue, 14 Jan 2020 11:13:58 -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=MFqB+06rBeER++BRySglojh7CJB3/vJLed3nR17srZY=; b=Cr1uy4rA/yc63G/NYnYI6sGqCHjIbj2TiaQVLsKC492L5usjwa9oleTsoZYu7gfzAz fViS+p1sEET0HTnq0582qDyZfsPjAw9Ra2caO/4j6osRwltuRqO4/3vDtygeKSJc5Isd 5OXxYJlilf3YnCifUUYtc59aGVj8cejFf5udT1ze8tUSnxdZg+oZDuh75TG2ov1we41u 5wuNe7KELTyQuRDb+nQ6wVTXB5CRurnsWsmU2IV5cbDT/ZGTWhRWaQV9TnDXkS8+Fq8t nBf+mW01SclboYCRG+sxLVUG8YtFgwpfHnPt2yo7FFNV0j1WgVRego3SjXeap6hREQk6 WBBw== 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=MFqB+06rBeER++BRySglojh7CJB3/vJLed3nR17srZY=; b=RZl0rP21WpIFESdYGs2F//HMoxhqAaE0qgc4q7BGZqRF6yXRnAbGWhWtCTKfd3cZ1j t+/YzU0UXva+qpWsF7uWtisRxLKMg7DkCHwKNr2wyewSKceFrua7MHi+x78fMFb386SD bi/JaGWYHLCjX4cVJQod+f+B0Nmy9z4A5Ftz/R4BwnGaFFetvVyLpptEpHDGbyfcNSYQ iCuZiWrEwDHjHJQlNEFdHipeLBV+7s+aU1qp8Q1QG0l8sHeXxWRd/ARu2FhcBNO7Exf9 M4DqcgnGqS0On0hABrgt0HjkTpUdrE1q6BnV1+UYs7ravOjdnuEr102enN0xw4Qu1QEq g1iA== X-Gm-Message-State: APjAAAUHqwlR1+E4oRJAtd+kJcJc9UrflkD8AKj/Hs+i4JAqiB6TEKN/ kyCXwP1HDUzcpZtDZXE33+md3LXwBiMYJtpkrKtG3HRs X-Received: by 2002:ac8:7b29:: with SMTP id l9mr72065qtu.141.1579029238026; Tue, 14 Jan 2020 11:13:58 -0800 (PST) MIME-Version: 1.0 References: <20200114164614.47029-1-brianvv@google.com> <20200114164614.47029-9-brianvv@google.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 14 Jan 2020 11:13:47 -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 10:54 AM Brian Vazquez wrote: > > 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. ah, ok, tricky semantics :) if syscall failed before kernel got to updating count, I'm guessing it is guaranteed to preserve old value? > > That being said, the condition 'if (count)' is wrong and I think it > should be removed. So count is mandatory, right? In that case both `if (count)` checks are wrong. > > > > > > + > > > + return ret; > > > +} > > > + > > > > [...]