diff mbox

[2/2] KVM: make guest mode entry to be rcu quiescent state

Message ID 1303984323-3203-3-git-send-email-gleb@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gleb Natapov April 28, 2011, 9:52 a.m. UTC
KVM does not hold any references to rcu protected data when it switches
CPU into a guest mode. In fact switching to a guest mode is very similar
to exiting to userspase from rcu point of view. In addition CPU may stay
in a guest mode for quite a long time (up to one time slice). Lets treat
guest mode as quiescent state, just like we do with user-mode execution.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 include/linux/kvm_host.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

Comments

Marcelo Tosatti May 3, 2011, 1:13 p.m. UTC | #1
Hi Gleb,

Thats a neat idea.

On Thu, Apr 28, 2011 at 12:52:03PM +0300, Gleb Natapov wrote:
> KVM does not hold any references to rcu protected data when it switches
> CPU into a guest mode. In fact switching to a guest mode is very similar
> to exiting to userspase from rcu point of view. In addition CPU may stay
> in a guest mode for quite a long time (up to one time slice). Lets treat
> guest mode as quiescent state, just like we do with user-mode execution.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
>  include/linux/kvm_host.h |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 0bc3d37..a347bce 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -593,6 +593,7 @@ static inline void kvm_guest_enter(void)
>  {
>  	account_system_vtime(current);
>  	current->flags |= PF_VCPU;
> +	rcu_note_context_switch(smp_processor_id());
>  }
>  
>  static inline void kvm_guest_exit(void)
> -- 
> 1.7.2.3

Please have it in x86's vcpu_enter_guest, then its more explicit
(uncertain about the context of kvm_guest_enter call in other arches).


--
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
Avi Kivity May 3, 2011, 1:20 p.m. UTC | #2
On 05/03/2011 04:13 PM, Marcelo Tosatti wrote:
> Please have it in x86's vcpu_enter_guest, then its more explicit
> (uncertain about the context of kvm_guest_enter call in other arches).

We do need it for other archs, don't we?
Gleb Natapov May 3, 2011, 1:21 p.m. UTC | #3
On Tue, May 03, 2011 at 10:13:17AM -0300, Marcelo Tosatti wrote:
> Hi Gleb,
> 
> Thats a neat idea.
> 
> On Thu, Apr 28, 2011 at 12:52:03PM +0300, Gleb Natapov wrote:
> > KVM does not hold any references to rcu protected data when it switches
> > CPU into a guest mode. In fact switching to a guest mode is very similar
> > to exiting to userspase from rcu point of view. In addition CPU may stay
> > in a guest mode for quite a long time (up to one time slice). Lets treat
> > guest mode as quiescent state, just like we do with user-mode execution.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > ---
> >  include/linux/kvm_host.h |    1 +
> >  1 files changed, 1 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > index 0bc3d37..a347bce 100644
> > --- a/include/linux/kvm_host.h
> > +++ b/include/linux/kvm_host.h
> > @@ -593,6 +593,7 @@ static inline void kvm_guest_enter(void)
> >  {
> >  	account_system_vtime(current);
> >  	current->flags |= PF_VCPU;
> > +	rcu_note_context_switch(smp_processor_id());
> >  }
> >  
> >  static inline void kvm_guest_exit(void)
> > -- 
> > 1.7.2.3
> 
> Please have it in x86's vcpu_enter_guest, then its more explicit
> (uncertain about the context of kvm_guest_enter call in other arches).
> 
I checked all of them and kvm_guest_enter() is always called with local
irq disabled. Paul confirmed that rcu_note_context_switch() can be
called in such context.

--
			Gleb.
--
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
Marcelo Tosatti May 3, 2011, 1:29 p.m. UTC | #4
On Tue, May 03, 2011 at 04:21:23PM +0300, Gleb Natapov wrote:
> On Tue, May 03, 2011 at 10:13:17AM -0300, Marcelo Tosatti wrote:
> > Hi Gleb,
> > 
> > Thats a neat idea.
> > 
> > On Thu, Apr 28, 2011 at 12:52:03PM +0300, Gleb Natapov wrote:
> > > KVM does not hold any references to rcu protected data when it switches
> > > CPU into a guest mode. In fact switching to a guest mode is very similar
> > > to exiting to userspase from rcu point of view. In addition CPU may stay
> > > in a guest mode for quite a long time (up to one time slice). Lets treat
> > > guest mode as quiescent state, just like we do with user-mode execution.
> > > 
> > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > ---
> > >  include/linux/kvm_host.h |    1 +
> > >  1 files changed, 1 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > > index 0bc3d37..a347bce 100644
> > > --- a/include/linux/kvm_host.h
> > > +++ b/include/linux/kvm_host.h
> > > @@ -593,6 +593,7 @@ static inline void kvm_guest_enter(void)
> > >  {
> > >  	account_system_vtime(current);
> > >  	current->flags |= PF_VCPU;
> > > +	rcu_note_context_switch(smp_processor_id());
> > >  }
> > >  
> > >  static inline void kvm_guest_exit(void)
> > > -- 
> > > 1.7.2.3
> > 
> > Please have it in x86's vcpu_enter_guest, then its more explicit
> > (uncertain about the context of kvm_guest_enter call in other arches).
> > 
> I checked all of them and kvm_guest_enter() is always called with local
> irq disabled. Paul confirmed that rcu_note_context_switch() can be
> called in such context.

