diff options
| author | Dave Airlie <airlied@redhat.com> | 2025-09-12 06:37:32 +0300 | 
|---|---|---|
| committer | Dave Airlie <airlied@redhat.com> | 2025-09-12 06:37:41 +0300 | 
| commit | cf99b26d3081b1f9961cc213415867706d19a414 (patch) | |
| tree | 297925ddee936e6e956138cccc530c204a7f8a83 /drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | |
| parent | 8d04ea1a92b843890b874551959a9b21bc7f30d4 (diff) | |
| parent | 2fd653b9bb5aacec5d4c421ab290905898fe85a2 (diff) | |
| download | linux-cf99b26d3081b1f9961cc213415867706d19a414.tar.xz | |
Merge tag 'amd-drm-next-6.18-2025-09-09' of https://gitlab.freedesktop.org/agd5f/linux into drm-next
amd-drm-next-6.18-2025-09-09:
amdgpu:
- Add CRIU support for gem objects
- SI UVD fix
- SI DPM fixes
- Misc code cleanups
- RAS updates
- GPUVM debugfs fixes
- Cyan Skillfish updates
- UserQ updates
- OEM i2c fix
- SMU 13.0.x updates
- DPCD probe quirk fix
- Make vbios build number available in sysfs
- HDCP updates
- Brightness curve fixes
- eDP updates
- Vblank fixes
- DCN 3.5 PG fix
- PBN calcution fix
amdkfd:
- Add CRIU support for gem objects
- Flexible array fix
- P2P topology fix
- APU memlimit fixes
- Misc code cleanups
UAPI:
- Add CRIU support for gem objects
  Proposed userspace: https://github.com/checkpoint-restore/criu/pull/2613
