kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neo Jia <cjia@nvidia.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Xiaoguang Chen <xiaoguang.chen@intel.com>
Cc: <kvm@vger.kernel.org>, <guangrong.xiao@intel.com>,
	<jike.song@intel.com>, Kirti Wankhede <kwankhede@nvidia.com>
Subject: Re: [PATCH 1/2] KVM: page track: add a new notifier type: track_flush_slot
Date: Mon, 10 Oct 2016 11:01:41 -0700	[thread overview]
Message-ID: <20161010180140.GA27757@nvidia.com> (raw)
In-Reply-To: <ad547eac-428c-751b-05c4-52002d78ecb4@redhat.com>

On Mon, Oct 10, 2016 at 07:06:27PM +0200, Paolo Bonzini wrote:
> 
> 
> On 09/10/2016 10:31, Neo Jia wrote:
> > On Sun, Oct 09, 2016 at 03:41:43PM +0800, Xiaoguang Chen wrote:
> >> When a memory slot is being moved or removed users of page track
> >> can be notified. So users can drop write-protection for the pages
> >> in that memory slot.
> >>
> >> This notifier type is needed by KVMGT to sync up its shadow page
> >> table when memory slot is being moved or removed.
> > 
> > Hi Xiaoguang,
> > 
> > How is this supposed to be used by the kvmgt?
> 
> Hi Neo,
> 
> AFAIK this is needed because KVMGT doesn't paravirtualize the PPGTT,
> while nVidia does.

> "From Xiaoguang:

> This is related to KVMGT device model.
> For KVMGT some ram will be allocated and used as ppgtt page table and
> the page table is write protected.
> We use page track to implement write protect. But get problem while
> memslot is moved or removed.
> We must clear the write protect for the pages in the memslot or there
> will be errors while ppgtt do cleanup.
> So KVMGT must register the track_flush_slot to get notified while
> memslot is moved or removed."

(merging thread)

Hi Paolo and Xiaoguang,

I am just wondering how device driver can register a notifier so he can be 
notified for write-protected pages when writes are happening.

Thanks,
Neo

