Skip to content

Commit 5933770

Browse files
Leonardo Brasbonzini
authored andcommitted
kvm: Note an RCU quiescent state on guest exit
As of today, KVM notes a quiescent state only in guest entry, which is good as it avoids the guest being interrupted for current RCU operations. While the guest vcpu runs, it can be interrupted by a timer IRQ that will check for any RCU operations waiting for this CPU. In case there are any of such, it invokes rcu_core() in order to sched-out the current thread and note a quiescent state. This occasional schedule work will introduce tens of microsseconds of latency, which is really bad for vcpus running latency-sensitive applications, such as real-time workloads. So, note a quiescent state in guest exit, so the interrupted guests is able to deal with any pending RCU operations before being required to invoke rcu_core(), and thus avoid the overhead of related scheduler work. Signed-off-by: Leonardo Bras <leobras@redhat.com> Acked-by: Paul E. McKenney <paulmck@kernel.org> Acked-by: Sean Christopherson <seanjc@google.com> Message-ID: <20240511020557.1198200-1-leobras@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d30d9ee commit 5933770

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/linux/context_tracking.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ static __always_inline bool context_tracking_guest_enter(void)
8080
return context_tracking_enabled_this_cpu();
8181
}
8282

83-
static __always_inline void context_tracking_guest_exit(void)
83+
static __always_inline bool context_tracking_guest_exit(void)
8484
{
8585
if (context_tracking_enabled())
8686
__ct_user_exit(CONTEXT_GUEST);
87+
88+
return context_tracking_enabled_this_cpu();
8789
}
8890

8991
#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled() && (cond))
@@ -98,7 +100,7 @@ static inline void exception_exit(enum ctx_state prev_ctx) { }
98100
static inline int ct_state(void) { return -1; }
99101
static inline int __ct_state(void) { return -1; }
100102
static __always_inline bool context_tracking_guest_enter(void) { return false; }
101-
static __always_inline void context_tracking_guest_exit(void) { }
103+
static __always_inline bool context_tracking_guest_exit(void) { return false; }
102104
#define CT_WARN_ON(cond) do { } while (0)
103105
#endif /* !CONFIG_CONTEXT_TRACKING_USER */
104106

include/linux/kvm_host.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,15 @@ static __always_inline void guest_state_enter_irqoff(void)
485485
*/
486486
static __always_inline void guest_context_exit_irqoff(void)
487487
{
488-
context_tracking_guest_exit();
488+
/*
489+
* Guest mode is treated as a quiescent state, see
490+
* guest_context_enter_irqoff() for more details.
491+
*/
492+
if (!context_tracking_guest_exit()) {
493+
instrumentation_begin();
494+
rcu_virt_note_context_switch();
495+
instrumentation_end();
496+
}
489497
}
490498

491499
/*

0 commit comments

Comments
 (0)