github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/sentry/platform/kvm/kvm_const.go (about)

     1  // Copyright 2018 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  package kvm
    16  
    17  // KVM ioctls.
    18  //
    19  // Only the ioctls we need in Go appear here; some additional ioctls are used
    20  // within the assembly stubs (KVM_INTERRUPT, etc.).
    21  const (
    22  	KVM_CREATE_VM              = 0xae01
    23  	KVM_GET_VCPU_MMAP_SIZE     = 0xae04
    24  	KVM_CREATE_VCPU            = 0xae41
    25  	KVM_SET_TSS_ADDR           = 0xae47
    26  	KVM_RUN                    = 0xae80
    27  	KVM_NMI                    = 0xae9a
    28  	KVM_CHECK_EXTENSION        = 0xae03
    29  	KVM_GET_TSC_KHZ            = 0xaea3
    30  	KVM_SET_TSC_KHZ            = 0xaea2
    31  	KVM_INTERRUPT              = 0x4004ae86
    32  	KVM_SET_MSRS               = 0x4008ae89
    33  	KVM_SET_USER_MEMORY_REGION = 0x4020ae46
    34  	KVM_SET_REGS               = 0x4090ae82
    35  	KVM_SET_SREGS              = 0x4138ae84
    36  	KVM_GET_MSRS               = 0xc008ae88
    37  	KVM_GET_REGS               = 0x8090ae81
    38  	KVM_GET_SREGS              = 0x8138ae83
    39  	KVM_GET_SUPPORTED_CPUID    = 0xc008ae05
    40  	KVM_SET_CPUID2             = 0x4008ae90
    41  	KVM_SET_SIGNAL_MASK        = 0x4004ae8b
    42  	KVM_GET_VCPU_EVENTS        = 0x8040ae9f
    43  	KVM_SET_VCPU_EVENTS        = 0x4040aea0
    44  	KVM_SET_DEVICE_ATTR        = 0x4018aee1
    45  )
    46  
    47  // KVM exit reasons.
    48  const (
    49  	_KVM_EXIT_EXCEPTION       = 0x1
    50  	_KVM_EXIT_IO              = 0x2
    51  	_KVM_EXIT_HYPERCALL       = 0x3
    52  	_KVM_EXIT_DEBUG           = 0x4
    53  	_KVM_EXIT_HLT             = 0x5
    54  	_KVM_EXIT_MMIO            = 0x6
    55  	_KVM_EXIT_IRQ_WINDOW_OPEN = 0x7
    56  	_KVM_EXIT_SHUTDOWN        = 0x8
    57  	_KVM_EXIT_FAIL_ENTRY      = 0x9
    58  	_KVM_EXIT_INTERNAL_ERROR  = 0x11
    59  	_KVM_EXIT_SYSTEM_EVENT    = 0x18
    60  	_KVM_EXIT_ARM_NISV        = 0x1c
    61  )
    62  
    63  // KVM capability options.
    64  const (
    65  	_KVM_CAP_MAX_MEMSLOTS          = 0x0a
    66  	_KVM_CAP_MAX_VCPUS             = 0x42
    67  	_KVM_CAP_ARM_VM_IPA_SIZE       = 0xa5
    68  	_KVM_CAP_VCPU_EVENTS           = 0x29
    69  	_KVM_CAP_ARM_INJECT_SERROR_ESR = 0x9e
    70  	_KVM_CAP_TSC_CONTROL           = 0x3c
    71  )
    72  
    73  // KVM limits.
    74  const (
    75  	_KVM_NR_MEMSLOTS      = 0x100
    76  	_KVM_NR_VCPUS         = 0xff
    77  	_KVM_NR_INTERRUPTS    = 0x100
    78  	_KVM_NR_CPUID_ENTRIES = 0x100
    79  )
    80  
    81  // KVM kvm_memory_region::flags.
    82  const (
    83  	_KVM_MEM_LOG_DIRTY_PAGES = uint32(1) << 0
    84  	_KVM_MEM_READONLY        = uint32(1) << 1
    85  	_KVM_MEM_FLAGS_NONE      = uint32(0)
    86  )
    87  
    88  // KVM hypercall list.
    89  //
    90  // Canonical list of hypercalls supported.
    91  const (
    92  	// On amd64, it uses 'HLT' to leave the guest.
    93  	//
    94  	// Unlike amd64, arm64 can only uses mmio_exit/psci to leave the guest.
    95  	//
    96  	// _KVM_HYPERCALL_VMEXIT is only used on arm64 for now.
    97  	_KVM_HYPERCALL_VMEXIT int = iota
    98  	_KVM_HYPERCALL_MAX
    99  )