Skip to contentSkip to conversation

Minor SCTP cleanups all over the place

PATCH In review Daniel Borkmann 5 participants 34 messages Apr 16, 2013 – Apr 17, 2013

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

cover Minor SCTP cleanups all over the place

That's a batch of cleanups for the SCTP protocol. Probably all deadly boring and trivial patches, but it always bugs me. :-) I guess this is still from the very SCTP beginning in Linux. Well, at least we can now remove 41 lines of code in total. lksctp-tools test suite run through without problems.

Daniel Borkmann (9):
net: sctp: sctp_ssnmap: remove 'malloced' element from struct
net: sctp: sctp_inq: remove dead code
net: sctp: sctp_outq: remove 'malloced' from its struct
net: sctp: sctp_outq: consolidate chars into bitfield
net: sctp: outqueue: simplify sctp_outq_uncork function
net: sctp: sctp_transport: remove unused variable
net: sctp: sctp_bind_addr: remove dead code
net: sctp: sctp_ulpq: remove 'malloced' struct member
net: sctp: sctp_ulpq: do not use char as a struct member

 include/net/sctp/structs.h  | 24 ++++--------------------
 include/net/sctp/ulpqueue.h |  3 +--
 net/sctp/bind_addr.c        |  7 -------
 net/sctp/inqueue.c          |  7 -------
 net/sctp/outqueue.c         | 11 ++---------
 net/sctp/ssnmap.c           | 23 ++++++++++++-----------
 net/sctp/transport.c        |  1 -
 net/sctp/ulpqueue.c         |  3 ---
 8 files changed, 19 insertions(+), 60 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/9 net: sctp: sctp_ssnmap: remove 'malloced' element from struct

sctp_ssnmap_init() can only be called from sctp_ssnmap_new() where malloced is always set to 1. Thus, when we call sctp_ssnmap_free() the test for map->malloced evaluates always to true.

---
 include/net/sctp/structs.h |  1 -
 net/sctp/ssnmap.c          | 23 ++++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
