netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lorenz Bauer <lmb@cloudflare.com>
To: ast@kernel.org, daniel@iogearbox.net
Cc: netdev@vger.kernel.org, linux-api@vger.kernel.org,
	Lorenz Bauer <lmb@cloudflare.com>
Subject: [PATCH 1/3] bpf: allow zero-initializing hash map seed
Date: Mon,  1 Oct 2018 11:45:07 +0100	[thread overview]
Message-ID: <20181001104509.24211-2-lmb@cloudflare.com> (raw)
In-Reply-To: <20181001104509.24211-1-lmb@cloudflare.com>

Add a new flag BPF_F_ZERO_SEED, which forces a hash map
to initialize the seed to zero.
---
 include/uapi/linux/bpf.h | 2 ++
 kernel/bpf/hashtab.c     | 8 ++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index aa5ccd2385ed..9d15c8f179ac 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -252,6 +252,8 @@ enum bpf_attach_type {
 #define BPF_F_NO_COMMON_LRU	(1U << 1)
 /* Specify numa node during map creation */
 #define BPF_F_NUMA_NODE		(1U << 2)
+/* Zero-initialize hash function seed */
+#define BPF_F_ZERO_SEED		(1U << 6)
 
 /* flags for BPF_PROG_QUERY */
 #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 2c1790288138..a79e123dae62 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -23,7 +23,7 @@
 
 #define HTAB_CREATE_FLAG_MASK						\
 	(BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU | BPF_F_NUMA_NODE |	\
-	 BPF_F_RDONLY | BPF_F_WRONLY)
+	 BPF_F_RDONLY | BPF_F_WRONLY | BPF_F_ZERO_SEED)
 
 struct bucket {
 	struct hlist_nulls_head head;
@@ -373,7 +373,11 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
 	if (!htab->buckets)
 		goto free_htab;
 
-	htab->hashrnd = get_random_int();
+	if (htab->map.map_flags & BPF_F_ZERO_SEED)
+		htab->hashrnd = 0;
+	else
+		htab->hashrnd = get_random_int();
+
 	for (i = 0; i < htab->n_buckets; i++) {
 		INIT_HLIST_NULLS_HEAD(&htab->buckets[i].head, i);
 		raw_spin_lock_init(&htab->buckets[i].lock);
-- 
2.17.1

  reply	other threads:[~2018-10-01 17:24 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 10:45 [PATCH 0/3] bpf: allow zero-initialising hash map seed Lorenz Bauer
2018-10-01 10:45 ` Lorenz Bauer [this message]
2018-10-02 19:59   ` [PATCH 1/3] bpf: allow zero-initializing " Jann Horn
2018-10-05  7:42     ` Lorenz Bauer
2018-10-05 14:12       ` Jann Horn
2018-10-05 14:21         ` Lorenz Bauer
2018-10-05 14:27           ` Jann Horn
2018-10-05 21:07             ` Alexei Starovoitov
2018-10-08  9:48               ` Lorenz Bauer
2018-10-01 10:45 ` [PATCH 2/3] tools: sync linux/bpf.h Lorenz Bauer
2018-10-01 10:45 ` [PATCH 3/3] tools: add selftest for BPF_F_ZERO_SEED Lorenz Bauer
2018-10-01 19:12 ` [PATCH 0/3] bpf: allow zero-initialising hash map seed Daniel Borkmann
2018-10-05 14:27   ` Lorenz Bauer
2018-10-05 14:29     ` Jann Horn
2018-10-08 10:32 ` [PATCH v2 " Lorenz Bauer
2018-10-08 10:32   ` [PATCH v2 1/3] bpf: allow zero-initializing " Lorenz Bauer
2018-10-08 23:07     ` Song Liu
2018-10-25 15:12       ` Lorenz Bauer
2018-11-07  0:39         ` Song Liu
2018-10-08 10:32   ` [PATCH v2 2/3] tools: sync linux/bpf.h Lorenz Bauer
2018-10-08 23:12     ` Song Liu
2018-10-25 15:07       ` Lorenz Bauer
2018-10-08 10:32   ` [PATCH v2 3/3] tools: add selftest for BPF_F_ZERO_SEED Lorenz Bauer
2018-10-08 23:15     ` Song Liu
2018-11-16 11:41 ` [PATCH v3 0/4] bpf: allow zero-initialising hash map seed Lorenz Bauer
2018-11-16 11:41   ` [PATCH v3 1/4] bpf: allow zero-initializing " Lorenz Bauer
2018-11-16 11:41   ` [PATCH v3 2/4] bpf: move BPF_F_QUERY_EFFECTIVE after map flags Lorenz Bauer
2018-11-16 11:41   ` [PATCH v3 3/4] tools: sync linux/bpf.h Lorenz Bauer
2018-11-16 11:41   ` [PATCH v3 4/4] tools: add selftest for BPF_F_ZERO_SEED Lorenz Bauer
2018-11-16 17:33   ` [PATCH v3 0/4] bpf: allow zero-initialising hash map seed Song Liu
2018-11-16 17:34   ` Song Liu
2018-11-19 23:56   ` Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181001104509.24211-2-lmb@cloudflare.com \
    --to=lmb@cloudflare.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-api@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).