gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/platform/kvm/kvm_arm64.go (about)

     1  // Copyright 2019 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build arm64
    16  // +build arm64
    17  
    18  package kvm
    19  
    20  import (
    21  	"fmt"
    22  
    23  	"gvisor.dev/gvisor/pkg/abi/linux"
    24  	"gvisor.dev/gvisor/pkg/ring0"
    25  	"gvisor.dev/gvisor/pkg/sentry/arch"
    26  )
    27  
    28  type kvmOneReg struct {
    29  	id   uint64
    30  	addr uint64
    31  }
    32  
    33  // arm64HypercallMMIOBase is MMIO base address used to dispatch hypercalls.
    34  var arm64HypercallMMIOBase uintptr
    35  
    36  const KVM_NR_SPSR = 5
    37  
    38  type userFpsimdState struct {
    39  	vregs    [64]uint64
    40  	fpsr     uint32
    41  	fpcr     uint32
    42  	reserved [2]uint32
    43  }
    44  
    45  type userRegs struct {
    46  	Regs    arch.Registers
    47  	sp_el1  uint64
    48  	elr_el1 uint64
    49  	spsr    [KVM_NR_SPSR]uint64
    50  	fpRegs  userFpsimdState
    51  }
    52  
    53  type exception struct {
    54  	sErrPending    uint8
    55  	sErrHasEsr     uint8
    56  	extDabtPending uint8
    57  	pad            [5]uint8
    58  	sErrEsr        uint64
    59  }
    60  
    61  type kvmVcpuEvents struct {
    62  	exception
    63  	rsvd [12]uint32
    64  }
    65  
    66  // updateGlobalOnce does global initialization. It has to be called only once.
    67  func updateGlobalOnce(fd int) error {
    68  	err := updateSystemValues(int(fd))
    69  	ring0.Init()
    70  	physicalInit()
    71  	// The linux.Task represents the possible largest task size, which the UserspaceSize shouldn't be larger than.
    72  	if linux.TaskSize < ring0.UserspaceSize {
    73  		return fmt.Errorf("gVisor doesn't support 3-level page tables on KVM platform. Try to recompile the kernel with CONFIG_ARM64_VA_BITS_48")
    74  	}
    75  	return err
    76  }