From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3428D19CD0B for ; Tue, 25 Feb 2025 18:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740507322; cv=none; b=Tm9yRuMDoE/+Jb0560Pl/ML+Jj7tJ5F6NOQNKPzgkwmBmZP0v7N+edH0UQlZAOh2EgVZxYYtr/2eGex2YL28yA3i5krQhm91o4VNchuBTmhVg7b5NqFDNpTh5CByqnkWy38InUFboPA/sixT+hpycGDw+Xekm3KSiqgKIXSThEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740507322; c=relaxed/simple; bh=HjlJmrZ0SxP4ehKsEiMi8e3l28z5QdOJ2UkYN5fJ53s=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=pVy1jLlJjjUJ0ERAqg0LKCOUqWIEETwEMXAMWIiHmW/9+WOWVrMLVSraZ1dwun54ijxuC2v4vh0Sl64pn0nYsPsUw+r//gUm7WVddd94qoqMK5MiDVSli8WhJ1wUBLcPegLN4pEWxz6QDFtwpyxOozF1LfHa8x+oAcG2QuLD7eE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i6Wc359u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i6Wc359u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 203E4C4CEDD; Tue, 25 Feb 2025 18:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740507321; bh=HjlJmrZ0SxP4ehKsEiMi8e3l28z5QdOJ2UkYN5fJ53s=; h=Date:Subject:From:To:References:In-Reply-To:From; b=i6Wc359uwbaXX+nVCL+7k+Kp0B3C688bjwwWXNqO0KlRzfTAbpXHFmCYobp5YJ5Eu QxqRRew8fCtcrjamu5l6CdGuOSFpgOuxzgwBGQbtyQp/IK+R1QlPrZkjFCFG5Rj7T1 HC7LOr7PT6g5hQJbKJUGrbpnYqorsik02CVcWAm6Nl2gNgfPl3UpHUjN3TAki8gBMW CwJJgqVvCJEltZAwE2aIUtqdzru7Yk4N4ZwHDSTtcLbgSsbr5EAQ+WQfoPWi47m5IW azzQfefqZF3qXOFNnGH0mjmu8Zll8jwuHh2Le4ia3yWwo7VCgR7pLDWbzjGd7xCsiT hFOLfeJTut9RA== Message-ID: Date: Tue, 25 Feb 2025 19:15:19 +0100 Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH mptcp-next] mptcp: pm: userspace: avoid scheduling in-kernel PM worker Content-Language: en-GB From: Matthieu Baerts To: Geliang Tang , mptcp@lists.linux.dev References: <20250224-mptcp-userspace-avoid-worker-v1-1-127325d3e9a4@kernel.org> <8ccd5c340bb75c8e325c8b8a1207671785cf911d.camel@kernel.org> <0b1c7e47-78d1-4dbb-b78b-e071f9c08dac@kernel.org> Autocrypt: addr=matttbe@kernel.org; keydata= xsFNBFXj+ekBEADxVr99p2guPcqHFeI/JcFxls6KibzyZD5TQTyfuYlzEp7C7A9swoK5iCvf YBNdx5Xl74NLSgx6y/1NiMQGuKeu+2BmtnkiGxBNanfXcnl4L4Lzz+iXBvvbtCbynnnqDDqU c7SPFMpMesgpcu1xFt0F6bcxE+0ojRtSCZ5HDElKlHJNYtD1uwY4UYVGWUGCF/+cY1YLmtfb WdNb/SF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0WJS3QzbObzHNgAp3zy/L4lXwc6WW5vnpWAzqXFHP8D9PTpqvBALbXqL06smP47JqbyQxj Xf7D2rrPeIqbYmVY9da1KzMOVf3gReazYa89zZSdVkMojfWsbq05zwYU+SCWS3NiyF6QghbW voxbFwX1i/0xRwJiX9NNbRj1huVKQuS4W7rbWA87TrVQPXUAdkyd7FRYICNW+0gddysIwPoa KrLfx3Ba6Rpx0JznbrVOtXlihjl4KV8mtOPjYDY9u+8x412xXnlGl6AC4HLu2F3ECkamY4G6 UxejX+E6vW6Xe4n7H+rEX5UFgPRdYkS1TA/X3nMen9bouxNsvIJv7C6adZmMHqu/2azX7S7I vrxxySzOw9GxjoVTuzWMKWpDGP8n71IFeOot8JuPZtJ8omz+DZel+WCNZMVdVNLPOd5frqOv mpz0VhFAlNTjU1Vy0CnuxX3AM51J8dpdNyG0S8rADh6C8AKCDOfUstpq28/6oTaQv7QZdge0 JY6dglzGKnCi/zsmp2+1w559frz4+IC7j/igvJGX4KDDKUs0mlld8J2u2sBXv7CGxdzQoHaz lzVbFe7fduHbABmYz9cefQpO7wDE/Q== Organization: NGI0 Core In-Reply-To: <0b1c7e47-78d1-4dbb-b78b-e071f9c08dac@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Geliang, On 25/02/2025 10:25, Matthieu Baerts wrote: > Hi Geliang, > > Thank you for your review! > > On 25/02/2025 05:21, Geliang Tang wrote: >> Hi Matt, >> >> On Mon, 2025-02-24 at 20:01 +0100, Matthieu Baerts (NGI0) wrote: >>> When the userspace PM is used, there is no need to schedule the PM >>> worker for in-kernel specific tasks, e.g. creating new subflows, or >>> sending more ADD_ADDR. >>> >>> Now, these tasks will be done only if the in-kernel PM is being used. >>> >>> Signed-off-by: Matthieu Baerts (NGI0) >>> --- >>> Notes: >>>  - I don't know if this should be seen as a fix. Maybe yes because it >>>    was not supposed to do that from the beginning, and it feels less >>>    risky not to schedule the worker when it is not needed. I'm open >>> to >>>    suggestions here. >>>  - I'm mainly sharing this patch now because Geliang is going to >>> modify >>>    these helpers to separate PM specific code. >>>    @Geliang: please rebase your series on top of this one (or include >>>    this patch if it is easier). >>> Cc: Geliang Tang >>> --- >>>  net/mptcp/pm.c | 10 ++++++++-- >>>  1 file changed, 8 insertions(+), 2 deletions(-) >>> >>> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c >>> index >>> 16cacce6c10fe86467aa7ef8e588f9f535b586fb..4eabb83328905676759768fb44c >>> 859f5682721e3 100644 >>> --- a/net/mptcp/pm.c >>> +++ b/net/mptcp/pm.c >>> @@ -138,7 +138,7 @@ void mptcp_pm_fully_established(struct mptcp_sock >>> *msk, const struct sock *ssk) >>>   * racing paths - accept() and check_fully_established() >>>   * be sure to serve this event only once. >>>   */ >>> - if (READ_ONCE(pm->work_pending) && >>> + if (mptcp_pm_is_kernel(msk) && READ_ONCE(pm->work_pending) >>> && >> >> I think there's no need to modify this. work_pending is set to 0 by >> userspace pm, for all cases where work_pending is 1, the path manager >> must be an in-kernel pm. > > Good point, I missed that! > > 'pm->work_pending' doesn't look like a good name for what it does. > Hopefully, this will be clearer when pm->ops will be used, which will > clearly separate what is done by the different PMs. > > Also, is it possible we never set 'pm->work_pending' back to 'true' once > it has been set to 'false'? Does it mean when we reach the limits, and > something happens (e.g. a removed subflow, limits are changed, etc.), > the worker is no longer used to establish new subflows or react when an > ADD_ADDR is received? I didn't check, but it feels like we should add something like that: > diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c > index d4328443d844..dee3e3c14ec3 100644 > --- a/net/mptcp/pm_netlink.c > +++ b/net/mptcp/pm_netlink.c > @@ -248,6 +248,8 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk) > WRITE_ONCE(msk->pm.work_pending, false); > return false; > } > + > + WRITE_ONCE(msk->pm.work_pending, true); > return true; > } > > @@ -911,6 +913,9 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, > WRITE_ONCE(msk->pm.accept_addr, true); > } > } > + > + if (mptcp_pm_is_kernel(msk)) > + mptcp_pm_nl_check_work_pending(msk); > } > > static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk) So to re-enable msk->pm.work_pending when limits have been reached, and it is no longer the case. WDYT? We would need a new subtest to confirm this patch is needed, and to avoid regressions later. (...) >>> @@ -278,6 +281,9 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock >>> *msk, >>>   for (i = 0; i < rm_list->nr; i++) >>>   mptcp_event_addr_removed(msk, rm_list->ids[i]); >>>   >>> + if (!mptcp_pm_is_kernel(msk)) >>> + return; >> >> This mptcp_pm_is_kernel() is indeed needed. > > Yes it is. And 'pm->work_pending' cannot be used, because it will be set > to false when the limits are reached, but a RM_ADDR will potentially > decrement counters. In fact, it is not needed: from what I see, the corresponding subflows are removed on the kernel side, the userspace daemon doesn't need to send a request to remove them. See the modification from 4d25247d3ae4 ("mptcp: bypass in-kernel PM restrictions for non-kernel PMs") in mptcp_pm_nl_rm_addr_or_subflow(). > I will send a v2 with only this change. I will send a v2 with only an early exit in mptcp_pm_add_addr_echoed() if there is no need to schedule the worker. Cheers, Matt -- Sponsored by the NGI0 Core fund.