KVM: x86: Replace cpu_dirty_logging_count with nr_memslots_dirty_logging
PATCH v2 1/1 KVM: x86: Replace cpu_dirty_logging_count with nr_memslots_dirty_logging
Drop cpu_dirty_logging_count in favor of nr_memslots_dirty_logging. Both fields count the number of memslots that have dirty-logging enabled, with the only difference being that cpu_dirty_logging_count is only incremented when using PML. So while nr_memslots_dirty_logging is not a direct replacement for cpu_dirty_logging_count, it can be combined with enable_pml to get the same information.
---
v2:
- Return early if !enable_pml in vmx_update_cpu_dirty_logging() [Sean]
- Do a single atomic_read() in kvm_mmu_update_cpu_dirty_logging() [Sean]
v1: https://lore.kernel.org/kvm/[email protected]/
arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/vmx/vmx.c | 9 ++++++--- arch/x86/kvm/x86.c | 8 +++----- 3 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1329,7 +1329,6 @@ struct kvm_arch {u32 bsp_vcpu_id;u64 disabled_quirks; -int cpu_dirty_logging_count;enum kvm_irqchip_mode irqchip_mode;u8 nr_reserved_ioapic_pins;
arch/x86/kvm/vmx/vmx.c +6 -3
@@ -4606,7 +4606,7 @@ static u32 vmx_secondary_exec_control(struct vcpu_vmx *vmx)* it needs to be set here when dirty logging is already active, e.g. * if this vCPU was created after dirty logging was enabled. */ -if (!vcpu->kvm->arch.cpu_dirty_logging_count) +if (!enable_pml || !atomic_read (&vcpu->kvm->nr_memslots_dirty_logging)) exec_control &= ~SECONDARY_EXEC_ENABLE_PML ;if (cpu_has_vmx_xsaves ()) {
@@ -7988,17 +7988,20 @@ void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); +if (WARN_ON_ONCE (!enable_pml)) +return ; +if (is_guest_mode (vcpu)) { vmx->nested.update_vmcs01_cpu_dirty_logging = true;return ; }/* -* Note, cpu_dirty_logging_count can be changed concurrent with this +* Note, nr_memslots_dirty_logging can be changed concurrent with this * code, but in that case another update request will be made and so * the guest will never run with a stale PML value. */ -if (vcpu->kvm->arch.cpu_dirty_logging_count) +if (atomic_read (&vcpu->kvm->nr_memslots_dirty_logging))secondary_exec_controls_setbit (vmx,SECONDARY_EXEC_ENABLE_PML );else secondary_exec_controls_clearbit (vmx,SECONDARY_EXEC_ENABLE_PML );
arch/x86/kvm/x86.c +3 -5
@@ -12482,16 +12482,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,static void kvm_mmu_update_cpu_dirty_logging (struct kvm *kvm,bool enable) { -struct kvm_arch *ka = &kvm->arch; +int nr_slots;if (!kvm_x86_ops.cpu_dirty_log_size)return ; -if ((enable && ++ka->cpu_dirty_logging_count ==1 ) || - (!enable && --ka->cpu_dirty_logging_count ==0 )) + nr_slots =atomic_read (&kvm->nr_memslots_dirty_logging); +if ((enable && nr_slots ==1 ) || !nr_slots)kvm_make_all_cpus_request (kvm,KVM_REQ_UPDATE_CPU_DIRTY_LOGGING ); - -WARN_ON_ONCE (ka->cpu_dirty_logging_count <0 ); } static void kvm_mmu_slot_apply_flags(struct kvm *kvm,
base-commit: 91dc252b0dbb6879e4067f614df1e397fec532a1
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
Quoted 8 lines · David Matlack
Drop
cpu_dirty_logging_countin favor ofnr_memslots_dirty_logging. Both fields count the number of memslots that have dirty-logging enabled, with the only difference being thatcpu_dirty_logging_countis only incremented when using PML. So whilenr_memslots_dirty_loggingis not a direct replacement forcpu_dirty_logging_count, it can be combined withenable_pmlto get the same information.[...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Replace cpu_dirty_logging_count with nr_memslots_dirty_logging
https://github.com/kvm-x86/linux/commit/1799eb69b994
--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes