Commit 72603d20 authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

mptcp: use WRITE_ONCE for the pernet *_max

This patch uses WRITE_ONCE() for all the pernet add_addr_signal_max,
add_addr_accept_max, local_addr_max and subflows_max fields in struct
pm_nl_pernet to avoid concurrency issues.
Signed-off-by: default avatarGeliang Tang <geliangtang@gmail.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e6d6ca6e
...@@ -572,6 +572,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, ...@@ -572,6 +572,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
struct mptcp_pm_addr_entry *entry) struct mptcp_pm_addr_entry *entry)
{ {
struct mptcp_pm_addr_entry *cur; struct mptcp_pm_addr_entry *cur;
unsigned int addr_max;
int ret = -EINVAL; int ret = -EINVAL;
spin_lock_bh(&pernet->lock); spin_lock_bh(&pernet->lock);
...@@ -614,10 +615,14 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, ...@@ -614,10 +615,14 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
if (entry->addr.id > pernet->next_id) if (entry->addr.id > pernet->next_id)
pernet->next_id = entry->addr.id; pernet->next_id = entry->addr.id;
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
pernet->add_addr_signal_max++; addr_max = pernet->add_addr_signal_max;
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) WRITE_ONCE(pernet->add_addr_signal_max, addr_max + 1);
pernet->local_addr_max++; }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
addr_max = pernet->local_addr_max;
WRITE_ONCE(pernet->local_addr_max, addr_max + 1);
}
pernet->addrs++; pernet->addrs++;
list_add_tail_rcu(&entry->list, &pernet->local_addr_list); list_add_tail_rcu(&entry->list, &pernet->local_addr_list);
...@@ -912,6 +917,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) ...@@ -912,6 +917,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
struct mptcp_pm_addr_entry addr, *entry; struct mptcp_pm_addr_entry addr, *entry;
unsigned int addr_max;
int ret; int ret;
ret = mptcp_pm_parse_addr(attr, info, false, &addr); ret = mptcp_pm_parse_addr(attr, info, false, &addr);
...@@ -925,10 +931,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info) ...@@ -925,10 +931,14 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
spin_unlock_bh(&pernet->lock); spin_unlock_bh(&pernet->lock);
return -EINVAL; return -EINVAL;
} }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) {
pernet->add_addr_signal_max--; addr_max = pernet->add_addr_signal_max;
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) WRITE_ONCE(pernet->add_addr_signal_max, addr_max - 1);
pernet->local_addr_max--; }
if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW) {
addr_max = pernet->local_addr_max;
WRITE_ONCE(pernet->local_addr_max, addr_max - 1);
}
pernet->addrs--; pernet->addrs--;
list_del_rcu(&entry->list); list_del_rcu(&entry->list);
...@@ -956,9 +966,9 @@ static void __flush_addrs(struct net *net, struct list_head *list) ...@@ -956,9 +966,9 @@ static void __flush_addrs(struct net *net, struct list_head *list)
static void __reset_counters(struct pm_nl_pernet *pernet) static void __reset_counters(struct pm_nl_pernet *pernet)
{ {
pernet->add_addr_signal_max = 0; WRITE_ONCE(pernet->add_addr_signal_max, 0);
pernet->add_addr_accept_max = 0; WRITE_ONCE(pernet->add_addr_accept_max, 0);
pernet->local_addr_max = 0; WRITE_ONCE(pernet->local_addr_max, 0);
pernet->addrs = 0; pernet->addrs = 0;
} }
......
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