Skip to content

Commit 13a8da8

Browse files
committed
Check SPRR by issuing MRS
1 parent 958ed09 commit 13a8da8

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

qemu/configure

+12-18
Original file line numberDiff line numberDiff line change
@@ -2151,32 +2151,26 @@ EOF
21512151
cat > $TMPC << EOF
21522152
#include "stdint.h"
21532153
int main() {
2154-
uint64_t commpage_sprr = (*(uint64_t*)0xFFFFFC10C);
2155-
2156-
// In Apple Hypervisor, this value is not accessbile and
2157-
// pthread_jit_write_protect_np essentially is a no-op
2158-
2159-
/*
2160-
if (!commpage_sprr) {
2161-
return 1;
2162-
} else {
2163-
return 0;
2164-
}
2165-
*/
2154+
uint64_t v;
21662155
2167-
// Now it is accessible but always zero, let's probe it runtime.
2156+
__asm__ __volatile__("isb sy\n"
2157+
"mrs %0, S3_6_c15_c1_5\n"
2158+
: "=r"(v)::"memory");
2159+
// In Apple Hypervisor virtualized environment (EL1), this value is not accessbile
2160+
// but pthread_jit_write_protect_np essentially is a no-op.
21682161
return 0;
21692162
}
21702163
EOF
21712164
if ! compile_prog ""; then
2172-
have_sprr='no'
2165+
have_sprr_mrs='no'
21732166
have_pthread_jit_protect='no'
21742167
else
21752168
$TMPE
21762169
if [ $? -eq 0 ]; then
2177-
have_sprr='yes'
2170+
have_sprr_mrs='yes'
21782171
else
2179-
have_sprr='no'
2172+
have_sprr_mrs='no'
2173+
have_pthread_jit_protect='no'
21802174
fi
21812175
fi
21822176
fi
@@ -2560,8 +2554,8 @@ if test "$have_pthread_jit_protect" = "yes" ; then
25602554
echo "HAVE_PTHREAD_JIT_PROTECT=y" >> $config_host_mak
25612555
fi
25622556

2563-
if test "$have_sprr" = "yes" ; then
2564-
echo "HAVE_SPRR=y" >> $config_host_mak
2557+
if test "$have_sprr_mrs" = "yes" ; then
2558+
echo "HAVE_SPRR_MRS=y" >> $config_host_mak
25652559
fi
25662560

25672561
# Hold two types of flag:

qemu/include/tcg/tcg-apple-jit.h

+10-12
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
#include "stdlib.h"
3131
#include "stdbool.h"
3232

33-
#if defined(__APPLE__) && defined(HAVE_SPRR) && (defined(__arm__) || defined(__aarch64__))
34-
3533
// Returns the S3_6_c15_c1_5 register's value
3634
// Taken from
3735
// https://stackoverflow.com/questions/70019553/lldb-how-to-read-the-permissions-of-a-memory-region-for-a-thread
3836
// https://blog.svenpeter.dev/posts/m1_sprr_gxf/
3937
// On Github Action (Virtualized environment), this shall always returns 0
38+
#if defined(HAVE_SPRR_MRS)
4039
static inline uint64_t read_sprr_perm(void)
4140
{
4241
uint64_t v;
@@ -45,6 +44,14 @@ static inline uint64_t read_sprr_perm(void)
4544
: "=r"(v)::"memory");
4645
return v;
4746
}
47+
#else
48+
static inline uint64_t read_sprr_perm(void)
49+
{
50+
return 0;
51+
}
52+
#endif
53+
54+
#if defined(__APPLE__) && defined(HAVE_PTHREAD_JIT_PROTECT) && (defined(__arm__) || defined(__aarch64__))
4855

4956
__attribute__((unused)) static inline uint8_t thread_mask()
5057
{
@@ -77,15 +84,6 @@ static inline void assert_executable(bool executable) {
7784

7885
#else
7986

80-
// Returns the S3_6_c15_c1_5 register's value
81-
// Taken from
82-
// https://stackoverflow.com/questions/70019553/lldb-how-to-read-the-permissions-of-a-memory-region-for-a-thread
83-
// https://blog.svenpeter.dev/posts/m1_sprr_gxf/
84-
static inline uint64_t read_sprr_perm(void)
85-
{
86-
return 0;
87-
}
88-
8987
__attribute__((unused)) static inline uint8_t thread_mask()
9088
{
9189
return 0;
@@ -107,7 +105,7 @@ static inline void assert_executable(bool executable) {
107105
#endif
108106

109107

110-
#if defined(__APPLE__) && defined(HAVE_PTHREAD_JIT_PROTECT) && defined(HAVE_SPRR) && (defined(__arm__) || defined(__aarch64__))
108+
#if defined(__APPLE__) && defined(HAVE_PTHREAD_JIT_PROTECT) && (defined(__arm__) || defined(__aarch64__))
111109

112110
/* write protect enable = write disable */
113111
static inline void jit_write_protect(int enabled)

0 commit comments

Comments
 (0)