Skip to content

Commit 6658538

Browse files
committed
Merge release-20250820.0-48-gbf4fd11e1 (automated)
2 parents 1f30edf + bf4fd11 commit 6658538

File tree

145 files changed

+319
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+319
-405
lines changed

pkg/gomaxprocs/gomaxprocs_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func gomaxprocsinitLockNames() {}
6060

6161
func init() {
6262
gomaxprocsinitLockNames()
63-
gomaxprocsprefixIndex = locking.NewMutexClass(reflect.TypeOf(gomaxprocsMutex{}), gomaxprocslockNames)
63+
gomaxprocsprefixIndex = locking.NewMutexClass(reflect.TypeFor[gomaxprocsMutex](), gomaxprocslockNames)
6464
}

pkg/metric/metric.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func newFieldMapper(fields ...Field) (fieldMapper, error) {
384384
// +checkescape:all
385385
//
386386
//go:nosplit
387-
func (m fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, remainingCombinationBucket int) (int, int) {
387+
func (m *fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, remainingCombinationBucket int) (int, int) {
388388
field := m.fields[fieldIndex]
389389
numValues := len(field.values)
390390

@@ -422,7 +422,7 @@ func (m fieldMapper) lookupSingle(fieldIndex int, fieldValue *FieldValue, idx, r
422422
// +checkescape:all
423423
//
424424
//go:nosplit
425-
func (m fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
425+
func (m *fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
426426
if (len(fields1) + len(fields2)) != len(m.fields) {
427427
panic("invalid field lookup depth")
428428
}
@@ -447,15 +447,15 @@ func (m fieldMapper) lookupConcat(fields1, fields2 []*FieldValue) int {
447447
// +checkescape:all
448448
//
449449
//go:nosplit
450-
func (m fieldMapper) lookup(fields ...*FieldValue) int {
450+
func (m *fieldMapper) lookup(fields ...*FieldValue) int {
451451
return m.lookupConcat(fields, nil)
452452
}
453453

454454
// numKeys returns the total number of key-to-field-combinations mappings
455455
// defined by the fieldMapper.
456456
//
457457
//go:nosplit
458-
func (m fieldMapper) numKeys() int {
458+
func (m *fieldMapper) numKeys() int {
459459
return m.numFieldCombinations
460460
}
461461

@@ -464,7 +464,7 @@ func (m fieldMapper) numKeys() int {
464464
// accessed using index "keys" made by fieldMapper.
465465
// - The second level corresponds to buckets within a metric. The number of
466466
// buckets is specified by numBuckets.
467-
func (m fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.Uint64 {
467+
func (m *fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.Uint64 {
468468
samples := make([][]atomicbitops.Uint64, m.numKeys())
469469
for i := range samples {
470470
samples[i] = make([]atomicbitops.Uint64, numBuckets)
@@ -475,7 +475,7 @@ func (m fieldMapper) makeDistributionSampleMap(numBuckets int) [][]atomicbitops.
475475
// keyToMultiField is the reverse of lookup/lookupConcat. The returned list of
476476
// field values corresponds to the same order of fields that were passed in to
477477
// newFieldMapper.
478-
func (m fieldMapper) keyToMultiField(key int) []string {
478+
func (m *fieldMapper) keyToMultiField(key int) []string {
479479
depth := len(m.fields)
480480
if depth == 0 && key == 0 {
481481
return nil
@@ -495,7 +495,7 @@ func (m fieldMapper) keyToMultiField(key int) []string {
495495
// `len(m.fields)`.
496496
//
497497
//go:nosplit
498-
func (m fieldMapper) keyToMultiFieldInPlace(key int, fieldValues []*FieldValue) {
498+
func (m *fieldMapper) keyToMultiFieldInPlace(key int, fieldValues []*FieldValue) {
499499
if len(m.fields) == 0 {
500500
return
501501
}
@@ -1386,10 +1386,10 @@ func EmitMetricUpdate() {
13861386
if (!ok && metricValue == 0) || (ok && prev.([]uint64)[fieldKey] == metricValue) {
13871387
continue
13881388
}
1389-
1389+
uint64M := allMetrics.uint64Metrics[k]
13901390
m.Metrics = append(m.Metrics, &pb.MetricValue{
13911391
Name: k,
1392-
FieldValues: allMetrics.uint64Metrics[k].fieldMapper.keyToMultiField(fieldKey),
1392+
FieldValues: uint64M.fieldMapper.keyToMultiField(fieldKey),
13931393
Value: &pb.MetricValue_Uint64Value{Uint64Value: metricValue},
13941394
})
13951395
}

pkg/ring0/kernel_amd64.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func HaltAndWriteFSBase(regs *arch.Registers)
3232

3333
// init initializes architecture-specific state.
3434
func (k *Kernel) init(maxCPUs int) {
35-
entrySize := reflect.TypeOf(kernelEntry{}).Size()
35+
entrySize := reflect.TypeFor[kernelEntry]().Size()
3636
var (
3737
entries []kernelEntry
3838
padding = 1
@@ -51,7 +51,7 @@ func (k *Kernel) init(maxCPUs int) {
5151
k.cpuEntries = entries
5252

5353
k.globalIDT = &idt64{}
54-
if reflect.TypeOf(idt64{}).Size() != hostarch.PageSize {
54+
if reflect.TypeFor[idt64]().Size() != hostarch.PageSize {
5555
panic("Size of globalIDT should be PageSize")
5656
}
5757
if reflect.ValueOf(k.globalIDT).Pointer()&(hostarch.PageSize-1) != 0 {
@@ -77,12 +77,12 @@ func (k *Kernel) EntryRegions() map[uintptr]uintptr {
7777
regions := make(map[uintptr]uintptr)
7878

7979
addr := reflect.ValueOf(&k.cpuEntries[0]).Pointer()
80-
size := reflect.TypeOf(kernelEntry{}).Size() * uintptr(len(k.cpuEntries))
80+
size := reflect.TypeFor[kernelEntry]().Size() * uintptr(len(k.cpuEntries))
8181
end, _ := hostarch.Addr(addr + size).RoundUp()
8282
regions[uintptr(hostarch.Addr(addr).RoundDown())] = uintptr(end)
8383

8484
addr = reflect.ValueOf(k.globalIDT).Pointer()
85-
size = reflect.TypeOf(idt64{}).Size()
85+
size = reflect.TypeFor[idt64]().Size()
8686
end, _ = hostarch.Addr(addr + size).RoundUp()
8787
regions[uintptr(hostarch.Addr(addr).RoundDown())] = uintptr(end)
8888

pkg/sentry/control/lifecycle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"google.golang.org/protobuf/types/known/timestamppb"
2323
"gvisor.dev/gvisor/pkg/abi/linux"
24+
"gvisor.dev/gvisor/pkg/cleanup"
2425
"gvisor.dev/gvisor/pkg/eventchannel"
2526
"gvisor.dev/gvisor/pkg/fd"
2627
"gvisor.dev/gvisor/pkg/log"
@@ -288,6 +289,8 @@ func (l *Lifecycle) StartContainer(args *StartContainerArgs, _ *uint32) error {
288289

289290
initArgs.MountNamespace = mntns
290291
initArgs.MountNamespace.IncRef()
292+
mntnsCu := cleanup.Make(func() { initArgs.MountNamespace.DecRef(ctx) })
293+
defer mntnsCu.Clean()
291294

292295
if args.ResolveBinaryPath {
293296
resolved, err := user.ResolveExecutablePath(ctx, &initArgs)
@@ -327,6 +330,7 @@ func (l *Lifecycle) StartContainer(args *StartContainerArgs, _ *uint32) error {
327330
}
328331
initArgs.InitialCgroups = initialCgroups
329332

333+
mntnsCu.Release() // mntns ref is transferred to Kernel.CreateProcess()
330334
tg, _, err := l.Kernel.CreateProcess(initArgs)
331335
if err != nil {
332336
return err

pkg/sentry/control/proc.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"gvisor.dev/gvisor/pkg/abi/linux"
28+
"gvisor.dev/gvisor/pkg/cleanup"
2829
"gvisor.dev/gvisor/pkg/fd"
2930
"gvisor.dev/gvisor/pkg/log"
3031
"gvisor.dev/gvisor/pkg/sentry/fdimport"
@@ -217,13 +218,18 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadI
217218
PIDNamespace: pidns,
218219
Origin: kernel.OriginExec,
219220
}
220-
if initArgs.MountNamespace != nil {
221-
// initArgs must hold a reference on MountNamespace, which will
222-
// be donated to the new process in CreateProcess.
223-
initArgs.MountNamespace.IncRef()
224-
}
225221
ctx := initArgs.NewContext(proc.Kernel)
226222

223+
if initArgs.MountNamespace == nil {
224+
// Set initArgs so that 'ctx' returns the namespace.
225+
initArgs.MountNamespace = proc.Kernel.GlobalInit().Leader().MountNamespace()
226+
}
227+
// initArgs must hold a reference on MountNamespace, which will
228+
// be donated to the new process in CreateProcess.
229+
initArgs.MountNamespace.IncRef()
230+
mntnsCu := cleanup.Make(func() { initArgs.MountNamespace.DecRef(ctx) })
231+
defer mntnsCu.Clean()
232+
227233
// Import file descriptors.
228234
var fdTable *kernel.FDTable
229235
if args.FDTable != nil {
@@ -235,15 +241,6 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadI
235241
}
236242
initArgs.FDTable = fdTable
237243

238-
// Get the full path to the filename from the PATH env variable.
239-
if initArgs.MountNamespace == nil {
240-
// Set initArgs so that 'ctx' returns the namespace.
241-
//
242-
// Add a reference to the namespace, which is transferred to the new process.
243-
initArgs.MountNamespace = proc.Kernel.GlobalInit().Leader().MountNamespace()
244-
initArgs.MountNamespace.IncRef()
245-
}
246-
247244
fdMap, execFD, err := args.unpackFiles()
248245
if err != nil {
249246
return nil, 0, nil, fmt.Errorf("creating fd map: %w", err)
@@ -311,6 +308,7 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadI
311308
initArgs.InitialCgroups = initialCgrps
312309
}
313310

311+
mntnsCu.Release() // mntns ref is transferred to Kernel.CreateProcess()
314312
tg, tid, err := proc.Kernel.CreateProcess(initArgs)
315313
if err != nil {
316314
return nil, 0, nil, err

pkg/sentry/devices/nvproxy/fds_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func fdsinitLockNames() {}
6060

6161
func init() {
6262
fdsinitLockNames()
63-
fdsprefixIndex = locking.NewMutexClass(reflect.TypeOf(fdsMutex{}), fdslockNames)
63+
fdsprefixIndex = locking.NewMutexClass(reflect.TypeFor[fdsMutex](), fdslockNames)
6464
}

pkg/sentry/devices/nvproxy/frontend_mmap_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func frontendMmapinitLockNames() {}
6060

6161
func init() {
6262
frontendMmapinitLockNames()
63-
frontendMmapprefixIndex = locking.NewMutexClass(reflect.TypeOf(frontendMmapMutex{}), frontendMmaplockNames)
63+
frontendMmapprefixIndex = locking.NewMutexClass(reflect.TypeFor[frontendMmapMutex](), frontendMmaplockNames)
6464
}

pkg/sentry/devices/nvproxy/objs_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func objsinitLockNames() {}
6060

6161
func init() {
6262
objsinitLockNames()
63-
objsprefixIndex = locking.NewMutexClass(reflect.TypeOf(objsMutex{}), objslockNames)
63+
objsprefixIndex = locking.NewMutexClass(reflect.TypeFor[objsMutex](), objslockNames)
6464
}

pkg/sentry/fsimpl/cgroupfs/pids_controller_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ func pidsControllerinitLockNames() {}
6060

6161
func init() {
6262
pidsControllerinitLockNames()
63-
pidsControllerprefixIndex = locking.NewMutexClass(reflect.TypeOf(pidsControllerMutex{}), pidsControllerlockNames)
63+
pidsControllerprefixIndex = locking.NewMutexClass(reflect.TypeFor[pidsControllerMutex](), pidsControllerlockNames)
6464
}

pkg/sentry/fsimpl/cgroupfs/task_mutex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ func taskinitLockNames() {}
9292

9393
func init() {
9494
taskinitLockNames()
95-
taskprefixIndex = locking.NewMutexClass(reflect.TypeOf(taskRWMutex{}), tasklockNames)
95+
taskprefixIndex = locking.NewMutexClass(reflect.TypeFor[taskRWMutex](), tasklockNames)
9696
}

0 commit comments

Comments
 (0)