Skip to contentSkip to conversation

sctp: Correct how sk_rmem_schedule is used.

RFC PATCH In review Vlad Yasevich 1 participant 2 messages Jun 19, 2008 – Jun 23, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/2 sctp: Correct how sk_rmem_schedule is used.

We used to only use sk_rmem_schedule when we potentially overflow the sk_rcvbuf. That allowed us to use sk_rmem[1] space on top of existing sk_recvbuf space which is way more that needed and thus incorrectly detecting memory pressure conditions.

We need to call sk_rmem_schedule at all times (whenever sk_rcvbuf is not locked), letting it correctly catch memory pressure conditions.

---
 net/sctp/ulpevent.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
net/sctp/ulpevent.c +7 -5
index a1f654a..71a97c7 100644
@@ -687,6 +687,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
 	struct sk_buff *skb;
 	size_t padding, len;
 	int rx_count;
+	int pressure = 0;
 
 	/*
 	 * check to see if we need to make space for this
@@ -698,12 +699,13 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
 	else
 		rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc);
 
-	if (rx_count >= asoc->base.sk->sk_rcvbuf) {
+	if (asoc->base.sk->sk_userlocks & SOCK_RCVBUF_LOCK)
+		pressure = sk_rmem_schedule(asoc->base.sk,
+					    chunk->skb->truesize);
+
+	if (rx_count >= asoc->base.sk->sk_rcvbuf || pressure)
+		goto fail;
 
-		if ((asoc->base.sk->sk_userlocks & SOCK_RCVBUF_LOCK) ||
-		    (!sk_rmem_schedule(asoc->base.sk, chunk->skb->truesize)))
-			goto fail;
-	}
 
 	/* Clone the original skb, sharing the data.  */
 	skb = skb_clone(chunk->skb, gfp);
Signature · 1 line
1.5.2.5
#1 lore raw
Quoted 34 lines · Vlad Yasevich

We used to only use sk_rmem_schedule when we potentially overflow the sk_rcvbuf. That allowed us to use sk_rmem[1] space on top of existing sk_recvbuf space which is way more that needed and thus incorrectly detecting memory pressure conditions.

We need to call sk_rmem_schedule at all times (whenever sk_rcvbuf is not locked), letting it correctly catch memory pressure conditions.

---
 net/sctp/ulpevent.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
net/sctp/ulpevent.c +5 -1
index a1f654a..71a97c7 100644
@@ -687,6 +687,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
 	struct sk_buff *skb;
 	size_t padding, len;
 	int rx_count;
+	int pressure = 0;
 
 	/*
 	 * check to see if we need to make space for this
@@ -698,12 +699,13 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
 	else
 		rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc);
 
-	if (rx_count >= asoc->base.sk->sk_rcvbuf) {
+	if (asoc->base.sk->sk_userlocks & SOCK_RCVBUF_LOCK)
+		pressure = sk_rmem_schedule(asoc->base.sk,
+					    chunk->skb->truesize);
+

net/sctp/ulpevent.c struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc, · line 711

Quoted 10 lines
net/sctp/ulpevent.c +2 -4
+	if (rx_count >= asoc->base.sk->sk_rcvbuf || pressure)
+		goto fail;
 
-		if ((asoc->base.sk->sk_userlocks & SOCK_RCVBUF_LOCK) ||
-		    (!sk_rmem_schedule(asoc->base.sk, chunk->skb->truesize)))
-			goto fail;
-	}
 
 	/* Clone the original skb, sharing the data.  */
 	skb = skb_clone(chunk->skb, gfp);

OK, this one is bogus. What we currently do is definitely wrong, but this patch is wrong as well.

We need to always call rmem_schedule, otherwise we allow too much of an overflow. We need to also adjust our sk_rcvbuf if we get into the condition of buffer exhaustion prior to rwnd.

-vlad