From ca4626f24f1ff690f6ebf9627b2df6c307391187 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Thu, 13 Apr 2023 15:52:41 -0700 Subject: [PATCH] `runsc`: Remove syscall number from the unimplemented syscall counter. Doing so has performance implications which need to be fixed before this can be added back. PiperOrigin-RevId: 524125147 --- pkg/sentry/kernel/syscalls.go | 17 ++++------------- runsc/container/metric_server_test.go | 13 ++++++++----- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pkg/sentry/kernel/syscalls.go b/pkg/sentry/kernel/syscalls.go index fdf8b1c67..5d99d5ab3 100644 --- a/pkg/sentry/kernel/syscalls.go +++ b/pkg/sentry/kernel/syscalls.go @@ -16,7 +16,6 @@ package kernel import ( "fmt" - "strconv" "google.golang.org/protobuf/proto" "gvisor.dev/gvisor/pkg/abi" @@ -391,13 +390,8 @@ func RegisterSyscallTable(s *SyscallTable) { } allSyscallTables = append(allSyscallTables, s) unimplementedSyscallCounterInit.Do(func() { - allowedValues := make([]string, maxSyscallNum+2) - unimplementedSyscallNumbers = make(map[uintptr]string, len(allowedValues)) - for i := uintptr(0); i <= maxSyscallNum; i++ { - s := strconv.Itoa(int(i)) - allowedValues[i] = s - unimplementedSyscallNumbers[i] = s - } + allowedValues := make([]string, 1) + // TODO(b/278108862): Add all other syscall numbers once doing so is possible. allowedValues[len(allowedValues)-1] = outOfRangeSyscallNumber unimplementedSyscallCounter = metric.MustCreateNewUint64Metric("unimplemented_syscalls", true, "Number of times the application tried to call an unimplemented syscall, broken down by syscall number", metric.NewField("sysno", allowedValues)) }) @@ -499,9 +493,6 @@ type SyscallInfo struct { // //go:nosplit func IncrementUnimplementedSyscallCounter(sysno uintptr) { - s, found := unimplementedSyscallNumbers[sysno] - if !found { - s = outOfRangeSyscallNumber - } - unimplementedSyscallCounter.Increment(s) + // TODO(b/278108862): Use the real syscall number once doing so is possible.s, found := unimplementedSyscallNumbers[sysno] + unimplementedSyscallCounter.Increment(outOfRangeSyscallNumber) } diff --git a/runsc/container/metric_server_test.go b/runsc/container/metric_server_test.go index 1b954014b..fa4bb3946 100644 --- a/runsc/container/metric_server_test.go +++ b/runsc/container/metric_server_test.go @@ -859,26 +859,29 @@ func TestMetricServerDoesNotExportZeroValueCounters(t *testing.T) { for _, test := range []struct { cont *Container - sysno uintptr + sysno int wantExistence bool }{ {unimpl1, 1337, true}, - {unimpl1, 1338, false}, - {unimpl2, 1337, false}, + // TODO(b/278108862): Uncomment this: {unimpl1, 1338, false}, + // TODO(b/278108862): Uncomment this: {unimpl2, 1337, false}, {unimpl2, 1338, true}, } { + // TODO(b/278108862): Undo this hack: + test.sysno = -1 + t.Run(fmt.Sprintf("container %s syscall %d", test.cont.ID, test.sysno), func(t *testing.T) { check := func() error { got, _, err := metricDataPtr.GetPrometheusContainerInteger(metricclient.WantMetric{ Metric: "testmetric_unimplemented_syscalls", Sandbox: test.cont.sandboxID(), - ExtraLabels: map[string]string{"sysno": strconv.Itoa(int(test.sysno))}, + ExtraLabels: map[string]string{"sysno": strconv.Itoa(test.sysno)}, }) if test.wantExistence { if err != nil { return fmt.Errorf("cannot get unimplemented syscall metric for sysno=%d even though we expected its presence: %v", test.sysno, err) } - if got != 1 { + if got <= 0 /* TODO(b/278108862): Revert to got != 1 */ { return fmt.Errorf("expected counter value for unimplemented syscall %d be exactly 1, got %d", test.sysno, got) } } else /* !test.wantExistence */ {