include/net/sctp/structs.h +0 -1
index e12aa77..3c1bb8d 100644
@@ -399,7 +399,6 @@ struct sctp_stream {
 struct sctp_ssnmap {
 	struct sctp_stream in;
 	struct sctp_stream out;
-	int malloced;
 };
 
 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
net/sctp/ssnmap.c +12 -11
index 825ea94..da86035 100644
@@ -74,7 +74,6 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
 	if (!sctp_ssnmap_init(retval, in, out))
 		goto fail_map;
 
-	retval->malloced = 1;
 	SCTP_DBG_OBJCNT_INC(ssnmap);
 
 	return retval;
@@ -118,14 +117,16 @@ void sctp_ssnmap_clear(struct sctp_ssnmap *map)
 /* Dispose of a ssnmap.  */
 void sctp_ssnmap_free(struct sctp_ssnmap *map)
 {
-	if (map && map->malloced) {
-		int size;
-
-		size = sctp_ssnmap_size(map->in.len, map->out.len);
-		if (size <= KMALLOC_MAX_SIZE)
-			kfree(map);
-		else
-			free_pages((unsigned long)map, get_order(size));
-		SCTP_DBG_OBJCNT_DEC(ssnmap);
-	}
+	int size;
+
+	if (unlikely(!map))
+		return;
+
+	size = sctp_ssnmap_size(map->in.len, map->out.len);
+	if (size <= KMALLOC_MAX_SIZE)
+		kfree(map);
+	else
+		free_pages((unsigned long)map, get_order(size));
+
+	SCTP_DBG_OBJCNT_DEC(ssnmap);
 }
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [PATCH net-next 1/9] net: sctp: sctp_ssnmap: remove 'malloced' element from struct

Quoted 65 lines · Daniel Borkmann

sctp_ssnmap_init() can only be called from sctp_ssnmap_new() where malloced is always set to 1. Thus, when we call sctp_ssnmap_free() the test for map->malloced evaluates always to true.

---
 include/net/sctp/structs.h |  1 -
 net/sctp/ssnmap.c          | 23 ++++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
include/net/sctp/structs.h +0 -1
index e12aa77..3c1bb8d 100644
@@ -399,7 +399,6 @@ struct sctp_stream {
 struct sctp_ssnmap {
 	struct sctp_stream in;
 	struct sctp_stream out;
-	int malloced;
 };
 
 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
net/sctp/ssnmap.c +12 -11
index 825ea94..da86035 100644
@@ -74,7 +74,6 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
 	if (!sctp_ssnmap_init(retval, in, out))
 		goto fail_map;
 
-	retval->malloced = 1;
 	SCTP_DBG_OBJCNT_INC(ssnmap);
 
 	return retval;
@@ -118,14 +117,16 @@ void sctp_ssnmap_clear(struct sctp_ssnmap *map)
 /* Dispose of a ssnmap.  */
 void sctp_ssnmap_free(struct sctp_ssnmap *map)
 {
-	if (map && map->malloced) {
-		int size;
-
-		size = sctp_ssnmap_size(map->in.len, map->out.len);
-		if (size <= KMALLOC_MAX_SIZE)
-			kfree(map);
-		else
-			free_pages((unsigned long)map, get_order(size));
-		SCTP_DBG_OBJCNT_DEC(ssnmap);
-	}
+	int size;
+
+	if (unlikely(!map))
+		return;
+
+	size = sctp_ssnmap_size(map->in.len, map->out.len);
+	if (size <= KMALLOC_MAX_SIZE)
+		kfree(map);
+	else
+		free_pages((unsigned long)map, get_order(size));
+
+	SCTP_DBG_OBJCNT_DEC(ssnmap);
 }
Signature · 1 line
1.7.11.7

I definately like what you're doing here, as the use of the ->malloced member always struck me as a half-assed way to try and avoid a double free that someone couldn't track down during this code's initial development. That said, I'm wondering if the !map check is going to fail at some point, given that the call site for sctp_ssnmap_free never sets asoc->ssnmap to NULL after its call. Maybe worthwhile adding such a NULL assoginment to the call site to ensure that we don't accidentally trigger a double free?

Neil

#3 lore raw

Re: [PATCH net-next 1/9] net: sctp: sctp_ssnmap: remove 'malloced' element from struct

Quoted 65 lines · Neil Horman
Quoted 64 lines · Daniel Borkmann

sctp_ssnmap_init() can only be called from sctp_ssnmap_new() where malloced is always set to 1. Thus, when we call sctp_ssnmap_free() the test for map->malloced evaluates always to true.

---
  include/net/sctp/structs.h |  1 -
  net/sctp/ssnmap.c          | 23 ++++++++++++-----------
  2 files changed, 12 insertions(+), 12 deletions(-)
include/net/sctp/structs.h +0 -1
index e12aa77..3c1bb8d 100644
@@ -399,7 +399,6 @@ struct sctp_stream {
  struct sctp_ssnmap {
  	struct sctp_stream in;
  	struct sctp_stream out;
-	int malloced;
  };
 
  struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
net/sctp/ssnmap.c +12 -12
index 825ea94..da86035 100644
@@ -74,7 +74,6 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
  	if (!sctp_ssnmap_init(retval, in, out))
  		goto fail_map;
 
-	retval->malloced = 1;
  	SCTP_DBG_OBJCNT_INC(ssnmap);
 
  	return retval;
@@ -118,14 +117,16 @@ void sctp_ssnmap_clear(struct sctp_ssnmap *map)
  /* Dispose of a ssnmap.  */
  void sctp_ssnmap_free(struct sctp_ssnmap *map)
  {
-	if (map && map->malloced) {
-		int size;
-
-		size = sctp_ssnmap_size(map->in.len, map->out.len);
-		if (size <= KMALLOC_MAX_SIZE)
-			kfree(map);
-		else
-			free_pages((unsigned long)map, get_order(size));
-		SCTP_DBG_OBJCNT_DEC(ssnmap);
-	}
+	int size;
+
+	if (unlikely(!map))
+		return;
+
+	size = sctp_ssnmap_size(map->in.len, map->out.len);
+	if (size <= KMALLOC_MAX_SIZE)
+		kfree(map);
+	else
+		free_pages((unsigned long)map, get_order(size));
+
+	SCTP_DBG_OBJCNT_DEC(ssnmap);
  }
--

1.7.11.7

Quoted 8 lines
Quoted 1 line

I definately like what you're doing here, as the use of the ->malloced member always struck me as a half-assed way to try and avoid a double free that someone couldn't track down during this code's initial development. That said, I'm wondering if the !map check is going to fail at some point, given that the call site for sctp_ssnmap_free never sets asoc->ssnmap to NULL after its call. Maybe worthwhile adding such a NULL assoginment to the call site to ensure that we don't accidentally trigger a double free?

I'll test that with lksctp-tools suite and come back to you today.

Thanks,
Daniel

#4 lore raw

Re: [PATCH net-next 1/9] net: sctp: sctp_ssnmap: remove 'malloced' element from struct

Quoted 75 lines · Daniel Borkmann
Quoted 65 lines · Neil Horman
Quoted 64 lines · Daniel Borkmann

sctp_ssnmap_init() can only be called from sctp_ssnmap_new() where malloced is always set to 1. Thus, when we call sctp_ssnmap_free() the test for map->malloced evaluates always to true.

---
  include/net/sctp/structs.h |  1 -
  net/sctp/ssnmap.c          | 23 ++++++++++++-----------
  2 files changed, 12 insertions(+), 12 deletions(-)
include/net/sctp/structs.h +0 -1
index e12aa77..3c1bb8d 100644
@@ -399,7 +399,6 @@ struct sctp_stream {
  struct sctp_ssnmap {
      struct sctp_stream in;
      struct sctp_stream out;
-    int malloced;
  };
 
  struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
net/sctp/ssnmap.c +12 -12
index 825ea94..da86035 100644
@@ -74,7 +74,6 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
      if (!sctp_ssnmap_init(retval, in, out))
          goto fail_map;
 
-    retval->malloced = 1;
      SCTP_DBG_OBJCNT_INC(ssnmap);
 
      return retval;
@@ -118,14 +117,16 @@ void sctp_ssnmap_clear(struct sctp_ssnmap *map)
  /* Dispose of a ssnmap.  */
  void sctp_ssnmap_free(struct sctp_ssnmap *map)
  {
-    if (map && map->malloced) {
-        int size;
-
-        size = sctp_ssnmap_size(map->in.len, map->out.len);
-        if (size <= KMALLOC_MAX_SIZE)
-            kfree(map);
-        else
-            free_pages((unsigned long)map, get_order(size));
-        SCTP_DBG_OBJCNT_DEC(ssnmap);
-    }
+    int size;
+
+    if (unlikely(!map))
+        return;
+
+    size = sctp_ssnmap_size(map->in.len, map->out.len);
+    if (size <= KMALLOC_MAX_SIZE)
+        kfree(map);
+    else
+        free_pages((unsigned long)map, get_order(size));
+
+    SCTP_DBG_OBJCNT_DEC(ssnmap);
  }
--

1.7.11.7

Quoted 8 lines
Quoted 1 line

I definately like what you're doing here, as the use of the ->malloced member always struck me as a half-assed way to try and avoid a double free that someone couldn't track down during this code's initial development. That said, I'm wondering if the !map check is going to fail at some point, given that the call site for sctp_ssnmap_free never sets asoc->ssnmap to NULL after its call. Maybe worthwhile adding such a NULL assoginment to the call site to ensure that we don't accidentally trigger a double free?

Quoted 1 line

I'll test that with lksctp-tools suite and come back to you today.

Just did that.

I've poisoned the pointers, so that they would throw a WARN_ON() if they have already been seen. Also, I've put a WARN_ON() before sctp_ssnmap_new() in sctp_process_init(), in case asoc->ssnmap was not NULL. I've run the lksctp-tools suite for v4/v6 and nothing was thrown, also it all passed.

That said, I think that the !map check is there because we init the asoc first with a NULL ssnmap. I suggest, if Dave wants to and if there are no other objections, that we could apply to net-next the patches ...

* [1/9] http://patchwork.ozlabs.org/patch/237101/
* [2/9] http://patchwork.ozlabs.org/patch/237102/
* [3/9] http://patchwork.ozlabs.org/patch/237103/
* [5/9] http://patchwork.ozlabs.org/patch/237105/
* [6/9] http://patchwork.ozlabs.org/patch/237109/
* [7/9] http://patchwork.ozlabs.org/patch/237106/
* [8/9] http://patchwork.ozlabs.org/patch/237107/

... as is. I've just tested it, they apply cleanly on top of each other without the missing. Alternatively, I could resend the set without the two that we cut out (nr 4 and 9). How you prefer, let me know.

For the remaining two, I think it needs some further analysis, thus I'd say that we could leave it as is for now and address this at a later point in time.

Thanks,

Daniel

#5 lore raw

Re: [PATCH net-next 1/9] net: sctp: sctp_ssnmap: remove 'malloced' element from struct

Quoted 97 lines · Daniel Borkmann
Quoted 75 lines · Daniel Borkmann
Quoted 65 lines · Neil Horman
Quoted 64 lines · Daniel Borkmann

sctp_ssnmap_init() can only be called from sctp_ssnmap_new() where malloced is always set to 1. Thus, when we call sctp_ssnmap_free() the test for map->malloced evaluates always to true.

---
 include/net/sctp/structs.h |  1 -
 net/sctp/ssnmap.c          | 23 ++++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)
include/net/sctp/structs.h +0 -1
index e12aa77..3c1bb8d 100644
@@ -399,7 +399,6 @@ struct sctp_stream {
 struct sctp_ssnmap {
     struct sctp_stream in;
     struct sctp_stream out;
-    int malloced;
 };
 
 struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
net/sctp/ssnmap.c +12 -12
index 825ea94..da86035 100644
@@ -74,7 +74,6 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
     if (!sctp_ssnmap_init(retval, in, out))
         goto fail_map;
 
-    retval->malloced = 1;
     SCTP_DBG_OBJCNT_INC(ssnmap);
 
     return retval;
@@ -118,14 +117,16 @@ void sctp_ssnmap_clear(struct sctp_ssnmap *map)
 /* Dispose of a ssnmap.  */
 void sctp_ssnmap_free(struct sctp_ssnmap *map)
 {
-    if (map && map->malloced) {
-        int size;
-
-        size = sctp_ssnmap_size(map->in.len, map->out.len);
-        if (size <= KMALLOC_MAX_SIZE)
-            kfree(map);
-        else
-            free_pages((unsigned long)map, get_order(size));
-        SCTP_DBG_OBJCNT_DEC(ssnmap);
-    }
+    int size;
+
+    if (unlikely(!map))
+        return;
+
+    size = sctp_ssnmap_size(map->in.len, map->out.len);
+    if (size <= KMALLOC_MAX_SIZE)
+        kfree(map);
+    else
+        free_pages((unsigned long)map, get_order(size));
+
+    SCTP_DBG_OBJCNT_DEC(ssnmap);
 }
--

1.7.11.7

Quoted 8 lines
Quoted 1 line

I definately like what you're doing here, as the use of the ->malloced member always struck me as a half-assed way to try and avoid a double free that someone couldn't track down during this code's initial development. That said, I'm wondering if the !map check is going to fail at some point, given that the call site for sctp_ssnmap_free never sets asoc->ssnmap to NULL after its call. Maybe worthwhile adding such a NULL assoginment to the call site to ensure that we don't accidentally trigger a double free?

Quoted 1 line

I'll test that with lksctp-tools suite and come back to you today.

Just did that.

I've poisoned the pointers, so that they would throw a WARN_ON() if they have already been seen. Also, I've put a WARN_ON() before sctp_ssnmap_new() in sctp_process_init(), in case asoc->ssnmap was not NULL. I've run the lksctp-tools suite for v4/v6 and nothing was thrown, also it all passed.

That said, I think that the !map check is there because we init the asoc first with a NULL ssnmap. I suggest, if Dave wants to and if there are no other objections, that we could apply to net-next the patches ...

* [1/9] http://patchwork.ozlabs.org/patch/237101/
* [2/9] http://patchwork.ozlabs.org/patch/237102/
* [3/9] http://patchwork.ozlabs.org/patch/237103/
* [5/9] http://patchwork.ozlabs.org/patch/237105/
* [6/9] http://patchwork.ozlabs.org/patch/237109/
* [7/9] http://patchwork.ozlabs.org/patch/237106/
* [8/9] http://patchwork.ozlabs.org/patch/237107/

Quoted 4 lines

... as is. I've just tested it, they apply cleanly on top of each other without the missing. Alternatively, I could resend the set without the two that we cut out (nr 4 and 9). How you prefer, let me know.

Dave's the final word, but I think the typical workflow is a resend to the list.

Neil

#6 lore raw

PATCH 2/9 net: sctp: sctp_inq: remove dead code

In reply to Daniel Borkmann

sctp_inq is never kmalloced, since it's integrated into sctp_ep_common and only initialized from eps and assocs. Therefore, remove the dead code from there.

---
 include/net/sctp/structs.h | 2 --
 net/sctp/inqueue.c         | 7 -------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -2
index 3c1bb8d..125a19c 100644
@@ -991,8 +991,6 @@ struct sctp_inq {
 	 * messages.
 	 */
 	struct work_struct immediate;
-
-	int malloced;	     /* Is this structure kfree()able?	*/
 };
 
 void sctp_inq_init(struct sctp_inq *);
net/sctp/inqueue.c +0 -7
index 2d5ad28..3221d07 100644
@@ -58,8 +58,6 @@ void sctp_inq_init(struct sctp_inq *queue)
 
 	/* Create a task for delivering data.  */
 	INIT_WORK(&queue->immediate, NULL);
-
-	queue->malloced = 0;
 }
 
 /* Release the memory associated with an SCTP inqueue.  */
@@ -80,11 +78,6 @@ void sctp_inq_free(struct sctp_inq *queue)
 		sctp_chunk_free(queue->in_progress);
 		queue->in_progress = NULL;
 	}
-
-	if (queue->malloced) {
-		/* Dump the master memory segment.  */
-		kfree(queue);
-	}
 }
 
 /* Put a new packet in an SCTP inqueue.
Signature · 1 line
1.7.11.7
Acked-by on v1 2/9
#7 lore raw

Re: [PATCH net-next 2/9] net: sctp: sctp_inq: remove dead code

Quoted 37 lines · Daniel Borkmann

sctp_inq is never kmalloced, since it's integrated into sctp_ep_common and only initialized from eps and assocs. Therefore, remove the dead code from there.

---
 include/net/sctp/structs.h | 2 --
 net/sctp/inqueue.c         | 7 -------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -2
index 3c1bb8d..125a19c 100644
@@ -991,8 +991,6 @@ struct sctp_inq {
 	 * messages.
 	 */
 	struct work_struct immediate;
-
-	int malloced;	     /* Is this structure kfree()able?	*/
 };
 
 void sctp_inq_init(struct sctp_inq *);
