Skip to content

Commit

Permalink
context_tracking: move rcu_virt_note_context_switch out of kvm_host.h
Browse files Browse the repository at this point in the history
Make kvm_guest_{enter,exit} and __kvm_guest_{enter,exit} trivial wrappers
around the code in context_tracking.h.  Name the context_tracking.h functions
consistently with what those for kernel<->user switch.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Paolo Bonzini committed Jun 28, 2016
1 parent fb6cec1 commit ebaac17
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
38 changes: 34 additions & 4 deletions include/linux/context_tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ static inline void context_tracking_init(void) { }


#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
static inline void guest_enter(void)
/* must be called with irqs disabled */
static inline void guest_enter_irqoff(void)
{
if (vtime_accounting_cpu_enabled())
vtime_guest_enter(current);
Expand All @@ -93,9 +94,19 @@ static inline void guest_enter(void)

if (context_tracking_is_enabled())
__context_tracking_enter(CONTEXT_GUEST);

/* 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 userspace 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.
*/
if (!context_tracking_cpu_is_enabled())
rcu_virt_note_context_switch(smp_processor_id());
}

static inline void guest_exit(void)
static inline void guest_exit_irqoff(void)
{
if (context_tracking_is_enabled())
__context_tracking_exit(CONTEXT_GUEST);
Expand All @@ -107,7 +118,7 @@ static inline void guest_exit(void)
}

#else
static inline void guest_enter(void)
static inline void guest_enter_irqoff(void)
{
/*
* This is running in ioctl context so its safe
Expand All @@ -116,14 +127,33 @@ static inline void guest_enter(void)
*/
vtime_account_system(current);
current->flags |= PF_VCPU;
rcu_virt_note_context_switch(smp_processor_id());
}

static inline void guest_exit(void)
static inline void guest_exit_irqoff(void)
{
/* Flush the guest cputime we spent on the guest */
vtime_account_system(current);
current->flags &= ~PF_VCPU;
}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */

static inline void guest_enter(void)
{
unsigned long flags;

local_irq_save(flags);
guest_enter_irqoff();
local_irq_restore(flags);
}

static inline void guest_exit(void)
{
unsigned long flags;

local_irq_save(flags);
guest_exit_irqoff();
local_irq_restore(flags);
}

#endif
25 changes: 4 additions & 21 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,40 +878,23 @@ static inline void kvm_iommu_unmap_pages(struct kvm *kvm,
/* must be called with irqs disabled */
static inline void __kvm_guest_enter(void)
{
guest_enter();
/* 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 userspace 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.
*/
if (!context_tracking_cpu_is_enabled())
rcu_virt_note_context_switch(smp_processor_id());
guest_enter_irqoff();
}

/* must be called with irqs disabled */
static inline void __kvm_guest_exit(void)
{
guest_exit();
guest_exit_irqoff();
}

static inline void kvm_guest_enter(void)
{
unsigned long flags;

local_irq_save(flags);
__kvm_guest_enter();
local_irq_restore(flags);
guest_enter();
}

static inline void kvm_guest_exit(void)
{
unsigned long flags;

local_irq_save(flags);
__kvm_guest_exit();
local_irq_restore(flags);
guest_exit();
}

/*
Expand Down

0 comments on commit ebaac17

Please sign in to comment.