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

drm: Fix oops in damage self-tests by mocking damage property

I've added a new check to make sure that drivers which insepct the
damage property have it set up correctly, but somehow missed that this
borke the damage selftest in the CI result noise.

Fix it up by mocking enough of drm_device and drm_plane so we can call
drm_plane_enable_fb_damage_clips() to make the new check happy.

Since there's a lot of duplicated mock code already copy-pasted into
each test I've also refactored this a bit to trim it down.

v2: Squash in fixup from 0day for

drivers/gpu/drm/selftests/test-drm_damage_helper.c:15:19: warning: symbol 'mock_device' was not declared. Should it be static?
drivers/gpu/drm/selftests/test-drm_damage_helper.c:16:30: warning: symbol 'mock_obj_props' was not declared. Should it be static?
drivers/gpu/drm/selftests/test-drm_damage_helper.c:17:18: warning: symbol 'mock_plane' was not declared. Should it be static?
drivers/gpu/drm/selftests/test-drm_damage_helper.c:18:21: warning: symbol 'mock_prop' was not declared. Should it be static?

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>

Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Fixes: c7fcbf251397 ("drm/plane: check that fb_damage is set up when used")
Cc: José Roberto de Souza <jose.souza@intel.com> (v1)
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: José Roberto de Souza <jose.souza@intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210730095251.4343-1-daniel.vetter@ffwll.ch
Link: https://patchwork.freedesktop.org/patch/msgid/20210730141948.GA11955@243d74413310