net/sctp/inqueue.c +0 -2
index 2d5ad28..3221d07 100644
@@ -58,8 +58,6 @@ void sctp_inq_init(struct sctp_inq *queue)
 
 	/* Create a task for delivering data.  */
 	INIT_WORK(&queue->immediate, NULL);
-
-	queue->malloced = 0;
 }
 
 /* Release the memory associated with an SCTP inqueue.  */

net/sctp/inqueue.c void sctp_inq_free(struct sctp_inq *queue) · line 82

Quoted 10 lines
net/sctp/inqueue.c +0 -5
@@ -80,11 +78,6 @@ void sctp_inq_free(struct sctp_inq *queue)
 		sctp_chunk_free(queue->in_progress);
 		queue->in_progress = NULL;
 	}
-
-	if (queue->malloced) {
-		/* Dump the master memory segment.  */
-		kfree(queue);
-	}
 }
 
#8 lore raw

PATCH 3/9 net: sctp: sctp_outq: remove 'malloced' from its struct

In reply to Daniel Borkmann

sctp_outq is embedded into sctp_association, and thus never kmalloced in any way. Also, malloced is always 0, thus kfree() is never called. Therefore, remove that dead piece of code.

---
 include/net/sctp/structs.h | 3 ---
 net/sctp/outqueue.c        | 6 ------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -3
