From dfe9d006add46d0cda5baaf32f12796b7faed528 Mon Sep 17 00:00:00 2001 From: "fu.lin" Date: Tue, 9 Aug 2022 12:18:00 -0700 Subject: [PATCH] breakpoint: enable breakpoints by default on amd64 and arm64 Signed-off-by: fu.lin Signed-off-by: Andrei Vagin --- compel/arch/aarch64/src/lib/infect.c | 12 ++++++++++++ compel/arch/x86/src/lib/infect.c | 11 +++++++++++ criu/include/fault-injection.h | 8 -------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/compel/arch/aarch64/src/lib/infect.c b/compel/arch/aarch64/src/lib/infect.c index 7b75da890..d0189f003 100644 --- a/compel/arch/aarch64/src/lib/infect.c +++ b/compel/arch/aarch64/src/lib/infect.c @@ -207,6 +207,7 @@ static struct hwbp_cap *ptrace_get_hwbp_cap(pid_t pid) int ptrace_set_breakpoint(pid_t pid, void *addr) { + k_rtsigset_t block; struct hwbp_cap *info = ptrace_get_hwbp_cap(pid); struct user_hwdebug_state regs = {}; unsigned int ctrl = 0; @@ -242,6 +243,17 @@ int ptrace_set_breakpoint(pid_t pid, void *addr) if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_BREAK, &iovec)) return -1; + /* + * FIXME(issues/1429): SIGTRAP can't be blocked, otherwise its handler + * will be reset to the default one. + */ + ksigfillset(&block); + ksigdelset(&block, SIGTRAP); + if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &block)) { + pr_perror("Can't block signals for %d", pid); + return -1; + } + if (ptrace(PTRACE_CONT, pid, NULL, NULL) != 0) { pr_perror("Unable to restart the stopped tracee process %d", pid); return -1; diff --git a/compel/arch/x86/src/lib/infect.c b/compel/arch/x86/src/lib/infect.c index c0e7a544a..01959b95b 100644 --- a/compel/arch/x86/src/lib/infect.c +++ b/compel/arch/x86/src/lib/infect.c @@ -588,6 +588,7 @@ int arch_fetch_sas(struct parasite_ctl *ctl, struct rt_sigframe *s) int ptrace_set_breakpoint(pid_t pid, void *addr) { + k_rtsigset_t block; int ret; /* Set a breakpoint */ @@ -603,6 +604,16 @@ int ptrace_set_breakpoint(pid_t pid, void *addr) return -1; } + /* + * FIXME(issues/1429): SIGTRAP can't be blocked, otherwise its handler + * will be reset to the default one. + */ + ksigfillset(&block); + ksigdelset(&block, SIGTRAP); + if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &block)) { + pr_perror("Can't block signals for %d", pid); + return -1; + } ret = ptrace(PTRACE_CONT, pid, NULL, NULL); if (ret) { pr_perror("Unable to restart the stopped tracee process %d", pid); diff --git a/criu/include/fault-injection.h b/criu/include/fault-injection.h index f33918de8..69d670be9 100644 --- a/criu/include/fault-injection.h +++ b/criu/include/fault-injection.h @@ -24,14 +24,6 @@ enum faults { static inline bool __fault_injected(enum faults f, enum faults fi_strategy) { - /* - * Temporary workaround for Xen guests. Breakpoints degrade - * performance linearly, so until we find out the reason, - * let's disable them. - */ - if (f == FI_NO_BREAKPOINTS) - return true; - return fi_strategy == f; }