tcpip/link: use lockdep mutexes

PiperOrigin-RevId: 692004573
This commit is contained in:
Andrei Vagin
2024-10-31 18:56:13 -07:00
committed by gVisor bot
parent b2d8bb498f
commit e2e84bf5ba
24 changed files with 184 additions and 30 deletions
+21 -1
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,12 +6,31 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "channel",
prefix = "endpoint",
)
declare_rwmutex(
name = "queue_mutex",
out = "queue_mutex.go",
package = "channel",
prefix = "queue",
)
go_library(
name = "channel",
srcs = ["channel.go"],
srcs = [
"channel.go",
"endpoint_mutex.go",
"queue_mutex.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+2 -3
View File
@@ -20,7 +20,6 @@ package channel
import (
"context"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
@@ -44,7 +43,7 @@ type NotificationHandle struct {
type queue struct {
// c is the outbound packet channel.
c chan *stack.PacketBuffer
mu sync.RWMutex
mu queueRWMutex
// +checklocks:mu
notify []*NotificationHandle
// +checklocks:mu
@@ -142,7 +141,7 @@ type Endpoint struct {
LinkEPCapabilities stack.LinkEndpointCapabilities
SupportedGSOKind stack.SupportedGSO
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
// +checklocks:mu
+26
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_mutex", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,15 +6,39 @@ package(
licenses = ["notice"],
)
declare_mutex(
name = "processor_mutex",
out = "processor_mutex.go",
package = "fdbased",
prefix = "processor",
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "fdbased",
prefix = "endpoint",
)
declare_rwmutex(
name = "injectable_endpoint_mutex",
out = "injectable_endpoint_mutex.go",
package = "fdbased",
prefix = "injectableEndpoint",
)
go_library(
name = "fdbased",
srcs = [
"endpoint.go",
"endpoint_mutex.go",
"endpoint_unsafe.go",
"injectable_endpoint_mutex.go",
"mmap.go",
"mmap_nonlinux.go",
"mmap_unsafe.go",
"packet_dispatchers.go",
"processor_mutex.go",
"processors.go",
"save_restore.go",
],
@@ -25,6 +50,7 @@ go_library(
"//pkg/rawfile",
"//pkg/sleep",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/hash/jenkins",
"//pkg/tcpip/header",
+2 -2
View File
@@ -133,7 +133,7 @@ type endpoint struct {
inboundDispatchers []linkDispatcher
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
@@ -863,7 +863,7 @@ func (*endpoint) SetOnCloseAction(func()) {}
type InjectableEndpoint struct {
endpoint
mu sync.RWMutex `state:"nosave"`
mu injectableEndpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+1 -1
View File
@@ -32,7 +32,7 @@ import (
// +stateify savable
type processor struct {
mu sync.Mutex `state:"nosave"`
mu processorMutex `state:"nosave"`
// +checklocks:mu
pkts stack.PacketBufferList
+14 -1
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library")
package(
@@ -5,11 +6,23 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "loopback",
prefix = "endpoint",
)
go_library(
name = "loopback",
srcs = ["loopback.go"],
srcs = [
"endpoint_mutex.go",
"loopback.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+1 -3
View File
@@ -21,8 +21,6 @@
package loopback
import (
"sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
@@ -34,7 +32,7 @@ const (
// +stateify savable
type endpoint struct {
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
// +checklocks:mu
+14 -1
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,12 +6,24 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "muxed",
prefix = "endpoint",
)
go_library(
name = "muxed",
srcs = ["injectable.go"],
srcs = [
"endpoint_mutex.go",
"injectable.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/buffer",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+1 -3
View File
@@ -16,8 +16,6 @@
package muxed
import (
"sync"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
@@ -33,7 +31,7 @@ import (
type InjectableEndpoint struct {
routes map[tcpip.Address]stack.InjectableLinkEndpoint
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+14 -1
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,11 +6,23 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "pipe",
prefix = "endpoint",
)
go_library(
name = "pipe",
srcs = ["pipe.go"],
srcs = [
"endpoint_mutex.go",
"pipe.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+1 -3
View File
@@ -17,8 +17,6 @@
package pipe
import (
"sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
@@ -47,7 +45,7 @@ func New(linkAddr1, linkAddr2 tcpip.LinkAddress, mtu uint32) (*Endpoint, *Endpoi
type Endpoint struct {
linked *Endpoint
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
// +checklocks:mu
+10
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_mutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,9 +6,17 @@ package(
licenses = ["notice"],
)
declare_mutex(
name = "dispatcher_mutex",
out = "dispatcher_mutex.go",
package = "fifo",
prefix = "queueDispatcher",
)
go_library(
name = "fifo",
srcs = [
"dispatcher_mutex.go",
"fifo.go",
"packet_buffer_circular_list.go",
],
@@ -16,6 +25,7 @@ go_library(
"//pkg/atomicbitops",
"//pkg/sleep",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/stack",
],
+1 -1
View File
@@ -58,7 +58,7 @@ type discipline struct {
type queueDispatcher struct {
lower stack.LinkWriter
mu sync.Mutex `state:"nosave"`
mu queueDispatcherMutex `state:"nosave"`
// +checklocks:mu
queue packetBufferCircularList
+18
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,11 +6,27 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "sharedmem",
prefix = "endpoint",
)
declare_rwmutex(
name = "server_endpoint_mutex",
out = "server_endpoint_mutex.go",
package = "sharedmem",
prefix = "serverEndpoint",
)
go_library(
name = "sharedmem",
srcs = [
"endpoint_mutex.go",
"queuepair.go",
"rx.go",
"server_endpoint_mutex.go",
"server_rx.go",
"server_tx.go",
"sharedmem.go",
@@ -29,6 +46,7 @@ go_library(
"//pkg/memutil",
"//pkg/rawfile",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/link/sharedmem/pipe",
+1 -1
View File
@@ -188,7 +188,7 @@ type endpoint struct {
onClosed func(tcpip.Error) `state:"nosave"`
// mu protects the following fields.
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// tx is the transmit queue.
// +checklocks:mu
+1 -1
View File
@@ -63,7 +63,7 @@ type serverEndpoint struct {
onClosed func(tcpip.Error) `state:"nosave"`
// mu protects the following fields.
mu sync.RWMutex `state:"nosave"`
mu serverEndpointRWMutex `state:"nosave"`
// tx is the transmit queue.
// +checklocks:mu
+10
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library")
load("//tools/go_generics:defs.bzl", "go_template_instance")
@@ -17,10 +18,18 @@ go_template_instance(
},
)
declare_rwmutex(
name = "device_mutex",
out = "device_mutex.go",
package = "tun",
prefix = "device",
)
go_library(
name = "tun",
srcs = [
"device.go",
"device_mutex.go",
"protocol.go",
"tun_endpoint_refs.go",
"tun_unsafe.go",
@@ -35,6 +44,7 @@ go_library(
"//pkg/log",
"//pkg/refs",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/link/channel",
+1 -2
View File
@@ -20,7 +20,6 @@ import (
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/link/channel"
@@ -46,7 +45,7 @@ var zeroMAC [6]byte
type Device struct {
waiter.Queue
mu sync.RWMutex `state:"nosave"`
mu deviceRWMutex `state:"nosave"`
endpoint *tunEndpoint
notifyHandle *channel.NotificationHandle
flags Flags
+21 -1
View File
@@ -1,3 +1,4 @@
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
load("//tools:defs.bzl", "go_library", "go_test")
package(
@@ -5,12 +6,31 @@ package(
licenses = ["notice"],
)
declare_rwmutex(
name = "veth_mutex",
out = "veth_mutex.go",
package = "veth",
prefix = "veth",
)
declare_rwmutex(
name = "endpoint_mutex",
out = "endpoint_mutex.go",
package = "veth",
prefix = "endpoint",
)
go_library(
name = "veth",
srcs = ["veth.go"],
srcs = [
"endpoint_mutex.go",
"veth.go",
"veth_mutex.go",
],
visibility = ["//visibility:public"],
deps = [
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip",
"//pkg/tcpip/header",
"//pkg/tcpip/stack",
+2 -3
View File
@@ -16,7 +16,6 @@
package veth
import (
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
@@ -27,7 +26,7 @@ var _ stack.GSOEndpoint = (*Endpoint)(nil)
// +stateify savable
type veth struct {
mu sync.RWMutex `state:"nosave"`
mu vethRWMutex `state:"nosave"`
closed bool
backlogQueue chan vethPacket `state:"nosave"`
mtu uint32
@@ -73,7 +72,7 @@ type Endpoint struct {
veth *veth
mu sync.RWMutex `state:"nosave"`
mu endpointRWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
// linkAddr is the local address of this endpoint.

Some files were not shown because too many files have changed in this diff Show More