Skip to content

Commit d495ebf

Browse files
avagingvisor-bot
authored andcommitted
tcp: use lockdep mutexes
PiperOrigin-RevId: 761300509
1 parent 126267e commit d495ebf

File tree

8 files changed

+132
-26
lines changed

8 files changed

+132
-26
lines changed

pkg/tcpip/transport/tcp/BUILD

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("//pkg/sync/locking:locking.bzl", "declare_mutex", "declare_rwmutex")
12
load("//tools:defs.bzl", "go_library", "go_test")
23
load("//tools/go_generics:defs.bzl", "go_template_instance")
34

@@ -6,6 +7,104 @@ package(
67
licenses = ["notice"],
78
)
89

10+
declare_mutex(
11+
name = "snd_queue_mutex",
12+
out = "snd_queue_mutex.go",
13+
package = "tcp",
14+
prefix = "sndQueue",
15+
)
16+
17+
declare_mutex(
18+
name = "pending_processing_mutex",
19+
out = "pending_processing_mutex.go",
20+
package = "tcp",
21+
prefix = "pendingProcessing",
22+
)
23+
24+
declare_mutex(
25+
name = "last_error_mutex",
26+
out = "last_error_mutex.go",
27+
package = "tcp",
28+
prefix = "lastError",
29+
)
30+
31+
declare_mutex(
32+
name = "rcv_queue_mutex",
33+
out = "rcv_queue_mutex.go",
34+
package = "tcp",
35+
prefix = "rcvQueue",
36+
)
37+
38+
declare_mutex(
39+
name = "accept_mutex",
40+
out = "accept_mutex.go",
41+
package = "tcp",
42+
prefix = "accept",
43+
)
44+
45+
declare_mutex(
46+
name = "keepalive_mutex",
47+
out = "keepalive_mutex.go",
48+
package = "tcp",
49+
prefix = "keepalive",
50+
)
51+
52+
declare_mutex(
53+
name = "hasher_mutex",
54+
out = "hasher_mutex.go",
55+
package = "tcp",
56+
prefix = "hasher",
57+
)
58+
59+
declare_mutex(
60+
name = "forwarder_mutex",
61+
out = "forwarder_mutex.go",
62+
package = "tcp",
63+
prefix = "forwarder",
64+
)
65+
66+
declare_mutex(
67+
name = "forwarder_request_mutex",
68+
out = "forwarder_request_mutex.go",
69+
package = "tcp",
70+
prefix = "forwarderRequest",
71+
)
72+
73+
declare_mutex(
74+
name = "segment_queue_mutex",
75+
out = "segment_queue_mutex.go",
76+
package = "tcp",
77+
prefix = "segmentQueue",
78+
)
79+
80+
declare_mutex(
81+
name = "ep_queue_mutex",
82+
out = "ep_queue_mutex.go",
83+
package = "tcp",
84+
prefix = "epQueue",
85+
)
86+
87+
declare_mutex(
88+
name = "dispatcher_mutex",
89+
out = "dispatcher_mutex.go",
90+
package = "tcp",
91+
prefix = "dispatcher",
92+
)
93+
94+
declare_mutex(
95+
name = "rtt_mutex",
96+
out = "rtt_mutex.go",
97+
package = "tcp",
98+
prefix = "rtt",
99+
)
100+
101+
declare_rwmutex(
102+
name = "protocol_mutex",
103+
out = "protocol_mutex.go",
104+
package = "tcp",
105+
prefix = "protocol",
106+
)
107+
9108
go_template_instance(
10109
name = "tcp_segment_list",
11110
out = "tcp_segment_list.go",
@@ -45,27 +144,41 @@ go_library(
45144
name = "tcp",
46145
srcs = [
47146
"accept.go",
147+
"accept_mutex.go",
48148
"connect.go",
49149
"connect_unsafe.go",
50150
"cubic.go",
51151
"dispatcher.go",
152+
"dispatcher_mutex.go",
52153
"endpoint.go",
53154
"endpoint_state.go",
155+
"ep_queue_mutex.go",
54156
"forwarder.go",
157+
"forwarder_mutex.go",
158+
"forwarder_request_mutex.go",
159+
"hasher_mutex.go",
160+
"keepalive_mutex.go",
161+
"last_error_mutex.go",
162+
"pending_processing_mutex.go",
55163
"protocol.go",
164+
"protocol_mutex.go",
56165
"rack.go",
57166
"rcv.go",
167+
"rcv_queue_mutex.go",
58168
"reno.go",
59169
"reno_recovery.go",
170+
"rtt_mutex.go",
60171
"sack.go",
61172
"sack_recovery.go",
62173
"sack_scoreboard.go",
63174
"segment.go",
64175
"segment_heap.go",
65176
"segment_queue.go",
177+
"segment_queue_mutex.go",
66178
"segment_state.go",
67179
"segment_unsafe.go",
68180
"snd.go",
181+
"snd_queue_mutex.go",
69182
"state.go",
70183
"tcp_endpoint_list.go",
71184
"tcp_segment_list.go",
@@ -81,6 +194,7 @@ go_library(
81194
"//pkg/refs",
82195
"//pkg/sleep",
83196
"//pkg/sync",
197+
"//pkg/sync/locking",
84198
"//pkg/tcpip",
85199
"//pkg/tcpip/checksum",
86200
"//pkg/tcpip/hash/jenkins",

pkg/tcpip/transport/tcp/accept.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"io"
2424
"time"
2525

26-
"gvisor.dev/gvisor/pkg/sync"
2726
"gvisor.dev/gvisor/pkg/tcpip"
2827
"gvisor.dev/gvisor/pkg/tcpip/header"
2928
"gvisor.dev/gvisor/pkg/tcpip/ports"
@@ -88,7 +87,7 @@ type listenContext struct {
8887
listenEP *Endpoint
8988

9089
// hasherMu protects hasher.
91-
hasherMu sync.Mutex
90+
hasherMu hasherMutex
9291
// hasher is the hash function used to generate a SYN cookie.
9392
hasher hash.Hash
9493

pkg/tcpip/transport/tcp/dispatcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
//
3333
// +stateify savable
3434
type epQueue struct {
35-
mu sync.Mutex `state:"nosave"`
35+
mu epQueueMutex `state:"nosave"`
3636
list endpointList
3737
}
3838

@@ -365,7 +365,7 @@ type dispatcher struct {
365365
processors []processor
366366
wg sync.WaitGroup `state:"nosave"`
367367
hasher jenkinsHasher
368-
mu sync.Mutex `state:"nosave"`
368+
mu dispatcherMutex `state:"nosave"`
369369
// +checklocks:mu
370370
paused bool
371371
// +checklocks:mu

pkg/tcpip/transport/tcp/endpoint.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (*Stats) IsEndpointStats() {}
285285
//
286286
// +stateify savable
287287
type sndQueueInfo struct {
288-
sndQueueMu sync.Mutex `state:"nosave"`
288+
sndQueueMu sndQueueMutex `state:"nosave"`
289289
TCPSndBufState
290290
}
291291

@@ -354,7 +354,7 @@ type Endpoint struct {
354354
endpointEntry `state:"nosave"`
355355

356356
// pendingProcessingMu protects pendingProcessing.
357-
pendingProcessingMu sync.Mutex `state:"nosave"`
357+
pendingProcessingMu pendingProcessingMutex `state:"nosave"`
358358

359359
// pendingProcessing is true if this endpoint is queued for processing
360360
// to a TCP processor.
@@ -374,10 +374,10 @@ type Endpoint struct {
374374

375375
// lastError represents the last error that the endpoint reported;
376376
// access to it is protected by the following mutex.
377-
lastErrorMu sync.Mutex `state:"nosave"`
377+
lastErrorMu lastErrorMutex `state:"nosave"`
378378
lastError tcpip.Error
379379

380-
rcvQueueMu sync.Mutex `state:"nosave"`
380+
rcvQueueMu rcvQueueMutex `state:"nosave"`
381381

382382
// +checklocks:rcvQueueMu
383383
TCPRcvBufState
@@ -834,11 +834,11 @@ func calculateTTL(route *stack.Route, ipv4TTL uint8, ipv6HopLimit int16) uint8 {
834834
//
835835
// +stateify savable
836836
type keepalive struct {
837-
sync.Mutex `state:"nosave"`
838-
idle time.Duration
839-
interval time.Duration
840-
count int
841-
unacked int
837+
keepaliveMutex `state:"nosave"`
838+
idle time.Duration
839+
interval time.Duration
840+
count int
841+
unacked int
842842
// should never be a zero timer if the endpoint is not closed.
843843
timer timer `state:"nosave"`
844844
waker sleep.Waker `state:"nosave"`

pkg/tcpip/transport/tcp/forwarder.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"fmt"
1919

2020
"gvisor.dev/gvisor/pkg/buffer"
21-
"gvisor.dev/gvisor/pkg/sync"
2221
"gvisor.dev/gvisor/pkg/tcpip"
2322
"gvisor.dev/gvisor/pkg/tcpip/header"
2423
"gvisor.dev/gvisor/pkg/tcpip/seqnum"
@@ -38,7 +37,7 @@ type Forwarder struct {
3837
maxInFlight int
3938
handler func(*ForwarderRequest)
4039

41-
mu sync.Mutex
40+
mu forwarderMutex
4241
inFlight map[stack.TransportEndpointID]struct{}
4342
listen *listenContext
4443
}
@@ -111,7 +110,7 @@ func (f *Forwarder) HandlePacket(id stack.TransportEndpointID, pkt *stack.Packet
111110
// and passed to the client. Clients must eventually call Complete() on it, and
112111
// may optionally create an endpoint to represent it via CreateEndpoint.
113112
type ForwarderRequest struct {
114-
mu sync.Mutex
113+
mu forwarderRequestMutex
115114
forwarder *Forwarder
116115
segment *segment
117116
synOptions header.TCPSynOptions

pkg/tcpip/transport/tcp/protocol.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"strings"
2424
"time"
2525

26-
"gvisor.dev/gvisor/pkg/sync"
2726
"gvisor.dev/gvisor/pkg/tcpip"
2827
"gvisor.dev/gvisor/pkg/tcpip/header"
2928
"gvisor.dev/gvisor/pkg/tcpip/header/parse"
@@ -90,7 +89,7 @@ const (
9089
type protocol struct {
9190
stack *stack.Stack
9291

93-
mu sync.RWMutex `state:"nosave"`
92+
mu protocolRWMutex `state:"nosave"`
9493
sackEnabled bool
9594
recovery tcpip.TCPRecovery
9695
delayEnabled bool

pkg/tcpip/transport/tcp/segment_queue.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414

1515
package tcp
1616

17-
import (
18-
"gvisor.dev/gvisor/pkg/sync"
19-
)
20-
2117
// segmentQueue is a bounded, thread-safe queue of TCP segments.
2218
//
2319
// +stateify savable
2420
type segmentQueue struct {
25-
mu sync.Mutex `state:"nosave"`
26-
list segmentList `state:"wait"`
21+
mu segmentQueueMutex `state:"nosave"`
22+
list segmentList `state:"wait"`
2723
ep *Endpoint
2824
frozen bool
2925
}

pkg/tcpip/transport/tcp/snd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"time"
2222

2323
"gvisor.dev/gvisor/pkg/buffer"
24-
"gvisor.dev/gvisor/pkg/sync"
2524
"gvisor.dev/gvisor/pkg/tcpip"
2625
"gvisor.dev/gvisor/pkg/tcpip/header"
2726
"gvisor.dev/gvisor/pkg/tcpip/seqnum"
@@ -237,7 +236,7 @@ func (wl *protectedWriteList) InsertAfter(before, seg *segment) {
237236
//
238237
// +stateify savable
239238
type rtt struct {
240-
sync.Mutex `state:"nosave"`
239+
rttMutex `state:"nosave"`
241240

242241
TCPRTTState
243242
}

0 commit comments

Comments
 (0)