From: Paolo Bonzini <pbonzini@redhat.com>
To: Ivan Shcherbakov <ivan@sysprogs.com>, qemu-devel@nongnu.org
Cc: armbru@redhat.com, mst@redhat.com
Subject: Re: [PATCH 3/3] whpx: Added support for breakpoints and stepping
Date: Wed, 23 Feb 2022 10:36:25 +0100 [thread overview]
Message-ID: <93318cc1-bf62-34dd-190c-1961a4716f75@redhat.com> (raw)
In-Reply-To: <010e01d82875$d3cc0ec0$7b642c40$@sysprogs.com>
On 2/23/22 06:25, Ivan Shcherbakov wrote:
> This adds support for breakpoints and stepping when debugging
> WHPX-accelerated guests with gdb.
> It enables reliable debugging of the Linux kernel in both single-CPU and SMP
> modes.
>
> Signed-off-by: Ivan Shcherbakov <ivan@sysprogs.com>
Hi,
in general this patch is really good work, thanks for contributing it!
Just a couple notes:
> +enum whpx_step_mode {
> + whpx_step_none = 0,
> + /* Halt other VCPUs */
> + whpx_step_exclusive,
> +};
Please use
typedef enum WhpxStepMode {
WHPX_STEP_NONE,
WHPX_STEP_EXCLUSIVE,
} WhpxStepMode;
and likewise for WhpxBreakpointState. (In the case of WhpxStepMode I
would also consider simply a "bool exclusive" in whpx_cpu_run).
> struct whpx_vcpu {
> WHV_EMULATOR_HANDLE emulator;
> bool window_registered;
> @@ -156,7 +163,6 @@ struct whpx_vcpu {
> uint64_t tpr;
> uint64_t apic_base;
> bool interruption_pending;
> -
Please leave the empty line.
> + if (set) {
> + /* Raise WHvX64ExceptionTypeDebugTrapOrFault after each instruction
> */
> + reg_value.Reg64 |= TF_MASK;
> + } else {
> + reg_value.Reg64 &= ~TF_MASK;
> + }
Out of curiosity, does the guest see TF=1 if it single steps through a
PUSHF (and then break horribly on POPF :))?
> +/*
> + * Linux uses int3 (0xCC) during startup (see int3_selftest()) and for
> + * debugging user-mode applications. Since the WHPX API does not offer
> + * an easy way to pass the intercepted exception back to the guest, we
> + * resort to using INT1 instead, and let the guest always handle INT3.
> + */
> +static const uint8_t whpx_breakpoint_instruction = 0xF1;
Makes sense.
> + breakpoints->original_addresses =
> + g_renew(vaddr, breakpoints->original_addresses,
> cpu_breakpoint_count);
> +
> + breakpoints->original_address_count = cpu_breakpoint_count;
> +
> + int max_breakpoints = cpu_breakpoint_count +
> + (breakpoints->breakpoints ? breakpoints->breakpoints->used : 0);
> +
> + struct whpx_breakpoint_collection *new_breakpoints =
> + (struct whpx_breakpoint_collection *)g_malloc0(
> + sizeof(struct whpx_breakpoint_collection) +
> + max_breakpoints * sizeof(struct whpx_breakpoint));
> + new_breakpoints->allocated = max_breakpoints;
Why separate the original addresses in a different array (and why the
different logic, with used/allocated for one array and an exact size for
the other)
> + enum whpx_breakpoint_state state = breakpoints->data[i].state;
Same comment on coding style applies to this enum.
I would have done most changes for you, but I didn't really understand
the breakpoints vs breakpoint collection part, so I would like your
input on that.
I have queued the first two patches already.
Thanks!
Paolo
next prev parent reply other threads:[~2022-02-23 10:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 5:25 [PATCH 3/3] whpx: Added support for breakpoints and stepping Ivan Shcherbakov
2022-02-23 9:36 ` Paolo Bonzini [this message]
2022-02-23 20:05 ` Ivan Shcherbakov
2022-02-24 9:35 ` Peter Maydell
2022-02-24 11:22 ` Alex Bennée
2022-02-24 15:54 ` Ivan Shcherbakov
2022-02-28 4:31 ` Ivan Shcherbakov
2022-02-28 10:28 ` Alex Bennée
2022-03-01 2:08 ` Ivan Shcherbakov
2022-03-02 2:06 ` Ivan Shcherbakov
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=93318cc1-bf62-34dd-190c-1961a4716f75@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=ivan@sysprogs.com \
--cc=mst@redhat.com \
--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).