Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11431879ybi; Thu, 25 Jul 2019 16:26:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+g1xAUqrZmsj/yrlCTo2P4uMPUL2C1shzCgwCZy8AP6T/0z6wYXH7/UtHMU63ueBEAXWY X-Received: by 2002:a63:d210:: with SMTP id a16mr86430743pgg.77.1564097216764; Thu, 25 Jul 2019 16:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564097216; cv=none; d=google.com; s=arc-20160816; b=X7Yt6KIgRDqEbcy2qdNzq2wjkR0d9D5TmQvqMt5w8kqXydQt3N0qYrNRCJU4HD90Tg F/pfn2v4931AnBvExibylIvqpKFqJCcXKXGuMKVQO+GnxGuXdq6G/lpLzk+ewqi/CNBY dFblokcVnV1XcmUcmP4bLWcR8gt83n1DpdKBQSOhq7s2FbM3llCUcn0ekrXQUT4BqVYA MAHG08/0iLBuhu9RhyCviioqt2lpG9f3cOMbPt9XTFYM9DIf2QiQMUpka2uFnbp0PbSU Z92Z3NL2CAsLKDOPINOpKHKHsZfpZmM+fFgFaRB10gPvZkYUEL7IN2l/tD108AwdyQYi s8yw== 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=9l3baTsqWUqUoLsmlugit8t4Kk96ZWT3/jwqQOX2+aM=; b=jt2SuXfFUx3tyivuu8kOvA8i6VvqULAgSnq1n9U9NqWpvLbPe1tKCwBZdYAz7OO34H 04bCW9HzhXyaoUajg4ezaI2c+9SPxoGjMxg8Lyc7DMbpkdPjX9Xv0064O10ORR7V++bl ikm/GXfk4A9DpoIocRrIKEPZD8prVtTK20ZPvtBoAfEq8idv9xeuKTSvZ8i16gX0PYO7 Dh55vlhIFEMcRx2vwtUWe0spUYA9CXkYk6X/f0oYC3ecvgtBoNthyDCySo3B8ZWvPp6U CQh7b9ta7gNJ5Y0O/pznH5riOYINJpO7LEpSpUrJVbhl+ciokNu7KTuqrmFrTvOz0bKf b4JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="M22/OEs3"; 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 e5si16529425pgc.29.2019.07.25.16.26.40; Thu, 25 Jul 2019 16:26:56 -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="M22/OEs3"; 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 S1726908AbfGYX0H (ORCPT + 99 others); Thu, 25 Jul 2019 19:26:07 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:47002 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfGYX0H (ORCPT ); Thu, 25 Jul 2019 19:26:07 -0400 Received: by mail-lf1-f65.google.com with SMTP id z15so31473951lfh.13; Thu, 25 Jul 2019 16:26:05 -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=9l3baTsqWUqUoLsmlugit8t4Kk96ZWT3/jwqQOX2+aM=; b=M22/OEs3jSuHhxuGfvjid3m6tR0t3Rv1gyvbMFbTdjzpPbX4zLaNv7tL4aaBpb/1hm m+7eZBTvMaCWebMUDMOSYHBdbBZBq3M+x9gl3Rr2cpj4F7lL3hUZJKWoJD1xpdUxcqQI aCBZ6oJm/MVTGh2WA3JL/n9Adb1tBYG1aO+4iKNzpGmMSmXzXkq5BRg8jb4Hx/ZrfwVf a5hJK2iAGvChJrbOrcBI9Uxp9SHPmbk/UA7iGElyxjjHKsmTewSbnETvKTUzJ+wac3+6 8ZZnLMRfgE6lM9ozd9c7wiSFheu2Sc06uvOgLtHuE/JwCb4T4Ew3zkRkZihlbWXTeA1G 4YsA== 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=9l3baTsqWUqUoLsmlugit8t4Kk96ZWT3/jwqQOX2+aM=; b=mQj6Jt0Ucpc+iwIfn61jpnm2zQyw6Xvjs7Szawwz3Ag9YmaWfJI9CuYZZ/ZHiT9n67 idsJ1DuhVGGwrwuc9HiA0Jzm187U67r2mGdu8zF4EajGuteoBuptlAnEJXtTIa+m2qAZ nggmtK+3tKfF9ggyUUTgMnyrrCd1MrJX7JhmJIwrAQ8wZ9C7U81vTXlal0Pfytr/NtgE 5UxuyyVDqqgiQorHA8Bma4GRSUX5ouZ//8k3RlJ0yLUc2iAHTCUAHssB9PrmzTaBoGHM +LVJV2NQJ/o0XT1dn1d7JydApAK/6bQ4VgzBhNanzbwuhNrKJ+exp0YZEXdT9cHaagtT EgkQ== X-Gm-Message-State: APjAAAWAFnHNnssPu7tdH/1SRqUxNchOIg7rctUzvQTbej/8Hr2RTZc0 +HksYerOtwCsKAj3CxlbCLkh0qqxVEVJ9wPWhFk= X-Received: by 2002:a05:6512:21c:: with SMTP id a28mr2351025lfo.14.1564097165009; Thu, 25 Jul 2019 16:26:05 -0700 (PDT) MIME-Version: 1.0 References: <20190724165803.87470-1-brianvv@google.com> <20190724165803.87470-3-brianvv@google.com> In-Reply-To: From: Brian Vazquez Date: Thu, 25 Jul 2019 16:25:53 -0700 Message-ID: Subject: Re: [PATCH bpf-next 2/6] bpf: add BPF_MAP_DUMP command to dump more than one entry per call To: Song Liu Cc: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Stanislav Fomichev , Willem de Bruijn , Petar Penkov , 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 > > > If prev_key is deleted before map_get_next_key(), we get the first key > > > again. This is pretty weird. > > > > Yes, I know. But note that the current scenario happens even for the > > old interface (imagine you are walking a map from userspace and you > > tried get_next_key the prev_key was removed, you will start again from > > the beginning without noticing it). > > I tried to sent a patch in the past but I was missing some context: > > before NULL was used to get the very first_key the interface relied in > > a random (non existent) key to retrieve the first_key in the map, and > > I was told what we still have to support that scenario. > > BPF_MAP_DUMP is slightly different, as you may return the first key > multiple times in the same call. Also, BPF_MAP_DUMP is new, so we > don't have to support legacy scenarios. > > Since BPF_MAP_DUMP keeps a list of elements. It is possible to try > to look up previous keys. Would something down this direction work? I've been thinking about it and I think first we need a way to detect that since key was not present we got the first_key instead: - One solution I had in mind was to explicitly asked for the first key with map_get_next_key(map, NULL, first_key) and while walking the map check that map_get_next_key(map, prev_key, key) doesn't return the same key. This could be done using memcmp. - Discussing with Stan, he mentioned that another option is to support a flag in map_get_next_key to let it know that we want an error instead of the first_key. After detecting the problem we also need to define what we want to do, here some options: a) Return the error to the caller b) Try with previous keys if any (which be limited to the keys that we have traversed so far in this dump call) c) continue with next entries in the map. array is easy just get the next valid key (starting on i+1), but hmap might be difficult since starting on the next bucket could potentially skip some keys that were concurrently added to the same bucket where key used to be, and starting on the same bucket could lead us to return repeated elements. Or maybe we could support those 3 cases via flags and let the caller decide which one to use? Let me know what are your thoughts. Thanks, Brian