Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5586311ybl; Tue, 14 Jan 2020 11:25:34 -0800 (PST) X-Google-Smtp-Source: APXvYqxBeyzHvaYbzucTtjUnNtavyHV55H7LYY8w2+6CY4Ucywgsh8QTVpLV/SXobyNgI/7YNyN3 X-Received: by 2002:aca:f1c2:: with SMTP id p185mr18421325oih.87.1579029934037; Tue, 14 Jan 2020 11:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579029934; cv=none; d=google.com; s=arc-20160816; b=QMD1yezzbWWGcnjSM+EUG7B4UxVB7Qp7qGUP5dkAGB69MMOsa+4LPrVixOtfkNPZcu qZ0+4bHuiMQuKWCCVM7VNNny8H0nNUd4DOF8mpXjFPQe8g6ggBn+xS1CcbCwDzQNBY5j UdKySaMD0SXh7R3KV0fAVZrUezsrF4KKMpCMyHXO9qXPlcsw0l5eDpDpffWpttd7DVMA WxvuuD0cn0zlP9H7V8N7+DN7VMgrGGyH723QWhdoEQZ8fApCRE/xWPeW1PGqvsurEkWB icXgUoikWqNxcL7CBzyNU+cIc4nNh7Ip0givsfsq/+9L/CpIUm6ifJXd16OTGl/LLlfX vtTA== 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=SvPYpJ3+ZQRE3RpgnFrfhCFn0sFFgxXkJCxLs6MF/eU=; b=u7qTw5pFF3h9WuO8KYRSQsvvAsxUDTXF8+PL/LO5SzQ32diZF8K2mCK8ryPOf7yrp0 pMYbYx5g5ICRvsGJ6KeRJHUWvP3k9rzn4crEVSKm0GMTLmpXpVA7O+LLeCqEuTcipEFX 8DVLokNIHjhvYZgRq+/xaEkyVSQQE+CwII2tbfkeD6qzHey4ljsR/nbbIUL2vz08PKau L7cbsLhhC5PXTs0eBX8FEIQKNagGBtOduFKDJt90u1ysvyQf4rxIRsMSj+7plkUqLRxN CQ15m8JFNe/7xi5dK9s9GI3AGdSIA3kaFzb8CnZGRLJ/M04CF/u/89K9p6pllwSScGWT QmPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IYJqCcsm; 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 a14si10193475otk.2.2020.01.14.11.25.22; Tue, 14 Jan 2020 11:25:34 -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=IYJqCcsm; 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 S1728855AbgANTYd (ORCPT + 99 others); Tue, 14 Jan 2020 14:24:33 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:45579 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728769AbgANTYc (ORCPT ); Tue, 14 Jan 2020 14:24:32 -0500 Received: by mail-qk1-f196.google.com with SMTP id x1so13217360qkl.12 for ; Tue, 14 Jan 2020 11:24:32 -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=SvPYpJ3+ZQRE3RpgnFrfhCFn0sFFgxXkJCxLs6MF/eU=; b=IYJqCcsmY3UmyL4J7VlHj6X+04mwAifaJQcJmyH55kxjQnz3O0kpjx8n3NJEJmBsTF A6z+04dTxFro/fimq/5FHbbV84ey+mcNMCB8tz5qWQh1qJyrf2xLzq9GP7b2sFYDk/JH 5WJuvUhKNCJWersYWsu23xIXLTyj4ZyRXMOk87R91DDIR/ji9sOCXBdqrQmVLaI8+39M t8zZCGrUS8BRPouK5+RaZ2pJfpYG2NQODy7vGPeq2+144RmVjTr1zBiAGvLzCbEF8Spl k+lNSL1rFhITVxZxNXOpZYX+mAfMp+pEalwX1tf8/BDvOqgUdiBfuDWADyxvAIJdsA7M 24PA== 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=SvPYpJ3+ZQRE3RpgnFrfhCFn0sFFgxXkJCxLs6MF/eU=; b=uhxl6M2tHnjKl7cBZ/q5GGKyzbfpwvZNv14i+P0zTHL+kXecbJQUZoEShEf+TYeUVj GD0Hd/C/rovKlXFGXtjBHr3oQBNR0aOIxdsHSZC5WT+p+Ey4olZv6gvjEIbgaoMNRAxq fhvEd5LliMqWKTP546jGJC6UOOlFWenPbVdTIlb8/mq30Bn6tY1u/igXOVFbHYe53hh6 JFotvWvLM8FBz6QCxlU4+mbYobc8PabbiioyIxmM4XEhkU3Skd3Lm8nSOjukD3YyXaH4 rWbyA032Q9v1zLrUn7kc51Jg4pSDf5mMw+n6TAJEihISiVztdD/JovlXKIDkS+kPyMEB Z2KQ== X-Gm-Message-State: APjAAAUaRqsihZzFzM4uQKemAYDRrKDvm0Ec/Krl4ANxJ4nth99KrBkU I10qCH9ImHzEveiiXyEV1GcLun3wvNG7YkE6Y5wvYA== X-Received: by 2002:a05:620a:1010:: with SMTP id z16mr19021899qkj.237.1579029871343; Tue, 14 Jan 2020 11:24:31 -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 11:24:20 -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 11:13 AM Andrii Nakryiko wrote: > > 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? > I think for correctness as a first step inside the syscall we should update count to 0 and copy back to user, so we never preserve the old value and we can trust what count is reporting. WDYT? > > > > 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. Yes, you are right. I'll remove them in next version. > > > > > > > > > > + > > > > + return ret; > > > > +} > > > > + > > > > > > [...]