All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: AMD #DB interception (was [PATCH] x86/vmx: Fix injection of #DB traps following XSA-165)
Date: Thu, 24 Dec 2015 18:54:02 +0000	[thread overview]
Message-ID: <567C3F4A.6050802@citrix.com> (raw)
In-Reply-To: <1450981384-2966-1-git-send-email-andrew.cooper3@citrix.com>

On 24/12/2015 18:23, Andrew Cooper wrote:
> Most debug exceptions are traps rather than faults.  Blindly re-injecting them
> as hardware exception causes the instruction pointer in the exception frame
> to point at the target instruct, rather than after it.  This in turn breaks
> debuggers in the guests.
>
> Introduce a helper which copies VM_EXIT_INTR_INTO to VM_ENTRY_INTR_INFO, and
> use it to mirror the intercepted interrupt back to the guest.  As part of
> doing so, introduce vmx_intr_info_t with a bitfield representation of an
> INTR_INFO field.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

In principle, the same logical bug exists for SVM, but things are a 
little more complicated.

In VT-x, all exception intercepts have fault semantics, but for SVM, 
exception intercepts for traps take place after the trapped instruction 
has completed.

Therefore, despite being conceptually incorrect, the XSA-165 patch of:

@@ -2434,8 +2435,9 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)

      case VMEXIT_EXCEPTION_DB:
          if ( !v->domain->debugger_attached )
-            goto unexpected_exit_type;
-        domain_pause_for_debugger();
+            hvm_inject_hw_exception(TRAP_debug, HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_pause_for_debugger();
          break;

      case VMEXIT_EXCEPTION_BP:

is correct, as whether the intercepted exception was a trap or a fault, 
it must be in-injected at the current %rip, as well as needing nrip = rip.

Could I please get a second opinion?

I don't actually have a unit test for this at the moment (my existing 
unit test uses ICEBP for #BP traps, which have different intercept 
semantics in SVM), but I will be working on one in due course.

~Andrew

  reply	other threads:[~2015-12-24 18:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-24 18:23 [PATCH] x86/vmx: Fix injection of #DB traps following XSA-165 Andrew Cooper
2015-12-24 18:54 ` Andrew Cooper [this message]
2015-12-25  1:36 ` Tian, Kevin
2015-12-29 10:50   ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=567C3F4A.6050802@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=JBeulich@suse.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.