Skip to content

Commit 1ca0016

Browse files
sean-jcKAGA-KOKO
authored andcommitted
context_tracking: KVM: Move guest enter/exit wrappers to KVM's domain
Move the guest enter/exit wrappers to kvm_host.h so that KVM can manage its context tracking vs. vtime accounting without bleeding too many KVM details into the context tracking code. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 14296e0 commit 1ca0016

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

include/linux/context_tracking.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -118,49 +118,4 @@ extern void context_tracking_init(void);
118118
static inline void context_tracking_init(void) { }
119119
#endif /* CONFIG_CONTEXT_TRACKING_FORCE */
120120

121-
/* must be called with irqs disabled */
122-
static __always_inline void guest_enter_irqoff(void)
123-
{
124-
/*
125-
* This is running in ioctl context so its safe to assume that it's the
126-
* stime pending cputime to flush.
127-
*/
128-
instrumentation_begin();
129-
vtime_account_guest_enter();
130-
instrumentation_end();
131-
132-
/*
133-
* KVM does not hold any references to rcu protected data when it
134-
* switches CPU into a guest mode. In fact switching to a guest mode
135-
* is very similar to exiting to userspace from rcu point of view. In
136-
* addition CPU may stay in a guest mode for quite a long time (up to
137-
* one time slice). Lets treat guest mode as quiescent state, just like
138-
* we do with user-mode execution.
139-
*/
140-
if (!context_tracking_guest_enter()) {
141-
instrumentation_begin();
142-
rcu_virt_note_context_switch(smp_processor_id());
143-
instrumentation_end();
144-
}
145-
}
146-
147-
static __always_inline void guest_exit_irqoff(void)
148-
{
149-
context_tracking_guest_exit();
150-
151-
instrumentation_begin();
152-
/* Flush the guest cputime we spent on the guest */
153-
vtime_account_guest_exit();
154-
instrumentation_end();
155-
}
156-
157-
static inline void guest_exit(void)
158-
{
159-
unsigned long flags;
160-
161-
local_irq_save(flags);
162-
guest_exit_irqoff();
163-
local_irq_restore(flags);
164-
}
165-
166121
#endif

include/linux/kvm_host.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,51 @@ struct kvm_vcpu {
338338
struct kvm_dirty_ring dirty_ring;
339339
};
340340

341+
/* must be called with irqs disabled */
342+
static __always_inline void guest_enter_irqoff(void)
343+
{
344+
/*
345+
* This is running in ioctl context so its safe to assume that it's the
346+
* stime pending cputime to flush.
347+
*/
348+
instrumentation_begin();
349+
vtime_account_guest_enter();
350+
instrumentation_end();
351+
352+
/*
353+
* KVM does not hold any references to rcu protected data when it
354+
* switches CPU into a guest mode. In fact switching to a guest mode
355+
* is very similar to exiting to userspace from rcu point of view. In
356+
* addition CPU may stay in a guest mode for quite a long time (up to
357+
* one time slice). Lets treat guest mode as quiescent state, just like
358+
* we do with user-mode execution.
359+
*/
360+
if (!context_tracking_guest_enter()) {
361+
instrumentation_begin();
362+
rcu_virt_note_context_switch(smp_processor_id());
363+
instrumentation_end();
364+
}
365+
}
366+
367+
static __always_inline void guest_exit_irqoff(void)
368+
{
369+
context_tracking_guest_exit();
370+
371+
instrumentation_begin();
372+
/* Flush the guest cputime we spent on the guest */
373+
vtime_account_guest_exit();
374+
instrumentation_end();
375+
}
376+
377+
static inline void guest_exit(void)
378+
{
379+
unsigned long flags;
380+
381+
local_irq_save(flags);
382+
guest_exit_irqoff();
383+
local_irq_restore(flags);
384+
}
385+
341386
static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
342387
{
343388
/*

0 commit comments

Comments
 (0)