Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm64/vmm: Preserve PSR_C64 when injecting an exception #2255

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions sys/arm64/vmm/vmm_arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,29 +1165,49 @@

for (;;) {
if (hypctx->has_exception) {
size_t off;
uint64_t c64mask;

hypctx->has_exception = false;
hypctx->elr_el1 = hypctx->tf.tf_elr;

mode = hypctx->tf.tf_spsr & (PSR_M_MASK | PSR_M_32);

if (mode == PSR_M_EL1t) {
hypctx->tf.tf_elr = hypctx->vbar_el1 + 0x0;
off = 0;
} else if (mode == PSR_M_EL1h) {
hypctx->tf.tf_elr = hypctx->vbar_el1 + 0x200;
off = 0x200;
} else if ((mode & PSR_M_32) == PSR_M_64) {
/* 64-bit EL0 */
hypctx->tf.tf_elr = hypctx->vbar_el1 + 0x400;
off = 0x400;
} else {
/* 32-bit EL0 */
hypctx->tf.tf_elr = hypctx->vbar_el1 + 0x600;
off = 0x600;
}
c64mask = 0;
#if __has_feature(capabilities)
switch (hypctx->cpacr_el1 & CPACR_CEN_MASK) {
case CPACR_CEN_TRAP_ALL1:
case CPACR_CEN_TRAP_ALL2:
hypctx->tf.tf_elr = cheri_setaddress(hypctx->elr_el1,

Check warning on line 1192 in sys/arm64/vmm/vmm_arm64.c

View workflow job for this annotation

GitHub Actions / Style Checker

line over 80 characters
hypctx->vbar_el1 + off);
break;
default:
hypctx->tf.tf_elr = hypctx->vbar_el1 + off;
if (hypctx->cctlr_el1 & CCTLR_EL1_C64E_MASK)
c64mask = PSR_C64;
break;
}
#else
hypctx->tf.tf_elr = hypctx->vbar_el1 + off;
#endif

/* Set the new spsr */
hypctx->spsr_el1 = hypctx->tf.tf_spsr;

/* Set the new cpsr */
hypctx->tf.tf_spsr = hypctx->spsr_el1 & PSR_FLAGS;
hypctx->tf.tf_spsr |= PSR_DAIF | PSR_M_EL1h;
hypctx->tf.tf_spsr |= PSR_DAIF | PSR_M_EL1h | c64mask;

/*
* Update fields that may change on exeption entry
Expand Down Expand Up @@ -1520,22 +1540,21 @@

if (val != 0) {
hypctx->debug_spsr |= (hypctx->tf.tf_spsr & PSR_SS);
hypctx->debug_mdscr |= hypctx->mdscr_el1 &
(MDSCR_SS | MDSCR_KDE);
hypctx->debug_mdscr |= (hypctx->mdscr_el1 & MDSCR_SS);

hypctx->tf.tf_spsr |= PSR_SS;
hypctx->mdscr_el1 |= MDSCR_SS | MDSCR_KDE;
hypctx->mdscr_el1 |= MDSCR_SS;
hypctx->mdcr_el2 |= MDCR_EL2_TDE;
} else {
hypctx->tf.tf_spsr &= ~PSR_SS;
hypctx->tf.tf_spsr |= hypctx->debug_spsr;
hypctx->debug_spsr &= ~PSR_SS;
hypctx->mdscr_el1 &= ~(MDSCR_SS | MDSCR_KDE);
hypctx->mdscr_el1 &= ~MDSCR_SS;
hypctx->mdscr_el1 |= hypctx->debug_mdscr;
hypctx->debug_mdscr &= ~(MDSCR_SS | MDSCR_KDE);
hypctx->debug_mdscr &= ~MDSCR_SS;
hypctx->mdcr_el2 &= ~MDCR_EL2_TDE;
}
break;

Check warning on line 1557 in sys/arm64/vmm/vmm_arm64.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
case VM_CAP_MASK_HWINTR:
if ((val != 0) == ((hypctx->setcaps & (1ul << num)) != 0))
break;
Expand Down