-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Record and replay architected timer accesses on arm64
This works using the recently added support for prctl(PR_SET_TSC) on arm64 which is due to be released in kernel version 6.12. Fixes #3740
- Loading branch information
Showing
17 changed files
with
241 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "util.h" | ||
|
||
#include <sys/auxv.h> | ||
#include <sys/prctl.h> | ||
#include <stdio.h> | ||
|
||
long cntfrq(void) { | ||
long c; | ||
__asm__ __volatile__("mrs %0, cntfrq_el0" : "=r"(c)); | ||
return c; | ||
} | ||
|
||
long cntvct(void) { | ||
long c; | ||
__asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(c)); | ||
return c; | ||
} | ||
|
||
long cntvctss(void) { | ||
long c; | ||
if (getauxval(AT_HWCAP2) & HWCAP2_ECV) { | ||
__asm__ __volatile__(".arch armv8.6-a\nmrs %0, cntvctss_el0" : "=r"(c)); | ||
} else { | ||
__asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(c)); | ||
} | ||
return c; | ||
} | ||
|
||
long initial_cntfrq; | ||
long initial_cntvct; | ||
|
||
void arch_timer_nops(void) { | ||
__asm__ __volatile__("mrs xzr, cntfrq_el0"); | ||
__asm__ __volatile__("mrs xzr, cntvct_el0"); | ||
if (getauxval(AT_HWCAP2) & HWCAP2_ECV) { | ||
__asm__ __volatile__("mrs xzr, cntvctss_el0"); | ||
} | ||
} | ||
|
||
void diversion_check(void) { | ||
arch_timer_nops(); | ||
test_assert(initial_cntfrq == cntfrq()); | ||
test_assert(initial_cntvct < cntvct()); | ||
test_assert(initial_cntvct < cntvctss()); | ||
atomic_puts("diversion_check passed"); | ||
} | ||
|
||
void breakpoint(void) {} | ||
|
||
int main(void) { | ||
initial_cntfrq = cntfrq(); | ||
initial_cntvct = cntvct(); | ||
breakpoint(); | ||
|
||
atomic_printf("%ld\n", cntvct()); | ||
atomic_printf("%ld\n", cntvctss()); | ||
atomic_printf("%ld\n", cntfrq()); | ||
|
||
arch_timer_nops(); | ||
|
||
atomic_puts("EXIT-SUCCESS"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source `dirname $0`/util.sh | ||
if ! prctl_tsc_supported; then | ||
exit 77 | ||
fi | ||
compare_test EXIT-SUCCESS | ||
debug_gdb_only arm/diversion_arch_timer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from util import * | ||
|
||
send_gdb('break breakpoint') | ||
expect_gdb('Breakpoint 1') | ||
|
||
send_gdb('c') | ||
expect_gdb('Breakpoint 1') | ||
|
||
send_gdb('call diversion_check()') | ||
expect_gdb('diversion_check passed') | ||
|
||
ok() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../util.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../util.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TEST_PREFIX=arm/ | ||
source `dirname $0`/../util.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source `dirname $0`/util.sh | ||
if ! prctl_tsc_supported; then | ||
exit 77 | ||
fi | ||
compare_test EXIT-SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <stdlib.h> | ||
#include <sys/prctl.h> | ||
|
||
int main(void) { | ||
return prctl(PR_SET_TSC, PR_TSC_ENABLE) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; | ||
} |
Oops, something went wrong.