All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Arnabjyoti Kalita <akalita@cs.stonybrook.edu>
Cc: Jim Mattson <jmattson@google.com>, kvm@vger.kernel.org
Subject: Re: Causing VMEXITs when kprobes are hit in the guest VM
Date: Wed, 11 May 2022 15:04:23 +0000	[thread overview]
Message-ID: <YnvQd5zvDlop7oRK@google.com> (raw)
In-Reply-To: <CAJGDS+G+z9S6QDEGRatR5u+q-5X_MAiWqnTsjf4L=4+PrThdsQ@mail.gmail.com>

On Wed, May 11, 2022, Arnabjyoti Kalita wrote:
> What could be the various ways a guest could handle #BP?

The kernel uses INT3 to patch instructions/flows, e.g. for alternatives.  For those,
the INT3 handler will unwind to the original RIP and retry.  The #BP will keep
occurring until the patching completes.  See text_poke_bp_batch(), poke_int3_handler(),
etc...

Userspace debuggers will do something similar; after catching the #BP, the original
instruction is restored and restarted.

The reason INT3 is a single byte is so that software can "atomically" trap/patch an
instruction without having to worry about cache line splits.  CPUs are guaranteed
to either see the INT3 or the original instruction in its entirety, i.e. other CPUs
will never decode a half-baked instruction.

The kernel has even fancier uses for things like static_call(), e.g. emulating
CALL, RET, and JMP from the #BP handler.

> Can we "make" the guest skip the instruction that caused the #BP ?

Well, technically yes, that's effectively what would happen if the host skips the
INT3 and doesn't inject the #BP.  Can you do that and expect the guest not to
crash?  Nope.

  reply	other threads:[~2022-05-11 15:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-01 15:30 Causing VMEXITs when kprobes are hit in the guest VM Arnabjyoti Kalita
2022-05-03 20:45 ` Sean Christopherson
2022-05-06  5:14   ` Arnabjyoti Kalita
2022-05-07  6:30     ` Arnabjyoti Kalita
2022-05-11  0:49       ` Jim Mattson
2022-05-11 13:59         ` Sean Christopherson
2022-05-11 14:08           ` Arnabjyoti Kalita
2022-05-11 14:16             ` Sean Christopherson
2022-05-11 14:38               ` Arnabjyoti Kalita
2022-05-11 15:04                 ` Sean Christopherson [this message]
2022-05-11 17:02                   ` Arnabjyoti Kalita
2022-05-23 19:44                     ` Arnabjyoti Kalita

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=YnvQd5zvDlop7oRK@google.com \
    --to=seanjc@google.com \
    --cc=akalita@cs.stonybrook.edu \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.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.