From 6f0e4e848bcff71efa95a049c7b804ce1dcf2627 Mon Sep 17 00:00:00 2001 From: Ignacio Moreno Gonzalez Date: Wed, 16 Jul 2025 16:38:13 +0200 Subject: [PATCH] restore: flush caches during restore See the previous commit for rationale and architecture-specific details. [ avagin: tweak code comment ] Signed-off-by: Ignacio Moreno Gonzalez Signed-off-by: Andrei Vagin --- criu/cr-restore.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/criu/cr-restore.c b/criu/cr-restore.c index c1d1f4b9d..b37603563 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -2569,6 +2569,17 @@ static int remap_restorer_blob(void *addr) restorer_setup_c_header_desc(&pbd, true); compel_relocs_apply(addr, addr, &pbd); + /* + * Ensure the infected thread sees the updated code. + * + * On architectures like ARM64, the Data Cache (D-cache) and + * Instruction Cache (I-cache) are not automatically coherent. + * Modifications land in the D-cache, so we must flush (clean) the + * D-cache to push changes to RAM to ensure the CPU fetches the updated + * instructions. + */ + __builtin___clear_cache(addr, addr + pbd.hdr.bsize); + return 0; }