lkml.org 
[lkml]   [2022]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 13/21] KVM: x86: Formalize blocking of nested pending exceptions
On Wed, Jul 06, 2022, Maxim Levitsky wrote:
> On Tue, 2022-06-14 at 20:47 +0000, Sean Christopherson wrote:
> > Capture nested_run_pending as block_pending_exceptions so that the logic
> > of why exceptions are blocked only needs to be documented once instead of
> > at every place that employs the logic.
> >
> > No functional change intended.
> >
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> > arch/x86/kvm/svm/nested.c | 20 ++++++++++----------
> > arch/x86/kvm/vmx/nested.c | 23 ++++++++++++-----------
> > 2 files changed, 22 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> > index 471d40e97890..460161e67ce5 100644
> > --- a/arch/x86/kvm/svm/nested.c
> > +++ b/arch/x86/kvm/svm/nested.c
> > @@ -1347,10 +1347,16 @@ static inline bool nested_exit_on_init(struct vcpu_svm *svm)
> >
> > static int svm_check_nested_events(struct kvm_vcpu *vcpu)
> > {
> > - struct vcpu_svm *svm = to_svm(vcpu);
> > - bool block_nested_events =
> > - kvm_event_needs_reinjection(vcpu) || svm->nested.nested_run_pending;
> > struct kvm_lapic *apic = vcpu->arch.apic;
> > + struct vcpu_svm *svm = to_svm(vcpu);
> > + /*
> > + * Only a pending nested run blocks a pending exception. If there is a
> > + * previously injected event, the pending exception occurred while said
> > + * event was being delivered and thus needs to be handled.
> > + */
>
> Tiny nitpick about the comment:
>
> One can say that if there is an injected event, this means that we
> are in the middle of handling it, thus we are not on instruction boundary,
> and thus we don't process events (e.g interrupts).
>
> So maybe write something like that?

Hmm, that's another way to look at things. My goal with the comment was to try
and call out that any pending exception is a continuation of the injected event,
i.e. that the injected event won't be lost. Talking about instruction boundaries
only explains why non-exception events are blocked, it doesn't explain why exceptions
are _not_ blocked.

I'll add a second comment above block_nested_events to capture the instruction
boundary angle.

> > + bool block_nested_exceptions = svm->nested.nested_run_pending;
> > + bool block_nested_events = block_nested_exceptions ||
> > + kvm_event_needs_reinjection(vcpu);
>
> Tiny nitpick: I don't like that much the name 'nested' as
> it can also mean a nested exception (e.g exception that
> happened while jumping to an exception handler).
>
> Here we mean just exception/events for the guest, so I would suggest
> to just drop the word 'nested'.

I don't disagree, but I'd prefer to keep the current naming because the helper
itself is *_check_nested_events(). I'm not opposed to renaming things in the
future, but I don't want to do that in this series.

\
 
 \ /
  Last update: 2022-07-06 19:38    [W:0.505 / U:0.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site