aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>2016-03-10 16:33:07 -0500
committerDavid S. Miller <davem@davemloft.net>2016-03-13 22:29:07 -0400
commitcea8768f333e3f0bc231d8b815aa4a9e63fa990c (patch)
tree60bf6ef493bdc7f9816f4c62f65b7aa106a9a0ce
parent6f15cdbf8a8ac2e22767cc8b1eae225702733c95 (diff)
sctp: allow sctp_transmit_packet and others to use gfp
Currently sctp_sendmsg() triggers some calls that will allocate memory with GFP_ATOMIC even when not necessary. In the case of sctp_packet_transmit it will allocate a linear skb that will be used to construct the packet and this may cause sends to fail due to ENOMEM more often than anticipated specially with big MTUs. This patch thus allows it to inherit gfp flags from upper calls so that it can use GFP_KERNEL if it was triggered by a sctp_sendmsg call or similar. All others, like retransmits or flushes started from BH, are still allocated using GFP_ATOMIC. In netperf tests this didn't result in any performance drawbacks when memory is not too fragmented and made it trigger ENOMEM way less often. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/sctp/sm.h2
-rw-r--r--include/net/sctp/structs.h10
-rw-r--r--net/sctp/associola.c2
-rw-r--r--net/sctp/chunk.c6
-rw-r--r--net/sctp/input.c2
-rw-r--r--net/sctp/output.c6
-rw-r--r--net/sctp/outqueue.c30
-rw-r--r--net/sctp/sm_make_chunk.c80
-rw-r--r--net/sctp/sm_sideeffect.c23
9 files changed, 89 insertions, 72 deletions
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 487ef34bbd63..efc01743b9d6 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -201,7 +201,7 @@ struct sctp_chunk *sctp_make_cwr(const struct sctp_association *,
201struct sctp_chunk * sctp_make_datafrag_empty(struct sctp_association *, 201struct sctp_chunk * sctp_make_datafrag_empty(struct sctp_association *,
202 const struct sctp_sndrcvinfo *sinfo, 202 const struct sctp_sndrcvinfo *sinfo,
203 int len, const __u8 flags, 203 int len, const __u8 flags,
204 __u16 ssn); 204 __u16 ssn, gfp_t gfp);
205struct sctp_chunk *sctp_make_ecne(const struct sctp_association *, 205struct sctp_chunk *sctp_make_ecne(const struct sctp_association *,
206 const __u32); 206 const __u32);
207struct sctp_chunk *sctp_make_sack(const struct sctp_association *); 207struct sctp_chunk *sctp_make_sack(const struct sctp_association *);
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index d05b56641abc..9d237669c52c 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -655,7 +655,7 @@ void sctp_chunk_free(struct sctp_chunk *);
655void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data); 655void *sctp_addto_chunk(struct sctp_chunk *, int len, const void *data);
656struct sctp_chunk *sctp_chunkify(struct sk_buff *, 656struct sctp_chunk *sctp_chunkify(struct sk_buff *,
657 const struct sctp_association *, 657 const struct sctp_association *,
658 struct sock *); 658 struct sock *, gfp_t gfp);
659void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *, 659void sctp_init_addrs(struct sctp_chunk *, union sctp_addr *,
660 union sctp_addr *); 660 union sctp_addr *);
661const union sctp_addr *sctp_source(const struct sctp_chunk *chunk); 661const union sctp_addr *sctp_source(const struct sctp_chunk *chunk);
@@ -717,10 +717,10 @@ struct sctp_packet *sctp_packet_init(struct sctp_packet *,
717 __u16 sport, __u16 dport); 717 __u16 sport, __u16 dport);
718struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int); 718struct sctp_packet *sctp_packet_config(struct sctp_packet *, __u32 vtag, int);
719sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *, 719sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *,
720 struct sctp_chunk *, int); 720 struct sctp_chunk *, int, gfp_t);
721sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *, 721sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *,
722 struct sctp_chunk *); 722 struct sctp_chunk *);
723int sctp_packet_transmit(struct sctp_packet *); 723int sctp_packet_transmit(struct sctp_packet *, gfp_t);
724void sctp_packet_free(struct sctp_packet *); 724void sctp_packet_free(struct sctp_packet *);
725 725
726static inline int sctp_packet_empty(struct sctp_packet *packet) 726static inline int sctp_packet_empty(struct sctp_packet *packet)
@@ -1053,7 +1053,7 @@ struct sctp_outq {
1053void sctp_outq_init(struct sctp_association *, struct sctp_outq *); 1053void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
1054void sctp_outq_teardown(struct sctp_outq *); 1054void sctp_outq_teardown(struct sctp_outq *);
1055void sctp_outq_free(struct sctp_outq*); 1055void sctp_outq_free(struct sctp_outq*);
1056int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk); 1056int sctp_outq_tail(struct sctp_outq *, struct sctp_chunk *chunk, gfp_t);
1057int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *); 1057int sctp_outq_sack(struct sctp_outq *, struct sctp_chunk *);
1058int sctp_outq_is_empty(const struct sctp_outq *); 1058int sctp_outq_is_empty(const struct sctp_outq *);
1059void sctp_outq_restart(struct sctp_outq *); 1059void sctp_outq_restart(struct sctp_outq *);
@@ -1061,7 +1061,7 @@ void sctp_outq_restart(struct sctp_outq *);
1061void sctp_retransmit(struct sctp_outq *, struct sctp_transport *, 1061void sctp_retransmit(struct sctp_outq *, struct sctp_transport *,
1062 sctp_retransmit_reason_t); 1062 sctp_retransmit_reason_t);
1063void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8); 1063void sctp_retransmit_mark(struct sctp_outq *, struct sctp_transport *, __u8);
1064int sctp_outq_uncork(struct sctp_outq *); 1064int sctp_outq_uncork(struct sctp_outq *, gfp_t gfp);
1065/* Uncork and flush an outqueue. */ 1065/* Uncork and flush an outqueue. */
1066static inline void sctp_outq_cork(struct sctp_outq *q) 1066static inline void sctp_outq_cork(struct sctp_outq *q)
1067{ 1067{
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index cd873446433c..a19b3e607703 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -1493,7 +1493,7 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned int len)
1493 1493
1494 asoc->peer.sack_needed = 0; 1494 asoc->peer.sack_needed = 0;
1495 1495
1496 sctp_outq_tail(&asoc->outqueue, sack); 1496 sctp_outq_tail(&asoc->outqueue, sack, GFP_ATOMIC);
1497 1497
1498 /* Stop the SACK timer. */ 1498 /* Stop the SACK timer. */
1499 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK]; 1499 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK];
diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c
index 3aa43073e0b9..958ef5f33f4b 100644
--- a/net/sctp/chunk.c
+++ b/net/sctp/chunk.c
@@ -260,7 +260,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
260 frag |= SCTP_DATA_SACK_IMM; 260 frag |= SCTP_DATA_SACK_IMM;
261 } 261 }
262 262
263 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag, 0); 263 chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag,
264 0, GFP_KERNEL);
264 265
265 if (!chunk) { 266 if (!chunk) {
266 err = -ENOMEM; 267 err = -ENOMEM;
@@ -296,7 +297,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
296 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY)) 297 (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
297 frag |= SCTP_DATA_SACK_IMM; 298 frag |= SCTP_DATA_SACK_IMM;
298 299
299 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag, 0); 300 chunk = sctp_make_datafrag_empty(asoc, sinfo, over, frag,
301 0, GFP_KERNEL);
300 302
301 if (!chunk) { 303 if (!chunk) {
302 err = -ENOMEM; 304 err = -ENOMEM;
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 21a2d6b7abaf..db76f1ab4ac2 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -221,7 +221,7 @@ int sctp_rcv(struct sk_buff *skb)
221 goto discard_release; 221 goto discard_release;
222 222
223 /* Create an SCTP packet structure. */ 223 /* Create an SCTP packet structure. */
224 chunk = sctp_chunkify(skb, asoc, sk); 224 chunk = sctp_chunkify(skb, asoc, sk, GFP_ATOMIC);
225 if (!chunk) 225 if (!chunk)
226 goto discard_release; 226 goto discard_release;
227 SCTP_INPUT_CB(skb)->chunk = chunk; 227 SCTP_INPUT_CB(skb)->chunk = chunk;
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 9d610eddd19e..736c004abfbc 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -153,7 +153,7 @@ void sctp_packet_free(struct sctp_packet *packet)
153 */ 153 */
154sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet, 154sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
155 struct sctp_chunk *chunk, 155 struct sctp_chunk *chunk,
156 int one_packet) 156 int one_packet, gfp_t gfp)
157{ 157{
158 sctp_xmit_t retval; 158 sctp_xmit_t retval;
159 int error = 0; 159 int error = 0;
@@ -163,7 +163,7 @@ sctp_xmit_t sctp_packet_transmit_chunk(struct sctp_packet *packet,
163 switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) { 163 switch ((retval = (sctp_packet_append_chunk(packet, chunk)))) {
164 case SCTP_XMIT_PMTU_FULL: 164 case SCTP_XMIT_PMTU_FULL:
165 if (!packet->has_cookie_echo) { 165 if (!packet->has_cookie_echo) {
166 error = sctp_packet_transmit(packet); 166 error = sctp_packet_transmit(packet, gfp);
167 if (error < 0) 167 if (error < 0)
168 chunk->skb->sk->sk_err = -error; 168 chunk->skb->sk->sk_err = -error;
169 169
@@ -376,7 +376,7 @@ static void sctp_packet_set_owner_w(struct sk_buff *skb, struct sock *sk)
376 * 376 *
377 * The return value is a normal kernel error return value. 377 * The return value is a normal kernel error return value.
378 */ 378 */
379int sctp_packet_transmit(struct sctp_packet *packet) 379int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
380{ 380{
381 struct sctp_transport *tp = packet->transport; 381 struct sctp_transport *tp = packet->transport;
382 struct sctp_association *asoc = tp->asoc; 382 struct sctp_association *asoc = tp->asoc;
diff --git a/net/sctp/outqueue.c b/net/sctp/outqueue.c
index c0380cfb16ae..f03541d0f12d 100644
--- a/net/sctp/outqueue.c
+++ b/net/sctp/outqueue.c
@@ -68,7 +68,7 @@ static void sctp_mark_missing(struct sctp_outq *q,
68 68
69static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn); 69static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 sack_ctsn);
70 70
71static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout); 71static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp);
72 72
73/* Add data to the front of the queue. */ 73/* Add data to the front of the queue. */
74static inline void sctp_outq_head_data(struct sctp_outq *q, 74static inline void sctp_outq_head_data(struct sctp_outq *q,
@@ -285,7 +285,7 @@ void sctp_outq_free(struct sctp_outq *q)
285} 285}
286 286
287/* Put a new chunk in an sctp_outq. */ 287/* Put a new chunk in an sctp_outq. */
288int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk) 288int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp)
289{ 289{
290 struct net *net = sock_net(q->asoc->base.sk); 290 struct net *net = sock_net(q->asoc->base.sk);
291 int error = 0; 291 int error = 0;
@@ -341,7 +341,7 @@ int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
341 return error; 341 return error;
342 342
343 if (!q->cork) 343 if (!q->cork)
344 error = sctp_outq_flush(q, 0); 344 error = sctp_outq_flush(q, 0, gfp);
345 345
346 return error; 346 return error;
347} 347}
@@ -510,7 +510,7 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
510 * will be flushed at the end. 510 * will be flushed at the end.
511 */ 511 */
512 if (reason != SCTP_RTXR_FAST_RTX) 512 if (reason != SCTP_RTXR_FAST_RTX)
513 error = sctp_outq_flush(q, /* rtx_timeout */ 1); 513 error = sctp_outq_flush(q, /* rtx_timeout */ 1, GFP_ATOMIC);
514 514
515 if (error) 515 if (error)
516 q->asoc->base.sk->sk_err = -error; 516 q->asoc->base.sk->sk_err = -error;
@@ -601,12 +601,12 @@ redo:
601 * control chunks are already freed so there 601 * control chunks are already freed so there
602 * is nothing we can do. 602 * is nothing we can do.
603 */ 603 */
604 sctp_packet_transmit(pkt); 604 sctp_packet_transmit(pkt, GFP_ATOMIC);
605 goto redo; 605 goto redo;
606 } 606 }
607 607
608 /* Send this packet. */ 608 /* Send this packet. */
609 error = sctp_packet_transmit(pkt); 609 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
610 610
611 /* If we are retransmitting, we should only 611 /* If we are retransmitting, we should only
612 * send a single packet. 612 * send a single packet.
@@ -622,7 +622,7 @@ redo:
622 622
623 case SCTP_XMIT_RWND_FULL: 623 case SCTP_XMIT_RWND_FULL:
624 /* Send this packet. */ 624 /* Send this packet. */
625 error = sctp_packet_transmit(pkt); 625 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
626 626
627 /* Stop sending DATA as there is no more room 627 /* Stop sending DATA as there is no more room
628 * at the receiver. 628 * at the receiver.
@@ -632,7 +632,7 @@ redo:
632 632
633 case SCTP_XMIT_DELAY: 633 case SCTP_XMIT_DELAY:
634 /* Send this packet. */ 634 /* Send this packet. */
635 error = sctp_packet_transmit(pkt); 635 error = sctp_packet_transmit(pkt, GFP_ATOMIC);
636 636
637 /* Stop sending DATA because of nagle delay. */ 637 /* Stop sending DATA because of nagle delay. */
638 done = 1; 638 done = 1;
@@ -685,12 +685,12 @@ redo:
685} 685}
686 686
687/* Cork the outqueue so queued chunks are really queued. */ 687/* Cork the outqueue so queued chunks are really queued. */
688int sctp_outq_uncork(struct sctp_outq *q) 688int sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp)
689{ 689{
690 if (q->cork) 690 if (q->cork)
691 q->cork = 0; 691 q->cork = 0;
692 692
693 return sctp_outq_flush(q, 0); 693 return sctp_outq_flush(q, 0, gfp);
694} 694}
695 695
696 696
@@ -703,7 +703,7 @@ int sctp_outq_uncork(struct sctp_outq *q)
703 * locking concerns must be made. Today we use the sock lock to protect 703 * locking concerns must be made. Today we use the sock lock to protect
704 * this function. 704 * this function.
705 */ 705 */
706static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout) 706static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
707{ 707{
708 struct sctp_packet *packet; 708 struct sctp_packet *packet;
709 struct sctp_packet singleton; 709 struct sctp_packet singleton;
@@ -825,7 +825,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
825 sctp_packet_init(&singleton, transport, sport, dport); 825 sctp_packet_init(&singleton, transport, sport, dport);
826 sctp_packet_config(&singleton, vtag, 0); 826 sctp_packet_config(&singleton, vtag, 0);
827 sctp_packet_append_chunk(&singleton, chunk); 827 sctp_packet_append_chunk(&singleton, chunk);
828 error = sctp_packet_transmit(&singleton); 828 error = sctp_packet_transmit(&singleton, gfp);
829 if (error < 0) 829 if (error < 0)
830 return error; 830 return error;
831 break; 831 break;
@@ -856,7 +856,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
856 case SCTP_CID_ASCONF: 856 case SCTP_CID_ASCONF:
857 case SCTP_CID_FWD_TSN: 857 case SCTP_CID_FWD_TSN:
858 status = sctp_packet_transmit_chunk(packet, chunk, 858 status = sctp_packet_transmit_chunk(packet, chunk,
859 one_packet); 859 one_packet, gfp);
860 if (status != SCTP_XMIT_OK) { 860 if (status != SCTP_XMIT_OK) {
861 /* put the chunk back */ 861 /* put the chunk back */
862 list_add(&chunk->list, &q->control_chunk_list); 862 list_add(&chunk->list, &q->control_chunk_list);
@@ -1011,7 +1011,7 @@ static int sctp_outq_flush(struct sctp_outq *q, int rtx_timeout)
1011 atomic_read(&chunk->skb->users) : -1); 1011 atomic_read(&chunk->skb->users) : -1);
1012 1012
1013 /* Add the chunk to the packet. */ 1013 /* Add the chunk to the packet. */
1014 status = sctp_packet_transmit_chunk(packet, chunk, 0); 1014 status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
1015 1015
1016 switch (status) { 1016 switch (status) {
1017 case SCTP_XMIT_PMTU_FULL: 1017 case SCTP_XMIT_PMTU_FULL:
@@ -1088,7 +1088,7 @@ sctp_flush_out:
1088 send_ready); 1088 send_ready);
1089 packet = &t->packet; 1089 packet = &t->packet;
1090 if (!sctp_packet_empty(packet)) 1090 if (!sctp_packet_empty(packet))
1091 error = sctp_packet_transmit(packet); 1091 error = sctp_packet_transmit(packet, gfp);
1092 1092
1093 /* Clear the burst limited state, if any */ 1093 /* Clear the burst limited state, if any */
1094 sctp_transport_burst_reset(t); 1094 sctp_transport_burst_reset(t);
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 5d6a03fad378..8449ca26aa0b 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -62,11 +62,13 @@
62#include <net/sctp/sm.h> 62#include <net/sctp/sm.h>
63 63
64static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc, 64static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc,
65 __u8 type, __u8 flags, int paylen); 65 __u8 type, __u8 flags, int paylen,
66 gfp_t gfp);
66static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc, 67static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc,
67 __u8 flags, int paylen); 68 __u8 flags, int paylen, gfp_t gfp);
68static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc, 69static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
69 __u8 type, __u8 flags, int paylen); 70 __u8 type, __u8 flags, int paylen,
71 gfp_t gfp);
70static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep, 72static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
71 const struct sctp_association *asoc, 73 const struct sctp_association *asoc,
72 const struct sctp_chunk *init_chunk, 74 const struct sctp_chunk *init_chunk,
@@ -318,7 +320,7 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
318 * PLEASE DO NOT FIXME [This version does not support Host Name.] 320 * PLEASE DO NOT FIXME [This version does not support Host Name.]
319 */ 321 */
320 322
321 retval = sctp_make_control(asoc, SCTP_CID_INIT, 0, chunksize); 323 retval = sctp_make_control(asoc, SCTP_CID_INIT, 0, chunksize, gfp);
322 if (!retval) 324 if (!retval)
323 goto nodata; 325 goto nodata;
324 326
@@ -465,7 +467,7 @@ struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
465 num_ext); 467 num_ext);
466 468
467 /* Now allocate and fill out the chunk. */ 469 /* Now allocate and fill out the chunk. */
468 retval = sctp_make_control(asoc, SCTP_CID_INIT_ACK, 0, chunksize); 470 retval = sctp_make_control(asoc, SCTP_CID_INIT_ACK, 0, chunksize, gfp);
469 if (!retval) 471 if (!retval)
470 goto nomem_chunk; 472 goto nomem_chunk;
471 473
@@ -570,7 +572,8 @@ struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc,
570 cookie_len = asoc->peer.cookie_len; 572 cookie_len = asoc->peer.cookie_len;
571 573
572 /* Build a cookie echo chunk. */ 574 /* Build a cookie echo chunk. */
573 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ECHO, 0, cookie_len); 575 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ECHO, 0,
576 cookie_len, GFP_ATOMIC);
574 if (!retval) 577 if (!retval)
575 goto nodata; 578 goto nodata;
576 retval->subh.cookie_hdr = 579 retval->subh.cookie_hdr =
@@ -615,7 +618,7 @@ struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc,
615{ 618{
616 struct sctp_chunk *retval; 619 struct sctp_chunk *retval;
617 620
618 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ACK, 0, 0); 621 retval = sctp_make_control(asoc, SCTP_CID_COOKIE_ACK, 0, 0, GFP_ATOMIC);
619 622
620 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 623 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
621 * 624 *
@@ -664,7 +667,7 @@ struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
664 667
665 cwr.lowest_tsn = htonl(lowest_tsn); 668 cwr.lowest_tsn = htonl(lowest_tsn);
666 retval = sctp_make_control(asoc, SCTP_CID_ECN_CWR, 0, 669 retval = sctp_make_control(asoc, SCTP_CID_ECN_CWR, 0,
667 sizeof(sctp_cwrhdr_t)); 670 sizeof(sctp_cwrhdr_t), GFP_ATOMIC);
668 671
669 if (!retval) 672 if (!retval)
670 goto nodata; 673 goto nodata;
@@ -698,7 +701,7 @@ struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
698 701
699 ecne.lowest_tsn = htonl(lowest_tsn); 702 ecne.lowest_tsn = htonl(lowest_tsn);
700 retval = sctp_make_control(asoc, SCTP_CID_ECN_ECNE, 0, 703 retval = sctp_make_control(asoc, SCTP_CID_ECN_ECNE, 0,
701 sizeof(sctp_ecnehdr_t)); 704 sizeof(sctp_ecnehdr_t), GFP_ATOMIC);
702 if (!retval) 705 if (!retval)
703 goto nodata; 706 goto nodata;
704 retval->subh.ecne_hdr = 707 retval->subh.ecne_hdr =
@@ -713,7 +716,8 @@ nodata:
713 */ 716 */
714struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc, 717struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc,
715 const struct sctp_sndrcvinfo *sinfo, 718 const struct sctp_sndrcvinfo *sinfo,
716 int data_len, __u8 flags, __u16 ssn) 719 int data_len, __u8 flags, __u16 ssn,
720 gfp_t gfp)
717{ 721{
718 struct sctp_chunk *retval; 722 struct sctp_chunk *retval;
719 struct sctp_datahdr dp; 723 struct sctp_datahdr dp;
@@ -734,7 +738,7 @@ struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc,
734 dp.ssn = htons(ssn); 738 dp.ssn = htons(ssn);
735 739
736 chunk_len = sizeof(dp) + data_len; 740 chunk_len = sizeof(dp) + data_len;
737 retval = sctp_make_data(asoc, flags, chunk_len); 741 retval = sctp_make_data(asoc, flags, chunk_len, gfp);
738 if (!retval) 742 if (!retval)
739 goto nodata; 743 goto nodata;
740 744
@@ -781,7 +785,7 @@ struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc)
781 + sizeof(__u32) * num_dup_tsns; 785 + sizeof(__u32) * num_dup_tsns;
782 786
783 /* Create the chunk. */ 787 /* Create the chunk. */
784 retval = sctp_make_control(asoc, SCTP_CID_SACK, 0, len); 788 retval = sctp_make_control(asoc, SCTP_CID_SACK, 0, len, GFP_ATOMIC);
785 if (!retval) 789 if (!retval)
786 goto nodata; 790 goto nodata;
787 791
@@ -861,7 +865,7 @@ struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
861 shut.cum_tsn_ack = htonl(ctsn); 865 shut.cum_tsn_ack = htonl(ctsn);
862 866
863 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN, 0, 867 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN, 0,
864 sizeof(sctp_shutdownhdr_t)); 868 sizeof(sctp_shutdownhdr_t), GFP_ATOMIC);
865 if (!retval) 869 if (!retval)
866 goto nodata; 870 goto nodata;
867 871
@@ -879,7 +883,8 @@ struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
879{ 883{
880 struct sctp_chunk *retval; 884 struct sctp_chunk *retval;
881 885
882 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_ACK, 0, 0); 886 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_ACK, 0, 0,
887 GFP_ATOMIC);
883 888
884 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 889 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
885 * 890 *
@@ -908,7 +913,8 @@ struct sctp_chunk *sctp_make_shutdown_complete(
908 */ 913 */
909 flags |= asoc ? 0 : SCTP_CHUNK_FLAG_T; 914 flags |= asoc ? 0 : SCTP_CHUNK_FLAG_T;
910 915
911 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_COMPLETE, flags, 0); 916 retval = sctp_make_control(asoc, SCTP_CID_SHUTDOWN_COMPLETE, flags,
917 0, GFP_ATOMIC);
912 918
913 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 919 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
914 * 920 *
@@ -947,7 +953,8 @@ struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc,
947 flags = SCTP_CHUNK_FLAG_T; 953 flags = SCTP_CHUNK_FLAG_T;
948 } 954 }
949 955
950 retval = sctp_make_control(asoc, SCTP_CID_ABORT, flags, hint); 956 retval = sctp_make_control(asoc, SCTP_CID_ABORT, flags, hint,
957 GFP_ATOMIC);
951 958
952 /* RFC 2960 6.4 Multi-homed SCTP Endpoints 959 /* RFC 2960 6.4 Multi-homed SCTP Endpoints
953 * 960 *
@@ -1139,7 +1146,8 @@ struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
1139 struct sctp_chunk *retval; 1146 struct sctp_chunk *retval;
1140 sctp_sender_hb_info_t hbinfo; 1147 sctp_sender_hb_info_t hbinfo;
1141 1148
1142 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0, sizeof(hbinfo)); 1149 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT, 0,
1150 sizeof(hbinfo), GFP_ATOMIC);
1143 1151
1144 if (!retval) 1152 if (!retval)
1145 goto nodata; 1153 goto nodata;
@@ -1167,7 +1175,8 @@ struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
1167{ 1175{
1168 struct sctp_chunk *retval; 1176 struct sctp_chunk *retval;
1169 1177
1170 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT_ACK, 0, paylen); 1178 retval = sctp_make_control(asoc, SCTP_CID_HEARTBEAT_ACK, 0, paylen,
1179 GFP_ATOMIC);
1171 if (!retval) 1180 if (!retval)
1172 goto nodata; 1181 goto nodata;
1173 1182
@@ -1200,7 +1209,7 @@ static struct sctp_chunk *sctp_make_op_error_space(
1200 struct sctp_chunk *retval; 1209 struct sctp_chunk *retval;
1201 1210
1202 retval = sctp_make_control(asoc, SCTP_CID_ERROR, 0, 1211 retval = sctp_make_control(asoc, SCTP_CID_ERROR, 0,
1203 sizeof(sctp_errhdr_t) + size); 1212 sizeof(sctp_errhdr_t) + size, GFP_ATOMIC);
1204 if (!retval) 1213 if (!retval)
1205 goto nodata; 1214 goto nodata;
1206 1215
@@ -1271,7 +1280,8 @@ struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc)
1271 return NULL; 1280 return NULL;
1272 1281
1273 retval = sctp_make_control(asoc, SCTP_CID_AUTH, 0, 1282 retval = sctp_make_control(asoc, SCTP_CID_AUTH, 0,
1274 hmac_desc->hmac_len + sizeof(sctp_authhdr_t)); 1283 hmac_desc->hmac_len + sizeof(sctp_authhdr_t),
1284 GFP_ATOMIC);
1275 if (!retval) 1285 if (!retval)
1276 return NULL; 1286 return NULL;
1277 1287
@@ -1309,11 +1319,11 @@ struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc)
1309 */ 1319 */
1310struct sctp_chunk *sctp_chunkify(struct sk_buff *skb, 1320struct sctp_chunk *sctp_chunkify(struct sk_buff *skb,
1311 const struct sctp_association *asoc, 1321 const struct sctp_association *asoc,
1312 struct sock *sk) 1322 struct sock *sk, gfp_t gfp)
1313{ 1323{
1314 struct sctp_chunk *retval; 1324 struct sctp_chunk *retval;
1315 1325
1316 retval = kmem_cache_zalloc(sctp_chunk_cachep, GFP_ATOMIC); 1326 retval = kmem_cache_zalloc(sctp_chunk_cachep, gfp);
1317 1327
1318 if (!retval) 1328 if (!retval)
1319 goto nodata; 1329 goto nodata;
@@ -1361,7 +1371,8 @@ const union sctp_addr *sctp_source(const struct sctp_chunk *chunk)
1361 * arguments, reserving enough space for a 'paylen' byte payload. 1371 * arguments, reserving enough space for a 'paylen' byte payload.
1362 */ 1372 */
1363static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc, 1373static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1364 __u8 type, __u8 flags, int paylen) 1374 __u8 type, __u8 flags, int paylen,
1375 gfp_t gfp)
1365{ 1376{
1366 struct sctp_chunk *retval; 1377 struct sctp_chunk *retval;
1367 sctp_chunkhdr_t *chunk_hdr; 1378 sctp_chunkhdr_t *chunk_hdr;
@@ -1369,8 +1380,7 @@ static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1369 struct sock *sk; 1380 struct sock *sk;
1370 1381
1371 /* No need to allocate LL here, as this is only a chunk. */ 1382 /* No need to allocate LL here, as this is only a chunk. */
1372 skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen), 1383 skb = alloc_skb(WORD_ROUND(sizeof(sctp_chunkhdr_t) + paylen), gfp);
1373 GFP_ATOMIC);
1374 if (!skb) 1384 if (!skb)
1375 goto nodata; 1385 goto nodata;
1376 1386
@@ -1381,7 +1391,7 @@ static struct sctp_chunk *_sctp_make_chunk(const struct sctp_association *asoc,
1381 chunk_hdr->length = htons(sizeof(sctp_chunkhdr_t)); 1391 chunk_hdr->length = htons(sizeof(sctp_chunkhdr_t));
1382 1392
1383 sk = asoc ? asoc->base.sk : NULL; 1393 sk = asoc ? asoc->base.sk : NULL;
1384 retval = sctp_chunkify(skb, asoc, sk); 1394 retval = sctp_chunkify(skb, asoc, sk, gfp);
1385 if (!retval) { 1395 if (!retval) {
1386 kfree_skb(skb); 1396 kfree_skb(skb);
1387 goto nodata; 1397 goto nodata;
@@ -1400,16 +1410,18 @@ nodata:
1400} 1410}
1401 1411
1402static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc, 1412static struct sctp_chunk *sctp_make_data(const struct sctp_association *asoc,
1403 __u8 flags, int paylen) 1413 __u8 flags, int paylen, gfp_t gfp)
1404{ 1414{
1405 return _sctp_make_chunk(asoc, SCTP_CID_DATA, flags, paylen); 1415 return _sctp_make_chunk(asoc, SCTP_CID_DATA, flags, paylen, gfp);
1406} 1416}
1407 1417
1408static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc, 1418static struct sctp_chunk *sctp_make_control(const struct sctp_association *asoc,
1409 __u8 type, __u8 flags, int paylen) 1419 __u8 type, __u8 flags, int paylen,
1420 gfp_t gfp)
1410{ 1421{
1411 struct sctp_chunk *chunk = _sctp_make_chunk(asoc, type, flags, paylen); 1422 struct sctp_chunk *chunk;
1412 1423
1424 chunk = _sctp_make_chunk(asoc, type, flags, paylen, gfp);
1413 if (chunk) 1425 if (chunk)
1414 sctp_control_set_owner_w(chunk); 1426 sctp_control_set_owner_w(chunk);
1415 1427
@@ -2756,7 +2768,8 @@ static struct sctp_chunk *sctp_make_asconf(struct sctp_association *asoc,
2756 length += addrlen; 2768 length += addrlen;
2757 2769
2758 /* Create the chunk. */ 2770 /* Create the chunk. */
2759 retval = sctp_make_control(asoc, SCTP_CID_ASCONF, 0, length); 2771 retval = sctp_make_control(asoc, SCTP_CID_ASCONF, 0, length,
2772 GFP_ATOMIC);
2760 if (!retval) 2773 if (!retval)
2761 return NULL; 2774 return NULL;
2762 2775
@@ -2940,7 +2953,8 @@ static struct sctp_chunk *sctp_make_asconf_ack(const struct sctp_association *as
2940 int length = sizeof(asconf) + vparam_len; 2953 int length = sizeof(asconf) + vparam_len;
2941 2954
2942 /* Create the chunk. */ 2955 /* Create the chunk. */
2943 retval = sctp_make_control(asoc, SCTP_CID_ASCONF_ACK, 0, length); 2956 retval = sctp_make_control(asoc, SCTP_CID_ASCONF_ACK, 0, length,
2957 GFP_ATOMIC);
2944 if (!retval) 2958 if (!retval)
2945 return NULL; 2959 return NULL;
2946 2960
@@ -3500,7 +3514,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
3500 3514
3501 hint = (nstreams + 1) * sizeof(__u32); 3515 hint = (nstreams + 1) * sizeof(__u32);
3502 3516
3503 retval = sctp_make_control(asoc, SCTP_CID_FWD_TSN, 0, hint); 3517 retval = sctp_make_control(asoc, SCTP_CID_FWD_TSN, 0, hint, GFP_ATOMIC);
3504 3518
3505 if (!retval) 3519 if (!retval)
3506 return NULL; 3520 return NULL;
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index b5327bb77458..3c22c41a2bc2 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -1019,13 +1019,13 @@ static void sctp_cmd_t1_timer_update(struct sctp_association *asoc,
1019 * encouraged for small fragments. 1019 * encouraged for small fragments.
1020 */ 1020 */
1021static int sctp_cmd_send_msg(struct sctp_association *asoc, 1021static int sctp_cmd_send_msg(struct sctp_association *asoc,
1022 struct sctp_datamsg *msg) 1022 struct sctp_datamsg *msg, gfp_t gfp)
1023{ 1023{
1024 struct sctp_chunk *chunk; 1024 struct sctp_chunk *chunk;
1025 int error = 0; 1025 int error = 0;
1026 1026
1027 list_for_each_entry(chunk, &msg->chunks, frag_list) { 1027 list_for_each_entry(chunk, &msg->chunks, frag_list) {
1028 error = sctp_outq_tail(&asoc->outqueue, chunk); 1028 error = sctp_outq_tail(&asoc->outqueue, chunk, gfp);
1029 if (error) 1029 if (error)
1030 break; 1030 break;
1031 } 1031 }
@@ -1249,7 +1249,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1249 case SCTP_CMD_NEW_ASOC: 1249 case SCTP_CMD_NEW_ASOC:
1250 /* Register a new association. */ 1250 /* Register a new association. */
1251 if (local_cork) { 1251 if (local_cork) {
1252 sctp_outq_uncork(&asoc->outqueue); 1252 sctp_outq_uncork(&asoc->outqueue, gfp);
1253 local_cork = 0; 1253 local_cork = 0;
1254 } 1254 }
1255 1255
@@ -1269,7 +1269,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1269 1269
1270 case SCTP_CMD_DELETE_TCB: 1270 case SCTP_CMD_DELETE_TCB:
1271 if (local_cork) { 1271 if (local_cork) {
1272 sctp_outq_uncork(&asoc->outqueue); 1272 sctp_outq_uncork(&asoc->outqueue, gfp);
1273 local_cork = 0; 1273 local_cork = 0;
1274 } 1274 }
1275 /* Delete the current association. */ 1275 /* Delete the current association. */
@@ -1423,13 +1423,14 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1423 local_cork = 1; 1423 local_cork = 1;
1424 } 1424 }
1425 /* Send a chunk to our peer. */ 1425 /* Send a chunk to our peer. */
1426 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.chunk); 1426 error = sctp_outq_tail(&asoc->outqueue, cmd->obj.chunk,
1427 gfp);
1427 break; 1428 break;
1428 1429
1429 case SCTP_CMD_SEND_PKT: 1430 case SCTP_CMD_SEND_PKT:
1430 /* Send a full packet to our peer. */ 1431 /* Send a full packet to our peer. */
1431 packet = cmd->obj.packet; 1432 packet = cmd->obj.packet;
1432 sctp_packet_transmit(packet); 1433 sctp_packet_transmit(packet, gfp);
1433 sctp_ootb_pkt_free(packet); 1434 sctp_ootb_pkt_free(packet);
1434 break; 1435 break;
1435 1436
@@ -1639,7 +1640,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1639 */ 1640 */
1640 chunk->pdiscard = 1; 1641 chunk->pdiscard = 1;
1641 if (asoc) { 1642 if (asoc) {
1642 sctp_outq_uncork(&asoc->outqueue); 1643 sctp_outq_uncork(&asoc->outqueue, gfp);
1643 local_cork = 0; 1644 local_cork = 0;
1644 } 1645 }
1645 break; 1646 break;
@@ -1677,7 +1678,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1677 case SCTP_CMD_FORCE_PRIM_RETRAN: 1678 case SCTP_CMD_FORCE_PRIM_RETRAN:
1678 t = asoc->peer.retran_path; 1679 t = asoc->peer.retran_path;
1679 asoc->peer.retran_path = asoc->peer.primary_path; 1680 asoc->peer.retran_path = asoc->peer.primary_path;
1680 error = sctp_outq_uncork(&asoc->outqueue); 1681 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1681 local_cork = 0; 1682 local_cork = 0;
1682 asoc->peer.retran_path = t; 1683 asoc->peer.retran_path = t;
1683 break; 1684 break;
@@ -1704,7 +1705,7 @@ static int sctp_cmd_interpreter(sctp_event_t event_type,
1704 sctp_outq_cork(&asoc->outqueue); 1705 sctp_outq_cork(&asoc->outqueue);
1705 local_cork = 1; 1706 local_cork = 1;
1706 } 1707 }
1707 error = sctp_cmd_send_msg(asoc, cmd->obj.msg); 1708 error = sctp_cmd_send_msg(asoc, cmd->obj.msg, gfp);
1708 break; 1709 break;
1709 case SCTP_CMD_SEND_NEXT_ASCONF: 1710 case SCTP_CMD_SEND_NEXT_ASCONF:
1710 sctp_cmd_send_asconf(asoc); 1711 sctp_cmd_send_asconf(asoc);
@@ -1734,9 +1735,9 @@ out:
1734 */ 1735 */
1735 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) { 1736 if (asoc && SCTP_EVENT_T_CHUNK == event_type && chunk) {
1736 if (chunk->end_of_packet || chunk->singleton) 1737 if (chunk->end_of_packet || chunk->singleton)
1737 error = sctp_outq_uncork(&asoc->outqueue); 1738 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1738 } else if (local_cork) 1739 } else if (local_cork)
1739 error = sctp_outq_uncork(&asoc->outqueue); 1740 error = sctp_outq_uncork(&asoc->outqueue, gfp);
1740 return error; 1741 return error;
1741nomem: 1742nomem:
1742 error = -ENOMEM; 1743 error = -ENOMEM;