Commit 71c9de99 authored by Steen Hegelund's avatar Steen Hegelund Committed by David S. Miller

net: microchip: sparx5: Add VCAP locking to protect rules

This ensures that the VCAP cache and the lists maintained in the VCAP
instance is protected when accessed by different clients.
Signed-off-by: default avatarSteen Hegelund <steen.hegelund@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 72d84dd6
...@@ -579,6 +579,7 @@ static void sparx5_vcap_admin_free(struct vcap_admin *admin) ...@@ -579,6 +579,7 @@ static void sparx5_vcap_admin_free(struct vcap_admin *admin)
{ {
if (!admin) if (!admin)
return; return;
mutex_destroy(&admin->lock);
kfree(admin->cache.keystream); kfree(admin->cache.keystream);
kfree(admin->cache.maskstream); kfree(admin->cache.maskstream);
kfree(admin->cache.actionstream); kfree(admin->cache.actionstream);
...@@ -598,6 +599,7 @@ sparx5_vcap_admin_alloc(struct sparx5 *sparx5, struct vcap_control *ctrl, ...@@ -598,6 +599,7 @@ sparx5_vcap_admin_alloc(struct sparx5 *sparx5, struct vcap_control *ctrl,
INIT_LIST_HEAD(&admin->list); INIT_LIST_HEAD(&admin->list);
INIT_LIST_HEAD(&admin->rules); INIT_LIST_HEAD(&admin->rules);
INIT_LIST_HEAD(&admin->enabled); INIT_LIST_HEAD(&admin->enabled);
mutex_init(&admin->lock);
admin->vtype = cfg->vtype; admin->vtype = cfg->vtype;
admin->vinst = cfg->vinst; admin->vinst = cfg->vinst;
admin->lookups = cfg->lookups; admin->lookups = cfg->lookups;
......
...@@ -1054,6 +1054,7 @@ int vcap_add_rule(struct vcap_rule *rule) ...@@ -1054,6 +1054,7 @@ int vcap_add_rule(struct vcap_rule *rule)
if (ret) if (ret)
return ret; return ret;
/* Insert the new rule in the list of vcap rules */ /* Insert the new rule in the list of vcap rules */
mutex_lock(&ri->admin->lock);
ret = vcap_insert_rule(ri, &move); ret = vcap_insert_rule(ri, &move);
if (ret < 0) { if (ret < 0) {
pr_err("%s:%d: could not insert rule in vcap list: %d\n", pr_err("%s:%d: could not insert rule in vcap list: %d\n",
...@@ -1072,6 +1073,7 @@ int vcap_add_rule(struct vcap_rule *rule) ...@@ -1072,6 +1073,7 @@ int vcap_add_rule(struct vcap_rule *rule)
if (ret) if (ret)
pr_err("%s:%d: rule write error: %d\n", __func__, __LINE__, ret); pr_err("%s:%d: rule write error: %d\n", __func__, __LINE__, ret);
out: out:
mutex_unlock(&ri->admin->lock);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(vcap_add_rule); EXPORT_SYMBOL_GPL(vcap_add_rule);
...@@ -1221,9 +1223,11 @@ int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id) ...@@ -1221,9 +1223,11 @@ int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id)
gap = vcap_fill_rule_gap(ri); gap = vcap_fill_rule_gap(ri);
/* Delete the rule from the list of rules and the cache */ /* Delete the rule from the list of rules and the cache */
mutex_lock(&admin->lock);
list_del(&ri->list); list_del(&ri->list);
vctrl->ops->init(ndev, admin, admin->last_used_addr, ri->size + gap); vctrl->ops->init(ndev, admin, admin->last_used_addr, ri->size + gap);
kfree(ri); kfree(ri);
mutex_unlock(&admin->lock);
/* Update the last used address, set to default when no rules */ /* Update the last used address, set to default when no rules */
if (list_empty(&admin->rules)) { if (list_empty(&admin->rules)) {
...@@ -1246,6 +1250,8 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin) ...@@ -1246,6 +1250,8 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin)
if (ret) if (ret)
return ret; return ret;
mutex_lock(&admin->lock);
list_for_each_entry_safe(ri, next_ri, &admin->rules, list) { list_for_each_entry_safe(ri, next_ri, &admin->rules, list) {
vctrl->ops->init(ri->ndev, admin, ri->addr, ri->size); vctrl->ops->init(ri->ndev, admin, ri->addr, ri->size);
list_del(&ri->list); list_del(&ri->list);
...@@ -1258,6 +1264,7 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin) ...@@ -1258,6 +1264,7 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin)
list_del(&eport->list); list_del(&eport->list);
kfree(eport); kfree(eport);
} }
mutex_unlock(&admin->lock);
return 0; return 0;
} }
...@@ -1687,10 +1694,13 @@ int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev, ...@@ -1687,10 +1694,13 @@ int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev,
if (chain_id) { if (chain_id) {
if (vcap_is_enabled(admin, ndev, cookie)) if (vcap_is_enabled(admin, ndev, cookie))
return -EADDRINUSE; return -EADDRINUSE;
mutex_lock(&admin->lock);
vcap_enable(admin, ndev, cookie); vcap_enable(admin, ndev, cookie);
} else { } else {
mutex_lock(&admin->lock);
vcap_disable(admin, ndev, cookie); vcap_disable(admin, ndev, cookie);
} }
mutex_unlock(&admin->lock);
return 0; return 0;
} }
......
...@@ -167,6 +167,7 @@ struct vcap_admin { ...@@ -167,6 +167,7 @@ struct vcap_admin {
struct list_head list; /* for insertion in vcap_control */ struct list_head list; /* for insertion in vcap_control */
struct list_head rules; /* list of rules */ struct list_head rules; /* list of rules */
struct list_head enabled; /* list of enabled ports */ struct list_head enabled; /* list of enabled ports */
struct mutex lock; /* control access to rules */
enum vcap_type vtype; /* type of vcap */ enum vcap_type vtype; /* type of vcap */
int vinst; /* instance number within the same type */ int vinst; /* instance number within the same type */
int first_cid; /* first chain id in this vcap */ int first_cid; /* first chain id in this vcap */
......
...@@ -625,6 +625,7 @@ static int vcap_show_admin(struct vcap_control *vctrl, ...@@ -625,6 +625,7 @@ static int vcap_show_admin(struct vcap_control *vctrl,
int ret = 0; int ret = 0;
vcap_show_admin_info(vctrl, admin, out); vcap_show_admin_info(vctrl, admin, out);
mutex_lock(&admin->lock);
list_for_each_entry(elem, &admin->rules, list) { list_for_each_entry(elem, &admin->rules, list) {
ri = vcap_dup_rule(elem); ri = vcap_dup_rule(elem);
if (IS_ERR(ri)) if (IS_ERR(ri))
...@@ -638,6 +639,7 @@ static int vcap_show_admin(struct vcap_control *vctrl, ...@@ -638,6 +639,7 @@ static int vcap_show_admin(struct vcap_control *vctrl,
free_rule: free_rule:
vcap_free_rule((struct vcap_rule *)ri); vcap_free_rule((struct vcap_rule *)ri);
} }
mutex_unlock(&admin->lock);
return ret; return ret;
} }
......
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