b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Simon Wunderlich <sw@simonwunderlich.de>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Sven Eckelmann <sven@narfation.org>,
	Simon Wunderlich <sw@simonwunderlich.de>
Subject: [B.A.T.M.A.N.] [PATCH 09/16] batman-adv: Store modification counter via hash helpers
Date: Wed, 14 Nov 2018 15:07:57 +0100	[thread overview]
Message-ID: <20181114140804.18381-10-sw@simonwunderlich.de> (raw)
In-Reply-To: <20181114140804.18381-1-sw@simonwunderlich.de>

From: Sven Eckelmann <sven@narfation.org>

Multiple datastructures use the hash helper functions to add and remove
entries from the simple hlist based hashes. These are often also dumped to
userspace via netlink and thus should have a generation sequence counter.

Reported-by: Matthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/hash.c | 2 ++
 net/batman-adv/hash.h | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 7b49e4001778..9194f4d891b1 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -32,6 +32,8 @@ static void batadv_hash_init(struct batadv_hashtable *hash)
 		INIT_HLIST_HEAD(&hash->table[i]);
 		spin_lock_init(&hash->list_locks[i]);
 	}
+
+	atomic_set(&hash->generation, 0);
 }
 
 /**
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index 9490a7ca2ba6..0e36fa1c7c3e 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -21,6 +21,7 @@
 
 #include "main.h"
 
+#include <linux/atomic.h>
 #include <linux/compiler.h>
 #include <linux/list.h>
 #include <linux/rculist.h>
@@ -58,6 +59,9 @@ struct batadv_hashtable {
 
 	/** @size: size of hashtable */
 	u32 size;
+
+	/** @generation: current (generation) sequence number */
+	atomic_t generation;
 };
 
 /* allocates and clears the hash */
@@ -112,6 +116,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,
 
 	/* no duplicate found in list, add new element */
 	hlist_add_head_rcu(data_node, head);
+	atomic_inc(&hash->generation);
 
 	ret = 0;
 
@@ -154,6 +159,7 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
 
 		data_save = node;
 		hlist_del_rcu(node);
+		atomic_inc(&hash->generation);
 		break;
 	}
 	spin_unlock_bh(&hash->list_locks[index]);
-- 
2.11.0


  parent reply	other threads:[~2018-11-14 14:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-14 14:07 [B.A.T.M.A.N.] [PATCH 00/16] pull request for net-next: batman-adv 2018-11-14 Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 01/16] batman-adv: Start new development cycle Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 02/16] batman-adv: Drop unused lockdep include Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 03/16] batman-adv: Add includes for deprecation warning Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 04/16] batman-adv: Improve includes for trace functionality Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 05/16] batman-adv: Allow to use BATMAN_ADV_DEBUG without BATMAN_ADV_DEBUGFS Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 06/16] batman-adv: Fix description for BATMAN_ADV_DEBUG Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 07/16] batman-adv: Add inconsistent gateway netlink dump detection Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 08/16] batman-adv: Add inconsistent hardif " Simon Wunderlich
2018-11-14 14:07 ` Simon Wunderlich [this message]
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 10/16] batman-adv: Add inconsistent backbone " Simon Wunderlich
2018-11-14 14:07 ` [B.A.T.M.A.N.] [PATCH 11/16] batman-adv: Add inconsistent claim " Simon Wunderlich
2018-11-14 14:08 ` [B.A.T.M.A.N.] [PATCH 12/16] batman-adv: Add inconsistent dat " Simon Wunderlich
2018-11-14 14:08 ` [B.A.T.M.A.N.] [PATCH 13/16] batman-adv: Add inconsistent local TT " Simon Wunderlich
2018-11-14 14:08 ` [B.A.T.M.A.N.] [PATCH 14/16] batman-adv: Add inconsistent multicast " Simon Wunderlich
2018-11-14 14:08 ` [B.A.T.M.A.N.] [PATCH 15/16] batman-adv: Move CRC16 dependency to BATMAN_ADV_BLA Simon Wunderlich
2018-11-14 14:08 ` [B.A.T.M.A.N.] [PATCH 16/16] batman-adv: enable MCAST by default at compile time Simon Wunderlich
2018-11-16  0:14 ` [B.A.T.M.A.N.] [PATCH 00/16] pull request for net-next: batman-adv 2018-11-14 David Miller

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=20181114140804.18381-10-sw@simonwunderlich.de \
    --to=sw@simonwunderlich.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sven@narfation.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).