index 125a19c..73fd5de 100644
@@ -1059,9 +1059,6 @@ struct sctp_outq {
 
 	/* Is this structure empty?  */
 	char empty;
-
-	/* Are we kfree()able? */
-	char malloced;
 };
 
 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
net/sctp/outqueue.c +0 -6
index 01dca75..d4c137e 100644
@@ -217,8 +217,6 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
 	q->outstanding_bytes = 0;
 	q->empty = 1;
 	q->cork  = 0;
-
-	q->malloced = 0;
 	q->out_qlen = 0;
 }
 
@@ -295,10 +293,6 @@ void sctp_outq_free(struct sctp_outq *q)
 {
 	/* Throw away leftover chunks. */
 	__sctp_outq_teardown(q);
-
-	/* If we were kmalloc()'d, free the memory.  */
-	if (q->malloced)
-		kfree(q);
 }
 
 /* Put a new chunk in an sctp_outq.  */
Signature · 1 line
1.7.11.7
Acked-by on v1 3/9
#9 lore raw

Re: [PATCH net-next 3/9] net: sctp: sctp_outq: remove 'malloced' from its struct

Quoted 51 lines · Daniel Borkmann

sctp_outq is embedded into sctp_association, and thus never kmalloced in any way. Also, malloced is always 0, thus kfree() is never called. Therefore, remove that dead piece of code.

---
 include/net/sctp/structs.h | 3 ---
 net/sctp/outqueue.c        | 6 ------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -3
index 125a19c..73fd5de 100644
@@ -1059,9 +1059,6 @@ struct sctp_outq {
 
 	/* Is this structure empty?  */
 	char empty;
-
-	/* Are we kfree()able? */
-	char malloced;
 };
 
 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
net/sctp/outqueue.c +0 -6
index 01dca75..d4c137e 100644
@@ -217,8 +217,6 @@ void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
 	q->outstanding_bytes = 0;
 	q->empty = 1;
 	q->cork  = 0;
-
-	q->malloced = 0;
 	q->out_qlen = 0;
 }
 
@@ -295,10 +293,6 @@ void sctp_outq_free(struct sctp_outq *q)
 {
 	/* Throw away leftover chunks. */
 	__sctp_outq_teardown(q);
-
-	/* If we were kmalloc()'d, free the memory.  */
-	if (q->malloced)
-		kfree(q);
 }
 
 /* Put a new chunk in an sctp_outq.  */
Signature · 1 line
1.7.11.7
#10 lore raw

PATCH 4/9 net: sctp: sctp_outq: consolidate chars into bitfield