> 
> Paolo
> 
> > Thanks,
> > Neo
> > 
> >>
> >> Reviewed-by: Xiao Guangrong <guangrong.xiao@intel.com>
> >> Signed-off-by: Chen Xiaoguang <xiaoguang.chen@intel.com>
> >> ---
> >>  arch/x86/include/asm/kvm_page_track.h |  9 +++++++++
> >>  arch/x86/kvm/page_track.c             | 25 +++++++++++++++++++++++++
> >>  arch/x86/kvm/x86.c                    |  2 +-
> >>  3 files changed, 35 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h
> >> index c2b8d24..5f66597 100644
> >> --- a/arch/x86/include/asm/kvm_page_track.h
> >> +++ b/arch/x86/include/asm/kvm_page_track.h
> >> @@ -32,6 +32,14 @@ struct kvm_page_track_notifier_node {
> >>  	 */
> >>  	void (*track_write)(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
> >>  			    int bytes);
> >> +	/*
> >> +	 * It is called when memory slot is being moved or removed
> >> +	 * users can drop write-protection for the pages in that memory slot
> >> +	 *
> >> +	 * @kvm: the kvm where memory slot being moved or removed
> >> +	 * @slot: the memory slot being moved or removed
> >> +	 */
> >> +	void (*track_flush_slot)(struct kvm *kvm, struct kvm_memory_slot *slot);
> >>  };
> >>  
> >>  void kvm_page_track_init(struct kvm *kvm);
> >> @@ -58,4 +66,5 @@ kvm_page_track_unregister_notifier(struct kvm *kvm,
> >>  				   struct kvm_page_track_notifier_node *n);
> >>  void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
> >>  			  int bytes);
> >> +void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot);
> >>  #endif
> >> diff --git a/arch/x86/kvm/page_track.c b/arch/x86/kvm/page_track.c
> >> index b431539..e79bb25 100644
> >> --- a/arch/x86/kvm/page_track.c
> >> +++ b/arch/x86/kvm/page_track.c
> >> @@ -225,3 +225,28 @@ void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
> >>  			n->track_write(vcpu, gpa, new, bytes);
> >>  	srcu_read_unlock(&head->track_srcu, idx);
> >>  }
> >> +
> >> +/*
> >> + * Notify the node that memory slot is being removed or moved so that it can
> >> + * drop write-protection for the pages in the memory slot.
> >> + *
> >> + * The node should figure out it has any write-protected pages in this slot
> >> + * by itself.
> >> + */
> >> +void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot)
> >> +{
> >> +	struct kvm_page_track_notifier_head *head;
> >> +	struct kvm_page_track_notifier_node *n;
> >> +	int idx;
> >> +
> >> +	head = &kvm->arch.track_notifier_head;
> >> +
> >> +	if (hlist_empty(&head->track_notifier_list))
> >> +		return;
> >> +
> >> +	idx = srcu_read_lock(&head->track_srcu);
> >> +	hlist_for_each_entry_rcu(n, &head->track_notifier_list, node)
> >> +		if (n->track_flush_slot)
> >> +			n->track_flush_slot(kvm, slot);
> >> +	srcu_read_unlock(&head->track_srcu, idx);
> >> +}
> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> >> index 87f5dbb..f8ae90c 100644
> >> --- a/arch/x86/kvm/x86.c
> >> +++ b/arch/x86/kvm/x86.c
> >> @@ -8278,7 +8278,7 @@ void kvm_arch_flush_shadow_all(struct kvm *kvm)
> >>  void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
> >>  				   struct kvm_memory_slot *slot)
> >>  {
> >> -	kvm_mmu_invalidate_zap_all_pages(kvm);
> >> +	kvm_page_track_flush_slot(kvm, slot);
> >>  }
> >>  
> >>  static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
> >> -- 
> >> 1.9.1
> >>
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe kvm" in
> >> the body of a message to majordomo@vger.kernel.org
> >> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2016-10-10 18:01 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-09  7:41 [PATCH 0/2] page track add notifier type track_flush_slot Xiaoguang Chen
2016-10-09  7:41 ` [PATCH 1/2] KVM: page track: add a new notifier type: track_flush_slot Xiaoguang Chen
2016-10-09  8:31   ` Neo Jia
2016-10-09  8:56     ` Chen, Xiaoguang
2016-10-10 17:06     ` Paolo Bonzini
2016-10-10 18:01       ` Neo Jia [this message]
2016-10-10 18:32         ` Paolo Bonzini
2016-10-11  2:39           ` Xiao Guangrong
2016-10-11  8:54             ` Paolo Bonzini
2016-10-11  9:21               ` Xiao Guangrong
2016-10-11  9:47                 ` Paolo Bonzini
2016-10-14 10:37                   ` Jike Song
2016-10-14 10:43                     ` Paolo Bonzini
2016-10-14 12:26                       ` Jike Song
2016-10-14 14:41                     ` [Qemu-devel] " Alex Williamson
2016-10-14 14:46                       ` Alex Williamson
2016-10-14 16:35                         ` [Qemu-devel] " Neo Jia
2016-10-14 16:51                           ` Alex Williamson
2016-10-14 22:19                             ` Neo Jia
2016-10-17 16:02                               ` Alex Williamson
2016-10-18 12:38                                 ` Jike Song
2016-10-18 14:59                                   ` Alex Williamson
2016-10-19  2:32                                     ` Jike Song
2016-10-19  5:45                                       ` Xiao Guangrong
2016-10-19 11:56                                         ` Paolo Bonzini
2016-10-19 13:39                                           ` Xiao Guangrong
2016-10-19 14:14                                             ` Paolo Bonzini
2016-10-20  1:48                                               ` [Qemu-devel] " Xiao Guangrong
2016-10-20 17:06                                                 ` Paolo Bonzini
2016-10-20 17:19                                                   ` Xiao, Guangrong
2016-10-21  2:47                                                     ` [Qemu-devel] " Jike Song
2016-10-26 13:44                                                   ` Jike Song
2016-10-26 14:45                                                     ` Paolo Bonzini
2016-10-29  4:07                                                       ` Jike Song
2016-10-19 13:56                                       ` Eric Blake
2016-10-24  6:32                                         ` [Qemu-devel] " Jike Song
2016-10-12 20:48   ` Radim Krčmář
2016-10-09  7:41 ` [PATCH 2/2] KVM: MMU: apply page track notifier type track_flush_slot Xiaoguang Chen
2016-10-10 17:06 ` [PATCH 0/2] page track add " Paolo Bonzini
2016-10-11  2:43   ` Xiao Guangrong
2016-10-11  8:55     ` Paolo Bonzini
2016-10-12 20:52       ` Radim Krčmář

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=20161010180140.GA27757@nvidia.com \
    --to=cjia@nvidia.com \
    --cc=guangrong.xiao@intel.com \
    --cc=jike.song@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=pbonzini@redhat.com \
    --cc=xiaoguang.chen@intel.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).