From: Fred Griffoul <fgriffo@amazon.co.uk>
Replace the eVMCS kvm_host_map with a gfn_to_pfn_cache to properly
handle memslot changes and unify with other pfncaches in nVMX.
The change introduces proper locking/unlocking semantics for eVMCS
access through nested_lock_evmcs() and nested_unlock_evmcs() helpers.
Signed-off-by: Fred Griffoul <fgriffo@amazon.co.uk>
---
arch/x86/kvm/vmx/hyperv.h | 21 ++++----
arch/x86/kvm/vmx/nested.c | 109 ++++++++++++++++++++++++++------------
arch/x86/kvm/vmx/vmx.h | 3 +-
3 files changed, 88 insertions(+), 45 deletions(-)
diff --git a/arch/x86/kvm/vmx/hyperv.h b/arch/x86/kvm/vmx/hyperv.h
index 3c7fea501ca5..3b6fcf8dff64 100644
--- a/arch/x86/kvm/vmx/hyperv.h
+++ b/arch/x86/kvm/vmx/hyperv.h
@@ -37,11 +37,6 @@ static inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
return evmptr_is_set(vmx->nested.hv_evmcs_vmptr);
}
-static inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
-{
- return vmx->nested.hv_evmcs;
-}
-
static inline bool guest_cpu_cap_has_evmcs(struct kvm_vcpu *vcpu)
{
/*
@@ -70,6 +65,8 @@ void nested_evmcs_filter_control_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *
int nested_evmcs_check_controls(struct vmcs12 *vmcs12);
bool nested_evmcs_l2_tlb_flush_enabled(struct kvm_vcpu *vcpu);
void vmx_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu);
+struct hv_enlightened_vmcs *nested_lock_evmcs(struct vcpu_vmx *vmx);
+void nested_unlock_evmcs(struct vcpu_vmx *vmx);
#else
static inline bool evmptr_is_valid(u64 evmptr)
{
@@ -91,11 +88,6 @@ static inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
return false;
}
-static inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
-{
- return NULL;
-}
-
static inline u32 nested_evmcs_clean_fields(struct vcpu_vmx *vmx)
{
return 0;
@@ -105,6 +97,15 @@ static inline bool nested_evmcs_msr_bitmap(struct vcpu_vmx *vmx)
{
return false;
}
+
+static inline struct hv_enlightened_vmcs *nested_lock_evmcs(struct vcpu_vmx *vmx)
+{
+ return NULL;
+}
+
+static inline void nested_unlock_evmcs(struct vcpu_vmx *vmx)
+{
+}
#endif
#endif /* __KVM_X86_VMX_HYPERV_H */
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index aec150612818..d910508e3c22 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -232,8 +232,6 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu)
struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
struct vcpu_vmx *vmx = to_vmx(vcpu);
- kvm_vcpu_unmap(vcpu, &vmx->nested.hv_evmcs_map);
- vmx->nested.hv_evmcs = NULL;
vmx->nested.hv_evmcs_vmptr = EVMPTR_INVALID;
vmx->nested.hv_clean_fields = 0;
vmx->nested.hv_msr_bitmap = false;
@@ -265,7 +263,7 @@ static bool nested_evmcs_handle_vmclear(struct kvm_vcpu *vcpu, gpa_t vmptr)
!evmptr_is_valid(nested_get_evmptr(vcpu)))
return false;
- if (nested_vmx_evmcs(vmx) && vmptr == vmx->nested.hv_evmcs_vmptr)
+ if (vmptr == vmx->nested.hv_evmcs_vmptr)
nested_release_evmcs(vcpu);
return true;
@@ -393,6 +391,9 @@ static void free_nested(struct kvm_vcpu *vcpu)
kvm_gpc_deactivate(&vmx->nested.virtual_apic_cache);
kvm_gpc_deactivate(&vmx->nested.apic_access_page_cache);
kvm_gpc_deactivate(&vmx->nested.msr_bitmap_cache);
+#ifdef CONFIG_KVM_HYPERV
+ kvm_gpc_deactivate(&vmx->nested.hv_evmcs_cache);
+#endif
free_vpid(vmx->nested.vpid02);
vmx->nested.posted_intr_nv = -1;
@@ -1735,11 +1736,12 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)
vmcs_load(vmx->loaded_vmcs->vmcs);
}
-static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields)
+static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx,
+ struct hv_enlightened_vmcs *evmcs,
+ u32 hv_clean_fields)
{
#ifdef CONFIG_KVM_HYPERV
struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12;
- struct hv_enlightened_vmcs *evmcs = nested_vmx_evmcs(vmx);
struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(&vmx->vcpu);
/* HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE */
@@ -1987,7 +1989,7 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)
{
#ifdef CONFIG_KVM_HYPERV
struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12;
- struct hv_enlightened_vmcs *evmcs = nested_vmx_evmcs(vmx);
+ struct hv_enlightened_vmcs *evmcs = nested_lock_evmcs(vmx);
/*
* Should not be changed by KVM:
@@ -2155,6 +2157,7 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)
evmcs->guest_bndcfgs = vmcs12->guest_bndcfgs;
+ nested_unlock_evmcs(vmx);
return;
#else /* CONFIG_KVM_HYPERV */
KVM_BUG_ON(1, vmx->vcpu.kvm);
@@ -2171,6 +2174,8 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
#ifdef CONFIG_KVM_HYPERV
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct hv_enlightened_vmcs *evmcs;
+ struct gfn_to_pfn_cache *gpc;
+ enum nested_evmptrld_status status = EVMPTRLD_SUCCEEDED;
bool evmcs_gpa_changed = false;
u64 evmcs_gpa;
@@ -2183,17 +2188,19 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
return EVMPTRLD_DISABLED;
}
+ gpc = &vmx->nested.hv_evmcs_cache;
+ if (nested_gpc_lock(gpc, evmcs_gpa)) {
+ nested_release_evmcs(vcpu);
+ return EVMPTRLD_ERROR;
+ }
+
+ evmcs = gpc->khva;
+
if (unlikely(evmcs_gpa != vmx->nested.hv_evmcs_vmptr)) {
vmx->nested.current_vmptr = INVALID_GPA;
nested_release_evmcs(vcpu);
- if (kvm_vcpu_map(vcpu, gpa_to_gfn(evmcs_gpa),
- &vmx->nested.hv_evmcs_map))
- return EVMPTRLD_ERROR;
-
- vmx->nested.hv_evmcs = vmx->nested.hv_evmcs_map.hva;
-
/*
* Currently, KVM only supports eVMCS version 1
* (== KVM_EVMCS_VERSION) and thus we expect guest to set this
@@ -2216,10 +2223,11 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
* eVMCS version or VMCS12 revision_id as valid values for first
* u32 field of eVMCS.
*/
- if ((vmx->nested.hv_evmcs->revision_id != KVM_EVMCS_VERSION) &&
- (vmx->nested.hv_evmcs->revision_id != VMCS12_REVISION)) {
+ if ((evmcs->revision_id != KVM_EVMCS_VERSION) &&
+ (evmcs->revision_id != VMCS12_REVISION)) {
nested_release_evmcs(vcpu);
- return EVMPTRLD_VMFAIL;
+ status = EVMPTRLD_VMFAIL;
+ goto unlock;
}
vmx->nested.hv_evmcs_vmptr = evmcs_gpa;
@@ -2244,14 +2252,11 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
* between different L2 guests as KVM keeps a single VMCS12 per L1.
*/
if (from_launch || evmcs_gpa_changed) {
- vmx->nested.hv_evmcs->hv_clean_fields &=
- ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL;
-
+ evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL;
vmx->nested.force_msr_bitmap_recalc = true;
}
/* Cache evmcs fields to avoid reading evmcs after copy to vmcs12 */
- evmcs = vmx->nested.hv_evmcs;
vmx->nested.hv_clean_fields = evmcs->hv_clean_fields;
vmx->nested.hv_flush_hypercall = evmcs->hv_enlightenments_control.nested_flush_hypercall;
vmx->nested.hv_msr_bitmap = evmcs->hv_enlightenments_control.msr_bitmap;
@@ -2260,13 +2265,15 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
if (likely(!vmcs12->hdr.shadow_vmcs)) {
- copy_enlightened_to_vmcs12(vmx, vmx->nested.hv_clean_fields);
+ copy_enlightened_to_vmcs12(vmx, evmcs, vmx->nested.hv_clean_fields);
/* Enlightened VMCS doesn't have launch state */
vmcs12->launch_state = !from_launch;
}
}
- return EVMPTRLD_SUCCEEDED;
+unlock:
+ nested_gpc_unlock(gpc);
+ return status;
#else
return EVMPTRLD_DISABLED;
#endif
@@ -2771,7 +2778,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
enum vm_entry_failure_code *entry_failure_code)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
- struct hv_enlightened_vmcs *evmcs;
bool load_guest_pdptrs_vmcs12 = false;
if (vmx->nested.dirty_vmcs12 || nested_vmx_is_evmptr12_valid(vmx)) {
@@ -2909,9 +2915,13 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
* bits when it changes a field in eVMCS. Mark all fields as clean
* here.
*/
- evmcs = nested_vmx_evmcs(vmx);
- if (evmcs)
+ if (nested_vmx_is_evmptr12_valid(vmx)) {
+ struct hv_enlightened_vmcs *evmcs;
+
+ evmcs = nested_lock_evmcs(vmx);
evmcs->hv_clean_fields |= HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL;
+ nested_unlock_evmcs(vmx);
+ }
return 0;
}
@@ -4147,6 +4157,18 @@ static void *nested_gpc_lock_if_active(struct gfn_to_pfn_cache *gpc)
return gpc->khva;
}
+#ifdef CONFIG_KVM_HYPERV
+struct hv_enlightened_vmcs *nested_lock_evmcs(struct vcpu_vmx *vmx)
+{
+ return nested_gpc_lock_if_active(&vmx->nested.hv_evmcs_cache);
+}
+
+void nested_unlock_evmcs(struct vcpu_vmx *vmx)
+{
+ nested_gpc_unlock(&vmx->nested.hv_evmcs_cache);
+}
+#endif
+
static struct pi_desc *nested_lock_pi_desc(struct vcpu_vmx *vmx)
{
u8 *pi_desc_page;
@@ -5636,6 +5658,9 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
kvm_gpc_init_for_vcpu(&vmx->nested.virtual_apic_cache, vcpu);
kvm_gpc_init_for_vcpu(&vmx->nested.pi_desc_cache, vcpu);
+#ifdef CONFIG_KVM_HYPERV
+ kvm_gpc_init(&vmx->nested.hv_evmcs_cache, vcpu->kvm);
+#endif
vmx->nested.vmcs02_initialized = false;
vmx->nested.vmxon = true;
@@ -5887,6 +5912,8 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
/* Read the field, zero-extended to a u64 value */
value = vmcs12_read_any(vmcs12, field, offset);
} else {
+ struct hv_enlightened_vmcs *evmcs;
+
/*
* Hyper-V TLFS (as of 6.0b) explicitly states, that while an
* enlightened VMCS is active VMREAD/VMWRITE instructions are
@@ -5905,7 +5932,9 @@ static int handle_vmread(struct kvm_vcpu *vcpu)
return nested_vmx_fail(vcpu, VMXERR_UNSUPPORTED_VMCS_COMPONENT);
/* Read the field, zero-extended to a u64 value */
- value = evmcs_read_any(nested_vmx_evmcs(vmx), field, offset);
+ evmcs = nested_lock_evmcs(vmx);
+ value = evmcs_read_any(evmcs, field, offset);
+ nested_unlock_evmcs(vmx);
}
/*
@@ -6935,6 +6964,27 @@ bool nested_vmx_reflect_vmexit(struct kvm_vcpu *vcpu)
return true;
}
+static void vmx_get_enlightened_to_vmcs12(struct vcpu_vmx *vmx)
+{
+#ifdef CONFIG_KVM_HYPERV
+ struct hv_enlightened_vmcs *evmcs;
+ struct kvm_vcpu *vcpu = &vmx->vcpu;
+
+ kvm_vcpu_srcu_read_lock(vcpu);
+ evmcs = nested_lock_evmcs(vmx);
+ /*
+ * L1 hypervisor is not obliged to keep eVMCS
+ * clean fields data always up-to-date while
+ * not in guest mode, 'hv_clean_fields' is only
+ * supposed to be actual upon vmentry so we need
+ * to ignore it here and do full copy.
+ */
+ copy_enlightened_to_vmcs12(vmx, evmcs, 0);
+ nested_unlock_evmcs(vmx);
+ kvm_vcpu_srcu_read_unlock(vcpu);
+#endif /* CONFIG_KVM_HYPERV */
+}
+
static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
struct kvm_nested_state __user *user_kvm_nested_state,
u32 user_data_size)
@@ -7025,14 +7075,7 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
copy_vmcs02_to_vmcs12_rare(vcpu, get_vmcs12(vcpu));
if (!vmx->nested.need_vmcs12_to_shadow_sync) {
if (nested_vmx_is_evmptr12_valid(vmx))
- /*
- * L1 hypervisor is not obliged to keep eVMCS
- * clean fields data always up-to-date while
- * not in guest mode, 'hv_clean_fields' is only
- * supposed to be actual upon vmentry so we need
- * to ignore it here and do full copy.
- */
- copy_enlightened_to_vmcs12(vmx, 0);
+ vmx_get_enlightened_to_vmcs12(vmx);
else if (enable_shadow_vmcs)
copy_shadow_to_vmcs12(vmx);
}
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 87708af502f3..4da5a42b0c60 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -208,8 +208,7 @@ struct nested_vmx {
u32 hv_clean_fields;
bool hv_msr_bitmap;
bool hv_flush_hypercall;
- struct hv_enlightened_vmcs *hv_evmcs;
- struct kvm_host_map hv_evmcs_map;
+ struct gfn_to_pfn_cache hv_evmcs_cache;
#endif
};
--
2.43.0
Hi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on kvm/queue]
[also build test WARNING on kvm/next mst-vhost/linux-next linus/master v6.18-rc6 next-20251120]
[cannot apply to kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/griffoul-gmail-com/KVM-nVMX-Implement-cache-for-L1-MSR-bitmap/20251119-012332
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link: https://lore.kernel.org/r/20251118171113.363528-8-griffoul%40gmail.org
patch subject: [PATCH v2 07/10] KVM: nVMX: Replace evmcs kvm_host_map with pfncache
config: x86_64-randconfig-101-20251120 (https://download.01.org/0day-ci/archive/20251120/202511202058.xwqVHqfx-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251120/202511202058.xwqVHqfx-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511202058.xwqVHqfx-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> arch/x86/kvm/vmx/nested.c:1739:13: warning: 'copy_enlightened_to_vmcs12' defined but not used [-Wunused-function]
1739 | static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/copy_enlightened_to_vmcs12 +1739 arch/x86/kvm/vmx/nested.c
1738
> 1739 static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx,
1740 struct hv_enlightened_vmcs *evmcs,
1741 u32 hv_clean_fields)
1742 {
1743 #ifdef CONFIG_KVM_HYPERV
1744 struct vmcs12 *vmcs12 = vmx->nested.cached_vmcs12;
1745 struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(&vmx->vcpu);
1746
1747 /* HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE */
1748 vmcs12->tpr_threshold = evmcs->tpr_threshold;
1749 vmcs12->guest_rip = evmcs->guest_rip;
1750
1751 if (unlikely(!(hv_clean_fields &
1752 HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL))) {
1753 hv_vcpu->nested.pa_page_gpa = evmcs->partition_assist_page;
1754 hv_vcpu->nested.vm_id = evmcs->hv_vm_id;
1755 hv_vcpu->nested.vp_id = evmcs->hv_vp_id;
1756 }
1757
1758 if (unlikely(!(hv_clean_fields &
1759 HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC))) {
1760 vmcs12->guest_rsp = evmcs->guest_rsp;
1761 vmcs12->guest_rflags = evmcs->guest_rflags;
1762 vmcs12->guest_interruptibility_info =
1763 evmcs->guest_interruptibility_info;
1764 /*
1765 * Not present in struct vmcs12:
1766 * vmcs12->guest_ssp = evmcs->guest_ssp;
1767 */
1768 }
1769
1770 if (unlikely(!(hv_clean_fields &
1771 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC))) {
1772 vmcs12->cpu_based_vm_exec_control =
1773 evmcs->cpu_based_vm_exec_control;
1774 }
1775
1776 if (unlikely(!(hv_clean_fields &
1777 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN))) {
1778 vmcs12->exception_bitmap = evmcs->exception_bitmap;
1779 }
1780
1781 if (unlikely(!(hv_clean_fields &
1782 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY))) {
1783 vmcs12->vm_entry_controls = evmcs->vm_entry_controls;
1784 }
1785
1786 if (unlikely(!(hv_clean_fields &
1787 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT))) {
1788 vmcs12->vm_entry_intr_info_field =
1789 evmcs->vm_entry_intr_info_field;
1790 vmcs12->vm_entry_exception_error_code =
1791 evmcs->vm_entry_exception_error_code;
1792 vmcs12->vm_entry_instruction_len =
1793 evmcs->vm_entry_instruction_len;
1794 }
1795
1796 if (unlikely(!(hv_clean_fields &
1797 HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1))) {
1798 vmcs12->host_ia32_pat = evmcs->host_ia32_pat;
1799 vmcs12->host_ia32_efer = evmcs->host_ia32_efer;
1800 vmcs12->host_cr0 = evmcs->host_cr0;
1801 vmcs12->host_cr3 = evmcs->host_cr3;
1802 vmcs12->host_cr4 = evmcs->host_cr4;
1803 vmcs12->host_ia32_sysenter_esp = evmcs->host_ia32_sysenter_esp;
1804 vmcs12->host_ia32_sysenter_eip = evmcs->host_ia32_sysenter_eip;
1805 vmcs12->host_rip = evmcs->host_rip;
1806 vmcs12->host_ia32_sysenter_cs = evmcs->host_ia32_sysenter_cs;
1807 vmcs12->host_es_selector = evmcs->host_es_selector;
1808 vmcs12->host_cs_selector = evmcs->host_cs_selector;
1809 vmcs12->host_ss_selector = evmcs->host_ss_selector;
1810 vmcs12->host_ds_selector = evmcs->host_ds_selector;
1811 vmcs12->host_fs_selector = evmcs->host_fs_selector;
1812 vmcs12->host_gs_selector = evmcs->host_gs_selector;
1813 vmcs12->host_tr_selector = evmcs->host_tr_selector;
1814 vmcs12->host_ia32_perf_global_ctrl = evmcs->host_ia32_perf_global_ctrl;
1815 /*
1816 * Not present in struct vmcs12:
1817 * vmcs12->host_ia32_s_cet = evmcs->host_ia32_s_cet;
1818 * vmcs12->host_ssp = evmcs->host_ssp;
1819 * vmcs12->host_ia32_int_ssp_table_addr = evmcs->host_ia32_int_ssp_table_addr;
1820 */
1821 }
1822
1823 if (unlikely(!(hv_clean_fields &
1824 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1))) {
1825 vmcs12->pin_based_vm_exec_control =
1826 evmcs->pin_based_vm_exec_control;
1827 vmcs12->vm_exit_controls = evmcs->vm_exit_controls;
1828 vmcs12->secondary_vm_exec_control =
1829 evmcs->secondary_vm_exec_control;
1830 }
1831
1832 if (unlikely(!(hv_clean_fields &
1833 HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP))) {
1834 vmcs12->io_bitmap_a = evmcs->io_bitmap_a;
1835 vmcs12->io_bitmap_b = evmcs->io_bitmap_b;
1836 }
1837
1838 if (unlikely(!(hv_clean_fields &
1839 HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP))) {
1840 vmcs12->msr_bitmap = evmcs->msr_bitmap;
1841 }
1842
1843 if (unlikely(!(hv_clean_fields &
1844 HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2))) {
1845 vmcs12->guest_es_base = evmcs->guest_es_base;
1846 vmcs12->guest_cs_base = evmcs->guest_cs_base;
1847 vmcs12->guest_ss_base = evmcs->guest_ss_base;
1848 vmcs12->guest_ds_base = evmcs->guest_ds_base;
1849 vmcs12->guest_fs_base = evmcs->guest_fs_base;
1850 vmcs12->guest_gs_base = evmcs->guest_gs_base;
1851 vmcs12->guest_ldtr_base = evmcs->guest_ldtr_base;
1852 vmcs12->guest_tr_base = evmcs->guest_tr_base;
1853 vmcs12->guest_gdtr_base = evmcs->guest_gdtr_base;
1854 vmcs12->guest_idtr_base = evmcs->guest_idtr_base;
1855 vmcs12->guest_es_limit = evmcs->guest_es_limit;
1856 vmcs12->guest_cs_limit = evmcs->guest_cs_limit;
1857 vmcs12->guest_ss_limit = evmcs->guest_ss_limit;
1858 vmcs12->guest_ds_limit = evmcs->guest_ds_limit;
1859 vmcs12->guest_fs_limit = evmcs->guest_fs_limit;
1860 vmcs12->guest_gs_limit = evmcs->guest_gs_limit;
1861 vmcs12->guest_ldtr_limit = evmcs->guest_ldtr_limit;
1862 vmcs12->guest_tr_limit = evmcs->guest_tr_limit;
1863 vmcs12->guest_gdtr_limit = evmcs->guest_gdtr_limit;
1864 vmcs12->guest_idtr_limit = evmcs->guest_idtr_limit;
1865 vmcs12->guest_es_ar_bytes = evmcs->guest_es_ar_bytes;
1866 vmcs12->guest_cs_ar_bytes = evmcs->guest_cs_ar_bytes;
1867 vmcs12->guest_ss_ar_bytes = evmcs->guest_ss_ar_bytes;
1868 vmcs12->guest_ds_ar_bytes = evmcs->guest_ds_ar_bytes;
1869 vmcs12->guest_fs_ar_bytes = evmcs->guest_fs_ar_bytes;
1870 vmcs12->guest_gs_ar_bytes = evmcs->guest_gs_ar_bytes;
1871 vmcs12->guest_ldtr_ar_bytes = evmcs->guest_ldtr_ar_bytes;
1872 vmcs12->guest_tr_ar_bytes = evmcs->guest_tr_ar_bytes;
1873 vmcs12->guest_es_selector = evmcs->guest_es_selector;
1874 vmcs12->guest_cs_selector = evmcs->guest_cs_selector;
1875 vmcs12->guest_ss_selector = evmcs->guest_ss_selector;
1876 vmcs12->guest_ds_selector = evmcs->guest_ds_selector;
1877 vmcs12->guest_fs_selector = evmcs->guest_fs_selector;
1878 vmcs12->guest_gs_selector = evmcs->guest_gs_selector;
1879 vmcs12->guest_ldtr_selector = evmcs->guest_ldtr_selector;
1880 vmcs12->guest_tr_selector = evmcs->guest_tr_selector;
1881 }
1882
1883 if (unlikely(!(hv_clean_fields &
1884 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2))) {
1885 vmcs12->tsc_offset = evmcs->tsc_offset;
1886 vmcs12->virtual_apic_page_addr = evmcs->virtual_apic_page_addr;
1887 vmcs12->xss_exit_bitmap = evmcs->xss_exit_bitmap;
1888 vmcs12->encls_exiting_bitmap = evmcs->encls_exiting_bitmap;
1889 vmcs12->tsc_multiplier = evmcs->tsc_multiplier;
1890 }
1891
1892 if (unlikely(!(hv_clean_fields &
1893 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR))) {
1894 vmcs12->cr0_guest_host_mask = evmcs->cr0_guest_host_mask;
1895 vmcs12->cr4_guest_host_mask = evmcs->cr4_guest_host_mask;
1896 vmcs12->cr0_read_shadow = evmcs->cr0_read_shadow;
1897 vmcs12->cr4_read_shadow = evmcs->cr4_read_shadow;
1898 vmcs12->guest_cr0 = evmcs->guest_cr0;
1899 vmcs12->guest_cr3 = evmcs->guest_cr3;
1900 vmcs12->guest_cr4 = evmcs->guest_cr4;
1901 vmcs12->guest_dr7 = evmcs->guest_dr7;
1902 }
1903
1904 if (unlikely(!(hv_clean_fields &
1905 HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER))) {
1906 vmcs12->host_fs_base = evmcs->host_fs_base;
1907 vmcs12->host_gs_base = evmcs->host_gs_base;
1908 vmcs12->host_tr_base = evmcs->host_tr_base;
1909 vmcs12->host_gdtr_base = evmcs->host_gdtr_base;
1910 vmcs12->host_idtr_base = evmcs->host_idtr_base;
1911 vmcs12->host_rsp = evmcs->host_rsp;
1912 }
1913
1914 if (unlikely(!(hv_clean_fields &
1915 HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT))) {
1916 vmcs12->ept_pointer = evmcs->ept_pointer;
1917 vmcs12->virtual_processor_id = evmcs->virtual_processor_id;
1918 }
1919
1920 if (unlikely(!(hv_clean_fields &
1921 HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1))) {
1922 vmcs12->vmcs_link_pointer = evmcs->vmcs_link_pointer;
1923 vmcs12->guest_ia32_debugctl = evmcs->guest_ia32_debugctl;
1924 vmcs12->guest_ia32_pat = evmcs->guest_ia32_pat;
1925 vmcs12->guest_ia32_efer = evmcs->guest_ia32_efer;
1926 vmcs12->guest_pdptr0 = evmcs->guest_pdptr0;
1927 vmcs12->guest_pdptr1 = evmcs->guest_pdptr1;
1928 vmcs12->guest_pdptr2 = evmcs->guest_pdptr2;
1929 vmcs12->guest_pdptr3 = evmcs->guest_pdptr3;
1930 vmcs12->guest_pending_dbg_exceptions =
1931 evmcs->guest_pending_dbg_exceptions;
1932 vmcs12->guest_sysenter_esp = evmcs->guest_sysenter_esp;
1933 vmcs12->guest_sysenter_eip = evmcs->guest_sysenter_eip;
1934 vmcs12->guest_bndcfgs = evmcs->guest_bndcfgs;
1935 vmcs12->guest_activity_state = evmcs->guest_activity_state;
1936 vmcs12->guest_sysenter_cs = evmcs->guest_sysenter_cs;
1937 vmcs12->guest_ia32_perf_global_ctrl = evmcs->guest_ia32_perf_global_ctrl;
1938 /*
1939 * Not present in struct vmcs12:
1940 * vmcs12->guest_ia32_s_cet = evmcs->guest_ia32_s_cet;
1941 * vmcs12->guest_ia32_lbr_ctl = evmcs->guest_ia32_lbr_ctl;
1942 * vmcs12->guest_ia32_int_ssp_table_addr = evmcs->guest_ia32_int_ssp_table_addr;
1943 */
1944 }
1945
1946 /*
1947 * Not used?
1948 * vmcs12->vm_exit_msr_store_addr = evmcs->vm_exit_msr_store_addr;
1949 * vmcs12->vm_exit_msr_load_addr = evmcs->vm_exit_msr_load_addr;
1950 * vmcs12->vm_entry_msr_load_addr = evmcs->vm_entry_msr_load_addr;
1951 * vmcs12->page_fault_error_code_mask =
1952 * evmcs->page_fault_error_code_mask;
1953 * vmcs12->page_fault_error_code_match =
1954 * evmcs->page_fault_error_code_match;
1955 * vmcs12->cr3_target_count = evmcs->cr3_target_count;
1956 * vmcs12->vm_exit_msr_store_count = evmcs->vm_exit_msr_store_count;
1957 * vmcs12->vm_exit_msr_load_count = evmcs->vm_exit_msr_load_count;
1958 * vmcs12->vm_entry_msr_load_count = evmcs->vm_entry_msr_load_count;
1959 */
1960
1961 /*
1962 * Read only fields:
1963 * vmcs12->guest_physical_address = evmcs->guest_physical_address;
1964 * vmcs12->vm_instruction_error = evmcs->vm_instruction_error;
1965 * vmcs12->vm_exit_reason = evmcs->vm_exit_reason;
1966 * vmcs12->vm_exit_intr_info = evmcs->vm_exit_intr_info;
1967 * vmcs12->vm_exit_intr_error_code = evmcs->vm_exit_intr_error_code;
1968 * vmcs12->idt_vectoring_info_field = evmcs->idt_vectoring_info_field;
1969 * vmcs12->idt_vectoring_error_code = evmcs->idt_vectoring_error_code;
1970 * vmcs12->vm_exit_instruction_len = evmcs->vm_exit_instruction_len;
1971 * vmcs12->vmx_instruction_info = evmcs->vmx_instruction_info;
1972 * vmcs12->exit_qualification = evmcs->exit_qualification;
1973 * vmcs12->guest_linear_address = evmcs->guest_linear_address;
1974 *
1975 * Not present in struct vmcs12:
1976 * vmcs12->exit_io_instruction_ecx = evmcs->exit_io_instruction_ecx;
1977 * vmcs12->exit_io_instruction_esi = evmcs->exit_io_instruction_esi;
1978 * vmcs12->exit_io_instruction_edi = evmcs->exit_io_instruction_edi;
1979 * vmcs12->exit_io_instruction_eip = evmcs->exit_io_instruction_eip;
1980 */
1981
1982 return;
1983 #else /* CONFIG_KVM_HYPERV */
1984 KVM_BUG_ON(1, vmx->vcpu.kvm);
1985 #endif /* CONFIG_KVM_HYPERV */
1986 }
1987
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.