@@ -71,6 +71,19 @@ static inline void exception_exit(enum ctx_state prev_ctx)
71
71
}
72
72
}
73
73
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
+ }
74
87
75
88
/**
76
89
* ct_state() - return the current context tracking state if known
@@ -92,6 +105,9 @@ static inline void user_exit_irqoff(void) { }
92
105
static inline enum ctx_state exception_enter (void ) { return 0 ; }
93
106
static inline void exception_exit (enum ctx_state prev_ctx ) { }
94
107
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
+
95
111
#endif /* !CONFIG_CONTEXT_TRACKING */
96
112
97
113
#define CT_WARN_ON (cond ) WARN_ON(context_tracking_enabled() && (cond))
@@ -102,74 +118,41 @@ extern void context_tracking_init(void);
102
118
static inline void context_tracking_init (void ) { }
103
119
#endif /* CONFIG_CONTEXT_TRACKING_FORCE */
104
120
105
-
106
- #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
107
121
/* must be called with irqs disabled */
108
122
static __always_inline void guest_enter_irqoff (void )
109
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
+ */
110
128
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 ();
115
130
instrumentation_end ();
116
131
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
121
134
* switches CPU into a guest mode. In fact switching to a guest mode
122
135
* is very similar to exiting to userspace from rcu point of view. In
123
136
* addition CPU may stay in a guest mode for quite a long time (up to
124
137
* one time slice). Lets treat guest mode as quiescent state, just like
125
138
* we do with user-mode execution.
126
139
*/
127
- if (!context_tracking_enabled_this_cpu ()) {
140
+ if (!context_tracking_guest_enter ()) {
128
141
instrumentation_begin ();
129
142
rcu_virt_note_context_switch (smp_processor_id ());
130
143
instrumentation_end ();
131
144
}
132
145
}
133
146
134
- static __always_inline void context_tracking_guest_exit (void )
135
- {
136
- if (context_tracking_enabled ())
137
- __context_tracking_exit (CONTEXT_GUEST );
138
- }
139
-
140
147
static __always_inline void guest_exit_irqoff (void )
141
148
{
142
149
context_tracking_guest_exit ();
143
150
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
- {
167
151
instrumentation_begin ();
168
152
/* Flush the guest cputime we spent on the guest */
169
153
vtime_account_guest_exit ();
170
154
instrumentation_end ();
171
155
}
172
- #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
173
156
174
157
static inline void guest_exit (void )
175
158
{
0 commit comments