From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Zhuangyanying <ann.zhuangyanying@huawei.com>
Cc: "xiaoguangrong@tencent.com" <xiaoguangrong@tencent.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"wangxin (U)" <wangxinxin.wang@huawei.com>,
"Liujinsong (Paul)" <liu.jinsong@huawei.com>,
"Zhoujian (jay)" <jianjay.zhou@huawei.com>,
"xiaoguangrong.eric@gmail.com" <xiaoguangrong.eric@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 4/4] KVM: MMU: fast cleanup D bit based on fast write protect
Date: Tue, 22 Jan 2019 07:17:08 -0800 [thread overview]
Message-ID: <20190122151708.GB28513@linux.intel.com> (raw)
In-Reply-To: <EC9759BC1E3E98429B5DE9A03DF86D8B59E9BBD4@DGGEML523-MBX.china.huawei.com>
On Mon, Jan 21, 2019 at 06:37:36AM +0000, Zhuangyanying wrote:
>
> > > u64 wp_all_indicator, kvm_wp_all_gen;
> > >
> > > - mutex_lock(&kvm->slots_lock);
> > > wp_all_indicator = get_write_protect_all_indicator(kvm);
> > > kvm_wp_all_gen = get_write_protect_all_gen(wp_all_indicator);
> > >
> > > @@ -6134,8 +6136,8 @@ void kvm_mmu_write_protect_all_pages(struct
> > kvm *kvm, bool write_protect)
> > > */
> > > if (write_protect)
> > > kvm_reload_remote_mmus(kvm);
> > > - mutex_unlock(&kvm->slots_lock);
> >
> > Why is the lock removed? And why was it added in the first place?
> >
> The original purpose of fast write protect is to implement lock-free get_dirty_log,
> kvm_mmu_write_protect_all_pages is a stand-alone kvm API. See
> https://lists.gnu.org/archive/html/qemu-devel/2017-06/msg04370.html
> A total of 7 patches, I only need the first 3 patches to achieve step-by-step
> page table traversal. In order to maintain the integrity of the xiaoguangrong
> patch, I did not directly modify it on his patch.
That's not a sufficient argument for adding locking and removing it one
patch later.
> > > }
> > > +EXPORT_SYMBOL_GPL(kvm_mmu_write_protect_all_pages);
> > >
> > > static unsigned long
> > > mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
> > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index
> > > f6915f1..5236a07 100644
> > > --- a/arch/x86/kvm/vmx/vmx.c
> > > +++ b/arch/x86/kvm/vmx/vmx.c
> > > @@ -7180,8 +7180,7 @@ static void vmx_sched_in(struct kvm_vcpu *vcpu,
> > > int cpu) static void vmx_slot_enable_log_dirty(struct kvm *kvm,
> > > struct kvm_memory_slot *slot) {
> > > - kvm_mmu_slot_leaf_clear_dirty(kvm, slot);
> > > - kvm_mmu_slot_largepage_remove_write_access(kvm, slot);
> > > + kvm_mmu_write_protect_all_pages(kvm, true);
> >
> > What's the purpose of having @write_protect if
> > kvm_mmu_write_protect_all_pages() is only ever called to enable
> > protection? If there's no known scenario where write protection is
> > explicitly disabled then there's no need for WP_ALL_ENABLE_MASK, i.e. a
> > non-zero generation would indicate write protection is enabled. That'd
> > simplify the code and clean up the atomic usage.
> >
> In the live migration, The large page split depends on the creation of memslot->dirty_bitmap
> in the function __kvm_set_memory_region().
> The interface design between qemu and kvm to enable dirty log is one by one in slot units.
> In order to enable dirty page tracking of the entire vm, it is necessary to call
> kvm_mmu_write_protect_all_pages multiple times. The page table update request can
> be merged for processing by the atomic usage. This method is not elegant, but it works.
> Complete the creation of all solt's dirty_bitmap in an API, just call
> kvm_mmu_write_protect_all_pages once, need more implementation changes, even qemu.
Calling kvm_mmu_write_protect_all_pages() multiple times is fine. My
question was regarding the 'write_protect' parameter. If all callers
always pass %true for 'write_protect' then why does the parameter exist?
And eliminating the parameter means you don't need an 'enable' flag
buried in the generation, which would simplify the implementation.
next prev parent reply other threads:[~2019-01-22 18:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 13:55 [Qemu-devel] [PATCH 0/4] KVM: MMU: fast cleanup D bit based on fast write protect Zhuangyanying
2019-01-17 13:55 ` [Qemu-devel] [PATCH 1/4] KVM: MMU: correct the behavior of mmu_spte_update_no_track Zhuangyanying
2019-01-17 15:44 ` Sean Christopherson
2019-01-17 13:55 ` [Qemu-devel] [PATCH 2/4] KVM: MMU: introduce possible_writable_spte_bitmap Zhuangyanying
2019-01-17 15:55 ` Sean Christopherson
2019-01-17 13:55 ` [Qemu-devel] [PATCH 3/4] KVM: MMU: introduce kvm_mmu_write_protect_all_pages Zhuangyanying
2019-01-17 16:09 ` Sean Christopherson
2019-01-17 13:55 ` [Qemu-devel] [PATCH 4/4] KVM: MMU: fast cleanup D bit based on fast write protect Zhuangyanying
2019-01-17 16:32 ` Sean Christopherson
2019-01-21 6:37 ` Zhuangyanying
2019-01-22 15:17 ` Sean Christopherson [this message]
2019-01-23 18:38 ` Zhuangyanying
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=20190122151708.GB28513@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=ann.zhuangyanying@huawei.com \
--cc=arei.gonglei@huawei.com \
--cc=jianjay.zhou@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=liu.jinsong@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wangxinxin.wang@huawei.com \
--cc=xiaoguangrong.eric@gmail.com \
--cc=xiaoguangrong@tencent.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).