Skip to contentSkip to conversation

x86/hvm: Corrections and improvements to unhandled vmexit logging

PATCH Superseded Andrew Cooper 5 participants 8 messages Apr 19, 2017 – Apr 21, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Corrections and improvements to unhandled vmexit logging

* Use gprintk rather than gdprintk. These logging messages shouldn't disappear in release builds, as they usually happen immediately before a domain crash. Raise them from WARNING to ERR.
* Format the vmexit reason in the same base as is used in the vendor manuals (decimal for Intel, hex for AMD), and consistently use 0x for hex numbers.

In particular, this corrects the information printed for nested VT-x, and actually prints information for nested SVM.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Julien Grall <[email protected]>

Request for this to be in 4.9, for the purposes of these log messages remaining present in release builds. The nested versions are less important, but modified here for consistency.

For the nested virt side of things, it is insecure to ever hit the default case, as it causes unknown exits to be handled in the context of being L1, even when it originated from L2. I considered putting using domain_crash(), but that isn't very helpful, and nested virt is still strictly expermiental.

---
 xen/arch/x86/hvm/svm/nestedsvm.c | 2 ++
 xen/arch/x86/hvm/svm/svm.c       | 7 +++----
 xen/arch/x86/hvm/vmx/vmx.c       | 2 +-
 xen/arch/x86/hvm/vmx/vvmx.c      | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/svm/nestedsvm.c +2 -0
index d4fc81f..097a4d8 100644
@@ -1406,6 +1406,8 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs,
         /* Always let the guest handle VMMCALL/VMCALL */
         return NESTEDHVM_VMEXIT_INJECT;
     default:
+        gprintk(XENLOG_ERR, "Unhandled nested vmexit: reason %#"PRIx64"\n",
+                exitcode);
         break;
     }
 
xen/arch/x86/hvm/svm/svm.c +3 -4
index 07e9718..68bdcdd 100644
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason, 
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
         svm_crash_or_fault(v);
         break;
     }
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index f8d3c17..98d3f08 100644
@@ -4106,7 +4106,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", exit_reason);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %ld\n", exit_reason);
 
         if ( vmx_get_cpl() )
             hvm_inject_hw_exception(TRAP_invalid_op,
xen/arch/x86/hvm/vmx/vvmx.c +2 -2
index 936feb6..560babb 100644
@@ -2550,8 +2550,8 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
             nvcpu->nv_vmexit_pending = 1;
         break;
     default:
-        gdprintk(XENLOG_WARNING, "Unknown nested vmexit reason %x.\n",
-                 exit_reason);
+        gprintk(XENLOG_ERR, "Unhandled nested vmexit: reason %u\n",
+                exit_reason);
     }
 
     return ( nvcpu->nv_vmexit_pending == 1 );
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrew Cooper

* Use gprintk rather than gdprintk. These logging messages shouldn't disappear in release builds, as they usually happen immediately before a domain crash. Raise them from WARNING to ERR.
* Format the vmexit reason in the same base as is used in the vendor manuals (decimal for Intel, hex for AMD), and consistently use 0x for hex numbers.

In particular, this corrects the information printed for nested VT-x, and actually prints information for nested SVM.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:58, <[email protected]> wrote:

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs *regs) · line 2838

Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +3 -4
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason, 
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);

Personally I think "unexpected" was more appropriate than "bad". Also I would have wished for you to eliminate the bogus casts as you touch these lines anyway.

xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 4109

Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -4106,7 +4106,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", exit_reason);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %ld\n", exit_reason);

%lu

With at least this last aspect taken care of

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:58, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +0 -0
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
Quoted 12 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs *regs) · line 2838

Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c +3 -4
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason, 
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);

Personally I think "unexpected" was more appropriate than "bad". Also I would have wished for you to eliminate the bogus casts as you touch these lines anyway.

Bad was for consistency between VT-x and SVM, and these messages also include the exit_and_crash cases, meaning that "unexpected" isn't entirely appropriate.

I'm happy to take an alternative if you can thing of something better.

Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs *regs) · line 4109

Quoted 9 lines
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -4106,7 +4106,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", exit_reason);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %ld\n", exit_reason);

%lu

Quoted 2 lines

With at least this last aspect taken care of

Will fix both.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 20.04.17 at 13:01, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.04.17 at 17:58, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +0 -0
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
Quoted 12 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs *regs) · line 2838

Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c +3 -4
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason, 
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);

Personally I think "unexpected" was more appropriate than "bad". Also I would have wished for you to eliminate the bogus casts as you touch these lines anyway.

Quoted 5 lines

Bad was for consistency between VT-x and SVM, and these messages also include the exit_and_crash cases, meaning that "unexpected" isn't entirely appropriate.

I'm happy to take an alternative if you can thing of something better.

