mbox series

[v3,0/7] Enhance event delivery error handling

Message ID 20241217181458.68690-1-iorlov@amazon.com (mailing list archive)
Headers show
Series Enhance event delivery error handling | expand

Message

Ivan Orlov Dec. 17, 2024, 6:14 p.m. UTC
Currently, the unhandleable vectoring (e.g. when guest accesses MMIO
during vectoring) is handled differently on VMX and SVM: on VMX KVM
returns internal error, when SVM goes into infinite loop trying to
deliver an event again and again.

This patch series eliminates this difference by returning a KVM internal
error when KVM can't emulate during vectoring for both VMX and SVM.

Also, introduce a selftest test case which covers the error handling
mentioned above.

V1 -> V2:
- Make commit messages more brief, avoid using pronouns
- Extract SVM error handling into a separate commit
- Introduce a new X86EMUL_ return type and detect the unhandleable
vectoring error in vendor-specific check_emulate_instruction instead of
handling it in the common MMU code (which is specific for cached MMIO)

V2 -> V3:
- Make the new X86EMUL_ code more generic
- Prohibit any emulation during vectoring if it is due to an intercepted
#PF
- Add a new patch for checking whether unprotect & retry is possible
before exiting to userspace due to unhandleable vectoring
- Codestyle fixes


Ivan Orlov (7):
  KVM: x86: Add function for vectoring error generation
  KVM: x86: Add emulation status for unhandleable vectoring
  KVM: x86: Unprotect & retry before unhandleable vectoring check
  KVM: VMX: Handle vectoring error in check_emulate_instruction
  KVM: SVM: Handle vectoring error in check_emulate_instruction
  selftests: KVM: extract lidt into helper function
  selftests: KVM: Add test case for MMIO during vectoring

 arch/x86/include/asm/kvm_host.h               | 11 +++-
 arch/x86/kvm/kvm_emulate.h                    |  2 +
 arch/x86/kvm/svm/svm.c                        |  6 +++
 arch/x86/kvm/vmx/vmx.c                        | 30 ++++-------
 arch/x86/kvm/x86.c                            | 31 +++++++++++
 .../selftests/kvm/include/x86_64/processor.h  |  7 +++
 .../selftests/kvm/set_memory_region_test.c    | 53 ++++++++++++++++++-
 .../selftests/kvm/x86_64/sev_smoke_test.c     |  2 +-
 8 files changed, 117 insertions(+), 25 deletions(-)

Comments

Sean Christopherson Dec. 18, 2024, 6:44 p.m. UTC | #1
On Tue, Dec 17, 2024, Ivan Orlov wrote:
> Currently, the unhandleable vectoring (e.g. when guest accesses MMIO
> during vectoring) is handled differently on VMX and SVM: on VMX KVM
> returns internal error, when SVM goes into infinite loop trying to
> deliver an event again and again.
> 
> This patch series eliminates this difference by returning a KVM internal
> error when KVM can't emulate during vectoring for both VMX and SVM.
> 
> Also, introduce a selftest test case which covers the error handling
> mentioned above.

A few nits throughout, but I'll address them when applying.  Thanks!
Ivan Orlov Dec. 18, 2024, 9:57 p.m. UTC | #2
On 12/18/24 18:44, Sean Christopherson wrote:
> On Tue, Dec 17, 2024, Ivan Orlov wrote:
>> Currently, the unhandleable vectoring (e.g. when guest accesses MMIO
>> during vectoring) is handled differently on VMX and SVM: on VMX KVM
>> returns internal error, when SVM goes into infinite loop trying to
>> deliver an event again and again.
>>
>> This patch series eliminates this difference by returning a KVM internal
>> error when KVM can't emulate during vectoring for both VMX and SVM.
>>
>> Also, introduce a selftest test case which covers the error handling
>> mentioned above.
> 
> A few nits throughout, but I'll address them when applying.  Thanks!
> 

Hi Sean,

Awesome, thanks a lot for fixing the commits and for the review.
Sean Christopherson Dec. 19, 2024, 2:40 a.m. UTC | #3
On Tue, 17 Dec 2024 18:14:51 +0000, Ivan Orlov wrote:
> Currently, the unhandleable vectoring (e.g. when guest accesses MMIO
> during vectoring) is handled differently on VMX and SVM: on VMX KVM
> returns internal error, when SVM goes into infinite loop trying to
> deliver an event again and again.
> 
> This patch series eliminates this difference by returning a KVM internal
> error when KVM can't emulate during vectoring for both VMX and SVM.
> 
> [...]

Applied to kvm-x86 misc, thanks!  If you get a chance, please double check that
I didn't fat-finger anything.

[1/7] KVM: x86: Add function for vectoring error generation
      https://github.com/kvm-x86/linux/commit/11c98fa07a79
[2/7] KVM: x86: Add emulation status for unhandleable vectoring
      https://github.com/kvm-x86/linux/commit/5c9cfc486636
[3/7] KVM: x86: Unprotect & retry before unhandleable vectoring check
      https://github.com/kvm-x86/linux/commit/704fc6021b9e
[4/7] KVM: VMX: Handle vectoring error in check_emulate_instruction
      https://github.com/kvm-x86/linux/commit/47ef3ef843c0
[5/7] KVM: SVM: Handle vectoring error in check_emulate_instruction
      https://github.com/kvm-x86/linux/commit/7bd7ff99110a
[6/7] selftests: KVM: extract lidt into helper function
      https://github.com/kvm-x86/linux/commit/4e9427aeb957
[7/7] selftests: KVM: Add test case for MMIO during vectoring
      https://github.com/kvm-x86/linux/commit/62e41f6b4f36

--
https://github.com/kvm-x86/linux/tree/next
Ivan Orlov Dec. 19, 2024, 11:19 p.m. UTC | #4
On Wed, Dec 18, 2024 at 06:40:46PM -0800, Sean Christopherson wrote:
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
> 
> 
> 
> On Tue, 17 Dec 2024 18:14:51 +0000, Ivan Orlov wrote:
> > Currently, the unhandleable vectoring (e.g. when guest accesses MMIO
> > during vectoring) is handled differently on VMX and SVM: on VMX KVM
> > returns internal error, when SVM goes into infinite loop trying to
> > deliver an event again and again.
> >
> > This patch series eliminates this difference by returning a KVM internal
> > error when KVM can't emulate during vectoring for both VMX and SVM.
> >
> > [...]
> 
> Applied to kvm-x86 misc, thanks!  If you get a chance, please double check that
> I didn't fat-finger anything.
> 
> [1/7] KVM: x86: Add function for vectoring error generation
>       https://github.com/kvm-x86/linux/commit/11c98fa07a79
> [2/7] KVM: x86: Add emulation status for unhandleable vectoring
>       https://github.com/kvm-x86/linux/commit/5c9cfc486636
> [3/7] KVM: x86: Unprotect & retry before unhandleable vectoring check
>       https://github.com/kvm-x86/linux/commit/704fc6021b9e
> [4/7] KVM: VMX: Handle vectoring error in check_emulate_instruction
>       https://github.com/kvm-x86/linux/commit/47ef3ef843c0
> [5/7] KVM: SVM: Handle vectoring error in check_emulate_instruction
>       https://github.com/kvm-x86/linux/commit/7bd7ff99110a
> [6/7] selftests: KVM: extract lidt into helper function
>       https://github.com/kvm-x86/linux/commit/4e9427aeb957
> [7/7] selftests: KVM: Add test case for MMIO during vectoring
>       https://github.com/kvm-x86/linux/commit/62e41f6b4f36
> 
> --
> https://github.com/kvm-x86/linux/tree/next

Hi Sean,

The commits (and the messages specifically) look good to me, thanks a
lot for making the changelogs better! :)

Also, I ran the selftests for the `next` branch on both Intel and AMD
platforms, and all of them seem to pass.

--
Kind regards,
Ivan Orlov