Skip to content

Commit 379cad6

Browse files
author
Thomas Hellström
committed
drm/xe: Use separate rpm lockdep map for non-d3cold-capable devices
For non-d3cold-capable devices we'd like to be able to wake up the device from reclaim. In particular, for Lunar Lake we'd like to be able to blit CCS metadata to system at shrink time; at least from kswapd where it's reasonable OK to wait for rpm resume and a preceding rpm suspend. Therefore use a separate lockdep map for such devices and prime it reclaim-tainted. v2: - Rename lockmap acquire- and release functions. (Rodrigo Vivi). - Reinstate the old xe_pm_runtime_lockdep_prime() function and rename it to xe_rpm_might_enter_cb(). (Matthew Auld). - Introduce a separate xe_pm_runtime_lockdep_prime function called from module init for known required locking orders. v3: - Actually hook up the prime function at module init. v4: - Rebase. v5: - Don't use reclaim-safe RPM with sriov. Cc: "Vivi, Rodrigo" <[email protected]> Cc: "Auld, Matthew" <[email protected]> Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 789e515 commit 379cad6

File tree

3 files changed

+80
-14
lines changed

3 files changed

+80
-14
lines changed

drivers/gpu/drm/xe/xe_module.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "xe_drv.h"
1414
#include "xe_hw_fence.h"
1515
#include "xe_pci.h"
16+
#include "xe_pm.h"
1617
#include "xe_observation.h"
1718
#include "xe_sched_job.h"
1819

@@ -76,6 +77,10 @@ struct init_funcs {
7677
void (*exit)(void);
7778
};
7879

