1 /* SPDX-License-Identifier: MIT */ 1 /* SPDX-License-Identifier: MIT */ 2 /********************************************* 2 /****************************************************************************** 3 * vcpu.h 3 * vcpu.h 4 * 4 * 5 * VCPU initialisation, query, and hotplug. 5 * VCPU initialisation, query, and hotplug. 6 * 6 * 7 * Copyright (c) 2005, Keir Fraser <keir@xenso 7 * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 8 */ 8 */ 9 9 10 #ifndef __XEN_PUBLIC_VCPU_H__ 10 #ifndef __XEN_PUBLIC_VCPU_H__ 11 #define __XEN_PUBLIC_VCPU_H__ 11 #define __XEN_PUBLIC_VCPU_H__ 12 12 13 /* 13 /* 14 * Prototype for this hypercall is: 14 * Prototype for this hypercall is: 15 * int vcpu_op(int cmd, int vcpuid, void 15 * int vcpu_op(int cmd, int vcpuid, void *extra_args) 16 * @cmd == VCPUOP_??? (VCPU operati 16 * @cmd == VCPUOP_??? (VCPU operation). 17 * @vcpuid == VCPU to operate on. 17 * @vcpuid == VCPU to operate on. 18 * @extra_args == Operation-specific extra arg 18 * @extra_args == Operation-specific extra arguments (NULL if none). 19 */ 19 */ 20 20 21 /* 21 /* 22 * Initialise a VCPU. Each VCPU can be initial 22 * Initialise a VCPU. Each VCPU can be initialised only once. A 23 * newly-initialised VCPU will not run until i 23 * newly-initialised VCPU will not run until it is brought up by VCPUOP_up. 24 * 24 * 25 * @extra_arg == pointer to vcpu_guest_context 25 * @extra_arg == pointer to vcpu_guest_context structure containing initial 26 * state for the 26 * state for the VCPU. 27 */ 27 */ 28 #define VCPUOP_initialise 28 #define VCPUOP_initialise 0 29 29 30 /* 30 /* 31 * Bring up a VCPU. This makes the VCPU runnab 31 * Bring up a VCPU. This makes the VCPU runnable. This operation will fail 32 * if the VCPU has not been initialised (VCPUO 32 * if the VCPU has not been initialised (VCPUOP_initialise). 33 */ 33 */ 34 #define VCPUOP_up 34 #define VCPUOP_up 1 35 35 36 /* 36 /* 37 * Bring down a VCPU (i.e., make it non-runnab 37 * Bring down a VCPU (i.e., make it non-runnable). 38 * There are a few caveats that callers should 38 * There are a few caveats that callers should observe: 39 * 1. This operation may return, and VCPU 39 * 1. This operation may return, and VCPU_is_up may return false, before the 40 * VCPU stops running (i.e., the comma 40 * VCPU stops running (i.e., the command is asynchronous). It is a good 41 * idea to ensure that the VCPU has en 41 * idea to ensure that the VCPU has entered a non-critical loop before 42 * bringing it down. Alternatively, th 42 * bringing it down. Alternatively, this operation is guaranteed 43 * synchronous if invoked by the VCPU 43 * synchronous if invoked by the VCPU itself. 44 * 2. After a VCPU is initialised, there 44 * 2. After a VCPU is initialised, there is currently no way to drop all its 45 * references to domain memory. Even a 45 * references to domain memory. Even a VCPU that is down still holds 46 * memory references via its pagetable 46 * memory references via its pagetable base pointer and GDT. It is good 47 * practise to move a VCPU onto an 'id 47 * practise to move a VCPU onto an 'idle' or default page table, LDT and 48 * GDT before bringing it down. 48 * GDT before bringing it down. 49 */ 49 */ 50 #define VCPUOP_down 50 #define VCPUOP_down 2 51 51 52 /* Returns 1 if the given VCPU is up. */ 52 /* Returns 1 if the given VCPU is up. */ 53 #define VCPUOP_is_up 53 #define VCPUOP_is_up 3 54 54 55 /* 55 /* 56 * Return information about the state and runn 56 * Return information about the state and running time of a VCPU. 57 * @extra_arg == pointer to vcpu_runstate_info 57 * @extra_arg == pointer to vcpu_runstate_info structure. 58 */ 58 */ 59 #define VCPUOP_get_runstate_info 4 59 #define VCPUOP_get_runstate_info 4 60 struct vcpu_runstate_info { 60 struct vcpu_runstate_info { 61 /* VCPU's current state (RUNSTATE_*). 61 /* VCPU's current state (RUNSTATE_*). */ 62 int state; 62 int state; 63 /* When was current state entered (sys 63 /* When was current state entered (system time, ns)? */ 64 uint64_t state_entry_time; 64 uint64_t state_entry_time; 65 /* 65 /* 66 * Update indicator set in state_entry 66 * Update indicator set in state_entry_time: 67 * When activated via VMASST_TYPE_runs 67 * When activated via VMASST_TYPE_runstate_update_flag, set during 68 * updates in guest memory mapped copy 68 * updates in guest memory mapped copy of vcpu_runstate_info. 69 */ 69 */ 70 #define XEN_RUNSTATE_UPDATE (1ULL << 63) 70 #define XEN_RUNSTATE_UPDATE (1ULL << 63) 71 /* 71 /* 72 * Time spent in each RUNSTATE_* (ns). 72 * Time spent in each RUNSTATE_* (ns). The sum of these times is 73 * guaranteed not to drift from system 73 * guaranteed not to drift from system time. 74 */ 74 */ 75 uint64_t time[4]; 75 uint64_t time[4]; 76 }; 76 }; 77 DEFINE_GUEST_HANDLE_STRUCT(vcpu_runstate_info) 77 DEFINE_GUEST_HANDLE_STRUCT(vcpu_runstate_info); 78 78 79 /* VCPU is currently running on a physical CPU 79 /* VCPU is currently running on a physical CPU. */ 80 #define RUNSTATE_running 0 80 #define RUNSTATE_running 0 81 81 82 /* VCPU is runnable, but not currently schedul 82 /* VCPU is runnable, but not currently scheduled on any physical CPU. */ 83 #define RUNSTATE_runnable 1 83 #define RUNSTATE_runnable 1 84 84 85 /* VCPU is blocked (a.k.a. idle). It is theref 85 /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */ 86 #define RUNSTATE_blocked 2 86 #define RUNSTATE_blocked 2 87 87 88 /* 88 /* 89 * VCPU is not runnable, but it is not blocked 89 * VCPU is not runnable, but it is not blocked. 90 * This is a 'catch all' state for things like 90 * This is a 'catch all' state for things like hotplug and pauses by the 91 * system administrator (or for critical secti 91 * system administrator (or for critical sections in the hypervisor). 92 * RUNSTATE_blocked dominates this state (it i 92 * RUNSTATE_blocked dominates this state (it is the preferred state). 93 */ 93 */ 94 #define RUNSTATE_offline 3 94 #define RUNSTATE_offline 3 95 95 96 /* 96 /* 97 * Register a shared memory area from which th 97 * Register a shared memory area from which the guest may obtain its own 98 * runstate information without needing to exe 98 * runstate information without needing to execute a hypercall. 99 * Notes: 99 * Notes: 100 * 1. The registered address may be virtu 100 * 1. The registered address may be virtual or physical, depending on the 101 * platform. The virtual address shoul 101 * platform. The virtual address should be registered on x86 systems. 102 * 2. Only one shared area may be registe 102 * 2. Only one shared area may be registered per VCPU. The shared area is 103 * updated by the hypervisor each time 103 * updated by the hypervisor each time the VCPU is scheduled. Thus 104 * runstate.state will always be RUNST 104 * runstate.state will always be RUNSTATE_running and 105 * runstate.state_entry_time will indi 105 * runstate.state_entry_time will indicate the system time at which the 106 * VCPU was last scheduled to run. 106 * VCPU was last scheduled to run. 107 * @extra_arg == pointer to vcpu_register_runs 107 * @extra_arg == pointer to vcpu_register_runstate_memory_area structure. 108 */ 108 */ 109 #define VCPUOP_register_runstate_memory_area 5 109 #define VCPUOP_register_runstate_memory_area 5 110 struct vcpu_register_runstate_memory_area { 110 struct vcpu_register_runstate_memory_area { 111 union { 111 union { 112 GUEST_HANDLE(v 112 GUEST_HANDLE(vcpu_runstate_info) h; 113 struct vcpu_ru 113 struct vcpu_runstate_info *v; 114 uint64_t p; 114 uint64_t p; 115 } addr; 115 } addr; 116 }; 116 }; 117 117 118 /* 118 /* 119 * Set or stop a VCPU's periodic timer. Every 119 * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer 120 * which can be set via these commands. Period 120 * which can be set via these commands. Periods smaller than one millisecond 121 * may not be supported. 121 * may not be supported. 122 */ 122 */ 123 #define VCPUOP_set_periodic_timer 6 /* 123 #define VCPUOP_set_periodic_timer 6 /* arg == vcpu_set_periodic_timer_t */ 124 #define VCPUOP_stop_periodic_timer 7 /* 124 #define VCPUOP_stop_periodic_timer 7 /* arg == NULL */ 125 struct vcpu_set_periodic_timer { 125 struct vcpu_set_periodic_timer { 126 uint64_t period_ns; 126 uint64_t period_ns; 127 }; 127 }; 128 DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_periodic_t 128 DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_periodic_timer); 129 129 130 /* 130 /* 131 * Set or stop a VCPU's single-shot timer. Eve 131 * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot 132 * timer which can be set via these commands. 132 * timer which can be set via these commands. 133 */ 133 */ 134 #define VCPUOP_set_singleshot_timer 8 /* 134 #define VCPUOP_set_singleshot_timer 8 /* arg == vcpu_set_singleshot_timer_t */ 135 #define VCPUOP_stop_singleshot_timer 9 /* arg 135 #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */ 136 struct vcpu_set_singleshot_timer { 136 struct vcpu_set_singleshot_timer { 137 uint64_t timeout_abs_ns; 137 uint64_t timeout_abs_ns; 138 uint32_t flags; 138 uint32_t flags; /* VCPU_SSHOTTMR_??? */ 139 }; 139 }; 140 DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_singleshot 140 DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_singleshot_timer); 141 141 142 /* Flags to VCPUOP_set_singleshot_timer. */ 142 /* Flags to VCPUOP_set_singleshot_timer. */ 143 /* Require the timeout to be in the future (r 143 /* Require the timeout to be in the future (return -ETIME if it's passed). */ 144 #define _VCPU_SSHOTTMR_future (0) 144 #define _VCPU_SSHOTTMR_future (0) 145 #define VCPU_SSHOTTMR_future (1U << _VCPU_SSH 145 #define VCPU_SSHOTTMR_future (1U << _VCPU_SSHOTTMR_future) 146 146 147 /* 147 /* 148 * Register a memory location in the guest add 148 * Register a memory location in the guest address space for the 149 * vcpu_info structure. This allows the guest 149 * vcpu_info structure. This allows the guest to place the vcpu_info 150 * structure in a convenient place, such as in 150 * structure in a convenient place, such as in a per-cpu data area. 151 * The pointer need not be page aligned, but t 151 * The pointer need not be page aligned, but the structure must not 152 * cross a page boundary. 152 * cross a page boundary. 153 */ 153 */ 154 #define VCPUOP_register_vcpu_info 10 /* arg 154 #define VCPUOP_register_vcpu_info 10 /* arg == struct vcpu_info */ 155 struct vcpu_register_vcpu_info { 155 struct vcpu_register_vcpu_info { 156 uint64_t mfn; /* mfn of page to place v 156 uint64_t mfn; /* mfn of page to place vcpu_info */ 157 uint32_t offset; /* offset within page */ 157 uint32_t offset; /* offset within page */ 158 uint32_t rsvd; /* unused */ 158 uint32_t rsvd; /* unused */ 159 }; 159 }; 160 DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_vcpu_ 160 DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_vcpu_info); 161 161 162 /* Send an NMI to the specified VCPU. @extra_a 162 /* Send an NMI to the specified VCPU. @extra_arg == NULL. */ 163 #define VCPUOP_send_nmi 11 163 #define VCPUOP_send_nmi 11 164 164 165 /* 165 /* 166 * Get the physical ID information for a pinne 166 * Get the physical ID information for a pinned vcpu's underlying physical 167 * processor. The physical ID informmation is 167 * processor. The physical ID informmation is architecture-specific. 168 * On x86: id[31:0]=apic_id, id[63:32]=acpi_id 168 * On x86: id[31:0]=apic_id, id[63:32]=acpi_id. 169 * This command returns -EINVAL if it is not a 169 * This command returns -EINVAL if it is not a valid operation for this VCPU. 170 */ 170 */ 171 #define VCPUOP_get_physid 12 /* arg 171 #define VCPUOP_get_physid 12 /* arg == vcpu_get_physid_t */ 172 struct vcpu_get_physid { 172 struct vcpu_get_physid { 173 uint64_t phys_id; 173 uint64_t phys_id; 174 }; 174 }; 175 DEFINE_GUEST_HANDLE_STRUCT(vcpu_get_physid); 175 DEFINE_GUEST_HANDLE_STRUCT(vcpu_get_physid); 176 #define xen_vcpu_physid_to_x86_apicid(physid) 176 #define xen_vcpu_physid_to_x86_apicid(physid) ((uint32_t)(physid)) 177 #define xen_vcpu_physid_to_x86_acpiid(physid) 177 #define xen_vcpu_physid_to_x86_acpiid(physid) ((uint32_t)((physid) >> 32)) 178 178 179 /* 179 /* 180 * Register a memory location to get a seconda 180 * Register a memory location to get a secondary copy of the vcpu time 181 * parameters. The master copy still exists a 181 * parameters. The master copy still exists as part of the vcpu shared 182 * memory area, and this secondary copy is upd 182 * memory area, and this secondary copy is updated whenever the master copy 183 * is updated (and using the same versioning s 183 * is updated (and using the same versioning scheme for synchronisation). 184 * 184 * 185 * The intent is that this copy may be mapped 185 * The intent is that this copy may be mapped (RO) into userspace so 186 * that usermode can compute system time using 186 * that usermode can compute system time using the time info and the 187 * tsc. Usermode will see an array of vcpu_ti 187 * tsc. Usermode will see an array of vcpu_time_info structures, one 188 * for each vcpu, and choose the right one by 188 * for each vcpu, and choose the right one by an existing mechanism 189 * which allows it to get the current vcpu num 189 * which allows it to get the current vcpu number (such as via a 190 * segment limit). It can then apply the norm 190 * segment limit). It can then apply the normal algorithm to compute 191 * system time from the tsc. 191 * system time from the tsc. 192 * 192 * 193 * @extra_arg == pointer to vcpu_register_time 193 * @extra_arg == pointer to vcpu_register_time_info_memory_area structure. 194 */ 194 */ 195 #define VCPUOP_register_vcpu_time_memory_area 195 #define VCPUOP_register_vcpu_time_memory_area 13 196 DEFINE_GUEST_HANDLE_STRUCT(vcpu_time_info); 196 DEFINE_GUEST_HANDLE_STRUCT(vcpu_time_info); 197 struct vcpu_register_time_memory_area { 197 struct vcpu_register_time_memory_area { 198 union { 198 union { 199 GUEST_HANDLE(vcpu_time_info) h 199 GUEST_HANDLE(vcpu_time_info) h; 200 struct pvclock_vcpu_time_info 200 struct pvclock_vcpu_time_info *v; 201 uint64_t p; 201 uint64_t p; 202 } addr; 202 } addr; 203 }; 203 }; 204 DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_time_ 204 DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_time_memory_area); 205 205 206 #endif /* __XEN_PUBLIC_VCPU_H__ */ 206 #endif /* __XEN_PUBLIC_VCPU_H__ */ 207 207
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.