@@ -590,7 +590,7 @@ struct kfd_process_device {
void *vm;
/* GPUVM allocations storage */
- struct idr alloc_idr;
+ struct xarray allocations;
/* Flag used to tell the pdd has dequeued from the dqm.
* This is used to prevent dev->dqm->ops.process_termination() from
@@ -284,13 +284,13 @@ static void kfd_process_device_free_bos(struct kfd_process_device *pdd)
{
struct kfd_process *p = pdd->process;
void *mem;
- int id;
+ unsigned long id;
/*
- * Remove all handles from idr and release appropriate
+ * Remove all handles and release appropriate
* local memory object
*/
- idr_for_each_entry(&pdd->alloc_idr, mem, id) {
+ xa_for_each(&pdd->allocations, id, mem) {
struct kfd_process_device *peer_pdd;
list_for_each_entry(peer_pdd, &p->per_device_data,
@@ -339,8 +339,6 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
get_order(KFD_CWSR_TBA_TMA_SIZE));
kfree(pdd->qpd.doorbell_bitmap);
- idr_destroy(&pdd->alloc_idr);
-
kfree(pdd);
}
}
@@ -656,8 +654,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
pdd->already_dequeued = false;
list_add(&pdd->per_device_list, &p->per_device_data);
- /* Init idr used for memory handle translation */
- idr_init(&pdd->alloc_idr);
+ xa_init_flags(&pdd->allocations, XA_FLAGS_ALLOC);
return pdd;
}
@@ -774,35 +771,36 @@ bool kfd_has_process_device_data(struct kfd_process *p)
return !(list_empty(&p->per_device_data));
}
-/* Create specific handle mapped to mem from process local memory idr
+/* Create specific handle mapped to mem from process local memory
* Assumes that the process lock is held.
*/
int kfd_process_device_create_obj_handle(struct kfd_process_device *pdd,
void *mem)
{
- return idr_alloc(&pdd->alloc_idr, mem, 0, 0, GFP_KERNEL);
+ int id, ret;
+
+ ret = xa_alloc(&pdd->allocations, &id, mem, xa_limit_31b, GFP_KERNEL);
+ if (ret < 0)
+ return ret;
+ return id;
}
-/* Translate specific handle from process local memory idr
+/* Translate specific handle from process local memory
* Assumes that the process lock is held.
*/
void *kfd_process_device_translate_handle(struct kfd_process_device *pdd,
int handle)
{
- if (handle < 0)
- return NULL;
-
- return idr_find(&pdd->alloc_idr, handle);
+ return xa_load(&pdd->allocations, handle);
}
-/* Remove specific handle from process local memory idr
+/* Remove specific handle from process local memory
* Assumes that the process lock is held.
*/
void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
int handle)
{
- if (handle >= 0)
- idr_remove(&pdd->alloc_idr, handle);
+ xa_erase(&pdd->allocations, handle);
}
/* This increments the process->ref counter. */
Signed-off-by: Matthew Wilcox <willy@infradead.org> --- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 32 +++++++++++------------- 2 files changed, 16 insertions(+), 18 deletions(-)