Skip to content

Commit 14296e0

Browse files
sean-jcKAGA-KOKO
authored andcommitted
context_tracking: Consolidate guest enter/exit wrappers
Consolidate the guest enter/exit wrappers, providing and tweaking stubs as needed. This will allow moving the wrappers under KVM without having to bleed #ifdefs into the soon-to-be KVM 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 6f922b8 commit 14296e0

File tree

1 file changed

+24
-41
lines changed

1 file changed

+24
-41
lines changed

include/linux/context_tracking.h

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ static inline void exception_exit(enum ctx_state prev_ctx)
7171
}
7272
}
7373

74+
static __always_inline bool context_tracking_guest_enter(void)
75+
{
76+
if (context_tracking_enabled())
77+
__context_tracking_enter(CONTEXT_GUEST);
78+
79+
return context_tracking_enabled_this_cpu();
80+
}
81+
82+
static __always_inline void context_tracking_guest_exit(void)
83+
{
84+
if (context_tracking_enabled())
85+
__context_tracking_exit(CONTEXT_GUEST);
86+
}
7487

7588
/**
7689
* ct_state() - return the current context tracking state if known
@@ -92,6 +105,9 @@ static inline void user_exit_irqoff(void) { }
92105
static inline enum ctx_state exception_enter(void) { return 0; }
93106
static inline void exception_exit(enum ctx_state prev_ctx) { }
94107
static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
108+
static inline bool context_tracking_guest_enter(void) { return false; }
109+
static inline void context_tracking_guest_exit(void) { }
110+
95111
#endif /* !CONFIG_CONTEXT_TRACKING */
96112

97113
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled() && (cond))
@@ -102,74 +118,41 @@ extern void context_tracking_init(void);
102118
static inline void context_tracking_init(void) { }
103119
#endif /* CONFIG_CONTEXT_TRACKING_FORCE */
104120

105-
106-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
107121
/* must be called with irqs disabled */
108122
static __always_inline void guest_enter_irqoff(void)
109123
{
124+
/*
125+
* This is running in ioctl context so its safe to assume that it's the
126+
* stime pending cputime to flush.
127+
*/
110128
instrumentation_begin();
111-
if (vtime_accounting_enabled_this_cpu())
112-
vtime_guest_enter(current);
113-
else
114-
current->flags |= PF_VCPU;
129+
vtime_account_guest_enter();
115130
instrumentation_end();
116131

117-
if (context_tracking_enabled())
118-
__context_tracking_enter(CONTEXT_GUEST);
119-
120-
/* KVM does not hold any references to rcu protected data when it
132+
/*
133+
* KVM does not hold any references to rcu protected data when it
121134
* switches CPU into a guest mode. In fact switching to a guest mode
122135
* is very similar to exiting to userspace from rcu point of view. In
123136
* addition CPU may stay in a guest mode for quite a long time (up to
124137
* one time slice). Lets treat guest mode as quiescent state, just like
125138
* we do with user-mode execution.
126139
*/
127-
if (!context_tracking_enabled_this_cpu()) {
140+
if (!context_tracking_guest_enter()) {
128141
instrumentation_begin();
129142
rcu_virt_note_context_switch(smp_processor_id());
130143
instrumentation_end();
131144
}
132145
}
133146

134-
static __always_inline void context_tracking_guest_exit(void)
135-
{
136-
if (context_tracking_enabled())
137-
__context_tracking_exit(CONTEXT_GUEST);
138-
}
139-
140147
static __always_inline void guest_exit_irqoff(void)
141148
{
142149
context_tracking_guest_exit();
143150

144-
instrumentation_begin();
145-
vtime_account_guest_exit();
146-
instrumentation_end();
147-
}
148-
149-
#else
150-
static __always_inline void guest_enter_irqoff(void)
151-
{
152-
/*
153-
* This is running in ioctl context so its safe
154-
* to assume that it's the stime pending cputime
155-
* to flush.
156-
*/
157-
instrumentation_begin();
158-
vtime_account_guest_enter();
159-
rcu_virt_note_context_switch(smp_processor_id());
160-
instrumentation_end();
161-
}
162-
163-
static __always_inline void context_tracking_guest_exit(void) { }
164-
165-
static __always_inline void guest_exit_irqoff(void)
166-
{
167151
instrumentation_begin();
168152
/* Flush the guest cputime we spent on the guest */
169153
vtime_account_guest_exit();
170154
instrumentation_end();
171155
}
172-
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
173156

174157
static inline void guest_exit(void)
175158
{

0 commit comments

Comments
 (0)