mptcp.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Mat Martineau <mathew.j.martineau@linux.intel.com>,
	mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-net 1/3] mptcp: Avoid acquiring PM lock for subflow priority changes
Date: Wed, 29 Jun 2022 21:57:13 +0200	[thread overview]
Message-ID: <c5935b379d4517af3edf6e7c567445032e8bf39b.camel@redhat.com> (raw)
In-Reply-To: <20220628190356.326233-2-mathew.j.martineau@linux.intel.com>

On Tue, 2022-06-28 at 12:03 -0700, Mat Martineau wrote:
> The in-kernel path manager code for changing subflow flags acquired both
> the msk socket lock and the PM lock when possibly changing the "backup"
> and "fullmesh" flags. mptcp_pm_nl_mp_prio_send_ack() does not access
> anything protected by the PM lock, and it must release and reacquire
> the PM lock.
> 
> By pushing the PM lock to where it is needed in mptcp_pm_nl_fullmesh(),
> the lock is only acquired when the fullmesh flag is changed and the
> backup flag code no longer has to release and reacquire the PM lock.
> 
> This change also makes it possible to call
> mptcp_pm_nl_mp_prio_send_ack() for the userspace PM commands without
> manipulating the in-kernel PM lock.
> 
> Fixes: 0f9f696a502e ("mptcp: add set_flags command in PM netlink")
> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
> ---
>  net/mptcp/pm_netlink.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
> index e099f2a12504..d04b34fc9a8e 100644
> --- a/net/mptcp/pm_netlink.c
> +++ b/net/mptcp/pm_netlink.c
> @@ -741,10 +741,8 @@ static int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
>  		subflow->request_bkup = bkup;
>  		__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIOTX);
>  
> -		spin_unlock_bh(&msk->pm.lock);
>  		pr_debug("send ack for mp_prio");
>  		mptcp_subflow_send_ack(ssk);
> -		spin_lock_bh(&msk->pm.lock);
>  
>  		return 0;
>  	}
> @@ -1816,8 +1814,10 @@ static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk,
>  
>  	list.ids[list.nr++] = addr->id;
>  
> +	spin_lock_bh(&msk->pm.lock);
>  	mptcp_pm_nl_rm_subflow_received(msk, &list);
>  	mptcp_pm_create_subflow_or_signal_addr(msk);
> +	spin_unlock_bh(&msk->pm.lock);
>  }
>  
>  static int mptcp_nl_set_flags(struct net *net,
> @@ -1835,12 +1835,10 @@ static int mptcp_nl_set_flags(struct net *net,
>  			goto next;
>  
>  		lock_sock(sk);
> -		spin_lock_bh(&msk->pm.lock);
>  		if (changed & MPTCP_PM_ADDR_FLAG_BACKUP)
>  			ret = mptcp_pm_nl_mp_prio_send_ack(msk, addr, bkup);

This causes a

BUG: using __this_cpu_add() in preemptible code

as
		__MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPPRIOTX);

in mptcp_pm_nl_mp_prio_send_ack is no longer in atomic context. Either
use MPTCP_INC_STATS() and/or move the increment in write_options (I
think the latter is better)

>  		if (changed & MPTCP_PM_ADDR_FLAG_FULLMESH)
>  			mptcp_pm_nl_fullmesh(msk, addr);
> -		spin_unlock_bh(&msk->pm.lock);
>  		release_sock(sk);
>  
>  next:


  reply	other threads:[~2022-06-29 19:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 19:03 [PATCH mptcp-net 0/3] Locking fixes for subflow flag changes Mat Martineau
2022-06-28 19:03 ` [PATCH mptcp-net 1/3] mptcp: Avoid acquiring PM lock for subflow priority changes Mat Martineau
2022-06-29 19:57   ` Paolo Abeni [this message]
2022-06-28 19:03 ` [PATCH mptcp-net 2/3] mptcp: Add a variant of mptcp_subflow_send_ack() for locked subflows Mat Martineau
2022-06-28 19:03 ` [PATCH mptcp-net 3/3] mptcp: Acquire the subflow socket lock before modifying MP_PRIO flags Mat Martineau
2022-06-28 20:50   ` mptcp: Acquire the subflow socket lock before modifying MP_PRIO flags: Tests Results MPTCP CI
2022-06-29 19:59   ` [PATCH mptcp-net 3/3] mptcp: Acquire the subflow socket lock before modifying MP_PRIO flags Paolo Abeni
2022-06-29 20:51     ` Mat Martineau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5935b379d4517af3edf6e7c567445032e8bf39b.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=mathew.j.martineau@linux.intel.com \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).