Commit 3abc05d9 authored by Florian Westphal's avatar Florian Westphal Committed by Jakub Kicinski

mptcp: pm: add lockdep assertions

Add a few assertions to make sure functions are called with the needed
locks held.
Two functions gain might_sleep annotations because they contain
conditional calls to functions that sleep.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1002b89f
...@@ -20,6 +20,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, ...@@ -20,6 +20,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
pr_debug("msk=%p, local_id=%d", msk, addr->id); pr_debug("msk=%p, local_id=%d", msk, addr->id);
lockdep_assert_held(&msk->pm.lock);
if (add_addr) { if (add_addr) {
pr_warn("addr_signal error, add_addr=%d", add_addr); pr_warn("addr_signal error, add_addr=%d", add_addr);
return -EINVAL; return -EINVAL;
......
...@@ -145,6 +145,8 @@ select_local_address(const struct pm_nl_pernet *pernet, ...@@ -145,6 +145,8 @@ select_local_address(const struct pm_nl_pernet *pernet,
struct mptcp_pm_addr_entry *entry, *ret = NULL; struct mptcp_pm_addr_entry *entry, *ret = NULL;
struct sock *sk = (struct sock *)msk; struct sock *sk = (struct sock *)msk;
msk_owned_by_me(msk);
rcu_read_lock(); rcu_read_lock();
__mptcp_flush_join_list(msk); __mptcp_flush_join_list(msk);
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
...@@ -246,6 +248,8 @@ lookup_anno_list_by_saddr(struct mptcp_sock *msk, ...@@ -246,6 +248,8 @@ lookup_anno_list_by_saddr(struct mptcp_sock *msk,
{ {
struct mptcp_pm_add_entry *entry; struct mptcp_pm_add_entry *entry;
lockdep_assert_held(&msk->pm.lock);
list_for_each_entry(entry, &msk->pm.anno_list, list) { list_for_each_entry(entry, &msk->pm.anno_list, list) {
if (addresses_equal(&entry->addr, addr, true)) if (addresses_equal(&entry->addr, addr, true))
return entry; return entry;
...@@ -342,6 +346,8 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, ...@@ -342,6 +346,8 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
struct sock *sk = (struct sock *)msk; struct sock *sk = (struct sock *)msk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
lockdep_assert_held(&msk->pm.lock);
if (lookup_anno_list_by_saddr(msk, &entry->addr)) if (lookup_anno_list_by_saddr(msk, &entry->addr))
return false; return false;
...@@ -496,6 +502,9 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk) ...@@ -496,6 +502,9 @@ void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk)
{ {
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
msk_owned_by_me(msk);
lockdep_assert_held(&msk->pm.lock);
if (!mptcp_pm_should_add_signal(msk)) if (!mptcp_pm_should_add_signal(msk))
return; return;
...@@ -566,6 +575,8 @@ void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk) ...@@ -566,6 +575,8 @@ void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
pr_debug("address rm_id %d", msk->pm.rm_id); pr_debug("address rm_id %d", msk->pm.rm_id);
msk_owned_by_me(msk);
if (!msk->pm.rm_id) if (!msk->pm.rm_id)
return; return;
...@@ -601,6 +612,8 @@ void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id) ...@@ -601,6 +612,8 @@ void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id)
pr_debug("subflow rm_id %d", rm_id); pr_debug("subflow rm_id %d", rm_id);
msk_owned_by_me(msk);
if (!rm_id) if (!rm_id)
return; return;
......
...@@ -2187,6 +2187,8 @@ static void __mptcp_close_subflow(struct mptcp_sock *msk) ...@@ -2187,6 +2187,8 @@ static void __mptcp_close_subflow(struct mptcp_sock *msk)
{ {
struct mptcp_subflow_context *subflow, *tmp; struct mptcp_subflow_context *subflow, *tmp;
might_sleep();
list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) { list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow); struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
...@@ -2529,6 +2531,8 @@ static void __mptcp_destroy_sock(struct sock *sk) ...@@ -2529,6 +2531,8 @@ static void __mptcp_destroy_sock(struct sock *sk)
pr_debug("msk=%p", msk); pr_debug("msk=%p", msk);
might_sleep();
/* dispose the ancillatory tcp socket, if any */ /* dispose the ancillatory tcp socket, if any */
if (msk->subflow) { if (msk->subflow) {
iput(SOCK_INODE(msk->subflow)); iput(SOCK_INODE(msk->subflow));
......
...@@ -288,6 +288,11 @@ struct mptcp_sock { ...@@ -288,6 +288,11 @@ struct mptcp_sock {
#define mptcp_for_each_subflow(__msk, __subflow) \ #define mptcp_for_each_subflow(__msk, __subflow) \
list_for_each_entry(__subflow, &((__msk)->conn_list), node) list_for_each_entry(__subflow, &((__msk)->conn_list), node)
static inline void msk_owned_by_me(const struct mptcp_sock *msk)
{
sock_owned_by_me((const struct sock *)msk);
}
static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
{ {
return (struct mptcp_sock *)sk; return (struct mptcp_sock *)sk;
......
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