Well - "unexpected"? (Many of the exit_and_crash paths are either not fitting "bad" any better or are in the same "unexpected" class" in the VMX case. There's only a single patch coming into SVM's unexpected_exit_type label, which does seem to fit "unexpected".)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 19 lines · Andrew Cooper

* Use gprintk rather than gdprintk. These logging messages shouldn't disappear in release builds, as they usually happen immediately before a domain crash. Raise them from WARNING to ERR.
* Format the vmexit reason in the same base as is used in the vendor manuals (decimal for Intel, hex for AMD), and consistently use 0x for hex numbers.

In particular, this corrects the information printed for nested VT-x, and actually prints information for nested SVM.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Julien Grall <[email protected]>

Quoted 3 lines

Request for this to be in 4.9, for the purposes of these log messages remaining present in release builds. The nested versions are less important, but modified here for consistency.

Cheers,

Quoted 72 lines

For the nested virt side of things, it is insecure to ever hit the default case, as it causes unknown exits to be handled in the context of being L1, even when it originated from L2. I considered putting using domain_crash(), but that isn't very helpful, and nested virt is still strictly expermiental.

---
 xen/arch/x86/hvm/svm/nestedsvm.c | 2 ++
 xen/arch/x86/hvm/svm/svm.c       | 7 +++----
 xen/arch/x86/hvm/vmx/vmx.c       | 2 +-
 xen/arch/x86/hvm/vmx/vvmx.c      | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/svm/nestedsvm.c +2 -0
index d4fc81f..097a4d8 100644
@@ -1406,6 +1406,8 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs,
         /* Always let the guest handle VMMCALL/VMCALL */
         return NESTEDHVM_VMEXIT_INJECT;
     default:
+        gprintk(XENLOG_ERR, "Unhandled nested vmexit: reason %#"PRIx64"\n",
+                exitcode);
         break;
     }
 
xen/arch/x86/hvm/svm/svm.c +3 -4
index 07e9718..68bdcdd 100644
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason,
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
         svm_crash_or_fault(v);
         break;
     }
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index f8d3c17..98d3f08 100644
@@ -4106,7 +4106,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", exit_reason);
+        gprintk(XENLOG_ERR, "Bad vmexit: reason %ld\n", exit_reason);
 
         if ( vmx_get_cpl() )
             hvm_inject_hw_exception(TRAP_invalid_op,
xen/arch/x86/hvm/vmx/vvmx.c +2 -2
index 936feb6..560babb 100644
@@ -2550,8 +2550,8 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
             nvcpu->nv_vmexit_pending = 1;
         break;
     default:
-        gdprintk(XENLOG_WARNING, "Unknown nested vmexit reason %x.\n",
-                 exit_reason);
+        gprintk(XENLOG_ERR, "Unhandled nested vmexit: reason %u\n",
+                exit_reason);
     }
 
     return ( nvcpu->nv_vmexit_pending == 1 );
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#6 lore raw
In reply to Andrew Cooper
Quoted 10 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Wednesday, April 19, 2017 11:58 PM

* Use gprintk rather than gdprintk. These logging messages shouldn't disappear in release builds, as they usually happen immediately before a domain crash. Raise them from WARNING to ERR.
* Format the vmexit reason in the same base as is used in the vendor manuals (decimal for Intel, hex for AMD), and consistently use 0x for hex numbers.

Quoted 4 lines

In particular, this corrects the information printed for nested VT-x, and actually prints information for nested SVM.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

PATCH v2 1/1 x86/hvm: Corrections and improvements to unhandled vmexit logging

In reply to Andrew Cooper

* Use gprintk rather than gdprintk. These logging messages shouldn't disappear in release builds, as they usually happen immediately before a domain crash. Raise them from WARNING to ERR.
* Format the vmexit reason in the same base as is used in the vendor manuals (decimal for Intel, hex for AMD), and consistently use 0x for hex numbers.
* Consistently use "Unexpected vmexit" terminology.

In particular, this corrects the information printed for nested VT-x, and actually prints information for nested SVM.

---
v2:
* Use consistent terminology
* Remove redundant casts

For the nested virt side of things, it is insecure to ever hit the default case, as it causes unknown exits to be handled in the context of being L1, even when it originated from L2. I considered putting using domain_crash(), but that isn't very helpful, and nested virt is still strictly expermiental.

---
 xen/arch/x86/hvm/svm/nestedsvm.c | 2 ++
 xen/arch/x86/hvm/svm/svm.c       | 7 +++----
 xen/arch/x86/hvm/vmx/vmx.c       | 2 +-
 xen/arch/x86/hvm/vmx/vvmx.c      | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/svm/nestedsvm.c +2 -0
index d4fc81f..f46e346 100644
@@ -1406,6 +1406,8 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs,
         /* Always let the guest handle VMMCALL/VMCALL */
         return NESTEDHVM_VMEXIT_INJECT;
     default:
+        gprintk(XENLOG_ERR, "Unexpected nested vmexit: reason %#"PRIx64"\n",
+                exitcode);
         break;
     }
 
xen/arch/x86/hvm/svm/svm.c +3 -4
index 07e9718..178adc5 100644
@@ -2833,10 +2833,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
 
     default:
     unexpected_exit_type:
-        gdprintk(XENLOG_ERR, "unexpected VMEXIT: exit reason = %#"PRIx64", "
-                 "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
-                 exit_reason, 
-                 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
+        gprintk(XENLOG_ERR, "Unexpected vmexit: reason %#"PRIx64", "
+                "exitinfo1 %#"PRIx64", exitinfo2 %#"PRIx64"\n",
+                exit_reason, vmcb->exitinfo1, vmcb->exitinfo2);
         svm_crash_or_fault(v);
         break;
     }
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index f8d3c17..c8ef18a 100644
@@ -4106,7 +4106,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", exit_reason);
+        gprintk(XENLOG_ERR, "Unexpected vmexit: reason %lu\n", exit_reason);
 
         if ( vmx_get_cpl() )
             hvm_inject_hw_exception(TRAP_invalid_op,
xen/arch/x86/hvm/vmx/vvmx.c +2 -2
index 936feb6..3560fae 100644
@@ -2550,8 +2550,8 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
             nvcpu->nv_vmexit_pending = 1;
         break;
     default:
-        gdprintk(XENLOG_WARNING, "Unknown nested vmexit reason %x.\n",
-                 exit_reason);
+        gprintk(XENLOG_ERR, "Unexpected nested vmexit: reason %u\n",
+                exit_reason);
     }
 
     return ( nvcpu->nv_vmexit_pending == 1 );
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel