Re: [PATCH v3] KVM: x86: enable dirty log gradually in small chunks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 26, 2020 at 04:59:40AM +0000, Zhoujian (jay) wrote:
> 
> 
> > -----Original Message-----
> > From: Peter Xu [mailto:peterx@xxxxxxxxxx]
> 
> [...]
> 
> > > > > > @@ -3320,6 +3326,10 @@ static long
> > > > > kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
> > > > > >  	case KVM_CAP_COALESCED_PIO:
> > > > > >  		return 1;
> > > > > >  #endif
> > > > > > +#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
> > > > > > +	case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2:
> > > > > > +		return KVM_DIRTY_LOG_MANUAL_CAPS;
> > > > >
> > > > > We probably can only return the new feature bit when with CONFIG_X86?
> 
> Since the meaning of KVM_DIRTY_LOG_MANUAL_CAPS will change accordingly in
> different archs, we can use it in kvm_vm_ioctl_enable_cap_generic, how about:
> 
> @@ -3347,11 +3351,17 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
>  {
>         switch (cap->cap) {
>  #ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
> -       case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2:
> -               if (cap->flags || (cap->args[0] & ~1))
> +       case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2: {
> +               u64 allowed_options = KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE;
> +
> +               if (cap->args[0] & KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE)
> +                       allowed_options = KVM_DIRTY_LOG_MANUAL_CAPS;
> +
> +               if (cap->flags || (cap->args[0] & ~allowed_options))
>                         return -EINVAL;
>                 kvm->manual_dirty_log_protect = cap->args[0];
>                 return 0;
> +       }

Looks good to me.

> 
> [...]
> 
> >> How about:
> > >
> > > ==========
> > >
> > > diff --git a/arch/x86/include/asm/kvm_host.h
> > > b/arch/x86/include/asm/kvm_host.h index 40a0c0fd95ca..fcffaf8a6964
> > > 100644
> > > --- a/arch/x86/include/asm/kvm_host.h
> > > +++ b/arch/x86/include/asm/kvm_host.h
> > > @@ -1697,4 +1697,7 @@ static inline int kvm_cpu_get_apicid(int mps_cpu)
> > >  #define GET_SMSTATE(type, buf, offset)         \
> > >         (*(type *)((buf) + (offset) - 0x7e00))
> > >
> > > +#define KVM_DIRTY_LOG_MANUAL_CAPS
> > (KVM_DIRTY_LOG_MANUAL_PROTECT | \
> > > +
> > KVM_DIRTY_LOG_INITIALLY_SET)
> > > +
> > >  #endif /* _ASM_X86_KVM_HOST_H */
> > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index
> > > e89eb67356cb..39d49802ee87 100644
> > > --- a/include/linux/kvm_host.h
> > > +++ b/include/linux/kvm_host.h
> > > @@ -1410,4 +1410,8 @@ int kvm_vm_create_worker_thread(struct kvm *kvm,
> > kvm_vm_thread_fn_t thread_fn,
> > >                                 uintptr_t data, const char *name,
> > >                                 struct task_struct **thread_ptr);
> > >
> > > +#ifndef KVM_DIRTY_LOG_MANUAL_CAPS
> > > +#define KVM_DIRTY_LOG_MANUAL_CAPS
> > KVM_DIRTY_LOG_MANUAL_PROTECT
> > > +#endif
> > > +
> > 
> > Hmm... Maybe this won't work, because I saw that asm/kvm_host.h and
> > linux/kvm_host.h has no dependency between each other (which I thought they
> > had).  Right now in most cases linux/ header can be included earlier than the
> > asm/ header in C files.  So intead, maybe we can move these lines into
> > kvm_main.c directly.
> 
> I did some tests on x86, and it works. Looks good to me.
> 
> > 
> > (I'm thinking ideally linux/kvm_host.h should include asm/kvm_host.h  within
> > itself, then C files should not include asm/kvm_host.h  directly. However I dare
> > not try that right now without being able to  test compile on all archs...)
> > 
> But, I see include/linux/kvm_host.h has already included asm/kvm_host.h in the
> upstream. Do I understand your meaning correctly?

Oh you are right, my eyeball missed that... :)

Then we should be able to remove the asm/kvm_host.h in most of the C
files.  I'll prepare a patch for it.

Thanks,

-- 
Peter Xu




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux