Skip to contentSkip to conversation

drm/amdkfd: replace idr_init() by idr_init_base()

PATCH In review Deepak R Varma 3 participants 4 messages Nov 4, 2020 – Nov 5, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: replace idr_init() by idr_init_base()

idr_init() uses base 0 which is an invalid identifier. The new function idr_init_base allows IDR to set the ID lookup from base 1. This avoids all lookups that otherwise starts from 0 since 0 is always unused.

References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")

---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c  | 2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
index ba2c2ce0c55a..b3339b53c8ad 100644
@@ -230,7 +230,7 @@ static int create_other_event(struct kfd_process *p, struct kfd_event *ev)
 void kfd_event_init_process(struct kfd_process *p)
 {
 	mutex_init(&p->event_mutex);
-	idr_init(&p->event_idr);
+	idr_init_base(&p->event_idr, 1);
 	p->signal_page = NULL;
 	p->signal_event_count = 0;
 }
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index 65803e153a22..022e61babe30 100644
@@ -1289,7 +1289,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
 	list_add(&pdd->per_device_list, &p->per_device_data);
 
 	/* Init idr used for memory handle translation */
-	idr_init(&pdd->alloc_idr);
+	idr_init_base(&pdd->alloc_idr, 1);
 
 	return pdd;
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Am 04.11.20 um 16:13 schrieb Deepak R Varma:

Quoted 7 lines

idr_init() uses base 0 which is an invalid identifier. The new function idr_init_base allows IDR to set the ID lookup from base 1. This avoids all lookups that otherwise starts from 0 since 0 is always unused.

References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")

Quoted 23 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
index ba2c2ce0c55a..b3339b53c8ad 100644
@@ -230,7 +230,7 @@ static int create_other_event(struct kfd_process *p, struct kfd_event *ev)
  void kfd_event_init_process(struct kfd_process *p)
  {
  	mutex_init(&p->event_mutex);
-	idr_init(&p->event_idr);
+	idr_init_base(&p->event_idr, 1);
  	p->signal_page = NULL;
  	p->signal_event_count = 0;
  }
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 65803e153a22..022e61babe30 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, · line 1295

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
@@ -1289,7 +1289,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
  	list_add(&pdd->per_device_list, &p->per_device_data);
 
  	/* Init idr used for memory handle translation */
-	idr_init(&pdd->alloc_idr);
+	idr_init_base(&pdd->alloc_idr, 1);
 
  	return pdd;
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer
#2 lore raw
In reply to Deepak R Varma
Quoted 3 lines · Deepak R Varma

idr_init() uses base 0 which is an invalid identifier. The new function idr_init_base allows IDR to set the ID lookup from base 1. This avoids all lookups that otherwise starts from 0 since 0 is always unused.

I disagree. We call idr_alloc with start=0 for both these IDRs. That means 0 seems to be a valid handle.

Regards,
  Felix

Quoted 27 lines

References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")

---
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
index ba2c2ce0c55a..b3339b53c8ad 100644
@@ -230,7 +230,7 @@ static int create_other_event(struct kfd_process *p, struct kfd_event *ev)
  void kfd_event_init_process(struct kfd_process *p)
  {
  	mutex_init(&p->event_mutex);
-	idr_init(&p->event_idr);
+	idr_init_base(&p->event_idr, 1);
  	p->signal_page = NULL;
  	p->signal_event_count = 0;
  }
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 65803e153a22..022e61babe30 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, · line 1295

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
@@ -1289,7 +1289,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
  	list_add(&pdd->per_device_list, &p->per_device_data);
 
  	/* Init idr used for memory handle translation */
-	idr_init(&pdd->alloc_idr);
+	idr_init_base(&pdd->alloc_idr, 1);
 
  	return pdd;
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw
Quoted 7 lines · Felix Kuehling
Quoted 3 lines · Deepak R Varma

idr_init() uses base 0 which is an invalid identifier. The new function idr_init_base allows IDR to set the ID lookup from base 1. This avoids all lookups that otherwise starts from 0 since 0 is always unused.

I disagree. We call idr_alloc with start=0 for both these IDRs. That means 0 seems to be a valid handle.

Hello Felix,
You are correct. There are calls made to idr_alloc with start range from
0. So, for this driver, id=0 seems a valid use case. The change I proposed is not relevant for this driver. You may please ignore the patch.

Thank you,
./drv

Quoted 37 lines

Regards,
  Felix

Quoted 32 lines

References: commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient")

---
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
index ba2c2ce0c55a..b3339b53c8ad 100644
@@ -230,7 +230,7 @@ static int create_other_event(struct kfd_process *p, struct kfd_event *ev)
  void kfd_event_init_process(struct kfd_process *p)
  {
  	mutex_init(&p->event_mutex);
-	idr_init(&p->event_idr);
+	idr_init_base(&p->event_idr, 1);
  	p->signal_page = NULL;
  	p->signal_event_count = 0;
  }
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
index 65803e153a22..022e61babe30 100644
@@ -1289,7 +1289,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
  	list_add(&pdd->per_device_list, &p->per_device_data);
  	/* Init idr used for memory handle translation */
-	idr_init(&pdd->alloc_idr);
+	idr_init_base(&pdd->alloc_idr, 1);
  	return pdd;