Update dependencies
This commit is contained in:
@@ -308,7 +308,7 @@ func (fs FeatureSet) HasFeature(feature Feature) bool {
|
||||
|
||||
// WriteCPUInfoTo is to generate a section of one cpu in /proc/cpuinfo. This is
|
||||
// a minimal /proc/cpuinfo, it is missing some fields like "microcode" that are
|
||||
// not always printed in Linux. The bogomips field is simply made up.
|
||||
// not always printed in Linux. Several fields are simply made up.
|
||||
func (fs FeatureSet) WriteCPUInfoTo(cpu, numCPU uint, w io.Writer) {
|
||||
// Avoid many redundant calls here, since this can occasionally appear
|
||||
// in the hot path. Read all basic information up front, see above.
|
||||
@@ -322,6 +322,13 @@ func (fs FeatureSet) WriteCPUInfoTo(cpu, numCPU uint, w io.Writer) {
|
||||
fmt.Fprintf(w, "model name\t: %s\n", "unknown") // Unknown for now.
|
||||
fmt.Fprintf(w, "stepping\t: %s\n", "unknown") // Unknown for now.
|
||||
fmt.Fprintf(w, "cpu MHz\t\t: %.3f\n", cpuFreqMHz)
|
||||
// Pretend the CPU has 8192 KB of cache. Note that real /proc/cpuinfo exposes total L3 cache
|
||||
// size on Intel and per-core L2 cache size on AMD (as of Linux 6.1.0), so the value of this
|
||||
// field is not really important in practice. Any value that is chosen here will be wrong
|
||||
// by an order of magnitude on a significant chunk of x86 machines.
|
||||
// 8192 KB is selected because it is a reasonable size that will be effectively usable on
|
||||
// lightly loaded machines - most machines have 1-4MB of L3 cache per core.
|
||||
fmt.Fprintf(w, "cache size\t: 8192 KB\n")
|
||||
fmt.Fprintf(w, "physical id\t: 0\n") // Pretend all CPUs are in the same socket.
|
||||
fmt.Fprintf(w, "siblings\t: %d\n", numCPU)
|
||||
fmt.Fprintf(w, "core id\t\t: %d\n", cpu)
|
||||
@@ -473,3 +480,17 @@ func (fs FeatureSet) archCheckHostCompatible(hfs FeatureSet) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllowedHWCap1 returns the HWCAP1 bits that the guest is allowed to depend
|
||||
// on.
|
||||
func (fs FeatureSet) AllowedHWCap1() uint64 {
|
||||
// HWCAPS are not supported on amd64.
|
||||
return 0
|
||||
}
|
||||
|
||||
// AllowedHWCap2 returns the HWCAP2 bits that the guest is allowed to depend
|
||||
// on.
|
||||
func (fs FeatureSet) AllowedHWCap2() uint64 {
|
||||
// HWCAPS are not supported on amd64.
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// automatically generated by stateify.
|
||||
|
||||
//go:build amd64 && amd64 && amd64 && amd64
|
||||
// +build amd64,amd64,amd64,amd64
|
||||
//go:build amd64 && amd64 && amd64 && amd64 && amd64
|
||||
// +build amd64,amd64,amd64,amd64,amd64
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
@@ -108,3 +108,47 @@ func (fs FeatureSet) WriteCPUInfoTo(cpu, numCPU uint, w io.Writer) {
|
||||
func (FeatureSet) archCheckHostCompatible(FeatureSet) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllowedHWCap1 returns the HWCAP1 bits that the guest is allowed to depend
|
||||
// on.
|
||||
func (fs FeatureSet) AllowedHWCap1() uint64 {
|
||||
// Pick a set of safe HWCAPS to expose. These do not rely on cpu state
|
||||
// that gvisor does not restore after a context switch.
|
||||
allowed := HWCAP_AES |
|
||||
HWCAP_ASIMD |
|
||||
HWCAP_ASIMDDP |
|
||||
HWCAP_ASIMDFHM |
|
||||
HWCAP_ASIMDHP |
|
||||
HWCAP_ASIMDRDM |
|
||||
HWCAP_ATOMICS |
|
||||
HWCAP_CRC32 |
|
||||
HWCAP_DCPOP |
|
||||
HWCAP_DIT |
|
||||
HWCAP_EVTSTRM |
|
||||
HWCAP_FCMA |
|
||||
HWCAP_FLAGM |
|
||||
HWCAP_FP |
|
||||
HWCAP_FPHP |
|
||||
HWCAP_ILRCPC |
|
||||
HWCAP_JSCVT |
|
||||
HWCAP_LRCPC |
|
||||
HWCAP_PMULL |
|
||||
HWCAP_SHA1 |
|
||||
HWCAP_SHA2 |
|
||||
HWCAP_SHA3 |
|
||||
HWCAP_SHA512 |
|
||||
HWCAP_SM3 |
|
||||
HWCAP_SM4 |
|
||||
HWCAP_USCAT
|
||||
return fs.hwCap.hwCap1 & uint64(allowed)
|
||||
}
|
||||
|
||||
// AllowedHWCap2 returns the HWCAP2 bits that the guest is allowed to depend
|
||||
// on.
|
||||
func (fs FeatureSet) AllowedHWCap2() uint64 {
|
||||
// We don't expose anything here yet, but this could be expanded to
|
||||
// include features do not rely on cpu state that is not restored after
|
||||
// a context switch.
|
||||
allowed := 0
|
||||
return fs.hwCap.hwCap2 & uint64(allowed)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// automatically generated by stateify.
|
||||
|
||||
//go:build arm64 && arm64 && arm64
|
||||
// +build arm64,arm64,arm64
|
||||
//go:build arm64 && arm64 && arm64 && arm64
|
||||
// +build arm64,arm64,arm64,arm64
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
24
vendor/gvisor.dev/gvisor/pkg/cpuid/hwcap_amd64.go
vendored
Normal file
24
vendor/gvisor.dev/gvisor/pkg/cpuid/hwcap_amd64.go
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2024 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build amd64
|
||||
// +build amd64
|
||||
|
||||
package cpuid
|
||||
|
||||
// See arch/x86/include/uapi/asm/hwcap2.h
|
||||
const (
|
||||
HWCAP2_RING3MWAIT = 1 << 0
|
||||
HWCAP2_FSGSBASE = 1 << 1
|
||||
)
|
||||
79
vendor/gvisor.dev/gvisor/pkg/cpuid/hwcap_arm64.go
vendored
Normal file
79
vendor/gvisor.dev/gvisor/pkg/cpuid/hwcap_arm64.go
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright 2024 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build arm64
|
||||
// +build arm64
|
||||
|
||||
package cpuid
|
||||
|
||||
// See arch/arm64/include/uapi/asm/hwcap.h
|
||||
const (
|
||||
// HWCAP flags for AT_HWCAP.
|
||||
HWCAP_FP = 1 << 0
|
||||
HWCAP_ASIMD = 1 << 1
|
||||
HWCAP_EVTSTRM = 1 << 2
|
||||
HWCAP_AES = 1 << 3
|
||||
HWCAP_PMULL = 1 << 4
|
||||
HWCAP_SHA1 = 1 << 5
|
||||
HWCAP_SHA2 = 1 << 6
|
||||
HWCAP_CRC32 = 1 << 7
|
||||
HWCAP_ATOMICS = 1 << 8
|
||||
HWCAP_FPHP = 1 << 9
|
||||
HWCAP_ASIMDHP = 1 << 10
|
||||
HWCAP_CPUID = 1 << 11
|
||||
HWCAP_ASIMDRDM = 1 << 12
|
||||
HWCAP_JSCVT = 1 << 13
|
||||
HWCAP_FCMA = 1 << 14
|
||||
HWCAP_LRCPC = 1 << 15
|
||||
HWCAP_DCPOP = 1 << 16
|
||||
HWCAP_SHA3 = 1 << 17
|
||||
HWCAP_SM3 = 1 << 18
|
||||
HWCAP_SM4 = 1 << 19
|
||||
HWCAP_ASIMDDP = 1 << 20
|
||||
HWCAP_SHA512 = 1 << 21
|
||||
HWCAP_SVE = 1 << 22
|
||||
HWCAP_ASIMDFHM = 1 << 23
|
||||
HWCAP_DIT = 1 << 24
|
||||
HWCAP_USCAT = 1 << 25
|
||||
HWCAP_ILRCPC = 1 << 26
|
||||
HWCAP_FLAGM = 1 << 27
|
||||
HWCAP_SSBS = 1 << 28
|
||||
HWCAP_SB = 1 << 29
|
||||
HWCAP_PACA = 1 << 30
|
||||
HWCAP_PACG = 1 << 31
|
||||
|
||||
// HWCAP2 flags for AT_HWCAP2.
|
||||
HWCAP2_DCPODP = 1 << 0
|
||||
HWCAP2_SVE2 = 1 << 1
|
||||
HWCAP2_SVEAES = 1 << 2
|
||||
HWCAP2_SVEPMULL = 1 << 3
|
||||
HWCAP2_SVEBITPERM = 1 << 4
|
||||
HWCAP2_SVESHA3 = 1 << 5
|
||||
HWCAP2_SVESM4 = 1 << 6
|
||||
HWCAP2_FLAGM2 = 1 << 7
|
||||
HWCAP2_FRINT = 1 << 8
|
||||
HWCAP2_SVEI8MM = 1 << 9
|
||||
HWCAP2_SVEF32MM = 1 << 10
|
||||
HWCAP2_SVEF64MM = 1 << 11
|
||||
HWCAP2_SVEBF16 = 1 << 12
|
||||
HWCAP2_I8MM = 1 << 13
|
||||
HWCAP2_BF16 = 1 << 14
|
||||
HWCAP2_DGH = 1 << 15
|
||||
HWCAP2_RNG = 1 << 16
|
||||
HWCAP2_BTI = 1 << 17
|
||||
HWCAP2_MTE = 1 << 18
|
||||
HWCAP2_ECV = 1 << 19
|
||||
HWCAP2_AFP = 1 << 20
|
||||
HWCAP2_RPRES = 1 << 21
|
||||
)
|
||||
@@ -18,9 +18,10 @@
|
||||
package cpuid
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
)
|
||||
@@ -180,39 +181,44 @@ var (
|
||||
// filter installation. This value is used to create the fake /proc/cpuinfo
|
||||
// from a FeatureSet.
|
||||
func readMaxCPUFreq() {
|
||||
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
cpuinfoFile, err := os.Open("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
// Leave it as 0... the VDSO bails out in the same way.
|
||||
log.Warningf("Could not read /proc/cpuinfo: %v", err)
|
||||
log.Warningf("Could not open /proc/cpuinfo: %v", err)
|
||||
return
|
||||
}
|
||||
cpuinfo := string(cpuinfob)
|
||||
defer cpuinfoFile.Close()
|
||||
|
||||
// We get the value straight from host /proc/cpuinfo. On machines with
|
||||
// frequency scaling enabled, this will only get the current value
|
||||
// which will likely be inaccurate. This is fine on machines with
|
||||
// frequency scaling disabled.
|
||||
for _, line := range strings.Split(cpuinfo, "\n") {
|
||||
if strings.Contains(line, "cpu MHz") {
|
||||
splitMHz := strings.Split(line, ":")
|
||||
s := bufio.NewScanner(cpuinfoFile)
|
||||
for s.Scan() {
|
||||
line := s.Bytes()
|
||||
if bytes.Contains(line, []byte("cpu MHz")) {
|
||||
splitMHz := bytes.Split(line, []byte(":"))
|
||||
if len(splitMHz) < 2 {
|
||||
log.Warningf("Could not read /proc/cpuinfo: malformed cpu MHz line")
|
||||
log.Warningf("Could not parse /proc/cpuinfo: malformed cpu MHz line: %q", line)
|
||||
return
|
||||
}
|
||||
|
||||
// If there was a problem, leave cpuFreqMHz as 0.
|
||||
var err error
|
||||
cpuFreqMHz, err = strconv.ParseFloat(strings.TrimSpace(splitMHz[1]), 64)
|
||||
splitMHzStr := string(bytes.TrimSpace(splitMHz[1]))
|
||||
f64MHz, err := strconv.ParseFloat(splitMHzStr, 64)
|
||||
if err != nil {
|
||||
log.Warningf("Could not parse cpu MHz value %v: %v", splitMHz[1], err)
|
||||
cpuFreqMHz = 0
|
||||
log.Warningf("Could not parse cpu MHz value %q: %v", splitMHzStr, err)
|
||||
return
|
||||
}
|
||||
cpuFreqMHz = f64MHz
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
log.Warningf("Could not read /proc/cpuinfo: %v", err)
|
||||
return
|
||||
}
|
||||
log.Warningf("Could not parse /proc/cpuinfo, it is empty or does not contain cpu MHz")
|
||||
|
||||
}
|
||||
|
||||
// xgetbv reads an extended control register.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
package cpuid
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -51,7 +51,7 @@ func initCPUInfo() {
|
||||
// warn about them not existing.
|
||||
return
|
||||
}
|
||||
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
cpuinfob, err := os.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
// Leave everything at 0, nothing can be done.
|
||||
log.Warningf("Could not read /proc/cpuinfo: %v", err)
|
||||
|
||||
@@ -26,7 +26,9 @@ type Static map[In]Out
|
||||
|
||||
// Fixed converts the FeatureSet to a fixed set.
|
||||
func (fs FeatureSet) Fixed() FeatureSet {
|
||||
return fs.ToStatic().ToFeatureSet()
|
||||
sfs := fs.ToStatic().ToFeatureSet()
|
||||
sfs.hwCap = fs.hwCap
|
||||
return sfs
|
||||
}
|
||||
|
||||
// ToStatic converts a FeatureSet to a Static function.
|
||||
|
||||
Reference in New Issue
Block a user