mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Enable lockdep for more mutexes
PiperOrigin-RevId: 533162054
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
load("//tools:defs.bzl", "go_library", "go_test")
|
||||
load("//tools/go_generics:defs.bzl", "go_template_instance")
|
||||
load("//pkg/sync/locking:locking.bzl", "declare_mutex")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = ["//:license"],
|
||||
licenses = ["notice"],
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "refs_mutex",
|
||||
out = "refs_mutex.go",
|
||||
package = "fsutil",
|
||||
prefix = "refs",
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "maps_mutex",
|
||||
out = "maps_mutex.go",
|
||||
package = "fsutil",
|
||||
prefix = "maps",
|
||||
)
|
||||
|
||||
go_template_instance(
|
||||
name = "dirty_set_impl",
|
||||
out = "dirty_set_impl.go",
|
||||
@@ -70,6 +85,8 @@ go_library(
|
||||
"host_file_mapper.go",
|
||||
"host_file_mapper_state.go",
|
||||
"host_file_mapper_unsafe.go",
|
||||
"maps_mutex.go",
|
||||
"refs_mutex.go",
|
||||
],
|
||||
visibility = ["//pkg/sentry:internal"],
|
||||
deps = [
|
||||
@@ -88,6 +105,7 @@ go_library(
|
||||
"//pkg/sentry/usage",
|
||||
"//pkg/state",
|
||||
"//pkg/sync",
|
||||
"//pkg/sync/locking",
|
||||
"//pkg/usermem",
|
||||
"//pkg/waiter",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/safemem"
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
)
|
||||
|
||||
// HostFileMapper caches mappings of an arbitrary host file descriptor. It is
|
||||
@@ -35,13 +34,13 @@ type HostFileMapper struct {
|
||||
// size and alignment chunkSize, and caches mappings of the file on a chunk
|
||||
// granularity.
|
||||
|
||||
refsMu sync.Mutex `state:"nosave"`
|
||||
refsMu refsMutex `state:"nosave"`
|
||||
|
||||
// refs maps chunk start offsets to the sum of reference counts for all
|
||||
// pages in that chunk. refs is protected by refsMu.
|
||||
refs map[uint64]int32
|
||||
|
||||
mapsMu sync.Mutex `state:"nosave"`
|
||||
mapsMu mapsMutex `state:"nosave"`
|
||||
|
||||
// mappings maps chunk start offsets to mappings of those chunks,
|
||||
// obtained by calling unix.Mmap. mappings is protected by
|
||||
|
||||
@@ -36,6 +36,13 @@ declare_mutex(
|
||||
prefix = "task",
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "task_work_mutex",
|
||||
out = "task_work_mutex.go",
|
||||
package = "kernel",
|
||||
prefix = "taskWork",
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "cgroup_mutex",
|
||||
out = "cgroup_mutex.go",
|
||||
@@ -261,6 +268,7 @@ go_library(
|
||||
"task_syscall.go",
|
||||
"task_usermem.go",
|
||||
"task_work.go",
|
||||
"task_work_mutex.go",
|
||||
"taskset_mutex.go",
|
||||
"thread_group.go",
|
||||
"thread_group_timer_mutex.go",
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
load("//tools:defs.bzl", "go_library")
|
||||
load("//pkg/sync/locking:locking.bzl", "declare_mutex")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = ["//:license"],
|
||||
licenses = ["notice"],
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "reg_mutex",
|
||||
out = "reg_mutex.go",
|
||||
package = "fasync",
|
||||
prefix = "reg",
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "file_mutex",
|
||||
out = "file_mutex.go",
|
||||
package = "fasync",
|
||||
prefix = "file",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "fasync",
|
||||
srcs = ["fasync.go"],
|
||||
srcs = [
|
||||
"fasync.go",
|
||||
"file_mutex.go",
|
||||
"reg_mutex.go",
|
||||
],
|
||||
visibility = ["//:sandbox"],
|
||||
deps = [
|
||||
"//pkg/abi/linux",
|
||||
@@ -16,6 +35,7 @@ go_library(
|
||||
"//pkg/sentry/kernel/auth",
|
||||
"//pkg/sentry/vfs",
|
||||
"//pkg/sync",
|
||||
"//pkg/sync/locking",
|
||||
"//pkg/waiter",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel"
|
||||
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
|
||||
@@ -67,12 +66,12 @@ type FileAsync struct {
|
||||
// through the registration action itself.
|
||||
//
|
||||
// Lock ordering: regMu, mu.
|
||||
regMu sync.Mutex `state:"nosave"`
|
||||
regMu regMutex `state:"nosave"`
|
||||
|
||||
// mu protects all following fields.
|
||||
//
|
||||
// Lock ordering: e.mu, mu.
|
||||
mu sync.Mutex `state:"nosave"`
|
||||
mu fileMutex `state:"nosave"`
|
||||
requester *auth.Credentials
|
||||
registered bool
|
||||
// signal is the signal to deliver upon I/O being available.
|
||||
|
||||
@@ -74,7 +74,7 @@ type Task struct {
|
||||
taskWorkCount atomicbitops.Int32
|
||||
|
||||
// taskWorkMu protects taskWork.
|
||||
taskWorkMu sync.Mutex `state:"nosave"`
|
||||
taskWorkMu taskWorkMutex `state:"nosave"`
|
||||
|
||||
// taskWork is a queue of work to be executed before resuming user execution.
|
||||
// It is similar to the task_work mechanism in Linux.
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
load("//tools:defs.bzl", "go_library", "go_test")
|
||||
load("//tools/go_generics:defs.bzl", "go_template_instance")
|
||||
load("//pkg/sync/locking:locking.bzl", "declare_mutex")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = ["//:license"],
|
||||
licenses = ["notice"],
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "memory_file_mutex",
|
||||
out = "memory_file_mutex.go",
|
||||
package = "pgalloc",
|
||||
prefix = "memoryFile",
|
||||
)
|
||||
|
||||
declare_mutex(
|
||||
name = "mappings_mutex",
|
||||
out = "mappings_mutex.go",
|
||||
package = "pgalloc",
|
||||
prefix = "mappings",
|
||||
)
|
||||
|
||||
go_template_instance(
|
||||
name = "evictable_range",
|
||||
out = "evictable_range.go",
|
||||
@@ -78,6 +93,8 @@ go_library(
|
||||
"context.go",
|
||||
"evictable_range.go",
|
||||
"evictable_range_set.go",
|
||||
"mappings_mutex.go",
|
||||
"memory_file_mutex.go",
|
||||
"pgalloc.go",
|
||||
"pgalloc_unsafe.go",
|
||||
"reclaim_set.go",
|
||||
@@ -101,6 +118,7 @@ go_library(
|
||||
"//pkg/state",
|
||||
"//pkg/state/wire",
|
||||
"//pkg/sync",
|
||||
"//pkg/sync/locking",
|
||||
"//pkg/usermem",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
|
||||
@@ -96,7 +96,7 @@ type MemoryFile struct {
|
||||
// file is the backing file. The file pointer is immutable.
|
||||
file *os.File
|
||||
|
||||
mu sync.Mutex
|
||||
mu memoryFileMutex
|
||||
|
||||
// usage maps each page in the file to metadata for that page. Pages for
|
||||
// which no segment exists in usage are both unallocated (not in use) and
|
||||
@@ -152,7 +152,7 @@ type MemoryFile struct {
|
||||
// only requires *either* holding mappingsMu or using atomic memory
|
||||
// operations. This allows MemoryFile.MapInternal to avoid locking in the
|
||||
// common case where chunk mappings already exist.
|
||||
mappingsMu sync.Mutex
|
||||
mappingsMu mappingsMutex
|
||||
mappings atomic.Value
|
||||
|
||||
// destroyed is set by Destroy to instruct the reclaimer goroutine to
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
load("//tools:defs.bzl", "go_library")
|
||||
load("//pkg/sync/locking:locking.bzl", "declare_rwmutex")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = ["//:license"],
|
||||
licenses = ["notice"],
|
||||
)
|
||||
|
||||
declare_rwmutex(
|
||||
name = "memory_mutex",
|
||||
out = "memory_mutex.go",
|
||||
package = "usage",
|
||||
prefix = "memory",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "usage",
|
||||
srcs = [
|
||||
"cpu.go",
|
||||
"io.go",
|
||||
"memory.go",
|
||||
"memory_mutex.go",
|
||||
"memory_unsafe.go",
|
||||
"usage.go",
|
||||
],
|
||||
@@ -22,6 +31,7 @@ go_library(
|
||||
"//pkg/bits",
|
||||
"//pkg/memutil",
|
||||
"//pkg/sync",
|
||||
"//pkg/sync/locking",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/atomicbitops"
|
||||
"gvisor.dev/gvisor/pkg/bits"
|
||||
"gvisor.dev/gvisor/pkg/memutil"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
)
|
||||
|
||||
// MemoryKind represents a type of memory used by the application.
|
||||
@@ -118,7 +117,7 @@ type RTMemoryStats struct {
|
||||
|
||||
// MemoryLocked is Memory with access methods.
|
||||
type MemoryLocked struct {
|
||||
mu sync.RWMutex
|
||||
mu memoryRWMutex
|
||||
// memoryStats records the memory stats.
|
||||
memoryStats
|
||||
// RTMemoryStats records the memory stats that need to be exposed through
|
||||
|
||||
Reference in New Issue
Block a user