All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Du <duchao@eswincomputing.com>
To: kvm-riscv@lists.infradead.org
Subject: [RFC PATCH 2/3] RISC-V: KVM: Implement kvm_arch_vcpu_ioctl_set_guest_debug()
Date: Thu, 21 Dec 2023 09:50:01 +0000	[thread overview]
Message-ID: <20231221095002.7404-3-duchao@eswincomputing.com> (raw)
In-Reply-To: <20231221095002.7404-1-duchao@eswincomputing.com>

Update the guest_debug flags from userspace accordingly.
Route the breakpoint exceptions to HS mode if the VM is being debugged
by userspace, by clearing the corresponding bit in hedeleg CSR.

Signed-off-by: Chao Du <duchao@eswincomputing.com>
---
 arch/riscv/kvm/vcpu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index e087c809073c..b8144434ff23 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -473,8 +473,19 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
-	/* TODO; To be implemented later. */
-	return -EINVAL;
+	if (dbg->control & KVM_GUESTDBG_ENABLE) {
+		if (vcpu->guest_debug != dbg->control) {
+			vcpu->guest_debug = dbg->control;
+			csr_clear(CSR_HEDELEG, BIT(EXC_BREAKPOINT));
+		}
+	} else {
+		if (vcpu->guest_debug != 0) {
+			vcpu->guest_debug = 0;
+			csr_set(CSR_HEDELEG, BIT(EXC_BREAKPOINT));
+		}
+	}
+
+	return 0;
 }
 
 static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu)
-- 
2.17.1



WARNING: multiple messages have this Message-ID (diff)
From: Chao Du <duchao@eswincomputing.com>
To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
	anup@brainfault.org, atishp@atishpatra.org,
	dbarboza@ventanamicro.com, paul.walmsley@sifive.com,
	palmer@dabbelt.com, aou@eecs.berkeley.edu
Subject: [RFC PATCH 2/3] RISC-V: KVM: Implement kvm_arch_vcpu_ioctl_set_guest_debug()
Date: Thu, 21 Dec 2023 09:50:01 +0000	[thread overview]
Message-ID: <20231221095002.7404-3-duchao@eswincomputing.com> (raw)
In-Reply-To: <20231221095002.7404-1-duchao@eswincomputing.com>

Update the guest_debug flags from userspace accordingly.
Route the breakpoint exceptions to HS mode if the VM is being debugged
by userspace, by clearing the corresponding bit in hedeleg CSR.

Signed-off-by: Chao Du <duchao@eswincomputing.com>
---
 arch/riscv/kvm/vcpu.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index e087c809073c..b8144434ff23 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -473,8 +473,19 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
-	/* TODO; To be implemented later. */
-	return -EINVAL;
+	if (dbg->control & KVM_GUESTDBG_ENABLE) {
+		if (vcpu->guest_debug != dbg->control) {
+			vcpu->guest_debug = dbg->control;
+			csr_clear(CSR_HEDELEG, BIT(EXC_BREAKPOINT));
+		}
+	} else {
+		if (vcpu->guest_debug != 0) {
+			vcpu->guest_debug = 0;
+			csr_set(CSR_HEDELEG, BIT(EXC_BREAKPOINT));
+		}
+	}
+
+	return 0;
 }
 
 static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu)
-- 
2.17.1


  parent reply	other threads:[~2023-12-21  9:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21  9:49 [RFC PATCH 0/3] RISC-V: KVM: Guest Debug Support Chao Du
2023-12-21  9:49 ` Chao Du
2023-12-21  9:50 ` [RFC PATCH 1/3] RISC-V: KVM: Enable the KVM_CAP_SET_GUEST_DEBUG capability Chao Du
2023-12-21  9:50   ` Chao Du
2023-12-21  9:50 ` Chao Du [this message]
2023-12-21  9:50   ` [RFC PATCH 2/3] RISC-V: KVM: Implement kvm_arch_vcpu_ioctl_set_guest_debug() Chao Du
2023-12-21  9:50 ` [RFC PATCH 3/3] RISC-V: KVM: Handle breakpoint exits for VCPU Chao Du
2023-12-21  9:50   ` Chao Du
2023-12-21 12:31 ` [RFC PATCH 0/3] RISC-V: KVM: Guest Debug Support Anup Patel
2023-12-21 12:31   ` Anup Patel
2023-12-22  8:28   ` Chao Du
2023-12-22  8:28     ` Chao Du
2023-12-25  2:52     ` Chao Du
2023-12-25  2:52       ` Chao Du
2024-01-04 10:22       ` Chao Du
2024-01-04 10:22         ` Chao Du
2024-01-04 11:29     ` Anup Patel
2024-01-04 11:29       ` Anup Patel
2024-01-05  9:42       ` Chao Du
2024-01-05  9:42         ` Chao Du

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=20231221095002.7404-3-duchao@eswincomputing.com \
    --to=duchao@eswincomputing.com \
    --cc=kvm-riscv@lists.infradead.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.