From: Matthew Wilcox Date: Mon, 18 Feb 2019 13:25:32 +0000 (-0500) Subject: drm/amdkfd: Convert alloc_idr to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cd8a3044c3b108a541477565f9cb1929535371e1;p=users%2Fwilly%2Fxarray.git drm/amdkfd: Convert alloc_idr to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 2387c96157ec0..b74a97bb6ce76 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -639,7 +639,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 diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 8f1076c0c88a2..a734b4477156a 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -372,13 +372,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, @@ -427,8 +427,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); } } @@ -756,8 +754,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; } @@ -874,35 +871,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. */