fix: validate the CASP pair on a mismatch in the LSE emulator

This commit is contained in:
Kurt Himebauch committed 2026-11-08 19:26:26 -05:00
1 parent ffac895afc
commit 0db9865045
6 files changed
+54 -18

No files matched your search

+3
View File
@@ -99,6 +99,9 @@ static __attribute__((noinline)) void single_forms(void) {
register uint64_t e0 __asm__("x4") = 1, e1 __asm__("x5") = 2, d0 __asm__("x6") = 3, d1 __asm__("x7") = 4;
__asm__ volatile("caspal x4, x5, x6, x7, [%4]" : "+r"(e0), "+r"(e1) : "r"(d0), "r"(d1), "r"(pair) : "memory");
check(e0 == 1 && e1 == 2 && pair[0] == 3 && pair[1] == 4, "caspal");
register uint64_t m0 __asm__("x4") = 8, m1 __asm__("x5") = 9, n0 __asm__("x6") = 5, n1 __asm__("x7") = 6;
__asm__ volatile("caspal x4, x5, x6, x7, [%4]" : "+r"(m0), "+r"(m1) : "r"(n0), "r"(n1), "r"(pair) : "memory");
check(m0 == 3 && m1 == 4 && pair[0] == 3 && pair[1] == 4, "caspal returns the current pair on a mismatch");
uint64_t missed = casal64(&v, 99, 1);
check(missed == 7 && v == 7, "casal leaves memory alone on a mismatch");
+11 -4
View File
@@ -1,3 +1,4 @@
import os
from pathlib import Path
import shutil
import subprocess
@@ -11,6 +12,8 @@ SYSROOT = Path("/usr/aarch64-linux-gnu")
def toolchain():
if not (shutil.which("aarch64-linux-gnu-gcc") and shutil.which("qemu-aarch64") and SYSROOT.is_dir()):
if os.environ.get("CI"):
raise AssertionError("CI must install gcc-aarch64-linux-gnu, libc6-dev-arm64-cross and qemu-user")
raise unittest.SkipTest("needs aarch64-linux-gnu-gcc, libc6-dev-arm64-cross and qemu-user")
@@ -46,15 +49,19 @@ class LseEmuTest(unittest.TestCase):
self.assertIn("lse ok", result.stdout)
self.assertRegex(result.stderr, r"traps=[1-9]\d* patched=0 ")
def test_patching_runs_every_form_on_an_armv8_0_cpu(self):
# qemu-user write-protects translated code pages and races when other threads run them while the
# stub arena is written, so threaded patching is only meaningful on hardware.
def patched(self, threads):
result = self.run_on("cortex-a57", f"LD_PRELOAD={self.library}", "LSE_EMU=1", "LSE_EMU_PATCH=1",
"LSE_EMU_STATS=1", threads=1)
"LSE_EMU_STATS=1", threads=threads)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn("lse ok", result.stdout)
self.assertRegex(result.stderr, r"patched=[1-9]\d* failed=0")
def test_patching_runs_every_form_on_an_armv8_0_cpu(self):
self.patched(threads=1)
def test_patching_stays_atomic_across_threads(self):
self.patched(threads=4)
def test_it_stays_off_without_the_switch(self):
result = self.run_on("cortex-a57", f"LD_PRELOAD={self.library}")
self.assertEqual(result.returncode, -4, result.stdout + result.stderr)