^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __KVM_X86_VMX_VMCS12_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __KVM_X86_VMX_VMCS12_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/build_bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "vmcs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * struct vmcs12 describes the state that our guest hypervisor (L1) keeps for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * single nested guest (L2), hence the name vmcs12. Any VMX implementation has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * a VMCS structure, and vmcs12 is our emulated VMX's VMCS. This structure is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * stored in guest memory specified by VMPTRLD, but is opaque to the guest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * which must access it using VMREAD/VMWRITE/VMCLEAR instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * More than one of these structures may exist, if L1 runs multiple L2 guests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * nested_vmx_run() will use the data here to build the vmcs02: a VMCS for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * underlying hardware which will be used to run L2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * This structure is packed to ensure that its layout is identical across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * machines (necessary for live migration).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * IMPORTANT: Changing the layout of existing fields in this structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * will break save/restore compatibility with older kvm releases. When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * adding new fields, either use space in the reserved padding* arrays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * or add the new fields to the end of the structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) typedef u64 natural_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct __packed vmcs12 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* According to the Intel spec, a VMCS region must start with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * following two fields. Then follow implementation-specific data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct vmcs_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u32 launch_state; /* set to 0 by VMCLEAR, to 1 by VMLAUNCH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 padding[7]; /* room for future expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u64 io_bitmap_a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u64 io_bitmap_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u64 msr_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u64 vm_exit_msr_store_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 vm_exit_msr_load_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u64 vm_entry_msr_load_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u64 tsc_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u64 virtual_apic_page_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u64 apic_access_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u64 posted_intr_desc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u64 ept_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 eoi_exit_bitmap0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u64 eoi_exit_bitmap1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u64 eoi_exit_bitmap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u64 eoi_exit_bitmap3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u64 xss_exit_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u64 guest_physical_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u64 vmcs_link_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u64 guest_ia32_debugctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u64 guest_ia32_pat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u64 guest_ia32_efer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u64 guest_ia32_perf_global_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u64 guest_pdptr0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u64 guest_pdptr1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u64 guest_pdptr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u64 guest_pdptr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u64 guest_bndcfgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 host_ia32_pat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u64 host_ia32_efer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u64 host_ia32_perf_global_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u64 vmread_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u64 vmwrite_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u64 vm_function_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u64 eptp_list_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u64 pml_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u64 padding64[3]; /* room for future expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * To allow migration of L1 (complete with its L2 guests) between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * machines of different natural widths (32 or 64 bit), we cannot have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * unsigned long fields with no explicit size. We use u64 (aliased
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * natural_width) instead. Luckily, x86 is little-endian.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) natural_width cr0_guest_host_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) natural_width cr4_guest_host_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) natural_width cr0_read_shadow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) natural_width cr4_read_shadow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) natural_width dead_space[4]; /* Last remnants of cr3_target_value[0-3]. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) natural_width exit_qualification;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) natural_width guest_linear_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) natural_width guest_cr0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) natural_width guest_cr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) natural_width guest_cr4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) natural_width guest_es_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) natural_width guest_cs_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) natural_width guest_ss_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) natural_width guest_ds_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) natural_width guest_fs_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) natural_width guest_gs_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) natural_width guest_ldtr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) natural_width guest_tr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) natural_width guest_gdtr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) natural_width guest_idtr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) natural_width guest_dr7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) natural_width guest_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) natural_width guest_rip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) natural_width guest_rflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) natural_width guest_pending_dbg_exceptions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) natural_width guest_sysenter_esp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) natural_width guest_sysenter_eip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) natural_width host_cr0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) natural_width host_cr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) natural_width host_cr4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) natural_width host_fs_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) natural_width host_gs_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) natural_width host_tr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) natural_width host_gdtr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) natural_width host_idtr_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) natural_width host_ia32_sysenter_esp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) natural_width host_ia32_sysenter_eip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) natural_width host_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) natural_width host_rip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) natural_width paddingl[8]; /* room for future expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) u32 pin_based_vm_exec_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 cpu_based_vm_exec_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u32 exception_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u32 page_fault_error_code_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 page_fault_error_code_match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u32 cr3_target_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u32 vm_exit_controls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u32 vm_exit_msr_store_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u32 vm_exit_msr_load_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u32 vm_entry_controls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u32 vm_entry_msr_load_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u32 vm_entry_intr_info_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) u32 vm_entry_exception_error_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u32 vm_entry_instruction_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u32 tpr_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) u32 secondary_vm_exec_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u32 vm_instruction_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u32 vm_exit_reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) u32 vm_exit_intr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u32 vm_exit_intr_error_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u32 idt_vectoring_info_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u32 idt_vectoring_error_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u32 vm_exit_instruction_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) u32 vmx_instruction_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u32 guest_es_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u32 guest_cs_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u32 guest_ss_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u32 guest_ds_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u32 guest_fs_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) u32 guest_gs_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u32 guest_ldtr_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u32 guest_tr_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u32 guest_gdtr_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 guest_idtr_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) u32 guest_es_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) u32 guest_cs_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u32 guest_ss_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) u32 guest_ds_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u32 guest_fs_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) u32 guest_gs_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u32 guest_ldtr_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u32 guest_tr_ar_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u32 guest_interruptibility_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u32 guest_activity_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u32 guest_sysenter_cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u32 host_ia32_sysenter_cs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u32 vmx_preemption_timer_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) u32 padding32[7]; /* room for future expansion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) u16 virtual_processor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u16 posted_intr_nv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u16 guest_es_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u16 guest_cs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u16 guest_ss_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u16 guest_ds_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) u16 guest_fs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u16 guest_gs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u16 guest_ldtr_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u16 guest_tr_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) u16 guest_intr_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u16 host_es_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u16 host_cs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) u16 host_ss_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) u16 host_ds_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) u16 host_fs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) u16 host_gs_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u16 host_tr_selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u16 guest_pml_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * VMCS12_REVISION is an arbitrary id that should be changed if the content or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * layout of struct vmcs12 is changed. MSR_IA32_VMX_BASIC returns this id, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * VMPTRLD verifies that the VMCS region that L1 is loading contains this id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * IMPORTANT: Changing this value will break save/restore compatibility with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * older kvm releases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define VMCS12_REVISION 0x11e57ed0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * VMCS12_SIZE is the number of bytes L1 should allocate for the VMXON region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * and any VMCS region. Although only sizeof(struct vmcs12) are used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * current implementation, 4K are reserved to avoid future complications and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * to preserve userspace ABI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define VMCS12_SIZE KVM_STATE_NESTED_VMX_VMCS_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * VMCS12_MAX_FIELD_INDEX is the highest index value used in any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * supported VMCS12 field encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define VMCS12_MAX_FIELD_INDEX 0x17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * For save/restore compatibility, the vmcs12 field offsets must not change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define CHECK_OFFSET(field, loc) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) BUILD_BUG_ON_MSG(offsetof(struct vmcs12, field) != (loc), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "Offset of " #field " in struct vmcs12 has changed.")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static inline void vmx_check_vmcs12_offsets(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) CHECK_OFFSET(hdr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) CHECK_OFFSET(abort, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) CHECK_OFFSET(launch_state, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) CHECK_OFFSET(io_bitmap_a, 40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) CHECK_OFFSET(io_bitmap_b, 48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) CHECK_OFFSET(msr_bitmap, 56);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) CHECK_OFFSET(vm_exit_msr_store_addr, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) CHECK_OFFSET(vm_exit_msr_load_addr, 72);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) CHECK_OFFSET(vm_entry_msr_load_addr, 80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) CHECK_OFFSET(tsc_offset, 88);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) CHECK_OFFSET(virtual_apic_page_addr, 96);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) CHECK_OFFSET(apic_access_addr, 104);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) CHECK_OFFSET(posted_intr_desc_addr, 112);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) CHECK_OFFSET(ept_pointer, 120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) CHECK_OFFSET(eoi_exit_bitmap0, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) CHECK_OFFSET(eoi_exit_bitmap1, 136);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) CHECK_OFFSET(eoi_exit_bitmap2, 144);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) CHECK_OFFSET(eoi_exit_bitmap3, 152);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) CHECK_OFFSET(xss_exit_bitmap, 160);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) CHECK_OFFSET(guest_physical_address, 168);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) CHECK_OFFSET(vmcs_link_pointer, 176);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) CHECK_OFFSET(guest_ia32_debugctl, 184);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) CHECK_OFFSET(guest_ia32_pat, 192);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) CHECK_OFFSET(guest_ia32_efer, 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) CHECK_OFFSET(guest_ia32_perf_global_ctrl, 208);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) CHECK_OFFSET(guest_pdptr0, 216);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) CHECK_OFFSET(guest_pdptr1, 224);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) CHECK_OFFSET(guest_pdptr2, 232);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) CHECK_OFFSET(guest_pdptr3, 240);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) CHECK_OFFSET(guest_bndcfgs, 248);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) CHECK_OFFSET(host_ia32_pat, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) CHECK_OFFSET(host_ia32_efer, 264);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) CHECK_OFFSET(host_ia32_perf_global_ctrl, 272);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) CHECK_OFFSET(vmread_bitmap, 280);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) CHECK_OFFSET(vmwrite_bitmap, 288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) CHECK_OFFSET(vm_function_control, 296);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) CHECK_OFFSET(eptp_list_address, 304);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) CHECK_OFFSET(pml_address, 312);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) CHECK_OFFSET(cr0_guest_host_mask, 344);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) CHECK_OFFSET(cr4_guest_host_mask, 352);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) CHECK_OFFSET(cr0_read_shadow, 360);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) CHECK_OFFSET(cr4_read_shadow, 368);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) CHECK_OFFSET(dead_space, 376);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) CHECK_OFFSET(exit_qualification, 408);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) CHECK_OFFSET(guest_linear_address, 416);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) CHECK_OFFSET(guest_cr0, 424);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) CHECK_OFFSET(guest_cr3, 432);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) CHECK_OFFSET(guest_cr4, 440);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) CHECK_OFFSET(guest_es_base, 448);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) CHECK_OFFSET(guest_cs_base, 456);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) CHECK_OFFSET(guest_ss_base, 464);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) CHECK_OFFSET(guest_ds_base, 472);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) CHECK_OFFSET(guest_fs_base, 480);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) CHECK_OFFSET(guest_gs_base, 488);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) CHECK_OFFSET(guest_ldtr_base, 496);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) CHECK_OFFSET(guest_tr_base, 504);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) CHECK_OFFSET(guest_gdtr_base, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) CHECK_OFFSET(guest_idtr_base, 520);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) CHECK_OFFSET(guest_dr7, 528);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) CHECK_OFFSET(guest_rsp, 536);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) CHECK_OFFSET(guest_rip, 544);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) CHECK_OFFSET(guest_rflags, 552);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) CHECK_OFFSET(guest_pending_dbg_exceptions, 560);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) CHECK_OFFSET(guest_sysenter_esp, 568);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) CHECK_OFFSET(guest_sysenter_eip, 576);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) CHECK_OFFSET(host_cr0, 584);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) CHECK_OFFSET(host_cr3, 592);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) CHECK_OFFSET(host_cr4, 600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) CHECK_OFFSET(host_fs_base, 608);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) CHECK_OFFSET(host_gs_base, 616);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) CHECK_OFFSET(host_tr_base, 624);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) CHECK_OFFSET(host_gdtr_base, 632);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) CHECK_OFFSET(host_idtr_base, 640);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) CHECK_OFFSET(host_ia32_sysenter_esp, 648);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) CHECK_OFFSET(host_ia32_sysenter_eip, 656);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) CHECK_OFFSET(host_rsp, 664);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) CHECK_OFFSET(host_rip, 672);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) CHECK_OFFSET(pin_based_vm_exec_control, 744);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) CHECK_OFFSET(cpu_based_vm_exec_control, 748);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) CHECK_OFFSET(exception_bitmap, 752);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) CHECK_OFFSET(page_fault_error_code_mask, 756);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) CHECK_OFFSET(page_fault_error_code_match, 760);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) CHECK_OFFSET(cr3_target_count, 764);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) CHECK_OFFSET(vm_exit_controls, 768);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) CHECK_OFFSET(vm_exit_msr_store_count, 772);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) CHECK_OFFSET(vm_exit_msr_load_count, 776);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) CHECK_OFFSET(vm_entry_controls, 780);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) CHECK_OFFSET(vm_entry_msr_load_count, 784);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) CHECK_OFFSET(vm_entry_intr_info_field, 788);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) CHECK_OFFSET(vm_entry_exception_error_code, 792);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) CHECK_OFFSET(vm_entry_instruction_len, 796);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) CHECK_OFFSET(tpr_threshold, 800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) CHECK_OFFSET(secondary_vm_exec_control, 804);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) CHECK_OFFSET(vm_instruction_error, 808);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) CHECK_OFFSET(vm_exit_reason, 812);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) CHECK_OFFSET(vm_exit_intr_info, 816);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) CHECK_OFFSET(vm_exit_intr_error_code, 820);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) CHECK_OFFSET(idt_vectoring_info_field, 824);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) CHECK_OFFSET(idt_vectoring_error_code, 828);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) CHECK_OFFSET(vm_exit_instruction_len, 832);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) CHECK_OFFSET(vmx_instruction_info, 836);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) CHECK_OFFSET(guest_es_limit, 840);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) CHECK_OFFSET(guest_cs_limit, 844);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) CHECK_OFFSET(guest_ss_limit, 848);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) CHECK_OFFSET(guest_ds_limit, 852);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) CHECK_OFFSET(guest_fs_limit, 856);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) CHECK_OFFSET(guest_gs_limit, 860);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) CHECK_OFFSET(guest_ldtr_limit, 864);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) CHECK_OFFSET(guest_tr_limit, 868);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) CHECK_OFFSET(guest_gdtr_limit, 872);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) CHECK_OFFSET(guest_idtr_limit, 876);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) CHECK_OFFSET(guest_es_ar_bytes, 880);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) CHECK_OFFSET(guest_cs_ar_bytes, 884);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) CHECK_OFFSET(guest_ss_ar_bytes, 888);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) CHECK_OFFSET(guest_ds_ar_bytes, 892);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) CHECK_OFFSET(guest_fs_ar_bytes, 896);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) CHECK_OFFSET(guest_gs_ar_bytes, 900);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) CHECK_OFFSET(guest_ldtr_ar_bytes, 904);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) CHECK_OFFSET(guest_tr_ar_bytes, 908);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) CHECK_OFFSET(guest_interruptibility_info, 912);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) CHECK_OFFSET(guest_activity_state, 916);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) CHECK_OFFSET(guest_sysenter_cs, 920);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) CHECK_OFFSET(host_ia32_sysenter_cs, 924);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) CHECK_OFFSET(vmx_preemption_timer_value, 928);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) CHECK_OFFSET(virtual_processor_id, 960);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) CHECK_OFFSET(posted_intr_nv, 962);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) CHECK_OFFSET(guest_es_selector, 964);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) CHECK_OFFSET(guest_cs_selector, 966);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) CHECK_OFFSET(guest_ss_selector, 968);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) CHECK_OFFSET(guest_ds_selector, 970);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) CHECK_OFFSET(guest_fs_selector, 972);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) CHECK_OFFSET(guest_gs_selector, 974);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) CHECK_OFFSET(guest_ldtr_selector, 976);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) CHECK_OFFSET(guest_tr_selector, 978);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) CHECK_OFFSET(guest_intr_status, 980);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) CHECK_OFFSET(host_es_selector, 982);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) CHECK_OFFSET(host_cs_selector, 984);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) CHECK_OFFSET(host_ss_selector, 986);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) CHECK_OFFSET(host_ds_selector, 988);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) CHECK_OFFSET(host_fs_selector, 990);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) CHECK_OFFSET(host_gs_selector, 992);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) CHECK_OFFSET(host_tr_selector, 994);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) CHECK_OFFSET(guest_pml_index, 996);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) extern const unsigned short vmcs_field_to_offset_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) extern const unsigned int nr_vmcs12_fields;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static inline short vmcs_field_to_offset(unsigned long field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned short offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (field >> 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) index = ROL16(field, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (index >= nr_vmcs12_fields)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) index = array_index_nospec(index, nr_vmcs12_fields);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) offset = vmcs_field_to_offset_table[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (offset == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #undef ROL16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static inline u64 vmcs12_read_any(struct vmcs12 *vmcs12, unsigned long field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) u16 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) char *p = (char *)vmcs12 + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) switch (vmcs_field_width(field)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) case VMCS_FIELD_WIDTH_NATURAL_WIDTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return *((natural_width *)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) case VMCS_FIELD_WIDTH_U16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return *((u16 *)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) case VMCS_FIELD_WIDTH_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return *((u32 *)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case VMCS_FIELD_WIDTH_U64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return *((u64 *)p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static inline void vmcs12_write_any(struct vmcs12 *vmcs12, unsigned long field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) u16 offset, u64 field_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) char *p = (char *)vmcs12 + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) switch (vmcs_field_width(field)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) case VMCS_FIELD_WIDTH_U16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) *(u16 *)p = field_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) case VMCS_FIELD_WIDTH_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) *(u32 *)p = field_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case VMCS_FIELD_WIDTH_U64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) *(u64 *)p = field_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) case VMCS_FIELD_WIDTH_NATURAL_WIDTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) *(natural_width *)p = field_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #endif /* __KVM_X86_VMX_VMCS12_H */