qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Steven Raasch <sraasch@gmail.com>
To: Alexander Bulekov <alxndr@bu.edu>
Cc: qemu-devel@nongnu.org
Subject: Re: Extracting PC information from QEMU/KVM during single-step
Date: Thu, 24 Jun 2021 08:49:45 -0500	[thread overview]
Message-ID: <CA+5M2MCNJP=EEz4hfWy4ougMz0Uon2-=9WmunWKqih3_e_DNYA@mail.gmail.com> (raw)
In-Reply-To: <20210624014538.6osoiuj5l4llor7v@mozz.bu.edu>

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

Alex -

Our application is similar to a high-end game in that it adjusts it's
code-path depending on how "fast" it is running. Our previous attempts to
trace it's execution have run into issues due to the overhead of the trace
collection.

My hope had been that by using QEMU, I could control the "hardware" that
the app is running on such that the app doesn't know that it's not running
at full speed. In my mind, this means instrumenting the VM itself.

Using GDB is my second choice, as I'm not sure that I can gather the trace
w/out slowing down the app's execution. I haven't dug into how GDB
interacts with QEMU and GDB-scripting as of yet.

-Steve


On Wed, Jun 23, 2021 at 8:46 PM Alexander Bulekov <alxndr@bu.edu> wrote:

> On 210623 1514, Steven Raasch wrote:
> > Hi -
> >
> > I'm trying to create a hack that will allow me to extract an instruction
> > trace from QEMU/KVM (i386). The KVM part is important (see below).
> >
> > Background:
> >
> >    - I have used KVM to create a snapshot of a windows-10 guest running a
> >    graphics-intensive app. The *original* issue is that the app does not
> >    execute correctly when re-started from the snapshot using TCG (it
> doesn't
> >    crash, but it doesn't run correctly, either). So, using the existing
> "-d
> >    in_asm" won't work. It seemed to me that hacking in tracing to KVM
> should
> >    be easier than figuring out why the app doesn't work.
> >    - I've poked around the tracing mechanism in the TCG, and extracted
> what
> >    I need to dump instructions and then added that to kvm_cpu_exec().
> >    - I'm setting DEBUG & single-step modes by calling cpu_single_step()
> >    from the top of kvm_vcpu_thread_fn().
> >    - in kvm_cpu_exec() I wait until I get a KVM_EXIT_DEBUG signal before
> >    logging the instruction.
> >
> > I have the output of TCG "-d in_asm" from the beginning of the execution,
> > and I'm comparing the KVM output with that.
> >
> > What I don't have right is the PC of the instruction that's been
> executed.
> > The TCG is clearly sane, but the KVM output is not.
> >
> > My best thought was to extract the PC from kvm_run (run->debug.arch.pc)
> > after the KVM_RUN ioctl, but that doesn't match up. I also tried
> > kvm_vcpu_ioctl() with KVM_GET_REGS, and grabbing the rip from
> cpu->env.rip.
> > I didn't expect any of these to be *exactly* right, but I thought they
> > would lead me to something sane.
> >
> > Using run->debug.arch.pc gives me the right address for the first
> > instruction, but nothing makes sense after that.
> >
> > Can anyone help me get onto the right track?
> >
> > Thanks!
> >
> > -Steve
>
> Is there some reason you can't do this using qemu's gdbstub and gdb? It
> supports single-stepping under KVM.
>
> -Alex
>

[-- Attachment #2: Type: text/html, Size: 3573 bytes --]

  reply	other threads:[~2021-06-24 13:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 20:14 Extracting PC information from QEMU/KVM during single-step Steven Raasch
2021-06-24  1:45 ` Alexander Bulekov
2021-06-24 13:49   ` Steven Raasch [this message]
2021-06-24 14:41     ` Alexander Bulekov
2021-06-24 16:22 ` Peter Maydell
2021-06-24 17:08   ` Steven Raasch
2021-06-24 18:51     ` Peter Maydell
2021-06-24 19:36       ` Steven Raasch

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='CA+5M2MCNJP=EEz4hfWy4ougMz0Uon2-=9WmunWKqih3_e_DNYA@mail.gmail.com' \
    --to=sraasch@gmail.com \
    --cc=alxndr@bu.edu \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).