Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp682092yba; Mon, 1 Apr 2019 14:39:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyu5ccfLONFyE4t2aNzEMpqqDxCyfyCU1FUHp1Tcf8NcNfn5ctXMQOVumczN5T/u47BgNE X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr68169325plb.281.1554154749717; Mon, 01 Apr 2019 14:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554154749; cv=none; d=google.com; s=arc-20160816; b=J+oBd50P2S0YAZY65UH1kf0EafhWMkYF/nWSUEivwXT5gAybKgFWvv/lPuPdG6xiTQ h3SC/ValDp+70CpBWFdCoryvQDJ0/4GFBElDr9TJPwUSbdz5UJvWTn9zF8mek8y88weB xqdt+pvca8aUK+k90UwlVhlNYsFloekhbXFf3ztyjoGQdkbkKgXymGsywef3ewnfNN7v r9q3xT6rtbegyw/bR+8gazlFti1bDLtXL4s0QiDjYvyM0Fx2Llq+A6aG09a6bjbpEqSX oFPz7/vBxkvrX3HTaM9cQ3KmSemaoLIEVojl1wI6UHCC+siXNCmqtk8m5BECSsdmZXQD qqFQ== 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=FHNIq0DAsiO68PBdakjAEu2fVLC527LLikbsrJoLlzw=; b=GC6z8MhiVcFCh4xZIYQ7sgJkXuRUaGYpr4h5sDhtWa407BjKasA5+DKlsv00AEw5lg n/jVRqKNexFLxPU6EtnfioA8gh0MLooZ5AO+Iezou+C+lJKj1UqW2Dy1s7fP1dzC3zME tAkptDcrHcIOUHa40H2URRJlml0MzAgcIdfuNMv7pBu2TpYIA8xvrPuI0Er9nIxqyTYu 6xExr30dBfoC4BggeeHGtsUH3kRoPL/tAOkEbvr6+fhemww006h2qHEqC1hEsBRKzuHD 5QzsqbdSB35OgZJucTENB9oI6TWP5LSQLMFA1lTOxGMK9drXRR7G3dAsCZQbeSG0Puj6 xfPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GuoOo1Jt; 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 w3si9519064pfw.94.2019.04.01.14.38.53; Mon, 01 Apr 2019 14:39:09 -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=@google.com header.s=20161025 header.b=GuoOo1Jt; 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 S1726918AbfDAViM (ORCPT + 99 others); Mon, 1 Apr 2019 17:38:12 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:40503 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbfDAViL (ORCPT ); Mon, 1 Apr 2019 17:38:11 -0400 Received: by mail-yb1-f196.google.com with SMTP id g12so1902929ybh.7 for ; Mon, 01 Apr 2019 14:38:10 -0700 (PDT) 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=FHNIq0DAsiO68PBdakjAEu2fVLC527LLikbsrJoLlzw=; b=GuoOo1Jtsv8fOQjSU/DMg/+OeDJo25ir04J2M6CQzfya8Aft4/BhJ+g3al2eV213gt B1hP9eiO/rrCOQB08YjA8O59LoU7MJxAYJpd411bxNKw4fNfTL+yrgJemihGxl/rofQz sXXi6YrU2wDiR/0gV5iNzKECTfbRY4wYhzbvMikja8QmcBpjKVlcTxSG4ofOS/SqnVDG jQZJhWFS5Q8twQTipMBVzM7JErAXf35f5ORR60XFumwAZkRDfS9rInxT8VpG3lUtGb9V PqqDjtqvgnFgFXTSyDGT5yPjDqgZtWc2R6GIAyd2QKM2tIWakZ/x+VIuU1APvk2WngMu uvaA== 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=FHNIq0DAsiO68PBdakjAEu2fVLC527LLikbsrJoLlzw=; b=L6TQxrbkzEpj0hQE/qL++WIIpjQLGqhGWifABzfTKWAHSTAcb5Xj6Av3upO3fRvvr0 0RShCgq5v2c9oTBzQCQV57nNQEepdvhOOu9pe01NhUln6V+Ru5MOduuszx+gTzNJsE9k ZMiBkXzrB4yYZsQSX7BQVryAndinz1SGxhAtHW+lFyXWQvFR3oO40F43bZWlFGhr6wbf d33gr+MPIgHcsNzw21CQRY93d84jWdvaPCeTqXsW7hOuI2xE0Rq0O0YfLyZ5naVkNJXI jh4WZCkVLBzcE0d23VhhBWuwFrhU+CO84WQuP827AsGtI5pVVXAFhziX7M5CMu1jAjSp Bxxg== X-Gm-Message-State: APjAAAWbPgKu9gtZpARkVpp2mM4GbfsogJ3354bGzefhIsvWS1HkzM9I 2L+Oa/10+vJsU4KL32aSDA6dnf8813GQUQNbM8dIBqaa83g= X-Received: by 2002:a25:5755:: with SMTP id l82mr54855357ybb.25.1554154690145; Mon, 01 Apr 2019 14:38:10 -0700 (PDT) MIME-Version: 1.0 References: <20190331064129.31702-1-brianvv.kernel@gmail.com> <74e3024f-6fde-a04d-4000-89c6e61acc26@iogearbox.net> In-Reply-To: <74e3024f-6fde-a04d-4000-89c6e61acc26@iogearbox.net> From: =?UTF-8?Q?Maciej_=C5=BBenczykowski?= Date: Mon, 1 Apr 2019 14:37:59 -0700 Message-ID: Subject: Re: [PATCH] bpf: do not start from first bucket if elem is not found on a htab To: Daniel Borkmann Cc: Brian Vazquez , Brian Vazquez , Alexei Starovoitov , "David S . Miller" , Kernel hackers , Linux NetDev 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 > This breaks BPF selftest suite unfortunately: > > # ./test_maps > test_maps: test_maps.c:114: test_hashmap: Assertion `bpf_map_get_next_key(fd, &key, &next_key) == 0 && (next_key == first_key)' failed. > Aborted > > Some more background, situation is a bit tricky: pre 8fe45924387b ("bpf: > map_get_next_key to return first key on NULL") there was no reliable way > of getting to the start of a hash table, meaning it needed an 'invalid' > key to return the first element for starting traversal which commit fixed > by being able to pass in NULL. So some applications might still just rely > on e.g. key of zero bytes (if guaranteed to not be used otherwise) to do > just that. With this patch, we'd start out from anywhere in the hash table. sdf@ just mentioned this internally as well... I think we simply will need to add a flags field with at least two options/flags: - return error if key not found - resume from bucket instead of beginning if key not found and while we're at it: - return concatenated key+value instead of just key to save an immediate lookup on the returned key