In reply to Daniel Borkmann

sctp_outq structure members fast_rtx, cork and empty are all of type char. Consolidate them into a single __u8 bitfield since they either carry 0 or 1. Have the rest 5 bits for future flags.

---
 include/net/sctp/structs.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
include/net/sctp/structs.h +3 -8
index 73fd5de..3de5985 100644
@@ -1051,14 +1051,9 @@ struct sctp_outq {
 	/* How many unackd bytes do we have in-flight?	*/
 	__u32 outstanding_bytes;
 
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
 };
 
 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
Signature · 1 line
1.7.11.7
#11 lore raw

RE: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

Quoted 4 lines
include/net/sctp/structs.h +0 -2
 	__u32 outstanding_bytes;
 
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
 };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

In the above you are just increasing the padding from 1 byte to 3 bytes.

David

#12 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

Quoted 18 lines · David Laight
Quoted 4 lines

__u32 outstanding_bytes;

include/net/sctp/structs.h +0 -2
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
  };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

#13 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

Quoted 20 lines · Daniel Borkmann
Quoted 18 lines · David Laight
Quoted 4 lines
include/net/sctp/structs.h +0 -2
 	__u32 outstanding_bytes;
 
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
 };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

Quoted 4 lines

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

Unrelated note: How did you get pahole to give you that information? For some reason pahole can never glean any useful information about struct sctp_association for me, despite having dwarf info embedded into the cu.

Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

Quoted 21 lines · Neil Horman
Quoted 20 lines · Daniel Borkmann
Quoted 18 lines · David Laight
Quoted 4 lines

__u32 outstanding_bytes;

include/net/sctp/structs.h +0 -2
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
  };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

Quoted 8 lines
Quoted 4 lines

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

Unrelated note: How did you get pahole to give you that information? For some reason pahole can never glean any useful information about struct sctp_association for me, despite having dwarf info embedded into the cu.

pahole -C sctp_association <sctp object file> works for me.

-vlad

Quoted 12 lines

Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

Quoted 26 lines · Vlad Yasevich
Quoted 25 lines · Neil Horman
Quoted 24 lines · Daniel Borkmann
Quoted 18 lines · David Laight
Quoted 4 lines
include/net/sctp/structs.h +0 -2
 	__u32 outstanding_bytes;
 
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
 };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

Quoted 9 lines
Quoted 4 lines

Unrelated note: How did you get pahole to give you that information? For some reason pahole can never glean any useful information about struct sctp_association for me, despite having dwarf info embedded into the cu.

pahole -C sctp_association <sctp object file> works for me.

-vlad

Strange, that doesn't work for me, and the DW_TAG_structure_type entry is in place in the debug_info section (though interestingly no byte offsets are noted for any members). I'll have to look at that further.

Thanks
Neil

Quoted 18 lines
Quoted 7 lines

Neil

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

In reply to Neil Horman
Quoted 21 lines · Neil Horman
Quoted 20 lines · Daniel Borkmann
Quoted 18 lines · David Laight
Quoted 4 lines

__u32 outstanding_bytes;

include/net/sctp/structs.h +0 -2
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
  };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

Quoted 7 lines
Quoted 4 lines

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

Unrelated note: How did you get pahole to give you that information? For some reason pahole can never glean any useful information about struct sctp_association for me, despite having dwarf info embedded into the cu.

I made a ``make net/sctp/'' and run pahole against net/sctp/sctp.o redirecting the output into a file, thus I have all possible headers visible.

#17 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

In reply to Daniel Borkmann
Quoted 20 lines · Daniel Borkmann
Quoted 18 lines · David Laight
Quoted 4 lines
      __u32 outstanding_bytes;
include/net/sctp/structs.h +0 -2
-    /* Are we doing fast-rtx on this queue */
-    char fast_rtx;

include/net/sctp/structs.h struct sctp_outq { · line 1057

Quoted 10 lines
include/net/sctp/structs.h +3 -6
-
-    /* Corked? */
-    char cork;
-
-    /* Is this structure empty?  */
-    char empty;
+    __u8 fast_rtx:1,    /* Are we doing fast-rtx on this queue */
+         cork:1,        /* Corked? */
+         empty:1;        /* Is this structure empty?  */
  };

Use of bitfields just makes the code slower.
The only real excuse for using them is to reduce the size of a structure that is allocated a lot.

Quoted 4 lines

sctp_outq is _embedded_ into an sctp_association structure, which has [size: 2280, cachelines: 36, members: 76]! A next step would be to try to reorder its elements carefully and see if we can reduce the size by filling some holes.

I remember attempting this undertaking that led me down the rabbit hole so fast that my head started to spin. It is a badly needed project, but be prepared to spend a lot of time on it.

Not sure if the space saving is worth the bad code generated for bit-fields, especially considering that empty and cork are used on almost every packet.

-vlad

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v1 4/9
#18 lore raw

Re: [PATCH net-next 4/9] net: sctp: sctp_outq: consolidate chars into bitfield

In reply to Daniel Borkmann
Quoted 34 lines · Daniel Borkmann

sctp_outq structure members fast_rtx, cork and empty are all of type char. Consolidate them into a single __u8 bitfield since they either carry 0 or 1. Have the rest 5 bits for future flags.

---
 include/net/sctp/structs.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
include/net/sctp/structs.h +3 -8
index 73fd5de..3de5985 100644
@@ -1051,14 +1051,9 @@ struct sctp_outq {
 	/* How many unackd bytes do we have in-flight?	*/
 	__u32 outstanding_bytes;
 
-	/* Are we doing fast-rtx on this queue */
-	char fast_rtx;
-
-	/* Corked? */
-	char cork;
-
-	/* Is this structure empty?  */
-	char empty;
+	__u8 fast_rtx:1,	/* Are we doing fast-rtx on this queue */
+	     cork:1,		/* Corked? */
+	     empty:1;		/* Is this structure empty?  */
 };
 
 void sctp_outq_init(struct sctp_association *, struct sctp_outq *);
