On Mon, Oct 26, 2020 at 04:45:18PM -0700, Andy Lutomirski wrote:

> PeterZ, this new scheme of having handlers clear bits in dr6 to
> consume them and set bits in virtual_dr6 to send signals is
> incomprehensible -- there is no possible way to read traps.c and tell
> what the code does :(

IIRC, it was you who suggested it. Also the old code was equally
incomprehensible. Now it has actual semantics.

> I attached a test case.  I'll make a real patch out of this in a bit.
> This passes on 5.8, and I haven't tested it yet on 5.10-rc1.  The real
> patch will also test ICEBP, and I'm sure we'll be quite unhappy with
> the result of that.

> diff --git a/tools/testing/selftests/x86/single_step_syscall.c 
> b/tools/testing/selftests/x86/single_step_syscall.c
> index 5a4c6e06872e..f6abefd4066e 100644
> --- a/tools/testing/selftests/x86/single_step_syscall.c
> +++ b/tools/testing/selftests/x86/single_step_syscall.c
> @@ -72,7 +72,6 @@ static unsigned char altstack_data[SIGSTKSZ];
>  static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
>  {
>       ucontext_t *ctx = (ucontext_t*)ctx_void;
> -     unsigned long dr6 = info->si_code;
>  
>       if (get_eflags() & X86_EFLAGS_TF) {
>               set_eflags(get_eflags() & ~X86_EFLAGS_TF);
> @@ -89,7 +88,10 @@ static void sigtrap(int sig, siginfo_t *info, void 
> *ctx_void)
>                      (unsigned long)ctx->uc_mcontext.gregs[REG_IP]);
>       }
>  
> -     printf("DR6 = 0x%lx\n", dr6);
> +     if (info->si_code != TRAP_TRACE) {
> +             printf("[FAIL]\tsi_code was 0x%lx; should have been TRAP_TRACE 
> (0x%lx)\n", (unsigned long)info->si_code, (unsigned long)TRAP_TRACE);
> +             _exit(1);
> +     }
>  }

That actually works (tested). Nothing here cares about the virtual_dr6 value.

Think of virtual_dr6 as the value used by ptrace_{get,set}_debugreg(6).
It (should) only contain bits that results from other ptrace() actions.

Reply via email to