mptcp: netlink event fixes
Subsystems (2)
Florian Westphal
cover mptcp: netlink event fixes
While testing upcoming mptcp reset option support i found a few issues with netlink events.
1. When remote side is closing, the subflow close event will be delayed until after the mptcp socket has shut down.
Schedule the worker to do a cleanup scan to avoid this.
2. When the mptcp socket is closing we can avoid sending individual 'subflow is closing' events; entire connection is going down so might as well wait for the normal mptcp-level close event.
3. Move the subflow close loop after dead check. This is not a fix, it would be fine to leave things as-is if you prefer -- its just that the extra conn_list walk can be avoided if the msk is already dead.
Florian Westphal (3):
mptcp: schedule worker when subflow is closed
mptcp: skip MPTCP_EVENT_SUB_CLOSED event when mptcp socket isn't
established
mptcp: move subflow close loop after sk close check
net/mptcp/protocol.c | 9 +++++---- net/mptcp/subflow.c | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.2
Florian Westphal
PATCH 1/3 mptcp: schedule worker when subflow is closed
When remote side closes a subflow we should schedule the worker to dispose of the subflow in a timely manner.
Otherwise, SF_CLOSED event won't be generated until the mptcp socket itself is closing or local side is closing another subflow.
--- net/mptcp/subflow.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/mptcp/subflow.c +7 -0
@@ -1413,6 +1413,13 @@ static void subflow_state_change(struct sock *sk)if (mptcp_subflow_data_available (sk))mptcp_data_ready (parent, sk); +if (sk->sk_state ==TCP_CLOSE && + !test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &mptcp_sk (parent)->flags)) { +sock_hold (parent); +if (!schedule_work (&mptcp_sk (parent)->work)) +sock_put (parent); + } +if (__mptcp_check_fallback (mptcp_sk (parent)) && !subflow->rx_eof &&subflow_is_done (sk)) { subflow->rx_eof =1 ;
Signature · 1 line
2.26.2
Paolo Abeni
[MPTCP] Re: [PATCH mptcp 1/3] mptcp: schedule worker when subflow is closed
Hello,
Quoted 16 lines · Florian Westphal
When remote side closes a subflow we should schedule the worker to dispose of the subflow in a timely manner.
Otherwise,
SF_CLOSEDevent won't be generated until the mptcp socket itself is closing or local side is closing another subflow.Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/subflow.c | 7 +++++++ 1 file changed, 7 insertions(+)net/mptcp/subflow.c +0
-0
net/mptcp/subflow.c static void subflow_state_change(struct sock *sk) · line 1422
Quoted 10 lines
net/mptcp/subflow.c +7
-0@@ -1413,6 +1413,13 @@ static void subflow_state_change(struct sock *sk)if (mptcp_subflow_data_available (sk))mptcp_data_ready (parent, sk); +if (sk->sk_state ==TCP_CLOSE && + !test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &mptcp_sk (parent)->flags)) { +sock_hold (parent); +if (!schedule_work (&mptcp_sk (parent)->work)) +sock_put (parent); + } +
Looks like this is causing issue/154. Reverting this patch the issues goes away here. @Matttbe: could you please double check that?
In case of fallback, the subflow can be closed by the peer while there are data pending in the subflow receive queue. Calling mptcp_close_subflow() will discard such data and will corrupt the stream.
I think that scenario is possible even with full msk, if the peer closes a single subflow while the msk is still alive (before DATA_FIN).
A possible fix could be additionally checking for empty ssk-
Quoted 1 line
sk_recevive_queue, plush adding a similar chunk
in __mptcp_move_skbs_from_subflow().
That means that subflow_close even could be delayed by user-space, if the latter does not spool the pending ingress data.
Or the NL event generation cold be de-coupled from the actual subflow close() but I fear some side effect even there.
Note that calling __mptcp_move_skbs_from_subflow()
from mptcp_close_subflow() will not solve the issue, as the msk receive queue could be full - I think;)
Side note: it would be nice using the deferred actions to do the netlink call, to avoid the workqueue usage. AFAICS this is one of the few workqueue usage that can be triggered on a server by any client regardless of the server configuration (the others being DATA_FIN/DATA_FIN-ack processing).
Cheers,
Paolo
Florian Westphal
[MPTCP] Re: [PATCH mptcp 1/3] mptcp: schedule worker when subflow is closed
Quoted 8 lines · Paolo Abeni
Quoted 8 lines
net/mptcp/subflow.c +0
-0@@ -1413,6 +1413,13 @@ static void subflow_state_change(struct sock *sk)if (mptcp_subflow_data_available (sk))mptcp_data_ready (parent, sk);
Quoted 10 lines
net/mptcp/subflow.c static void subflow_state_change(struct sock *sk) · line 1422
Quoted 7 lines
net/mptcp/subflow.c +7
-0+if (sk->sk_state ==TCP_CLOSE && + !test_and_set_bit (MPTCP_WORK_CLOSE_SUBFLOW , &mptcp_sk (parent)->flags)) { +sock_hold (parent); +if (!schedule_work (&mptcp_sk (parent)->work)) +sock_put (parent); + } +Looks like this is causing issue/154. Reverting this patch the issues goes away here. @Matttbe: could you please double check that?
No need, I am sure you are correct.
Quoted 4 lines
In case of fallback, the subflow can be closed by the peer while there are data pending in the subflow receive queue. Calling
mptcp_close_subflow()will discard such data and will corrupt the stream.
This.
Quoted 2 lines
I think that scenario is possible even with full msk, if the peer closes a single subflow while the msk is still alive (before
DATA_FIN).
You mean because there might be unprocessed data in subflow rx queue?
Quoted 3 lines
A possible fix could be additionally checking for empty ssk-
Quoted 1 line
sk_recevive_queue, plush adding a similar chunkin
__mptcp_move_skbs_from_subflow().
Yes, not nice, I don't see another solution atm though.
Will look into this tomorrow.
Quoted 2 lines
That means that
subflow_closeeven could be delayed by user-space, if the latter does not spool the pending ingress data.
We can decouple the event from actual close.
Quoted 2 lines
Or the NL event generation cold be de-coupled from the actual subflow
close()but I fear some side effect even there.
Hmm, why?
Quoted 3 lines
Note that calling
__mptcp_move_skbs_from_subflow()
frommptcp_close_subflow()will not solve the issue, as the msk receive queue could be full - I think;)
Yes, it could be full.
thats possible.
Quoted 2 lines
Side note: it would be nice using the deferred actions to do the netlink call, to avoid the workqueue usage.
Why? How many events/s do you expect?
Events try to prefer GFP_KERNEL allocations where possible.
Paolo Abeni
[MPTCP] Re: [PATCH mptcp 1/3] mptcp: schedule worker when subflow is closed
Quoted 6 lines · Florian Westphal
Quoted 4 lines · Paolo Abeni
In case of fallback, the subflow can be closed by the peer while there are data pending in the subflow receive queue. Calling
mptcp_close_subflow()will discard such data and will corrupt the stream.
Quoted 7 lines
This.
Quoted 2 lines
I think that scenario is possible even with full msk, if the peer closes a single subflow while the msk is still alive (before
DATA_FIN).You mean because there might be unprocessed data in subflow rx queue?
Yes. With the fallback scenario it happens quite easily. I think because the subflow finds the msk receive queue exceeding msk-
Quoted 6 lines
sk_rcvbuf, but I really did not investigate that much.Quoted 2 lines
Or the NL event generation cold be de-coupled from the actual subflow
close()but I fear some side effect even there.Hmm, why?
if the actual close is also in charge of subflow accounting (and subflow limits enforcing), likely there will be no issue. If subflow accounting is done at NL event generation time, a malicius peer could open/close a subflow multiple times and "leeking" (not really leaking, but still cause allocation with no free) a lot of subflow on this side.
Quoted 4 lines
Quoted 2 lines
Side note: it would be nice using the deferred actions to do the netlink call, to avoid the workqueue usage.
Why? How many events/s do you expect?
At least one per msk connection, I think. On a busy server with an high ingress connection rate is likely significant. Yes, DATA_FIN (ack) will weight twice (or 4x) more, so I think we should use delegated action even for that ;)
Quoted 1 line
Events try to prefer
GFP_KERNELallocations where possible.
yep, that is relevant. Delegated actions are handled at msk release_cb time - depending on the lock status when they are fires - even in non atomic/process context. We could use GFP_KERNEL when triggering the event from release_cb and ATOMIC elsewhere. Would that inconsistency be acceptable?
I have some related patches "cleaning-up" mptcp_release_cb that I'll hopefully share soon.
Or perhaps we could check for genl_has_listeners() before scheduling the workqueue?
/P
Florian Westphal
[MPTCP] Re: [PATCH mptcp 1/3] mptcp: schedule worker when subflow is closed
Quoted 6 lines · Paolo Abeni
On Tue, 2021-02-09 at 00:47 +0100, Florian Westphal wrote:
if the actual close is also in charge of subflow accounting (and subflow limits enforcing), likely there will be no issue. If subflow accounting is done at NL event generation time, a malicius peer could open/close a subflow multiple times and "leeking" (not really leaking, but still cause allocation with no free) a lot of subflow on this side.
No, event generation should do just that, emit the mcast event, no accounting or similar.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Side note: it would be nice using the deferred actions to do the netlink call, to avoid the workqueue usage.
Why? How many events/s do you expect?
At least one per msk connection, I think. On a busy server with an high ingress connection rate is likely significant. Yes,
DATA_FIN(ack) will weight twice (or 4x) more, so I think we should use delegated action even for that ;)
Compared to packet processing they are likely not relevant, but see below.
Quoted 7 lines
Quoted 1 line
Events try to prefer
GFP_KERNELallocations where possible.yep, that is relevant. Delegated actions are handled at msk
release_cbtime - depending on the lock status when they are fires - even in non atomic/process context. We could useGFP_KERNELwhen triggering the event fromrelease_cband ATOMIC elsewhere. Would that inconsistency be acceptable?
The function already provides a gfp_t arg, there are spots where event happens from atomic context.
Quoted 2 lines
I have some related patches "cleaning-up"
mptcp_release_cbthat I'll hopefully share soon.
Ok, will have a l ook.
Quoted 2 lines
Or perhaps we could check for
genl_has_listeners()before scheduling the workqueue?
I think thats a good idea, however, the idea was not just to kick the event but also do the actual socket close, so if we don't sched the wq the ssk will stay around until msk close time, no?
Paolo Abeni
[MPTCP] Re: [PATCH mptcp 1/3] mptcp: schedule worker when subflow is closed
Quoted 7 lines · Florian Westphal
Quoted 4 lines · Paolo Abeni
At least one per msk connection, I think. On a busy server with an high ingress connection rate is likely significant. Yes,
DATA_FIN(ack) will weight twice (or 4x) more, so I think we should use delegated action even for that ;)Compared to packet processing they are likely not relevant,
I'm not sure - for short lived connection. Looks like time has come to collect some connection/rate performance figure ;)
Quoted 4 lines
Quoted 2 lines
I have some related patches "cleaning-up"
mptcp_release_cbthat I'll hopefully share soon.Ok, will have a l ook.
Just shared ;)
Quoted 7 lines
Quoted 3 lines
Or perhaps we could check for
genl_has_listeners()before scheduling the workqueue?I think thats a good idea, however, the idea was not just to kick the event but also do the actual socket close, so if we don't sched the wq the ssk will stay around until msk close time, no?
We can use the delegated actions to close the subflow (or do any other task requiring the msk socket lock), with the folloing pattern:
// under ssk lock
mptcp_data_lock();
if (!sock_owned_by_user(msk))
if (<target ssk != us>) mptcp_subflow_delegate(target_subflow, action id); // mptcp_subflow_delegate to be extended to schedule // different actions [1] else <do the intended task> // [2]
else
<schedule the task for release_cb time> // [3]
[1] and [2] must act atomically, while [3] could sleep, using the loop introduced by "mptcp: fix race in release_cb".
For CLOSE_SUBFLOW the target ssk will always be the current one, so there is actually no need for delegated actions, the release cb will suffice.
/P
Florian Westphal
PATCH 2/3 mptcp: skip MPTCP_EVENT_SUB_CLOSED event when mptcp socket isn't established
In reply to Florian WestphalA CLOSE event will be sent when the logical mptcp socket is closing. Thus there is no need to generate individual subflow close events if the mptcp socket isn't established anymore.
--- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
@@ -2150,7 +2150,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,void mptcp_close_ssk (struct sock *sk,struct sock *ssk,struct mptcp_subflow_context *subflow) { -mptcp_event (MPTCP_EVENT_SUB_CLOSED ,mptcp_sk (sk), ssk,GFP_KERNEL ); +if (sk->sk_state ==TCP_ESTABLISHED ) +mptcp_event (MPTCP_EVENT_SUB_CLOSED ,mptcp_sk (sk), ssk,GFP_KERNEL );__mptcp_close_ssk (sk, ssk, subflow); }
Signature · 1 line
2.26.2
Florian Westphal
PATCH 3/3 mptcp: move subflow close loop after sk close check
In reply to Florian WestphalIn case mptcp socket is already dead the entire mptcp socket will be freed. We can avoid the close check in this case.
--- net/mptcp/protocol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +3 -3
@@ -2244,9 +2244,6 @@ static void mptcp_worker(struct work_struct *work)mptcp_check_fastclose (msk); -if (test_and_clear_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) -__mptcp_close_subflow (msk); -if (msk->pm.status)mptcp_pm_nl_work (msk);
@@ -2268,6 +2265,9 @@ static void mptcp_worker(struct work_struct *work) goto unlock; } +if (test_and_clear_bit (MPTCP_WORK_CLOSE_SUBFLOW , &msk->flags)) +__mptcp_close_subflow (msk); +if (!test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags)) goto unlock;
Signature · 1 line
2.26.2
Mat Martineau
Quoted 6 lines · Florian Westphal
While testing upcoming mptcp reset option support i found a few issues with netlink events.
1. When remote side is closing, the subflow close event will be delayed until after the mptcp socket has shut down.
Quoted 7 lines
Schedule the worker to do a cleanup scan to avoid this.
2. When the mptcp socket is closing we can avoid sending individual 'subflow is closing' events; entire connection is going down so might as well wait for the normal mptcp-level close event.
Those two fixes look good for the export branch.
Quoted 4 lines
3. Move the subflow close loop after dead check. This is not a fix, it would be fine to leave things as-is if you prefer -- its just that the extra
conn_listwalk can be avoided if the msk is already dead.
This also skips the MPTCP_EVENT_SUB_CLOSED events when the whole socket is closed, right? That's worthwhile. It doesn't look like delaying the ssk close(s) will change the other calls that might happen for the PM / EOF / DATA_FIN stuff, so I think the patch is ok. If there's a problem we can drop it from the export branch.
Thanks!
Mat
Quoted 7 lines
Florian Westphal (3):
mptcp: schedule worker when subflow is closed
mptcp: skipMPTCP_EVENT_SUB_CLOSEDevent when mptcp socket isn't
established
mptcp: move subflow close loop after sk close check
Quoted 6 lines
net/mptcp/protocol.c| 9 +++++----net/mptcp/subflow.c| 7 +++++++2 files changed, 12 insertions(+), 4 deletions(-)Signature · 1 line
2.26.2
--
Mat Martineau
Intel
Matthieu Baerts
Hi Florian, Mat,
Quoted 2 lines · Florian Westphal
While testing upcoming mptcp reset option support i found a few issues with netlink events.
Thank you for the patches and the reviews!
As discussed on IRC, I squashed patch 2/3 in "mptcp: add netlink event support":
- 51e4bae2c6c9: "squashed" patch 2/3 in "mptcp: add netlink event support"
- Results: f3a1a5d5ef41..eee71bc20e17
Then I added patches 1/3 and 3/3/ in our tree between "mptcp: split __mptcp_close_ssk helper" and "mptcp: pass subflow socket to a few helpers". I also added Mat's RvB tags:
- 95fc52697bf7: mptcp: schedule worker when subflow is closed
- 74975e28f8ec: mptcp: move subflow close loop after sk close check
- Results: eee71bc20e17..7b3ea53ce791
Tests + export are in progress!
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net