vm_session(x86): support cstar register

Fixes #3964
This commit is contained in:
Alexander Boettcher 2020-11-28 22:05:47 +01:00 committed by Norman Feske
parent 9189342b77
commit c5de2acf57
12 changed files with 37 additions and 14 deletions

View File

@ -152,6 +152,7 @@ struct Vcpu : Thread
MSR_FMASK = 0x2842,
MSR_LSTAR = 0x2844,
MSR_CSTAR = 0x2846,
MSR_STAR = 0x284a,
KERNEL_GS_BASE = 0x284c,
@ -614,6 +615,7 @@ struct Vcpu : Thread
state.star.value(l4_vm_vmx_read(vmcs, Vmcs::MSR_STAR));
state.lstar.value(l4_vm_vmx_read(vmcs, Vmcs::MSR_LSTAR));
state.cstar.value(l4_vm_vmx_read(vmcs, Vmcs::MSR_CSTAR));
state.fmask.value(l4_vm_vmx_read(vmcs, Vmcs::MSR_FMASK));
state.kernel_gs_base.value(l4_vm_vmx_read(vmcs, Vmcs::KERNEL_GS_BASE));
@ -756,7 +758,7 @@ struct Vcpu : Thread
error("pdpte not implemented");
}
if (state.star.valid() || state.lstar.valid() ||
if (state.star.valid() || state.lstar.valid() || state.cstar.valid() ||
state.fmask.valid() || state.kernel_gs_base.valid()) {
error("star, fstar, fmask, kernel_gs_base not implemented");
@ -813,6 +815,9 @@ struct Vcpu : Thread
if (state.lstar.valid())
l4_vm_vmx_write(vmcs, Vmcs::MSR_LSTAR, state.lstar.value());
if (state.cstar.valid())
l4_vm_vmx_write(vmcs, Vmcs::MSR_CSTAR, state.cstar.value());
if (state.fmask.valid())
l4_vm_vmx_write(vmcs, Vmcs::MSR_FMASK, state.fmask.value());
@ -1032,7 +1037,7 @@ struct Vcpu : Thread
vmcb->control_area.tsc_offset = _tsc_offset;
}
if (state.star.value() || state.lstar.value() ||
if (state.star.value() || state.lstar.value() || state.cstar.value() ||
state.fmask.value() || state.kernel_gs_base.value())
error(__LINE__, " not implemented");

View File

@ -566,6 +566,7 @@ namespace Nova {
mword_t cr8, efer;
unsigned long long star;
unsigned long long lstar;
unsigned long long cstar;
unsigned long long fmask;
unsigned long long kernel_gs_base;
unsigned tpr;
@ -625,6 +626,8 @@ namespace Nova {
inline void write_star(mword_t value) { star = value; }
inline mword_t read_lstar() { return lstar; }
inline void write_lstar(mword_t value) { lstar = value; }
inline mword_t read_cstar() { return cstar; }
inline void write_cstar(mword_t value) { cstar = value; }
inline mword_t read_fmask() { return fmask; }
inline void write_fmask(mword_t value) { fmask = value; }
inline mword_t read_kernel_gs_base() { return kernel_gs_base; }
@ -656,6 +659,8 @@ namespace Nova {
inline void write_star(mword_t) { }
inline mword_t read_lstar() { return 0UL; }
inline void write_lstar(mword_t) { }
inline mword_t read_cstar() { return 0UL; }
inline void write_cstar(mword_t) { }
inline mword_t read_fmask() { return 0UL; }
inline void write_fmask(mword_t) { }
inline mword_t read_kernel_gs_base() { return 0UL; }

View File

@ -1 +1 @@
e0a4960688b5e6aac8f77998dda98e891e19441c
c9523ea8553360b7d9732280817bb2ba1ef701de

View File

@ -4,7 +4,7 @@ DOWNLOADS := nova.git
# r10 branch
URL(nova) := https://github.com/alex-ab/NOVA.git
REV(nova) := af931a15fc6b032615f076e946b6026a31dbacaf
REV(nova) := 7f9d73e3266c7cb7418c18fb37bb97e3c6b2442d
DIR(nova) := src/kernel/nova
PATCHES := $(sort $(wildcard $(REP_DIR)/patches/*.patch))

View File

@ -191,6 +191,7 @@ struct Vcpu {
if (utcb.mtd & Nova::Mtd::SYSCALL_SWAPGS) {
state.star.value(utcb.read_star());
state.lstar.value(utcb.read_lstar());
state.cstar.value(utcb.read_cstar());
state.fmask.value(utcb.read_fmask());
state.kernel_gs_base.value(utcb.read_kernel_gs_base());
}
@ -384,11 +385,13 @@ struct Vcpu {
}
if (state.star.valid() || state.lstar.valid() ||
state.fmask.valid() || state.kernel_gs_base.valid()) {
state.cstar.valid() || state.fmask.valid() ||
state.kernel_gs_base.valid()) {
utcb.mtd |= Nova::Mtd::SYSCALL_SWAPGS;
utcb.write_star(state.star.value());
utcb.write_lstar(state.lstar.value());
utcb.write_cstar(state.cstar.value());
utcb.write_fmask(state.fmask.value());
utcb.write_kernel_gs_base(state.kernel_gs_base.value());
}
@ -671,7 +674,8 @@ struct Vcpu {
mtd |= Nova::Mtd::PDPTE;
if (state.star.valid() || state.lstar.valid() ||
state.fmask.valid() || state.kernel_gs_base.valid())
state.cstar.valid() || state.fmask.valid() ||
state.kernel_gs_base.valid())
mtd |= Nova::Mtd::SYSCALL_SWAPGS;
if (state.tpr.valid() || state.tpr_threshold.valid())

View File

@ -374,12 +374,12 @@ struct Vcpu : Genode::Thread
#endif
}
if (state.star.valid() || state.lstar.valid() ||
if (state.star.valid() || state.lstar.valid() || state.cstar.valid() ||
state.fmask.valid() || state.kernel_gs_base.valid())
{
if (_show_error_unsupported_star) {
_show_error_unsupported_star = false;
Genode::error("star, lstar, fmask, gs_base not supported by seL4");
Genode::error("star, lstar, cstar, fmask, gs_base not supported by seL4");
}
}
@ -704,7 +704,7 @@ struct Vcpu : Genode::Thread
state.efer.value(_read_vmcs(service, Vmcs::EFER));
/* XXX star, lstar, fmask, kernel_gs_base not supported by seL4 */
/* XXX star, lstar, cstar, fmask, kernel_gs_base not supported by seL4 */
/* XXX tpr and tpr_threshold not supported by seL4 */
}

View File

@ -134,6 +134,7 @@ struct Genode::Vm_state
Register<uint64_t> star;
Register<uint64_t> lstar;
Register<uint64_t> cstar;
Register<uint64_t> fmask;
Register<uint64_t> kernel_gs_base;

View File

@ -1 +1 @@
e8d6968e967852affc6a7290936466f032dc210b
e4c5e41a5d3b5398a310dbc39b52a5393526c816

View File

@ -3,8 +3,8 @@ VERSION := git
DOWNLOADS := seoul.git
URL(seoul) := https://github.com/alex-ab/seoul.git
# branch genode_20_02
REV(seoul) := bcbb781d9412fe8c10d6e324e02116faf04b8d1f
# branch genode_20_11
REV(seoul) := 9c009e7ad2b5ec9fbafdc731e8796f33ff90e921
DIR(seoul) := src/app/seoul
#

View File

@ -373,10 +373,10 @@ unsigned Seoul::read_vm_state(Genode::Vm_state &state, CpuState &seoul)
Genode::warning("pdpte not supported by Seoul");
}
if (state.star.valid() || state.lstar.valid() ||
if (state.star.valid() || state.lstar.valid() || state.cstar.valid() ||
state.fmask.valid() || state.kernel_gs_base.valid()) {
Genode::warning("star, lstar, fmask, kernel_gs not supported by Seoul");
Genode::warning("star, lstar, cstar, fmask, kernel_gs not supported by Seoul");
}
if (state.tpr.valid() || state.tpr_threshold.valid()) {

View File

@ -517,6 +517,7 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher<Genode::Thread>,
utcb->mtd |= Mtd::SYSCALL_SWAPGS;
utcb->write_star(pCtx->msrSTAR);
utcb->write_lstar(pCtx->msrLSTAR);
utcb->write_cstar(pCtx->msrCSTAR);
utcb->write_fmask(pCtx->msrSFMASK);
utcb->write_kernel_gs_base(pCtx->msrKERNELGSBASE);
@ -604,6 +605,9 @@ class Vcpu_handler : public Vmm::Vcpu_dispatcher<Genode::Thread>,
if (pCtx->msrLSTAR != utcb->read_lstar())
CPUMSetGuestMsr(pVCpu, MSR_K8_LSTAR, utcb->read_lstar());
if (pCtx->msrCSTAR != utcb->read_cstar())
CPUMSetGuestMsr(pVCpu, MSR_K8_CSTAR, utcb->read_cstar());
if (pCtx->msrSFMASK != utcb->read_fmask())
CPUMSetGuestMsr(pVCpu, MSR_K8_SF_MASK, utcb->read_fmask());

View File

@ -345,6 +345,7 @@ class Vcpu_handler : public Genode::List<Vcpu_handler>::Element
_state->star.value(pCtx->msrSTAR);
_state->lstar.value(pCtx->msrLSTAR);
_state->cstar.value(pCtx->msrCSTAR);
_state->fmask.value(pCtx->msrSFMASK);
_state->kernel_gs_base.value(pCtx->msrKERNELGSBASE);
@ -437,6 +438,9 @@ class Vcpu_handler : public Genode::List<Vcpu_handler>::Element
if (pCtx->msrLSTAR != _state->lstar.value())
CPUMSetGuestMsr(pVCpu, MSR_K8_LSTAR, _state->lstar.value());
if (pCtx->msrCSTAR != _state->cstar.value())
CPUMSetGuestMsr(pVCpu, MSR_K8_CSTAR, _state->cstar.value());
if (pCtx->msrSFMASK != _state->fmask.value())
CPUMSetGuestMsr(pVCpu, MSR_K8_SF_MASK, _state->fmask.value());