Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Allow choice of CI memory location in alignment_handler test

The alignment handler selftest needs cache-inhibited memory and
currently /dev/fb0 is relied on to provided this. This prevents running
the test on systems without /dev/fb0 (e.g., mambo). Read the commandline
arguments for an optional path to be used instead, as well as an
optional offset to be for mmaping this path.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
Tested-by: Alistair Popple <alistair@popple.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200520021103.19798-1-jniethe5@gmail.com

authored by

Jordan Niethe and committed by
Michael Ellerman
01bd2946 5f202c1a

+42 -21
+42 -21
tools/testing/selftests/powerpc/alignment/alignment_handler.c
··· 9 9 * This selftest exercises the powerpc alignment fault handler. 10 10 * 11 11 * We create two sets of source and destination buffers, one in regular memory, 12 - * the other cache-inhibited (we use /dev/fb0 for this). 12 + * the other cache-inhibited (by default we use /dev/fb0 for this, but an 13 + * alterative path for cache-inhibited memory may be provided). 14 + * 15 + * One way to get cache-inhibited memory is to use the "mem" kernel parameter 16 + * to limit the kernel to less memory than actually exists. Addresses above 17 + * the limit may still be accessed but will be treated as cache-inhibited. For 18 + * example, if there is actually 4GB of memory and the parameter "mem=3GB" is 19 + * used, memory from address 0xC0000000 onwards is treated as cache-inhibited. 20 + * To access this region /dev/mem is used. The kernel should be configured 21 + * without CONFIG_STRICT_DEVMEM. In this case use: 22 + * ./alignment_handler /dev/mem 0xc0000000 13 23 * 14 24 * We initialise the source buffers, then use whichever set of load/store 15 25 * instructions is under test to copy bytes from the source buffers to the ··· 63 53 int debug; 64 54 int testing; 65 55 volatile int gotsig; 56 + char *cipath = "/dev/fb0"; 57 + long cioffset; 66 58 67 59 void sighandler(int sig, siginfo_t *info, void *ctx) 68 60 { ··· 207 195 208 196 printf("\tDoing %s:\t", test_name); 209 197 210 - fd = open("/dev/fb0", O_RDWR); 198 + fd = open(cipath, O_RDWR); 211 199 if (fd < 0) { 212 200 printf("\n"); 213 - perror("Can't open /dev/fb0 now?"); 201 + perror("Can't open ci file now?"); 214 202 return 1; 215 203 } 216 204 217 - ci0 = mmap(NULL, bufsize, PROT_WRITE, MAP_SHARED, 218 - fd, 0x0); 219 - ci1 = mmap(NULL, bufsize, PROT_WRITE, MAP_SHARED, 220 - fd, bufsize); 205 + ci0 = mmap(NULL, bufsize, PROT_WRITE | PROT_READ, MAP_SHARED, 206 + fd, cioffset); 207 + ci1 = mmap(NULL, bufsize, PROT_WRITE | PROT_READ, MAP_SHARED, 208 + fd, cioffset + bufsize); 209 + 221 210 if ((ci0 == MAP_FAILED) || (ci1 == MAP_FAILED)) { 222 211 printf("\n"); 223 212 perror("mmap failed"); ··· 283 270 return rc; 284 271 } 285 272 286 - static bool can_open_fb0(void) 273 + static bool can_open_cifile(void) 287 274 { 288 275 int fd; 289 276 290 - fd = open("/dev/fb0", O_RDWR); 277 + fd = open(cipath, O_RDWR); 291 278 if (fd < 0) 292 279 return false; 293 280 ··· 299 286 { 300 287 int rc = 0; 301 288 302 - SKIP_IF(!can_open_fb0()); 289 + SKIP_IF(!can_open_cifile()); 303 290 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 304 291 305 292 printf("VSX: 2.06B\n"); ··· 317 304 { 318 305 int rc = 0; 319 306 320 - SKIP_IF(!can_open_fb0()); 307 + SKIP_IF(!can_open_cifile()); 321 308 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07)); 322 309 323 310 printf("VSX: 2.07B\n"); ··· 333 320 { 334 321 int rc = 0; 335 322 336 - SKIP_IF(!can_open_fb0()); 323 + SKIP_IF(!can_open_cifile()); 337 324 338 325 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00)); 339 326 printf("VSX: 3.00B\n"); ··· 365 352 { 366 353 int rc = 0; 367 354 368 - SKIP_IF(!can_open_fb0()); 355 + SKIP_IF(!can_open_cifile()); 369 356 370 357 printf("Integer\n"); 371 358 LOAD_DFORM_TEST(lbz); ··· 421 408 { 422 409 int rc = 0; 423 410 424 - SKIP_IF(!can_open_fb0()); 411 + SKIP_IF(!can_open_cifile()); 425 412 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 426 413 427 414 printf("Integer: 2.06\n"); ··· 436 423 { 437 424 int rc = 0; 438 425 439 - SKIP_IF(!can_open_fb0()); 426 + SKIP_IF(!can_open_cifile()); 440 427 SKIP_IF(!have_hwcap(PPC_FEATURE_HAS_ALTIVEC)); 441 428 442 429 printf("VMX\n"); ··· 464 451 { 465 452 int rc = 0; 466 453 467 - SKIP_IF(!can_open_fb0()); 454 + SKIP_IF(!can_open_cifile()); 468 455 469 456 printf("Floating point\n"); 470 457 LOAD_FLOAT_DFORM_TEST(lfd); ··· 492 479 { 493 480 int rc = 0; 494 481 495 - SKIP_IF(!can_open_fb0()); 482 + SKIP_IF(!can_open_cifile()); 496 483 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_05)); 497 484 498 485 printf("Floating point: 2.05\n"); ··· 510 497 { 511 498 int rc = 0; 512 499 513 - SKIP_IF(!can_open_fb0()); 500 + SKIP_IF(!can_open_cifile()); 514 501 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 515 502 516 503 printf("Floating point: 2.06\n"); ··· 522 509 523 510 void usage(char *prog) 524 511 { 525 - printf("Usage: %s [options]\n", prog); 512 + printf("Usage: %s [options] [path [offset]]\n", prog); 526 513 printf(" -d Enable debug error output\n"); 527 514 printf("\n"); 528 - printf("This test requires a POWER8 or POWER9 CPU and a usable "); 529 - printf("framebuffer at /dev/fb0.\n"); 515 + printf("This test requires a POWER8 or POWER9 CPU and either a "); 516 + printf("usable framebuffer at /dev/fb0 or the path to usable "); 517 + printf("cache-inhibited memory and optional offset to be provided\n"); 530 518 } 531 519 532 520 int main(int argc, char *argv[]) ··· 547 533 exit(1); 548 534 } 549 535 } 536 + argc -= optind; 537 + argv += optind; 538 + 539 + if (argc > 0) 540 + cipath = argv[0]; 541 + if (argc > 1) 542 + cioffset = strtol(argv[1], 0, 0x10); 550 543 551 544 bufsize = getpagesize(); 552 545