All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
@ 2018-10-23 19:07 Marek Olšák
       [not found] ` <20181023190733.15251-1-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-23 19:07 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Marek Olšák <marek.olsak@amd.com>

---
 amdgpu/amdgpu_bo.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index c0f42e81..81f8a5f7 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -22,20 +22,21 @@
  *
  */
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <limits.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/time.h>
 
 #include "libdrm_macros.h"
 #include "xf86drm.h"
 #include "amdgpu_drm.h"
 #include "amdgpu_internal.h"
 #include "util_math.h"
 
@@ -442,21 +443,29 @@ drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
 {
 	union drm_amdgpu_gem_mmap args;
 	void *ptr;
 	int r;
 
 	pthread_mutex_lock(&bo->cpu_access_mutex);
 
 	if (bo->cpu_ptr) {
 		/* already mapped */
 		assert(bo->cpu_map_count > 0);
-		bo->cpu_map_count++;
+
+		/* If the counter has already reached INT_MAX, don't increment
+		 * it and assume that the buffer will be mapped indefinitely.
+		 * The buffer is pretty unlikely to get unmapped by the user
+		 * at this point.
+		 */
+		if (bo->cpu_map_count != INT_MAX)
+			bo->cpu_map_count++;
+
 		*cpu = bo->cpu_ptr;
 		pthread_mutex_unlock(&bo->cpu_access_mutex);
 		return 0;
 	}
 
 	assert(bo->cpu_map_count == 0);
 
 	memset(&args, 0, sizeof(args));
 
 	/* Query the buffer address (args.addr_ptr).
@@ -492,21 +501,27 @@ drm_public int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo)
 
 	pthread_mutex_lock(&bo->cpu_access_mutex);
 	assert(bo->cpu_map_count >= 0);
 
 	if (bo->cpu_map_count == 0) {
 		/* not mapped */
 		pthread_mutex_unlock(&bo->cpu_access_mutex);
 		return -EINVAL;
 	}
 
-	bo->cpu_map_count--;
+	/* If the counter has already reached INT_MAX, don't decrement it.
+	 * This is because amdgpu_bo_cpu_map doesn't increment it past
+	 * INT_MAX.
+	 */
+	if (bo->cpu_map_count != INT_MAX)
+		bo->cpu_map_count--;
+
 	if (bo->cpu_map_count > 0) {
 		/* mapped multiple times */
 		pthread_mutex_unlock(&bo->cpu_access_mutex);
 		return 0;
 	}
 
 	r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno;
 	bo->cpu_ptr = NULL;
 	pthread_mutex_unlock(&bo->cpu_access_mutex);
 	return r;
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations
       [not found] ` <20181023190733.15251-1-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-23 19:07   ` Marek Olšák
       [not found]     ` <20181023190733.15251-2-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-10-24  2:38   ` [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count Zhang, Jerry(Junwei)
  2018-10-24  7:45   ` Christian König
  2 siblings, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-23 19:07 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Marek Olšák <marek.olsak@amd.com>

---
 amdgpu/amdgpu_bo.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 81f8a5f7..00b9b54a 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -91,26 +91,29 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev,
 	if (r)
 		goto out;
 
 	r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle,
 			     buf_handle);
 	if (r) {
 		amdgpu_close_kms_handle(dev, args.out.handle);
 		goto out;
 	}
 
