From: "Nikunj A. Dadhania" <nikunj@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: <pbonzini@redhat.com>, <bp@alien8.de>,
<joao.m.martins@oracle.com>, <kai.huang@intel.com>,
<kvm@vger.kernel.org>, <thomas.lendacky@amd.com>,
<yosry@kernel.org>
Subject: Re: [PATCH v7.1] KVM: SVM: Add Page modification logging support
Date: Wed, 2 Sep 2026 14:22:23 +0530 [thread overview]
Message-ID: <6e22fa3d-b443-441f-8717-3c544f5aeb59@amd.com> (raw)
In-Reply-To: <apdpQ4eUkXODO-bI@google.com>
Hi Sean,
Thanks for the review!
On 9/2/2026 5:39 AM, Sean Christopherson wrote:
> On Fri, May 29, 2026, Nikunj A Dadhania wrote:
>> @@ -3331,6 +3364,53 @@ static int vmmcall_interception(struct kvm_vcpu *vcpu)
>> return kvm_emulate_hypercall(vcpu);
>> }
>>
>> +void svm_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
>
> This can be static.
>
>> +{
>> + struct vcpu_svm *svm = to_svm(vcpu);
>> + struct vmcb *vmcb01 = svm->vmcb01.ptr;
>> +
>> + if (WARN_ON_ONCE(!vcpu->kvm->arch.cpu_dirty_log_size))
>
> This can/should be moved to common code.
>
>> + return;
>> +
>> + /*
>> + * 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.
>> + */
>
> Ditto with this copy+pasted comment.
>
>> + if (atomic_read(&vcpu->kvm->nr_memslots_dirty_logging))
>
> And this check. E.g. (incomplete, needs to be split up)
Sure, will refactor into a common kvm_update_cpu_dirty_logging()
wrapper in x86.c as suggested in a separate pre-patch.
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 0a8ef0b4ddda..73564619a61e 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3377,20 +3377,12 @@ static int vmmcall_interception(struct kvm_vcpu *vcpu)
> return kvm_emulate_hypercall(vcpu);
> }
>
> -void svm_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
> +static void svm_update_cpu_dirty_logging(struct kvm_vcpu *vcpu, bool enable)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> struct vmcb *vmcb01 = svm->vmcb01.ptr;
>
> - if (WARN_ON_ONCE(!vcpu->kvm->arch.cpu_dirty_log_size))
> - return;
> -
> - /*
> - * 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 (atomic_read(&vcpu->kvm->nr_memslots_dirty_logging))
> + if (enable)
> vmcb01->control.misc_ctl |= SVM_MISC_ENABLE_PML;
> else
> vmcb01->control.misc_ctl &= ~SVM_MISC_ENABLE_PML;
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 0052446e04d9..828a51418d83 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -8416,21 +8416,13 @@ static void vmx_update_hv_timer(struct kvm_vcpu *vcpu, bool force_immediate_exit
> }
> #endif
>
> -void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
> +void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu, bool enable)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
>
> - if (WARN_ON_ONCE(!vcpu->kvm->arch.cpu_dirty_log_size))
> - return;
> -
> guard(vmx_vmcs01)(vcpu);
>
> - /*
> - * 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 (atomic_read(&vcpu->kvm->nr_memslots_dirty_logging))
> + if (enable)
> secondary_exec_controls_setbit(vmx, SECONDARY_EXEC_ENABLE_PML);
> else
> secondary_exec_controls_clearbit(vmx, SECONDARY_EXEC_ENABLE_PML);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 33715236afc9..4443796c4426 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8073,6 +8073,21 @@ static void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
> kvm_x86_call(set_apic_access_page_addr)(vcpu);
> }
>
> +static void kvm_update_cpu_dirty_logging(struct kvm_vcpu *vcpu)
> +{
> + /*
> + * 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.
> + */
> + bool enabled = atomic_read(&vcpu->kvm->nr_memslots_dirty_logging);
> +
> + if (WARN_ON_ONCE(!vcpu->kvm->arch.cpu_dirty_log_size))
> + return;
> +
> + kvm_x86_call(update_cpu_dirty_logging)(vcpu, enable);
> +}
> +
One subtle ordering change for VMX: currently guard(vmx_vmcs01) is
taken before the atomic_read; with this refactoring the atomic_read
happens in common code before guard(vmx_vmcs01) is called.
The ordering flip looks harmless to me.
> /*
> * Called within kvm->srcu read side.
> * Returns 1 to let vcpu_run() continue the guest execution loop without
> @@ -8238,8 +8253,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
> if (kvm_check_request(KVM_REQ_RECALC_INTERCEPTS, vcpu))
> kvm_x86_call(recalc_intercepts)(vcpu);
>
> - if (kvm_check_request(KVM_REQ_UPDATE_CPU_DIRTY_LOGGING, vcpu))
> - kvm_x86_call(update_cpu_dirty_logging)(vcpu);
> +
> + /*
> + * 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 stale PML state.
> + */
Looks like the comment got put in two places; will retain it only in
kvm_update_cpu_dirty_logging().
> + if (kvm_check_request(KVM_REQ_UPDATE_CPU_DIRTY_LOGGING, vcpu)
> + kvm_update_cpu_dirty_logging(vcpu);
...
>> @@ -5465,6 +5570,8 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
>> .gmem_prepare = sev_gmem_prepare,
>> .gmem_invalidate = sev_gmem_invalidate,
>> .gmem_max_mapping_level = sev_gmem_max_mapping_level,
>> +
>> + .update_cpu_dirty_logging = svm_update_cpu_dirty_logging,
>
> Please keep the ordering somewhat similar to the other declarations, i.e. don't
> just put this at the end. This seems like the least awful place:
>
> .handle_exit_irqoff = svm_handle_exit_irqoff,
>
> .update_cpu_dirty_logging = svm_update_cpu_dirty_logging,
>
> .deliver_interrupt = svm_deliver_interrupt,
Ack, will fix.
>> @@ -832,6 +833,8 @@ static inline void svm_enable_intercept_for_msr(struct kvm_vcpu *vcpu,
>> svm_set_intercept_for_msr(vcpu, msr, type, true);
>> }
>>
>> +void svm_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
>
> And this goes away.
Ack.
Regards,
Nikunj
prev parent reply other threads:[~2026-09-02 8:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 4:59 [PATCH v7 0/7] KVM: SVM: Add Page Modification Logging (PML) support Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 1/7] KVM: VMX: Pass @vcpu, not @vmx to init_vmcs() Nikunj A Dadhania
2026-05-18 11:35 ` Huang, Kai
2026-05-18 4:59 ` [PATCH v7 2/7] KVM: x86: Move PML page to common vcpu arch structure Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 3/7] KVM: x86: Carve out PML flush routine Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 4/7] KVM: VMX: Use cpu_dirty_log_size instead of enable_pml for PML checks Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 5/7] x86/cpufeatures: Add Page modification logging Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 6/7] KVM: SVM: Use BIT_ULL for 64-bit misc_ctl bit definitions Nikunj A Dadhania
2026-05-18 4:59 ` [PATCH v7 7/7] KVM: SVM: Add Page modification logging support Nikunj A Dadhania
2026-05-18 17:12 ` Yosry Ahmed
2026-05-18 18:55 ` Sean Christopherson
2026-05-18 19:14 ` Yosry Ahmed
2026-05-18 19:25 ` Yosry Ahmed
2026-05-19 14:46 ` Nikunj A. Dadhania
2026-05-29 6:38 ` [PATCH v7.1] " Nikunj A Dadhania
2026-07-13 6:12 ` Nikunj A. Dadhania
2026-08-12 23:25 ` Sean Christopherson
2026-08-13 8:24 ` Nikunj A. Dadhania
2026-09-02 0:09 ` Sean Christopherson
2026-09-02 8:52 ` Nikunj A. Dadhania [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e22fa3d-b443-441f-8717-3c544f5aeb59@amd.com \
--to=nikunj@amd.com \
--cc=bp@alien8.de \
--cc=joao.m.martins@oracle.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox