From: David Gibson <david@gibson.dropbear.id.au>
To: Fabiano Rosas <farosas@linux.ibm.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>,
Alexey Kardashevskiy <aik@ozlabs.ru>
Subject: Re: [Qemu-devel] [RFC PATCH v4 2/5] kvm-all: Introduce kvm_set_singlestep
Date: Mon, 4 Mar 2019 16:50:18 +1100 [thread overview]
Message-ID: <20190304055018.GM7792@umbus.fritz.box> (raw)
In-Reply-To: <20190228225759.21328-3-farosas@linux.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 5669 bytes --]
On Thu, Feb 28, 2019 at 07:57:56PM -0300, Fabiano Rosas wrote:
> For single stepping (via KVM) of a guest vcpu to work, KVM needs not
> only to support the SET_GUEST_DEBUG ioctl but to also recognize the
> KVM_GUESTDBG_SINGLESTEP bit in the control field of the
> kvm_guest_debug struct.
>
> This patch adds support for querying the single step capability so
> that QEMU can decide what to do for the platforms that do not have
> such support.
>
> This will allow architecture-specific implementations of a fallback
> mechanism for single stepping in cases where KVM does not support it.
>
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
> accel/kvm/kvm-all.c | 16 ++++++++++++++++
> accel/stubs/kvm-stub.c | 4 ++++
> exec.c | 2 +-
> include/sysemu/kvm.h | 3 +++
> stubs/Makefile.objs | 1 +
> stubs/kvm-arch-set-singlestep.c | 8 ++++++++
> 6 files changed, 33 insertions(+), 1 deletion(-)
> create mode 100644 stubs/kvm-arch-set-singlestep.c
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index fd92b6f375..d3ac5a9e5c 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2267,6 +2267,13 @@ bool kvm_arm_supports_user_irq(void)
> return kvm_check_extension(kvm_state, KVM_CAP_ARM_USER_IRQ);
> }
>
> +/* Whether the KVM_SET_GUEST_DEBUG ioctl supports single stepping */
> +int kvm_has_guestdbg_singlestep(void)
> +{
> + /* return kvm_check_extension(kvm_state, KVM_CAP_GUEST_DEBUG_SSTEP); */
I don't see a KVM_CAP_GUEST_DEBUG_SSTEP in either the qemu or kernel
trees. Where does that come from?
> + return 0;
> +}
> +
> #ifdef KVM_CAP_SET_GUEST_DEBUG
> struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu,
> target_ulong pc)
> @@ -2316,6 +2323,15 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
> return data.err;
> }
>
> +void kvm_set_singlestep(CPUState *cs, int enabled)
> +{
> + if (kvm_has_guestdbg_singlestep()) {
> + kvm_update_guest_debug(cs, 0);
> + } else {
> + kvm_arch_set_singlestep(cs, enabled);
> + }
> +}
> +
> int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
> target_ulong len, int type)
> {
> diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
> index 02d5170031..69bd07f50e 100644
> --- a/accel/stubs/kvm-stub.c
> +++ b/accel/stubs/kvm-stub.c
> @@ -79,6 +79,10 @@ int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
> return -ENOSYS;
> }
>
> +void kvm_set_singlestep(CPUState *cs, int enabled)
> +{
> +}
> +
> int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
> target_ulong len, int type)
> {
> diff --git a/exec.c b/exec.c
> index 518064530b..8817513e26 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1236,7 +1236,7 @@ void cpu_single_step(CPUState *cpu, int enabled)
> if (cpu->singlestep_enabled != enabled) {
> cpu->singlestep_enabled = enabled;
> if (kvm_enabled()) {
> - kvm_update_guest_debug(cpu, 0);
> + kvm_set_singlestep(cpu, enabled);
> } else {
> /* must flush all the translated code to avoid inconsistencies */
> /* XXX: only flush what is necessary */
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index a6d1cd190f..e1ef2f5b99 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -214,6 +214,7 @@ int kvm_has_pit_state2(void);
> int kvm_has_many_ioeventfds(void);
> int kvm_has_gsi_routing(void);
> int kvm_has_intx_set_mask(void);
> +int kvm_has_guestdbg_singlestep(void);
>
> int kvm_init_vcpu(CPUState *cpu);
> int kvm_cpu_exec(CPUState *cpu);
> @@ -246,6 +247,7 @@ bool kvm_memcrypt_enabled(void);
> */
> int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len);
>
> +void kvm_arch_set_singlestep(CPUState *cpu, int enabled);
>
> #ifdef NEED_CPU_H
> #include "cpu.h"
> @@ -258,6 +260,7 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
> target_ulong len, int type);
> void kvm_remove_all_breakpoints(CPUState *cpu);
> int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap);
> +void kvm_set_singlestep(CPUState *cs, int enabled);
>
> int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
> int kvm_on_sigbus(int code, void *addr);
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 269dfa5832..884f9b2268 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -12,6 +12,7 @@ stub-obj-y += get-vm-name.o
> stub-obj-y += iothread.o
> stub-obj-y += iothread-lock.o
> stub-obj-y += is-daemonized.o
> +stub-obj-y += kvm-arch-set-singlestep.o
> stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
> stub-obj-y += machine-init-done.o
> stub-obj-y += migr-blocker.o
> diff --git a/stubs/kvm-arch-set-singlestep.c b/stubs/kvm-arch-set-singlestep.c
> new file mode 100644
> index 0000000000..ba6e0323d6
> --- /dev/null
> +++ b/stubs/kvm-arch-set-singlestep.c
> @@ -0,0 +1,8 @@
> +#include "qemu/osdep.h"
> +#include "qemu/error-report.h"
> +#include "sysemu/kvm.h"
> +
> +void kvm_arch_set_singlestep(CPUState *cpu, int enabled)
> +{
> + warn_report("KVM does not support single stepping");
> +}
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-03-04 6:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 22:57 [Qemu-devel] [RFC PATCH v4 0/5] target/ppc: single step for KVM HV Fabiano Rosas
2019-02-28 22:57 ` [Qemu-devel] [RFC PATCH v4 1/5] target/ppc: Move exception vector offset computation into a function Fabiano Rosas
2019-03-04 5:36 ` David Gibson
2019-02-28 22:57 ` [Qemu-devel] [RFC PATCH v4 2/5] kvm-all: Introduce kvm_set_singlestep Fabiano Rosas
2019-03-04 5:50 ` David Gibson [this message]
2019-03-04 12:58 ` Fabiano Rosas
2019-03-08 19:09 ` Fabiano Rosas
2019-02-28 22:57 ` [Qemu-devel] [RFC PATCH v4 3/5] target/ppc: Move handling of hardware breakpoints to a separate function Fabiano Rosas
2019-03-04 5:51 ` David Gibson
2019-02-28 22:57 ` [Qemu-devel] [RFC PATCH v4 4/5] target/ppc: Refactor kvm_handle_debug Fabiano Rosas
2019-03-04 5:56 ` David Gibson
2019-02-28 22:57 ` [Qemu-devel] [RFC PATCH v4 5/5] target/ppc: support single stepping with KVM HV Fabiano Rosas
[not found] ` <b8a30b89-8c19-821e-e3a3-f1b71a088d9d@ozlabs.ru>
[not found] ` <87ef73rl39.fsf@linux.ibm.com>
[not found] ` <eadc5e30-5094-9b76-7268-cfb633ac40bd@ozlabs.ru>
2019-06-12 6:31 ` Alexey Kardashevskiy
2019-06-12 13:34 ` Fabiano Rosas
2019-06-12 23:27 ` Alexey Kardashevskiy
2019-06-13 2:01 ` Fabiano Rosas
2019-06-13 6:03 ` Alexey Kardashevskiy
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=20190304055018.GM7792@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=aik@ozlabs.ru \
--cc=farosas@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=rth@twiddle.net \
/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).