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
This commit is contained in:
Mark Johnston 2024-02-07 08:47:24 -05:00
parent e6516294f4
commit f493ea650e
4 changed files with 34 additions and 2 deletions

View file

@ -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
};

View file

@ -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 */

View file

@ -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

View file

@ -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);