radeon:
- Use dev_warn_once() in CS parsers
Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Alex Deucher <alexander.deucher@amd.com>
Link: https://lore.kernel.org/r/20250909161928.942785-1-alexander.deucher@amd.com
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c')
| -rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 179 | 
1 files changed, 157 insertions, 22 deletions
| diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index d5e685c5e28b..630175746780 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -442,15 +442,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,  	int r;  	/* reject invalid gem flags */ -	if (flags & ~(AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | -		      AMDGPU_GEM_CREATE_NO_CPU_ACCESS | -		      AMDGPU_GEM_CREATE_CPU_GTT_USWC | -		      AMDGPU_GEM_CREATE_VRAM_CLEARED | -		      AMDGPU_GEM_CREATE_VM_ALWAYS_VALID | -		      AMDGPU_GEM_CREATE_EXPLICIT_SYNC | -		      AMDGPU_GEM_CREATE_ENCRYPTED | -		      AMDGPU_GEM_CREATE_GFX12_DCC | -		      AMDGPU_GEM_CREATE_DISCARDABLE)) +	if (flags & ~AMDGPU_GEM_CREATE_SETTABLE_MASK)  		return -EINVAL;  	/* reject invalid gem domains */ @@ -963,17 +955,34 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,  	struct drm_gem_object *gobj;  	struct amdgpu_vm_bo_base *base;  	struct amdgpu_bo *robj; +	struct drm_exec exec; +	struct amdgpu_fpriv *fpriv = filp->driver_priv;  	int r; +	if (args->padding) +		return -EINVAL; +  	gobj = drm_gem_object_lookup(filp, args->handle);  	if (!gobj)  		return -ENOENT;  	robj = gem_to_amdgpu_bo(gobj); -	r = amdgpu_bo_reserve(robj, false); -	if (unlikely(r)) -		goto out; +	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT | +			  DRM_EXEC_IGNORE_DUPLICATES, 0); +	drm_exec_until_all_locked(&exec) { +		r = drm_exec_lock_obj(&exec, gobj); +		drm_exec_retry_on_contention(&exec); +		if (r) +			goto out_exec; + +		if (args->op == AMDGPU_GEM_OP_GET_MAPPING_INFO) { +			r = amdgpu_vm_lock_pd(&fpriv->vm, &exec, 0); +			drm_exec_retry_on_contention(&exec); +			if (r) +				goto out_exec; +		} +	}  	switch (args->op) {  	case AMDGPU_GEM_OP_GET_GEM_CREATE_INFO: { @@ -984,7 +993,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,  		info.alignment = robj->tbo.page_alignment << PAGE_SHIFT;  		info.domains = robj->preferred_domains;  		info.domain_flags = robj->flags; -		amdgpu_bo_unreserve(robj); +		drm_exec_fini(&exec);  		if (copy_to_user(out, &info, sizeof(info)))  			r = -EFAULT;  		break; @@ -993,20 +1002,17 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,  		if (drm_gem_is_imported(&robj->tbo.base) &&  		    args->value & AMDGPU_GEM_DOMAIN_VRAM) {  			r = -EINVAL; -			amdgpu_bo_unreserve(robj); -			break; +			goto out_exec;  		}  		if (amdgpu_ttm_tt_get_usermm(robj->tbo.ttm)) {  			r = -EPERM; -			amdgpu_bo_unreserve(robj); -			break; +			goto out_exec;  		}  		for (base = robj->vm_bo; base; base = base->next)  			if (amdgpu_xgmi_same_hive(amdgpu_ttm_adev(robj->tbo.bdev),  				amdgpu_ttm_adev(base->vm->root.bo->tbo.bdev))) {  				r = -EINVAL; -				amdgpu_bo_unreserve(robj); -				goto out; +				goto out_exec;  			} @@ -1019,17 +1025,146 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,  		if (robj->flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)  			amdgpu_vm_bo_invalidate(robj, true); +		drm_exec_fini(&exec); +		break; +	case AMDGPU_GEM_OP_GET_MAPPING_INFO: { +		struct amdgpu_bo_va *bo_va = amdgpu_vm_bo_find(&fpriv->vm, robj); +		struct drm_amdgpu_gem_vm_entry *vm_entries; +		struct amdgpu_bo_va_mapping *mapping; +		int num_mappings = 0; +		/* +		 * num_entries is set as an input to the size of the user-allocated array of +		 * drm_amdgpu_gem_vm_entry stored at args->value. +		 * num_entries is sent back as output as the number of mappings the bo has. +		 * If that number is larger than the size of the array, the ioctl must +		 * be retried. +		 */ +		vm_entries = kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL); +		if (!vm_entries) +			return -ENOMEM; + +		amdgpu_vm_bo_va_for_each_valid_mapping(bo_va, mapping) { +			if (num_mappings < args->num_entries) { +				vm_entries[num_mappings].addr = mapping->start * AMDGPU_GPU_PAGE_SIZE; +				vm_entries[num_mappings].size = (mapping->last - mapping->start + 1) * AMDGPU_GPU_PAGE_SIZE; +				vm_entries[num_mappings].offset = mapping->offset; +				vm_entries[num_mappings].flags = mapping->flags; +			} +			num_mappings += 1; +		} + +		amdgpu_vm_bo_va_for_each_invalid_mapping(bo_va, mapping) { +			if (num_mappings < args->num_entries) { +				vm_entries[num_mappings].addr = mapping->start * AMDGPU_GPU_PAGE_SIZE; +				vm_entries[num_mappings].size = (mapping->last - mapping->start + 1) * AMDGPU_GPU_PAGE_SIZE; +				vm_entries[num_mappings].offset = mapping->offset; +				vm_entries[num_mappings].flags = mapping->flags; +			} +			num_mappings += 1; +		} -		amdgpu_bo_unreserve(robj); +		drm_exec_fini(&exec); + +		if (num_mappings > 0 && num_mappings <= args->num_entries) +			if (copy_to_user(u64_to_user_ptr(args->value), vm_entries, num_mappings * sizeof(*vm_entries))) +				r = -EFAULT; + +		args->num_entries = num_mappings; + +		kvfree(vm_entries);  		break; +	}  	default: -		amdgpu_bo_unreserve(robj); +		drm_exec_fini(&exec);  		r = -EINVAL;  	} -out:  	drm_gem_object_put(gobj);  	return r; +out_exec: +	drm_exec_fini(&exec); +	drm_gem_object_put(gobj); +	return r; +} + +/** + * amdgpu_gem_list_handles_ioctl - get information about a process' buffer objects + * + * @dev: drm device pointer + * @data: drm_amdgpu_gem_list_handles + * @filp: drm file pointer + * + * num_entries is set as an input to the size of the entries array. + * num_entries is sent back as output as the number of bos in the process. + * If that number is larger than the size of the array, the ioctl must + * be retried. + * + * Returns: + * 0 for success, -errno for errors. + */ +int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data, +				  struct drm_file *filp) +{ +	struct drm_amdgpu_gem_list_handles *args = data; +	struct drm_amdgpu_gem_list_handles_entry *bo_entries; +	struct drm_gem_object *gobj; +	int id, ret = 0; +	int bo_index = 0; +	int num_bos = 0; + +	spin_lock(&filp->table_lock); +	idr_for_each_entry(&filp->object_idr, gobj, id) +		num_bos += 1; +	spin_unlock(&filp->table_lock); + +	if (args->num_entries < num_bos) { +		args->num_entries = num_bos; +		return 0; +	} + +	if (num_bos == 0) { +		args->num_entries = 0; +		return 0; +	} + +	bo_entries = kvcalloc(num_bos, sizeof(*bo_entries), GFP_KERNEL); +	if (!bo_entries) +		return -ENOMEM; + +	spin_lock(&filp->table_lock); +	idr_for_each_entry(&filp->object_idr, gobj, id) { +		struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj); +		struct drm_amdgpu_gem_list_handles_entry *bo_entry; + +		if (bo_index >= num_bos) { +			ret = -EAGAIN; +			break; +		} + +		bo_entry = &bo_entries[bo_index]; + +		bo_entry->size = amdgpu_bo_size(bo); +		bo_entry->alloc_flags = bo->flags & AMDGPU_GEM_CREATE_SETTABLE_MASK; +		bo_entry->preferred_domains = bo->preferred_domains; +		bo_entry->gem_handle = id; +		bo_entry->alignment = bo->tbo.page_alignment; + +		if (bo->tbo.base.import_attach) +			bo_entry->flags |= AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT; + +		bo_index += 1; +	} +	spin_unlock(&filp->table_lock); + +	args->num_entries = bo_index; + +	if (!ret) +		if (copy_to_user(u64_to_user_ptr(args->entries), bo_entries, num_bos * sizeof(*bo_entries))) +			ret = -EFAULT; + +	kvfree(bo_entries); + +	return ret;  }  static int amdgpu_gem_align_pitch(struct amdgpu_device *adev, | 
