Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11453234ybi; Thu, 25 Jul 2019 16:56:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMnNvfUag8yqqugQWy5/AwM9yvzMPkTMs3Q14zgqCtaKtARvA9ZmZOO65n2xcPjFE8gRRS X-Received: by 2002:a65:68c8:: with SMTP id k8mr4215655pgt.192.1564098970815; Thu, 25 Jul 2019 16:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564098970; cv=none; d=google.com; s=arc-20160816; b=ZobT+RQgWjxydojuEulL/kg1Xmzh4Nb5gBg2Yd6QkYuv24fY/kh0aADdttUl6hYZY9 UA8UY0cmLeJAed4vgZ1u7LxjYEbbhlV0vj8Kgkth2FF15pdI4sdqnZJl2zDkWL0CMP/w p+Zb9WvCmPEAGq0kfP5nP6oLf6SFmBZ6wmVN93y8p2nBJvazSbL307/vV2CFMOFBFfWr JmoVQ/p7PElo2C9zj2Qnkk7GgTHsyXZlU8GqK7hiD/MNDqVxv4h6dxRTK0txhqXXsYJy Ol9B3YO31SLaKkujsmFcdZvPpe7HSX2jEpUXjH33FvTOdzLzcXK7LAq2qqcYBAPPpQBs 8ArA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jbjn6X1o+b+RloH7E/SSTLYw0cWzlKuB788mEgA/bpM=; b=KO3XAZJ1PGQxsHBR1OvojfbSxUXlMrf7LfbEB2TbO/xblBADvekHnEL6PvAjnK1gNL Ci+rKSi4iIKRkdMS4yvZXfkB5ei0BzyXuEZ3R/pHPdQe2xDYbY2NTajZOnbd61NgRTJ3 Zp2OaYUHO3qmQ0SkGpuhH86SsuUZYq/fRJK8Mg3GqyEz9JN2Aa8uKtPC+9bKakr480U6 saaPRIbh/i8yBcSFd0Xd030HIFrIG/ZLiJ2CKa52KLVQa991kaknu+lidcT2yPDQ585m t2H+sgpLpx6UIEDi1srUVjYVrOJGGdZEpcGTCMDsTnXteyBsnAQQdVQQkkFwa6EKuvW2 8HgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=P+R+4w2M; 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 t11si14499735pgu.16.2019.07.25.16.55.55; Thu, 25 Jul 2019 16:56:10 -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=P+R+4w2M; 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 S1726988AbfGYXyh (ORCPT + 99 others); Thu, 25 Jul 2019 19:54:37 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41928 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726380AbfGYXyg (ORCPT ); Thu, 25 Jul 2019 19:54:36 -0400 Received: by mail-pl1-f194.google.com with SMTP id m9so23908917pls.8; Thu, 25 Jul 2019 16:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jbjn6X1o+b+RloH7E/SSTLYw0cWzlKuB788mEgA/bpM=; b=P+R+4w2MxJZR2ZtX05liUIbVVC5sHJ1cw/fh/WcaeHysDxmi3GzLzGaWIp5i3b7Wpp Z5axEdJM0C9BxpHhuJgeIfMtZiJ7OqS55l0Vk59YkWRWJYtV1I/xYiTpcPhaBxl9DoGE VWSFrwfLKi5hXTOVrjw1Bg4X9Xatca02BwLVrlB1NQsTop3tDT+bPDNuhMI8GNxI2Ohr WdJK53rB4iq8IIAsOClZ9aGiFSX5o+twaXEa8q0fMxEm5tfROzEPOFV0VtctPb/A6xTo C9MGQjy1vM0Vo3/n5ReQCnqqIc4dSzextvN953XLWfo+GRG43E2+T7NzSwkUQOaC1mXB 5uRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jbjn6X1o+b+RloH7E/SSTLYw0cWzlKuB788mEgA/bpM=; b=PKjuRydWHLXvoYpOPK71GHMd8Hi+40bwYCPZZ6hPvdi2opVLtixTNhMRG4qMDEEAsH a9/UFeikLt7g3pLUhCxZ+lceMlmn1VuqvPWdQuL4l9z/dc2XBePdhNti2DXzLFuQVU1u AsFovNX8lc71+SsJcZRFKXMVCbVDhmu3GC6k5yumx6jAMmC0sJhe04CSbanaTZSt8fRl AbkBUoGcn+aTeT+cecHK7U8REL0csu+NOJpwRV8zA7pupPp7dXncR+C7aZ61WzIr8r5K 4h4qq+btUaOYWNJqRmC6Azczm/nN6CKrXGgawKw84E9aMKBRU7Cr5RZenq9BnzFQbHoX +fQw== X-Gm-Message-State: APjAAAWDRVsOdOzT5WX0NLh4KWPscg0qhYUXINiel3OI6UjenrPc1Zks tArGygBKDY0W/cG2sQmNB0w= X-Received: by 2002:a17:902:7612:: with SMTP id k18mr92208136pll.48.1564098875806; Thu, 25 Jul 2019 16:54:35 -0700 (PDT) Received: from ast-mbp ([2620:10d:c090:200::1:85f9]) by smtp.gmail.com with ESMTPSA id w18sm64466745pfj.37.2019.07.25.16.54.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 16:54:34 -0700 (PDT) Date: Thu, 25 Jul 2019 16:54:33 -0700 From: Alexei Starovoitov To: Brian Vazquez Cc: Song Liu , Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Stanislav Fomichev , Willem de Bruijn , Petar Penkov , open list , Networking , bpf Subject: Re: [PATCH bpf-next 2/6] bpf: add BPF_MAP_DUMP command to dump more than one entry per call Message-ID: <20190725235432.lkptx3fafegnm2et@ast-mbp> References: <20190724165803.87470-1-brianvv@google.com> <20190724165803.87470-3-brianvv@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 25, 2019 at 04:25:53PM -0700, Brian Vazquez wrote: > > > > 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? this type of indecision is the reason why I wasn't excited about batch dumping in the first place and gave 'soft yes' when Stan mentioned it during lsf/mm/bpf uconf. We probably shouldn't do it. It feels this map_dump makes api more complex and doesn't really give much benefit to the user other than large map dump becomes faster. I think we gotta solve this problem differently.