80+
static void xe_dummy_exit(void)
81+
{
82+
}
83+
7984
static const struct init_funcs init_funcs[] = {
8085
{
8186
.init = xe_check_nomodeset,
@@ -96,6 +101,10 @@ static const struct init_funcs init_funcs[] = {
96101
.init = xe_observation_sysctl_register,
97102
.exit = xe_observation_sysctl_unregister,
98103
},
104+
{
105+
.init = xe_pm_module_init,
106+
.exit = xe_dummy_exit,
107+
},
99108
};
100109

101110
static int __init xe_call_init_func(unsigned int i)

drivers/gpu/drm/xe/xe_pm.c

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,34 @@
7070
*/
7171

7272
#ifdef CONFIG_LOCKDEP
73-
static struct lockdep_map xe_pm_runtime_lockdep_map = {
74-
.name = "xe_pm_runtime_lockdep_map"
73+
static struct lockdep_map xe_pm_runtime_d3cold_map = {
74+
.name = "xe_rpm_d3cold_map"
75+
};
76+
77+
static struct lockdep_map xe_pm_runtime_nod3cold_map = {
78+
.name = "xe_rpm_nod3cold_map"
7579
};
7680
#endif
7781

82+
static bool __maybe_unused xe_rpm_reclaim_safe(const struct xe_device *xe)
83+
{
84+
return !xe->d3cold.capable && !xe->info.has_sriov;
85+
}
86+
87+
static void xe_rpm_lockmap_acquire(const struct xe_device *xe)
88+
{
89+
lock_map_acquire(xe_rpm_reclaim_safe(xe) ?
90+
&xe_pm_runtime_nod3cold_map :
91+
&xe_pm_runtime_d3cold_map);
92+
}
93+
94+
static void xe_rpm_lockmap_release(const struct xe_device *xe)
95+
{
96+
lock_map_release(xe_rpm_reclaim_safe(xe) ?
97+
&xe_pm_runtime_nod3cold_map :
98+
&xe_pm_runtime_d3cold_map);
99+
}
100+
78101
/**
79102
* xe_pm_suspend - Helper for System suspend, i.e. S0->S3 / S0->S2idle
80103
* @xe: xe device instance
@@ -354,7 +377,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
354377
* annotation here and in xe_pm_runtime_get() lockdep will see
355378
* the potential lock inversion and give us a nice splat.
356379
*/
357-
lock_map_acquire(&xe_pm_runtime_lockdep_map);
380+
xe_rpm_lockmap_acquire(xe);
358381

359382
/*
360383
* Applying lock for entire list op as xe_ttm_bo_destroy and xe_bo_move_notify
@@ -387,7 +410,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe)
387410
out:
388411
if (err)
389412
xe_display_pm_resume(xe, true);
390-
lock_map_release(&xe_pm_runtime_lockdep_map);
413+
xe_rpm_lockmap_release(xe);
391414
xe_pm_write_callback_task(xe, NULL);
392415
return err;
393416
}
@@ -408,7 +431,7 @@ int xe_pm_runtime_resume(struct xe_device *xe)
408431
/* Disable access_ongoing asserts and prevent recursive pm calls */
409432
xe_pm_write_callback_task(xe, current);
410433

411-
lock_map_acquire(&xe_pm_runtime_lockdep_map);
434+
xe_rpm_lockmap_acquire(xe);
412435

413436
if (xe->d3cold.allowed) {
414437
err = xe_pcode_ready(xe, true);
@@ -440,7 +463,7 @@ int xe_pm_runtime_resume(struct xe_device *xe)
440463
}
441464

442465
out:
443-
lock_map_release(&xe_pm_runtime_lockdep_map);
466+
xe_rpm_lockmap_release(xe);
444467
xe_pm_write_callback_task(xe, NULL);
445468
return err;
446469
}
@@ -454,15 +477,37 @@ int xe_pm_runtime_resume(struct xe_device *xe)
454477
* stuff that can happen inside the runtime_resume callback by acquiring
455478
* a dummy lock (it doesn't protect anything and gets compiled out on
456479
* non-debug builds). Lockdep then only needs to see the
457-
* xe_pm_runtime_lockdep_map -> runtime_resume callback once, and then can
458-
* hopefully validate all the (callers_locks) -> xe_pm_runtime_lockdep_map.
480+
* xe_pm_runtime_xxx_map -> runtime_resume callback once, and then can
481+
* hopefully validate all the (callers_locks) -> xe_pm_runtime_xxx_map.
459482
* For example if the (callers_locks) are ever grabbed in the
460483
* runtime_resume callback, lockdep should give us a nice splat.
461484
*/
462-
static void pm_runtime_lockdep_prime(void)
485+
static void xe_rpm_might_enter_cb(const struct xe_device *xe)
463486
{
464-
lock_map_acquire(&xe_pm_runtime_lockdep_map);
465-
lock_map_release(&xe_pm_runtime_lockdep_map);
487+
xe_rpm_lockmap_acquire(xe);
488+
xe_rpm_lockmap_release(xe);
489+
}
490+
491+
/*
492+
* Prime the lockdep maps for known locking orders that need to
493+
* be supported but that may not always occur on all systems.
494+
*/
495+
static void xe_pm_runtime_lockdep_prime(void)
496+
{
497+
struct dma_resv lockdep_resv;
498+
499+
dma_resv_init(&lockdep_resv);
500+
lock_map_acquire(&xe_pm_runtime_d3cold_map);
501+
/* D3Cold takes the dma_resv locks to evict bos */
502+
dma_resv_lock(&lockdep_resv, NULL);
503+
dma_resv_unlock(&lockdep_resv);
504+
lock_map_release(&xe_pm_runtime_d3cold_map);
505+
506+
/* Shrinkers might like to wake up the device under reclaim. */
507+
fs_reclaim_acquire(GFP_KERNEL);
508+
lock_map_acquire(&xe_pm_runtime_nod3cold_map);
509+
lock_map_release(&xe_pm_runtime_nod3cold_map);
510+
fs_reclaim_release(GFP_KERNEL);
466511
}
467512

468513
/**
@@ -477,7 +522,7 @@ void xe_pm_runtime_get(struct xe_device *xe)
477522
if (xe_pm_read_callback_task(xe) == current)
478523
return;
479524

480-
pm_runtime_lockdep_prime();
525+
xe_rpm_might_enter_cb(xe);
481526
pm_runtime_resume(xe->drm.dev);
482527
}
483528

@@ -509,7 +554,7 @@ int xe_pm_runtime_get_ioctl(struct xe_device *xe)
509554
if (WARN_ON(xe_pm_read_callback_task(xe) == current))
510555
return -ELOOP;
511556

512-
pm_runtime_lockdep_prime();
557+
xe_rpm_might_enter_cb(xe);
513558
return pm_runtime_get_sync(xe->drm.dev);
514559
}
515560

@@ -577,7 +622,7 @@ bool xe_pm_runtime_resume_and_get(struct xe_device *xe)
577622
return true;
578623
}
579624

580-
pm_runtime_lockdep_prime();
625+
xe_rpm_might_enter_cb(xe);
581626
return pm_runtime_resume_and_get(xe->drm.dev) >= 0;
582627
}
583628

@@ -669,3 +714,14 @@ void xe_pm_d3cold_allowed_toggle(struct xe_device *xe)
669714
drm_dbg(&xe->drm,
670715
"d3cold: allowed=%s\n", str_yes_no(xe->d3cold.allowed));
671716
}
717+
718+
/**
719+
* xe_pm_module_init() - Perform xe_pm specific module initialization.
720+
*
721+
* Return: 0 on success. Currently doesn't fail.
722+
*/
723+
int __init xe_pm_module_init(void)
724+
{
725+
xe_pm_runtime_lockdep_prime();
726+
return 0;
727+
}

drivers/gpu/drm/xe/xe_pm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ void xe_pm_assert_unbounded_bridge(struct xe_device *xe);
3232
int xe_pm_set_vram_threshold(struct xe_device *xe, u32 threshold);
3333
void xe_pm_d3cold_allowed_toggle(struct xe_device *xe);
3434
struct task_struct *xe_pm_read_callback_task(struct xe_device *xe);
35+
int xe_pm_module_init(void);
3536

3637
#endif

0 commit comments

Comments
 (0)