Skip to content

sctp: Avoid redundant initialisation in sctp_accept() and sctp_do_peeloff().

Kuniyuki Iwashima linux-sctp netdev 3 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest8 patches 8 repliesApplied 8/8
  2. v28 patches 8 repliesSuperseded
  3. v18 patches 1 replySuperseded

Changes in v3 from the cover letter

* Patch 4: Check if (lock) for bh_unlock_sock(). (Xin Long)

Patches in v3 All 8 applied

#Subject and filesSizeRepliesApplied
1/8sctp: Defer SCTP_DBG_OBJCNT_DEC() to sctp_destroy_sock().net/sctp/socket.c+3 -21 replyApplied
2/8sctp: Don't copy sk_sndbuf and sk_rcvbuf in sctp_sock_migrate().net/sctp/socket.c+2 -51 replyApplied
3/8sctp: Don't call sk->sk_prot->init() in sctp_v[46]_create_accept_sk().net/sctp/ipv6.c net/sctp/protocol.c net/sctp/socket.c+24 -191 replyApplied
4/8net: Add sk_clone().include/net/sock.h net/core/sock.c+22 -91 replyApplied
5/8sctp: Use sk_clone() in sctp_accept().net/ipv4/af_inet.c net/sctp/socket.c+77 -401 replyApplied
6/8sctp: Remove sctp_pf.create_accept_sk().include/net/sctp/structs.h net/sctp/ipv6.c net/sctp/protocol.c+0 -751 replyApplied
7/8sctp: Use sctp_clone_sock() in sctp_do_peeloff().net/ipv4/af_inet.c net/sctp/socket.c+16 -211 replyApplied
8/8sctp: Remove sctp_copy_sock() and sctp_copy_descendant().include/net/inet_sock.h include/net/sctp/sctp.h net/sctp/socket.c+1 -811 replyApplied

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchXin Long
1/8A-b
2/8A-b
3/8A-b
4/8R-b
5/8A-b
6/8A-b
7/8A-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 net-next 0/8] sctp: Avoid redundant initialisation in sctp_accept() and sctp_do_peeloff().

When sctp_accept() and sctp_do_peeloff() allocates a new socket, somehow sk_alloc() is used, and the new socket goes through full initialisation, but most of the fields are overwritten later.

1)
sctp_accept()

  |- sctp_v[46]_create_accept_sk()
  |  |- sk_alloc()
  |  |- sock_init_data()
  |  |- sctp_copy_sock()
  |  `- newsk->sk_prot->init() / sctp_init_sock()
  |

`- sctp_sock_migrate()
`- sctp_copy_descendant(newsk, oldsk)

sock_init_data() initialises struct sock, but many fields are overwritten by sctp_copy_sock(), which inherits fields of struct sock and inet_sock from the parent socket.

sctp_init_sock() fully initialises struct sctp_sock, but later sctp_copy_descendant() inherits most fields from the parent's struct sctp_sock by memcpy().

2)
sctp_do_peeloff()

  |- sock_create()
  |  |
  |  ...
  |      |- sk_alloc()
  |      |- sock_init_data()
  |  ...
  |    `- newsk->sk_prot->init() / sctp_init_sock()
  |
  |- sctp_copy_sock()

`- sctp_sock_migrate()
`- sctp_copy_descendant(newsk, oldsk)

sock_create() creates a brand new socket, but sctp_copy_sock() and sctp_sock_migrate() overwrite most of the fields.

So, sk_alloc(), sock_init_data(), sctp_copy_sock(), and sctp_copy_descendant() can be replaced with a single function like sk_clone_lock().

This series does the conversion and removes TODO comment added by commit 4a997d49d92ad ("tcp: Save lock_sock() for memcg in inet_csk_accept().").

Tested accept() and SCTP_SOCKOPT_PEELOFF and both work properly.

socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
listen(3, -1) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(49460), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP) = 4
connect(4, {sa_family=AF_INET, sin_port=htons(49460), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
accept(3, NULL, NULL) = 5
...
socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
listen(3, -1) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(48240), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP) = 4
connect(4, {sa_family=AF_INET, sin_port=htons(48240), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 getsockopt(3, SOL_SCTP, SCTP_SOCKOPT_PEELOFF, "*\0\0\0\5\0\0\0", [8]) = 5

Changes:
v3:
* Patch 4: Check if (lock) for bh_unlock_sock(). (Xin Long)

v2:
* Patch 7: Export __inet_accept()

v1: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (8):
sctp: Defer SCTP_DBG_OBJCNT_DEC() to sctp_destroy_sock().
sctp: Don't copy sk_sndbuf and sk_rcvbuf in sctp_sock_migrate().
sctp: Don't call sk->sk_prot->init() in sctp_v[46]_create_accept_sk().
net: Add sk_clone().
sctp: Use sk_clone() in sctp_accept().
sctp: Remove sctp_pf.create_accept_sk().
sctp: Use sctp_clone_sock() in sctp_do_peeloff().
sctp: Remove sctp_copy_sock() and sctp_copy_descendant().

 include/net/inet_sock.h    |   8 --
 include/net/sctp/sctp.h    |   3 +-
 include/net/sctp/structs.h |   3 -
 include/net/sock.h         |   7 +-
 net/core/sock.c            |  24 +++--
 net/ipv4/af_inet.c         |   5 +-
 net/sctp/ipv6.c            |  51 ---------
 net/sctp/protocol.c        |  33 ------
 net/sctp/socket.c          | 209 +++++++++++++++++--------------------
 9 files changed, 118 insertions(+), 225 deletions(-)
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog