Commit 9579e2c2 authored by Steen Hegelund's avatar Steen Hegelund Committed by David S. Miller

net: microchip: sparx5: Add VCAP admin locking in debugFS

This ensures that the admin lock is taken before the debugFS functions
starts iterating the VCAP rules.
It also adds a separate function to decode a rule, which expects the lock
to have been taken before it is called.
Signed-off-by: default avatarSteen Hegelund <steen.hegelund@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 975d86ac
...@@ -2170,47 +2170,53 @@ void vcap_free_rule(struct vcap_rule *rule) ...@@ -2170,47 +2170,53 @@ void vcap_free_rule(struct vcap_rule *rule)
} }
EXPORT_SYMBOL_GPL(vcap_free_rule); EXPORT_SYMBOL_GPL(vcap_free_rule);
struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id) /* Decode a rule from the VCAP cache and return a copy */
struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem)
{ {
struct vcap_rule_internal *elem;
struct vcap_rule_internal *ri; struct vcap_rule_internal *ri;
int err; int err;
ri = NULL;
err = vcap_api_check(vctrl);
if (err)
return ERR_PTR(err);
elem = vcap_lookup_rule(vctrl, id);
if (!elem)
return NULL;
mutex_lock(&elem->admin->lock);
ri = vcap_dup_rule(elem, elem->state == VCAP_RS_DISABLED); ri = vcap_dup_rule(elem, elem->state == VCAP_RS_DISABLED);
if (IS_ERR(ri)) if (IS_ERR(ri))
goto unlock; return ERR_PTR(PTR_ERR(ri));
if (ri->state == VCAP_RS_DISABLED) if (ri->state == VCAP_RS_DISABLED)
goto unlock; goto out;
err = vcap_read_rule(ri); err = vcap_read_rule(ri);
if (err) { if (err)
ri = ERR_PTR(err); return ERR_PTR(err);
goto unlock;
}
err = vcap_decode_keyset(ri); err = vcap_decode_keyset(ri);
if (err) { if (err)
ri = ERR_PTR(err); return ERR_PTR(err);
goto unlock;
}
err = vcap_decode_actionset(ri); err = vcap_decode_actionset(ri);
if (err) { if (err)
ri = ERR_PTR(err); return ERR_PTR(err);
goto unlock;
}
unlock: out:
return &ri->data;
}
struct vcap_rule *vcap_get_rule(struct vcap_control *vctrl, u32 id)
{
struct vcap_rule_internal *elem;
struct vcap_rule *rule;
int err;
err = vcap_api_check(vctrl);
if (err)
return ERR_PTR(err);
elem = vcap_lookup_rule(vctrl, id);
if (!elem)
return NULL;
mutex_lock(&elem->admin->lock);
rule = vcap_decode_rule(elem);
mutex_unlock(&elem->admin->lock); mutex_unlock(&elem->admin->lock);
return (struct vcap_rule *)ri; return rule;
} }
EXPORT_SYMBOL_GPL(vcap_get_rule); EXPORT_SYMBOL_GPL(vcap_get_rule);
......
...@@ -295,7 +295,7 @@ static int vcap_show_admin(struct vcap_control *vctrl, ...@@ -295,7 +295,7 @@ static int vcap_show_admin(struct vcap_control *vctrl,
vcap_show_admin_info(vctrl, admin, out); vcap_show_admin_info(vctrl, admin, out);
list_for_each_entry(elem, &admin->rules, list) { list_for_each_entry(elem, &admin->rules, list) {
vrule = vcap_get_rule(vctrl, elem->data.id); vrule = vcap_decode_rule(elem);
if (IS_ERR_OR_NULL(vrule)) { if (IS_ERR_OR_NULL(vrule)) {
ret = PTR_ERR(vrule); ret = PTR_ERR(vrule);
break; break;
...@@ -404,8 +404,12 @@ static int vcap_debugfs_show(struct seq_file *m, void *unused) ...@@ -404,8 +404,12 @@ static int vcap_debugfs_show(struct seq_file *m, void *unused)
.prf = (void *)seq_printf, .prf = (void *)seq_printf,
.dst = m, .dst = m,
}; };
int ret;
return vcap_show_admin(info->vctrl, info->admin, &out); mutex_lock(&info->admin->lock);
ret = vcap_show_admin(info->vctrl, info->admin, &out);
mutex_unlock(&info->admin->lock);
return ret;
} }
DEFINE_SHOW_ATTRIBUTE(vcap_debugfs); DEFINE_SHOW_ATTRIBUTE(vcap_debugfs);
...@@ -417,8 +421,12 @@ static int vcap_raw_debugfs_show(struct seq_file *m, void *unused) ...@@ -417,8 +421,12 @@ static int vcap_raw_debugfs_show(struct seq_file *m, void *unused)
.prf = (void *)seq_printf, .prf = (void *)seq_printf,
.dst = m, .dst = m,
}; };
int ret;
return vcap_show_admin_raw(info->vctrl, info->admin, &out); mutex_lock(&info->admin->lock);
ret = vcap_show_admin_raw(info->vctrl, info->admin, &out);
mutex_unlock(&info->admin->lock);
return ret;
} }
DEFINE_SHOW_ATTRIBUTE(vcap_raw_debugfs); DEFINE_SHOW_ATTRIBUTE(vcap_raw_debugfs);
......
...@@ -118,4 +118,7 @@ int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt, ...@@ -118,4 +118,7 @@ int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt,
/* Get the keysets that matches the rule key type/mask */ /* Get the keysets that matches the rule key type/mask */
int vcap_rule_get_keysets(struct vcap_rule_internal *ri, int vcap_rule_get_keysets(struct vcap_rule_internal *ri,
struct vcap_keyset_list *matches); struct vcap_keyset_list *matches);
/* Decode a rule from the VCAP cache and return a copy */
struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem);
#endif /* __VCAP_API_PRIVATE__ */ #endif /* __VCAP_API_PRIVATE__ */
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