Signature · 1 line
1.7.11.7
#19 lore raw

PATCH 5/9 net: sctp: outqueue: simplify sctp_outq_uncork function

In reply to Daniel Borkmann

Just a minor edit to simplify the function. No need for this error variable here.

---
 net/sctp/outqueue.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/sctp/outqueue.c +2 -3
index d4c137e..32a4625 100644
@@ -701,11 +701,10 @@ redo:
 /* Cork the outqueue so queued chunks are really queued. */
 int sctp_outq_uncork(struct sctp_outq *q)
 {
-	int error = 0;
 	if (q->cork)
 		q->cork = 0;
-	error = sctp_outq_flush(q, 0);
-	return error;
+
+	return sctp_outq_flush(q, 0);
 }
 
 
Signature · 1 line
1.7.11.7
Acked-by on v1 5/9
#20 lore raw

Re: [PATCH net-next 5/9] net: sctp: outqueue: simplify sctp_outq_uncork function

Quoted 34 lines · Daniel Borkmann

Just a minor edit to simplify the function. No need for this error variable here.

---
 net/sctp/outqueue.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/sctp/outqueue.c +2 -3
index d4c137e..32a4625 100644
@@ -701,11 +701,10 @@ redo:
 /* Cork the outqueue so queued chunks are really queued. */
 int sctp_outq_uncork(struct sctp_outq *q)
 {
-	int error = 0;
 	if (q->cork)
 		q->cork = 0;
-	error = sctp_outq_flush(q, 0);
-	return error;
+
+	return sctp_outq_flush(q, 0);
 }
 
 
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#21 lore raw

PATCH 6/9 net: sctp: sctp_transport: remove unused variable

In reply to Daniel Borkmann

sctp_transport's member 'malloced' is set to 1, never evaluated and the structure is kfreed anyway. So just remove it.

---
 include/net/sctp/structs.h | 5 +----
 net/sctp/transport.c       | 1 -
 2 files changed, 1 insertion(+), 5 deletions(-)