-	pthread_mutex_lock(&dev->bo_table_mutex);
-	r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
-				*buf_handle);
-	pthread_mutex_unlock(&dev->bo_table_mutex);
-	if (r)
-		amdgpu_bo_free(*buf_handle);
+	if (alloc_buffer->preferred_heap &
+	    (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {
+		pthread_mutex_lock(&dev->bo_table_mutex);
+		r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
+					*buf_handle);
+		pthread_mutex_unlock(&dev->bo_table_mutex);
+		if (r)
+			amdgpu_bo_free(*buf_handle);
+	}
 out:
 	return r;
 }
 
 drm_public int amdgpu_bo_set_metadata(amdgpu_bo_handle bo,
 				      struct amdgpu_bo_metadata *info)
 {
 	struct drm_amdgpu_gem_metadata args = {};
 
 	args.handle = bo->handle;
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found] ` <20181023190733.15251-1-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-10-23 19:07   ` [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations Marek Olšák
@ 2018-10-24  2:38   ` Zhang, Jerry(Junwei)
       [not found]     ` <63dd9ca5-dbfc-ad21-4a3b-6c1f48f03a03-5C7GfCeVMHo@public.gmane.org>
  2018-10-24  7:45   ` Christian König
  2 siblings, 1 reply; 20+ messages in thread
From: Zhang, Jerry(Junwei) @ 2018-10-24  2:38 UTC (permalink / raw)
  To: Marek Olšák, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 10/24/18 3:07 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak@amd.com>

We need commit log and sign-off here.

BTW, have you encounter any issue about that?

>
> ---
>   amdgpu/amdgpu_bo.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> index c0f42e81..81f8a5f7 100644
> --- a/amdgpu/amdgpu_bo.c
> +++ b/amdgpu/amdgpu_bo.c
> @@ -22,20 +22,21 @@
>    *
>    */
>   
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <stdint.h>
>   #include <string.h>
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <unistd.h>
> +#include <limits.h>
>   #include <sys/ioctl.h>
>   #include <sys/mman.h>
>   #include <sys/time.h>
>   
>   #include "libdrm_macros.h"
>   #include "xf86drm.h"
>   #include "amdgpu_drm.h"
>   #include "amdgpu_internal.h"
>   #include "util_math.h"
>   
> @@ -442,21 +443,29 @@ drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
>   {
>   	union drm_amdgpu_gem_mmap args;
>   	void *ptr;
>   	int r;
>   
>   	pthread_mutex_lock(&bo->cpu_access_mutex);
>   
>   	if (bo->cpu_ptr) {
>   		/* already mapped */
>   		assert(bo->cpu_map_count > 0);
> -		bo->cpu_map_count++;
> +
> +		/* If the counter has already reached INT_MAX, don't increment
> +		 * it and assume that the buffer will be mapped indefinitely.
> +		 * The buffer is pretty unlikely to get unmapped by the user
> +		 * at this point.
> +		 */
> +		if (bo->cpu_map_count != INT_MAX)
> +			bo->cpu_map_count++;

If so, shall we print some error here to notice that indefinite mappings 
come up.

Regards,
Jerry
> +
>   		*cpu = bo->cpu_ptr;
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return 0;
>   	}
>   
>   	assert(bo->cpu_map_count == 0);
>   
>   	memset(&args, 0, sizeof(args));
>   
>   	/* Query the buffer address (args.addr_ptr).
> @@ -492,21 +501,27 @@ drm_public int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo)
>   
>   	pthread_mutex_lock(&bo->cpu_access_mutex);
>   	assert(bo->cpu_map_count >= 0);
>   
>   	if (bo->cpu_map_count == 0) {
>   		/* not mapped */
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return -EINVAL;
>   	}
>   
> -	bo->cpu_map_count--;
> +	/* If the counter has already reached INT_MAX, don't decrement it.
> +	 * This is because amdgpu_bo_cpu_map doesn't increment it past
> +	 * INT_MAX.
> +	 */
> +	if (bo->cpu_map_count != INT_MAX)
> +		bo->cpu_map_count--;
> +
>   	if (bo->cpu_map_count > 0) {
>   		/* mapped multiple times */
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return 0;
>   	}
>   
>   	r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno;
>   	bo->cpu_ptr = NULL;
>   	pthread_mutex_unlock(&bo->cpu_access_mutex);
>   	return r;

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations
       [not found]     ` <20181023190733.15251-2-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-24  2:41       ` Zhang, Jerry(Junwei)
  2018-10-24  8:04       ` Michel Dänzer
  1 sibling, 0 replies; 20+ messages in thread
From: Zhang, Jerry(Junwei) @ 2018-10-24  2:41 UTC (permalink / raw)
  To: Marek Olšák, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 10/24/18 3:07 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak@amd.com>

commit log and sign-off here as well.
And any reason for that?

Regards,
Jerry

>
> ---
>   amdgpu/amdgpu_bo.c | 15 +++++++++------
>   1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> index 81f8a5f7..00b9b54a 100644
> --- a/amdgpu/amdgpu_bo.c
> +++ b/amdgpu/amdgpu_bo.c
> @@ -91,26 +91,29 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev,
>   	if (r)
>   		goto out;
>   
>   	r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle,
>   			     buf_handle);
>   	if (r) {
>   		amdgpu_close_kms_handle(dev, args.out.handle);
>   		goto out;
>   	}
>   
> -	pthread_mutex_lock(&dev->bo_table_mutex);
> -	r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
> -				*buf_handle);
> -	pthread_mutex_unlock(&dev->bo_table_mutex);
> -	if (r)
> -		amdgpu_bo_free(*buf_handle);
> +	if (alloc_buffer->preferred_heap &
> +	    (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {
> +		pthread_mutex_lock(&dev->bo_table_mutex);
> +		r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
> +					*buf_handle);
> +		pthread_mutex_unlock(&dev->bo_table_mutex);
> +		if (r)
> +			amdgpu_bo_free(*buf_handle);
> +	}
>   out:
>   	return r;
>   }
>   
>   drm_public int amdgpu_bo_set_metadata(amdgpu_bo_handle bo,
>   				      struct amdgpu_bo_metadata *info)
>   {
>   	struct drm_amdgpu_gem_metadata args = {};
>   
>   	args.handle = bo->handle;

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found] ` <20181023190733.15251-1-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-10-23 19:07   ` [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations Marek Olšák
  2018-10-24  2:38   ` [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count Zhang, Jerry(Junwei)
@ 2018-10-24  7:45   ` Christian König
       [not found]     ` <7690cf4c-5eff-85e4-885c-2ecc9dc01c25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2 siblings, 1 reply; 20+ messages in thread
From: Christian König @ 2018-10-24  7:45 UTC (permalink / raw)
  To: Marek Olšák, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Daenzer, Michel

That looks really ugly to me. Mapping the same BO so often is illegal 
and should be handled as error.

Otherwise we will never be able to cleanly recover from a GPU lockup 
with lost state by reloading the client library.

Christian.

Am 23.10.18 um 21:07 schrieb Marek Olšák:
> From: Marek Olšák <marek.olsak@amd.com>
>
> ---
>   amdgpu/amdgpu_bo.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> index c0f42e81..81f8a5f7 100644
> --- a/amdgpu/amdgpu_bo.c
> +++ b/amdgpu/amdgpu_bo.c
> @@ -22,20 +22,21 @@
>    *
>    */
>   
>   #include <stdlib.h>
>   #include <stdio.h>
>   #include <stdint.h>
>   #include <string.h>
>   #include <errno.h>
>   #include <fcntl.h>
>   #include <unistd.h>
> +#include <limits.h>
>   #include <sys/ioctl.h>
>   #include <sys/mman.h>
>   #include <sys/time.h>
>   
>   #include "libdrm_macros.h"
>   #include "xf86drm.h"
>   #include "amdgpu_drm.h"
>   #include "amdgpu_internal.h"
>   #include "util_math.h"
>   
> @@ -442,21 +443,29 @@ drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu)
>   {
>   	union drm_amdgpu_gem_mmap args;
>   	void *ptr;
>   	int r;
>   
>   	pthread_mutex_lock(&bo->cpu_access_mutex);
>   
>   	if (bo->cpu_ptr) {
>   		/* already mapped */
>   		assert(bo->cpu_map_count > 0);
> -		bo->cpu_map_count++;
> +
> +		/* If the counter has already reached INT_MAX, don't increment
> +		 * it and assume that the buffer will be mapped indefinitely.
> +		 * The buffer is pretty unlikely to get unmapped by the user
> +		 * at this point.
> +		 */
> +		if (bo->cpu_map_count != INT_MAX)
> +			bo->cpu_map_count++;
> +
>   		*cpu = bo->cpu_ptr;
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return 0;
>   	}
>   
>   	assert(bo->cpu_map_count == 0);
>   
>   	memset(&args, 0, sizeof(args));
>   
>   	/* Query the buffer address (args.addr_ptr).
> @@ -492,21 +501,27 @@ drm_public int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo)
>   
>   	pthread_mutex_lock(&bo->cpu_access_mutex);
>   	assert(bo->cpu_map_count >= 0);
>   
>   	if (bo->cpu_map_count == 0) {
>   		/* not mapped */
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return -EINVAL;
>   	}
>   
> -	bo->cpu_map_count--;
> +	/* If the counter has already reached INT_MAX, don't decrement it.
> +	 * This is because amdgpu_bo_cpu_map doesn't increment it past
> +	 * INT_MAX.
> +	 */
> +	if (bo->cpu_map_count != INT_MAX)
> +		bo->cpu_map_count--;
> +
>   	if (bo->cpu_map_count > 0) {
>   		/* mapped multiple times */
>   		pthread_mutex_unlock(&bo->cpu_access_mutex);
>   		return 0;
>   	}
>   
>   	r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno;
>   	bo->cpu_ptr = NULL;
>   	pthread_mutex_unlock(&bo->cpu_access_mutex);
>   	return r;

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations
       [not found]     ` <20181023190733.15251-2-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-10-24  2:41       ` Zhang, Jerry(Junwei)
@ 2018-10-24  8:04       ` Michel Dänzer
       [not found]         ` <ea6c7b39-82e6-cbe0-15b3-071f0e8964d2-otUistvHUpPR7s880joybQ@public.gmane.org>
  1 sibling, 1 reply; 20+ messages in thread
From: Michel Dänzer @ 2018-10-24  8:04 UTC (permalink / raw)
  To: Marek Olšák; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 2018-10-23 9:07 p.m., Marek Olšák wrote:
> From: Marek Olšák <marek.olsak@amd.com>
> 
> ---
>  amdgpu/amdgpu_bo.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> index 81f8a5f7..00b9b54a 100644
> --- a/amdgpu/amdgpu_bo.c
> +++ b/amdgpu/amdgpu_bo.c
> @@ -91,26 +91,29 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev,
>  	if (r)
>  		goto out;
>  
>  	r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle,
>  			     buf_handle);
>  	if (r) {
>  		amdgpu_close_kms_handle(dev, args.out.handle);
>  		goto out;
>  	}
>  
> -	pthread_mutex_lock(&dev->bo_table_mutex);
> -	r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
> -				*buf_handle);
> -	pthread_mutex_unlock(&dev->bo_table_mutex);
> -	if (r)
> -		amdgpu_bo_free(*buf_handle);
> +	if (alloc_buffer->preferred_heap &
> +	    (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {

What about AMDGPU_GEM_DOMAIN_CPU? I mean, that's unlikely to actually be
used here, but if it were, exporting and importing the resulting BO
should work fine?

Instead of white-listing the domains which can be shared, it might be
better to black-list those which can't, i.e. GDS/GWS/OA.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations
       [not found]         ` <ea6c7b39-82e6-cbe0-15b3-071f0e8964d2-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2018-10-24  8:14           ` Christian König
       [not found]             ` <5d944204-e524-7ada-0188-f68cedbedf1c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Christian König @ 2018-10-24  8:14 UTC (permalink / raw)
  To: Michel Dänzer, Marek Olšák
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 24.10.18 um 10:04 schrieb Michel Dänzer:
> On 2018-10-23 9:07 p.m., Marek Olšák wrote:
>> From: Marek Olšák <marek.olsak@amd.com>
>>
>> ---
>>   amdgpu/amdgpu_bo.c | 15 +++++++++------
>>   1 file changed, 9 insertions(+), 6 deletions(-)
>>
>> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
>> index 81f8a5f7..00b9b54a 100644
>> --- a/amdgpu/amdgpu_bo.c
>> +++ b/amdgpu/amdgpu_bo.c
>> @@ -91,26 +91,29 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev,
>>   	if (r)
>>   		goto out;
>>   
>>   	r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle,
>>   			     buf_handle);
>>   	if (r) {
>>   		amdgpu_close_kms_handle(dev, args.out.handle);
>>   		goto out;
>>   	}
>>   
>> -	pthread_mutex_lock(&dev->bo_table_mutex);
>> -	r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
>> -				*buf_handle);
>> -	pthread_mutex_unlock(&dev->bo_table_mutex);
>> -	if (r)
>> -		amdgpu_bo_free(*buf_handle);
>> +	if (alloc_buffer->preferred_heap &
>> +	    (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {
> What about AMDGPU_GEM_DOMAIN_CPU? I mean, that's unlikely to actually be
> used here, but if it were, exporting and importing the resulting BO
> should work fine?
>
> Instead of white-listing the domains which can be shared, it might be
> better to black-list those which can't, i.e. GDS/GWS/OA.

Well first of all GDS can be shared between applications.

Then adding a BO to the tracking doesn't add much overhead (only 8 bytes 
and only if it was the last allocated).

So I don't really see a reason why we should do this?

Christian.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]     ` <63dd9ca5-dbfc-ad21-4a3b-6c1f48f03a03-5C7GfCeVMHo@public.gmane.org>
@ 2018-10-29 21:12       ` Marek Olšák
  0 siblings, 0 replies; 20+ messages in thread
From: Marek Olšák @ 2018-10-29 21:12 UTC (permalink / raw)
  To: Junwei Zhang; +Cc: amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 2190 bytes --]