OK then. Perhaps have an assert to verify interrupts are disabled?

--
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
Gleb Natapov May 3, 2011, 1:39 p.m. UTC | #5
On Tue, May 03, 2011 at 10:29:52AM -0300, Marcelo Tosatti wrote:
> On Tue, May 03, 2011 at 04:21:23PM +0300, Gleb Natapov wrote:
> > On Tue, May 03, 2011 at 10:13:17AM -0300, Marcelo Tosatti wrote:
> > > Hi Gleb,
> > > 
> > > Thats a neat idea.
> > > 
> > > On Thu, Apr 28, 2011 at 12:52:03PM +0300, Gleb Natapov wrote:
> > > > KVM does not hold any references to rcu protected data when it switches
> > > > CPU into a guest mode. In fact switching to a guest mode is very similar
> > > > to exiting to userspase from rcu point of view. In addition CPU may stay
> > > > in a guest mode for quite a long time (up to one time slice). Lets treat
> > > > guest mode as quiescent state, just like we do with user-mode execution.
> > > > 
> > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > > ---
> > > >  include/linux/kvm_host.h |    1 +
> > > >  1 files changed, 1 insertions(+), 0 deletions(-)
> > > > 
> > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > > > index 0bc3d37..a347bce 100644
> > > > --- a/include/linux/kvm_host.h
> > > > +++ b/include/linux/kvm_host.h
> > > > @@ -593,6 +593,7 @@ static inline void kvm_guest_enter(void)
> > > >  {
> > > >  	account_system_vtime(current);
> > > >  	current->flags |= PF_VCPU;
> > > > +	rcu_note_context_switch(smp_processor_id());
> > > >  }
> > > >  
> > > >  static inline void kvm_guest_exit(void)
> > > > -- 
> > > > 1.7.2.3
> > > 
> > > Please have it in x86's vcpu_enter_guest, then its more explicit
> > > (uncertain about the context of kvm_guest_enter call in other arches).
> > > 
> > I checked all of them and kvm_guest_enter() is always called with local
> > irq disabled. Paul confirmed that rcu_note_context_switch() can be
> > called in such context.
> 
> OK then. Perhaps have an assert to verify interrupts are disabled?
Yes. Can add BUG_ON(preemptible()).

--
			Gleb.
--
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
Marcelo Tosatti May 3, 2011, 3:42 p.m. UTC | #6
On Tue, May 03, 2011 at 04:39:01PM +0300, Gleb Natapov wrote:
> > > > On Thu, Apr 28, 2011 at 12:52:03PM +0300, Gleb Natapov wrote:
> > > > > KVM does not hold any references to rcu protected data when it switches
> > > > > CPU into a guest mode. In fact switching to a guest mode is very similar
> > > > > to exiting to userspase from rcu point of view. In addition CPU may stay
> > > > > in a guest mode for quite a long time (up to one time slice). Lets treat
> > > > > guest mode as quiescent state, just like we do with user-mode execution.
> > > > > 
> > > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > > > ---
> > > > >  include/linux/kvm_host.h |    1 +
> > > > >  1 files changed, 1 insertions(+), 0 deletions(-)
> > > > > 
> > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > > > > index 0bc3d37..a347bce 100644
> > > > > --- a/include/linux/kvm_host.h
> > > > > +++ b/include/linux/kvm_host.h
> > > > > @@ -593,6 +593,7 @@ static inline void kvm_guest_enter(void)
> > > > >  {
> > > > >  	account_system_vtime(current);
> > > > >  	current->flags |= PF_VCPU;
> > > > > +	rcu_note_context_switch(smp_processor_id());
> > > > >  }
> > > > >  
> > > > >  static inline void kvm_guest_exit(void)
> > > > > -- 
> > > > > 1.7.2.3
> > > > 
> > > > Please have it in x86's vcpu_enter_guest, then its more explicit
> > > > (uncertain about the context of kvm_guest_enter call in other arches).
> > > > 
> > > I checked all of them and kvm_guest_enter() is always called with local
> > > irq disabled. Paul confirmed that rcu_note_context_switch() can be
> > > called in such context.
> > 
> > OK then. Perhaps have an assert to verify interrupts are disabled?
> Yes. Can add BUG_ON(preemptible()).

Also please add a comment to explain whats going on. The commit message
above seems appropriate.

--
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
diff mbox

Patch

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 0bc3d37..a347bce 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -593,6 +593,7 @@  static inline void kvm_guest_enter(void)
 {
 	account_system_vtime(current);
 	current->flags |= PF_VCPU;
+	rcu_note_context_switch(smp_processor_id());
 }
 
 static inline void kvm_guest_exit(void)