All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Maxim Levitsky" <mlevitsk@redhat.com>
Subject: [PULL 08/13] gdbstub, kvm: let KVM report supported singlestep flags
Date: Wed, 15 Dec 2021 21:25:10 +0100	[thread overview]
Message-ID: <20211215202515.91586-9-pbonzini@redhat.com> (raw)
In-Reply-To: <20211215202515.91586-1-pbonzini@redhat.com>

From: Maxim Levitsky <mlevitsk@redhat.com>

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
[Extracted from Maxim's patch into a separate commit. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20211111110604.207376-5-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel/kvm/kvm-all.c  | 12 ++++++++++++
 gdbstub.c            | 10 +++++++++-
 include/sysemu/kvm.h | 15 +++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index eecd8031cf..2f5597572a 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -168,6 +168,8 @@ bool kvm_vm_attributes_allowed;
 bool kvm_direct_msi_allowed;
 bool kvm_ioeventfd_any_length_allowed;
 bool kvm_msi_use_devid;
+bool kvm_has_guest_debug;
+int kvm_sstep_flags;
 static bool kvm_immediate_exit;
 static hwaddr kvm_max_slot_size = ~0;
 
@@ -2564,6 +2566,16 @@ static int kvm_init(MachineState *ms)
     kvm_ioeventfd_any_length_allowed =
         (kvm_check_extension(s, KVM_CAP_IOEVENTFD_ANY_LENGTH) > 0);
 
+#ifdef KVM_CAP_SET_GUEST_DEBUG
+    kvm_has_guest_debug =
+        (kvm_check_extension(s, KVM_CAP_SET_GUEST_DEBUG) > 0);
+#endif
+
+    kvm_sstep_flags = 0;
+    if (kvm_has_guest_debug) {
+        kvm_sstep_flags = SSTEP_ENABLE;
+    }
+
     kvm_state = s;
 
     ret = kvm_arch_init(ms, s);
diff --git a/gdbstub.c b/gdbstub.c
index a955175fd4..3c14c6a038 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -391,6 +391,8 @@ static void init_gdbserver_state(void)
      */
     if (replay_mode != REPLAY_MODE_NONE) {
         gdbserver_state.supported_sstep_flags = SSTEP_ENABLE;
+    } else if (kvm_enabled()) {
+        gdbserver_state.supported_sstep_flags = kvm_get_supported_sstep_flags();
     } else {
         gdbserver_state.supported_sstep_flags =
             SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER;
@@ -400,7 +402,8 @@ static void init_gdbserver_state(void)
      * By default use no IRQs and no timers while single stepping so as to
      * make single stepping like an ICE HW step.
      */
-    gdbserver_state.sstep_flags = gdbserver_state.supported_sstep_flags;
+    gdbserver_state.sstep_flags = SSTEP_ENABLE | SSTEP_NOIRQ | SSTEP_NOTIMER;
+    gdbserver_state.sstep_flags &= gdbserver_state.supported_sstep_flags;
 
 }
 
@@ -3520,6 +3523,11 @@ int gdbserver_start(const char *device)
         return -1;
     }
 
+    if (kvm_enabled() && !kvm_supports_guest_debug()) {
+        error_report("gdbstub: KVM doesn't support guest debugging");
+        return -1;
+    }
+
     if (!device)
         return -1;
     if (strcmp(device, "none") != 0) {
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 7b22aeb6ae..6eb39a088b 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -46,6 +46,8 @@ extern bool kvm_readonly_mem_allowed;
 extern bool kvm_direct_msi_allowed;
 extern bool kvm_ioeventfd_any_length_allowed;
 extern bool kvm_msi_use_devid;
+extern bool kvm_has_guest_debug;
+extern int kvm_sstep_flags;
 
 #define kvm_enabled()           (kvm_allowed)
 /**
@@ -167,6 +169,17 @@ extern bool kvm_msi_use_devid;
  */
 #define kvm_msi_devid_required() (kvm_msi_use_devid)
 
+/*
+ * Does KVM support guest debugging
+ */
+#define kvm_supports_guest_debug() (kvm_has_guest_debug)
+
+/*
+ * kvm_supported_sstep_flags
+ * Returns: SSTEP_* flags that KVM supports for guest debug
+ */
+#define kvm_get_supported_sstep_flags() (kvm_sstep_flags)
+
 #else
 
 #define kvm_enabled()           (0)
@@ -184,6 +197,8 @@ extern bool kvm_msi_use_devid;
 #define kvm_direct_msi_enabled() (false)
 #define kvm_ioeventfd_any_length_enabled() (false)
 #define kvm_msi_devid_required() (false)
+#define kvm_supports_guest_debug() (false)
+#define kvm_get_supported_sstep_flags() (0)
 
 #endif  /* CONFIG_KVM_IS_POSSIBLE */
 
-- 
2.33.1




  parent reply	other threads:[~2021-12-15 20:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-15 20:25 [PULL 00/13] Misc patches for 2021-12-15 Paolo Bonzini
2021-12-15 20:25 ` [PULL 01/13] hw/scsi/lsi53c895a: Do not abort when DMA requested and no data queued Paolo Bonzini
2021-12-15 20:25 ` [PULL 02/13] tests/qtest: Add fuzz-lsi53c895a-test Paolo Bonzini
2021-12-15 20:25 ` [PULL 03/13] qapi/machine.json: Fix incorrect description for die-id Paolo Bonzini
2021-12-15 20:25 ` [PULL 04/13] scripts/entitlement.sh: Use backward-compatible cp flags Paolo Bonzini
2021-12-15 20:25 ` [PULL 05/13] virtio-gpu: do not byteswap padding Paolo Bonzini
2021-12-15 20:25 ` [PULL 06/13] linux-headers: update to 5.16-rc1 Paolo Bonzini
2021-12-15 20:25 ` [PULL 07/13] gdbstub: reject unsupported flags in handle_set_qemu_sstep Paolo Bonzini
2021-12-15 20:25 ` Paolo Bonzini [this message]
2021-12-15 20:25 ` [PULL 09/13] kvm: add support for KVM_GUESTDBG_BLOCKIRQ Paolo Bonzini
2021-12-15 20:25 ` [PULL 10/13] numa: Enable numa for SGX EPC sections Paolo Bonzini
2022-01-13 16:16   ` Daniel P. Berrangé
2021-12-15 20:25 ` [PULL 11/13] numa: Support SGX numa in the monitor and Libvirt interfaces Paolo Bonzini
2022-01-13 16:15   ` Daniel P. Berrangé
2022-01-17 10:37     ` Yang Zhong
2022-01-19  9:19       ` Daniel P. Berrangé
2021-12-15 20:25 ` [PULL 12/13] doc: Add the SGX numa description Paolo Bonzini
2021-12-15 20:25 ` [PULL 13/13] configure: remove dead variables Paolo Bonzini
2021-12-16 18:19 ` [PULL 00/13] Misc patches for 2021-12-15 Richard Henderson

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=20211215202515.91586-9-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=mlevitsk@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 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.