Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10532884ybi; Thu, 25 Jul 2019 01:02:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2MoyqVN7xJ9ouBvZj1fG/OUFDgLFbDEAWCgxy2owy6kgbrdhb2WRlghybIyZn4W0hdMKp X-Received: by 2002:a17:902:9689:: with SMTP id n9mr91064035plp.241.1564041747055; Thu, 25 Jul 2019 01:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564041747; cv=none; d=google.com; s=arc-20160816; b=nIFISYYE/YtEwoDexjApVFrKCddGWplbBKJUEmdTB+hys7X1+O3UQLecQFP3YQjBxA QbKyo0F/oAfTknieXaD2Qm4lMENrxuklJz40Mp7z1DkGTsDT7fvhqxEjSwZgmX9+7jLW 28oBuOzKxBUBzeL3U+G/BisxdgEgteHRWL/CsrAd9bUbwe6RuWznZLiWuMRAYVzIpC7p 6628FPbPNJQ9Iv/87HeOjgYE6hWxr8snjrB0og+T870K7BujqV2d8RtsbzamPRnV0ctJ qgpWiXiT0TdQg0ywx0Zre4ZlUvecA2BWKu/568a2wOvT0NpWsDh1Egj8vaUd73v3hQEw 0FFQ== 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=dgiQF2cvC8jfXzt5HL3uJMfZaBJ8NW3XQoRQC8ii038=; b=WIdcruN7Uk9WZFdEISzbivKhdBNZqSkiMovMnTLALbAXbJ5U0L5bIaF0G8KZpsN+BN sEbwe1wKBJ/BAqXVPoU2MvRlDZt4ZaEi+mpav0JEeNmwJkiCMzAizJpwEOzhSVBnNBuh Vb3gjTirnDP7WcRbpc9ok20C+ydiXpq+3CGqTuxfaI5fk4ImfeGjC+bmmME0RiL+YUjL TmqialWlLUyf5vWkV7DqExBwyzMJdwkRFZZEM24xkOOw7xtHak8Tz9eCQHAari4kG4KP KDhRJnd0tZE9DmTzZLmV+9vCyRs4Y+s1DHzRF767Ttw8qwd3K1h+DgBTHxMygiG0DSeo xsBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vQHeAiyX; 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 x12si15729525plo.64.2019.07.25.01.02.06; Thu, 25 Jul 2019 01:02:27 -0700 (PDT) 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=vQHeAiyX; 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 S2388805AbfGXUOM (ORCPT + 99 others); Wed, 24 Jul 2019 16:14:12 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:37030 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404068AbfGXTza (ORCPT ); Wed, 24 Jul 2019 15:55:30 -0400 Received: by mail-ed1-f68.google.com with SMTP id w13so48179881eds.4; Wed, 24 Jul 2019 12:55:29 -0700 (PDT) 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=dgiQF2cvC8jfXzt5HL3uJMfZaBJ8NW3XQoRQC8ii038=; b=vQHeAiyXQ/fCWx93RMqspZg1DqWs3Ss8caJgC5JiNt1q2PzivWVm84dLQmP+XWPMBJ wiM8lTSMXvxMkz5oJReFb1oqB5mBoC0dfhceBItUItDfaKYJuiQuwzJQIp9MHNmubDnM Hds5/qNqyc8M+MnlPxI4ary5YddYAtlyLSbFFgcR5W/TTXYK6PlvEwlRN2OuFo9tO3E0 vGkFfsvGiINEUILt8rxNw2oCJPkB3cbjEeOIVoGHkQJPpucIBZWG53bDgkWZR8gLCwRb IKvmqXEZEfLxA2ClNvYwQrE/YOQr7QqRX90PgnXj/7aHOC81GSClCaAVu7UTdbjzOZtg Az/Q== 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=dgiQF2cvC8jfXzt5HL3uJMfZaBJ8NW3XQoRQC8ii038=; b=V59YyzLW4j4i4sPf+gLYnGFxtm9Q2iG+Ij1DwNU90qKoagLKVYGRZvyew2iicc17nK dGWCRRIYvwDaP0LYVq8vA+igDBGF/oR0zfRSUyHvsgkzUw6a2lwxfW6QDTT+ZyYvoes1 Tyjfvg4HyxUCQUw8XZCWvwEKQL90Kffk4g+v7B8m7JCQEU0KSn9WuHlcM167ruGMHNhD HoueKZVjIrRCWW+mErF+dIDcckv52VDC16kLv+9NtgLe4oh5qGLgezdFjr0a47WPgkCe pIIVxtndjG/ag9LQCsbLArXJFWGbg6Fzia5CZR0fHdtHAe/MteLz76/OGltraUBX3a81 JKPQ== X-Gm-Message-State: APjAAAVL95xc01TZtrLi97XVX7ZW6bGzTmXlMYYbzbLTaVgNL4DIufEi OmgFg6oVPsKb3aAH1NibahwVwGkp1J/VDPLXEJss+w== X-Received: by 2002:a50:eb92:: with SMTP id y18mr72682568edr.245.1563998128385; Wed, 24 Jul 2019 12:55:28 -0700 (PDT) MIME-Version: 1.0 References: <20190724165803.87470-1-brianvv@google.com> <20190724165803.87470-3-brianvv@google.com> In-Reply-To: <20190724165803.87470-3-brianvv@google.com> From: Willem de Bruijn Date: Wed, 24 Jul 2019 15:54:52 -0400 Message-ID: Subject: Re: [PATCH bpf-next 2/6] bpf: add BPF_MAP_DUMP command to dump more than one entry per call To: Brian Vazquez Cc: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Stanislav Fomichev , Willem de Bruijn , Petar Penkov , LKML , Network Development , 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 Wed, Jul 24, 2019 at 1:10 PM Brian Vazquez wrote: > > This introduces a new command to retrieve multiple number of entries > from a bpf map, wrapping the existing bpf methods: > map_get_next_key and map_lookup_elem > > To start dumping the map from the beginning you must specify NULL as > the prev_key. > > The new API returns 0 when it successfully copied all the elements > requested or it copied less because there weren't more elements to > retrieved (i.e err == -ENOENT). In last scenario err will be masked to 0. I think I understand this, but perhaps it can be explained a bit more concisely without reference to ENOENT and error masking. The function returns the min of the number of requested elements and the number of remaining elements in the map from the given starting point (prev_key). > On a successful call buf and buf_len will contain correct data and in > case prev_key was provided (not for the first walk, since prev_key is > NULL) it will contain the last_key copied into the prev_key which will > simplify next call. > > Only when it can't find a single element it will return -ENOENT meaning > that the map has been entirely walked. When an error is return buf, > buf_len and prev_key shouldn't be read nor used. That's common for error handling. No need to state explicitly. > Because maps can be called from userspace and kernel code, this function > can have a scenario where the next_key was found but by the time we > try to retrieve the value the element is not there, in this case the > function continues and tries to get a new next_key value, skipping the > deleted key. If at some point the function find itself trap in a loop, > it will return -EINTR. Good to point this out! I don't think that unbounded continue; statements until an interrupt happens is sufficient. Please bound the number of retries to a low number. > The function will try to fit as much as possible in the buf provided and > will return -EINVAL if buf_len is smaller than elem_size. > > QUEUE and STACK maps are not supported. > > Note that map_dump doesn't guarantee that reading the entire table is > consistent since this function is always racing with kernel and user code > but the same behaviour is found when the entire table is walked using > the current interfaces: map_get_next_key + map_lookup_elem. > It is also important to note that with a locked map, the lock is grabbed > for 1 entry at the time, meaning that the returned buf might or might not > be consistent. Would it be informative to signal to the caller if the read was complete and consistent (because the entire table was read while the lock was held)? > > Suggested-by: Stanislav Fomichev > Signed-off-by: Brian Vazquez