Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/ring0/aarch64.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ package ring0
const (
// VirtualAddressBits is fixed at 48.
VirtualAddressBits = 48
)

// PhysicalAddressBits is fixed at 40.
PhysicalAddressBits = 40
var (
// PhysicalAddressBits is the number of bits available in the physical
// address space. On ARM64, this is dynamically limited by the host KVM IPA size,
// up to a maximum of 40 bits.
PhysicalAddressBits uintptr = 40
)

const (
// DAIF bits:debug, sError, IRQ, FIQ.
_PSR_D_BIT = 0x00000200
_PSR_A_BIT = 0x00000100
Expand Down
1 change: 1 addition & 0 deletions pkg/sentry/platform/kvm/kvm_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func updateGlobalOnce(fd int) error {
ring0.Init(cpuid.FeatureSet{
Function: s,
})
initFaultBlocks()
physicalInit()
return nil
}
13 changes: 13 additions & 0 deletions pkg/sentry/platform/kvm/kvm_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package kvm
import (
"fmt"

"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/hostsyscall"
"gvisor.dev/gvisor/pkg/ring0"
"gvisor.dev/gvisor/pkg/sentry/arch"
)
Expand Down Expand Up @@ -66,7 +68,18 @@ type kvmVcpuEvents struct {
// updateGlobalOnce does global initialization. It has to be called only once.
func updateGlobalOnce(fd int) error {
err := updateSystemValues(int(fd))

maxIPA, errno := hostsyscall.RawSyscall(unix.SYS_IOCTL, uintptr(fd), KVM_CHECK_EXTENSION, _KVM_CAP_ARM_VM_IPA_SIZE)
if errno == 0 && maxIPA > 0 {
if maxIPA < 40 {
ring0.PhysicalAddressBits = uintptr(maxIPA)
} else {
ring0.PhysicalAddressBits = 40
}
}

ring0.Init()
initFaultBlocks()
physicalInit()

// Explicitly configure address space for 48-bit VA.
Expand Down
8 changes: 2 additions & 6 deletions pkg/sentry/platform/kvm/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,9 @@ func newMachine(vm int, config *Config) (*machine, error) {
// mmap isn't called frequently, it seems better than the memory and
// startup time overhead introduced by mapping the entire address
// space.
mapEntireAddressSpace := forceMappingEntireAddressSpace ||
runtime.GOARCH != "amd64"
mapEntireAddressSpace := forceMappingEntireAddressSpace || mapEntireAddressSpaceDefault
if mapEntireAddressSpace {
// Increase faultBlockSize to be sure that we will not reach the limit.
// faultBlockSize has to equal or less than KVM_MEM_MAX_NR_PAGES.
faultBlockSize = uintptr(1) << 42
faultBlockMask = ^uintptr(faultBlockSize - 1)
archOverrideFaultBlocks()
} else {
// Install seccomp rules to trap runtime mmap system calls. They will
// be handled by seccompMmapHandler.
Expand Down
14 changes: 14 additions & 0 deletions pkg/sentry/platform/kvm/machine_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,17 @@ func (m *machine) getMaxVCPU() {
func archPhysicalRegions(physicalRegions []physicalRegion) []physicalRegion {
return physicalRegions
}

const mapEntireAddressSpaceDefault = false

func initFaultBlocks() {
faultBlockSize = uintptr(8 << 30) // 8 GiB
faultBlockMask = ^uintptr(faultBlockSize - 1)
}

func archOverrideFaultBlocks() {
// Increase faultBlockSize to be sure that we will not reach the limit.
// faultBlockSize has to equal or less than KVM_MEM_MAX_NR_PAGES.
faultBlockSize = uintptr(1) << 42
faultBlockMask = ^uintptr(faultBlockSize - 1)
}
13 changes: 13 additions & 0 deletions pkg/sentry/platform/kvm/machine_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,16 @@ func (m *machine) getMaxVCPU() {
}
}
}

const mapEntireAddressSpaceDefault = true

func initFaultBlocks() {
if ring0.PhysicalAddressBits <= 39 {
faultBlockSize = uintptr(1 << 30) // 1 GiB
} else {
faultBlockSize = uintptr(8 << 30) // 8 GiB
}
faultBlockMask = ^uintptr(faultBlockSize - 1)
}

func archOverrideFaultBlocks() {}
Loading