include/net/sctp/structs.h +1 -4
index 3de5985..945e952 100644
@@ -779,10 +779,7 @@ struct sctp_transport {
 		hb_sent:1,
 
 		/* Is the Path MTU update pending on this tranport */
-		pmtu_pending:1,
-
-		/* Is this structure kfree()able? */
-		malloced:1;
+		pmtu_pending:1;
 
 	/* Has this transport moved the ctsn since we last sacked */
 	__u32 sack_generation;
net/sctp/transport.c +0 -1
index fafd2a4..098f1d5f 100644
@@ -123,7 +123,6 @@ struct sctp_transport *sctp_transport_new(struct net *net,
 	if (!sctp_transport_init(net, transport, addr, gfp))
 		goto fail_init;
 
-	transport->malloced = 1;
 	SCTP_DBG_OBJCNT_INC(transport);
 
 	return transport;
Signature · 1 line
1.7.11.7
Acked-by on v1 6/9
#22 lore raw

Re: [PATCH net-next 6/9] net: sctp: sctp_transport: remove unused variable

Quoted 45 lines · Daniel Borkmann

sctp_transport's member 'malloced' is set to 1, never evaluated and the structure is kfreed anyway. So just remove it.

---
 include/net/sctp/structs.h | 5 +----
 net/sctp/transport.c       | 1 -
 2 files changed, 1 insertion(+), 5 deletions(-)
include/net/sctp/structs.h +1 -4
index 3de5985..945e952 100644
@@ -779,10 +779,7 @@ struct sctp_transport {
 		hb_sent:1,
 
 		/* Is the Path MTU update pending on this tranport */
-		pmtu_pending:1,
-
-		/* Is this structure kfree()able? */
-		malloced:1;
+		pmtu_pending:1;
 
 	/* Has this transport moved the ctsn since we last sacked */
 	__u32 sack_generation;
net/sctp/transport.c +0 -1
index fafd2a4..098f1d5f 100644
@@ -123,7 +123,6 @@ struct sctp_transport *sctp_transport_new(struct net *net,
 	if (!sctp_transport_init(net, transport, addr, gfp))
 		goto fail_init;
 
-	transport->malloced = 1;
 	SCTP_DBG_OBJCNT_INC(transport);
 
 	return transport;
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw

PATCH 7/9 net: sctp: sctp_bind_addr: remove dead code

In reply to Daniel Borkmann

The sctp_bind_addr structure has a 'malloced' member that is always set to 0, thus in sctp_bind_addr_free() the kfree() part can never be called. This part is embedded into sctp_ep_common anyway and never alloced.

---
 include/net/sctp/structs.h | 2 --
 net/sctp/bind_addr.c       | 7 -------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -2
index 945e952..b4e9894 100644
@@ -1088,8 +1088,6 @@ struct sctp_bind_addr {
 	 *	peer(s) in INIT and INIT ACK chunks.
 	 */
 	struct list_head address_list;
-
-	int malloced;	     /* Are we kfree()able?  */
 };
 
 void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
net/sctp/bind_addr.c +0 -7
index d886b3b..41145fe 100644
@@ -131,8 +131,6 @@ int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
  */
 void sctp_bind_addr_init(struct sctp_bind_addr *bp, __u16 port)
 {
-	bp->malloced = 0;
-
 	INIT_LIST_HEAD(&bp->address_list);
 	bp->port = port;
 }
@@ -155,11 +153,6 @@ void sctp_bind_addr_free(struct sctp_bind_addr *bp)
 {
 	/* Empty the bind address list. */
 	sctp_bind_addr_clean(bp);
-
-	if (bp->malloced) {
-		kfree(bp);
-		SCTP_DBG_OBJCNT_DEC(bind_addr);
-	}
 }
 
 /* Add an address to the bind address list in the SCTP_bind_addr structure. */
Signature · 1 line
1.7.11.7
Acked-by on v1 7/9
#24 lore raw

Re: [PATCH net-next 7/9] net: sctp: sctp_bind_addr: remove dead code

Quoted 57 lines · Daniel Borkmann

The sctp_bind_addr structure has a 'malloced' member that is always set to 0, thus in sctp_bind_addr_free() the kfree() part can never be called. This part is embedded into sctp_ep_common anyway and never alloced.

---
 include/net/sctp/structs.h | 2 --
 net/sctp/bind_addr.c       | 7 -------
 2 files changed, 9 deletions(-)
include/net/sctp/structs.h +0 -2
index 945e952..b4e9894 100644
@@ -1088,8 +1088,6 @@ struct sctp_bind_addr {
 	 *	peer(s) in INIT and INIT ACK chunks.
 	 */
 	struct list_head address_list;
-
-	int malloced;	     /* Are we kfree()able?  */
 };
 
 void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
net/sctp/bind_addr.c +0 -7
index d886b3b..41145fe 100644
@@ -131,8 +131,6 @@ int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
  */
 void sctp_bind_addr_init(struct sctp_bind_addr *bp, __u16 port)
 {
-	bp->malloced = 0;
-
 	INIT_LIST_HEAD(&bp->address_list);
 	bp->port = port;
 }
@@ -155,11 +153,6 @@ void sctp_bind_addr_free(struct sctp_bind_addr *bp)
 {
 	/* Empty the bind address list. */
 	sctp_bind_addr_clean(bp);
-
-	if (bp->malloced) {
-		kfree(bp);
-		SCTP_DBG_OBJCNT_DEC(bind_addr);
-	}
 }
 
 /* Add an address to the bind address list in the SCTP_bind_addr structure. */
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#25 lore raw

PATCH 8/9 net: sctp: sctp_ulpq: remove 'malloced' struct member

In reply to Daniel Borkmann

The structure sctp_ulpq is embedded into sctp_association and never separately allocated, also ulpq->malloced is always 0, so that kfree() is never called. Therefore, remove this code.

---
 include/net/sctp/ulpqueue.h | 1 -
 net/sctp/ulpqueue.c         | 3 ---
 2 files changed, 4 deletions(-)
include/net/sctp/ulpqueue.h +0 -1
index ff1b8ba7..00e50ba 100644
@@ -49,7 +49,6 @@
 
 /* A structure to carry information to the ULP (e.g. Sockets API) */
 struct sctp_ulpq {
-	char malloced;
 	char pd_mode;
 	struct sctp_association *asoc;
 	struct sk_buff_head reasm;
net/sctp/ulpqueue.c +0 -3
index 0fd5b3d..04e3d47 100644
@@ -68,7 +68,6 @@ struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
 	skb_queue_head_init(&ulpq->reasm);
 	skb_queue_head_init(&ulpq->lobby);
 	ulpq->pd_mode  = 0;
-	ulpq->malloced = 0;
 
 	return ulpq;
 }
@@ -96,8 +95,6 @@ void sctp_ulpq_flush(struct sctp_ulpq *ulpq)
 void sctp_ulpq_free(struct sctp_ulpq *ulpq)
 {
 	sctp_ulpq_flush(ulpq);
-	if (ulpq->malloced)
-		kfree(ulpq);
 }
 
 /* Process an incoming DATA chunk.  */
Signature · 1 line
1.7.11.7
Acked-by on v1 8/9
#26 lore raw

Re: [PATCH net-next 8/9] net: sctp: sctp_ulpq: remove 'malloced' struct member

Quoted 51 lines · Daniel Borkmann

The structure sctp_ulpq is embedded into sctp_association and never separately allocated, also ulpq->malloced is always 0, so that kfree() is never called. Therefore, remove this code.

---
 include/net/sctp/ulpqueue.h | 1 -
 net/sctp/ulpqueue.c         | 3 ---
 2 files changed, 4 deletions(-)
include/net/sctp/ulpqueue.h +0 -1
index ff1b8ba7..00e50ba 100644
@@ -49,7 +49,6 @@
 
 /* A structure to carry information to the ULP (e.g. Sockets API) */
 struct sctp_ulpq {
-	char malloced;
 	char pd_mode;
 	struct sctp_association *asoc;
 	struct sk_buff_head reasm;
net/sctp/ulpqueue.c +0 -3
index 0fd5b3d..04e3d47 100644
@@ -68,7 +68,6 @@ struct sctp_ulpq *sctp_ulpq_init(struct sctp_ulpq *ulpq,
 	skb_queue_head_init(&ulpq->reasm);
 	skb_queue_head_init(&ulpq->lobby);
 	ulpq->pd_mode  = 0;
-	ulpq->malloced = 0;
 
 	return ulpq;
 }
@@ -96,8 +95,6 @@ void sctp_ulpq_flush(struct sctp_ulpq *ulpq)
 void sctp_ulpq_free(struct sctp_ulpq *ulpq)
 {
 	sctp_ulpq_flush(ulpq);
-	if (ulpq->malloced)
-		kfree(ulpq);
 }
 
 /* Process an incoming DATA chunk.  */
Signature · 6 lines
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#27 lore raw

PATCH 9/9 net: sctp: sctp_ulpq: do not use char as a struct member

In reply to Daniel Borkmann

Replace char with a more appropriate __u8 bitfield for pd_mode.

---
 include/net/sctp/ulpqueue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sctp/ulpqueue.h +1 -1
index 00e50ba..a2bebd4 100644
@@ -49,10 +49,10 @@
 
 /* A structure to carry information to the ULP (e.g. Sockets API) */
 struct sctp_ulpq {
-	char pd_mode;
 	struct sctp_association *asoc;
 	struct sk_buff_head reasm;
 	struct sk_buff_head lobby;
+	__u8 pd_mode:1;
 };
 
 /* Prototypes. */
Signature · 1 line
1.7.11.7
#28 lore raw

Re: [PATCH net-next 9/9] net: sctp: sctp_ulpq: do not use char as a struct member

Quoted 14 lines · Daniel Borkmann

Replace char with a more appropriate __u8 bitfield for pd_mode.

---
  include/net/sctp/ulpqueue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sctp/ulpqueue.h +0 -0
index 00e50ba..a2bebd4 100644
@@ -49,10 +49,10 @@
 

include/net/sctp/ulpqueue.h line 58

Quoted 10 lines
include/net/sctp/ulpqueue.h +1 -1
  /* A structure to carry information to the ULP (e.g. Sockets API) */
  struct sctp_ulpq {
-	char pd_mode;
  	struct sctp_association *asoc;
  	struct sk_buff_head reasm;
  	struct sk_buff_head lobby;
+	__u8 pd_mode:1;
  };
 
  /* Prototypes. */

This one is a bit pointless. You are not saving any space and making generated code worse.

-vlad

#29 lore raw

Re: [PATCH net-next 9/9] net: sctp: sctp_ulpq: do not use char as a struct member

Quoted 23 lines · Vlad Yasevich
Quoted 22 lines · Daniel Borkmann

Replace char with a more appropriate __u8 bitfield for pd_mode.

---
  include/net/sctp/ulpqueue.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sctp/ulpqueue.h +1 -1
index 00e50ba..a2bebd4 100644
@@ -49,10 +49,10 @@
 
  /* A structure to carry information to the ULP (e.g. Sockets API) */
  struct sctp_ulpq {
-    char pd_mode;
      struct sctp_association *asoc;
      struct sk_buff_head reasm;
      struct sk_buff_head lobby;
+    __u8 pd_mode:1;
  };
 
Quoted 3 lines

include/net/sctp/ulpqueue.h line 58

Quoted 1 line
include/net/sctp/ulpqueue.h +0 -0
  /* Prototypes. */

This one is a bit pointless. You are not saving any space and making generated code worse.

Right, this one should be dropped, if Dave wants me to resubmit from 0 to 8, I can do that, otherwise just this one can be left out.

#30 lore raw

Re: [PATCH net-next 9/9] net: sctp: sctp_ulpq: do not use char as a struct member

In reply to Daniel Borkmann
Quoted 12 lines · Daniel Borkmann

Replace char with a more appropriate __u8 bitfield for pd_mode.

---
 include/net/sctp/ulpqueue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/sctp/ulpqueue.h +0 -0
index 00e50ba..a2bebd4 100644

include/net/sctp/ulpqueue.h line 57

Quoted 10 lines
include/net/sctp/ulpqueue.h +1 -1
@@ -49,10 +49,10 @@
 
 /* A structure to carry information to the ULP (e.g. Sockets API) */
 struct sctp_ulpq {
-	char pd_mode;
 	struct sctp_association *asoc;
 	struct sk_buff_head reasm;
 	struct sk_buff_head lobby;
+	__u8 pd_mode:1;
 };
 

Can you move the char (or __u8 if you prefer) to right after the reasm meber? I think theres a hole there that you can fill in
Neil

#31 lore raw

RE: [PATCH net-next 9/9] net: sctp: sctp_ulpq: do not use char as a struct member

Quoted 4 lines
Quoted 4 lines

/* A structure to carry information to the ULP (e.g. Sockets API) */ struct sctp_ulpq {

include/net/sctp/ulpqueue.h +0 -1
-	char pd_mode;
 	struct sctp_association *asoc;
Quoted 8 lines

include/net/sctp/ulpqueue.h line 56

Quoted 5 lines
include/net/sctp/ulpqueue.h +1 -0
 	struct sk_buff_head reasm;
 	struct sk_buff_head lobby;
+	__u8 pd_mode:1;
 };

Can you move the char (or __u8 if you prefer) to right after the reasm meber? I think theres a hole there that you can fill in

If there is a hole after 'reasm' there will also be one after 'lobby'. In any case it can't be worse than the 7 byte pad after pd_mode in the existing file.

In the other structure there is a uint32 preceding the three flag bytes - so unless some other stuff is moved making them bitfields won't change any sizes at all.

FWIW we do use SCTP (for M3UA).
The code has to be an order of magnitude slower than TCP! Never mind the difficulty in generating long ethernet frames (since the data flow means you have to disable nagle).

David.

maintainer
#32 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Tue, 16 Apr 2013 23:07:09 +0200

Quoted 6 lines

That's a batch of cleanups for the SCTP protocol. Probably all deadly boring and trivial patches, but it always bugs me. :-) I guess this is still from the very SCTP beginning in Linux. Well, at least we can now remove 41 lines of code in total. lksctp-tools test suite run through without problems.

Quoted 10 lines

Daniel Borkmann (9):
net: sctp: sctp_ssnmap: remove 'malloced' element from struct
net: sctp: sctp_inq: remove dead code
net: sctp: sctp_outq: remove 'malloced' from its struct
net: sctp: sctp_outq: consolidate chars into bitfield
net: sctp: outqueue: simplify sctp_outq_uncork function
net: sctp: sctp_transport: remove unused variable
net: sctp: sctp_bind_addr: remove dead code
net: sctp: sctp_ulpq: remove 'malloced' struct member
net: sctp: sctp_ulpq: do not use char as a struct member

All applied except for #4 and #9, thanks.

#33 lore raw
Quoted 1 line · David Miller

All applied except for #4 and #9, thanks.

Thanks David !