Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | // SPDX-License-Identifier: GPL-2.0+ /* * Ptrace test for hw breakpoints * * Based on tools/testing/selftests/breakpoints/breakpoint_test.c * * This test forks and the parent then traces the child doing various * types of ptrace enabled breakpoints * * Copyright (C) 2018 Michael Neuling, IBM Corporation. */ #include <sys/ptrace.h> #include <unistd.h> #include <stddef.h> #include <sys/user.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/syscall.h> #include <linux/limits.h> #include "ptrace.h" #include "reg.h" #define SPRN_PVR 0x11F #define PVR_8xx 0x00500000 bool is_8xx; /* * Use volatile on all global var so that compiler doesn't * optimise their load/stores. Otherwise selftest can fail. */ static volatile __u64 glvar; #define DAWR_MAX_LEN 512 static volatile __u8 big_var[DAWR_MAX_LEN] __attribute__((aligned(512))); #define A_LEN 6 #define B_LEN 6 struct gstruct { __u8 a[A_LEN]; /* double word aligned */ __u8 b[B_LEN]; /* double word unaligned */ }; static volatile struct gstruct gstruct __attribute__((aligned(512))); static volatile char cwd[PATH_MAX] __attribute__((aligned(8))); static void get_dbginfo(pid_t child_pid, struct ppc_debug_info *dbginfo) { if (ptrace(PPC_PTRACE_GETHWDBGINFO, child_pid, NULL, dbginfo)) { perror("Can't get breakpoint info"); exit(-1); } } static bool dawr_present(struct ppc_debug_info *dbginfo) { return !!(dbginfo->features & PPC_DEBUG_FEATURE_DATA_BP_DAWR); } static void write_var(int len) { volatile __u8 *pcvar; volatile __u16 *psvar; volatile __u32 *pivar; volatile __u64 *plvar; switch (len) { case 1: pcvar = (volatile __u8 *)&glvar; *pcvar = 0xff; break; case 2: psvar = (volatile __u16 *)&glvar; *psvar = 0xffff; break; case 4: pivar = (volatile __u32 *)&glvar; *pivar = 0xffffffff; break; case 8: plvar = (volatile __u64 *)&glvar; *plvar = 0xffffffffffffffffLL; break; } } static void read_var(int len) { __u8 cvar __attribute__((unused)); __u16 svar __attribute__((unused)); __u32 ivar __attribute__((unused)); __u64 lvar __attribute__((unused)); switch (len) { case 1: cvar = (volatile __u8)glvar; break; case 2: svar = (volatile __u16)glvar; break; case 4: ivar = (volatile __u32)glvar; break; case 8: lvar = (volatile __u64)glvar; break; } } static void test_workload(void) { __u8 cvar __attribute__((unused)); __u32 ivar __attribute__((unused)); int len = 0; if (ptrace(PTRACE_TRACEME, 0, NULL, 0)) { perror("Child can't be traced?"); exit(-1); } /* Wake up father so that it sets up the first test */ kill(getpid(), SIGUSR1); /* PTRACE_SET_DEBUGREG, WO test */ for (len = 1; len <= sizeof(glvar); len <<= 1) write_var(len); /* PTRACE_SET_DEBUGREG, RO test */ for (len = 1; len <= sizeof(glvar); len <<= 1) read_var(len); /* PTRACE_SET_DEBUGREG, RW test */ for (len = 1; len <= sizeof(glvar); len <<= 1) { if (rand() % 2) read_var(len); else write_var(len); } /* PTRACE_SET_DEBUGREG, Kernel Access Userspace test */ syscall(__NR_getcwd, &cwd, PATH_MAX); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, WO test */ write_var(1); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RO test */ read_var(1); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RW test */ if (rand() % 2) write_var(1); else read_var(1); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, Kernel Access Userspace test */ syscall(__NR_getcwd, &cwd, PATH_MAX); /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, WO test */ gstruct.a[rand() % A_LEN] = 'a'; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, RO test */ cvar = gstruct.a[rand() % A_LEN]; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, RW test */ if (rand() % 2) gstruct.a[rand() % A_LEN] = 'a'; else cvar = gstruct.a[rand() % A_LEN]; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, WO test */ gstruct.b[rand() % B_LEN] = 'b'; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, RO test */ cvar = gstruct.b[rand() % B_LEN]; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, RW test */ if (rand() % 2) gstruct.b[rand() % B_LEN] = 'b'; else cvar = gstruct.b[rand() % B_LEN]; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, DAR OUTSIDE, RW test */ if (rand() % 2) *((int *)(gstruct.a + 4)) = 10; else ivar = *((int *)(gstruct.a + 4)); /* PPC_PTRACE_SETHWDEBUG. DAWR_MAX_LEN. RW test */ if (rand() % 2) big_var[rand() % DAWR_MAX_LEN] = 'a'; else cvar = big_var[rand() % DAWR_MAX_LEN]; /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */ gstruct.a[rand() % A_LEN] = 'a'; /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */ cvar = gstruct.b[rand() % B_LEN]; /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */ gstruct.a[rand() % A_LEN] = 'a'; /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */ cvar = gstruct.a[rand() % A_LEN]; } static void check_success(pid_t child_pid, const char *name, const char *type, unsigned long saddr, int len) { int status; siginfo_t siginfo; unsigned long eaddr = (saddr + len - 1) | 0x7; saddr &= ~0x7; /* Wait for the child to SIGTRAP */ wait(&status); ptrace(PTRACE_GETSIGINFO, child_pid, NULL, &siginfo); if (!WIFSTOPPED(status) || WSTOPSIG(status) != SIGTRAP || (unsigned long)siginfo.si_addr < saddr || (unsigned long)siginfo.si_addr > eaddr) { printf("%s, %s, len: %d: Fail\n", name, type, len); exit(-1); } printf("%s, %s, len: %d: Ok\n", name, type, len); if (!is_8xx) { /* * For ptrace registered watchpoint, signal is generated * before executing load/store. Singlestep the instruction * and then continue the test. */ ptrace(PTRACE_SINGLESTEP, child_pid, NULL, 0); wait(NULL); } } static void ptrace_set_debugreg(pid_t child_pid, unsigned long wp_addr) { if (ptrace(PTRACE_SET_DEBUGREG, child_pid, 0, wp_addr)) { perror("PTRACE_SET_DEBUGREG failed"); exit(-1); } } static int ptrace_sethwdebug(pid_t child_pid, struct ppc_hw_breakpoint *info) { int wh = ptrace(PPC_PTRACE_SETHWDEBUG, child_pid, 0, info); if (wh <= 0) { perror("PPC_PTRACE_SETHWDEBUG failed"); exit(-1); } return wh; } static void ptrace_delhwdebug(pid_t child_pid, int wh) { if (ptrace(PPC_PTRACE_DELHWDEBUG, child_pid, 0, wh) < 0) { perror("PPC_PTRACE_DELHWDEBUG failed"); exit(-1); } } #define DABR_READ_SHIFT 0 #define DABR_WRITE_SHIFT 1 #define DABR_TRANSLATION_SHIFT 2 static int test_set_debugreg(pid_t child_pid) { unsigned long wp_addr = (unsigned long)&glvar; char *name = "PTRACE_SET_DEBUGREG"; int len; /* PTRACE_SET_DEBUGREG, WO test*/ wp_addr &= ~0x7UL; wp_addr |= (1UL << DABR_WRITE_SHIFT); wp_addr |= (1UL << DABR_TRANSLATION_SHIFT); for (len = 1; len <= sizeof(glvar); len <<= 1) { ptrace_set_debugreg(child_pid, wp_addr); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "WO", wp_addr, len); } /* PTRACE_SET_DEBUGREG, RO test */ wp_addr &= ~0x7UL; wp_addr |= (1UL << DABR_READ_SHIFT); wp_addr |= (1UL << DABR_TRANSLATION_SHIFT); for (len = 1; len <= sizeof(glvar); len <<= 1) { ptrace_set_debugreg(child_pid, wp_addr); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RO", wp_addr, len); } /* PTRACE_SET_DEBUGREG, RW test */ wp_addr &= ~0x7UL; wp_addr |= (1Ul << DABR_READ_SHIFT); wp_addr |= (1UL << DABR_WRITE_SHIFT); wp_addr |= (1UL << DABR_TRANSLATION_SHIFT); for (len = 1; len <= sizeof(glvar); len <<= 1) { ptrace_set_debugreg(child_pid, wp_addr); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); } ptrace_set_debugreg(child_pid, 0); return 0; } static int test_set_debugreg_kernel_userspace(pid_t child_pid) { unsigned long wp_addr = (unsigned long)cwd; char *name = "PTRACE_SET_DEBUGREG"; /* PTRACE_SET_DEBUGREG, Kernel Access Userspace test */ wp_addr &= ~0x7UL; wp_addr |= (1Ul << DABR_READ_SHIFT); wp_addr |= (1UL << DABR_WRITE_SHIFT); wp_addr |= (1UL << DABR_TRANSLATION_SHIFT); ptrace_set_debugreg(child_pid, wp_addr); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "Kernel Access Userspace", wp_addr, 8); ptrace_set_debugreg(child_pid, 0); return 0; } static void get_ppc_hw_breakpoint(struct ppc_hw_breakpoint *info, int type, unsigned long addr, int len) { info->version = 1; info->trigger_type = type; info->condition_mode = PPC_BREAKPOINT_CONDITION_NONE; info->addr = (__u64)addr; info->addr2 = (__u64)addr + len; info->condition_value = 0; if (!len) info->addr_mode = PPC_BREAKPOINT_MODE_EXACT; else info->addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE; } static void test_sethwdebug_exact(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr = (unsigned long)&glvar; char *name = "PPC_PTRACE_SETHWDEBUG, MODE_EXACT"; int len = 1; /* hardcoded in kernel */ int wh; /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, WO test */ get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, 0); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "WO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RO test */ get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_READ, wp_addr, 0); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, RW test */ get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_RW, wp_addr, 0); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } static void test_sethwdebug_exact_kernel_userspace(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr = (unsigned long)&cwd; char *name = "PPC_PTRACE_SETHWDEBUG, MODE_EXACT"; int len = 1; /* hardcoded in kernel */ int wh; /* PPC_PTRACE_SETHWDEBUG, MODE_EXACT, Kernel Access Userspace test */ get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, 0); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "Kernel Access Userspace", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } static void test_sethwdebug_range_aligned(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr; char *name = "PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED"; int len; int wh; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, WO test */ wp_addr = (unsigned long)&gstruct.a; len = A_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "WO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, RO test */ wp_addr = (unsigned long)&gstruct.a; len = A_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_READ, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW ALIGNED, RW test */ wp_addr = (unsigned long)&gstruct.a; len = A_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_RW, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } static void test_multi_sethwdebug_range(pid_t child_pid) { struct ppc_hw_breakpoint info1, info2; unsigned long wp_addr1, wp_addr2; char *name1 = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED"; char *name2 = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED"; int len1, len2; int wh1, wh2; wp_addr1 = (unsigned long)&gstruct.a; wp_addr2 = (unsigned long)&gstruct.b; len1 = A_LEN; len2 = B_LEN; get_ppc_hw_breakpoint(&info1, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr1, len1); get_ppc_hw_breakpoint(&info2, PPC_BREAKPOINT_TRIGGER_READ, wp_addr2, len2); /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */ wh1 = ptrace_sethwdebug(child_pid, &info1); /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */ wh2 = ptrace_sethwdebug(child_pid, &info2); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name1, "WO", wp_addr1, len1); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name2, "RO", wp_addr2, len2); ptrace_delhwdebug(child_pid, wh1); ptrace_delhwdebug(child_pid, wh2); } static void test_multi_sethwdebug_range_dawr_overlap(pid_t child_pid) { struct ppc_hw_breakpoint info1, info2; unsigned long wp_addr1, wp_addr2; char *name = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap"; int len1, len2; int wh1, wh2; wp_addr1 = (unsigned long)&gstruct.a; wp_addr2 = (unsigned long)&gstruct.a; len1 = A_LEN; len2 = A_LEN; get_ppc_hw_breakpoint(&info1, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr1, len1); get_ppc_hw_breakpoint(&info2, PPC_BREAKPOINT_TRIGGER_READ, wp_addr2, len2); /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */ wh1 = ptrace_sethwdebug(child_pid, &info1); /* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */ wh2 = ptrace_sethwdebug(child_pid, &info2); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "WO", wp_addr1, len1); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RO", wp_addr2, len2); ptrace_delhwdebug(child_pid, wh1); ptrace_delhwdebug(child_pid, wh2); } static void test_sethwdebug_range_unaligned(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr; char *name = "PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED"; int len; int wh; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, WO test */ wp_addr = (unsigned long)&gstruct.b; len = B_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "WO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, RO test */ wp_addr = (unsigned long)&gstruct.b; len = B_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_READ, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RO", wp_addr, len); ptrace_delhwdebug(child_pid, wh); /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, RW test */ wp_addr = (unsigned long)&gstruct.b; len = B_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_RW, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } static void test_sethwdebug_range_unaligned_dar(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr; char *name = "PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, DAR OUTSIDE"; int len; int wh; /* PPC_PTRACE_SETHWDEBUG, MODE_RANGE, DW UNALIGNED, DAR OUTSIDE, RW test */ wp_addr = (unsigned long)&gstruct.b; len = B_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } static void test_sethwdebug_dawr_max_range(pid_t child_pid) { struct ppc_hw_breakpoint info; unsigned long wp_addr; char *name = "PPC_PTRACE_SETHWDEBUG, DAWR_MAX_LEN"; int len; int wh; /* PPC_PTRACE_SETHWDEBUG, DAWR_MAX_LEN, RW test */ wp_addr = (unsigned long)big_var; len = DAWR_MAX_LEN; get_ppc_hw_breakpoint(&info, PPC_BREAKPOINT_TRIGGER_RW, wp_addr, len); wh = ptrace_sethwdebug(child_pid, &info); ptrace(PTRACE_CONT, child_pid, NULL, 0); check_success(child_pid, name, "RW", wp_addr, len); ptrace_delhwdebug(child_pid, wh); } /* Set the breakpoints and check the child successfully trigger them */ static void run_tests(pid_t child_pid, struct ppc_debug_info *dbginfo, bool dawr) { test_set_debugreg(child_pid); test_set_debugreg_kernel_userspace(child_pid); test_sethwdebug_exact(child_pid); test_sethwdebug_exact_kernel_userspace(child_pid); if (dbginfo->features & PPC_DEBUG_FEATURE_DATA_BP_RANGE) { test_sethwdebug_range_aligned(child_pid); if (dawr || is_8xx) { test_sethwdebug_range_unaligned(child_pid); test_sethwdebug_range_unaligned_dar(child_pid); test_sethwdebug_dawr_max_range(child_pid); if (dbginfo->num_data_bps > 1) { test_multi_sethwdebug_range(child_pid); test_multi_sethwdebug_range_dawr_overlap(child_pid); } } } } static int ptrace_hwbreak(void) { pid_t child_pid; struct ppc_debug_info dbginfo; bool dawr; child_pid = fork(); if (!child_pid) { test_workload(); return 0; } wait(NULL); get_dbginfo(child_pid, &dbginfo); SKIP_IF_MSG(dbginfo.num_data_bps == 0, "No data breakpoints present"); dawr = dawr_present(&dbginfo); run_tests(child_pid, &dbginfo, dawr); /* Let the child exit first. */ ptrace(PTRACE_CONT, child_pid, NULL, 0); wait(NULL); /* * Testcases exits immediately with -1 on any failure. If * it has reached here, it means all tests were successful. */ return TEST_PASS; } int main(int argc, char **argv, char **envp) { is_8xx = mfspr(SPRN_PVR) == PVR_8xx; return test_harness(ptrace_hwbreak, "ptrace-hwbreak"); } |