On Tue, Oct 23, 2018 at 10:38 PM Zhang, Jerry(Junwei) <Jerry.Zhang-5C7GfCeVMHo@public.gmane.org>
wrote:

> On 10/24/18 3:07 AM, Marek Olšák wrote:
> > From: Marek Olšák <marek.olsak-5C7GfCeVMHo@public.gmane.org>
>
> We need commit log and sign-off here.
>
> BTW, have you encounter any issue about that?
>

I don't know what you mean. I'm pretty sure that a sign-off is not needed
for libdrm.


>
> >
> > ---
> >   amdgpu/amdgpu_bo.c | 19 +++++++++++++++++--
> >   1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> > index c0f42e81..81f8a5f7 100644
> > --- a/amdgpu/amdgpu_bo.c
> > +++ b/amdgpu/amdgpu_bo.c
> > @@ -22,20 +22,21 @@
> >    *
> >    */
> >
> >   #include <stdlib.h>
> >   #include <stdio.h>
> >   #include <stdint.h>
> >   #include <string.h>
> >   #include <errno.h>
> >   #include <fcntl.h>
> >   #include <unistd.h>
> > +#include <limits.h>
> >   #include <sys/ioctl.h>
> >   #include <sys/mman.h>
> >   #include <sys/time.h>
> >
> >   #include "libdrm_macros.h"
> >   #include "xf86drm.h"
> >   #include "amdgpu_drm.h"
> >   #include "amdgpu_internal.h"
> >   #include "util_math.h"
> >
> > @@ -442,21 +443,29 @@ drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle
> bo, void **cpu)
> >   {
> >       union drm_amdgpu_gem_mmap args;
> >       void *ptr;
> >       int r;
> >
> >       pthread_mutex_lock(&bo->cpu_access_mutex);
> >
> >       if (bo->cpu_ptr) {
> >               /* already mapped */
> >               assert(bo->cpu_map_count > 0);
> > -             bo->cpu_map_count++;
> > +
> > +             /* If the counter has already reached INT_MAX, don't
> increment
> > +              * it and assume that the buffer will be mapped
> indefinitely.
> > +              * The buffer is pretty unlikely to get unmapped by the
> user
> > +              * at this point.
> > +              */
> > +             if (bo->cpu_map_count != INT_MAX)
> > +                     bo->cpu_map_count++;
>
> If so, shall we print some error here to notice that indefinite mappings
> come up.
>

No error. This is expected usage.

Marek

[-- Attachment #1.2: Type: text/html, Size: 3276 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]     ` <7690cf4c-5eff-85e4-885c-2ecc9dc01c25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-29 21:15       ` Marek Olšák
       [not found]         ` <CAAxE2A50X-XGvyx7GcZnnAC4p-bRnXrQpjQZ1D-8pD5ir3QdMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-29 21:15 UTC (permalink / raw)
  To: Christian König; +Cc: Michel Dänzer, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 3683 bytes --]

You and I discussed this extensively internally a while ago. It's expected
and correct behavior. Mesa doesn't unmap some buffers and never will.

Marek

On Wed, Oct 24, 2018 at 3:45 AM Christian König <
ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> That looks really ugly to me. Mapping the same BO so often is illegal
> and should be handled as error.
>
> Otherwise we will never be able to cleanly recover from a GPU lockup
> with lost state by reloading the client library.
>
> Christian.
>
> Am 23.10.18 um 21:07 schrieb Marek Olšák:
> > From: Marek Olšák <marek.olsak-5C7GfCeVMHo@public.gmane.org>
> >
> > ---
> >   amdgpu/amdgpu_bo.c | 19 +++++++++++++++++--
> >   1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> > index c0f42e81..81f8a5f7 100644
> > --- a/amdgpu/amdgpu_bo.c
> > +++ b/amdgpu/amdgpu_bo.c
> > @@ -22,20 +22,21 @@
> >    *
> >    */
> >
> >   #include <stdlib.h>
> >   #include <stdio.h>
> >   #include <stdint.h>
> >   #include <string.h>
> >   #include <errno.h>
> >   #include <fcntl.h>
> >   #include <unistd.h>
> > +#include <limits.h>
> >   #include <sys/ioctl.h>
> >   #include <sys/mman.h>
> >   #include <sys/time.h>
> >
> >   #include "libdrm_macros.h"
> >   #include "xf86drm.h"
> >   #include "amdgpu_drm.h"
> >   #include "amdgpu_internal.h"
> >   #include "util_math.h"
> >
> > @@ -442,21 +443,29 @@ drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle
> bo, void **cpu)
> >   {
> >       union drm_amdgpu_gem_mmap args;
> >       void *ptr;
> >       int r;
> >
> >       pthread_mutex_lock(&bo->cpu_access_mutex);
> >
> >       if (bo->cpu_ptr) {
> >               /* already mapped */
> >               assert(bo->cpu_map_count > 0);
> > -             bo->cpu_map_count++;
> > +
> > +             /* If the counter has already reached INT_MAX, don't
> increment
> > +              * it and assume that the buffer will be mapped
> indefinitely.
> > +              * The buffer is pretty unlikely to get unmapped by the
> user
> > +              * at this point.
> > +              */
> > +             if (bo->cpu_map_count != INT_MAX)
> > +                     bo->cpu_map_count++;
> > +
> >               *cpu = bo->cpu_ptr;
> >               pthread_mutex_unlock(&bo->cpu_access_mutex);
> >               return 0;
> >       }
> >
> >       assert(bo->cpu_map_count == 0);
> >
> >       memset(&args, 0, sizeof(args));
> >
> >       /* Query the buffer address (args.addr_ptr).
> > @@ -492,21 +501,27 @@ drm_public int
> amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo)
> >
> >       pthread_mutex_lock(&bo->cpu_access_mutex);
> >       assert(bo->cpu_map_count >= 0);
> >
> >       if (bo->cpu_map_count == 0) {
> >               /* not mapped */
> >               pthread_mutex_unlock(&bo->cpu_access_mutex);
> >               return -EINVAL;
> >       }
> >
> > -     bo->cpu_map_count--;
> > +     /* If the counter has already reached INT_MAX, don't decrement it.
> > +      * This is because amdgpu_bo_cpu_map doesn't increment it past
> > +      * INT_MAX.
> > +      */
> > +     if (bo->cpu_map_count != INT_MAX)
> > +             bo->cpu_map_count--;
> > +
> >       if (bo->cpu_map_count > 0) {
> >               /* mapped multiple times */
> >               pthread_mutex_unlock(&bo->cpu_access_mutex);
> >               return 0;
> >       }
> >
> >       r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno;
> >       bo->cpu_ptr = NULL;
> >       pthread_mutex_unlock(&bo->cpu_access_mutex);
> >       return r;
>
>

[-- Attachment #1.2: Type: text/html, Size: 5174 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations
       [not found]             ` <5d944204-e524-7ada-0188-f68cedbedf1c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-29 21:16               ` Marek Olšák
  0 siblings, 0 replies; 20+ messages in thread
From: Marek Olšák @ 2018-10-29 21:16 UTC (permalink / raw)
  To: Christian König; +Cc: Michel Dänzer, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 2012 bytes --]

OK. I'll drop this patch.

Marek

On Wed, Oct 24, 2018 at 4:14 AM Christian König <
ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Am 24.10.18 um 10:04 schrieb Michel Dänzer:
> > On 2018-10-23 9:07 p.m., Marek Olšák wrote:
> >> From: Marek Olšák <marek.olsak-5C7GfCeVMHo@public.gmane.org>
> >>
> >> ---
> >>   amdgpu/amdgpu_bo.c | 15 +++++++++------
> >>   1 file changed, 9 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
> >> index 81f8a5f7..00b9b54a 100644
> >> --- a/amdgpu/amdgpu_bo.c
> >> +++ b/amdgpu/amdgpu_bo.c
> >> @@ -91,26 +91,29 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle
> dev,
> >>      if (r)
> >>              goto out;
> >>
> >>      r = amdgpu_bo_create(dev, alloc_buffer->alloc_size,
> args.out.handle,
> >>                           buf_handle);
> >>      if (r) {
> >>              amdgpu_close_kms_handle(dev, args.out.handle);
> >>              goto out;
> >>      }
> >>
> >> -    pthread_mutex_lock(&dev->bo_table_mutex);
> >> -    r = handle_table_insert(&dev->bo_handles, (*buf_handle)->handle,
> >> -                            *buf_handle);
> >> -    pthread_mutex_unlock(&dev->bo_table_mutex);
> >> -    if (r)
> >> -            amdgpu_bo_free(*buf_handle);
> >> +    if (alloc_buffer->preferred_heap &
> >> +        (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) {
> > What about AMDGPU_GEM_DOMAIN_CPU? I mean, that's unlikely to actually be
> > used here, but if it were, exporting and importing the resulting BO
> > should work fine?
> >
> > Instead of white-listing the domains which can be shared, it might be
> > better to black-list those which can't, i.e. GDS/GWS/OA.
>
> Well first of all GDS can be shared between applications.
>
> Then adding a BO to the tracking doesn't add much overhead (only 8 bytes
> and only if it was the last allocated).
>
> So I don't really see a reason why we should do this?
>
> Christian.
>

[-- Attachment #1.2: Type: text/html, Size: 2833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]         ` <CAAxE2A50X-XGvyx7GcZnnAC4p-bRnXrQpjQZ1D-8pD5ir3QdMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-10-30  8:20           ` Michel Dänzer
       [not found]             ` <e8cf4264-f211-70b3-01ec-34d0eb5e7edb-otUistvHUpPR7s880joybQ@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Michel Dänzer @ 2018-10-30  8:20 UTC (permalink / raw)
  To: Marek Olšák, Christian König; +Cc: amd-gfx mailing list

On 2018-10-29 10:15 p.m., Marek Olšák wrote:
> You and I discussed this extensively internally a while ago. It's expected
> and correct behavior. Mesa doesn't unmap some buffers and never will.

It doesn't need to keep mapping the same buffer over and over again
though, does it?


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]             ` <e8cf4264-f211-70b3-01ec-34d0eb5e7edb-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2018-10-30  9:19               ` Koenig, Christian
  2018-10-30 15:49               ` Marek Olšák
  1 sibling, 0 replies; 20+ messages in thread
From: Koenig, Christian @ 2018-10-30  9:19 UTC (permalink / raw)
  To: Michel Dänzer, Marek Olšák; +Cc: amd-gfx mailing list

Am 30.10.18 um 09:20 schrieb Michel Dänzer:
> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>> You and I discussed this extensively internally a while ago. It's expected
>> and correct behavior. Mesa doesn't unmap some buffers and never will.

Ah! Now I at least remember what issue that one was good for.

> It doesn't need to keep mapping the same buffer over and over again
> though, does it?

Yeah, that's a bit unclear to me as well.

Christian.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]             ` <e8cf4264-f211-70b3-01ec-34d0eb5e7edb-otUistvHUpPR7s880joybQ@public.gmane.org>
  2018-10-30  9:19               ` Koenig, Christian
@ 2018-10-30 15:49               ` Marek Olšák
       [not found]                 ` <CAAxE2A59+J7-jdYobFMMFDhS0oPLS8MgJXzV-Z=N7jhMr9rcdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  1 sibling, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-30 15:49 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Christian König, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 729 bytes --]

On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel-otUistvHUpPR7s880joybQ@public.gmane.org> wrote:

> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
> > You and I discussed this extensively internally a while ago. It's
> expected
> > and correct behavior. Mesa doesn't unmap some buffers and never will.
>
> It doesn't need to keep mapping the same buffer over and over again
> though, does it?
>

It doesnt map it again. It just doesnt unmap. So the next map call just
returns the pointer. It's correct to stop the counter wraparound.

Marek


>
> --
> Earthling Michel Dänzer               |               http://www.amd.com
> Libre software enthusiast             |             Mesa and X developer
>

[-- Attachment #1.2: Type: text/html, Size: 1439 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                 ` <CAAxE2A59+J7-jdYobFMMFDhS0oPLS8MgJXzV-Z=N7jhMr9rcdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-10-30 15:52                   ` Marek Olšák
       [not found]                     ` <CAAxE2A7kA_W3xeK01F7jthfMyEij3TFy_G7=A5_vsduNVrKpbQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-30 15:52 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Christian König, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1054 bytes --]

On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

>
>
> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel-otUistvHUpPR7s880joybQ@public.gmane.org> wrote:
>
>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>> > You and I discussed this extensively internally a while ago. It's
>> expected
>> > and correct behavior. Mesa doesn't unmap some buffers and never will.
>>
>> It doesn't need to keep mapping the same buffer over and over again
>> though, does it?
>>
>
> It doesnt map it again. It just doesnt unmap. So the next map call just
> returns the pointer. It's correct to stop the counter wraparound.
>

Mesa doesn't track whether a buffer is already mapped. Libdrm tracks that.
It's a feature of libdrm to return the same pointer and expect infinite
number of map calls.

Marek


> Marek
>
>
>>
>> --
>> Earthling Michel Dänzer               |               http://www.amd.com
>> Libre software enthusiast             |             Mesa and X developer
>>
>

[-- Attachment #1.2: Type: text/html, Size: 2335 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                     ` <CAAxE2A7kA_W3xeK01F7jthfMyEij3TFy_G7=A5_vsduNVrKpbQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-10-30 15:55                       ` Marek Olšák
  2018-10-30 15:59                       ` Michel Dänzer
  1 sibling, 0 replies; 20+ messages in thread
From: Marek Olšák @ 2018-10-30 15:55 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Christian König, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1345 bytes --]

On Tue, Oct 30, 2018, 11:52 AM Marek Olšák <maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

>
>
> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>>
>>
>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel-otUistvHUpPR7s880joybQ@public.gmane.org> wrote:
>>
>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>>> > You and I discussed this extensively internally a while ago. It's
>>> expected
>>> > and correct behavior. Mesa doesn't unmap some buffers and never will.
>>>
>>> It doesn't need to keep mapping the same buffer over and over again
>>> though, does it?
>>>
>>
>> It doesnt map it again. It just doesnt unmap. So the next map call just
>> returns the pointer. It's correct to stop the counter wraparound.
>>
>
> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks that.
> It's a feature of libdrm to return the same pointer and expect infinite
> number of map calls.
>

Mesa has been having this optimization for 8 years. (since the radeon
winsys). It's surprising that it surprises you now.

Marek



> Marek
>
>
>> Marek
>>
>>
>>>
>>> --
>>> Earthling Michel Dänzer               |               http://www.amd.com
>>> Libre software enthusiast             |             Mesa and X developer
>>>
>>

[-- Attachment #1.2: Type: text/html, Size: 3216 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                     ` <CAAxE2A7kA_W3xeK01F7jthfMyEij3TFy_G7=A5_vsduNVrKpbQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2018-10-30 15:55                       ` Marek Olšák
@ 2018-10-30 15:59                       ` Michel Dänzer
       [not found]                         ` <79fe6959-6f43-5c3b-8fa1-69d43498cdd4-otUistvHUpPR7s880joybQ@public.gmane.org>
  1 sibling, 1 reply; 20+ messages in thread
From: Michel Dänzer @ 2018-10-30 15:59 UTC (permalink / raw)
  To: Marek Olšák; +Cc: Christian König, amd-gfx mailing list

On 2018-10-30 4:52 p.m., Marek Olšák wrote:
> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo@gmail.com> wrote:
>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel@daenzer.net> wrote:
>>
>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>>>> You and I discussed this extensively internally a while ago. It's
>>> expected
>>>> and correct behavior. Mesa doesn't unmap some buffers and never will.
>>>
>>> It doesn't need to keep mapping the same buffer over and over again
>>> though, does it?
>>>
>>
>> It doesnt map it again. It just doesnt unmap. So the next map call just
>> returns the pointer. It's correct to stop the counter wraparound.
>>
> 
> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks that.
> It's a feature of libdrm to return the same pointer and expect infinite
> number of map calls.

That's not what the reference counting in libdrm is intended for. It's
for keeping track of how many independent callers have mapped the
buffer. Mesa should remember that it mapped a buffer and not map it again.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                         ` <79fe6959-6f43-5c3b-8fa1-69d43498cdd4-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2018-10-31  7:59                           ` Koenig, Christian
       [not found]                             ` <e434a695-a6c4-14f7-deff-5420d08311f7-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Koenig, Christian @ 2018-10-31  7:59 UTC (permalink / raw)
  To: Michel Dänzer, Marek Olšák; +Cc: amd-gfx mailing list

Am 30.10.18 um 16:59 schrieb Michel Dänzer:
> On 2018-10-30 4:52 p.m., Marek Olšák wrote:
>> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo@gmail.com> wrote:
>>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel@daenzer.net> wrote:
>>>
>>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>>>>> You and I discussed this extensively internally a while ago. It's
>>>> expected
>>>>> and correct behavior. Mesa doesn't unmap some buffers and never will.
>>>> It doesn't need to keep mapping the same buffer over and over again
>>>> though, does it?
>>>>
>>> It doesnt map it again. It just doesnt unmap. So the next map call just
>>> returns the pointer. It's correct to stop the counter wraparound.
>>>
>> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks that.
>> It's a feature of libdrm to return the same pointer and expect infinite
>> number of map calls.
> That's not what the reference counting in libdrm is intended for. It's
> for keeping track of how many independent callers have mapped the
> buffer. Mesa should remember that it mapped a buffer and not map it again.

Well if Mesa just wants to query the existing mapping then why not add a 
amdgpu_bo_get_cpu_ptr() which just queries if a CPU mapping exists and 
if yes returns the appropriate pointer or NULL otherwise?

I mean when we want to abstract everything in libdrm then we just need 
to add the functions we need to use this abstraction.

Christian.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                             ` <e434a695-a6c4-14f7-deff-5420d08311f7-5C7GfCeVMHo@public.gmane.org>
@ 2018-10-31 22:12                               ` Marek Olšák
       [not found]                                 ` <CAAxE2A7aZ2YiJN0P8KD1F=ncj17ds1x2Dmkka-tHR7Y5vrOOBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Marek Olšák @ 2018-10-31 22:12 UTC (permalink / raw)
  To: Christian König; +Cc: Michel Dänzer, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 1835 bytes --]

On Wed, Oct 31, 2018 at 3:59 AM Koenig, Christian <Christian.Koenig-5C7GfCeVMHo@public.gmane.org>
wrote:

> Am 30.10.18 um 16:59 schrieb Michel Dänzer:
> > On 2018-10-30 4:52 p.m., Marek Olšák wrote:
> >> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel-otUistvHUpPR7s880joybQ@public.gmane.org>
> wrote:
> >>>
> >>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
> >>>>> You and I discussed this extensively internally a while ago. It's
> >>>> expected
> >>>>> and correct behavior. Mesa doesn't unmap some buffers and never will.
> >>>> It doesn't need to keep mapping the same buffer over and over again
> >>>> though, does it?
> >>>>
> >>> It doesnt map it again. It just doesnt unmap. So the next map call just
> >>> returns the pointer. It's correct to stop the counter wraparound.
> >>>
> >> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks
> that.
> >> It's a feature of libdrm to return the same pointer and expect infinite
> >> number of map calls.
> > That's not what the reference counting in libdrm is intended for. It's
> > for keeping track of how many independent callers have mapped the
> > buffer. Mesa should remember that it mapped a buffer and not map it
> again.
>
> Well if Mesa just wants to query the existing mapping then why not add a
> amdgpu_bo_get_cpu_ptr() which just queries if a CPU mapping exists and
> if yes returns the appropriate pointer or NULL otherwise?
>
> I mean when we want to abstract everything in libdrm then we just need
> to add the functions we need to use this abstraction.
>

That can be future work for the sake of cleanliness and clarity, but it
would be a waste of time and wouldn't help old Mesa.

Marek

[-- Attachment #1.2: Type: text/html, Size: 2557 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                                 ` <CAAxE2A7aZ2YiJN0P8KD1F=ncj17ds1x2Dmkka-tHR7Y5vrOOBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2018-11-02  7:39                                   ` Koenig, Christian
       [not found]                                     ` <7ca0e170-5a2b-a6ed-4d2e-13d9b32011a7-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: Koenig, Christian @ 2018-11-02  7:39 UTC (permalink / raw)
  To: Marek Olšák; +Cc: Michel Dänzer, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 2046 bytes --]

Am 31.10.18 um 23:12 schrieb Marek Olšák:
On Wed, Oct 31, 2018 at 3:59 AM Koenig, Christian <Christian.Koenig@amd.com<mailto:Christian.Koenig@amd.com>> wrote:
Am 30.10.18 um 16:59 schrieb Michel Dänzer:
> On 2018-10-30 4:52 p.m., Marek Olšák wrote:
>> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo@gmail.com<mailto:maraeo@gmail.com>> wrote:
>>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel@daenzer.net<mailto:michel@daenzer.net>> wrote:
>>>
>>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>>>>> You and I discussed this extensively internally a while ago. It's
>>>> expected
>>>>> and correct behavior. Mesa doesn't unmap some buffers and never will.
>>>> It doesn't need to keep mapping the same buffer over and over again
>>>> though, does it?
>>>>
>>> It doesnt map it again. It just doesnt unmap. So the next map call just
>>> returns the pointer. It's correct to stop the counter wraparound.
>>>
>> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks that.
>> It's a feature of libdrm to return the same pointer and expect infinite
>> number of map calls.
> That's not what the reference counting in libdrm is intended for. It's
> for keeping track of how many independent callers have mapped the
> buffer. Mesa should remember that it mapped a buffer and not map it again.

Well if Mesa just wants to query the existing mapping then why not add a
amdgpu_bo_get_cpu_ptr() which just queries if a CPU mapping exists and
if yes returns the appropriate pointer or NULL otherwise?

I mean when we want to abstract everything in libdrm then we just need
to add the functions we need to use this abstraction.

That can be future work for the sake of cleanliness and clarity, but it would be a waste of time and wouldn't help old Mesa.

That it doesn't help old Mesa is unfortunate, but this is clearly a bug in Mesa.

If old Mesa is broken then we should fix it by updating it and not add workarounds for specific clients in libdrm.

Regards,
Christian.


Marek


[-- Attachment #1.2: Type: text/html, Size: 3299 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count
       [not found]                                     ` <7ca0e170-5a2b-a6ed-4d2e-13d9b32011a7-5C7GfCeVMHo@public.gmane.org>
@ 2018-11-02 19:42                                       ` Marek Olšák
  0 siblings, 0 replies; 20+ messages in thread
From: Marek Olšák @ 2018-11-02 19:42 UTC (permalink / raw)
  To: Christian König; +Cc: Michel Dänzer, amd-gfx mailing list


[-- Attachment #1.1: Type: text/plain, Size: 2707 bytes --]

On Fri, Nov 2, 2018 at 3:39 AM Koenig, Christian <Christian.Koenig-5C7GfCeVMHo@public.gmane.org>
wrote:

> Am 31.10.18 um 23:12 schrieb Marek Olšák:
>
> On Wed, Oct 31, 2018 at 3:59 AM Koenig, Christian <
> Christian.Koenig-5C7GfCeVMHo@public.gmane.org> wrote:
>
>> Am 30.10.18 um 16:59 schrieb Michel Dänzer:
>> > On 2018-10-30 4:52 p.m., Marek Olšák wrote:
>> >> On Tue, Oct 30, 2018, 11:49 AM Marek Olšák <maraeo-Re5JQEeQqe8@public.gmane.orgm> wrote:
>> >>> On Tue, Oct 30, 2018, 4:20 AM Michel Dänzer <michel-otUistvHUpPR7s880joybQ@public.gmane.org>
>> wrote:
>> >>>
>> >>>> On 2018-10-29 10:15 p.m., Marek Olšák wrote:
>> >>>>> You and I discussed this extensively internally a while ago. It's
>> >>>> expected
>> >>>>> and correct behavior. Mesa doesn't unmap some buffers and never
>> will.
>> >>>> It doesn't need to keep mapping the same buffer over and over again
>> >>>> though, does it?
>> >>>>
>> >>> It doesnt map it again. It just doesnt unmap. So the next map call
>> just
>> >>> returns the pointer. It's correct to stop the counter wraparound.
>> >>>
>> >> Mesa doesn't track whether a buffer is already mapped. Libdrm tracks
>> that.
>> >> It's a feature of libdrm to return the same pointer and expect infinite
>> >> number of map calls.
>> > That's not what the reference counting in libdrm is intended for. It's
>> > for keeping track of how many independent callers have mapped the
>> > buffer. Mesa should remember that it mapped a buffer and not map it
>> again.
>>
>> Well if Mesa just wants to query the existing mapping then why not add a
>> amdgpu_bo_get_cpu_ptr() which just queries if a CPU mapping exists and
>> if yes returns the appropriate pointer or NULL otherwise?
>>
>> I mean when we want to abstract everything in libdrm then we just need
>> to add the functions we need to use this abstraction.
>>
>
> That can be future work for the sake of cleanliness and clarity, but it
> would be a waste of time and wouldn't help old Mesa.
>
>
> That it doesn't help old Mesa is unfortunate, but this is clearly a bug in
> Mesa.
>
> If old Mesa is broken then we should fix it by updating it and not add
> workarounds for specific clients in libdrm.
>

It's not a workaround. We made a decision with amdgpu to share code by
moving portions of the Mesa winsys into libdrm. The map_count is part of
that. It's highly desirable to continue with code sharing. There is nothing
broken with Mesa. Mesa won't check whether a buffer is already mapped.
That's the responsibility of libdrm as part of code sharing and we don't
want to duplicate the same logic in Mesa. It's all part of the intended
design.

Marek

[-- Attachment #1.2: Type: text/html, Size: 3863 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2018-11-02 19:42 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-23 19:07 [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count Marek Olšák
     [not found] ` <20181023190733.15251-1-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-23 19:07   ` [PATCH libdrm 2/2] amdgpu: don't track handles for non-memory allocations Marek Olšák
     [not found]     ` <20181023190733.15251-2-maraeo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-24  2:41       ` Zhang, Jerry(Junwei)
2018-10-24  8:04       ` Michel Dänzer
     [not found]         ` <ea6c7b39-82e6-cbe0-15b3-071f0e8964d2-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-10-24  8:14           ` Christian König
     [not found]             ` <5d944204-e524-7ada-0188-f68cedbedf1c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-29 21:16               ` Marek Olšák
2018-10-24  2:38   ` [PATCH libdrm 1/2] amdgpu: prevent an integer wraparound of cpu_map_count Zhang, Jerry(Junwei)
     [not found]     ` <63dd9ca5-dbfc-ad21-4a3b-6c1f48f03a03-5C7GfCeVMHo@public.gmane.org>
2018-10-29 21:12       ` Marek Olšák
2018-10-24  7:45   ` Christian König
     [not found]     ` <7690cf4c-5eff-85e4-885c-2ecc9dc01c25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-29 21:15       ` Marek Olšák
     [not found]         ` <CAAxE2A50X-XGvyx7GcZnnAC4p-bRnXrQpjQZ1D-8pD5ir3QdMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-10-30  8:20           ` Michel Dänzer
     [not found]             ` <e8cf4264-f211-70b3-01ec-34d0eb5e7edb-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-10-30  9:19               ` Koenig, Christian
2018-10-30 15:49               ` Marek Olšák
     [not found]                 ` <CAAxE2A59+J7-jdYobFMMFDhS0oPLS8MgJXzV-Z=N7jhMr9rcdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-10-30 15:52                   ` Marek Olšák
     [not found]                     ` <CAAxE2A7kA_W3xeK01F7jthfMyEij3TFy_G7=A5_vsduNVrKpbQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-10-30 15:55                       ` Marek Olšák
2018-10-30 15:59                       ` Michel Dänzer
     [not found]                         ` <79fe6959-6f43-5c3b-8fa1-69d43498cdd4-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-10-31  7:59                           ` Koenig, Christian
     [not found]                             ` <e434a695-a6c4-14f7-deff-5420d08311f7-5C7GfCeVMHo@public.gmane.org>
2018-10-31 22:12                               ` Marek Olšák
     [not found]                                 ` <CAAxE2A7aZ2YiJN0P8KD1F=ncj17ds1x2Dmkka-tHR7Y5vrOOBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-11-02  7:39                                   ` Koenig, Christian
     [not found]                                     ` <7ca0e170-5a2b-a6ed-4d2e-13d9b32011a7-5C7GfCeVMHo@public.gmane.org>
2018-11-02 19:42                                       ` Marek Olšák

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.