From: Gavin Shan <gshan@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: maz@kernel.org, kvm@vger.kernel.org, catalin.marinas@arm.com,
andrew.jones@linux.dev, dmatlack@google.com, will@kernel.org,
shan.gavin@gmail.com, bgardon@google.com, kvmarm@lists.linux.dev,
pbonzini@redhat.com, zhenyzha@redhat.com, shuah@kernel.org,
kvmarm@lists.cs.columbia.edu, ajones@ventanamicro.com
Subject: Re: [PATCH v9 3/7] KVM: Support dirty ring in conjunction with bitmap
Date: Wed, 9 Nov 2022 06:19:36 +0800 [thread overview]
Message-ID: <49217b8f-ce53-c41b-98aa-ced34cd079cc@redhat.com> (raw)
In-Reply-To: <Y2qDCqFeL1vwqq3f@google.com>
Hi Sean,
On 11/9/22 12:25 AM, Sean Christopherson wrote:
> On Tue, Nov 08, 2022, Gavin Shan wrote:
>> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
>> index 800f9470e36b..228be1145cf3 100644
>> --- a/virt/kvm/Kconfig
>> +++ b/virt/kvm/Kconfig
>> @@ -33,6 +33,14 @@ config HAVE_KVM_DIRTY_RING_ACQ_REL
>> bool
>> select HAVE_KVM_DIRTY_RING
>>
>> +# Only architectures that need to dirty memory outside of a vCPU
>> +# context should select this, advertising to userspace the
>> +# requirement to use a dirty bitmap in addition to the vCPU dirty
>> +# ring.
>
> The Kconfig does more than advertise a feature to userspace.
>
> # Allow enabling both the dirty bitmap and dirty ring. Only architectures that
> # need to dirty memory outside of a vCPU context should select this.
>
Agreed. The comments will be adjusted accordingly.
>> +config HAVE_KVM_DIRTY_RING_WITH_BITMAP
>
> I think we should replace "HAVE" with "NEED". Any architecture that supports the
> dirty ring can easily support ring+bitmap, but based on the discussion from v5[*],
> the comment above, and the fact that the bitmap will _never_ be used in the
> proposed implementation because x86 will always have a vCPU, this Kconfig should
> only be selected if the bitmap is needed to support migration.
>
> [*] https://lore.kernel.org/all/Y0SxnoT5u7+1TCT+@google.com
>
Both look good to me. Lets change it to CONFIG_NEED_KVM_DIRTY_RING_WITH_BITMAP
then.
>> + bool
>> + depends on HAVE_KVM_DIRTY_RING
>> +
>> config HAVE_KVM_EVENTFD
>> bool
>> select EVENTFD
>> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
>> index fecbb7d75ad2..f95cbcdd74ff 100644
>> --- a/virt/kvm/dirty_ring.c
>> +++ b/virt/kvm/dirty_ring.c
>> @@ -21,6 +21,18 @@ u32 kvm_dirty_ring_get_rsvd_entries(void)
>> return KVM_DIRTY_RING_RSVD_ENTRIES + kvm_cpu_dirty_log_size();
>> }
>>
>> +bool kvm_use_dirty_bitmap(struct kvm *kvm)
>> +{
>> + lockdep_assert_held(&kvm->slots_lock);
>> +
>> + return !kvm->dirty_ring_size || kvm->dirty_ring_with_bitmap;
>> +}
>> +
>> +bool __weak kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm)
>
> Rather than __weak, what about wrapping this with an #ifdef to effectively force
> architectures to implement the override if they need ring+bitmap? Given that the
> bitmap will never be used if there's a running vCPU, selecting the Kconfig without
> overriding this utility can't possibly be correct.
>
> #ifndef CONFIG_NEED_KVM_DIRTY_RING_WITH_BITMAP
> bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm)
> {
> return false;
> }
> #endif
>
It's a good idea, which will be included to next revision :)
>> @@ -4588,6 +4608,29 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
>> return -EINVAL;
>>
>> return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]);
>> + case KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP: {
>> + int r = -EINVAL;
>> +
>> + if (!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_RING_WITH_BITMAP) ||
>> + !kvm->dirty_ring_size)
>
> I have no objection to disallowing userspace from disabling the combo, but I
> think it's worth requiring cap->args[0] to be '0' just in case we change our minds
> in the future.
>
I assume you're suggesting to have non-zero value in cap->args[0] to enable the
capability.
if (!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_RING_WITH_BITMAP) ||
!kvm->dirty_ring_size || !cap->args[0])
return r;
>> + return r;
>> +
>> + mutex_lock(&kvm->slots_lock);
>> +
>> + /*
>> + * For simplicity, allow enabling ring+bitmap if and only if
>> + * there are no memslots, e.g. to ensure all memslots allocate
>> + * a bitmap after the capability is enabled.
>> + */
>> + if (kvm_are_all_memslots_empty(kvm)) {
>> + kvm->dirty_ring_with_bitmap = true;
>> + r = 0;
>> + }
>> +
>> + mutex_unlock(&kvm->slots_lock);
>> +
>> + return r;
>> + }
>> default:
>> return kvm_vm_ioctl_enable_cap(kvm, cap);
>> }
Thanks,
Gavin
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
WARNING: multiple messages have this Message-ID (diff)
From: Gavin Shan <gshan@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu,
kvm@vger.kernel.org, shuah@kernel.org, catalin.marinas@arm.com,
andrew.jones@linux.dev, ajones@ventanamicro.com,
bgardon@google.com, dmatlack@google.com, will@kernel.org,
suzuki.poulose@arm.com, alexandru.elisei@arm.com,
pbonzini@redhat.com, maz@kernel.org, peterx@redhat.com,
oliver.upton@linux.dev, zhenyzha@redhat.com,
shan.gavin@gmail.com
Subject: Re: [PATCH v9 3/7] KVM: Support dirty ring in conjunction with bitmap
Date: Wed, 9 Nov 2022 06:19:36 +0800 [thread overview]
Message-ID: <49217b8f-ce53-c41b-98aa-ced34cd079cc@redhat.com> (raw)
Message-ID: <20221108221936.lMUTtQoJBB2chAUH5YvPRnI5p2kCQJuTlxgcVim6oak@z> (raw)
In-Reply-To: <Y2qDCqFeL1vwqq3f@google.com>
Hi Sean,
On 11/9/22 12:25 AM, Sean Christopherson wrote:
> On Tue, Nov 08, 2022, Gavin Shan wrote:
>> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
>> index 800f9470e36b..228be1145cf3 100644
>> --- a/virt/kvm/Kconfig
>> +++ b/virt/kvm/Kconfig
>> @@ -33,6 +33,14 @@ config HAVE_KVM_DIRTY_RING_ACQ_REL
>> bool
>> select HAVE_KVM_DIRTY_RING
>>
>> +# Only architectures that need to dirty memory outside of a vCPU
>> +# context should select this, advertising to userspace the
>> +# requirement to use a dirty bitmap in addition to the vCPU dirty
>> +# ring.
>
> The Kconfig does more than advertise a feature to userspace.
>
> # Allow enabling both the dirty bitmap and dirty ring. Only architectures that
> # need to dirty memory outside of a vCPU context should select this.
>
Agreed. The comments will be adjusted accordingly.
>> +config HAVE_KVM_DIRTY_RING_WITH_BITMAP
>
> I think we should replace "HAVE" with "NEED". Any architecture that supports the
> dirty ring can easily support ring+bitmap, but based on the discussion from v5[*],
> the comment above, and the fact that the bitmap will _never_ be used in the
> proposed implementation because x86 will always have a vCPU, this Kconfig should
> only be selected if the bitmap is needed to support migration.
>
> [*] https://lore.kernel.org/all/Y0SxnoT5u7+1TCT+@google.com
>
Both look good to me. Lets change it to CONFIG_NEED_KVM_DIRTY_RING_WITH_BITMAP
then.
>> + bool
>> + depends on HAVE_KVM_DIRTY_RING
>> +
>> config HAVE_KVM_EVENTFD
>> bool
>> select EVENTFD
>> diff --git a/virt/kvm/dirty_ring.c b/virt/kvm/dirty_ring.c
>> index fecbb7d75ad2..f95cbcdd74ff 100644
>> --- a/virt/kvm/dirty_ring.c
>> +++ b/virt/kvm/dirty_ring.c
>> @@ -21,6 +21,18 @@ u32 kvm_dirty_ring_get_rsvd_entries(void)
>> return KVM_DIRTY_RING_RSVD_ENTRIES + kvm_cpu_dirty_log_size();
>> }
>>
>> +bool kvm_use_dirty_bitmap(struct kvm *kvm)
>> +{
>> + lockdep_assert_held(&kvm->slots_lock);
>> +
>> + return !kvm->dirty_ring_size || kvm->dirty_ring_with_bitmap;
>> +}
>> +
>> +bool __weak kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm)
>
> Rather than __weak, what about wrapping this with an #ifdef to effectively force
> architectures to implement the override if they need ring+bitmap? Given that the
> bitmap will never be used if there's a running vCPU, selecting the Kconfig without
> overriding this utility can't possibly be correct.
>
> #ifndef CONFIG_NEED_KVM_DIRTY_RING_WITH_BITMAP
> bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm)
> {
> return false;
> }
> #endif
>
It's a good idea, which will be included to next revision :)
>> @@ -4588,6 +4608,29 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
>> return -EINVAL;
>>
>> return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]);
>> + case KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP: {
>> + int r = -EINVAL;
>> +
>> + if (!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_RING_WITH_BITMAP) ||
>> + !kvm->dirty_ring_size)
>
> I have no objection to disallowing userspace from disabling the combo, but I
> think it's worth requiring cap->args[0] to be '0' just in case we change our minds
> in the future.
>
I assume you're suggesting to have non-zero value in cap->args[0] to enable the
capability.
if (!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_RING_WITH_BITMAP) ||
!kvm->dirty_ring_size || !cap->args[0])
return r;
>> + return r;
>> +
>> + mutex_lock(&kvm->slots_lock);
>> +
>> + /*
>> + * For simplicity, allow enabling ring+bitmap if and only if
>> + * there are no memslots, e.g. to ensure all memslots allocate
>> + * a bitmap after the capability is enabled.
>> + */
>> + if (kvm_are_all_memslots_empty(kvm)) {
>> + kvm->dirty_ring_with_bitmap = true;
>> + r = 0;
>> + }
>> +
>> + mutex_unlock(&kvm->slots_lock);
>> +
>> + return r;
>> + }
>> default:
>> return kvm_vm_ioctl_enable_cap(kvm, cap);
>> }
Thanks,
Gavin
next prev parent reply other threads:[~2022-11-08 22:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 4:10 [PATCH v9 0/7] KVM: arm64: Enable ring-based dirty memory tracking Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 1/7] KVM: x86: Introduce KVM_REQ_DIRTY_RING_SOFT_FULL Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 2/7] KVM: Move declaration of kvm_cpu_dirty_log_size() to kvm_dirty_ring.h Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 3/7] KVM: Support dirty ring in conjunction with bitmap Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 16:25 ` Sean Christopherson
2022-11-08 16:25 ` Sean Christopherson
2022-11-08 22:19 ` Gavin Shan [this message]
2022-11-08 22:19 ` Gavin Shan
2022-11-09 0:05 ` Sean Christopherson
2022-11-09 0:05 ` Sean Christopherson
2022-11-09 0:17 ` Gavin Shan
2022-11-09 0:17 ` Gavin Shan
2022-11-09 0:32 ` Sean Christopherson
2022-11-09 0:32 ` Sean Christopherson
2022-11-09 0:51 ` Gavin Shan
2022-11-09 0:51 ` Gavin Shan
2022-11-10 10:25 ` Marc Zyngier
2022-11-10 10:25 ` Marc Zyngier
2022-11-10 10:56 ` Gavin Shan
2022-11-10 10:56 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 4/7] KVM: arm64: Enable ring-based dirty memory tracking Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 5/7] KVM: selftests: Use host page size to map ring buffer in dirty_log_test Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 6/7] KVM: selftests: Clear dirty ring states between two modes " Gavin Shan
2022-11-08 4:10 ` Gavin Shan
2022-11-08 4:10 ` [PATCH v9 7/7] KVM: selftests: Automate choosing dirty ring size " Gavin Shan
2022-11-08 4:10 ` Gavin Shan
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=49217b8f-ce53-c41b-98aa-ced34cd079cc@redhat.com \
--to=gshan@redhat.com \
--cc=ajones@ventanamicro.com \
--cc=andrew.jones@linux.dev \
--cc=bgardon@google.com \
--cc=catalin.marinas@arm.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shan.gavin@gmail.com \
--cc=shuah@kernel.org \
--cc=will@kernel.org \
--cc=zhenyzha@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.