sctp: shrink stream outq in the right place
Subsystems (3)
Xin Long
maintainercover sctp: shrink stream outq in the right place
Patch 1 is an improvement, and Patch 2 is a bug fix.
Xin Long (2):
sctp: shrink stream outq only when new outcnt < old outcnt
sctp: shrink stream outq when fails to do addstream reconf
net/sctp/stream.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH 1/2 sctp: shrink stream outq only when new outcnt < old outcnt
It's not necessary to go list_for_each for outq->out_chunk_list when new outcnt >= old outcnt, as no chunk with higher sid than new (outcnt - 1) exists in the outqueue.
While at it, also move the list_for_each code in a new function sctp_stream_shrink_out(), which will be used in the next patch.
--- net/sctp/stream.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
net/sctp/stream.c +14 -7
@@ -22,17 +22,11 @@#include <net/sctp/sm.h> #include <net/sctp/stream_sched.h> -/* Migrates chunks from stream queues to new stream queues if needed, -* but not across associations. Also, removes those chunks to streams -* higher than the new max. -*/ -static void sctp_stream_outq_migrate (struct sctp_stream *stream, -struct sctp_stream *new,__u16 outcnt) +static void sctp_stream_shrink_out (struct sctp_stream *stream,__u16 outcnt) {struct sctp_association *asoc;struct sctp_chunk *ch, *temp;struct sctp_outq *outq; -int i; asoc = container_of(stream, struct sctp_association, stream); outq = &asoc->outqueue;
@@ -56,6 +50,19 @@ static void sctp_stream_outq_migrate(struct sctp_stream *stream,sctp_chunk_free (ch); } +} + +/* Migrates chunks from stream queues to new stream queues if needed, +* but not across associations. Also, removes those chunks to streams +* higher than the new max. +*/ +static void sctp_stream_outq_migrate (struct sctp_stream *stream, +struct sctp_stream *new,__u16 outcnt) +{ +int i; + +if (stream->outcnt > outcnt) +sctp_stream_shrink_out (stream, outcnt);if (new) {/* Here we actually move the old ext stuff into the new
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH 2/2 sctp: shrink stream outq when fails to do addstream reconf
When adding a stream with stream reconf, the new stream firstly is in CLOSED state but new out chunks can still be enqueued. Then once gets the confirmation from the peer, the state will change to OPEN.
However, if the peer denies, it needs to roll back the stream. But when doing that, it only sets the stream outcnt back, and the chunks already in the new stream don't get purged. It caused these chunks can still be dequeued in sctp_outq_dequeue_data().
As its stream is still in CLOSE, the chunk will be enqueued to the head again by sctp_outq_head_data(). This chunk will never be sent out, and the chunks after it can never be dequeued. The assoc will be 'hung' in a dead loop of sending this chunk.
To fix it, this patch is to purge these chunks already in the new stream by calling sctp_stream_shrink_out() when failing to do the addstream reconf.
--- net/sctp/stream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/sctp/stream.c +4 -2
@@ -1044,11 +1044,13 @@ struct sctp_chunk *sctp_process_strreset_resp( nums =ntohs (addstrm->number_of_streams); number = stream->outcnt - nums; -if (result =SCTP_STRRESET_PERFORMED ) +if (result =SCTP_STRRESET_PERFORMED ) {for (i = number; i < stream->outcnt; i++)SCTP_SO (stream, i)->state =SCTP_STREAM_OPEN ; -else + }else { +sctp_stream_shrink_out (stream, number); stream->outcnt = number; + } *evp =sctp_ulpevent_make_stream_change_event (asoc, flags,0 , nums,GFP_ATOMIC );
Signature · 1 line
2.1.0
Quoted 5 lines · Xin Long
Patch 1 is an improvement, and Patch 2 is a bug fix.
Xin Long (2):
sctp: shrink stream outq only when new outcnt < old outcnt
sctp: shrink stream outq when fails to do addstream reconf
Nice changelogs, thanks.
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Wed, 22 Jul 2020 23:52:10 +0800
Quoted 1 line
Patch 1 is an improvement, and Patch 2 is a bug fix.
Series applied, and queued up for -stable, thank you.