My patch queue
Subsystems (7)
cover My patch queue
This is set of various patches that are stuck in my patch queue.
KVM_REQ_GET_NESTED_STATE_PAGES patch is mostly RFC, but it does seem to work for me.
Read-only APIC ID is also somewhat RFC.
Some of these patches are preparation for support for nested AVIC which I almost done developing, and will start testing very soon.
Best regards,
Maxim Levitsky
Maxim Levitsky (30):
KVM: x86: SVM: don't passthrough SMAP/SMEP/PKE bits in !NPT &&
!gCR0.PG case
KVM: x86: nSVM: fix potential NULL derefernce on nested migration
KVM: x86: nSVM: mark vmcb01 as dirty when restoring SMM saved state
KVM: x86: nSVM/nVMX: set nested_run_pending on VM entry which is a
result of RSM
KVM: x86: nSVM: expose clean bit support to the guest
KVM: x86: mark syntethic SMM vmexit as SVM_EXIT_SW
KVM: x86: nSVM: deal with L1 hypervisor that intercepts interrupts but
lets L2 control them
KVM: x86: lapic: don't touch irr_pending in kvm_apic_update_apicv when
inhibiting it
KVM: x86: SVM: move avic definitions from AMD's spec to svm.h
KVM: x86: SVM: fix race between interrupt delivery and AVIC inhibition
KVM: x86: SVM: use vmcb01 in avic_init_vmcb
KVM: x86: SVM: allow AVIC to co-exist with a nested guest running
KVM: x86: lapic: don't allow to change APIC ID when apic acceleration
is enabled
KVM: x86: lapic: don't allow to change local apic id when using older
x2apic api
KVM: x86: SVM: remove avic's broken code that updated APIC ID
KVM: x86: SVM: allow to force AVIC to be enabled
KVM: x86: mmu: trace kvm_mmu_set_spte after the new SPTE was set
KVM: x86: mmu: add strict mmu mode
KVM: x86: mmu: add gfn_in_memslot helper
KVM: x86: mmu: allow to enable write tracking externally
x86: KVMGT: use kvm_page_track_write_tracking_enable
KVM: x86: nSVM: correctly virtualize LBR msrs when L2 is running
KVM: x86: nSVM: implement nested LBR virtualization
KVM: x86: nSVM: implement nested VMLOAD/VMSAVE
KVM: x86: nSVM: support PAUSE filter threshold and count when
cpu_pm=on
KVM: x86: nSVM: implement nested vGIF
KVM: x86: add force_intercept_exceptions_mask
KVM: SVM: implement force_intercept_exceptions_mask
KVM: VMX: implement force_intercept_exceptions_mask
KVM: x86: get rid of KVM_REQ_GET_NESTED_STATE_PAGES
arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 24 +- arch/x86/include/asm/kvm_page_track.h | 1 + arch/x86/include/asm/msr-index.h | 1 + arch/x86/include/asm/svm.h | 36 +++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/Kconfig | 3 - arch/x86/kvm/hyperv.c | 4 + arch/x86/kvm/lapic.c | 53 ++-- arch/x86/kvm/mmu.h | 8 +- arch/x86/kvm/mmu/mmu.c | 31 ++- arch/x86/kvm/mmu/page_track.c | 10 +- arch/x86/kvm/svm/avic.c | 135 +++------- arch/x86/kvm/svm/nested.c | 167 +++++++----- arch/x86/kvm/svm/svm.c | 375 ++++++++++++++++++++++---- arch/x86/kvm/svm/svm.h | 60 +++-- arch/x86/kvm/svm/svm_onhyperv.c | 1 + arch/x86/kvm/vmx/nested.c | 107 +++----- arch/x86/kvm/vmx/vmcs.h | 6 + arch/x86/kvm/vmx/vmx.c | 48 +++- arch/x86/kvm/x86.c | 42 ++- arch/x86/kvm/x86.h | 5 + drivers/gpu/drm/i915/Kconfig | 1 - drivers/gpu/drm/i915/gvt/kvmgt.c | 5 + include/linux/kvm_host.h | 10 +- 25 files changed, 764 insertions(+), 371 deletions(-)
Signature · 1 line
2.26.3
PATCH 1/30 KVM: x86: SVM: don't passthrough SMAP/SMEP/PKE bits in !NPT && !gCR0.PG case
When the guest doesn't enable paging, and NPT/EPT is disabled, we use guest't paging CR3's as KVM's shadow paging pointer and we are technically in direct mode as if we were to use NPT/EPT.
In direct mode we create SPTEs with user mode permissions because usually in the direct mode the NPT/EPT doesn't need to restrict access based on guest CPL
(there are MBE/GMET extenstions for that but KVM doesn't use them).
In this special "use guest paging as direct" mode however, and if CR4.SMAP/CR4.SMEP are enabled, that will make the CPU fault on each access and KVM will enter endless loop of page faults.
Since page protection doesn't have any meaning in !PG case, just don't passthrough these bits.
The fix is the same as was done for VMX in commit:
commit 656ec4a4928a ("KVM: VMX: fix SMEP and SMAP without EPT")
This fixes the boot of windows 10 without NPT for good. (Without this patch, BSP boots, but APs were stuck in endless loop of page faults, causing the VM boot with 1 CPU)
--- arch/x86/kvm/svm/svm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +10 -2
@@ -1596,6 +1596,7 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) {struct vcpu_svm *svm =to_svm (vcpu);u64 hcr0 = cr0; +bool old_paging =is_paging (vcpu);#ifdef CONFIG_X86_64 if (vcpu->arch.efer &EFER_LME && !vcpu->arch.guest_state_protected) {
@@ -1612,8 +1613,11 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)#endif vcpu->arch.cr0 = cr0; -if (!npt_enabled) +if (!npt_enabled) { hcr0 |=X86_CR0_PG |X86_CR0_WP ; +if (old_paging !=is_paging (vcpu)) +svm_set_cr4 (vcpu,kvm_read_cr4 (vcpu)); + }/* * re-enable caching here because the QEMU bios
@@ -1657,8 +1661,12 @@ void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)svm_flush_tlb_current (vcpu); vcpu->arch.cr4 = cr4; -if (!npt_enabled) +if (!npt_enabled) { cr4 |=X86_CR4_PAE ; + +if (!is_paging (vcpu)) + cr4 &= ~(X86_CR4_SMEP |X86_CR4_SMAP |X86_CR4_PKE ); + } cr4 |= host_cr4_mce;to_svm (vcpu)->vmcb->save.cr4 = cr4;vmcb_mark_dirty (to_svm (vcpu)->vmcb,VMCB_CR );
Signature · 1 line
2.26.3
PATCH 2/30 KVM: x86: nSVM: fix potential NULL derefernce on nested migration
In reply to Maxim LevitskyTurns out that due to review feedback and/or rebases
I accidentally moved the call to nested_svm_load_cr3 to be too early, before the NPT is enabled, which is very wrong to do.
KVM can't even access guest memory at that point as nested NPT is needed for that, and of course it won't initialize the walk_mmu, which is main issue the patch was addressing.
Fix this for real.
--- arch/x86/kvm/svm/nested.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
arch/x86/kvm/svm/nested.c +14 -12
@@ -1457,18 +1457,6 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, !__nested_vmcb_check_save(vcpu, &save_cached)) goto out_free; -/* -* While the nested guest CR3 is already checked and set by -* KVM_SET_SREGS, it was set when nested state was yet loaded, -* thus MMU might not be initialized correctly. -* Set it again to fix this. -*/ - - ret =nested_svm_load_cr3 (&svm->vcpu, vcpu->arch.cr3, -nested_npt_enabled (svm), false); -if (WARN_ON_ONCE (ret)) - goto out_free; -/* * All checks done, we can enter guest mode. Userspace provides
@@ -1494,6 +1482,20 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,svm_switch_vmcb (svm, &svm->nested.vmcb02);nested_vmcb02_prepare_control (svm); + +/* +* While the nested guest CR3 is already checked and set by +* KVM_SET_SREGS, it was set when nested state was yet loaded, +* thus MMU might not be initialized correctly. +* Set it again to fix this. +*/ + + ret =nested_svm_load_cr3 (&svm->vcpu, vcpu->arch.cr3, +nested_npt_enabled (svm), false); +if (WARN_ON_ONCE (ret)) + goto out_free; + +kvm_make_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu); ret =0 ; out_free:
Signature · 1 line
2.26.3
PATCH 3/30 KVM: x86: nSVM: mark vmcb01 as dirty when restoring SMM saved state
In reply to Maxim LevitskyWhile usually, restoring the smm state makes the KVM enter the nested guest thus a different vmcb (vmcb02 vs vmcb01), KVM should still mark it as dirty, since hardware can in theory cache multiple vmcbs.
Failure to do so, combined with lack of setting the nested_run_pending (which is fixed in the next patch), might make KVM re-enter vmcb01, which was just exited from, with completely different set of guest state registers (SMM vs non SMM) and without proper dirty bits set, which results in the CPU reusing stale IDTR pointer which leads to a guest shutdown on any interrupt.
On the real hardware this usually doesn't happen, but when running nested, L0's KVM does check and honour few dirty bits, causing this issue to happen.
This patch fixes boot of hyperv and SMM enabled windows VM running nested on KVM.
--- arch/x86/kvm/svm/svm.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/svm/svm.c +2 -0
@@ -4267,6 +4267,8 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)* Enter the nested guest now */ +vmcb_mark_all_dirty (svm->vmcb01.ptr); + vmcb12 = map.hva;nested_copy_vmcb_control_to_cache (svm, &vmcb12->control);nested_copy_vmcb_save_to_cache (svm, &vmcb12->save);
Signature · 1 line
2.26.3
PATCH 4/30 KVM: x86: nSVM/nVMX: set nested_run_pending on VM entry which is a result of RSM
In reply to Maxim LevitskyWhile RSM induced VM entries are not full VM entries, they still need to be followed by actual VM entry to complete it, unlike setting the nested state.
This patch fixes boot of hyperv and SMM enabled windows VM running nested on KVM, which fail due to this issue combined with lack of dirty bit setting.
--- arch/x86/kvm/svm/svm.c | 5 +++++ arch/x86/kvm/vmx/vmx.c | 1 + 2 files changed, 6 insertions(+)
arch/x86/kvm/svm/svm.c +5 -0
@@ -4274,6 +4274,11 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)nested_copy_vmcb_save_to_cache (svm, &vmcb12->save); ret =enter_svm_guest_mode (vcpu, vmcb12_gpa, vmcb12, false); +if (ret) + goto unmap_save; + + svm->nested.nested_run_pending =1 ; + unmap_save:kvm_vcpu_unmap (vcpu, &map_save, true); unmap_map:
arch/x86/kvm/vmx/vmx.c +1 -0
@@ -7659,6 +7659,7 @@ static int vmx_leave_smm(struct kvm_vcpu *vcpu, const char *smstate)if (ret)return ret; + vmx->nested.nested_run_pending =1 ; vmx->nested.smm.guest_mode = false; }return 0 ;
Signature · 1 line
2.26.3
PATCH 5/30 KVM: x86: nSVM: expose clean bit support to the guest
In reply to Maxim LevitskyKVM already honours few clean bits thus it makes sense to let the nested guest know about it.
Note that KVM also doesn't check if the hardware supports clean bits, and therefore nested KVM was
already setting clean bits and L0 KVM
was already honouring them.
--- arch/x86/kvm/svm/svm.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kvm/svm/svm.c +1 -0
@@ -4663,6 +4663,7 @@ static __init void svm_set_cpu_caps(void)/* CPUID 0x80000001 and 0x8000000A (SVM features) */ if (nested) {kvm_cpu_cap_set (X86_FEATURE_SVM ); +kvm_cpu_cap_set (X86_FEATURE_VMCBCLEAN );if (nrips)kvm_cpu_cap_set (X86_FEATURE_NRIPS );
Signature · 1 line
2.26.3
PATCH 6/30 KVM: x86: mark syntethic SMM vmexit as SVM_EXIT_SW
In reply to Maxim LevitskyUse a dummy unused vmexit reason to mark the 'VM exit' that is happening when we exit to handle SMM, which is not a real VM exit.
This makes it a bit easier to read the KVM trace, and avoids other potential problems.
--- arch/x86/kvm/svm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/svm.c +1 -1
@@ -4194,7 +4194,7 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, char *smstate) svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP ]; svm->vmcb->save.rip = vcpu->arch.regs[VCPU_REGS_RIP ]; - ret =nested_svm_vmexit (svm); + ret =nested_svm_simple_vmexit (svm,SVM_EXIT_SW );if (ret)return ret;
Signature · 1 line
2.26.3
PATCH 7/30 KVM: x86: nSVM: deal with L1 hypervisor that intercepts interrupts but lets L2 control them
In reply to Maxim LevitskyFix a corner case in which the L1 hypervisor intercepts interrupts (INTERCEPT_INTR) and either doesn't set virtual interrupt masking (V_INTR_MASKING) or enters a nested guest with EFLAGS.IF disabled prior to the entry.
In this case, despite the fact that L1 intercepts the interrupts, KVM still needs to set up an interrupt window to wait before injecting the INTR vmexit.
Currently the KVM instead enters an endless loop of 'req_immediate_exit'.
Exactly the same issue also happens for SMIs and NMI. Fix this as well.
Note that on VMX, this case is impossible as there is only 'vmexit on external interrupts' execution control which either set, in which case both host and guest's EFLAGS.IF
are ignored, or not set, in which case no VMexits are delivered.
--- arch/x86/kvm/svm/svm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
arch/x86/kvm/svm/svm.c +13 -4
@@ -3372,11 +3372,13 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)if (svm->nested.nested_run_pending)return -EBUSY ; +if (svm_nmi_blocked (vcpu)) +return 0 ; +/* An NMI must not be injected into L2 if it's supposed to VM-Exit. */ if (for_injection &&is_guest_mode (vcpu) &&nested_exit_on_nmi (svm))return -EBUSY ; - -return !svm_nmi_blocked (vcpu); +return 1 ; }static bool svm_get_nmi_mask (struct kvm_vcpu *vcpu)
@@ -3428,9 +3430,13 @@ bool svm_interrupt_blocked(struct kvm_vcpu *vcpu)static int svm_interrupt_allowed (struct kvm_vcpu *vcpu,bool for_injection) {struct vcpu_svm *svm =to_svm (vcpu); +if (svm->nested.nested_run_pending)return -EBUSY ; +if (svm_interrupt_blocked (vcpu)) +return 0 ; +/* * An IRQ must not be injected into L2 if it's supposed to VM-Exit, * e.g. if the IRQ arrived asynchronously after checking nested events.
@@ -3438,7 +3444,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool for_injection)if (for_injection &&is_guest_mode (vcpu) &&nested_exit_on_intr (svm))return -EBUSY ; -return !svm_interrupt_blocked (vcpu); +return 1 ; }static void svm_enable_irq_window (struct kvm_vcpu *vcpu)
@@ -4169,11 +4175,14 @@ static int svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection)if (svm->nested.nested_run_pending)return -EBUSY ; +if (svm_smi_blocked (vcpu)) +return 0 ; +/* An SMI must not be injected into L2 if it's supposed to VM-Exit. */ if (for_injection &&is_guest_mode (vcpu) &&nested_exit_on_smi (svm))return -EBUSY ; -return !svm_smi_blocked (vcpu); +return 1 ; }static int svm_enter_smm (struct kvm_vcpu *vcpu,char *smstate)
Signature · 1 line
2.26.3
PATCH 8/30 KVM: x86: lapic: don't touch irr_pending in kvm_apic_update_apicv when inhibiting it
In reply to Maxim Levitskykvm_apic_update_apicv is called when AVIC is still active, thus IRR bits can be set by the CPU after it is called, and don't cause the irr_pending to be set to true.
Also logic in avic_kick_target_vcpu doesn't expect a race with this function so to make it simple, just keep irr_pending set to true and let the next interrupt injection to the guest clear it.
--- arch/x86/kvm/lapic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/lapic.c +6 -1
@@ -2307,7 +2307,12 @@ void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) apic->irr_pending = true; apic->isr_count =1 ; }else { - apic->irr_pending = (apic_search_irr (apic) !=-1 ); +/* +* Don't clear irr_pending, searching the IRR can race with +* updates from the CPU as APICv is still active from hardware's +* perspective. The flag will be cleared as appropriate when +* KVM injects the interrupt. +*/ apic->isr_count =count_vectors (apic->regs +APIC_ISR ); } }
Signature · 1 line
2.26.3
PATCH 9/30 KVM: x86: SVM: move avic definitions from AMD's spec to svm.h
In reply to Maxim Levitskyasm/svm.h is the correct place for all values that are defined in the SVM spec, and that includes AVIC.
Also add some values from the spec that were not defined before and will be soon useful.
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/include/asm/svm.h | 36 ++++++++++++++++++++++++++++++++ arch/x86/kvm/svm/avic.c | 22 +------------------ arch/x86/kvm/svm/svm.h | 11 ---------- 4 files changed, 38 insertions(+), 32 deletions(-)
arch/x86/include/asm/msr-index.h +1 -0
@@ -476,6 +476,7 @@#define MSR_AMD64_ICIBSEXTDCTL 0xc001103c#define MSR_AMD64_IBSOPDATA4 0xc001103d#define MSR_AMD64_IBS_REG_COUNT_MAX 8/* includes MSR_AMD64_IBSBRTARGET */ +#define MSR_AMD64_SVM_AVIC_DOORBELL 0xc001011b#define MSR_AMD64_VM_PAGE_FLUSH 0xc001011e#define MSR_AMD64_SEV_ES_GHCB 0xc0010130#define MSR_AMD64_SEV 0xc0010131
arch/x86/include/asm/svm.h +36 -0
@@ -220,6 +220,42 @@ struct __attribute__ ((__packed__)) vmcb_control_area {#define SVM_NESTED_CTL_SEV_ENABLE BIT(1)#define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2) + +/* AVIC */ +#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) +#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 +#define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) + +#define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK (0xFFULL) +#define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) +#define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) +#define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) +#define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK (0xFF) + +#define AVIC_DOORBELL_PHYSICAL_ID_MASK (0xFF) + +#define AVIC_UNACCEL_ACCESS_WRITE_MASK 1 +#define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0 +#define AVIC_UNACCEL_ACCESS_VECTOR_MASK 0xFFFFFFFF + +enum avic_ipi_failure_cause { +AVIC_IPI_FAILURE_INVALID_INT_TYPE , +AVIC_IPI_FAILURE_TARGET_NOT_RUNNING , +AVIC_IPI_FAILURE_INVALID_TARGET , +AVIC_IPI_FAILURE_INVALID_BACKING_PAGE , +}; + + +/* +* 0xff is broadcast, so the max index allowed for physical APIC ID +* table is 0xfe. APIC IDs above 0xff are reserved. +*/ +#define AVIC_MAX_PHYSICAL_ID_COUNT 0xff + +#define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) +#define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL + +struct vmcb_seg {u16 selector;u16 attrib;
arch/x86/kvm/svm/avic.c +1 -21
@@ -27,20 +27,6 @@#include "irq.h" #include "svm.h" -#define SVM_AVIC_DOORBELL 0xc001011b - -#define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) - -/* -* 0xff is broadcast, so the max index allowed for physical APIC ID -* table is 0xfe. APIC IDs above 0xff are reserved. -*/ -#define AVIC_MAX_PHYSICAL_ID_COUNT 255 - -#define AVIC_UNACCEL_ACCESS_WRITE_MASK 1 -#define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0 -#define AVIC_UNACCEL_ACCESS_VECTOR_MASK 0xFFFFFFFF -/* AVIC GATAG is encoded using VM and VCPU IDs */ #define AVIC_VCPU_ID_BITS 8#define AVIC_VCPU_ID_MASK ((1 << AVIC_VCPU_ID_BITS) - 1)
@@ -73,12 +59,6 @@ struct amd_svm_iommu_ir {void *data;/* Storing pointer to struct amd_ir_data */ }; -enum avic_ipi_failure_cause { -AVIC_IPI_FAILURE_INVALID_INT_TYPE , -AVIC_IPI_FAILURE_TARGET_NOT_RUNNING , -AVIC_IPI_FAILURE_INVALID_TARGET , -AVIC_IPI_FAILURE_INVALID_BACKING_PAGE , -};/* Note: * This function is called from IOMMU driver to notify
@@ -702,7 +682,7 @@ int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)* one is harmless). */ if (cpu !=get_cpu ()) -wrmsrl (SVM_AVIC_DOORBELL ,kvm_cpu_get_apicid (cpu)); +wrmsrl (MSR_AMD64_SVM_AVIC_DOORBELL ,kvm_cpu_get_apicid (cpu));put_cpu (); }else {/*
arch/x86/kvm/svm/svm.h +0 -11
@@ -555,17 +555,6 @@ extern struct kvm_x86_nested_ops svm_nested_ops;/* avic.c */ -#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) -#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 -#define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) - -#define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK (0xFFULL) -#define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) -#define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) -#define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) - -#define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL -int avic_ga_log_notifier (u32 ga_tag);void avic_vm_destroy (struct kvm *kvm);int avic_vm_init (struct kvm *kvm);
Signature · 1 line
2.26.3
PATCH 10/30 KVM: x86: SVM: fix race between interrupt delivery and AVIC inhibition
In reply to Maxim LevitskyIf svm_deliver_avic_intr is called just after the target vcpu's AVIC got inhibited, it might read a stale value of vcpu->arch.apicv_active which can lead to the target vCPU not noticing the interrupt.
To fix this use load-acquire/store-release so that, if the target vCPU is IN_GUEST_MODE, we're guaranteed to see a previous disabling of the AVIC. If AVIC has been disabled in the meanwhile, proceed with the KVM_REQ_EVENT-based delivery.
All this complicated logic is actually exactly how we can handle an incomplete IPI vmexit; the only difference lies in who sets IRR, whether KVM or the processor.
Also incomplete IPI vmexit also has the same races as svm_deliver_avic_intr.
Therefore use the avic_kick_target_vcpu there as well.
--- arch/x86/kvm/svm/avic.c | 73 ++++++++++++++--------------------------- arch/x86/kvm/svm/svm.c | 65 ++++++++++++++++++++++++++++-------- arch/x86/kvm/svm/svm.h | 3 ++ arch/x86/kvm/x86.c | 4 ++- 4 files changed, 82 insertions(+), 63 deletions(-)
arch/x86/kvm/svm/avic.c +25 -48
@@ -269,6 +269,24 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)return 0 ; } + +void avic_ring_doorbell (struct kvm_vcpu *vcpu) +{ +/* +* Note, the vCPU could get migrated to a different pCPU at any +* point, which could result in signalling the wrong/previous +* pCPU. But if that happens the vCPU is guaranteed to do a +* VMRUN (after being migrated) and thus will process pending +* interrupts, i.e. a doorbell is not needed (and the spurious +* one is harmless). +*/ +int cpu =READ_ONCE (vcpu->cpu); + +if (cpu !=get_cpu ()) +wrmsrl (MSR_AMD64_SVM_AVIC_DOORBELL ,kvm_cpu_get_apicid (cpu)); +put_cpu (); +} +static void avic_kick_target_vcpus (struct kvm *kvm,struct kvm_lapic *source,u32 icrl,u32 icrh) {
@@ -284,8 +302,13 @@ static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *source,kvm_for_each_vcpu (i, vcpu, kvm) {if (kvm_apic_match_dest (vcpu, source, icrl &APIC_SHORT_MASK ,GET_APIC_DEST_FIELD (icrh), - icrl &APIC_DEST_MASK )) -kvm_vcpu_wake_up (vcpu); + icrl &APIC_DEST_MASK )) { + vcpu->arch.apic->irr_pending = true; +svm_complete_interrupt_delivery (vcpu, + icrl &APIC_MODE_MASK , + icrl &APIC_INT_LEVELTRIG , + icrl &APIC_VECTOR_MASK ); + } } }
@@ -649,52 +672,6 @@ void avic_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)return ; } -int svm_deliver_avic_intr (struct kvm_vcpu *vcpu,int vec) -{ -if (!vcpu->arch.apicv_active) -return -1 ; - -kvm_lapic_set_irr (vec, vcpu->arch.apic); - -/* -* Pairs with the smp_mb_*() after setting vcpu->guest_mode in -* vcpu_enter_guest() to ensure the write to the vIRR is ordered before -* the read of guest_mode, which guarantees that either VMRUN will see -* and process the new vIRR entry, or that the below code will signal -* the doorbell if the vCPU is already running in the guest. -*/ -smp_mb__after_atomic (); - -/* -* Signal the doorbell to tell hardware to inject the IRQ if the vCPU -* is in the guest. If the vCPU is not in the guest, hardware will -* automatically process AVIC interrupts at VMRUN. -*/ -if (vcpu->mode ==IN_GUEST_MODE ) { -int cpu =READ_ONCE (vcpu->cpu); - -/* -* Note, the vCPU could get migrated to a different pCPU at any -* point, which could result in signalling the wrong/previous -* pCPU. But if that happens the vCPU is guaranteed to do a -* VMRUN (after being migrated) and thus will process pending -* interrupts, i.e. a doorbell is not needed (and the spurious -* one is harmless). -*/ -if (cpu !=get_cpu ()) -wrmsrl (MSR_AMD64_SVM_AVIC_DOORBELL ,kvm_cpu_get_apicid (cpu)); -put_cpu (); - }else { -/* -* Wake the vCPU if it was blocking. KVM will then detect the -* pending IRQ when checking if the vCPU has a wake event. -*/ -kvm_vcpu_wake_up (vcpu); - } - -return 0 ; -} -bool avic_dy_apicv_has_pending_interrupt (struct kvm_vcpu *vcpu) {return false;
arch/x86/kvm/svm/svm.c +51 -14
77 lines not on this page · raw message
arch/x86/kvm/svm/svm.h +3 -0
@@ -488,6 +488,8 @@ void svm_set_gif(struct vcpu_svm *svm, bool value);int svm_invoke_exit_handler (struct kvm_vcpu *vcpu,u64 exit_code);void set_msr_interception (struct kvm_vcpu *vcpu,u32 *msrpm,u32 msr,int read,int write); +void svm_complete_interrupt_delivery (struct kvm_vcpu *vcpu,int delivery_mode, +int trig_mode,int vec);/* nested.c */
@@ -577,6 +579,7 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, bool set);void avic_vcpu_blocking (struct kvm_vcpu *vcpu);void avic_vcpu_unblocking (struct kvm_vcpu *vcpu); +void avic_ring_doorbell (struct kvm_vcpu *vcpu);/* sev.c */
arch/x86/kvm/x86.c +3 -1
@@ -10039,7 +10039,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)* result in virtual interrupt delivery. */ local_irq_disable (); - vcpu->mode =IN_GUEST_MODE ; + +/* Store vcpu->apicv_active before vcpu->mode. */ +smp_store_release (&vcpu->mode,IN_GUEST_MODE );srcu_read_unlock (&vcpu->kvm->srcu, vcpu->srcu_idx);
Signature · 1 line
2.26.3
PATCH 11/30 KVM: x86: SVM: use vmcb01 in avic_init_vmcb
In reply to Maxim LevitskyOut of precation use vmcb01 when enabling host AVIC.
No functional change intended.
--- arch/x86/kvm/svm/avic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/avic.c +1 -1
@@ -167,7 +167,7 @@ int avic_vm_init(struct kvm *kvm)void avic_init_vmcb (struct vcpu_svm *svm) { -struct vmcb *vmcb = svm->vmcb; +struct vmcb *vmcb = svm->vmcb01.ptr;struct kvm_svm *kvm_svm =to_kvm_svm (svm->vcpu.kvm);phys_addr_t bpa =__sme_set (page_to_phys (svm->avic_backing_page));phys_addr_t lpa =__sme_set (page_to_phys (kvm_svm->avic_logical_id_table_page));
Signature · 1 line
2.26.3
PATCH 12/30 KVM: x86: SVM: allow AVIC to co-exist with a nested guest running
In reply to Maxim LevitskyInhibit the AVIC of the vCPU that is running nested for the duration of the nested run, so that all interrupts arriving from both its vCPU siblings and from KVM are delivered using normal IPIs and cause that vCPU to vmexit.
Note that unlike normal AVIC inhibition, there is no need to update the AVIC mmio memslot, because the nested guest uses its own set of paging tables.
That also means that AVIC doesn't need to be inhibited VM wide.
Note that in the theory when a nested guest doesn't intercept physical interrupts, we could continue using AVIC to deliver them to it but don't bother doing so for now. Plus when nested AVIC is implemented, the nested guest will likely use it, which will not allow this optimization to be used
(can't use real AVIC to support both L1 and L2 at the same time)
--- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 8 +++++++- arch/x86/kvm/svm/avic.c | 7 ++++++- arch/x86/kvm/svm/nested.c | 15 ++++++++++----- arch/x86/kvm/svm/svm.c | 31 +++++++++++++++++++----------- arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/x86.c | 18 +++++++++++++++-- 7 files changed, 61 insertions(+), 20 deletions(-)
arch/x86/include/asm/kvm-x86-ops.h +1 -0
@@ -125,6 +125,7 @@ KVM_X86_OP_NULL(migrate_timers) KVM_X86_OP(msr_filter_changed) KVM_X86_OP_NULL(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) +KVM_X86_OP_NULL(vcpu_has_apicv_inhibit_condition);#undef KVM_X86_OP#undef KVM_X86_OP_NULL
arch/x86/include/asm/kvm_host.h +7 -1
@@ -1039,7 +1039,6 @@ struct kvm_x86_msr_filter {#define APICV_INHIBIT_REASON_DISABLE 0#define APICV_INHIBIT_REASON_HYPERV 1 -#define APICV_INHIBIT_REASON_NESTED 2#define APICV_INHIBIT_REASON_IRQWIN 3#define APICV_INHIBIT_REASON_PIT_REINJ 4#define APICV_INHIBIT_REASON_X2APIC 5
@@ -1494,6 +1493,12 @@ struct kvm_x86_ops {int (*complete_emulated_msr)(struct kvm_vcpu *vcpu,int err);void (*vcpu_deliver_sipi_vector)(struct kvm_vcpu *vcpu,u8 vector); + +/* +* Returns true if for some reason APICv (e.g guest mode) +* must be inhibited on this vCPU +*/ +bool (*vcpu_has_apicv_inhibit_condition)(struct kvm_vcpu *vcpu); };struct kvm_x86_nested_ops {
@@ -1784,6 +1789,7 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,bool kvm_apicv_activated (struct kvm *kvm);void kvm_vcpu_update_apicv (struct kvm_vcpu *vcpu); +bool vcpu_has_apicv_inhibit_condition (struct kvm_vcpu *vcpu);void kvm_request_apicv_update (struct kvm *kvm,bool activate,unsigned long bit);
arch/x86/kvm/svm/avic.c +6 -1
@@ -677,6 +677,12 @@ bool avic_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu)return false; } +bool avic_has_vcpu_inhibit_condition (struct kvm_vcpu *vcpu) +{ +return is_guest_mode (vcpu); +} + +static void svm_ir_list_del (struct vcpu_svm *svm,struct amd_iommu_pi_data *pi) {unsigned long flags;
@@ -888,7 +894,6 @@ bool avic_check_apicv_inhibit_reasons(ulong bit)ulong supported =BIT (APICV_INHIBIT_REASON_DISABLE ) |BIT (APICV_INHIBIT_REASON_ABSENT ) |BIT (APICV_INHIBIT_REASON_HYPERV ) | -BIT (APICV_INHIBIT_REASON_NESTED ) |BIT (APICV_INHIBIT_REASON_IRQWIN ) |BIT (APICV_INHIBIT_REASON_PIT_REINJ ) | BIT(APICV_INHIBIT_REASON_X2APIC) |
arch/x86/kvm/svm/nested.c +10 -5
@@ -551,11 +551,6 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)* exit_int_info, exit_int_info_err, next_rip, insn_len, insn_bytes. */ -/* -* Also covers avic_vapic_bar, avic_backing_page, avic_logical_id, -* avic_physical_id. -*/ -WARN_ON (kvm_apicv_activated (svm->vcpu.kvm));/* Copied from vmcb01. msrpm_base can be overwritten later. */ svm->vmcb->control.nested_ctl = svm->vmcb01.ptr->control.nested_ctl;
@@ -659,6 +654,9 @@ int enter_svm_guest_mode(struct kvm_vcpu *vcpu, u64 vmcb12_gpa,svm_set_gif (svm, true); +if (kvm_vcpu_apicv_active (vcpu)) +kvm_make_request (KVM_REQ_APICV_UPDATE , vcpu); +return 0 ; }
@@ -923,6 +921,13 @@ int nested_svm_vmexit(struct vcpu_svm *svm)if (unlikely (svm->vmcb->save.rflags &X86_EFLAGS_TF ))kvm_queue_exception (&(svm->vcpu),DB_VECTOR ); +/* +* Un-inhibit the AVIC right away, so that other vCPUs can start +* to benefit from VM-exit less IPI right away +*/ +if (kvm_apicv_activated (vcpu->kvm)) +kvm_vcpu_update_apicv (vcpu); +return 0 ; }
arch/x86/kvm/svm/svm.c +20 -11
@@ -1392,7 +1392,8 @@ static void svm_set_vintr(struct vcpu_svm *svm)/* * The following fields are ignored when AVIC is enabled */ -WARN_ON (kvm_apicv_activated (svm->vcpu.kvm)); +if (!is_guest_mode (&svm->vcpu)) +WARN_ON (kvm_apicv_activated (svm->vcpu.kvm));svm_set_intercept (svm,INTERCEPT_VINTR );
@@ -2898,10 +2899,16 @@ static int interrupt_window_interception(struct kvm_vcpu *vcpu)svm_clear_vintr (to_svm (vcpu));/* -* For AVIC, the only reason to end up here is ExtINTs. +* If not running nested, for AVIC, the only reason to end up here is ExtINTs. * In this case AVIC was temporarily disabled for * requesting the IRQ window and we have to re-enable it. +* +* If running nested, still uninhibit the AVIC in case irq window +* was requested when it was not running nested. +* All vCPUs which run nested will have their AVIC still +* inhibited due to AVIC inhibition override for that. */ +kvm_request_apicv_update (vcpu->kvm, true,APICV_INHIBIT_REASON_IRQWIN ); ++vcpu->stat.irq_window_exits;
@@ -3451,8 +3458,16 @@ static void svm_enable_irq_window(struct kvm_vcpu *vcpu)* unless we have pending ExtINT since it cannot be injected * via AVIC. In such case, we need to temporarily disable AVIC, * and fallback to injecting IRQ via V_IRQ. +* +* If running nested, this vCPU will use separate page tables +* which don't have L1's AVIC mapped, and the AVIC is +* already inhibited thus there is no need for global +* AVIC inhibition. */ -kvm_request_apicv_update (vcpu->kvm, false,APICV_INHIBIT_REASON_IRQWIN ); + +if (!is_guest_mode (vcpu)) +kvm_request_apicv_update (vcpu->kvm, false,APICV_INHIBIT_REASON_IRQWIN ); +svm_set_vintr (svm); } }
@@ -3927,14 +3942,6 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)if (guest_cpuid_has (vcpu,X86_FEATURE_X2APIC ))kvm_request_apicv_update (vcpu->kvm, false,APICV_INHIBIT_REASON_X2APIC ); - -/* -* Currently, AVIC does not work with nested virtualization. -* So, we disable AVIC when cpuid for SVM is set in the L1 guest. -*/ -if (nested &&guest_cpuid_has (vcpu,X86_FEATURE_SVM )) -kvm_request_apicv_update (vcpu->kvm, false, -APICV_INHIBIT_REASON_NESTED ); }init_vmcb_after_set_cpuid (vcpu); }
@@ -4657,6 +4664,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .complete_emulated_msr = svm_complete_emulated_msr, .vcpu_deliver_sipi_vector = svm_vcpu_deliver_sipi_vector, + .vcpu_has_apicv_inhibit_condition = avic_has_vcpu_inhibit_condition, };/*
@@ -4840,6 +4848,7 @@ static __init int svm_hardware_setup(void) }else { svm_x86_ops.vcpu_blocking =NULL ; svm_x86_ops.vcpu_unblocking =NULL ; + svm_x86_ops.vcpu_has_apicv_inhibit_condition =NULL ; }if (vls) {
arch/x86/kvm/svm/svm.h +1 -0
@@ -580,6 +580,7 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,void avic_vcpu_blocking (struct kvm_vcpu *vcpu);void avic_vcpu_unblocking (struct kvm_vcpu *vcpu);void avic_ring_doorbell (struct kvm_vcpu *vcpu); +bool avic_has_vcpu_inhibit_condition (struct kvm_vcpu *vcpu);/* sev.c */
arch/x86/kvm/x86.c +16 -2
@@ -9697,6 +9697,14 @@ void kvm_make_scan_ioapic_request(struct kvm *kvm)kvm_make_all_cpus_request (kvm,KVM_REQ_SCAN_IOAPIC ); } +bool vcpu_has_apicv_inhibit_condition (struct kvm_vcpu *vcpu) +{ +if (kvm_x86_ops.vcpu_has_apicv_inhibit_condition) +return static_call (kvm_x86_vcpu_has_apicv_inhibit_condition)(vcpu); +else +return false; +} +void kvm_vcpu_update_apicv (struct kvm_vcpu *vcpu) {bool activate;
@@ -9706,7 +9714,9 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu)down_read (&vcpu->kvm->arch.apicv_update_lock); - activate =kvm_apicv_activated (vcpu->kvm); + activate =kvm_apicv_activated (vcpu->kvm) && + !vcpu_has_apicv_inhibit_condition (vcpu); +if (vcpu->arch.apicv_active == activate) goto out;
@@ -10110,7 +10120,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)* per-VM state, and responsing vCPUs must wait for the update * to complete before servicing KVM_REQ_APICV_UPDATE. */ -WARN_ON_ONCE (kvm_apicv_activated (vcpu->kvm) !=kvm_vcpu_apicv_active (vcpu)); +if (vcpu_has_apicv_inhibit_condition (vcpu)) +WARN_ON (kvm_vcpu_apicv_active (vcpu)); +else +WARN_ON_ONCE (kvm_apicv_activated (vcpu->kvm) !=kvm_vcpu_apicv_active (vcpu)); + exit_fastpath =static_call (kvm_x86_vcpu_run)(vcpu);if (likely (exit_fastpath !=EXIT_FASTPATH_REENTER_GUEST ))
Signature · 1 line
2.26.3
PATCH 13/30 KVM: x86: lapic: don't allow to change APIC ID when apic acceleration is enabled
In reply to Maxim LevitskyNo normal guest has any reason to change physical APIC IDs, and allowing this introduces bugs into APIC acceleration code.
--- arch/x86/kvm/lapic.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
arch/x86/kvm/lapic.c +22 -6
@@ -2002,10 +2002,20 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)switch (reg) {case APIC_ID :/* Local APIC ID */ -if (!apic_x2apic_mode (apic)) -kvm_apic_set_xapic_id (apic, val >>24 ); -else +if (apic_x2apic_mode (apic)) { ret =1 ; +break ; + } +/* +* Don't allow setting APIC ID with any APIC acceleration +* enabled to avoid unexpected issues +*/ +if (enable_apicv && ((val >>24 ) != apic->vcpu->vcpu_id)) { +kvm_vm_bugged (apic->vcpu->kvm); +break ; + } + +kvm_apic_set_xapic_id (apic, val >>24 );break ;case APIC_TASKPRI :
@@ -2572,10 +2582,16 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)static int kvm_apic_state_fixup (struct kvm_vcpu *vcpu,struct kvm_lapic_state *s,bool set) { -if (apic_x2apic_mode (vcpu->arch.apic)) { -u32 *id = (u32 *)(s->regs +APIC_ID ); -u32 *ldr = (u32 *)(s->regs +APIC_LDR ); +u32 *id = (u32 *)(s->regs +APIC_ID ); +u32 *ldr = (u32 *)(s->regs +APIC_LDR ); +if (!apic_x2apic_mode (vcpu->arch.apic)) { +/* Don't allow setting APIC ID with any APIC acceleration +* enabled to avoid unexpected issues +*/ +if (enable_apicv && (*id >>24 ) != vcpu->vcpu_id) +return -EINVAL ; + }else {if (vcpu->kvm->arch.x2apic_format) {if (*id != vcpu->vcpu_id)return -EINVAL ;
Signature · 1 line
2.26.3
PATCH 14/30 KVM: x86: lapic: don't allow to change local apic id when using older x2apic api
In reply to Maxim LevitskyKVM allowed to set non boot apic id via setting apic state if using older non x2apic 32 bit apic id userspace api.
--- arch/x86/kvm/lapic.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
arch/x86/kvm/lapic.c +9 -9
@@ -2592,15 +2592,15 @@ static int kvm_apic_state_fixup(struct kvm_vcpu *vcpu,if (enable_apicv && (*id >>24 ) != vcpu->vcpu_id)return -EINVAL ; }else { -if (vcpu->kvm->arch.x2apic_format) { -if (*id != vcpu->vcpu_id) -return -EINVAL ; - }else { -if (set) - *id >>=24 ; -else - *id <<=24 ; - } + +if (!vcpu->kvm->arch.x2apic_format && set) + *id >>=24 ; + +if (*id != vcpu->vcpu_id) +return -EINVAL ; + +if (!vcpu->kvm->arch.x2apic_format && !set) + *id <<=24 ;/* In x2APIC mode, the LDR is fixed and based on the id */ if (set)
Signature · 1 line
2.26.3
PATCH 15/30 KVM: x86: SVM: remove avic's broken code that updated APIC ID
In reply to Maxim LevitskyNow that KVM doesn't allow to change APIC ID in case AVIC is enabled, remove buggy AVIC code that tried to do so.
--- arch/x86/kvm/svm/avic.c | 35 ----------------------------------- 1 file changed, 35 deletions(-)
arch/x86/kvm/svm/avic.c +0 -35
@@ -440,35 +440,6 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)return ret; } -static int avic_handle_apic_id_update (struct kvm_vcpu *vcpu) -{ -u64 *old, *new; -struct vcpu_svm *svm =to_svm (vcpu); -u32 id =kvm_xapic_id (vcpu->arch.apic); - -if (vcpu->vcpu_id == id) -return 0 ; - - old =avic_get_physical_id_entry (vcpu, vcpu->vcpu_id); - new =avic_get_physical_id_entry (vcpu, id); -if (!new || !old) -return 1 ; - -/* We need to move physical_id_entry to new offset */ - *new = *old; - *old =0ULL ; -to_svm (vcpu)->avic_physical_id_cache = new; - -/* -* Also update the guest physical APIC ID in the logical -* APIC ID table entry if already setup the LDR. -*/ -if (svm->ldr_reg) -avic_handle_ldr_update (vcpu); - -return 0 ; -} -static void avic_handle_dfr_update (struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu);
@@ -488,10 +459,6 @@ static int avic_unaccel_trap_write(struct vcpu_svm *svm)AVIC_UNACCEL_ACCESS_OFFSET_MASK ;switch (offset) { -case APIC_ID : -if (avic_handle_apic_id_update (&svm->vcpu)) -return 0 ; -break ;case APIC_LDR :if (avic_handle_ldr_update (&svm->vcpu))return 0 ;
@@ -584,8 +551,6 @@ int avic_init_vcpu(struct vcpu_svm *svm)void avic_apicv_post_state_restore (struct kvm_vcpu *vcpu) { -if (avic_handle_apic_id_update (vcpu) !=0 ) -return ;avic_handle_dfr_update (vcpu);avic_handle_ldr_update (vcpu); }
Signature · 1 line
2.26.3
PATCH 16/30 KVM: x86: SVM: allow to force AVIC to be enabled
In reply to Maxim LevitskyApparently on some systems AVIC is disabled in CPUID but still usable.
Allow the user to override the CPUID if the user is willing to take the risk.
--- arch/x86/kvm/svm/svm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +9 -2
@@ -202,6 +202,9 @@ module_param(tsc_scaling, int, 0444);static bool avic;module_param (avic, bool,0444 ); +static bool force_avic; +module_param_unsafe (force_avic, bool,0444 ); +bool __read_mostly dump_invalid_vmcb;module_param (dump_invalid_vmcb, bool,0644 );
@@ -4839,10 +4842,14 @@ static __init int svm_hardware_setup(void) nrips = false; } - enable_apicv = avic = avic && npt_enabled &&boot_cpu_has (X86_FEATURE_AVIC ); + enable_apicv = avic = avic && npt_enabled && (boot_cpu_has (X86_FEATURE_AVIC ) || force_avic);if (enable_apicv) { -pr_info ("AVIC enabled\n" ); +if (!boot_cpu_has (X86_FEATURE_AVIC )) { +pr_warn ("AVIC is not supported in CPUID but force enabled" ); +pr_warn ("Your system might crash and burn" ); + }else +pr_info ("AVIC enabled\n" );amd_iommu_register_ga_log_notifier (&avic_ga_log_notifier); }else {
Signature · 1 line
2.26.3
PATCH 17/30 KVM: x86: mmu: trace kvm_mmu_set_spte after the new SPTE was set
In reply to Maxim LevitskyIt makes more sense to print new SPTE value than the old value.
--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -2708,8 +2708,8 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,if (*sptep == spte) { ret =RET_PF_SPURIOUS ; }else { -trace_kvm_mmu_set_spte (level, gfn, sptep); flush |=mmu_spte_update (sptep, spte); +trace_kvm_mmu_set_spte (level, gfn, sptep); }if (wrprot) {
Signature · 1 line
2.26.3
PATCH 18/30 KVM: x86: mmu: add strict mmu mode
In reply to Maxim LevitskyAdd an (mostly debug) option to force KVM's shadow mmu to never have unsync pages.
This is useful in some cases to debug it.
It is also useful for some legacy guest OSes which don't flush TLBs correctly, and thus don't work on modern CPUs which have speculative MMUs.
Using this option together with legacy paging (npt/ept=0) allows to correctly simulate such old MMU while still getting most of the benefits of the virtualization.
--- arch/x86/kvm/mmu/mmu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +11 -2
@@ -91,6 +91,10 @@ __MODULE_PARM_TYPE(nx_huge_pages_recovery_period_ms, "uint");static bool __read_mostly force_flush_and_sync_on_reuse;module_param_named (flush_on_reuse, force_flush_and_sync_on_reuse, bool,0644 ); + +bool strict_mmu; +module_param (strict_mmu, bool,0644 ); +/* * When setting this variable to true it enables Two-Dimensional-Paging * where the hardware walks 2 page tables:
@@ -2703,7 +2707,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, } wrprot =make_spte (vcpu, sp, slot, pte_access, gfn, pfn, *sptep, prefetch, - true, host_writable, &spte); + !strict_mmu, host_writable, &spte);if (*sptep == spte) { ret =RET_PF_SPURIOUS ;
@@ -5139,6 +5143,11 @@ static u64 mmu_pte_write_fetch_gpte(struct kvm_vcpu *vcpu, gpa_t *gpa,*/ static bool detect_write_flooding (struct kvm_mmu_page *sp) { +/* +* When using non speculating MMU, use a bit higher threshold +* for write flood detection +*/ +int threshold = strict_mmu ?10 :3 ;/* * Skip write-flooding detected for the sp whose level is 1, because * it can become unsync, then the guest page is not write-protected.
@@ -5147,7 +5156,7 @@ static bool detect_write_flooding(struct kvm_mmu_page *sp)return false;atomic_inc (&sp->write_flooding_count); -return atomic_read (&sp->write_flooding_count) >=3 ; +return atomic_read (&sp->write_flooding_count) >= threshold; }/*
Signature · 1 line
2.26.3
PATCH 19/30 KVM: x86: mmu: add gfn_in_memslot helper
In reply to Maxim LevitskyThis is a tiny refactoring, and can be useful to check if a GPA/GFN is within a memslot a bit more cleanly.
--- include/linux/kvm_host.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
include/linux/kvm_host.h +9 -1
@@ -1564,6 +1564,13 @@ int kvm_request_irq_source_id(struct kvm *kvm);void kvm_free_irq_source_id (struct kvm *kvm,int irq_source_id);bool kvm_arch_irqfd_allowed (struct kvm *kvm,struct kvm_irqfd *args); + +static inline bool gfn_in_memslot (struct kvm_memory_slot *slot,gfn_t gfn) +{ +return (gfn >= slot->base_gfn && gfn < slot->base_gfn + slot->npages); +} + +/* * Returns a pointer to the memslot if it contains gfn. * Otherwise returns NULL.
@@ -1574,12 +1581,13 @@ try_get_memslot(struct kvm_memory_slot *slot, gfn_t gfn)if (!slot)return NULL ; -if (gfn >= slot->base_gfn && gfn < slot->base_gfn + slot->npages) +if (gfn_in_memslot (slot, gfn))return slot;else return NULL ; } +/* * Returns a pointer to the memslot that contains gfn. Otherwise returns NULL. *
Signature · 1 line
2.26.3
PATCH 20/30 KVM: x86: mmu: allow to enable write tracking externally
In reply to Maxim LevitskyThis will be used to enable write tracking from nested AVIC code and can also be used to enable write tracking in GVT-g module when it actually uses it as opposed to always enabling it, when the module is compiled in the kernel.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/asm/kvm_page_track.h | 1 + arch/x86/kvm/mmu.h | 8 +++++--- arch/x86/kvm/mmu/mmu.c | 16 +++++++++------- arch/x86/kvm/mmu/page_track.c | 10 ++++++++-- 5 files changed, 24 insertions(+), 13 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1225,7 +1225,7 @@ struct kvm_arch {* is used as one input when determining whether certain memslot * related allocations are necessary. */ -bool shadow_root_allocated; +bool mmu_page_tracking_enabled;#if IS_ENABLED (CONFIG_HYPERV )hpa_t hv_root_tdp;
arch/x86/include/asm/kvm_page_track.h +1 -0
@@ -50,6 +50,7 @@ int kvm_page_track_init(struct kvm *kvm);void kvm_page_track_cleanup (struct kvm *kvm);bool kvm_page_track_write_tracking_enabled (struct kvm *kvm); +int kvm_page_track_write_tracking_enable (struct kvm *kvm);int kvm_page_track_write_tracking_alloc (struct kvm_memory_slot *slot);void kvm_page_track_free_memslot (struct kvm_memory_slot *slot);
arch/x86/kvm/mmu.h +5 -3
@@ -267,7 +267,7 @@ int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu);int kvm_mmu_post_init_vm (struct kvm *kvm);void kvm_mmu_pre_destroy_vm (struct kvm *kvm); -static inline bool kvm_shadow_root_allocated (struct kvm *kvm) +static inline bool mmu_page_tracking_enabled (struct kvm *kvm) {/* * Read shadow_root_allocated before related pointers. Hence, threads
@@ -275,9 +275,11 @@ static inline bool kvm_shadow_root_allocated(struct kvm *kvm)* see the pointers. Pairs with smp_store_release in * mmu_first_shadow_root_alloc. */ -return smp_load_acquire (&kvm->arch.shadow_root_allocated); +return smp_load_acquire (&kvm->arch.mmu_page_tracking_enabled); } +int mmu_enable_write_tracking (struct kvm *kvm); +#ifdef CONFIG_X86_64 static inline bool is_tdp_mmu_enabled (struct kvm *kvm) {return kvm->arch.tdp_mmu_enabled; }#else
@@ -286,7 +288,7 @@ static inline bool is_tdp_mmu_enabled(struct kvm *kvm) { return false; }static inline bool kvm_memslots_have_rmaps (struct kvm *kvm) { -return !is_tdp_mmu_enabled (kvm) ||kvm_shadow_root_allocated (kvm); +return !is_tdp_mmu_enabled (kvm) ||mmu_page_tracking_enabled (kvm); }static inline gfn_t gfn_to_index (gfn_t gfn,gfn_t base_gfn,int level)
arch/x86/kvm/mmu/mmu.c +9 -7
@@ -3384,7 +3384,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)return r; } -static int mmu_first_shadow_root_alloc (struct kvm *kvm) +int mmu_enable_write_tracking (struct kvm *kvm) {struct kvm_memslots *slots;struct kvm_memory_slot *slot;
@@ -3394,21 +3394,20 @@ static int mmu_first_shadow_root_alloc(struct kvm *kvm)* Check if this is the first shadow root being allocated before * taking the lock. */ -if (kvm_shadow_root_allocated (kvm)) +if (mmu_page_tracking_enabled (kvm))return 0 ;mutex_lock (&kvm->slots_arch_lock);/* Recheck, under the lock, whether this is the first shadow root. */ -if (kvm_shadow_root_allocated (kvm)) +if (mmu_page_tracking_enabled (kvm)) goto out_unlock;/* * Check if anything actually needs to be allocated, e.g. all metadata * will be allocated upfront if TDP is disabled. */ -if (kvm_memslots_have_rmaps (kvm) && -kvm_page_track_write_tracking_enabled (kvm)) +if (kvm_memslots_have_rmaps (kvm) &&mmu_page_tracking_enabled (kvm)) goto out_success;for (i =0 ; i <KVM_ADDRESS_SPACE_NUM ; i++) {
@@ -3438,7 +3437,7 @@ static int mmu_first_shadow_root_alloc(struct kvm *kvm)* all the related pointers are set. */ out_success: -smp_store_release (&kvm->arch.shadow_root_allocated, true); +smp_store_release (&kvm->arch.mmu_page_tracking_enabled, true); out_unlock:mutex_unlock (&kvm->slots_arch_lock);
@@ -3475,7 +3474,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) } } - r =mmu_first_shadow_root_alloc (vcpu->kvm); + r =mmu_enable_write_tracking (vcpu->kvm);if (r)return r;
@@ -5712,6 +5711,9 @@ void kvm_mmu_init_vm(struct kvm *kvm) node->track_write = kvm_mmu_pte_write; node->track_flush_slot = kvm_mmu_invalidate_zap_pages_in_memslot;kvm_page_track_register_notifier (kvm, node); + +if (IS_ENABLED (CONFIG_KVM_EXTERNAL_WRITE_TRACKING ) || !tdp_enabled) +mmu_enable_write_tracking (kvm); }void kvm_mmu_uninit_vm (struct kvm *kvm)
arch/x86/kvm/mmu/page_track.c +8 -2
@@ -21,10 +21,16 @@bool kvm_page_track_write_tracking_enabled (struct kvm *kvm) { -return IS_ENABLED (CONFIG_KVM_EXTERNAL_WRITE_TRACKING ) || - !tdp_enabled ||kvm_shadow_root_allocated (kvm); +return mmu_page_tracking_enabled (kvm); } +int kvm_page_track_write_tracking_enable (struct kvm *kvm) +{ +return mmu_enable_write_tracking (kvm); +} +EXPORT_SYMBOL_GPL (kvm_page_track_write_tracking_enable); + +void kvm_page_track_free_memslot (struct kvm_memory_slot *slot) {int i;
Signature · 1 line
2.26.3
PATCH 21/30 x86: KVMGT: use kvm_page_track_write_tracking_enable
In reply to Maxim LevitskyThis allows to enable the write tracking only when KVMGT is actually used and doesn't carry any penalty otherwise.
Tested by booting a VM with a kvmgt mdev device.
--- arch/x86/kvm/Kconfig | 3 --- arch/x86/kvm/mmu/mmu.c | 2 +- drivers/gpu/drm/i915/Kconfig | 1 - drivers/gpu/drm/i915/gvt/kvmgt.c | 5 +++++ 4 files changed, 6 insertions(+), 5 deletions(-)
arch/x86/kvm/Kconfig +0 -3
@@ -132,7 +132,4 @@ config KVM_MMU_AUDIT This option adds a R/W kVM module parameter 'mmu_audit', which allows auditing of KVM MMU events at runtime. -config KVM_EXTERNAL_WRITE_TRACKING - bool - endif # VIRTUALIZATION
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -5712,7 +5712,7 @@ void kvm_mmu_init_vm(struct kvm *kvm) node->track_flush_slot = kvm_mmu_invalidate_zap_pages_in_memslot;kvm_page_track_register_notifier (kvm, node); -if (IS_ENABLED (CONFIG_KVM_EXTERNAL_WRITE_TRACKING ) || !tdp_enabled) +if (!tdp_enabled)mmu_enable_write_tracking (kvm); }
drivers/gpu/drm/i915/Kconfig +0 -1
@@ -126,7 +126,6 @@ config DRM_I915_GVT_KVMGT depends on DRM_I915_GVT depends on KVM depends on VFIO_MDEV - select KVM_EXTERNAL_WRITE_TRACKING default n help Choose this option if you want to enable KVMGT support for
drivers/gpu/drm/i915/gvt/kvmgt.c +5 -0
@@ -1916,6 +1916,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev)struct intel_vgpu *vgpu;struct kvmgt_vdev *vdev;struct kvm *kvm; +int ret; vgpu =mdev_get_drvdata (mdev);if (handle_valid (vgpu->handle))
@@ -1931,6 +1932,10 @@ static int kvmgt_guest_init(struct mdev_device *mdev)if (__kvmgt_vgpu_exist (vgpu, kvm))return -EEXIST ; + ret =kvm_page_track_write_tracking_enable (kvm); +if (ret) +return ret; + info =vzalloc (sizeof (struct kvmgt_guest_info ));if (!info)return -ENOMEM ;
Signature · 1 line
2.26.3
PATCH 22/30 KVM: x86: nSVM: correctly virtualize LBR msrs when L2 is running
In reply to Maxim LevitskyWhen L2 is running without LBR virtualization, we should ensure that L1's LBR msrs continue to update as usual.
--- arch/x86/kvm/svm/nested.c | 11 +++++ arch/x86/kvm/svm/svm.c | 98 +++++++++++++++++++++++++++++++-------- arch/x86/kvm/svm/svm.h | 2 + 3 files changed, 92 insertions(+), 19 deletions(-)
arch/x86/kvm/svm/nested.c +11 -0
@@ -535,6 +535,9 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12 svm->vcpu.arch.dr6 = svm->nested.save.dr6 |DR6_ACTIVE_LOW ;vmcb_mark_dirty (svm->vmcb,VMCB_DR ); } + +if (unlikely (svm->vmcb01.ptr->control.virt_ext &LBR_CTL_ENABLE_MASK )) +svm_copy_lbrs (svm->vmcb01.ptr, svm->vmcb); }static void nested_vmcb02_prepare_control (struct vcpu_svm *svm)
@@ -587,6 +590,9 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) svm->vmcb->control.event_inj = svm->nested.ctl.event_inj; svm->vmcb->control.event_inj_err = svm->nested.ctl.event_inj_err; + svm->vmcb->control.virt_ext = svm->vmcb01.ptr->control.virt_ext & +LBR_CTL_ENABLE_MASK ; +nested_svm_transition_tlb_flush (vcpu);/* Enter Guest-Mode */
@@ -852,6 +858,11 @@ int nested_svm_vmexit(struct vcpu_svm *svm)svm_switch_vmcb (svm, &svm->vmcb01); +if (unlikely (svm->vmcb->control.virt_ext &LBR_CTL_ENABLE_MASK )) { +svm_copy_lbrs (svm->nested.vmcb02.ptr, svm->vmcb); +svm_update_lbrv (vcpu); + } +/* * On vmexit the GIF is set to false and * no event can be injected in L1.
arch/x86/kvm/svm/svm.c +79 -19
134 lines not on this page · raw message
arch/x86/kvm/svm/svm.h +2 -0
@@ -476,6 +476,8 @@ u32 svm_msrpm_offset(u32 msr);u32 *svm_vcpu_alloc_msrpm (void );void svm_vcpu_init_msrpm (struct kvm_vcpu *vcpu,u32 *msrpm);void svm_vcpu_free_msrpm (u32 *msrpm); +void svm_copy_lbrs (struct vmcb *from_vmcb,struct vmcb *to_vmcb); +void svm_update_lbrv (struct kvm_vcpu *vcpu);int svm_set_efer (struct kvm_vcpu *vcpu,u64 efer);void svm_set_cr0 (struct kvm_vcpu *vcpu,unsigned long cr0);
Signature · 1 line
2.26.3
PATCH 23/30 KVM: x86: nSVM: implement nested LBR virtualization
In reply to Maxim LevitskyThis was tested with kvm-unit-test that was developed for this purpose.
--- arch/x86/kvm/svm/nested.c | 21 +++++++++++++++++++-- arch/x86/kvm/svm/svm.c | 8 ++++++++ arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/nested.c +19 -2
@@ -536,8 +536,19 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12vmcb_mark_dirty (svm->vmcb,VMCB_DR ); } -if (unlikely (svm->vmcb01.ptr->control.virt_ext &LBR_CTL_ENABLE_MASK )) +if (unlikely (svm->lbrv_enabled && (svm->nested.ctl.virt_ext &LBR_CTL_ENABLE_MASK ))) { + +/* Copy LBR related registers from vmcb12, +* but make sure that we only pick LBR enable bit from the guest. +*/ + +svm_copy_lbrs (vmcb12, svm->vmcb); + svm->vmcb->save.dbgctl &=LBR_CTL_ENABLE_MASK ; +svm_update_lbrv (&svm->vcpu); + + }else if (unlikely (svm->vmcb01.ptr->control.virt_ext &LBR_CTL_ENABLE_MASK )) {svm_copy_lbrs (svm->vmcb01.ptr, svm->vmcb); + } }static void nested_vmcb02_prepare_control (struct vcpu_svm *svm)
@@ -592,6 +603,9 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) svm->vmcb->control.virt_ext = svm->vmcb01.ptr->control.virt_ext &LBR_CTL_ENABLE_MASK ; +if (svm->lbrv_enabled) + svm->vmcb->control.virt_ext |= + (svm->nested.ctl.virt_ext &LBR_CTL_ENABLE_MASK );nested_svm_transition_tlb_flush (vcpu);
@@ -858,7 +872,10 @@ int nested_svm_vmexit(struct vcpu_svm *svm)svm_switch_vmcb (svm, &svm->vmcb01); -if (unlikely (svm->vmcb->control.virt_ext &LBR_CTL_ENABLE_MASK )) { +if (unlikely (svm->lbrv_enabled && (svm->nested.ctl.virt_ext &LBR_CTL_ENABLE_MASK ))) { +svm_copy_lbrs (svm->nested.vmcb02.ptr, vmcb12); +svm_update_lbrv (vcpu); + }else if (unlikely (svm->vmcb->control.virt_ext &LBR_CTL_ENABLE_MASK )) {svm_copy_lbrs (svm->nested.vmcb02.ptr, svm->vmcb);svm_update_lbrv (vcpu); }
arch/x86/kvm/svm/svm.c +8 -0
@@ -890,6 +890,10 @@ void svm_update_lbrv(struct kvm_vcpu *vcpu)bool current_enable_lbrv = !!(svm->vmcb->control.virt_ext &LBR_CTL_ENABLE_MASK ); +if (unlikely (is_guest_mode (vcpu) && svm->lbrv_enabled)) +if (unlikely (svm->nested.ctl.virt_ext &LBR_CTL_ENABLE_MASK )) + enable_lbrv = true; +if (enable_lbrv == current_enable_lbrv)return ;
@@ -3987,6 +3991,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)guest_cpuid_has (vcpu,X86_FEATURE_NRIPS ); svm->tsc_scaling_enabled = tsc_scaling &&guest_cpuid_has (vcpu,X86_FEATURE_TSCRATEMSR ); + svm->lbrv_enabled = lbrv &&guest_cpuid_has (vcpu,X86_FEATURE_LBRV );svm_recalc_instruction_intercepts (vcpu, svm);
@@ -4791,6 +4796,9 @@ static __init void svm_set_cpu_caps(void)if (tsc_scaling)kvm_cpu_cap_set (X86_FEATURE_TSCRATEMSR ); +if (lbrv) +kvm_cpu_cap_set (X86_FEATURE_LBRV ); +/* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set (X86_FEATURE_SVME_ADDR_CHK ); }
arch/x86/kvm/svm/svm.h +1 -0
@@ -220,6 +220,7 @@ struct vcpu_svm {/* cached guest cpuid flags for faster access */ bool nrips_enabled : 1; bool tsc_scaling_enabled : 1; + bool lbrv_enabled : 1;u32 ldr_reg;u32 dfr_reg;
Signature · 1 line
2.26.3
PATCH 24/30 KVM: x86: nSVM: implement nested VMLOAD/VMSAVE
In reply to Maxim LevitskyThis was tested by booting L1,L2,L3 (all Linux) and checking that no VMLOAD/VMSAVE vmexits happened.
--- arch/x86/kvm/svm/nested.c | 35 +++++++++++++++++++++++++++++------ arch/x86/kvm/svm/svm.c | 7 +++++++ arch/x86/kvm/svm/svm.h | 8 +++++++- 3 files changed, 43 insertions(+), 7 deletions(-)
arch/x86/kvm/svm/nested.c +29 -6
@@ -120,6 +120,20 @@ static void nested_svm_uninit_mmu_context(struct kvm_vcpu *vcpu) vcpu->arch.walk_mmu = &vcpu->arch.root_mmu; } +static bool nested_vmcb_needs_vls_intercept (struct vcpu_svm *svm) +{ +if (!svm->v_vmload_vmsave_enabled) +return true; + +if (!nested_npt_enabled (svm)) +return true; + +if (!(svm->nested.ctl.virt_ext &VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK )) +return true; + +return false; +} +void recalc_intercepts (struct vcpu_svm *svm) {struct vmcb_control_area *c, *h;
@@ -161,8 +175,17 @@ void recalc_intercepts(struct vcpu_svm *svm)if (!intercept_smi)vmcb_clr_intercept (c,INTERCEPT_SMI ); -vmcb_set_intercept (c,INTERCEPT_VMLOAD ); -vmcb_set_intercept (c,INTERCEPT_VMSAVE ); +if (nested_vmcb_needs_vls_intercept (svm)) { +/* +* If the virtual VMLOAD/VMSAVE is not enabled for the L2, +* we must intercept these instructions to correctly +* emulate them in case L1 doesn't intercept them. +*/ +vmcb_set_intercept (c,INTERCEPT_VMLOAD ); +vmcb_set_intercept (c,INTERCEPT_VMSAVE ); + }else { +WARN_ON (!(c->virt_ext &VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK )); + } }static bool nested_svm_vmrun_msrpm (struct vcpu_svm *svm)
@@ -426,10 +449,7 @@ static void nested_save_pending_event_to_vmcb12(struct vcpu_svm *svm, vmcb12->control.exit_int_info = exit_int_info; } -static inline bool nested_npt_enabled (struct vcpu_svm *svm) -{ -return svm->nested.ctl.nested_ctl &SVM_NESTED_CTL_NP_ENABLE ; -} +static void nested_svm_transition_tlb_flush (struct kvm_vcpu *vcpu) {
@@ -607,6 +627,9 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) svm->vmcb->control.virt_ext |= (svm->nested.ctl.virt_ext &LBR_CTL_ENABLE_MASK ); +if (!nested_vmcb_needs_vls_intercept (svm)) + svm->vmcb->control.virt_ext |=VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK ; +nested_svm_transition_tlb_flush (vcpu);/* Enter Guest-Mode */
arch/x86/kvm/svm/svm.c +7 -0
@@ -1051,6 +1051,8 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu)set_msr_interception (vcpu, svm->msrpm,MSR_IA32_SYSENTER_EIP ,0 ,0 );set_msr_interception (vcpu, svm->msrpm,MSR_IA32_SYSENTER_ESP ,0 ,0 ); + + svm->v_vmload_vmsave_enabled = false; }else {/* * If hardware supports Virtual VMLOAD VMSAVE then enable it
@@ -3993,6 +3995,8 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) svm->tsc_scaling_enabled = tsc_scaling &&guest_cpuid_has (vcpu,X86_FEATURE_TSCRATEMSR ); svm->lbrv_enabled = lbrv &&guest_cpuid_has (vcpu,X86_FEATURE_LBRV ); + svm->v_vmload_vmsave_enabled = vls &&guest_cpuid_has (vcpu,X86_FEATURE_V_VMSAVE_VMLOAD ); +svm_recalc_instruction_intercepts (vcpu, svm);/* For sev guests, the memory encryption bit is not reserved in CR3. */
@@ -4799,6 +4803,9 @@ static __init void svm_set_cpu_caps(void)if (lbrv)kvm_cpu_cap_set (X86_FEATURE_LBRV ); +if (vls) +kvm_cpu_cap_set (X86_FEATURE_V_VMSAVE_VMLOAD ); +/* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set (X86_FEATURE_SVME_ADDR_CHK ); }
arch/x86/kvm/svm/svm.h +7 -1
@@ -217,10 +217,11 @@ struct vcpu_svm {unsigned int3_injected;unsigned long int3_rip; -/* cached guest cpuid flags for faster access */ +/* optional nested SVM features that are enabled for this guest */ bool nrips_enabled : 1; bool tsc_scaling_enabled : 1; bool lbrv_enabled : 1; + bool v_vmload_vmsave_enabled : 1;u32 ldr_reg;u32 dfr_reg;
@@ -468,6 +469,11 @@ static inline bool gif_set(struct vcpu_svm *svm)return !!(svm->vcpu.arch.hflags &HF_GIF_MASK ); } +static inline bool nested_npt_enabled (struct vcpu_svm *svm) +{ +return svm->nested.ctl.nested_ctl &SVM_NESTED_CTL_NP_ENABLE ; +} +/* svm.c */ #define MSR_INVALID 0xffffffffU
Signature · 1 line
2.26.3
PATCH 25/30 KVM: x86: nSVM: support PAUSE filter threshold and count when cpu_pm=on
In reply to Maxim LevitskyAllow L1 to use these settings if L0 disables PAUSE interception (AKA cpu_pm=on)
--- arch/x86/kvm/svm/nested.c | 6 ++++++ arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++ arch/x86/kvm/svm/svm.h | 2 ++ 3 files changed, 25 insertions(+)
arch/x86/kvm/svm/nested.c +6 -0
@@ -630,6 +630,12 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)if (!nested_vmcb_needs_vls_intercept (svm)) svm->vmcb->control.virt_ext |=VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK ; +if (svm->pause_filter_enabled) + svm->vmcb->control.pause_filter_count = svm->nested.ctl.pause_filter_count; + +if (svm->pause_threshold_enabled) + svm->vmcb->control.pause_filter_thresh = svm->nested.ctl.pause_filter_thresh; +nested_svm_transition_tlb_flush (vcpu);/* Enter Guest-Mode */
arch/x86/kvm/svm/svm.c +17 -0
@@ -3997,6 +3997,17 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) svm->v_vmload_vmsave_enabled = vls &&guest_cpuid_has (vcpu,X86_FEATURE_V_VMSAVE_VMLOAD ); +if (kvm_pause_in_guest (vcpu->kvm)) { + svm->pause_filter_enabled = pause_filter_count >0 && +guest_cpuid_has (vcpu,X86_FEATURE_PAUSEFILTER ); + + svm->pause_threshold_enabled = pause_filter_thresh >0 && +guest_cpuid_has (vcpu,X86_FEATURE_PFTHRESHOLD ); + }else { + svm->pause_filter_enabled = false; + svm->pause_threshold_enabled = false; + } +svm_recalc_instruction_intercepts (vcpu, svm);/* For sev guests, the memory encryption bit is not reserved in CR3. */
@@ -4806,6 +4817,12 @@ static __init void svm_set_cpu_caps(void)if (vls)kvm_cpu_cap_set (X86_FEATURE_V_VMSAVE_VMLOAD ); +if (pause_filter_count) +kvm_cpu_cap_set (X86_FEATURE_PAUSEFILTER ); + +if (pause_filter_thresh) +kvm_cpu_cap_set (X86_FEATURE_PFTHRESHOLD ); +/* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set (X86_FEATURE_SVME_ADDR_CHK ); }
arch/x86/kvm/svm/svm.h +2 -0
@@ -222,6 +222,8 @@ struct vcpu_svm { bool tsc_scaling_enabled : 1; bool lbrv_enabled : 1; bool v_vmload_vmsave_enabled : 1; + bool pause_filter_enabled : 1; + bool pause_threshold_enabled : 1;u32 ldr_reg;u32 dfr_reg;
Signature · 1 line
2.26.3
PATCH 26/30 KVM: x86: nSVM: implement nested vGIF
In reply to Maxim LevitskyIn case L1 enables vGIF for L2, the L2 cannot affect L1's GIF, regardless of STGI/CLGI intercepts, and since VM entry enables GIF, this means that L1's GIF is always 1 while L2 is running.
Thus in this case leave L1's vGIF in vmcb01, while letting L2 control the vGIF thus implementing nested vGIF.
Also allow KVM to toggle L1's GIF during nested entry/exit by always using vmcb01.
--- arch/x86/kvm/svm/nested.c | 17 +++++++++++++---- arch/x86/kvm/svm/svm.c | 5 +++++ arch/x86/kvm/svm/svm.h | 25 +++++++++++++++++++++---- 3 files changed, 39 insertions(+), 8 deletions(-)
arch/x86/kvm/svm/nested.c +13 -4
@@ -408,6 +408,10 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *svm)*/ mask &= ~V_IRQ_MASK ; } + +if (nested_vgif_enabled (svm)) + mask |=V_GIF_MASK ; + svm->nested.ctl.int_ctl &= ~mask; svm->nested.ctl.int_ctl |= svm->vmcb->control.int_ctl & mask; }
@@ -573,10 +577,8 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12static void nested_vmcb02_prepare_control (struct vcpu_svm *svm) { -const u32 int_ctl_vmcb01_bits = -V_INTR_MASKING_MASK |V_GIF_MASK |V_GIF_ENABLE_MASK ; - -const u32 int_ctl_vmcb12_bits =V_TPR_MASK |V_IRQ_INJECTION_BITS_MASK ; +u32 int_ctl_vmcb01_bits =V_INTR_MASKING_MASK ; +u32 int_ctl_vmcb12_bits =V_TPR_MASK |V_IRQ_INJECTION_BITS_MASK ;struct kvm_vcpu *vcpu = &svm->vcpu;
@@ -586,6 +588,13 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)*/ + + +if (svm->vgif_enabled && (svm->nested.ctl.int_ctl &V_GIF_ENABLE_MASK )) + int_ctl_vmcb12_bits |= (V_GIF_MASK |V_GIF_ENABLE_MASK ); +else + int_ctl_vmcb01_bits |= (V_GIF_MASK |V_GIF_ENABLE_MASK ); +/* Copied from vmcb01. msrpm_base can be overwritten later. */ svm->vmcb->control.nested_ctl = svm->vmcb01.ptr->control.nested_ctl; svm->vmcb->control.iopm_base_pa = svm->vmcb01.ptr->control.iopm_base_pa;
arch/x86/kvm/svm/svm.c +5 -0
@@ -4008,6 +4008,8 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) svm->pause_threshold_enabled = false; } + svm->vgif_enabled = vgif &&guest_cpuid_has (vcpu,X86_FEATURE_VGIF ); +svm_recalc_instruction_intercepts (vcpu, svm);/* For sev guests, the memory encryption bit is not reserved in CR3. */
@@ -4823,6 +4825,9 @@ static __init void svm_set_cpu_caps(void)if (pause_filter_thresh)kvm_cpu_cap_set (X86_FEATURE_PFTHRESHOLD ); +if (vgif) +kvm_cpu_cap_set (X86_FEATURE_VGIF ); +/* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set (X86_FEATURE_SVME_ADDR_CHK ); }
arch/x86/kvm/svm/svm.h +21 -4
@@ -224,6 +224,7 @@ struct vcpu_svm { bool v_vmload_vmsave_enabled : 1; bool pause_filter_enabled : 1; bool pause_threshold_enabled : 1; + bool vgif_enabled : 1;u32 ldr_reg;u32 dfr_reg;
@@ -442,31 +443,47 @@ static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit)return vmcb_is_intercept (&svm->vmcb->control, bit); } +static bool nested_vgif_enabled (struct vcpu_svm *svm) +{ +if (!is_guest_mode (&svm->vcpu) || !svm->vgif_enabled) +return false; +return svm->nested.ctl.int_ctl &V_GIF_ENABLE_MASK ; +} +static inline bool vgif_enabled (struct vcpu_svm *svm) { -return !!(svm->vmcb->control.int_ctl &V_GIF_ENABLE_MASK ); +struct vmcb *vmcb =nested_vgif_enabled (svm) ? svm->vmcb01.ptr : svm->vmcb; + +return !!(vmcb->control.int_ctl &V_GIF_ENABLE_MASK ); }static inline void enable_gif (struct vcpu_svm *svm) { +struct vmcb *vmcb =nested_vgif_enabled (svm) ? svm->vmcb01.ptr : svm->vmcb; +if (vgif_enabled (svm)) - svm->vmcb->control.int_ctl |=V_GIF_MASK ; + vmcb->control.int_ctl |=V_GIF_MASK ;else svm->vcpu.arch.hflags |=HF_GIF_MASK ; }static inline void disable_gif (struct vcpu_svm *svm) { +struct vmcb *vmcb =nested_vgif_enabled (svm) ? svm->vmcb01.ptr : svm->vmcb; +if (vgif_enabled (svm)) - svm->vmcb->control.int_ctl &= ~V_GIF_MASK ; + vmcb->control.int_ctl &= ~V_GIF_MASK ;else svm->vcpu.arch.hflags &= ~HF_GIF_MASK ; + }static inline bool gif_set (struct vcpu_svm *svm) { +struct vmcb *vmcb =nested_vgif_enabled (svm) ? svm->vmcb01.ptr : svm->vmcb; +if (vgif_enabled (svm)) -return !!(svm->vmcb->control.int_ctl &V_GIF_MASK ); +return !!(vmcb->control.int_ctl &V_GIF_MASK );else return !!(svm->vcpu.arch.hflags &HF_GIF_MASK ); }
Signature · 1 line
2.26.3
PATCH 27/30 KVM: x86: add force_intercept_exceptions_mask
In reply to Maxim LevitskyThis parameter will be used by VMX and SVM code to force interception of a set of exceptions, given by a bitmask for guest debug and/or kvm debug.
This is based on an idea first shown here:
https://patchwork.kernel.org/project/kvm/patch/[email protected]/
--- arch/x86/include/asm/kvm_host.h | 7 +++++++ arch/x86/kvm/x86.c | 9 +++++++++ arch/x86/kvm/x86.h | 5 +++++ 3 files changed, 21 insertions(+)
arch/x86/include/asm/kvm_host.h +7 -0
@@ -1168,6 +1168,13 @@ struct kvm_arch {struct kvm_pmu_event_filter __rcu *pmu_event_filter;struct task_struct *nx_lpage_recovery_thread; +/* +* Bitmask of exceptions that KVM will intercept +* and forward to the guest, even if that is not needed +* for normal operation. Debug feature. +*/ +u32 force_intercept_exceptions_bitmask; +#ifdef CONFIG_X86_64 /* * Whether the TDP MMU is enabled for this VM. This contains a
arch/x86/kvm/x86.c +9 -0
@@ -193,6 +193,13 @@ module_param(enable_pmu, bool, 0444);bool __read_mostly eager_page_split = true;module_param (eager_page_split, bool,0644 ); +/* +* force_intercept_exceptions_mask is a writable param and its value +* is snapshotted when a VM is created +*/ +static uint force_intercept_exceptions_mask; +module_param (force_intercept_exceptions_mask, uint,S_IRUGO |S_IWUSR ); +/* * Restoring the host value for MSRs that are only consumed when running in * usermode, e.g. SYSCALL MSRs and TSC_AUX, can be deferred until the CPU
@@ -11646,6 +11653,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)raw_spin_unlock_irqrestore (&kvm->arch.tsc_write_lock, flags); kvm->arch.guest_can_read_msr_platform_info = true; + kvm->arch.force_intercept_exceptions_bitmask = force_intercept_exceptions_mask;#if IS_ENABLED (CONFIG_HYPERV )spin_lock_init (&kvm->arch.hv_root_tdp_lock);
@@ -12886,6 +12894,7 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size, }EXPORT_SYMBOL_GPL (kvm_sev_es_string_io); +EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_entry);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_exit);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_fast_mmio);
arch/x86/kvm/x86.h +5 -0
@@ -91,6 +91,11 @@ static inline bool kvm_exception_is_soft(unsigned int nr)return (nr ==BP_VECTOR ) || (nr ==OF_VECTOR ); } +static inline bool kvm_is_exception_force_intercepted (struct kvm *kvm,int exception) +{ +return kvm->arch.force_intercept_exceptions_bitmask &BIT (exception); +} +static inline bool is_protmode (struct kvm_vcpu *vcpu) {return kvm_read_cr0_bits (vcpu,X86_CR0_PE );
Signature · 1 line
2.26.3
PATCH 28/30 KVM: SVM: implement force_intercept_exceptions_mask
In reply to Maxim LevitskyCurrently #TS interception is only done once. Also exception interception is not enabled for SEV guests.
--- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/svm.c | 92 ++++++++++++++++++++++++++++++++- arch/x86/kvm/svm/svm.h | 5 +- arch/x86/kvm/svm/svm_onhyperv.c | 1 + arch/x86/kvm/x86.c | 5 +- 6 files changed, 101 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -1750,6 +1750,8 @@ int kvm_emulate_rdpmc(struct kvm_vcpu *vcpu);void kvm_queue_exception (struct kvm_vcpu *vcpu,unsigned nr);void kvm_queue_exception_e (struct kvm_vcpu *vcpu,unsigned nr,u32 error_code);void kvm_queue_exception_p (struct kvm_vcpu *vcpu,unsigned nr,unsigned long payload); +void kvm_queue_exception_e_p (struct kvm_vcpu *vcpu,unsigned nr, +u32 error_code,unsigned long payload);void kvm_requeue_exception (struct kvm_vcpu *vcpu,unsigned nr);void kvm_requeue_exception_e (struct kvm_vcpu *vcpu,unsigned nr,u32 error_code);void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault);
arch/x86/include/uapi/asm/kvm.h +1 -0
@@ -32,6 +32,7 @@#define MC_VECTOR 18#define XM_VECTOR 19#define VE_VECTOR 20 +#define CP_VECTOR 21/* Select x86 specific features in <linux/kvm.h> */ #define __KVM_HAVE_PIT
arch/x86/kvm/svm/svm.c +90 -2
133 lines not on this page · raw message
arch/x86/kvm/svm/svm.h +4 -1
@@ -415,8 +415,11 @@ static inline void clr_exception_intercept(struct vcpu_svm *svm, u32 bit)struct vmcb *vmcb = svm->vmcb01.ptr;WARN_ON_ONCE (bit >=32 ); -vmcb_clr_intercept (&vmcb->control,INTERCEPT_EXCEPTION_OFFSET + bit); +if (kvm_is_exception_force_intercepted (svm->vcpu.kvm, bit)) +return ; + +vmcb_clr_intercept (&vmcb->control,INTERCEPT_EXCEPTION_OFFSET + bit);recalc_intercepts (svm); }
arch/x86/kvm/svm/svm_onhyperv.c +1 -0
@@ -8,6 +8,7 @@#include <asm/mshyperv.h> +#include "x86.h" #include "svm.h" #include "svm_ops.h"
arch/x86/kvm/x86.c +3 -2
@@ -706,12 +706,13 @@ void kvm_queue_exception_p(struct kvm_vcpu *vcpu, unsigned nr, }EXPORT_SYMBOL_GPL (kvm_queue_exception_p); -static void kvm_queue_exception_e_p (struct kvm_vcpu *vcpu,unsigned nr, -u32 error_code,unsigned long payload) +void kvm_queue_exception_e_p (struct kvm_vcpu *vcpu,unsigned nr, +u32 error_code,unsigned long payload) {kvm_multiple_exception (vcpu, nr, true, error_code, true, payload, false); } +EXPORT_SYMBOL_GPL (kvm_queue_exception_e_p);int kvm_complete_insn_gp (struct kvm_vcpu *vcpu,int err) {
Signature · 1 line
2.26.3
PATCH 29/30 KVM: VMX: implement force_intercept_exceptions_mask
In reply to Maxim LevitskyAll exceptions are supported. Some bugs might remain in regard to KVM own interception of #PF but since this is strictly
debug feature this should be OK.
--- arch/x86/kvm/vmx/nested.c | 8 +++++++ arch/x86/kvm/vmx/vmcs.h | 6 +++++ arch/x86/kvm/vmx/vmx.c | 47 +++++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 7 deletions(-)
arch/x86/kvm/vmx/nested.c +8 -0
@@ -5902,6 +5902,14 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,switch ((u16 )exit_reason.basic) {case EXIT_REASON_EXCEPTION_NMI : intr_info =vmx_get_intr_info (vcpu); + +if (is_exception (intr_info)) { +int ex_no = intr_info &INTR_INFO_VECTOR_MASK ; + +if (kvm_is_exception_force_intercepted (vcpu->kvm, ex_no)) +return true; + } +if (is_nmi (intr_info))return true;else if (is_page_fault (intr_info))
arch/x86/kvm/vmx/vmcs.h +6 -0
@@ -94,6 +94,12 @@ static inline bool is_exception_n(u32 intr_info, u8 vector)return is_intr_type_n (intr_info,INTR_TYPE_HARD_EXCEPTION , vector); } +static inline bool is_exception (u32 intr_info) +{ +return is_intr_type (intr_info,INTR_TYPE_HARD_EXCEPTION ) || +is_intr_type (intr_info,INTR_TYPE_SOFT_EXCEPTION ); +} +static inline bool is_debug (u32 intr_info) {return is_exception_n (intr_info,DB_VECTOR );
arch/x86/kvm/vmx/vmx.c +40 -7
99 lines not on this page · raw message
Signature · 1 line
2.26.3
PATCH 30/30 KVM: x86: get rid of KVM_REQ_GET_NESTED_STATE_PAGES
In reply to Maxim LevitskyAs it turned out this request isn't really needed, and it complicates the nested migration.
In theory this patch can break userspace if userspace relies on updating KVM's memslots after setting nested state but there is little reason for it to rely on this.
However this is undocumented and there is a good chance that no userspace relies on this, thus
just try to remove this code.
--- arch/x86/include/asm/kvm_host.h | 5 +- arch/x86/kvm/hyperv.c | 4 ++ arch/x86/kvm/svm/nested.c | 50 ++++------------- arch/x86/kvm/svm/svm.c | 2 +- arch/x86/kvm/svm/svm.h | 2 +- arch/x86/kvm/vmx/nested.c | 99 +++++++++------------------------ arch/x86/kvm/x86.c | 6 -- 7 files changed, 45 insertions(+), 123 deletions(-)
arch/x86/include/asm/kvm_host.h +3 -2
@@ -92,7 +92,6 @@#define KVM_REQ_HV_EXIT KVM_ARCH_REQ(21)#define KVM_REQ_HV_STIMER KVM_ARCH_REQ(22)#define KVM_REQ_LOAD_EOI_EXITMAP KVM_ARCH_REQ(23) -#define KVM_REQ_GET_NESTED_STATE_PAGES KVM_ARCH_REQ(24)#define KVM_REQ_APICV_UPDATE \ KVM_ARCH_REQ_FLAGS(25, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_TLB_FLUSH_CURRENT KVM_ARCH_REQ(26)
@@ -1519,12 +1518,14 @@ struct kvm_x86_nested_ops {int (*set_state)(struct kvm_vcpu *vcpu,struct kvm_nested_state __user *user_kvm_nested_state,struct kvm_nested_state *kvm_state); -bool (*get_nested_state_pages)(struct kvm_vcpu *vcpu);int (*write_log_dirty)(struct kvm_vcpu *vcpu,gpa_t l2_gpa);int (*enable_evmcs)(struct kvm_vcpu *vcpu,uint16_t *vmcs_version);uint16_t (*get_evmcs_version)(struct kvm_vcpu *vcpu); + +bool (*get_evmcs_page)(struct kvm_vcpu *vcpu); + };struct kvm_x86_init_ops {
arch/x86/kvm/hyperv.c +4 -0
@@ -1497,6 +1497,10 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host) gfn_to_gpa(gfn) | KVM_MSR_ENABLED, sizeof(struct hv_vp_assist_page)))return 1 ; + +if (host && kvm_x86_ops.nested_ops->get_evmcs_page) +if (!kvm_x86_ops.nested_ops->get_evmcs_page (vcpu)) +return 1 ;break ; }case HV_X64_MSR_EOI :
arch/x86/kvm/svm/nested.c +11 -39
109 lines not on this page · raw message
arch/x86/kvm/svm/svm.c +1 -1
@@ -4498,7 +4498,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) vmcb12 = map.hva;nested_copy_vmcb_control_to_cache (svm, &vmcb12->control);nested_copy_vmcb_save_to_cache (svm, &vmcb12->save); - ret =enter_svm_guest_mode (vcpu, vmcb12_gpa, vmcb12, false); + ret =enter_svm_guest_mode (vcpu, vmcb12_gpa, vmcb12);if (ret) goto unmap_save;
arch/x86/kvm/svm/svm.h +1 -1
@@ -551,7 +551,7 @@ static inline bool nested_exit_on_nmi(struct vcpu_svm *svm) }int enter_svm_guest_mode (struct kvm_vcpu *vcpu, -u64 vmcb_gpa,struct vmcb *vmcb12,bool from_vmrun); +u64 vmcb_gpa,struct vmcb *vmcb12);void svm_leave_nested (struct kvm_vcpu *vcpu);void svm_free_nested (struct vcpu_svm *svm);int svm_allocate_nested (struct vcpu_svm *svm);
arch/x86/kvm/vmx/nested.c +25 -74
164 lines not on this page · raw message
arch/x86/kvm/x86.c +0 -6
@@ -9897,12 +9897,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r = -EIO ; goto out; } -if (kvm_check_request (KVM_REQ_GET_NESTED_STATE_PAGES , vcpu)) { -if (unlikely (!kvm_x86_ops.nested_ops->get_nested_state_pages (vcpu))) { - r =0 ; - goto out; - } - }if (kvm_check_request (KVM_REQ_MMU_RELOAD , vcpu))kvm_mmu_unload (vcpu);if (kvm_check_request (KVM_REQ_MIGRATE_TIMER , vcpu))
Signature · 1 line
2.26.3
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for My patch queue
In reply to Maxim Levitsky== Series Details ==
== Series Details ==
Series: My patch queue
URL : https://patchwork.freedesktop.org/series/99770/
State : failure
== Summary ==
Applying: KVM: x86: SVM: don't passthrough SMAP/SMEP/PKE bits in !NPT && !gCR0.PG case
error: sha1 information is lacking or useless (arch/x86/kvm/svm/svm.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 KVM: x86: SVM: don't passthrough SMAP/SMEP/PKE bits in !NPT && !gCR0.PG case When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Sean Christopherson
maintainerQuoted 9 lines · Maxim Levitsky
This is set of various patches that are stuck in my patch queue.
KVM_REQ_GET_NESTED_STATE_PAGESpatch is mostly RFC, but it does seem to work for me.Read-only APIC ID is also somewhat RFC.
Some of these patches are preparation for support for nested AVIC which I almost done developing, and will start testing very soon.
Please split this up into smaller series and/or standalone patches. At a glance, this has 10+ different unrealted series/patches rolled into one, which makes everything far more difficult to review.
Quoted 6 lines · Sean Christopherson
Quoted 5 lines · Maxim Levitsky
This is set of various patches that are stuck in my patch queue.
KVM_REQ_GET_NESTED_STATE_PAGESpatch is mostly RFC, but it does seem to work for me.
Quoted 9 lines
Quoted 4 lines
Read-only APIC ID is also somewhat RFC.
Some of these patches are preparation for support for nested AVIC which I almost done developing, and will start testing very soon.
Please split this up into smaller series and/or standalone patches. At a glance, this has 10+ different unrealted series/patches rolled into one, which makes everything far more difficult to review.
True to be honest. I ended up with too many patches in my local patch queue, including some bugfixes which really should be send long ago, and I wanted to push all of this out to get some feedback before the tree is rebased again, and I'll get to rebase again and again :-)
Best regards,
Maxim Levitsky