VM introspection - EPT Views and Virtualization Exceptions
Subsystems (9)
cover VM introspection - EPT Views and Virtualization Exceptions
This patch series is based on the VM introspection patches
(https://lore.kernel.org/kvm/[email protected]/),
extending the introspection API with EPT Views and Virtualization Exceptions (#VE) support.
The purpose of this series is to get an initial feedback and to see if we are on the right track, especially because the changes made to add the EPT views are not small (even if they add support only for different access rights for now, not for different content).
One use case for these extensions is to run a guest agent, isolated in another EPT view and using Virtualization Exceptions (#VE), to reduce the number of VM-Exits caused by EPT violations.
Another case for EPT views is to single-step one vCPU on a different view (with more relaxed page access restrictions) while all the others run on a main/restricted view.
Patches 1-11 make preparatory changes for EPT views.
Patches 12-19 extend the VM introspection API with EPT-views related commands and data. The Get/Set/Control EPT view commands are added, the KVMI_VM_SET_PAGE_ACCESS command and the vCPU introspection events are extended with the EPT view.
Patches 20-30 make preparatory changes for #VE.
Patches 31-34 extend the VM introspection API with #VE related commands.
Adalbert Lazăr (2):
KVM: x86: mmu: reindent to avoid lines longer than 80 chars
KVM: introspection: mask out non-rwx flags when reading/writing
from/to the internal database
Marian Rotariu (5):
KVM: x86: export .get_vmfunc_status()
KVM: x86: export .get_eptp_switching_status()
KVM: x86: mmu: add support for EPT switching
KVM: x86: add .set_ept_view()
KVM: x86: vmx: add support for virtualization exceptions
Sean Christopherson (2):
KVM: VMX: Define EPT suppress #VE bit (bit 63 in EPT leaf entries)
KVM: VMX: Suppress EPT violation #VE by default (when enabled)
Ștefan Șicleru (25):
KVM: x86: add kvm_get_ept_view()
KVM: x86: mmu: add EPT view parameter to kvm_mmu_get_page()
KVM: x86: mmu: increase mmu_memory_cache size
KVM: x86: add .control_ept_view()
KVM: x86: page track: allow page tracking for different EPT views
KVM: x86: mmu: allow zapping shadow pages for specific EPT views
KVM: introspection: extend struct kvmi_features with the EPT views
status support
KVM: introspection: add KVMI_VCPU_GET_EPT_VIEW
KVM: introspection: add 'view' field to struct kvmi_event_arch
KVM: introspection: add KVMI_VCPU_SET_EPT_VIEW
KVM: introspection: add KVMI_VCPU_CONTROL_EPT_VIEW
KVM: introspection: extend the access rights database with EPT view
info
KVM: introspection: extend KVMI_VM_SET_PAGE_ACCESS with EPT view info
KVM: introspection: clean non-default EPTs on unhook
KVM: x86: mmu: fix: update present_mask in spte_read_protect()
KVM: vmx: trigger vm-exits for mmio sptes by default when #VE is
enabled
KVM: x86: svm: set .clear_page()
KVM: x86: add .set_ve_info()
KVM: x86: add .disable_ve()
KVM: x86: page_track: add support for suppress #VE bit
KVM: vmx: make use of EPTP_INDEX in vmx_handle_exit()
KVM: vmx: make use of EPTP_INDEX in vmx_set_ept_view()
KVM: introspection: add #VE host capability checker
KVM: introspection: add KVMI_VCPU_SET_VE_INFO/KVMI_VCPU_DISABLE_VE
KVM: introspection: add KVMI_VM_SET_PAGE_SVE
Documentation/virt/kvm/kvmi.rst | 227 +++++++++++- arch/x86/include/asm/kvm_host.h | 27 +- arch/x86/include/asm/kvm_page_track.h | 5 +- arch/x86/include/asm/kvmi_host.h | 1 + arch/x86/include/asm/vmx.h | 5 + arch/x86/include/uapi/asm/kvmi.h | 44 ++- arch/x86/kvm/Makefile | 2 +- arch/x86/kvm/kvmi.c | 83 ++++- arch/x86/kvm/mmu.h | 12 +- arch/x86/kvm/mmu/mmu.c | 191 +++++++--- arch/x86/kvm/mmu/page_track.c | 63 ++-- arch/x86/kvm/mmu/paging_tmpl.h | 6 +- arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/vmx/capabilities.h | 13 + arch/x86/kvm/vmx/clear_page.S | 17 + arch/x86/kvm/vmx/vmx.c | 291 ++++++++++++++- arch/x86/kvm/vmx/vmx.h | 18 + arch/x86/kvm/x86.c | 20 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 8 +- include/linux/kvmi_host.h | 2 +- include/uapi/linux/kvmi.h | 12 +- .../testing/selftests/kvm/x86_64/kvmi_test.c | 335 +++++++++++++++++- virt/kvm/introspection/kvmi.c | 175 ++++++--- virt/kvm/introspection/kvmi_int.h | 17 +- virt/kvm/introspection/kvmi_msg.c | 106 ++++++ 25 files changed, 1512 insertions(+), 169 deletions(-) create mode 100644 arch/x86/kvm/vmx/clear_page.S
base-commit: d9da9f5842e0697564f0f3e586d858f2626e8f92
Based-on: <[email protected]>
CC: Sean Christopherson <[email protected]>
RFC PATCH 1/34 KVM: x86: export .get_vmfunc_status()
From: Marian Rotariu <[email protected]>
The introspection tool uses this function to check the hardware support for VMFUNC, which can be used either to singlestep vCPUs
on a unprotected EPT view or to use #VE in order to filter out VM-exits caused by EPT violations.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 6 ++++++ 2 files changed, 7 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1300,6 +1300,7 @@ struct kvm_x86_ops {bool (*spt_fault)(struct kvm_vcpu *vcpu);bool (*gpt_translation_fault)(struct kvm_vcpu *vcpu);void (*control_singlestep)(struct kvm_vcpu *vcpu,bool enable); +bool (*get_vmfunc_status)(void ); };struct kvm_x86_nested_ops {
arch/x86/kvm/vmx/vmx.c +6 -0
@@ -7992,6 +7992,11 @@ static void vmx_control_singlestep(struct kvm_vcpu *vcpu, bool enable) CPU_BASED_MONITOR_TRAP_FLAG); } +static bool vmx_get_vmfunc_status (void ) +{ +return cpu_has_vmx_vmfunc (); +} +static struct kvm_x86_ops vmx_x86_ops__initdata = { .hardware_unsetup = hardware_unsetup,
@@ -8133,6 +8138,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .spt_fault = vmx_spt_fault, .gpt_translation_fault = vmx_gpt_translation_fault, .control_singlestep = vmx_control_singlestep, + .get_vmfunc_status = vmx_get_vmfunc_status, };static __init int hardware_setup (void )
RFC PATCH 2/34 KVM: x86: export .get_eptp_switching_status()
In reply to Adalbert LazărFrom: Marian Rotariu <[email protected]>
The introspection tool uses this function to check the hardware support for EPT switching, which can be used either to singlestep vCPUs on a unprotected EPT view or to use #VE in order to avoid filter out VM-exits caused by EPT violations.
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/vmx/capabilities.h | 8 ++++++++ arch/x86/kvm/vmx/vmx.c | 8 ++++++++ arch/x86/kvm/x86.c | 3 +++ 4 files changed, 21 insertions(+)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -1301,6 +1301,7 @@ struct kvm_x86_ops {bool (*gpt_translation_fault)(struct kvm_vcpu *vcpu);void (*control_singlestep)(struct kvm_vcpu *vcpu,bool enable);bool (*get_vmfunc_status)(void ); +bool (*get_eptp_switching_status)(void ); };struct kvm_x86_nested_ops {
@@ -1422,6 +1423,7 @@ extern u64 kvm_max_tsc_scaling_ratio;extern u64 kvm_default_tsc_scaling_ratio;extern u64 kvm_mce_cap_supported; +extern bool kvm_eptp_switching_supported;/* * EMULTYPE_NO_DECODE - Set when re-emulating an instruction (after completing
arch/x86/kvm/vmx/capabilities.h +8 -0
@@ -219,6 +219,14 @@ static inline bool cpu_has_vmx_vmfunc(void)SECONDARY_EXEC_ENABLE_VMFUNC ; } +static inline bool cpu_has_vmx_eptp_switching (void ) +{ +u64 vmx_msr; + +rdmsrl (MSR_IA32_VMX_VMFUNC , vmx_msr); +return vmx_msr &VMX_VMFUNC_EPTP_SWITCHING ; +} +static inline bool cpu_has_vmx_shadow_vmcs (void ) {u64 vmx_msr;
arch/x86/kvm/vmx/vmx.c +8 -0
@@ -7997,6 +7997,11 @@ static bool vmx_get_vmfunc_status(void)return cpu_has_vmx_vmfunc (); } +static bool vmx_get_eptp_switching_status (void ) +{ +return kvm_eptp_switching_supported; +} +static struct kvm_x86_ops vmx_x86_ops__initdata = { .hardware_unsetup = hardware_unsetup,
@@ -8139,6 +8144,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .gpt_translation_fault = vmx_gpt_translation_fault, .control_singlestep = vmx_control_singlestep, .get_vmfunc_status = vmx_get_vmfunc_status, + .get_eptp_switching_status = vmx_get_eptp_switching_status, };static __init int hardware_setup (void )
@@ -8178,6 +8184,8 @@ static __init int hardware_setup(void) !cpu_has_vmx_invept_global()) enable_ept =0 ; + kvm_eptp_switching_supported =cpu_has_vmx_eptp_switching (); +if (!cpu_has_vmx_ept_ad_bits () || !enable_ept) enable_ept_ad_bits =0 ;
arch/x86/kvm/x86.c +3 -0
@@ -161,6 +161,9 @@ module_param(force_emulation_prefix, bool, S_IRUGO);int __read_mostly pi_inject_timer =-1 ;module_param (pi_inject_timer, bint,S_IRUGO |S_IWUSR ); +bool __read_mostly kvm_eptp_switching_supported; +EXPORT_SYMBOL_GPL (kvm_eptp_switching_supported); +#define KVM_NR_SHARED_MSRS 16struct kvm_shared_msrs_global {
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 3/34 KVM: x86: add kvm_get_ept_view()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This function returns the EPT view of the current vCPU or 0 if the hardware support is missing.
--- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/vmx/vmx.c | 8 ++++++++ arch/x86/kvm/vmx/vmx.h | 3 +++ arch/x86/kvm/x86.c | 10 ++++++++++ 4 files changed, 24 insertions(+)
arch/x86/include/asm/kvm_host.h +3 -0
@@ -1302,6 +1302,7 @@ struct kvm_x86_ops {void (*control_singlestep)(struct kvm_vcpu *vcpu,bool enable);bool (*get_vmfunc_status)(void );bool (*get_eptp_switching_status)(void ); +u16 (*get_ept_view)(struct kvm_vcpu *vcpu); };struct kvm_x86_nested_ops {
@@ -1773,4 +1774,6 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)#define GET_SMSTATE (type, buf, offset) \ (*(type *)((buf) + (offset) - 0x7e00)) +u16 kvm_get_ept_view (struct kvm_vcpu *vcpu); +#endif /* _ASM_X86_KVM_HOST_H */
arch/x86/kvm/vmx/vmx.c +8 -0
@@ -8002,6 +8002,13 @@ static bool vmx_get_eptp_switching_status(void)return kvm_eptp_switching_supported; } +static u16 vmx_get_ept_view (struct kvm_vcpu *vcpu) +{ +const struct vcpu_vmx *vmx =to_vmx (vcpu); + +return vmx->view; +} +static struct kvm_x86_ops vmx_x86_ops__initdata = { .hardware_unsetup = hardware_unsetup,
@@ -8145,6 +8152,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .control_singlestep = vmx_control_singlestep, .get_vmfunc_status = vmx_get_vmfunc_status, .get_eptp_switching_status = vmx_get_eptp_switching_status, + .get_ept_view = vmx_get_ept_view, };static __init int hardware_setup (void )
arch/x86/kvm/vmx/vmx.h +3 -0
@@ -296,6 +296,9 @@ struct vcpu_vmx {u64 ept_pointer;struct pt_desc pt_desc; + +/* The view this vcpu operates on. */ +u16 view; };enum ept_pointers_status {
arch/x86/kvm/x86.c +10 -0
@@ -10869,6 +10869,16 @@ u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvm_spec_ctrl_valid_bits); +u16 kvm_get_ept_view (struct kvm_vcpu *vcpu) +{ +if (!kvm_x86_ops.get_ept_view) +return 0 ; + +return kvm_x86_ops.get_ept_view (vcpu); +} +EXPORT_SYMBOL_GPL (kvm_get_ept_view); + +EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_exit);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_fast_mmio);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_inj_virq);
RFC PATCH 4/34 KVM: x86: mmu: reindent to avoid lines longer than 80 chars
In reply to Adalbert Lazăr--- arch/x86/kvm/mmu/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +3 -1
@@ -2573,6 +2573,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,bool flush = false;int collisions =0 ;LIST_HEAD (invalid_list); +unsigned int pg_hash; role = vcpu->arch.mmu->mmu_role.base; role.level = level;
@@ -2623,8 +2624,9 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, sp->gfn = gfn; sp->role = role; + pg_hash =kvm_page_table_hashfn (gfn);hlist_add_head (&sp->hash_link, - &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn (gfn)]); + &vcpu->kvm->arch.mmu_page_hash[pg_hash]);if (!direct) {/* * we should do write protection before syncing pages
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 5/34 KVM: x86: mmu: add EPT view parameter to kvm_mmu_get_page()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This will be used to create root_hpa for all the EPT views.
--- arch/x86/include/asm/kvm_host.h | 7 +++++- arch/x86/kvm/mmu/mmu.c | 43 ++++++++++++++++++++------------- arch/x86/kvm/mmu/paging_tmpl.h | 6 +++-- 3 files changed, 36 insertions(+), 20 deletions(-)
arch/x86/include/asm/kvm_host.h +6 -1
@@ -243,6 +243,8 @@ enum x86_intercept_stage; PFERR_WRITE_MASK | \ PFERR_PRESENT_MASK) +#define KVM_MAX_EPT_VIEWS 3 +/* apic attention bits */ #define KVM_APIC_CHECK_VAPIC 0/*
@@ -349,6 +351,9 @@ struct kvm_mmu_page {union kvm_mmu_page_role role;gfn_t gfn; +/* The view this shadow page belongs to */ +u16 view; +u64 *spt;/* hold the gfn of each spte inside spt */ gfn_t *gfns;
@@ -936,7 +941,7 @@ struct kvm_arch {unsigned long n_max_mmu_pages;unsigned int indirect_shadow_pages;u8 mmu_valid_gen; -struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES ]; +struct hlist_head mmu_page_hash[KVM_MAX_EPT_VIEWS ][KVM_NUM_MMU_PAGES ];/* * Hash table of struct kvm_mmu_page. */
arch/x86/kvm/mmu/mmu.c +26 -17
117 lines not on this page · raw message
arch/x86/kvm/mmu/paging_tmpl.h +4 -2
@@ -665,7 +665,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,if (!is_shadow_present_pte (*it.sptep)) { table_gfn = gw->table_gfn[it.level -2 ]; sp =kvm_mmu_get_page (vcpu, table_gfn, addr, it.level-1 , - false, access); + false, access, +kvm_get_ept_view (vcpu)); }/*
@@ -702,7 +703,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,if (!is_shadow_present_pte (*it.sptep)) { sp =kvm_mmu_get_page (vcpu, base_gfn, addr, - it.level -1 , true, direct_access); + it.level -1 , true, direct_access, +kvm_get_ept_view (vcpu));link_shadow_page (vcpu, it.sptep, sp);if (lpage_disallowed)account_huge_nx_page (vcpu->kvm, sp);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 6/34 KVM: x86: mmu: add support for EPT switching
In reply to Adalbert LazărFrom: Marian Rotariu <[email protected]>
The introspection tool uses this function to check the hardware support for EPT switching, which can be used either to singlestep vCPUs on a unprotected EPT view or to use #VE in order to avoid filter out VM-exits caused by EPT violations.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu/mmu.c | 12 ++-- arch/x86/kvm/vmx/vmx.c | 98 +++++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.h | 1 + 4 files changed, 108 insertions(+), 4 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -421,6 +421,7 @@ struct kvm_mmu {void (*update_pte)(struct kvm_vcpu *vcpu,struct kvm_mmu_page *sp,u64 *spte,const void *pte);hpa_t root_hpa; +hpa_t root_hpa_altviews[KVM_MAX_EPT_VIEWS ];gpa_t root_pgd;union kvm_mmu_role mmu_role;u8 root_level;
arch/x86/kvm/mmu/mmu.c +8 -4
@@ -3760,8 +3760,11 @@ void kvm_mmu_free_roots(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,if (free_active_root) {if (mmu->shadow_root_level >=PT64_ROOT_4LEVEL && (mmu->root_level >=PT64_ROOT_4LEVEL || mmu->direct_map)) { -mmu_free_root_page (vcpu->kvm, &mmu->root_hpa, - &invalid_list); +for (i =0 ; i <KVM_MAX_EPT_VIEWS ; i++) +mmu_free_root_page (vcpu->kvm, + mmu->root_hpa_altviews + i, + &invalid_list); + mmu->root_hpa =INVALID_PAGE ; }else {for (i =0 ; i <4 ; ++i)if (mmu->pae_root[i] !=0 )
@@ -3821,9 +3824,10 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) shadow_root_level, true, i);if (!VALID_PAGE (root))return -ENOSPC ; -if (i ==0 ) - vcpu->arch.mmu->root_hpa = root; + vcpu->arch.mmu->root_hpa_altviews[i] = root; } + vcpu->arch.mmu->root_hpa = + vcpu->arch.mmu->root_hpa_altviews[kvm_get_ept_view (vcpu)]; }else if (shadow_root_level ==PT32E_ROOT_LEVEL ) {for (i =0 ; i <4 ; ++i) {MMU_WARN_ON (VALID_PAGE (vcpu->arch.mmu->pae_root[i]));
arch/x86/kvm/vmx/vmx.c +98 -0
158 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.h +1 -0
@@ -297,6 +297,7 @@ struct vcpu_vmx {struct pt_desc pt_desc; +struct page *eptp_list_pg;/* The view this vcpu operates on. */ u16 view; };
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 7/34 KVM: x86: mmu: increase mmu_memory_cache size
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
We use/allocate more root_hpa's every time mmu_alloc_roots() is called.
--- arch/x86/kvm/mmu/mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +4 -2
@@ -1119,11 +1119,13 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu) pte_list_desc_cache, 8 + PTE_PREFETCH_NUM);if (r) goto out; - r =mmu_topup_memory_cache_page (&vcpu->arch.mmu_page_cache,8 ); + r =mmu_topup_memory_cache_page (&vcpu->arch.mmu_page_cache, +8 *KVM_MAX_EPT_VIEWS );if (r) goto out; r =mmu_topup_memory_cache (&vcpu->arch.mmu_page_header_cache, - mmu_page_header_cache,4 ); + mmu_page_header_cache, +4 *KVM_MAX_EPT_VIEWS ); out:return r; }
RFC PATCH 8/34 KVM: x86: add .set_ept_view()
In reply to Adalbert LazărFrom: Marian Rotariu <[email protected]>
The introspection tool uses this function to check the hardware support for EPT switching, which can be used either to singlestep vCPUs on a unprotected EPT view.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1309,6 +1309,7 @@ struct kvm_x86_ops {bool (*get_vmfunc_status)(void );bool (*get_eptp_switching_status)(void );u16 (*get_ept_view)(struct kvm_vcpu *vcpu); +int (*set_ept_view)(struct kvm_vcpu *vcpu,u16 view); };struct kvm_x86_nested_ops {
arch/x86/kvm/vmx/vmx.c +34 -1
@@ -4373,6 +4373,28 @@ static int vmx_alloc_eptp_list_page(struct vcpu_vmx *vmx)return 0 ; } +static int vmx_set_ept_view (struct kvm_vcpu *vcpu,u16 view) +{ +if (view >=KVM_MAX_EPT_VIEWS ) +return -EINVAL ; + +if (to_vmx (vcpu)->eptp_list_pg) { +int r; + +to_vmx (vcpu)->view = view; + +/* +* Reload mmu and make sure vmx_load_mmu_pgd() is called so that +* VMCS::EPT_POINTER is updated accordingly +*/ +kvm_mmu_unload (vcpu); + r =kvm_mmu_reload (vcpu); +WARN_ON_ONCE (r); + } + +return 0 ; +} +#define VMX_XSS_EXIT_BITMAP 0/*
@@ -4463,9 +4485,15 @@ static void init_vmcs(struct vcpu_vmx *vmx)if (cpu_has_vmx_encls_vmexit ())vmcs_write64 (ENCLS_EXITING_BITMAP ,-1ull ); -if (vmx->eptp_list_pg) +if (vmx->eptp_list_pg) { +u64 vm_function_control; +vmcs_write64 (EPTP_LIST_ADDRESS ,page_to_phys (vmx->eptp_list_pg)); + vm_function_control =vmcs_read64 (VM_FUNCTION_CONTROL ); + vm_function_control |=VMX_VMFUNC_EPTP_SWITCHING ; +vmcs_write64 (VM_FUNCTION_CONTROL , vm_function_control); + }if (vmx_pt_mode_is_host_guest ()) {memset (&vmx->pt_desc,0 ,sizeof (vmx->pt_desc));
@@ -5965,6 +5993,10 @@ static void dump_eptp_list(void) eptp_list =phys_to_virt (eptp_list_phys); +pr_err ("VMFunctionControl=%08x VMFunctionControlHigh=%08x\n" , +vmcs_read32 (VM_FUNCTION_CONTROL ), +vmcs_read32 (VM_FUNCTION_CONTROL_HIGH )); +pr_err ("*** EPTP Switching ***\n" );pr_err ("EPTP List Address: %p (phys %p)\n" , eptp_list, (void *)eptp_list_phys);
@@ -8251,6 +8283,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .get_vmfunc_status = vmx_get_vmfunc_status, .get_eptp_switching_status = vmx_get_eptp_switching_status, .get_ept_view = vmx_get_ept_view, + .set_ept_view = vmx_set_ept_view, };static __init int hardware_setup (void )
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 9/34 KVM: x86: add .control_ept_view()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This will be used by the introspection tool to control the EPT views to which the guest is allowed to switch.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 18 +++++++++++++++++- arch/x86/kvm/vmx/vmx.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1310,6 +1310,7 @@ struct kvm_x86_ops {bool (*get_eptp_switching_status)(void );u16 (*get_ept_view)(struct kvm_vcpu *vcpu);int (*set_ept_view)(struct kvm_vcpu *vcpu,u16 view); +int (*control_ept_view)(struct kvm_vcpu *vcpu,u16 view,u8 visible); };struct kvm_x86_nested_ops {
arch/x86/kvm/vmx/vmx.c +17 -1
@@ -3138,8 +3138,11 @@ static void vmx_construct_eptp_with_index(struct kvm_vcpu *vcpu,if (!eptp_list)return ; - eptp_list[view] =construct_eptp (vcpu, +if (test_bit (view, &vmx->allowed_views)) + eptp_list[view] =construct_eptp (vcpu, vcpu->arch.mmu->root_hpa_altviews[view]); +else + eptp_list[view] = (~0ULL ); }static void vmx_construct_eptp_list (struct kvm_vcpu *vcpu)
@@ -4395,6 +4398,18 @@ static int vmx_set_ept_view(struct kvm_vcpu *vcpu, u16 view)return 0 ; } +static int vmx_control_ept_view (struct kvm_vcpu *vcpu,u16 view,u8 visible) +{ +if (visible) +set_bit (view, &to_vmx (vcpu)->allowed_views); +else +clear_bit (view, &to_vmx (vcpu)->allowed_views); + +vmx_construct_eptp_with_index (vcpu, view); + +return 0 ; +} +#define VMX_XSS_EXIT_BITMAP 0/*
@@ -8284,6 +8299,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .get_eptp_switching_status = vmx_get_eptp_switching_status, .get_ept_view = vmx_get_ept_view, .set_ept_view = vmx_set_ept_view, + .control_ept_view = vmx_control_ept_view, };static __init int hardware_setup (void )
arch/x86/kvm/vmx/vmx.h +2 -0
@@ -300,6 +300,8 @@ struct vcpu_vmx {struct page *eptp_list_pg;/* The view this vcpu operates on. */ u16 view; +/* Visible EPT views bitmap for in-guest VMFUNC. */ +unsigned long allowed_views; };enum ept_pointers_status {
RFC PATCH 10/34 KVM: x86: page track: allow page tracking for different EPT views
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool uses this to set distinct access rights on different EPT views.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/asm/kvm_page_track.h | 4 +- arch/x86/kvm/kvmi.c | 6 ++- arch/x86/kvm/mmu.h | 9 ++-- arch/x86/kvm/mmu/mmu.c | 60 +++++++++++++++++---------- arch/x86/kvm/mmu/page_track.c | 56 +++++++++++++------------ drivers/gpu/drm/i915/gvt/kvmgt.c | 8 ++-- 7 files changed, 86 insertions(+), 59 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -860,7 +860,7 @@ struct kvm_lpage_info {struct kvm_arch_memory_slot {struct kvm_rmap_head *rmap[KVM_NR_PAGE_SIZES ];struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES -1 ]; -unsigned short *gfn_track[KVM_PAGE_TRACK_MAX ]; +unsigned short *gfn_track[KVM_MAX_EPT_VIEWS ][KVM_PAGE_TRACK_MAX ]; };/*
arch/x86/include/asm/kvm_page_track.h +2 -2
@@ -109,10 +109,10 @@ int kvm_page_track_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot,void kvm_slot_page_track_add_page (struct kvm *kvm,struct kvm_memory_slot *slot,gfn_t gfn, -enum kvm_page_track_mode mode); +enum kvm_page_track_mode mode,u16 view);void kvm_slot_page_track_remove_page (struct kvm *kvm,struct kvm_memory_slot *slot,gfn_t gfn, -enum kvm_page_track_mode mode); +enum kvm_page_track_mode mode,u16 view);bool kvm_page_track_is_active (struct kvm_vcpu *vcpu,gfn_t gfn,enum kvm_page_track_mode mode);
arch/x86/kvm/kvmi.c +4 -2
@@ -1215,11 +1215,13 @@ void kvmi_arch_update_page_tracking(struct kvm *kvm,if (m->access & allow_bit) {if (slot_tracked) {kvm_slot_page_track_remove_page (kvm, slot, - m->gfn, mode); + m->gfn, mode, +0 );clear_bit (slot->id, arch->active[mode]); } }else if (!slot_tracked) { -kvm_slot_page_track_add_page (kvm, slot, m->gfn, mode); +kvm_slot_page_track_add_page (kvm, slot, m->gfn, mode, +0 );set_bit (slot->id, arch->active[mode]); } }
arch/x86/kvm/mmu.h +6 -3
@@ -221,11 +221,14 @@ void kvm_zap_gfn_range(struct kvm *kvm, gfn_t gfn_start, gfn_t gfn_end);void kvm_mmu_gfn_disallow_lpage (struct kvm_memory_slot *slot,gfn_t gfn);void kvm_mmu_gfn_allow_lpage (struct kvm_memory_slot *slot,gfn_t gfn);bool kvm_mmu_slot_gfn_write_protect (struct kvm *kvm, -struct kvm_memory_slot *slot,u64 gfn); +struct kvm_memory_slot *slot,u64 gfn, +u16 view);bool kvm_mmu_slot_gfn_read_protect (struct kvm *kvm, -struct kvm_memory_slot *slot,u64 gfn); +struct kvm_memory_slot *slot,u64 gfn, +u16 view);bool kvm_mmu_slot_gfn_exec_protect (struct kvm *kvm, -struct kvm_memory_slot *slot,u64 gfn); +struct kvm_memory_slot *slot,u64 gfn, +u16 view);int kvm_arch_write_log_dirty (struct kvm_vcpu *vcpu,gpa_t l2_gpa);int kvm_mmu_post_init_vm (struct kvm *kvm);
arch/x86/kvm/mmu/mmu.c +38 -22
159 lines not on this page · raw message
arch/x86/kvm/mmu/page_track.c +30 -26
128 lines not on this page · raw message
drivers/gpu/drm/i915/gvt/kvmgt.c +5 -3
@@ -1706,7 +1706,8 @@ static int kvmgt_page_track_add(unsigned long handle, u64 gfn)if (kvmgt_gfn_is_write_protected (info, gfn)) goto out; -kvm_slot_page_track_add_page (kvm, slot, gfn,KVM_PAGE_TRACK_WRITE ); +kvm_slot_page_track_add_page (kvm, slot, gfn, +KVM_PAGE_TRACK_WRITE ,0 );kvmgt_protect_table_add (info, gfn); out:
@@ -1740,7 +1741,8 @@ static int kvmgt_page_track_remove(unsigned long handle, u64 gfn)if (!kvmgt_gfn_is_write_protected (info, gfn)) goto out; -kvm_slot_page_track_remove_page (kvm, slot, gfn,KVM_PAGE_TRACK_WRITE ); +kvm_slot_page_track_remove_page (kvm, slot, gfn, +KVM_PAGE_TRACK_WRITE ,0 );kvmgt_protect_table_del (info, gfn); out:
@@ -1775,7 +1777,7 @@ static void kvmgt_page_track_flush_slot(struct kvm *kvm, gfn = slot->base_gfn + i;if (kvmgt_gfn_is_write_protected (info, gfn)) {kvm_slot_page_track_remove_page (kvm, slot, gfn, -KVM_PAGE_TRACK_WRITE ); +KVM_PAGE_TRACK_WRITE ,0 );kvmgt_protect_table_del (info, gfn); } }
RFC PATCH 11/34 KVM: x86: mmu: allow zapping shadow pages for specific EPT views
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
Add a view mask for kvm_mmu_zap_all() in order to allow zapping shadow pages for specific EPT views. This is required when an introspected VM is unhooked. In that case, shadow pages that belong to non-default views will be zapped.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/mmu/mmu.c | 4 +++- arch/x86/kvm/x86.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1392,7 +1392,7 @@ void kvm_mmu_slot_set_dirty(struct kvm *kvm,void kvm_mmu_clear_dirty_pt_masked (struct kvm *kvm,struct kvm_memory_slot *slot,gfn_t gfn_offset,unsigned long mask); -void kvm_mmu_zap_all (struct kvm *kvm); +void kvm_mmu_zap_all (struct kvm *kvm,u16 view_mask);void kvm_mmu_invalidate_mmio_sptes (struct kvm *kvm,u64 gen);unsigned long kvm_mmu_calculate_default_mmu_pages (struct kvm *kvm);void kvm_mmu_change_mmu_pages (struct kvm *kvm,unsigned long kvm_nr_mmu_pages);
arch/x86/kvm/mmu/mmu.c +3 -1
@@ -6166,7 +6166,7 @@ void kvm_mmu_slot_set_dirty(struct kvm *kvm, }EXPORT_SYMBOL_GPL (kvm_mmu_slot_set_dirty); -void kvm_mmu_zap_all (struct kvm *kvm) +void kvm_mmu_zap_all (struct kvm *kvm,u16 view_mask) {struct kvm_mmu_page *sp, *node;LIST_HEAD (invalid_list);
@@ -6175,6 +6175,8 @@ void kvm_mmu_zap_all(struct kvm *kvm)spin_lock (&kvm->mmu_lock); restart:list_for_each_entry_safe (sp, node, &kvm->arch.active_mmu_pages, link) { +if (!test_bit (sp->view, (unsigned long *)&view_mask)) +continue ;if (sp->role.invalid && sp->root_count)continue ;if (__kvm_mmu_prepare_zap_page (kvm, sp, &invalid_list, &ign))
arch/x86/kvm/x86.c +3 -1
@@ -10406,7 +10406,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,void kvm_arch_flush_shadow_all (struct kvm *kvm) { -kvm_mmu_zap_all (kvm); +u16 ept_views_to_keep =0 ; + +kvm_mmu_zap_all (kvm, ~ept_views_to_keep); } void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 12/34 KVM: introspection: extend struct kvmi_features with the EPT views status support
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool will use these new fields to check the hardware support before using the related introspection commands.
--- Documentation/virt/kvm/kvmi.rst | 6 ++++-- arch/x86/include/uapi/asm/kvmi.h | 4 +++- arch/x86/kvm/kvmi.c | 4 ++++ tools/testing/selftests/kvm/x86_64/kvmi_test.c | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-)
Documentation/virt/kvm/kvmi.rst +4 -2
@@ -263,11 +263,13 @@ For x86 struct kvmi_features { __u8 singlestep; - __u8 padding[7]; + __u8 vmfunc; + __u8 eptp; + __u8 padding[5]; }; Returns the introspection API version and some of the features supported -by the hardware. +by the hardware (eg. alternate EPT views). This command is always allowed and successful.
arch/x86/include/uapi/asm/kvmi.h +3 -1
@@ -147,7 +147,9 @@ struct kvmi_event_msr_reply {struct kvmi_features {__u8 singlestep; -__u8 padding[7 ]; +__u8 vmfunc; +__u8 eptp; +__u8 padding[5 ]; };#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +4 -0
@@ -1356,6 +1356,10 @@ static void kvmi_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot,void kvmi_arch_features (struct kvmi_features *feat) { feat->singlestep = !!kvm_x86_ops.control_singlestep; + feat->vmfunc = kvm_x86_ops.get_vmfunc_status && + kvm_x86_ops.get_vmfunc_status (); + feat->eptp = kvm_x86_ops.get_eptp_switching_status && + kvm_x86_ops.get_eptp_switching_status (); }bool kvmi_arch_start_singlestep (struct kvm_vcpu *vcpu)
tools/testing/selftests/kvm/x86_64/kvmi_test.c +2 -0
@@ -443,6 +443,8 @@ static void test_cmd_get_version(void)pr_info ("KVMI version: %u\n" , rpl.version);pr_info ("\tsinglestep: %u\n" , features.singlestep); +pr_info ("\tvmfunc: %u\n" , features.vmfunc); +pr_info ("\teptp: %u\n" , features.eptp); }static void cmd_vm_check_command (__u16 id,__u16 padding,int expected_err)
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 13/34 KVM: introspection: add KVMI_VCPU_GET_EPT_VIEW
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool uses this function to check the hardware support for EPT switching, which can be used either to singlestep vCPUs on a unprotected EPT view or to use #VE in order to avoid filter out VM-exits caused by EPT violations.
--- Documentation/virt/kvm/kvmi.rst | 34 +++++++++++++++++++ arch/x86/include/uapi/asm/kvmi.h | 6 ++++ arch/x86/kvm/kvmi.c | 5 +++ include/uapi/linux/kvmi.h | 1 + .../testing/selftests/kvm/x86_64/kvmi_test.c | 28 +++++++++++++++ virt/kvm/introspection/kvmi_int.h | 1 + virt/kvm/introspection/kvmi_msg.c | 14 ++++++++ 7 files changed, 89 insertions(+)
Documentation/virt/kvm/kvmi.rst +34 -0
@@ -1120,6 +1120,40 @@ the address cannot be translated. * -KVM_EINVAL - the padding is not zero * -KVM_EAGAIN - the selected vCPU can't be introspected yet +26. KVMI_VCPU_GET_EPT_VIEW +-------------------------- + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vcpu_hdr; + +:Returns: + +:: + + struct kvmi_error_code; + struct kvmi_vcpu_get_ept_view_reply { + __u16 view; + __u16 padding1; + __u32 padding2; + }; + +Returns the EPT ``view`` the provided vCPU operates on. + +Before getting EPT views, the introspection tool should use +*KVMI_GET_VERSION* to check if the hardware has support for VMFUNC and +EPTP switching mechanism (see **KVMI_GET_VERSION**). If the hardware +does not provide support for these features, the returned EPT view will +be zero. + +* -KVM_EINVAL - the selected vCPU is invalid +* -KVM_EINVAL - the padding is not zero +* -KVM_EAGAIN - the selected vCPU can't be introspected yet + Events ======
arch/x86/include/uapi/asm/kvmi.h +6 -0
@@ -152,4 +152,10 @@ struct kvmi_features { __u8 padding[5]; }; +struct kvmi_vcpu_get_ept_view_reply { +__u16 view; +__u16 padding1; +__u32 padding2; +}; +#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +5 -0
@@ -1417,3 +1417,8 @@ bool kvmi_update_ad_flags(struct kvm_vcpu *vcpu)return ret; } + +u16 kvmi_arch_cmd_get_ept_view (struct kvm_vcpu *vcpu) +{ +return kvm_get_ept_view (vcpu); +}
include/uapi/linux/kvmi.h +1 -0
@@ -49,6 +49,7 @@ enum {KVMI_VCPU_CONTROL_SINGLESTEP =24 ,KVMI_VCPU_TRANSLATE_GVA =25 , +KVMI_VCPU_GET_EPT_VIEW =26 , KVMI_NUM_MESSAGES };
tools/testing/selftests/kvm/x86_64/kvmi_test.c +28 -0
@@ -2071,6 +2071,33 @@ static void test_cmd_translate_gva(struct kvm_vm *vm) (vm_vaddr_t)-1, (vm_paddr_t)-1); } +static __u16 get_ept_view (struct kvm_vm *vm) +{ +struct { +struct kvmi_msg_hdr hdr; +struct kvmi_vcpu_hdr vcpu_hdr; + } req = {}; +struct kvmi_vcpu_get_ept_view_reply rpl; + +test_vcpu0_command (vm,KVMI_VCPU_GET_EPT_VIEW , + &req.hdr,sizeof (req), &rpl,sizeof (rpl)); + +return rpl.view; +} + +static void test_cmd_vcpu_get_ept_view (struct kvm_vm *vm) +{ +__u16 view; + +if (!features.eptp) { +print_skip ("EPT views not supported" ); +return ; + } + + view =get_ept_view (vm); +pr_info ("EPT view %u\n" , view); +} +static void test_introspection (struct kvm_vm *vm) {srandom (time (0 ));
@@ -2107,6 +2134,7 @@ static void test_introspection(struct kvm_vm *vm)test_event_pf (vm);test_cmd_vcpu_control_singlestep (vm);test_cmd_translate_gva (vm); +test_cmd_vcpu_get_ept_view (vm);unhook_introspection (vm); }
virt/kvm/introspection/kvmi_int.h +1 -0
@@ -142,5 +142,6 @@ void kvmi_arch_features(struct kvmi_features *feat);bool kvmi_arch_start_singlestep (struct kvm_vcpu *vcpu);bool kvmi_arch_stop_singlestep (struct kvm_vcpu *vcpu);gpa_t kvmi_arch_cmd_translate_gva (struct kvm_vcpu *vcpu,gva_t gva); +u16 kvmi_arch_cmd_get_ept_view (struct kvm_vcpu *vcpu);#endif
virt/kvm/introspection/kvmi_msg.c +14 -0
@@ -661,6 +661,19 @@ static int handle_vcpu_translate_gva(const struct kvmi_vcpu_msg_job *job,return kvmi_msg_vcpu_reply (job, msg,0 , &rpl,sizeof (rpl)); } +static int handle_vcpu_get_ept_view (const struct kvmi_vcpu_msg_job *job, +const struct kvmi_msg_hdr *msg, +const void *req) +{ +struct kvmi_vcpu_get_ept_view_reply rpl; + +memset (&rpl,0 ,sizeof (rpl)); + + rpl.view =kvmi_arch_cmd_get_ept_view (job->vcpu); + +return kvmi_msg_vcpu_reply (job, msg,0 , &rpl,sizeof (rpl)); +} +/* * These functions are executed from the vCPU thread. The receiving thread * passes the messages using a newly allocated 'struct kvmi_vcpu_msg_job'
@@ -675,6 +688,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_msg_job *, [KVMI_VCPU_CONTROL_MSR] = handle_vcpu_control_msr, [KVMI_VCPU_CONTROL_SINGLESTEP] = handle_vcpu_control_singlestep, [KVMI_VCPU_GET_CPUID] = handle_vcpu_get_cpuid, + [KVMI_VCPU_GET_EPT_VIEW] = handle_vcpu_get_ept_view, [KVMI_VCPU_GET_INFO] = handle_vcpu_get_info, [KVMI_VCPU_GET_MTRR_TYPE] = handle_vcpu_get_mtrr_type, [KVMI_VCPU_GET_REGISTERS] = handle_vcpu_get_registers,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 14/34 KVM: introspection: add 'view' field to struct kvmi_event_arch
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
Report the view a vCPU operates on when sending events to the introspection tool.
--- arch/x86/include/uapi/asm/kvmi.h | 4 +++- arch/x86/kvm/kvmi.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
arch/x86/include/uapi/asm/kvmi.h +3 -1
@@ -12,7 +12,9 @@struct kvmi_event_arch {__u8 mode;/* 2, 4 or 8 */ -__u8 padding[7 ]; +__u8 padding1; +__u16 view; +__u32 padding2;struct kvm_regs regs;struct kvm_sregs sregs;struct {
arch/x86/kvm/kvmi.c +1 -0
@@ -102,6 +102,7 @@ void kvmi_arch_setup_event(struct kvm_vcpu *vcpu, struct kvmi_event *ev)kvm_arch_vcpu_get_sregs (vcpu, &event->sregs); ev->arch.mode =kvmi_vcpu_mode (vcpu, &event->sregs);kvmi_get_msrs (vcpu, event); + event->view =kvm_get_ept_view (vcpu); } int kvmi_arch_cmd_vcpu_get_info(struct kvm_vcpu *vcpu,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 15/34 KVM: introspection: add KVMI_VCPU_SET_EPT_VIEW
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool uses this function to check the hardware support for EPT switching, which can be used to singlestep vCPUs
on a unprotected EPT view.
--- Documentation/virt/kvm/kvmi.rst | 36 ++++++++++++++++ arch/x86/include/uapi/asm/kvmi.h | 6 +++ arch/x86/kvm/kvmi.c | 9 ++++ include/uapi/linux/kvmi.h | 1 + .../testing/selftests/kvm/x86_64/kvmi_test.c | 43 +++++++++++++++++++ virt/kvm/introspection/kvmi_int.h | 6 +++ virt/kvm/introspection/kvmi_msg.c | 20 +++++++++ 7 files changed, 121 insertions(+)
Documentation/virt/kvm/kvmi.rst +36 -0
@@ -1154,6 +1154,42 @@ be zero. * -KVM_EINVAL - the padding is not zero * -KVM_EAGAIN - the selected vCPU can't be introspected yet +27. KVMI_VCPU_SET_EPT_VIEW +-------------------------- + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vcpu_hdr; + struct kvmi_vcpu_set_ept_view { + __u16 view; + __u16 padding1; + __u32 padding2; + }; + +:Returns: + +:: + + struct kvmi_error_code; + +Configures the vCPU to use the provided ``view``. + +Before switching EPT views, the introspection tool should use +*KVMI_GET_VERSION* to check if the hardware has support for VMFUNC and +EPTP switching mechanism (see **KVMI_GET_VERSION**). + +:Errors: + +* -KVM_EINVAL - the selected vCPU is invalid +* -KVM_EINVAL - padding is not zero +* -KVM_EINVAL - the selected EPT view is invalid +* -KVM_EAGAIN - the selected vCPU can't be introspected yet +* -KVM_EOPNOTSUPP - an EPT view was selected but the hardware doesn't support it + Events ======
arch/x86/include/uapi/asm/kvmi.h +6 -0
@@ -160,4 +160,10 @@ struct kvmi_vcpu_get_ept_view_reply { __u32 padding2; }; +struct kvmi_vcpu_set_ept_view { +__u16 view; +__u16 padding1; +__u32 padding2; +}; +#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +9 -0
@@ -1423,3 +1423,12 @@ u16 kvmi_arch_cmd_get_ept_view(struct kvm_vcpu *vcpu) {return kvm_get_ept_view (vcpu); } + +int kvmi_arch_cmd_set_ept_view (struct kvm_vcpu *vcpu,u16 view) +{ + +if (!kvm_x86_ops.set_ept_view) +return -KVM_EINVAL ; + +return kvm_x86_ops.set_ept_view (vcpu, view); +}
include/uapi/linux/kvmi.h +1 -0
@@ -50,6 +50,7 @@ enum {KVMI_VCPU_CONTROL_SINGLESTEP =24 ,KVMI_VCPU_TRANSLATE_GVA =25 ,KVMI_VCPU_GET_EPT_VIEW =26 , +KVMI_VCPU_SET_EPT_VIEW =27 , KVMI_NUM_MESSAGES };
tools/testing/selftests/kvm/x86_64/kvmi_test.c +43 -0
61 lines not on this page · raw message
virt/kvm/introspection/kvmi_int.h +6 -0
@@ -32,6 +32,11 @@ static inline bool is_event_enabled(struct kvm_vcpu *vcpu, int event)return test_bit (event,VCPUI (vcpu)->ev_enable_mask); } +static inline bool is_valid_view (unsigned short view) +{ +return (view <KVM_MAX_EPT_VIEWS ); +} +/* kvmi_msg.c */ bool kvmi_sock_get (struct kvm_introspection *kvmi,int fd);void kvmi_sock_shutdown (struct kvm_introspection *kvmi);
@@ -143,5 +148,6 @@ bool kvmi_arch_start_singlestep(struct kvm_vcpu *vcpu);bool kvmi_arch_stop_singlestep (struct kvm_vcpu *vcpu);gpa_t kvmi_arch_cmd_translate_gva (struct kvm_vcpu *vcpu,gva_t gva);u16 kvmi_arch_cmd_get_ept_view (struct kvm_vcpu *vcpu); +int kvmi_arch_cmd_set_ept_view (struct kvm_vcpu *vcpu,u16 view);#endif
virt/kvm/introspection/kvmi_msg.c +20 -0
@@ -674,6 +674,25 @@ static int handle_vcpu_get_ept_view(const struct kvmi_vcpu_msg_job *job,return kvmi_msg_vcpu_reply (job, msg,0 , &rpl,sizeof (rpl)); } +static int handle_vcpu_set_ept_view (const struct kvmi_vcpu_msg_job *job, +const struct kvmi_msg_hdr *msg, +const void *_req) +{ +const struct kvmi_vcpu_set_ept_view *req = _req; +int ec; + +if (req->padding1 || req->padding2) + ec = -KVM_EINVAL ; +else if (!is_valid_view (req->view)) + ec = -KVM_EINVAL ; +else if (!kvm_eptp_switching_supported) + ec = -KVM_EOPNOTSUPP ; +else + ec =kvmi_arch_cmd_set_ept_view (job->vcpu, req->view); + +return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); +} +/* * These functions are executed from the vCPU thread. The receiving thread * passes the messages using a newly allocated 'struct kvmi_vcpu_msg_job'
@@ -695,6 +714,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_msg_job *, [KVMI_VCPU_GET_XCR] = handle_vcpu_get_xcr, [KVMI_VCPU_GET_XSAVE] = handle_vcpu_get_xsave, [KVMI_VCPU_INJECT_EXCEPTION] = handle_vcpu_inject_exception, + [KVMI_VCPU_SET_EPT_VIEW] = handle_vcpu_set_ept_view, [KVMI_VCPU_SET_REGISTERS] = handle_vcpu_set_registers, [KVMI_VCPU_SET_XSAVE] = handle_vcpu_set_xsave, [KVMI_VCPU_TRANSLATE_GVA] = handle_vcpu_translate_gva,
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 16/34 KVM: introspection: add KVMI_VCPU_CONTROL_EPT_VIEW
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This will be used by the introspection tool to control the EPT views to which the guest is allowed to switch.
--- Documentation/virt/kvm/kvmi.rst | 37 ++++++ arch/x86/include/uapi/asm/kvmi.h | 7 ++ arch/x86/kvm/kvmi.c | 9 ++ include/uapi/linux/kvmi.h | 1 + .../testing/selftests/kvm/x86_64/kvmi_test.c | 118 ++++++++++++++++++ virt/kvm/introspection/kvmi_int.h | 2 + virt/kvm/introspection/kvmi_msg.c | 19 +++ 7 files changed, 193 insertions(+)
Documentation/virt/kvm/kvmi.rst +37 -0
@@ -1190,6 +1190,43 @@ EPTP switching mechanism (see **KVMI_GET_VERSION**). * -KVM_EAGAIN - the selected vCPU can't be introspected yet * -KVM_EOPNOTSUPP - an EPT view was selected but the hardware doesn't support it +28. KVMI_VCPU_CONTROL_EPT_VIEW +------------------------------ + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vcpu_hdr; + struct kvmi_vcpu_control_ept_view { + __u16 view; + __u8 visible; + __u8 padding1; + __u32 padding2; + }; + +:Returns: + +:: + + struct kvmi_error_code; + +Controls the capability of the guest to successfully change EPT views +through VMFUNC instruction without triggering a vm-exit. If ``visible`` +is true, the guest will be capable to change EPT views through VMFUNC(0, +``view``). If ``visible`` is false, VMFUNC(0, ``view``) triggers a +vm-exit, a #UD exception is injected to guest and the guest application +is terminated. + +:Errors: + +* -KVM_EINVAL - the selected vCPU is invalid +* -KVM_EAGAIN - the selected vCPU can't be introspected yet +* -KVM_EINVAL - padding is not zero +* -KVM_EINVAL - the selected EPT view is not valid + Events ======
arch/x86/include/uapi/asm/kvmi.h +7 -0
@@ -166,4 +166,11 @@ struct kvmi_vcpu_set_ept_view { __u32 padding2; }; +struct kvmi_vcpu_control_ept_view { +__u16 view; +__u8 visible; +__u8 padding1; +__u32 padding2; +}; +#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +9 -0
@@ -1432,3 +1432,12 @@ int kvmi_arch_cmd_set_ept_view(struct kvm_vcpu *vcpu, u16 view)return kvm_x86_ops.set_ept_view (vcpu, view); } + +int kvmi_arch_cmd_control_ept_view (struct kvm_vcpu *vcpu,u16 view, +bool visible) +{ +if (!kvm_x86_ops.control_ept_view) +return -KVM_EINVAL ; + +return kvm_x86_ops.control_ept_view (vcpu, view, visible); +}
include/uapi/linux/kvmi.h +1 -0
@@ -51,6 +51,7 @@ enum {KVMI_VCPU_TRANSLATE_GVA =25 ,KVMI_VCPU_GET_EPT_VIEW =26 ,KVMI_VCPU_SET_EPT_VIEW =27 , +KVMI_VCPU_CONTROL_EPT_VIEW =28 , KVMI_NUM_MESSAGES };
tools/testing/selftests/kvm/x86_64/kvmi_test.c +118 -0
166 lines not on this page · raw message
virt/kvm/introspection/kvmi_int.h +2 -0
@@ -149,5 +149,7 @@ bool kvmi_arch_stop_singlestep(struct kvm_vcpu *vcpu);gpa_t kvmi_arch_cmd_translate_gva (struct kvm_vcpu *vcpu,gva_t gva);u16 kvmi_arch_cmd_get_ept_view (struct kvm_vcpu *vcpu);int kvmi_arch_cmd_set_ept_view (struct kvm_vcpu *vcpu,u16 view); +int kvmi_arch_cmd_control_ept_view (struct kvm_vcpu *vcpu,u16 view, +bool visible);#endif
virt/kvm/introspection/kvmi_msg.c +19 -0
@@ -693,6 +693,24 @@ static int handle_vcpu_set_ept_view(const struct kvmi_vcpu_msg_job *job,return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); } +static int handle_vcpu_control_ept_view (const struct kvmi_vcpu_msg_job *job, +const struct kvmi_msg_hdr *msg, +const void *_req) +{ +const struct kvmi_vcpu_control_ept_view *req = _req; +int ec; + +if (req->padding1 || req->padding2) + ec = -KVM_EINVAL ; +else if (!is_valid_view (req->view)) + ec = -KVM_EINVAL ; +else + ec =kvmi_arch_cmd_control_ept_view (job->vcpu, req->view, + req->visible); + +return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); +} +/* * These functions are executed from the vCPU thread. The receiving thread * passes the messages using a newly allocated 'struct kvmi_vcpu_msg_job'
@@ -703,6 +721,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_msg_job *, const struct kvmi_msg_hdr *, const void *) = { [KVMI_EVENT ] = handle_vcpu_event_reply, [KVMI_VCPU_CONTROL_CR ] = handle_vcpu_control_cr, + [KVMI_VCPU_CONTROL_EPT_VIEW ] = handle_vcpu_control_ept_view, [KVMI_VCPU_CONTROL_EVENTS ] = handle_vcpu_control_events, [KVMI_VCPU_CONTROL_MSR ] = handle_vcpu_control_msr, [KVMI_VCPU_CONTROL_SINGLESTEP ] = handle_vcpu_control_singlestep,
RFC PATCH 17/34 KVM: introspection: extend the access rights database with EPT view info
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
On EPT violations, when we check if the introspection tool has shown interest in the current guest page, we will take into consideration the EPT view of the current vCPU too.
--- arch/x86/include/asm/kvmi_host.h | 1 + arch/x86/kvm/kvmi.c | 9 +-- include/linux/kvmi_host.h | 2 +- virt/kvm/introspection/kvmi.c | 107 +++++++++++++++++------------- virt/kvm/introspection/kvmi_int.h | 4 +- 5 files changed, 71 insertions(+), 52 deletions(-)
arch/x86/include/asm/kvmi_host.h +1 -0
@@ -9,6 +9,7 @@ struct msr_data;#define KVMI_NUM_CR 5#define KVMI_NUM_MSR 0x2000 +#define KVMI_MAX_ACCESS_TREES KVM_MAX_EPT_VIEWSstruct kvmi_monitor_interception {bool kvmi_intercepted;
arch/x86/kvm/kvmi.c +5 -4
@@ -1197,7 +1197,7 @@ static const struct {void kvmi_arch_update_page_tracking (struct kvm *kvm,struct kvm_memory_slot *slot, -struct kvmi_mem_access *m) +struct kvmi_mem_access *m,u16 view) {struct kvmi_arch_mem_access *arch = &m->arch;int i;
@@ -1217,12 +1217,12 @@ void kvmi_arch_update_page_tracking(struct kvm *kvm,if (slot_tracked) {kvm_slot_page_track_remove_page (kvm, slot, m->gfn, mode, -0 ); + view);clear_bit (slot->id, arch->active[mode]); } }else if (!slot_tracked) {kvm_slot_page_track_add_page (kvm, slot, m->gfn, mode, -0 ); + view);set_bit (slot->id, arch->active[mode]); } }
@@ -1256,7 +1256,8 @@ static bool is_pf_of_interest(struct kvm_vcpu *vcpu, gpa_t gpa, u8 access)if (kvm_x86_ops.gpt_translation_fault (vcpu))return false; -return kvmi_restricted_page_access (KVMI (vcpu->kvm), gpa, access); +return kvmi_restricted_page_access (KVMI (vcpu->kvm), gpa, access, +kvm_get_ept_view (vcpu)); } static bool handle_pf_event(struct kvm_vcpu *vcpu, gpa_t gpa, gva_t gva,
include/linux/kvmi_host.h +1 -1
@@ -69,7 +69,7 @@ struct kvm_introspection {bool cleanup_on_unhook; -struct radix_tree_root access_tree; +struct radix_tree_root access_tree[KVMI_MAX_ACCESS_TREES ];rwlock_t access_tree_lock; };
virt/kvm/introspection/kvmi.c +62 -45
239 lines not on this page · raw message
virt/kvm/introspection/kvmi_int.h +2 -2
@@ -89,7 +89,7 @@ int kvmi_cmd_set_page_access(struct kvm_introspection *kvmi,const struct kvmi_msg_hdr *msg, const struct kvmi_vm_set_page_access *req);bool kvmi_restricted_page_access (struct kvm_introspection *kvmi,gpa_t gpa, -u8 access); +u8 access,u16 view);bool kvmi_pf_event (struct kvm_vcpu *vcpu,gpa_t gpa,gva_t gva,u8 access);void kvmi_add_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages);
@@ -140,7 +140,7 @@ int kvmi_arch_cmd_vcpu_control_msr(struct kvm_vcpu *vcpu, const struct kvmi_vcpu_control_msr *req);void kvmi_arch_update_page_tracking (struct kvm *kvm,struct kvm_memory_slot *slot, -struct kvmi_mem_access *m); +struct kvmi_mem_access *m,u16 view);void kvmi_arch_hook (struct kvm *kvm);void kvmi_arch_unhook (struct kvm *kvm);void kvmi_arch_features (struct kvmi_features *feat);
RFC PATCH 18/34 KVM: introspection: extend KVMI_VM_SET_PAGE_ACCESS with EPT view info
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool uses this command to set distinct access rights on different EPT views.
--- Documentation/virt/kvm/kvmi.rst | 8 +++++--- include/uapi/linux/kvmi.h | 4 ++-- virt/kvm/introspection/kvmi.c | 10 ++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-)
Documentation/virt/kvm/kvmi.rst +5 -3
@@ -1003,8 +1003,8 @@ to control events for any other register will fail with -KVM_EINVAL:: struct kvmi_vm_set_page_access { __u16 count; - __u16 padding1; - __u32 padding2; + __u16 view; + __u32 padding; struct kvmi_page_access_entry entries[0]; };
@@ -1026,7 +1026,7 @@ where:: struct kvmi_error_code Sets the access bits (rwx) for an array of ``count`` guest physical -addresses. +addresses, for the selected view. The valid access bits are::
@@ -1048,7 +1048,9 @@ In order to 'forget' an address, all three bits ('rwx') must be set. * -KVM_EINVAL - the specified access bits combination is invalid * -KVM_EINVAL - the padding is not zero +* -KVM_EINVAL - the selected EPT view is invalid * -KVM_EINVAL - the message size is invalid +* -KVM_EOPNOTSUPP - an EPT view was selected but the hardware doesn't support it * -KVM_EAGAIN - the selected vCPU can't be introspected yet * -KVM_ENOMEM - there is not enough memory to add the page tracking structures
include/uapi/linux/kvmi.h +2 -2
@@ -191,8 +191,8 @@ struct kvmi_page_access_entry {struct kvmi_vm_set_page_access {__u16 count; -__u16 padding1; -__u32 padding2; +__u16 view; +__u32 padding;struct kvmi_page_access_entry entries[0 ]; };
virt/kvm/introspection/kvmi.c +8 -2
@@ -1187,14 +1187,20 @@ int kvmi_cmd_set_page_access(struct kvm_introspection *kvmi,const struct kvmi_page_access_entry *end = req->entries + req->count;int ec =0 ; -if (req->padding1 || req->padding2) +if (req->padding)return -KVM_EINVAL ;if (msg->size <struct_size (req, entries, req->count))return -KVM_EINVAL ; +if (!is_valid_view (req->view)) +return -KVM_EINVAL ; + +if (req->view !=0 && !kvm_eptp_switching_supported) +return -KVM_EOPNOTSUPP ; +for (; entry < end; entry++) { -int r =set_page_access_entry (kvmi,0 , entry); +int r =set_page_access_entry (kvmi, req->view, entry);if (r && !ec) ec = r;
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 19/34 KVM: introspection: clean non-default EPTs on unhook
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
When a guest is unhooked, the VM is brought to default state and uses default EPT view. Delete all shadow pages that belong to non-default EPT views in order to free unused shadow pages. They are not used because the guest cannot VMFUNC to any EPT view.
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/kvmi.c | 23 ++++++++++++++++++++++- virt/kvm/introspection/kvmi.c | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -1026,6 +1026,8 @@ struct kvm_arch {struct kvm_pmu_event_filter *pmu_event_filter;struct task_struct *nx_lpage_recovery_thread; + +refcount_t kvmi_refcount; };struct kvm_vm_stat {
arch/x86/kvm/kvmi.c +22 -1
@@ -640,6 +640,25 @@ static void kvmi_arch_restore_interception(struct kvm_vcpu *vcpu)kvmi_arch_disable_msrw_intercept (vcpu, arch_vcpui->msrw.kvmi_mask.high); } +void kvmi_arch_restore_ept_view (struct kvm_vcpu *vcpu) +{ +struct kvm *kvm = vcpu->kvm; +u16 view, default_view =0 ; +bool visible = false; + +if (kvm_get_ept_view (vcpu) != default_view) +kvmi_arch_cmd_set_ept_view (vcpu, default_view); + +for (view =0 ; view <KVM_MAX_EPT_VIEWS ; view++) +kvmi_arch_cmd_control_ept_view (vcpu, view, visible); + +if (refcount_dec_and_test (&kvm->arch.kvmi_refcount)) { +u16 zap_mask = ~(1 << default_view); + +kvm_mmu_zap_all (vcpu->kvm, zap_mask); + } +} +bool kvmi_arch_clean_up_interception (struct kvm_vcpu *vcpu) {struct kvmi_interception *arch_vcpui = vcpu->arch.kvmi;
@@ -647,8 +666,10 @@ bool kvmi_arch_clean_up_interception(struct kvm_vcpu *vcpu)if (!arch_vcpui || !arch_vcpui->cleanup)return false; -if (arch_vcpui->restore_interception) +if (arch_vcpui->restore_interception) {kvmi_arch_restore_interception (vcpu); +kvmi_arch_restore_ept_view (vcpu); + }return true; }
virt/kvm/introspection/kvmi.c +3 -0
@@ -288,6 +288,9 @@ static void free_kvmi(struct kvm *kvm)kvmi_clear_mem_access (kvm); +refcount_set (&kvm->arch.kvmi_refcount, +atomic_read (&kvm->online_vcpus)); +kvm_for_each_vcpu (i, vcpu, kvm)free_vcpui (vcpu, restore_interception);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 20/34 KVM: x86: vmx: add support for virtualization exceptions
In reply to Adalbert LazărFrom: Marian Rotariu <[email protected]>
Only the hardware support check function and the #VE info page management are introduced.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/asm/vmx.h | 3 +++ arch/x86/kvm/vmx/capabilities.h | 5 +++++ arch/x86/kvm/vmx/vmx.c | 31 +++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.h | 12 ++++++++++++ arch/x86/kvm/x86.c | 3 +++ 6 files changed, 55 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1435,6 +1435,7 @@ extern u64 kvm_default_tsc_scaling_ratio;extern u64 kvm_mce_cap_supported;extern bool kvm_eptp_switching_supported; +extern bool kvm_ve_supported;/* * EMULTYPE_NO_DECODE - Set when re-emulating an instruction (after completing
arch/x86/include/asm/vmx.h +3 -0
@@ -67,6 +67,7 @@#define SECONDARY_EXEC_ENCLS_EXITING VMCS_CONTROL_BIT(ENCLS_EXITING)#define SECONDARY_EXEC_RDSEED_EXITING VMCS_CONTROL_BIT(RDSEED_EXITING)#define SECONDARY_EXEC_ENABLE_PML VMCS_CONTROL_BIT(PAGE_MOD_LOGGING) +#define SECONDARY_EXEC_EPT_VE VMCS_CONTROL_BIT(EPT_VIOLATION_VE)#define SECONDARY_EXEC_PT_CONCEAL_VMX VMCS_CONTROL_BIT(PT_CONCEAL_VMX)#define SECONDARY_EXEC_XSAVES VMCS_CONTROL_BIT(XSAVES)#define SECONDARY_EXEC_MODE_BASED_EPT_EXEC VMCS_CONTROL_BIT(MODE_BASED_EPT_EXEC)
@@ -213,6 +214,8 @@ enum vmcs_field {VMREAD_BITMAP_HIGH =0x00002027 ,VMWRITE_BITMAP =0x00002028 ,VMWRITE_BITMAP_HIGH =0x00002029 , +VE_INFO_ADDRESS =0x0000202A , +VE_INFO_ADDRESS_HIGH =0x0000202B ,XSS_EXIT_BITMAP =0x0000202C ,XSS_EXIT_BITMAP_HIGH =0x0000202D , ENCLS_EXITING_BITMAP = 0x0000202E,
arch/x86/kvm/vmx/capabilities.h +5 -0
@@ -257,6 +257,11 @@ static inline bool cpu_has_vmx_pml(void)return vmcs_config.cpu_based_2nd_exec_ctrl &SECONDARY_EXEC_ENABLE_PML ; } +static inline bool cpu_has_vmx_ve (void ) +{ +return vmcs_config.cpu_based_2nd_exec_ctrl &SECONDARY_EXEC_EPT_VE ; +} +static inline bool vmx_xsaves_supported (void ) { return vmcs_config.cpu_based_2nd_exec_ctrl &
arch/x86/kvm/vmx/vmx.c +31 -0
@@ -2463,6 +2463,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,SECONDARY_EXEC_RDSEED_EXITING |SECONDARY_EXEC_RDRAND_EXITING |SECONDARY_EXEC_ENABLE_PML | +SECONDARY_EXEC_EPT_VE |SECONDARY_EXEC_TSC_SCALING |SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | SECONDARY_EXEC_PT_USE_GPA |
@@ -4247,6 +4248,12 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)*/ exec_control &= ~SECONDARY_EXEC_SHADOW_VMCS ; +/* #VE must be disabled by default. +* Once enabled, all EPT violations on pages missing the SVE bit +* will be delivered to the guest. +*/ + exec_control &= ~SECONDARY_EXEC_EPT_VE ; +if (!enable_pml) exec_control &= ~SECONDARY_EXEC_ENABLE_PML ;
@@ -6019,6 +6026,28 @@ static void dump_eptp_list(void)pr_err ("%d: %016llx\n" , i, *(eptp_list + i)); } +static void dump_ve_info (void ) +{ +phys_addr_t ve_info_phys; +struct vcpu_ve_info *ve_info =NULL ; + +if (!cpu_has_vmx_ve ()) +return ; + + ve_info_phys = (phys_addr_t )vmcs_read64 (VE_INFO_ADDRESS ); +if (!ve_info_phys) +return ; + + ve_info = (struct vcpu_ve_info *)phys_to_virt (ve_info_phys); + +pr_err ("*** Virtualization Exception Info ***\n" ); +pr_err ("ExitReason: %x\n" , ve_info->exit_reason); +pr_err ("ExitQualification: %llx\n" , ve_info->exit_qualification); +pr_err ("GVA: %llx\n" , ve_info->gva); +pr_err ("GPA: %llx\n" , ve_info->gpa); +pr_err ("EPTPIndex: %x\n" , ve_info->eptp_index); +} +void dump_vmcs (void ) {u32 vmentry_ctl, vmexit_ctl;
@@ -6169,6 +6198,7 @@ void dump_vmcs(void) vmcs_read16(VIRTUAL_PROCESSOR_ID));dump_eptp_list (); +dump_ve_info (); }static unsigned int update_ept_view (struct vcpu_vmx *vmx)
@@ -8340,6 +8370,7 @@ static __init int hardware_setup(void) enable_ept =0 ; kvm_eptp_switching_supported =cpu_has_vmx_eptp_switching (); + kvm_ve_supported =cpu_has_vmx_ve ();if (!cpu_has_vmx_ept_ad_bits () || !enable_ept) enable_ept_ad_bits =0 ;
arch/x86/kvm/vmx/vmx.h +12 -0
@@ -24,6 +24,18 @@ extern const u32 vmx_msr_index[];#define NR_LOADSTORE_MSRS 8 +struct vcpu_ve_info { +u32 exit_reason; +u32 unused; +u64 exit_qualification; +u64 gva; +u64 gpa; +u16 eptp_index; + +u16 offset1; +u32 offset2; +}; +struct vmx_msrs {unsigned int nr;struct vmx_msr_entry val[NR_LOADSTORE_MSRS ];
arch/x86/kvm/x86.c +3 -0
@@ -164,6 +164,9 @@ module_param(pi_inject_timer, bint, S_IRUGO | S_IWUSR);bool __read_mostly kvm_eptp_switching_supported;EXPORT_SYMBOL_GPL (kvm_eptp_switching_supported); +bool __read_mostly kvm_ve_supported; +EXPORT_SYMBOL_GPL (kvm_ve_supported); +#define KVM_NR_SHARED_MSRS 16struct kvm_shared_msrs_global {
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 21/34 KVM: VMX: Define EPT suppress #VE bit (bit 63 in EPT leaf entries)
In reply to Adalbert LazărFrom: Sean Christopherson <[email protected]>
VMX provides a capability that allows EPT violations to be reflected into the guest as Virtualization Exceptions (#VE). The primary use case of EPT violation #VEs is to improve the performance of virtualization- based security solutions, e.g. eliminate a VM-Exit -> VM-Exit roundtrip when utilizing EPT to protect priveleged data structures or code.
The "Suppress #VE" bit allows a VMM to opt-out of EPT violation #VEs on a per page basis, e.g. when a page is marked not-present due to lazy installation or is write-protected for dirty page logging.
The "Suppress #VE" bit is ignored:
- By hardware that does not support EPT violation #VEs
- When the EPT violation #VE VMCS control is disabled
- On non-leaf EPT entries
--- arch/x86/include/asm/vmx.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/vmx.h +1 -0
@@ -498,6 +498,7 @@ enum vmcs_field {#define VMX_EPT_IPAT_BIT (1ull << 6)#define VMX_EPT_ACCESS_BIT (1ull << 8)#define VMX_EPT_DIRTY_BIT (1ull << 9) +#define VMX_EPT_SUPPRESS_VE_BIT (1ull << 63)#define VMX_EPT_RWX_MASK (VMX_EPT_READABLE_MASK | \ VMX_EPT_WRITABLE_MASK | \ VMX_EPT_EXECUTABLE_MASK)
RFC PATCH 22/34 KVM: VMX: Suppress EPT violation #VE by default (when enabled)
In reply to Adalbert LazărFrom: Sean Christopherson <[email protected]>
Unfortunately (for software), EPT violation #VEs are opt-out on a per page basis, e.g. a not-present EPT violation on a zeroed EPT entry will be morphed to a #VE due to the "suppress #VE" bit not being set.
When EPT violation #VEs are enabled, use a variation of clear_page() that sets bit 63 (suppress #VE) in all 8-byte entries. To wire up the new behavior in the x86 MMU, add a new kvm_x86_ops hook and a new mask to define a "shadow init value", which is needed to express the concept that a cleared spte has a non-zero value when EPT violation #VEs are in use.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/Makefile | 2 +- arch/x86/kvm/mmu.h | 1 + arch/x86/kvm/mmu/mmu.c | 22 +++++++++++++++------- arch/x86/kvm/vmx/clear_page.S | 17 +++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 18 +++++++++++++++--- 6 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 arch/x86/kvm/vmx/clear_page.S
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1168,6 +1168,7 @@ struct kvm_x86_ops {* the implementation may choose to ignore if appropriate. */ void (*tlb_flush_gva)(struct kvm_vcpu *vcpu,gva_t addr); +void (*clear_page)(void *page);/* * Flush any TLB entries created by the guest. Like tlb_flush_gva(),
arch/x86/kvm/Makefile +1 -1
@@ -19,7 +19,7 @@ kvm-y += x86.o emulate.o i8259.o irq.o lapic.o \ i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \ hyperv.o debugfs.o mmu/mmu.o mmu/page_track.o -kvm-intel-y += vmx/vmx.o vmx/vmenter.o vmx/pmu_intel.o vmx/vmcs12.o vmx/evmcs.o vmx/nested.o +kvm-intel-y += vmx/vmx.o vmx/vmenter.o vmx/pmu_intel.o vmx/vmcs12.o vmx/evmcs.o vmx/nested.o vmx/clear_page.o kvm-amd-y += svm/svm.o svm/vmenter.o svm/pmu.o svm/nested.o svm/avic.o svm/sev.o obj-$(CONFIG_KVM) += kvm.o
arch/x86/kvm/mmu.h +1 -0
@@ -52,6 +52,7 @@ static inline u64 rsvd_bits(int s, int e) }void kvm_mmu_set_mmio_spte_mask (u64 mmio_value,u64 access_mask); +void kvm_mmu_set_spte_init_value (u64 init_value);void reset_shadow_zero_bits_mask (struct kvm_vcpu *vcpu,struct kvm_mmu *context);
arch/x86/kvm/mmu/mmu.c +15 -7
@@ -253,6 +253,7 @@ static u64 __read_mostly shadow_mmio_value;static u64 __read_mostly shadow_mmio_access_mask;static u64 __read_mostly shadow_present_mask;static u64 __read_mostly shadow_me_mask; +static u64 __read_mostly shadow_init_value;/* * SPTEs used by MMUs without A/D bits are marked with SPTE_AD_DISABLED_MASK;
@@ -542,6 +543,12 @@ void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, }EXPORT_SYMBOL_GPL (kvm_mmu_set_mask_ptes); +void kvm_mmu_set_spte_init_value (u64 init_value) +{ + shadow_init_value = init_value; +} +EXPORT_SYMBOL_GPL (kvm_mmu_set_spte_init_value); +static u8 kvm_get_shadow_phys_bits (void ) {/*
@@ -572,6 +579,7 @@ static void kvm_mmu_reset_all_pte_masks(void) shadow_x_mask =0 ; shadow_present_mask =0 ; shadow_acc_track_mask =0 ; + shadow_init_value =0 ; shadow_phys_bits =kvm_get_shadow_phys_bits ();
@@ -612,7 +620,7 @@ static int is_nx(struct kvm_vcpu *vcpu)static int is_shadow_present_pte (u64 pte) { -return (pte !=0 ) && !is_mmio_spte (pte); +return (pte !=0 ) && pte != shadow_init_value && !is_mmio_spte (pte); }static int is_large_pte (u64 pte)
@@ -923,9 +931,9 @@ static int mmu_spte_clear_track_bits(u64 *sptep)u64 old_spte = *sptep;if (!spte_has_volatile_bits (old_spte)) -__update_clear_spte_fast (sptep,0ull ); +__update_clear_spte_fast (sptep, shadow_init_value);else - old_spte =__update_clear_spte_slow (sptep,0ull ); + old_spte =__update_clear_spte_slow (sptep, shadow_init_value);if (!is_shadow_present_pte (old_spte))return 0 ;
@@ -955,7 +963,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep)*/ static void mmu_spte_clear_no_track (u64 *sptep) { -__update_clear_spte_fast (sptep,0ull ); +__update_clear_spte_fast (sptep, shadow_init_value); }static u64 mmu_spte_get_lockless (u64 *sptep)
@@ -2660,7 +2668,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,if (level >PG_LEVEL_4K && need_sync) flush |=kvm_sync_pages (vcpu, gfn, &invalid_list); } -clear_page (sp->spt); + kvm_x86_ops.clear_page (sp->spt);trace_kvm_mmu_get_page (sp, true);kvm_mmu_flush_or_zap (vcpu, &invalid_list, false, flush);
@@ -3637,7 +3645,7 @@ static bool fast_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,struct kvm_shadow_walk_iterator iterator;struct kvm_mmu_page *sp;bool fault_handled = false; -u64 spte =0ull ; +u64 spte = shadow_init_value;uint retry_count =0 ;if (!page_fault_can_be_fast (error_code))
@@ -4073,7 +4081,7 @@ static bool walk_shadow_page_get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr, u64 *sptep) { struct kvm_shadow_walk_iterator iterator; -u64 sptes[PT64_ROOT_MAX_LEVEL ], spte =0ull ; +u64 sptes[PT64_ROOT_MAX_LEVEL ], spte = shadow_init_value;struct rsvd_bits_validate *rsvd_check;int root, leaf;bool reserved = false;
arch/x86/kvm/vmx/clear_page.S new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/linkage.h> + +/* + * "Clear" an EPT page when EPT violation #VEs are enabled, in which case the + * suppress #VE bit needs to be set for all unused entries. + * + * %rdi - page + */ +#define VMX_EPT_SUPPRESS_VE_BIT (1ull << 63) + +SYM_FUNC_START(vmx_suppress_ve_clear_page) + movl $4096/8,%ecx + movabsq $0x8000000000000000,%rax + rep stosq + ret +SYM_FUNC_END(vmx_suppress_ve_clear_page)
arch/x86/kvm/vmx/vmx.c +15 -3
@@ -5639,14 +5639,24 @@ static void wakeup_handler(void)spin_unlock (&per_cpu (blocked_vcpu_on_cpu_lock, cpu)); } +void vmx_suppress_ve_clear_page (void *page); +static void vmx_enable_tdp (void ) { +u64 p_mask =0 ; + +if (!cpu_has_vmx_ept_execute_only ()) + p_mask |=VMX_EPT_READABLE_MASK ; +if (kvm_ve_supported) { + p_mask |=VMX_EPT_SUPPRESS_VE_BIT ; +kvm_mmu_set_spte_init_value (VMX_EPT_SUPPRESS_VE_BIT ); + kvm_x86_ops.clear_page = vmx_suppress_ve_clear_page; + } +kvm_mmu_set_mask_ptes (VMX_EPT_READABLE_MASK , enable_ept_ad_bits ?VMX_EPT_ACCESS_BIT :0ull , enable_ept_ad_bits ?VMX_EPT_DIRTY_BIT :0ull , -0ull ,VMX_EPT_EXECUTABLE_MASK , -cpu_has_vmx_ept_execute_only () ?0ull :VMX_EPT_READABLE_MASK , -VMX_EPT_RWX_MASK ,0ull ); +0ull ,VMX_EPT_EXECUTABLE_MASK , p_mask,VMX_EPT_RWX_MASK ,0ull );ept_set_mmio_spte_mask (); }
@@ -8238,6 +8248,8 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .tlb_flush_gva = vmx_flush_tlb_gva, .tlb_flush_guest = vmx_flush_tlb_guest, + .clear_page = clear_page, + .run = vmx_vcpu_run, .handle_exit = vmx_handle_exit, .skip_emulated_instruction = vmx_skip_emulated_instruction,
RFC PATCH 23/34 KVM: x86: mmu: fix: update present_mask in spte_read_protect()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
shadow_present_mask is not 0ull if #VE support is enabled. If #VE support is enabled, shadow_present_mask is updated in vmx_enable_tdp() with VMX_EPT_SUPPRESS_VE_BIT.
--- arch/x86/kvm/mmu/mmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +7 -1
@@ -1601,7 +1601,13 @@ static bool spte_write_protect(u64 *sptep, bool pt_protect)static bool spte_read_protect (u64 *sptep) {u64 spte = *sptep; -bool exec_only_supported = (shadow_present_mask ==0ull ); +bool exec_only_supported; + +if (kvm_ve_supported) + exec_only_supported = + (shadow_present_mask ==VMX_EPT_SUPPRESS_VE_BIT ); +else + exec_only_supported = (shadow_present_mask ==0ull );rmap_printk ("rmap_read_protect: spte %p %llx\n" , sptep, *sptep);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 24/34 KVM: vmx: trigger vm-exits for mmio sptes by default when #VE is enabled
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
All sptes, including mmio sptes must have SVE bit set by default, in
order to trigger vm-exits instead of #VEs (in case of an EPT violation).
MMIO sptes were overlooked in commit 28b8bc704111 ("KVM: VMX: Suppress EPT violation #VE by default (when enabled)") which provided a new mask for non-mmio sptes.
--- arch/x86/kvm/vmx/vmx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +9 -1
@@ -4367,11 +4367,19 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)static void ept_set_mmio_spte_mask (void ) { +u64 mmio_value =VMX_EPT_MISCONFIG_WX_VALUE ; + +/* All sptes, including mmio sptes should trigger vm-exits by +* default, instead of #VE (when supported) +*/ +if (kvm_ve_supported) + mmio_value |=VMX_EPT_SUPPRESS_VE_BIT ; +/* * EPT Misconfigurations can be generated if the value of bits 2:0 * of an EPT paging-structure entry is 110b (write/execute). */ -kvm_mmu_set_mmio_spte_mask (VMX_EPT_MISCONFIG_WX_VALUE ,0 ); +kvm_mmu_set_mmio_spte_mask (mmio_value,0 ); }static int vmx_alloc_eptp_list_page (struct vcpu_vmx *vmx)
RFC PATCH 25/34 KVM: x86: svm: set .clear_page()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
--- arch/x86/kvm/svm/svm.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/svm/svm.c +1 -0
@@ -4324,6 +4324,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .fault_gla = svm_fault_gla, .spt_fault = svm_spt_fault, .gpt_translation_fault = svm_gpt_translation_fault, + .clear_page = clear_page, };static struct kvm_x86_init_ops svm_init_ops__initdata = {
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 26/34 KVM: x86: add .set_ve_info()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This function is needed for the KVMI_VCPU_SET_VE_INFO command.
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx/vmx.c | 40 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -1314,6 +1314,8 @@ struct kvm_x86_ops {u16 (*get_ept_view)(struct kvm_vcpu *vcpu);int (*set_ept_view)(struct kvm_vcpu *vcpu,u16 view);int (*control_ept_view)(struct kvm_vcpu *vcpu,u16 view,u8 visible); +int (*set_ve_info)(struct kvm_vcpu *vcpu,unsigned long ve_info, +bool trigger_vmexit); };struct kvm_x86_nested_ops {
arch/x86/include/asm/vmx.h +1 -0
@@ -157,6 +157,7 @@ static inline int vmx_misc_mseg_revid(u64 vmx_misc)enum vmcs_field {VIRTUAL_PROCESSOR_ID =0x00000000 ,POSTED_INTR_NV =0x00000002 , +EPTP_INDEX =0x00000004 ,GUEST_ES_SELECTOR =0x00000800 ,GUEST_CS_SELECTOR =0x00000802 ,GUEST_SS_SELECTOR =0x00000804 ,
arch/x86/kvm/vmx/vmx.c +40 -0
@@ -4425,6 +4425,45 @@ static int vmx_control_ept_view(struct kvm_vcpu *vcpu, u16 view, u8 visible)return 0 ; } +static int vmx_set_ve_info (struct kvm_vcpu *vcpu,unsigned long ve_info, +bool trigger_vmexit) +{ +struct page *ve_info_pg; +struct vcpu_vmx *vmx =to_vmx (vcpu); +int idx; +u32 eb; + +if (!kvm_ve_supported) +return -KVM_EOPNOTSUPP ; + + idx =srcu_read_lock (&vcpu->kvm->srcu); + ve_info_pg =kvm_vcpu_gpa_to_page (vcpu, ve_info); +srcu_read_unlock (&vcpu->kvm->srcu, idx); + +if (is_error_page (ve_info_pg)) +return -KVM_EINVAL ; + +vmcs_write64 (VE_INFO_ADDRESS ,page_to_phys (ve_info_pg)); + +/* Make sure EPTP_INDEX is up-to-date before enabling #VE */ +vmcs_write16 (EPTP_INDEX , vmx->view); + +/* Enable #VE mechanism */ +secondary_exec_controls_setbit (vmx,SECONDARY_EXEC_EPT_VE ); + +/* Decide if #VE exception should trigger a VM exit */ + eb =vmcs_read32 (EXCEPTION_BITMAP ); + +if (trigger_vmexit) + eb |= (1u <<VE_VECTOR ); +else + eb &= ~(1u <<VE_VECTOR ); + +vmcs_write32 (EXCEPTION_BITMAP , eb); + +return 0 ; +} +#define VMX_XSS_EXIT_BITMAP 0/*
@@ -8350,6 +8389,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .get_ept_view = vmx_get_ept_view, .set_ept_view = vmx_set_ept_view, .control_ept_view = vmx_control_ept_view, + .set_ve_info = vmx_set_ve_info, };static __init int hardware_setup (void )
RFC PATCH 27/34 KVM: x86: add .disable_ve()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This function is needed for the KVMI_VCPU_DISABLE_VE command.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1316,6 +1316,7 @@ struct kvm_x86_ops {int (*control_ept_view)(struct kvm_vcpu *vcpu,u16 view,u8 visible);int (*set_ve_info)(struct kvm_vcpu *vcpu,unsigned long ve_info,bool trigger_vmexit); +int (*disable_ve)(struct kvm_vcpu *vcpu); };struct kvm_x86_nested_ops {
arch/x86/kvm/vmx/vmx.c +10 -0
@@ -4464,6 +4464,15 @@ static int vmx_set_ve_info(struct kvm_vcpu *vcpu, unsigned long ve_info,return 0 ; } +static int vmx_disable_ve (struct kvm_vcpu *vcpu) +{ +if (kvm_ve_supported) +secondary_exec_controls_clearbit (to_vmx (vcpu), +SECONDARY_EXEC_EPT_VE ); + +return 0 ; +} +#define VMX_XSS_EXIT_BITMAP 0/*
@@ -8390,6 +8399,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = { .set_ept_view = vmx_set_ept_view, .control_ept_view = vmx_control_ept_view, .set_ve_info = vmx_set_ve_info, + .disable_ve = vmx_disable_ve, };static __init int hardware_setup (void )
RFC PATCH 28/34 KVM: x86: page_track: add support for suppress #VE bit
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
Setting SPTEs from rmaps is not enough because rmaps contain only present SPTEs. If there is no mapping created for the GFN, SPTEs must be configured when they are created. Use the page tracking mechanism in order to configure the SVE bit when a PF occurs. This is similar to how access rights are configured using the page tracking mechanism.
--- arch/x86/include/asm/kvm_page_track.h | 1 + arch/x86/kvm/mmu.h | 2 ++ arch/x86/kvm/mmu/mmu.c | 38 +++++++++++++++++++++++++++ arch/x86/kvm/mmu/page_track.c | 7 +++++ 4 files changed, 48 insertions(+)
arch/x86/include/asm/kvm_page_track.h +1 -0
@@ -7,6 +7,7 @@ enum kvm_page_track_mode {KVM_PAGE_TRACK_PREWRITE ,KVM_PAGE_TRACK_WRITE ,KVM_PAGE_TRACK_PREEXEC , +KVM_PAGE_TRACK_SVE , KVM_PAGE_TRACK_MAX, };
arch/x86/kvm/mmu.h +2 -0
@@ -234,5 +234,7 @@ int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu, gpa_t l2_gpa);int kvm_mmu_post_init_vm (struct kvm *kvm);void kvm_mmu_pre_destroy_vm (struct kvm *kvm); +bool kvm_mmu_set_ept_page_sve (struct kvm *kvm,struct kvm_memory_slot *slot, +gfn_t gfn,u16 index,bool suppress);#endif
arch/x86/kvm/mmu/mmu.c +38 -0
@@ -1890,6 +1890,41 @@ bool kvm_mmu_slot_gfn_exec_protect(struct kvm *kvm,return exec_protected; } +static bool spte_suppress_ve (u64 *sptep,bool suppress) +{ +u64 spte = *sptep; + +if (suppress) + spte |=VMX_EPT_SUPPRESS_VE_BIT ; +else + spte &= ~VMX_EPT_SUPPRESS_VE_BIT ; + +return mmu_spte_update (sptep, spte); +} + +bool kvm_mmu_set_ept_page_sve (struct kvm *kvm,struct kvm_memory_slot *slot, +gfn_t gfn,u16 index,bool suppress) +{ +struct kvm_rmap_head *rmap_head; +struct rmap_iterator iter; +struct kvm_mmu_page *sp; +bool flush = false; +u64 *sptep; +int i; + +for (i =PG_LEVEL_4K ; i <=KVM_MAX_HUGEPAGE_LEVEL ; i++) { + rmap_head =__gfn_to_rmap (gfn, i, slot); +for_each_rmap_spte (rmap_head, &iter, sptep) { + sp =page_header (__pa (sptep)); +if (index ==0 || (index >0 && index == sp->view)) + flush |=spte_suppress_ve (sptep, suppress); + } + } + +return flush; +} +EXPORT_SYMBOL_GPL (kvm_mmu_set_ept_page_sve); +static bool rmap_write_protect (struct kvm_vcpu *vcpu,u64 gfn) {struct kvm_memory_slot *slot;
@@ -3171,6 +3206,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep, spte |= (u64 )pfn <<PAGE_SHIFT ; +if (kvm_page_track_is_active (vcpu, gfn,KVM_PAGE_TRACK_SVE )) + spte &= ~VMX_EPT_SUPPRESS_VE_BIT ; +if (pte_access &ACC_WRITE_MASK ) { spte |=PT_WRITABLE_MASK |SPTE_MMU_WRITEABLE ;
arch/x86/kvm/mmu/page_track.c +7 -0
@@ -125,6 +125,9 @@ void kvm_slot_page_track_add_page(struct kvm *kvm, }else if (mode ==KVM_PAGE_TRACK_PREEXEC ) {if (kvm_mmu_slot_gfn_exec_protect (kvm, slot, gfn, view))kvm_flush_remote_tlbs (kvm); + }else if (mode ==KVM_PAGE_TRACK_SVE ) { +if (kvm_mmu_set_ept_page_sve (kvm, slot, gfn, view, false)) +kvm_flush_remote_tlbs (kvm); } }EXPORT_SYMBOL_GPL (kvm_slot_page_track_add_page);
@@ -151,6 +154,10 @@ void kvm_slot_page_track_remove_page(struct kvm *kvm,update_gfn_track (slot, gfn, mode,-1 , view); +if (mode ==KVM_PAGE_TRACK_SVE ) +if (kvm_mmu_set_ept_page_sve (kvm, slot, gfn, view, true)) +kvm_flush_remote_tlbs (kvm); +/* * allow large page mapping for the tracked page * after the tracker is gone.
RFC PATCH 29/34 KVM: vmx: make use of EPTP_INDEX in vmx_handle_exit()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
If the guest has EPTP switching capabilities with VMFUNC, read the current view from VMCS instead of walking through the EPTP list when #VE support is active.
--- arch/x86/kvm/vmx/vmx.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
arch/x86/kvm/vmx/vmx.c +14 -8
@@ -6269,15 +6269,21 @@ void dump_vmcs(void)static unsigned int update_ept_view (struct vcpu_vmx *vmx) { -u64 *eptp_list =phys_to_virt (page_to_phys (vmx->eptp_list_pg)); -u64 eptp =vmcs_read64 (EPT_POINTER ); -unsigned int view; +/* if #VE support is active, read the EPT index from VMCS */ +if (kvm_ve_supported && +secondary_exec_controls_get (vmx) &SECONDARY_EXEC_EPT_VE ) { + vmx->view =vmcs_read16 (EPTP_INDEX ); + }else { +u64 *eptp_list =phys_to_virt (page_to_phys (vmx->eptp_list_pg)); +u64 eptp =vmcs_read64 (EPT_POINTER ); +unsigned int view; -for (view =0 ; view <KVM_MAX_EPT_VIEWS ; view++) -if (eptp_list[view] == eptp) { - vmx->view = view; -break ; - } +for (view =0 ; view <KVM_MAX_EPT_VIEWS ; view++) +if (eptp_list[view] == eptp) { + vmx->view = view; +break ; + } + }return vmx->view; }
RFC PATCH 30/34 KVM: vmx: make use of EPTP_INDEX in vmx_set_ept_view()
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
--- arch/x86/kvm/vmx/vmx.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/x86/kvm/vmx/vmx.c +7 -0
@@ -4408,6 +4408,13 @@ static int vmx_set_ept_view(struct kvm_vcpu *vcpu, u16 view)kvm_mmu_unload (vcpu); r =kvm_mmu_reload (vcpu);WARN_ON_ONCE (r); + +/* When #VE happens, current EPT index will be saved +* by the logical processor into VE information area, +* see chapter 24.6.18 and 25.5.6.2 from Intel SDM. +*/ +if (kvm_ve_supported) +vmcs_write16 (EPTP_INDEX , view); }return 0 ;
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RFC PATCH 31/34 KVM: introspection: add #VE host capability checker
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
Add one more field to struct kvmi_features in order to publish #VE capabilities on the host as indicated by kvm_ve_supported flag.
--- Documentation/virt/kvm/kvmi.rst | 5 +++-- arch/x86/include/uapi/asm/kvmi.h | 3 ++- arch/x86/kvm/kvmi.c | 1 + tools/testing/selftests/kvm/x86_64/kvmi_test.c | 1 + 4 files changed, 7 insertions(+), 3 deletions(-)
Documentation/virt/kvm/kvmi.rst +3 -2
@@ -265,11 +265,12 @@ For x86 __u8 singlestep; __u8 vmfunc; __u8 eptp; - __u8 padding[5]; + __u8 ve; + __u8 padding[4]; }; Returns the introspection API version and some of the features supported -by the hardware (eg. alternate EPT views). +by the hardware (eg. alternate EPT views, virtualization exception). This command is always allowed and successful.
arch/x86/include/uapi/asm/kvmi.h +2 -1
@@ -151,7 +151,8 @@ struct kvmi_features {__u8 singlestep;__u8 vmfunc;__u8 eptp; -__u8 padding[5 ]; +__u8 ve; +__u8 padding[4 ]; };struct kvmi_vcpu_get_ept_view_reply {
arch/x86/kvm/kvmi.c +1 -0
@@ -1383,6 +1383,7 @@ void kvmi_arch_features(struct kvmi_features *feat) kvm_x86_ops.get_vmfunc_status (); feat->eptp = kvm_x86_ops.get_eptp_switching_status && kvm_x86_ops.get_eptp_switching_status (); + feat->ve = kvm_ve_supported; }bool kvmi_arch_start_singlestep (struct kvm_vcpu *vcpu)
tools/testing/selftests/kvm/x86_64/kvmi_test.c +1 -0
@@ -459,6 +459,7 @@ static void test_cmd_get_version(void)pr_info ("\tsinglestep: %u\n" , features.singlestep);pr_info ("\tvmfunc: %u\n" , features.vmfunc);pr_info ("\teptp: %u\n" , features.eptp); +pr_info ("\tve: %u\n" , features.ve); }static void cmd_vm_check_command (__u16 id,__u16 padding,int expected_err)
RFC PATCH 32/34 KVM: introspection: add KVMI_VCPU_SET_VE_INFO/KVMI_VCPU_DISABLE_VE
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
The introspection tool can use #VE to reduce the number of VM-exits caused by SPT violations for some guests.
--- Documentation/virt/kvm/kvmi.rst | 63 +++++++++++++++++++ arch/x86/include/uapi/asm/kvmi.h | 8 +++ arch/x86/kvm/kvmi.c | 19 ++++++ include/uapi/linux/kvmi.h | 2 + .../testing/selftests/kvm/x86_64/kvmi_test.c | 52 +++++++++++++++ virt/kvm/introspection/kvmi_int.h | 3 + virt/kvm/introspection/kvmi_msg.c | 30 +++++++++ 7 files changed, 177 insertions(+)
Documentation/virt/kvm/kvmi.rst +63 -0
@@ -1230,6 +1230,69 @@ is terminated. * -KVM_EINVAL - padding is not zero * -KVM_EINVAL - the selected EPT view is not valid +29. KVMI_VCPU_SET_VE_INFO +------------------------- + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vcpu_hdr; + struct kvmi_vcpu_set_ve_info { + __u64 gpa; + __u8 trigger_vmexit; + __u8 padding1; + __u16 padding2; + __u32 padding3; + }; + +:Returns: + +:: + + struct kvmi_error_code; + +Configures the guest physical address for the #VE info page and enables +the #VE mechanism. If ``trigger_vmexit`` is true, any virtualization +exception will trigger a vm-exit. Otherwise, the exception is delivered +using gate descriptor 20 from the Interrupt Descriptor Table (IDT). + +:Errors: + +* -KVM_EINVAL - the selected vCPU is invalid +* -KVM_EINVAL - one of the specified GPAs is invalid +* -KVM_EOPNOTSUPP - the hardware does not support #VE +* -KVM_EINVAL - padding is not zero +* -KVM_EAGAIN - the selected vCPU can't be introspected yet + +30. KVMI_VCPU_DISABLE_VE +------------------------ + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vcpu_hdr; + +:Returns: + +:: + + struct kvmi_error_code; + +Disables the #VE mechanism. All EPT violations will trigger a vm-exit, +regardless of the corresponding spte 63rd bit (SVE) for the GPA that +triggered the EPT violation within a specific EPT view. + +:Errors: + +* -KVM_EINVAL - the selected vCPU is invalid +* -KVM_EAGAIN - the selected vCPU can't be introspected yet + Events ======
arch/x86/include/uapi/asm/kvmi.h +8 -0
@@ -174,4 +174,12 @@ struct kvmi_vcpu_control_ept_view { __u32 padding2; }; +struct kvmi_vcpu_set_ve_info { +__u64 gpa; +__u8 trigger_vmexit; +__u8 padding1; +__u16 padding2; +__u32 padding3; +}; +#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +19 -0
@@ -1464,3 +1464,22 @@ int kvmi_arch_cmd_control_ept_view(struct kvm_vcpu *vcpu, u16 view,return kvm_x86_ops.control_ept_view (vcpu, view, visible); } + +int kvmi_arch_cmd_set_ve_info (struct kvm_vcpu *vcpu,u64 gpa, +bool trigger_vmexit) +{ +unsigned long ve_info = (unsigned long ) gpa; + +if (!kvm_x86_ops.set_ve_info) +return -KVM_EINVAL ; + +return kvm_x86_ops.set_ve_info (vcpu, ve_info, trigger_vmexit); +} + +int kvmi_arch_cmd_disable_ve (struct kvm_vcpu *vcpu) +{ +if (!kvm_x86_ops.disable_ve) +return 0 ; + +return kvm_x86_ops.disable_ve (vcpu); +}
include/uapi/linux/kvmi.h +2 -0
@@ -52,6 +52,8 @@ enum {KVMI_VCPU_GET_EPT_VIEW =26 ,KVMI_VCPU_SET_EPT_VIEW =27 ,KVMI_VCPU_CONTROL_EPT_VIEW =28 , +KVMI_VCPU_SET_VE_INFO =29 , +KVMI_VCPU_DISABLE_VE =30 , KVMI_NUM_MESSAGES };
tools/testing/selftests/kvm/x86_64/kvmi_test.c +52 -0
76 lines not on this page · raw message
virt/kvm/introspection/kvmi_int.h +3 -0
@@ -151,5 +151,8 @@ u16 kvmi_arch_cmd_get_ept_view(struct kvm_vcpu *vcpu);int kvmi_arch_cmd_set_ept_view (struct kvm_vcpu *vcpu,u16 view);int kvmi_arch_cmd_control_ept_view (struct kvm_vcpu *vcpu,u16 view,bool visible); +int kvmi_arch_cmd_set_ve_info (struct kvm_vcpu *vcpu,u64 gpa, +bool trigger_vmexit); +int kvmi_arch_cmd_disable_ve (struct kvm_vcpu *vcpu);#endif
virt/kvm/introspection/kvmi_msg.c +30 -0
@@ -711,6 +711,34 @@ static int handle_vcpu_control_ept_view(const struct kvmi_vcpu_msg_job *job,return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); } +static int handle_vcpu_set_ve_info (const struct kvmi_vcpu_msg_job *job, +const struct kvmi_msg_hdr *msg, +const void *_req) +{ +const struct kvmi_vcpu_set_ve_info *req = _req; +bool trigger_vmexit = !!req->trigger_vmexit; +int ec; + +if (req->padding1 || req->padding2 || req->padding3) + ec = -KVM_EINVAL ; +else + ec =kvmi_arch_cmd_set_ve_info (job->vcpu, req->gpa, + trigger_vmexit); + +return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); +} + +static int handle_vcpu_disable_ve (const struct kvmi_vcpu_msg_job *job, +const struct kvmi_msg_hdr *msg, +const void *req) +{ +int ec; + + ec =kvmi_arch_cmd_disable_ve (job->vcpu); + +return kvmi_msg_vcpu_reply (job, msg, ec,NULL ,0 ); +} +/* * These functions are executed from the vCPU thread. The receiving thread * passes the messages using a newly allocated 'struct kvmi_vcpu_msg_job'
@@ -725,6 +753,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_msg_job *, [KVMI_VCPU_CONTROL_EVENTS] = handle_vcpu_control_events, [KVMI_VCPU_CONTROL_MSR] = handle_vcpu_control_msr, [KVMI_VCPU_CONTROL_SINGLESTEP] = handle_vcpu_control_singlestep, + [KVMI_VCPU_DISABLE_VE] = handle_vcpu_disable_ve, [KVMI_VCPU_GET_CPUID] = handle_vcpu_get_cpuid, [KVMI_VCPU_GET_EPT_VIEW] = handle_vcpu_get_ept_view, [KVMI_VCPU_GET_INFO] = handle_vcpu_get_info,
@@ -736,6 +765,7 @@ static int(*const msg_vcpu[])(const struct kvmi_vcpu_msg_job *, [KVMI_VCPU_SET_EPT_VIEW] = handle_vcpu_set_ept_view, [KVMI_VCPU_SET_REGISTERS] = handle_vcpu_set_registers, [KVMI_VCPU_SET_XSAVE] = handle_vcpu_set_xsave, + [KVMI_VCPU_SET_VE_INFO] = handle_vcpu_set_ve_info, [KVMI_VCPU_TRANSLATE_GVA] = handle_vcpu_translate_gva, };
RFC PATCH 33/34 KVM: introspection: mask out non-rwx flags when reading/writing from/to the internal database
In reply to Adalbert LazărThis is needed because the KVMI_VM_SET_PAGE_SVE command we will use the same database to keep the suppress #VE bit requested by the introspection tool.
--- virt/kvm/introspection/kvmi.c | 36 ++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
virt/kvm/introspection/kvmi.c +25 -11
@@ -23,9 +23,12 @@ static struct kmem_cache *msg_cache;static struct kmem_cache *job_cache;static struct kmem_cache *radix_cache; -static const u8 full_access =KVMI_PAGE_ACCESS_R | -KVMI_PAGE_ACCESS_W | -KVMI_PAGE_ACCESS_X ; +static const u8 rwx_access =KVMI_PAGE_ACCESS_R | +KVMI_PAGE_ACCESS_W | +KVMI_PAGE_ACCESS_X ; +static const u8 full_access =KVMI_PAGE_ACCESS_R | +KVMI_PAGE_ACCESS_W | +KVMI_PAGE_ACCESS_X ;void *kvmi_msg_alloc (void ) {
@@ -1100,7 +1103,7 @@ static void kvmi_insert_mem_access(struct kvm *kvm, struct kvmi_mem_access *m, }static void kvmi_set_mem_access (struct kvm *kvm,struct kvmi_mem_access *m, -u16 view,bool *used) +u8 mask,u16 view,bool *used) {struct kvm_introspection *kvmi =KVMI (kvm);struct kvmi_mem_access *found;
@@ -1112,11 +1115,14 @@ static void kvmi_set_mem_access(struct kvm *kvm, struct kvmi_mem_access *m, found =__kvmi_get_gfn_access (kvmi, m->gfn, view);if (found) { - found->access = m->access; + found->access = (m->access & mask) | (found->access & ~mask);kvmi_update_mem_access (kvm, found, view); - }else if (m->access != full_access) { -kvmi_insert_mem_access (kvm, m, view); - *used = true; + }else { + m->access |= full_access & ~mask; +if (m->access != full_access) { +kvmi_insert_mem_access (kvm, m, view); + *used = true; + } }write_unlock (&kvmi->access_tree_lock);
@@ -1141,7 +1147,7 @@ static int kvmi_set_gfn_access(struct kvm *kvm, gfn_t gfn, u8 access,if (radix_tree_preload (GFP_KERNEL )) err = -KVM_ENOMEM ;else -kvmi_set_mem_access (kvm, m, view, &used); +kvmi_set_mem_access (kvm, m, rwx_access, view, &used);radix_tree_preload_end ();
@@ -1216,14 +1222,22 @@ static int kvmi_get_gfn_access(struct kvm_introspection *kvmi, const gfn_t gfn, u8 *access, u16 view) {struct kvmi_mem_access *m; +u8 allowed = rwx_access; +bool restricted;read_lock (&kvmi->access_tree_lock); m =__kvmi_get_gfn_access (kvmi, gfn, view);if (m) - *access = m->access; + allowed = m->access;read_unlock (&kvmi->access_tree_lock); -return m ?0 :-1 ; + restricted = (allowed & rwx_access) != rwx_access; + +if (!restricted) +return -1 ; + + *access = allowed; +return 0 ; } bool kvmi_restricted_page_access(struct kvm_introspection *kvmi, gpa_t gpa,
RFC PATCH 34/34 KVM: introspection: add KVMI_VM_SET_PAGE_SVE
In reply to Adalbert LazărFrom: Ștefan Șicleru <[email protected]>
This command is used by the introspection tool to set/clear the suppress-VE bit for specific guest memory pages.
--- Documentation/virt/kvm/kvmi.rst | 42 +++++++++ arch/x86/include/uapi/asm/kvmi.h | 8 ++ arch/x86/kvm/kvmi.c | 1 + include/uapi/linux/kvmi.h | 3 + .../testing/selftests/kvm/x86_64/kvmi_test.c | 91 ++++++++++++++++++- virt/kvm/introspection/kvmi.c | 29 +++++- virt/kvm/introspection/kvmi_int.h | 1 + virt/kvm/introspection/kvmi_msg.c | 23 +++++ 8 files changed, 196 insertions(+), 2 deletions(-)
Documentation/virt/kvm/kvmi.rst +42 -0
@@ -1293,6 +1293,48 @@ triggered the EPT violation within a specific EPT view. * -KVM_EINVAL - the selected vCPU is invalid * -KVM_EAGAIN - the selected vCPU can't be introspected yet +31. KVMI_VM_SET_PAGE_SVE +------------------------ + +:Architecture: x86 +:Versions: >= 1 +:Parameters: + +:: + + struct kvmi_vm_set_page_sve { + __u16 view; + __u8 suppress; + __u8 padding1; + __u32 padding2; + __u64 gpa; + }; + +:Returns: + +:: + + struct kvmi_error_code; + +Configures the spte 63rd bit (Suppress #VE, SVE) for ``gpa`` on the +provided EPT ``view``. If ``suppress`` field is 1, the SVE bit will be set. +If it is 0, the SVE it will be cleared. + +If the SVE bit is cleared, EPT violations generated by the provided +guest physical address will trigger a #VE instead of a #PF, which is +delivered using gate descriptor 20 in the IDT. + +Before configuring the SVE bit, the introspection tool should use +*KVMI_GET_VERSION* to check if the hardware has support for the #VE +mechanism (see **KVMI_GET_VERSION**). + +:Errors: + +* -KVM_EINVAL - padding is not zero +* -KVM_ENOMEM - not enough memory to add the page tracking structures +* -KVM_EOPNOTSUPP - an EPT view was selected but the hardware doesn't support it +* -KVM_EINVAL - the selected EPT view is not valid + Events ======
arch/x86/include/uapi/asm/kvmi.h +8 -0
@@ -182,4 +182,12 @@ struct kvmi_vcpu_set_ve_info { __u32 padding3; }; +struct kvmi_vm_set_page_sve { +__u16 view; +__u8 suppress; +__u8 padding1; +__u32 padding2; +__u64 gpa; +}; +#endif /* _UAPI_ASM_X86_KVMI_H */
arch/x86/kvm/kvmi.c +1 -0
@@ -1214,6 +1214,7 @@ static const struct { { KVMI_PAGE_ACCESS_R, KVM_PAGE_TRACK_PREREAD }, { KVMI_PAGE_ACCESS_W, KVM_PAGE_TRACK_PREWRITE }, { KVMI_PAGE_ACCESS_X, KVM_PAGE_TRACK_PREEXEC }, + { KVMI_PAGE_SVE, KVM_PAGE_TRACK_SVE }, }; void kvmi_arch_update_page_tracking(struct kvm *kvm,
include/uapi/linux/kvmi.h +3 -0
@@ -55,6 +55,8 @@ enum {KVMI_VCPU_SET_VE_INFO =29 ,KVMI_VCPU_DISABLE_VE =30 , +KVMI_VM_SET_PAGE_SVE =31 , + KVMI_NUM_MESSAGES };
@@ -84,6 +86,7 @@ enum {KVMI_PAGE_ACCESS_R =1 <<0 ,KVMI_PAGE_ACCESS_W =1 <<1 ,KVMI_PAGE_ACCESS_X =1 <<2 , + KVMI_PAGE_SVE = 1 << 3, }; struct kvmi_msg_hdr {
tools/testing/selftests/kvm/x86_64/kvmi_test.c +90 -1
142 lines not on this page · raw message
virt/kvm/introspection/kvmi.c +28 -1
@@ -28,7 +28,7 @@ static const u8 rwx_access = KVMI_PAGE_ACCESS_R |KVMI_PAGE_ACCESS_X ;static const u8 full_access =KVMI_PAGE_ACCESS_R |KVMI_PAGE_ACCESS_W | -KVMI_PAGE_ACCESS_X ; +KVMI_PAGE_ACCESS_X |KVMI_PAGE_SVE ;void *kvmi_msg_alloc (void ) {
@@ -1447,3 +1447,30 @@ bool kvmi_tracked_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)return ret; } + +int kvmi_cmd_set_page_sve (struct kvm *kvm,gpa_t gpa,u16 view,bool suppress) +{ +struct kvmi_mem_access *m; +u8 mask =KVMI_PAGE_SVE ; +bool used = false; +int err =0 ; + + m =kmem_cache_zalloc (radix_cache,GFP_KERNEL ); +if (!m) +return -KVM_ENOMEM ; + + m->gfn =gpa_to_gfn (gpa); + m->access = suppress ?KVMI_PAGE_SVE :0 ; + +if (radix_tree_preload (GFP_KERNEL )) + err = -KVM_ENOMEM ; +else +kvmi_set_mem_access (kvm, m, mask, view, &used); + +radix_tree_preload_end (); + +if (!used) +kmem_cache_free (radix_cache, m); + +return err; +}
virt/kvm/introspection/kvmi_int.h +1 -0
@@ -88,6 +88,7 @@ int kvmi_cmd_vcpu_set_registers(struct kvm_vcpu *vcpu,int kvmi_cmd_set_page_access (struct kvm_introspection *kvmi,const struct kvmi_msg_hdr *msg,const struct kvmi_vm_set_page_access *req); +int kvmi_cmd_set_page_sve (struct kvm *kvm,gpa_t gpa,u16 view,bool suppress);bool kvmi_restricted_page_access (struct kvm_introspection *kvmi,gpa_t gpa,u8 access,u16 view);bool kvmi_pf_event (struct kvm_vcpu *vcpu,gpa_t gpa,gva_t gva,u8 access);
virt/kvm/introspection/kvmi_msg.c +23 -0
@@ -347,6 +347,28 @@ static int handle_vm_set_page_access(struct kvm_introspection *kvmi,return kvmi_msg_vm_reply (kvmi, msg, ec,NULL ,0 ); } +static int handle_vm_set_page_sve (struct kvm_introspection *kvmi, +const struct kvmi_msg_hdr *msg, +const void *_req) +{ +const struct kvmi_vm_set_page_sve *req = _req; +int ec; + +if (!is_valid_view (req->view)) + ec = -KVM_EINVAL ; +else if (req->suppress >1 ) + ec = -KVM_EINVAL ; +else if (req->padding1 || req->padding2) + ec = -KVM_EINVAL ; +else if (req->view !=0 && !kvm_eptp_switching_supported) + ec = -KVM_EOPNOTSUPP ; +else + ec =kvmi_cmd_set_page_sve (kvmi->kvm, req->gpa, req->view, + req->suppress ==1 ); + +return kvmi_msg_vm_reply (kvmi, msg, ec,NULL ,0 ); +} +/* * These commands are executed by the receiving thread. */
@@ -362,6 +384,7 @@ static int(*const msg_vm[])(struct kvm_introspection *, [KVMI_VM_GET_MAX_GFN] = handle_vm_get_max_gfn, [KVMI_VM_READ_PHYSICAL] = handle_vm_read_physical, [KVMI_VM_SET_PAGE_ACCESS] = handle_vm_set_page_access, + [KVMI_VM_SET_PAGE_SVE] = handle_vm_set_page_sve, [KVMI_VM_WRITE_PHYSICAL] = handle_vm_write_physical, };