git: da0d8fe5d903 - main - amd64/vmm: Do not fall back to the VMCS for vmxctx registers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Nov 2026 08:03:59 UTC
The branch main has been updated by hayzam:
URL: https://cgit.FreeBSD.org/src/commit/?id=da0d8fe5d90375ca506e15c0c74e64bcefca8530
commit da0d8fe5d90375ca506e15c0c74e64bcefca8530
Author: Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-27 07:57:33 +0000
Commit: Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-27 07:57:33 +0000
amd64/vmm: Do not fall back to the VMCS for vmxctx registers
vmx_setreg() first calls vmxctx_setreg() and, if that fails, handles the
register as a VMCS field. This relies on vmxctx_setreg() failing only
for registers that are not kept in the vCPU context. Were it to reject
a value for one of its own registers, the error would be dropped and
the request passed on to vmcs_setreg(), which would fail it only
because the register has no VMCS field.
Check whether the register is kept in the vCPU context instead, and if
so return the result of vmxctx_setreg() directly. This lets
vmxctx_setreg() validate values and have its error returned as is. Do
the same in vmx_getreg(), so that the two functions read alike.
No functional change intended.
Reviewed by: markj
Approved by: markj
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61954
---
sys/amd64/vmm/intel/vmx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index c16e0ae33fb9..b51140a0213d 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -3433,8 +3433,8 @@ vmx_getreg(void *vcpui, int reg, uint64_t *retval)
return (0);
}
- if (vmxctx_getreg(&vcpu->ctx, reg, retval) == 0)
- return (0);
+ if (vmxctx_regptr(&vcpu->ctx, reg) != NULL)
+ return (vmxctx_getreg(&vcpu->ctx, reg, retval));
return (vmcs_getreg(vcpu->vmcs, running, reg, retval));
}
@@ -3456,8 +3456,8 @@ vmx_setreg(void *vcpui, int reg, uint64_t val)
if (reg == VM_REG_GUEST_INTR_SHADOW)
return (vmx_modify_intr_shadow(vcpu, running, val));
- if (vmxctx_setreg(&vcpu->ctx, reg, val) == 0)
- return (0);
+ if (vmxctx_regptr(&vcpu->ctx, reg) != NULL)
+ return (vmxctx_setreg(&vcpu->ctx, reg, val));
/* Do not permit user write access to VMCS fields by offset. */
if (reg < 0)