#include "datapath.h"
#include "table.h"
+#include <linux/genetlink.h>
#include <linux/gfp.h>
#include <linux/slab.h>
#include <linux/mm.h>
struct tbl_node *objs[];
};
+static struct tbl_bucket *get_bucket(struct tbl_bucket __rcu *bucket)
+{
+ return rcu_dereference_check(bucket, rcu_read_lock_held() ||
+ lockdep_genl_is_held());
+}
+
+static struct tbl_bucket *get_bucket_protected(struct tbl_bucket __rcu *bucket)
+{
+ return rcu_dereference_protected(bucket, lockdep_genl_is_held());
+}
+
static inline int bucket_size(int n_objs)
{
return sizeof(struct tbl_bucket) + sizeof(struct tbl_node *) * n_objs;
int (*cmp)(const struct tbl_node *, void *))
{
struct tbl_bucket __rcu **bucketp = find_bucket(table, hash);
- struct tbl_bucket *bucket = rcu_dereference(*bucketp);
+ struct tbl_bucket *bucket = get_bucket(*bucketp);
int index;
if (!bucket)
struct tbl_bucket *bucket;
unsigned int i;
- bucket = rcu_dereference(l2[l2_idx]);
+ bucket = get_bucket(l2[l2_idx]);
if (!bucket)
continue;
for (l2_idx = s_l2_idx; l2_idx < TBL_L2_SIZE; l2_idx++) {
struct tbl_bucket *bucket;
- bucket = rcu_dereference(l2[l2_idx]);
+ bucket = get_bucket_protected(l2[l2_idx]);
if (bucket && s_obj < bucket->n_objs) {
*bucketp = (l1_idx << TBL_L1_SHIFT) + l2_idx;
*objp = s_obj + 1;
int tbl_insert(struct tbl *table, struct tbl_node *target, u32 hash)
{
struct tbl_bucket __rcu **oldp = find_bucket(table, hash);
- struct tbl_bucket *old = rcu_dereference(*oldp);
+ struct tbl_bucket *old = get_bucket_protected(*oldp);
unsigned int n = old ? old->n_objs : 0;
struct tbl_bucket *new = bucket_alloc(n + 1);
int tbl_remove(struct tbl *table, struct tbl_node *target)
{
struct tbl_bucket __rcu **oldp = find_bucket(table, target->hash);
- struct tbl_bucket *old = rcu_dereference(*oldp);
+ struct tbl_bucket *old = get_bucket_protected(*oldp);
unsigned int n = old->n_objs;
struct tbl_bucket *new;