Commit 422c032a authored by Paul Blakey's avatar Paul Blakey Committed by Pablo Neira Ayuso

netfilter: flowtable: Use rw sem as flow block lock

Currently flow offload threads are synchronized by the flow block mutex.
Use rw lock instead to increase flow insertion (read) concurrency.
Signed-off-by: default avatarPaul Blakey <paulb@mellanox.com>
Reviewed-by: default avatarOz Shlomo <ozsh@mellanox.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 0a6a9515
...@@ -74,7 +74,7 @@ struct nf_flowtable { ...@@ -74,7 +74,7 @@ struct nf_flowtable {
struct delayed_work gc_work; struct delayed_work gc_work;
unsigned int flags; unsigned int flags;
struct flow_block flow_block; struct flow_block flow_block;
struct mutex flow_block_lock; /* Guards flow_block */ struct rw_semaphore flow_block_lock; /* Guards flow_block */
possible_net_t net; possible_net_t net;
}; };
......
...@@ -392,7 +392,7 @@ int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table, ...@@ -392,7 +392,7 @@ int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table,
struct flow_block_cb *block_cb; struct flow_block_cb *block_cb;
int err = 0; int err = 0;
mutex_lock(&flow_table->flow_block_lock); down_write(&flow_table->flow_block_lock);
block_cb = flow_block_cb_lookup(block, cb, cb_priv); block_cb = flow_block_cb_lookup(block, cb, cb_priv);
if (block_cb) { if (block_cb) {
err = -EEXIST; err = -EEXIST;
...@@ -408,7 +408,7 @@ int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table, ...@@ -408,7 +408,7 @@ int nf_flow_table_offload_add_cb(struct nf_flowtable *flow_table,
list_add_tail(&block_cb->list, &block->cb_list); list_add_tail(&block_cb->list, &block->cb_list);
unlock: unlock:
mutex_unlock(&flow_table->flow_block_lock); up_write(&flow_table->flow_block_lock);
return err; return err;
} }
EXPORT_SYMBOL_GPL(nf_flow_table_offload_add_cb); EXPORT_SYMBOL_GPL(nf_flow_table_offload_add_cb);
...@@ -419,13 +419,13 @@ void nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table, ...@@ -419,13 +419,13 @@ void nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table,
struct flow_block *block = &flow_table->flow_block; struct flow_block *block = &flow_table->flow_block;
struct flow_block_cb *block_cb; struct flow_block_cb *block_cb;
mutex_lock(&flow_table->flow_block_lock); down_write(&flow_table->flow_block_lock);
block_cb = flow_block_cb_lookup(block, cb, cb_priv); block_cb = flow_block_cb_lookup(block, cb, cb_priv);
if (block_cb) if (block_cb)
list_del(&block_cb->list); list_del(&block_cb->list);
else else
WARN_ON(true); WARN_ON(true);
mutex_unlock(&flow_table->flow_block_lock); up_write(&flow_table->flow_block_lock);
} }
EXPORT_SYMBOL_GPL(nf_flow_table_offload_del_cb); EXPORT_SYMBOL_GPL(nf_flow_table_offload_del_cb);
...@@ -551,7 +551,7 @@ int nf_flow_table_init(struct nf_flowtable *flowtable) ...@@ -551,7 +551,7 @@ int nf_flow_table_init(struct nf_flowtable *flowtable)
INIT_DEFERRABLE_WORK(&flowtable->gc_work, nf_flow_offload_work_gc); INIT_DEFERRABLE_WORK(&flowtable->gc_work, nf_flow_offload_work_gc);
flow_block_init(&flowtable->flow_block); flow_block_init(&flowtable->flow_block);
mutex_init(&flowtable->flow_block_lock); init_rwsem(&flowtable->flow_block_lock);
err = rhashtable_init(&flowtable->rhashtable, err = rhashtable_init(&flowtable->rhashtable,
&nf_flow_offload_rhash_params); &nf_flow_offload_rhash_params);
...@@ -614,7 +614,6 @@ void nf_flow_table_free(struct nf_flowtable *flow_table) ...@@ -614,7 +614,6 @@ void nf_flow_table_free(struct nf_flowtable *flow_table)
nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, flow_table); nf_flow_table_iterate(flow_table, nf_flow_offload_gc_step, flow_table);
nf_flow_table_offload_flush(flow_table); nf_flow_table_offload_flush(flow_table);
rhashtable_destroy(&flow_table->rhashtable); rhashtable_destroy(&flow_table->rhashtable);
mutex_destroy(&flow_table->flow_block_lock);
} }
EXPORT_SYMBOL_GPL(nf_flow_table_free); EXPORT_SYMBOL_GPL(nf_flow_table_free);
......
...@@ -691,7 +691,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable, ...@@ -691,7 +691,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
if (cmd == FLOW_CLS_REPLACE) if (cmd == FLOW_CLS_REPLACE)
cls_flow.rule = flow_rule->rule; cls_flow.rule = flow_rule->rule;
mutex_lock(&flowtable->flow_block_lock); down_read(&flowtable->flow_block_lock);
list_for_each_entry(block_cb, block_cb_list, list) { list_for_each_entry(block_cb, block_cb_list, list) {
err = block_cb->cb(TC_SETUP_CLSFLOWER, &cls_flow, err = block_cb->cb(TC_SETUP_CLSFLOWER, &cls_flow,
block_cb->cb_priv); block_cb->cb_priv);
...@@ -700,7 +700,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable, ...@@ -700,7 +700,7 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
i++; i++;
} }
mutex_unlock(&flowtable->flow_block_lock); up_read(&flowtable->flow_block_lock);
if (cmd == FLOW_CLS_STATS) if (cmd == FLOW_CLS_STATS)
memcpy(stats, &cls_flow.stats, sizeof(*stats)); memcpy(stats, &cls_flow.stats, sizeof(*stats));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment