All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: VMX: Factor out is_exception_n helper
@ 2016-02-09 19:14 Jan Kiszka
  2016-02-09 19:15 ` [PATCH 2/2] KVM: VMX: Fix guest debugging while in L2 Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2016-02-09 19:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm

[-- Attachment #1: Type: text/plain, Size: 1684 bytes --]

From: Jan Kiszka <jan.kiszka@siemens.com>

There is quite some common code in all these is_<exception>() helpers.
Factor it out before adding even more of them.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 arch/x86/kvm/vmx.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 164eb9e..7852092 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -961,25 +961,26 @@ static const u32 vmx_msr_index[] = {
 	MSR_EFER, MSR_TSC_AUX, MSR_STAR,
 };
 
-static inline bool is_page_fault(u32 intr_info)
+static inline bool is_exception_n(u32 intr_info, u8 vector)
 {
 	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
 			     INTR_INFO_VALID_MASK)) ==
-		(INTR_TYPE_HARD_EXCEPTION | PF_VECTOR | INTR_INFO_VALID_MASK);
+		(INTR_TYPE_HARD_EXCEPTION | vector | INTR_INFO_VALID_MASK);
+}
+
+static inline bool is_page_fault(u32 intr_info)
+{
+	return is_exception_n(intr_info, PF_VECTOR);
 }
 
 static inline bool is_no_device(u32 intr_info)
 {
-	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
-			     INTR_INFO_VALID_MASK)) ==
-		(INTR_TYPE_HARD_EXCEPTION | NM_VECTOR | INTR_INFO_VALID_MASK);
+	return is_exception_n(intr_info, NM_VECTOR);
 }
 
 static inline bool is_invalid_opcode(u32 intr_info)
 {
-	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
-			     INTR_INFO_VALID_MASK)) ==
-		(INTR_TYPE_HARD_EXCEPTION | UD_VECTOR | INTR_INFO_VALID_MASK);
+	return is_exception_n(intr_info, UD_VECTOR);
 }
 
 static inline bool is_external_interrupt(u32 intr_info)
-- 
2.1.4


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] KVM: VMX: Fix guest debugging while in L2
  2016-02-09 19:14 [PATCH 1/2] KVM: VMX: Factor out is_exception_n helper Jan Kiszka
@ 2016-02-09 19:15 ` Jan Kiszka
  2016-02-10 14:41   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2016-02-09 19:15 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

From: Jan Kiszka <jan.kiszka@siemens.com>

When we take a #DB or #BP vmexit while in guest mode, we first of all
need to check if there is ongoing guest debugging that might be
interested in the event. Currently, we unconditionally leave L2 and
inject the event into L1 if it is intercepting the exceptions. That
breaks things marvelously.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
- ---
 arch/x86/kvm/vmx.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7852092..cb501d3 100644
- --- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -968,6 +968,16 @@ static inline bool is_exception_n(u32 intr_info, u8 vector)
 		(INTR_TYPE_HARD_EXCEPTION | vector | INTR_INFO_VALID_MASK);
 }
 
+static inline bool is_debug(u32 intr_info)
+{
+	return is_exception_n(intr_info, DB_VECTOR);
+}
+
+static inline bool is_breakpoint(u32 intr_info)
+{
+	return is_exception_n(intr_info, BP_VECTOR);
+}
+
 static inline bool is_page_fault(u32 intr_info)
 {
 	return is_exception_n(intr_info, PF_VECTOR);
@@ -7753,6 +7763,13 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu)
 		else if (is_no_device(intr_info) &&
 			 !(vmcs12->guest_cr0 & X86_CR0_TS))
 			return false;
+		else if (is_debug(intr_info) &&
+			 vcpu->guest_debug &
+			 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
+			return false;
+		else if (is_breakpoint(intr_info) &&
+			 vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
+			return false;
 		return vmcs12->exception_bitmap &
 				(1u << (intr_info & INTR_INFO_VECTOR_MASK));
 	case EXIT_REASON_EXTERNAL_INTERRUPT:
- -- 
2.1.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAla6OsYACgkQitSsb3rl5xSzCACffw3KGJi4oXaT2WM6ec5puJNe
4bUAn012m9dYnUkkRBC7iHNENFbKs1y2
=abYj
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] KVM: VMX: Fix guest debugging while in L2
  2016-02-09 19:15 ` [PATCH 2/2] KVM: VMX: Fix guest debugging while in L2 Jan Kiszka
@ 2016-02-10 14:41   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2016-02-10 14:41 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: kvm



On 09/02/2016 20:15, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> When we take a #DB or #BP vmexit while in guest mode, we first of all
> need to check if there is ongoing guest debugging that might be
> interested in the event. Currently, we unconditionally leave L2 and
> inject the event into L1 if it is intercepting the exceptions. That
> breaks things marvelously.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  arch/x86/kvm/vmx.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 7852092..cb501d3 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -968,6 +968,16 @@ static inline bool is_exception_n(u32 intr_info, u8 vector)
>  		(INTR_TYPE_HARD_EXCEPTION | vector | INTR_INFO_VALID_MASK);
>  }
> 
> +static inline bool is_debug(u32 intr_info)
> +{
> +	return is_exception_n(intr_info, DB_VECTOR);
> +}
> +
> +static inline bool is_breakpoint(u32 intr_info)
> +{
> +	return is_exception_n(intr_info, BP_VECTOR);
> +}
> +
>  static inline bool is_page_fault(u32 intr_info)
>  {
>  	return is_exception_n(intr_info, PF_VECTOR);
> @@ -7753,6 +7763,13 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu)
>  		else if (is_no_device(intr_info) &&
>  			 !(vmcs12->guest_cr0 & X86_CR0_TS))
>  			return false;
> +		else if (is_debug(intr_info) &&
> +			 vcpu->guest_debug &
> +			 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
> +			return false;
> +		else if (is_breakpoint(intr_info) &&
> +			 vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
> +			return false;
>  		return vmcs12->exception_bitmap &
>  				(1u << (intr_info & INTR_INFO_VECTOR_MASK));
>  	case EXIT_REASON_EXTERNAL_INTERRUPT:
> 

Thanks, I'll apply both patches shortly to kvm/queue.

However, next time please do not sign the patches.  git send-email
doesn't like the way PGP signed messages escape "-" at the beginning of
the line.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-10 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-09 19:14 [PATCH 1/2] KVM: VMX: Factor out is_exception_n helper Jan Kiszka
2016-02-09 19:15 ` [PATCH 2/2] KVM: VMX: Fix guest debugging while in L2 Jan Kiszka
2016-02-10 14:41   ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.