Skip to content

Enable CNTVCT on cloned vCPUs#230

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:cloned-vcpu
Jul 20, 2026
Merged

Enable CNTVCT on cloned vCPUs#230
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:cloned-vcpu

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Worker vCPUs created for clone threads did not get CNTKCTL_EL1 configured, even though the initial vCPU enables EL0 access to the architected counter.

Set CNTKCTL_EL1 during cloned vCPU setup so CNTVCT_EL0 reads work from guest threads as they do on the main vCPU. Add a pthread regression test that reads CNTVCT_EL0 from both main and worker vCPUs.

Fix #229


Summary by cubic

Enable EL0 reads of the architected timers on all vCPUs by using a single CNTKCTL_EL1 mask in bootstrap and both cloned-vCPU paths (CLONE_THREAD and CLONE_VM). Restores CNTVCT_EL0/CNTPCT_EL0 for guest threads and adds a regression test. Fixes #229.

  • Bug Fixes
    • Define CNTKCTL_EL1_EL0_TIMER_EN in hvutil.h; apply it in bootstrap, thread_create_and_run, and vm_clone_thread_run to enable CNTVCT_EL0 and CNTPCT_EL0 at EL0.
    • Add tests/test-cntvct-thread.c; verify CNTVCT_EL0 on the main vCPU and a CLONE_THREAD worker. Add to test matrix and update baselines (elfuse-aarch64 238, qemu-aarch64 218).

Written for commit 37c3c53. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread src/runtime/forkipc.c Outdated
Comment thread src/runtime/forkipc.c Outdated
Comment thread tests/test-cntvct-thread.c Outdated
Comment thread tests/test-cntvct-thread.c Outdated
Comment thread tests/test-cntvct-thread.c Outdated
Comment thread tests/test-cntvct-thread.c Outdated
@doanbaotrung

Copy link
Copy Markdown
Collaborator Author

Implemented the reviewed fixes in third_party/elfuse:

  • Added shared CNTKCTL_EL1_EL0_TIMER_EN in hvutil.h.
  • Replaced all three 0x3ULL CNTKCTL sites in bootstrap.c and forkipc.c.
  • Expanded test-cntvct-thread.c to:
    • read both CNTVCT_EL0 and CNTPCT_EL0
    • cover pthread_create / CLONE_THREAD
    • cover raw clone(CLONE_VM | SIGCHLD) for vm_clone_thread_run
    • fail loudly on non-aarch64 builds with #error
    • document the current “trapped MRS returns 0” coupling

@doanbaotrung
doanbaotrung force-pushed the cloned-vcpu branch 2 times, most recently from 91c02c0 to 78cc0fc Compare July 20, 2026 05:24
Define the EL0 timer access mask once and reuse it for bootstrap,
CLONE_THREAD, and CLONE_VM vCPU setup.

Extend the CNTVCT regression test to also read CNTPCT_EL0 and cover
the raw CLONE_VM path so both cloned-vCPU setup sites are exercised.

Fix sysprog21#229
@jserv
jserv merged commit 6cee917 into sysprog21:main Jul 20, 2026
10 checks passed
@jserv

jserv commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Thank @doanbaotrung for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloned vCPUs do not preserve EL0 virtual counter access

2 participants