[Intel-xe] [PATCH v5 5/7] drm/xe/ggtt: prime ggtt->lock against FS_RECLAIM

Matthew Auld matthew.auld at intel.com
Wed May 17 16:21:39 UTC 2023


On 17/05/2023 16:48, Rodrigo Vivi wrote:
> On Wed, May 17, 2023 at 04:22:42PM +0100, Matthew Auld wrote:
>> Increase the sensitivity of the ggtt->lock by priming it against
>> FS_RECLAIM, such that allocating memory while holding will result in
>> lockdep splats.
>>
>> Signed-off-by: Matthew Auld <matthew.auld at intel.com>
>> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
>> Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
>> ---
>>   drivers/gpu/drm/xe/xe_ggtt.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
>> index f986e8218820..e25eb70d44f6 100644
>> --- a/drivers/gpu/drm/xe/xe_ggtt.c
>> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
>> @@ -90,6 +90,16 @@ static void ggtt_fini_noalloc(struct drm_device *drm, void *arg)
>>   	xe_bo_unpin_map_no_vm(ggtt->scratch);
>>   }
>>   
>> +static void primelockdep(struct xe_ggtt *ggtt)
>> +{
>> +	if (!IS_ENABLED(CONFIG_LOCKDEP))
>> +		return;
>> +
>> +	fs_reclaim_acquire(GFP_KERNEL);
>> +	might_lock(&ggtt->lock);
>> +	fs_reclaim_release(GFP_KERNEL);
> 
> should we use the might_alloc instead of these fs_reclaim directly?
> or the order here with the ggtt->lock in the middle matters?

Yeah, the order matters. I think roughly fs_reclaim is a dummy lock 
taken when entering direct reclaim (like shrinker). So here we are just 
teaching lockdep that fs_reclaim -> ggtt->lock is the correct lock 
order. If anything later inverts that we should get a splat, like for 
example doing kmalloc(GFP_KERNEL) while holding ggtt->lock. In other 
words we are saying that ggtt->lock can potentially be grabbed directly 
from the shrinker.

> 
>> +}
>> +
>>   int xe_ggtt_init_noalloc(struct xe_gt *gt, struct xe_ggtt *ggtt)
>>   {
>>   	struct xe_device *xe = gt_to_xe(gt);
>> @@ -132,6 +142,7 @@ int xe_ggtt_init_noalloc(struct xe_gt *gt, struct xe_ggtt *ggtt)
>>   	drm_mm_init(&ggtt->mm, xe_wopcm_size(xe),
>>   		    ggtt->size - xe_wopcm_size(xe));
>>   	mutex_init(&ggtt->lock);
>> +	primelockdep(ggtt);
>>   
>>   	return drmm_add_action_or_reset(&xe->drm, ggtt_fini_noalloc, ggtt);
>>   }
>> -- 
>> 2.40.1
>>


More information about the Intel-xe mailing list