+71 -216
+71 -216
drivers/gpu/drm/selftests/test-drm_damage_helper.c
··· 6 6 #define pr_fmt(fmt) "drm_damage_helper: " fmt 7 7 8 8 #include <drm/drm_damage_helper.h> 9 + #include <drm/drm_plane.h> 10 + #include <drm/drm_drv.h> 9 11 10 12 #include "test-drm_modeset_common.h" 13 + 14 + struct drm_driver mock_driver; 15 + static struct drm_device mock_device; 16 + static struct drm_object_properties mock_obj_props; 17 + static struct drm_plane mock_plane; 18 + static struct drm_property mock_prop; 19 + 20 + static void mock_setup(struct drm_plane_state *state) 21 + { 22 + static bool setup_done = false; 23 + 24 + state->plane = &mock_plane; 25 + 26 + if (setup_done) 27 + return; 28 + 29 + /* just enough so that drm_plane_enable_fb_damage_clips() works */ 30 + mock_device.driver = &mock_driver; 31 + mock_device.mode_config.prop_fb_damage_clips = &mock_prop; 32 + mock_plane.dev = &mock_device; 33 + mock_plane.base.properties = &mock_obj_props; 34 + mock_prop.base.id = 1; /* 0 is an invalid id */ 35 + mock_prop.dev = &mock_device; 36 + 37 + drm_plane_enable_fb_damage_clips(&mock_plane); 38 + } 11 39 12 40 static void set_plane_src(struct drm_plane_state *state, int x1, int y1, int x2, 13 41 int y2) ··· 98 70 return true; 99 71 } 100 72 73 + const struct drm_framebuffer fb = { 74 + .width = 2048, 75 + .height = 2048 76 + }; 77 + 78 + /* common mocked structs many tests need */ 79 + #define MOCK_VARIABLES() \ 80 + struct drm_plane_state old_state; \ 81 + struct drm_plane_state state = { \ 82 + .crtc = ZERO_SIZE_PTR, \ 83 + .fb = (struct drm_framebuffer *) &fb, \ 84 + .visible = true, \ 85 + }; \ 86 + mock_setup(&old_state); \ 87 + mock_setup(&state); 88 + 101 89 int igt_damage_iter_no_damage(void *ignored) 102 90 { 103 91 struct drm_atomic_helper_damage_iter iter; 104 - struct drm_plane_state old_state; 105 92 struct drm_rect clip; 106 93 uint32_t num_hits = 0; 107 94 108 - struct drm_framebuffer fb = { 109 - .width = 2048, 110 - .height = 2048 111 - }; 112 - 113 - struct drm_plane_state state = { 114 - .crtc = ZERO_SIZE_PTR, 115 - .fb = &fb, 116 - .visible = true, 117 - }; 95 + MOCK_VARIABLES(); 118 96 119 97 /* Plane src same as fb size. */ 120 98 set_plane_src(&old_state, 0, 0, fb.width << 16, fb.height << 16); ··· 138 104 int igt_damage_iter_no_damage_fractional_src(void *ignored) 139 105 { 140 106 struct drm_atomic_helper_damage_iter iter; 141 - struct drm_plane_state old_state; 142 107 struct drm_rect clip; 143 108 uint32_t num_hits = 0; 144 109 145 - struct drm_framebuffer fb = { 146 - .width = 2048, 147 - .height = 2048 148 - }; 149 - 150 - struct drm_plane_state state = { 151 - .crtc = ZERO_SIZE_PTR, 152 - .fb = &fb, 153 - .visible = true, 154 - }; 110 + MOCK_VARIABLES(); 155 111 156 112 /* Plane src has fractional part. */ 157 113 set_plane_src(&old_state, 0x3fffe, 0x3fffe, ··· 161 137 int igt_damage_iter_no_damage_src_moved(void *ignored) 162 138 { 163 139 struct drm_atomic_helper_damage_iter iter; 164 - struct drm_plane_state old_state; 165 140 struct drm_rect clip; 166 141 uint32_t num_hits = 0; 167 142 168 - struct drm_framebuffer fb = { 169 - .width = 2048, 170 - .height = 2048 171 - }; 172 - 173 - struct drm_plane_state state = { 174 - .crtc = ZERO_SIZE_PTR, 175 - .fb = &fb, 176 - .visible = true, 177 - }; 143 + MOCK_VARIABLES(); 178 144 179 145 /* Plane src moved since old plane state. */ 180 146 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); ··· 183 169 int igt_damage_iter_no_damage_fractional_src_moved(void *ignored) 184 170 { 185 171 struct drm_atomic_helper_damage_iter iter; 186 - struct drm_plane_state old_state; 187 172 struct drm_rect clip; 188 173 uint32_t num_hits = 0; 189 174 190 - struct drm_framebuffer fb = { 191 - .width = 2048, 192 - .height = 2048 193 - }; 194 - 195 - struct drm_plane_state state = { 196 - .crtc = ZERO_SIZE_PTR, 197 - .fb = &fb, 198 - .visible = true, 199 - }; 175 + MOCK_VARIABLES(); 200 176 201 177 /* Plane src has fractional part and it moved since old plane state. */ 202 178 set_plane_src(&old_state, 0x3fffe, 0x3fffe, ··· 206 202 int igt_damage_iter_no_damage_not_visible(void *ignored) 207 203 { 208 204 struct drm_atomic_helper_damage_iter iter; 209 - struct drm_plane_state old_state; 210 205 struct drm_rect clip; 211 206 uint32_t num_hits = 0; 212 207 213 - struct drm_framebuffer fb = { 214 - .width = 2048, 215 - .height = 2048 216 - }; 208 + MOCK_VARIABLES(); 217 209 218 - struct drm_plane_state state = { 219 - .crtc = ZERO_SIZE_PTR, 220 - .fb = &fb, 221 - .visible = false, 222 - }; 210 + state.visible = false; 211 + 212 + mock_setup(&old_state); 223 213 224 214 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 225 215 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 229 231 int igt_damage_iter_no_damage_no_crtc(void *ignored) 230 232 { 231 233 struct drm_atomic_helper_damage_iter iter; 232 - struct drm_plane_state old_state; 233 234 struct drm_rect clip; 234 235 uint32_t num_hits = 0; 235 236 236 - struct drm_framebuffer fb = { 237 - .width = 2048, 238 - .height = 2048 239 - }; 237 + MOCK_VARIABLES(); 240 238 241 - struct drm_plane_state state = { 242 - .crtc = 0, 243 - .fb = &fb, 244 - }; 239 + state.crtc = NULL; 245 240 246 241 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 247 242 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 259 268 .fb = 0, 260 269 }; 261 270 271 + mock_setup(&old_state); 272 + 262 273 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 263 274 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); 264 275 drm_atomic_helper_damage_iter_init(&iter, &old_state, &state); ··· 275 282 int igt_damage_iter_simple_damage(void *ignored) 276 283 { 277 284 struct drm_atomic_helper_damage_iter iter; 278 - struct drm_plane_state old_state; 279 285 struct drm_property_blob damage_blob; 280 286 struct drm_mode_rect damage; 281 287 struct drm_rect clip; 282 288 uint32_t num_hits = 0; 283 289 284 - struct drm_framebuffer fb = { 285 - .width = 2048, 286 - .height = 2048 287 - }; 288 - 289 - struct drm_plane_state state = { 290 - .crtc = ZERO_SIZE_PTR, 291 - .fb = &fb, 292 - .visible = true, 293 - }; 290 + MOCK_VARIABLES(); 294 291 295 292 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 296 293 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 301 318 int igt_damage_iter_single_damage(void *ignored) 302 319 { 303 320 struct drm_atomic_helper_damage_iter iter; 304 - struct drm_plane_state old_state; 305 321 struct drm_property_blob damage_blob; 306 322 struct drm_mode_rect damage; 307 323 struct drm_rect clip; 308 324 uint32_t num_hits = 0; 309 325 310 - struct drm_framebuffer fb = { 311 - .width = 2048, 312 - .height = 2048 313 - }; 314 - 315 - struct drm_plane_state state = { 316 - .crtc = ZERO_SIZE_PTR, 317 - .fb = &fb, 318 - .visible = true, 319 - }; 326 + MOCK_VARIABLES(); 320 327 321 328 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 322 329 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 326 353 int igt_damage_iter_single_damage_intersect_src(void *ignored) 327 354 { 328 355 struct drm_atomic_helper_damage_iter iter; 329 - struct drm_plane_state old_state; 330 356 struct drm_property_blob damage_blob; 331 357 struct drm_mode_rect damage; 332 358 struct drm_rect clip; 333 359 uint32_t num_hits = 0; 334 360 335 - struct drm_framebuffer fb = { 336 - .width = 2048, 337 - .height = 2048 338 - }; 339 - 340 - struct drm_plane_state state = { 341 - .crtc = ZERO_SIZE_PTR, 342 - .fb = &fb, 343 - .visible = true, 344 - }; 361 + MOCK_VARIABLES(); 345 362 346 363 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 347 364 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 352 389 int igt_damage_iter_single_damage_outside_src(void *ignored) 353 390 { 354 391 struct drm_atomic_helper_damage_iter iter; 355 - struct drm_plane_state old_state; 356 392 struct drm_property_blob damage_blob; 357 393 struct drm_mode_rect damage; 358 394 struct drm_rect clip; 359 395 uint32_t num_hits = 0; 360 396 361 - struct drm_framebuffer fb = { 362 - .width = 2048, 363 - .height = 2048 364 - }; 365 - 366 - struct drm_plane_state state = { 367 - .crtc = ZERO_SIZE_PTR, 368 - .fb = &fb, 369 - .visible = true, 370 - }; 397 + MOCK_VARIABLES(); 371 398 372 399 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 373 400 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 377 424 int igt_damage_iter_single_damage_fractional_src(void *ignored) 378 425 { 379 426 struct drm_atomic_helper_damage_iter iter; 380 - struct drm_plane_state old_state; 381 427 struct drm_property_blob damage_blob; 382 428 struct drm_mode_rect damage; 383 429 struct drm_rect clip; 384 430 uint32_t num_hits = 0; 385 431 386 - struct drm_framebuffer fb = { 387 - .width = 2048, 388 - .height = 2048 389 - }; 390 - 391 - struct drm_plane_state state = { 392 - .crtc = ZERO_SIZE_PTR, 393 - .fb = &fb, 394 - .visible = true, 395 - }; 432 + MOCK_VARIABLES(); 396 433 397 434 /* Plane src has fractional part. */ 398 435 set_plane_src(&old_state, 0x40002, 0x40002, ··· 405 462 int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored) 406 463 { 407 464 struct drm_atomic_helper_damage_iter iter; 408 - struct drm_plane_state old_state; 409 465 struct drm_property_blob damage_blob; 410 466 struct drm_mode_rect damage; 411 467 struct drm_rect clip; 412 468 uint32_t num_hits = 0; 413 469 414 - struct drm_framebuffer fb = { 415 - .width = 2048, 416 - .height = 2048 417 - }; 418 - 419 - struct drm_plane_state state = { 420 - .crtc = ZERO_SIZE_PTR, 421 - .fb = &fb, 422 - .visible = true, 423 - }; 470 + MOCK_VARIABLES(); 424 471 425 472 /* Plane src has fractional part. */ 426 473 set_plane_src(&old_state, 0x40002, 0x40002, ··· 434 501 int igt_damage_iter_single_damage_outside_fractional_src(void *ignored) 435 502 { 436 503 struct drm_atomic_helper_damage_iter iter; 437 - struct drm_plane_state old_state; 438 504 struct drm_property_blob damage_blob; 439 505 struct drm_mode_rect damage; 440 506 struct drm_rect clip; 441 507 uint32_t num_hits = 0; 442 508 443 - struct drm_framebuffer fb = { 444 - .width = 2048, 445 - .height = 2048 446 - }; 447 - 448 - struct drm_plane_state state = { 449 - .crtc = ZERO_SIZE_PTR, 450 - .fb = &fb, 451 - .visible = true, 452 - }; 509 + MOCK_VARIABLES(); 453 510 454 511 /* Plane src has fractional part. */ 455 512 set_plane_src(&old_state, 0x40002, 0x40002, ··· 462 539 int igt_damage_iter_single_damage_src_moved(void *ignored) 463 540 { 464 541 struct drm_atomic_helper_damage_iter iter; 465 - struct drm_plane_state old_state; 466 542 struct drm_property_blob damage_blob; 467 543 struct drm_mode_rect damage; 468 544 struct drm_rect clip; 469 545 uint32_t num_hits = 0; 470 546 471 - struct drm_framebuffer fb = { 472 - .width = 2048, 473 - .height = 2048 474 - }; 475 - 476 - struct drm_plane_state state = { 477 - .crtc = ZERO_SIZE_PTR, 478 - .fb = &fb, 479 - .visible = true, 480 - }; 547 + MOCK_VARIABLES(); 481 548 482 549 /* Plane src moved since old plane state. */ 483 550 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); ··· 489 576 int igt_damage_iter_single_damage_fractional_src_moved(void *ignored) 490 577 { 491 578 struct drm_atomic_helper_damage_iter iter; 492 - struct drm_plane_state old_state; 493 579 struct drm_property_blob damage_blob; 494 580 struct drm_mode_rect damage; 495 581 struct drm_rect clip; 496 582 uint32_t num_hits = 0; 497 583 498 - struct drm_framebuffer fb = { 499 - .width = 2048, 500 - .height = 2048 501 - }; 502 - 503 - struct drm_plane_state state = { 504 - .crtc = ZERO_SIZE_PTR, 505 - .fb = &fb, 506 - .visible = true, 507 - }; 584 + MOCK_VARIABLES(); 508 585 509 586 /* Plane src with fractional part moved since old plane state. */ 510 587 set_plane_src(&old_state, 0x3fffe, 0x3fffe, ··· 518 615 int igt_damage_iter_damage(void *ignored) 519 616 { 520 617 struct drm_atomic_helper_damage_iter iter; 521 - struct drm_plane_state old_state; 522 618 struct drm_property_blob damage_blob; 523 619 struct drm_mode_rect damage[2]; 524 620 struct drm_rect clip; 525 621 uint32_t num_hits = 0; 526 622 527 - struct drm_framebuffer fb = { 528 - .width = 2048, 529 - .height = 2048 530 - }; 531 - 532 - struct drm_plane_state state = { 533 - .crtc = ZERO_SIZE_PTR, 534 - .fb = &fb, 535 - .visible = true, 536 - }; 623 + MOCK_VARIABLES(); 537 624 538 625 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 539 626 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 549 656 int igt_damage_iter_damage_one_intersect(void *ignored) 550 657 { 551 658 struct drm_atomic_helper_damage_iter iter; 552 - struct drm_plane_state old_state; 553 659 struct drm_property_blob damage_blob; 554 660 struct drm_mode_rect damage[2]; 555 661 struct drm_rect clip; 556 662 uint32_t num_hits = 0; 557 663 558 - struct drm_framebuffer fb = { 559 - .width = 2048, 560 - .height = 2048 561 - }; 562 - 563 - struct drm_plane_state state = { 564 - .crtc = ZERO_SIZE_PTR, 565 - .fb = &fb, 566 - .visible = true, 567 - }; 664 + MOCK_VARIABLES(); 568 665 569 666 set_plane_src(&old_state, 0x40002, 0x40002, 570 667 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); ··· 582 699 int igt_damage_iter_damage_one_outside(void *ignored) 583 700 { 584 701 struct drm_atomic_helper_damage_iter iter; 585 - struct drm_plane_state old_state; 586 702 struct drm_property_blob damage_blob; 587 703 struct drm_mode_rect damage[2]; 588 704 struct drm_rect clip; 589 705 uint32_t num_hits = 0; 590 706 591 - struct drm_framebuffer fb = { 592 - .width = 2048, 593 - .height = 2048 594 - }; 595 - 596 - struct drm_plane_state state = { 597 - .crtc = ZERO_SIZE_PTR, 598 - .fb = &fb, 599 - .visible = true, 600 - }; 707 + MOCK_VARIABLES(); 601 708 602 709 set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16); 603 710 set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16); ··· 609 736 int igt_damage_iter_damage_src_moved(void *ignored) 610 737 { 611 738 struct drm_atomic_helper_damage_iter iter; 612 - struct drm_plane_state old_state; 613 739 struct drm_property_blob damage_blob; 614 740 struct drm_mode_rect damage[2]; 615 741 struct drm_rect clip; 616 742 uint32_t num_hits = 0; 617 743 618 - struct drm_framebuffer fb = { 619 - .width = 2048, 620 - .height = 2048 621 - }; 622 - 623 - struct drm_plane_state state = { 624 - .crtc = ZERO_SIZE_PTR, 625 - .fb = &fb, 626 - .visible = true, 627 - }; 744 + MOCK_VARIABLES(); 628 745 629 746 set_plane_src(&old_state, 0x40002, 0x40002, 630 747 0x40002 + (1024 << 16), 0x40002 + (768 << 16)); ··· 638 775 int igt_damage_iter_damage_not_visible(void *ignored) 639 776 { 640 777 struct drm_atomic_helper_damage_iter iter; 641 - struct drm_plane_state old_state; 642 778 struct drm_property_blob damage_blob; 643 779 struct drm_mode_rect damage[2]; 644 780 struct drm_rect clip; 645 781 uint32_t num_hits = 0; 646 782 647 - struct drm_framebuffer fb = { 648 - .width = 2048, 649 - .height = 2048 650 - }; 783 + MOCK_VARIABLES(); 651 784 652 - struct drm_plane_state state = { 653 - .crtc = ZERO_SIZE_PTR, 654 - .fb = &fb, 655 - .visible = false, 656 - }; 785 + state.visible = false; 657 786 658 787 set_plane_src(&old_state, 0x40002, 0x40002, 659 788 0x40002 + (1024 << 16), 0x40002 + (768 << 16));