git: f493ea650e61 - main - vmm: Expose more registers to VM_GET_REGISTER
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 07 Feb 2024 13:53:10 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=f493ea650e6137ba657dfa0627da1e8bb4a985e9
commit f493ea650e6137ba657dfa0627da1e8bb4a985e9
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-02-07 13:47:24 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-02-07 13:52:46 +0000
vmm: Expose more registers to VM_GET_REGISTER
In a follow-up revision the gdb stub will support sending an XML target
description to gdb, which lets us send additional registers, including
the ones added in this patch.
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D43665
---
sys/amd64/include/vmm.h | 4 ++++
sys/amd64/vmm/amd/vmcb.c | 17 +++++++++++++++++
sys/amd64/vmm/intel/vmcs.c | 5 ++++-
sys/amd64/vmm/intel/vmx.c | 10 +++++++++-
4 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h
index 273a1a46ba04..7d5d13678122 100644
--- a/sys/amd64/include/vmm.h
+++ b/sys/amd64/include/vmm.h
@@ -98,6 +98,10 @@ enum vm_reg_name {
VM_REG_GUEST_DR3,
VM_REG_GUEST_DR6,
VM_REG_GUEST_ENTRY_INST_LENGTH,
+ VM_REG_GUEST_FS_BASE,
+ VM_REG_GUEST_GS_BASE,
+ VM_REG_GUEST_KGS_BASE,
+ VM_REG_GUEST_TPR,
VM_REG_LAST
};
diff --git a/sys/amd64/vmm/amd/vmcb.c b/sys/amd64/vmm/amd/vmcb.c
index ce05c912fc6a..4bd2fae9f821 100644
--- a/sys/amd64/vmm/amd/vmcb.c
+++ b/sys/amd64/vmm/amd/vmcb.c
@@ -39,6 +39,7 @@
#include "vmm_ktr.h"
+#include "vlapic.h"
#include "vmcb.h"
#include "svm.h"
#include "svm_softc.h"
@@ -231,6 +232,22 @@ vmcb_read(struct svm_vcpu *vcpu, int ident, uint64_t *retval)
*retval = seg->selector;
break;
+ case VM_REG_GUEST_FS_BASE:
+ case VM_REG_GUEST_GS_BASE:
+ seg = vmcb_segptr(vmcb, ident == VM_REG_GUEST_FS_BASE ?
+ VM_REG_GUEST_FS : VM_REG_GUEST_GS);
+ KASSERT(seg != NULL, ("%s: unable to get segment %d from VMCB",
+ __func__, ident));
+ *retval = seg->base;
+ break;
+ case VM_REG_GUEST_KGS_BASE:
+ *retval = state->kernelgsbase;
+ break;
+
+ case VM_REG_GUEST_TPR:
+ *retval = vlapic_get_cr8(vm_lapic(vcpu->vcpu));
+ break;
+
case VM_REG_GUEST_GDTR:
case VM_REG_GUEST_IDTR:
/* GDTR and IDTR don't have segment selectors */
diff --git a/sys/amd64/vmm/intel/vmcs.c b/sys/amd64/vmm/intel/vmcs.c
index 52068b8eba54..35c2ee5b6eff 100644
--- a/sys/amd64/vmm/intel/vmcs.c
+++ b/sys/amd64/vmm/intel/vmcs.c
@@ -119,10 +119,13 @@ vmcs_field_encoding(int ident)
return (VMCS_GUEST_PDPTE3);
case VM_REG_GUEST_ENTRY_INST_LENGTH:
return (VMCS_ENTRY_INST_LENGTH);
+ case VM_REG_GUEST_FS_BASE:
+ return (VMCS_GUEST_FS_BASE);
+ case VM_REG_GUEST_GS_BASE:
+ return (VMCS_GUEST_GS_BASE);
default:
return (-1);
}
-
}
static int
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index b7c1544ac0b3..31ca9256b527 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -3404,8 +3404,16 @@ vmx_getreg(void *vcpui, int reg, uint64_t *retval)
panic("vmx_getreg: %s%d is running", vm_name(vmx->vm),
vcpu->vcpuid);
- if (reg == VM_REG_GUEST_INTR_SHADOW)
+ switch (reg) {
+ case VM_REG_GUEST_INTR_SHADOW:
return (vmx_get_intr_shadow(vcpu, running, retval));
+ case VM_REG_GUEST_KGS_BASE:
+ *retval = vcpu->guest_msrs[IDX_MSR_KGSBASE];
+ return (0);
+ case VM_REG_GUEST_TPR:
+ *retval = vlapic_get_cr8(vm_lapic(vcpu->vcpu));
+ return (0);
+ }
if (vmxctx_getreg(&vcpu->ctx, reg, retval) == 0)
return (0);