Skip to contentSkip to conversation

drm/amdgpu: don't try to unreserve NULL pointer

PATCH In review Christian König 5 participants 11 messages Sep 17, 2018 – Sep 18, 2018 8 messages not in the archive

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

PATCH 1/1 drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
 	return 0;
 }
Signature · 6 lines
2.14.1

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

A message that is not in the archive (sent off-list or not yet received): 20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw
Quoted 14 lines · Christian König

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct amdgpu_device *adev, · line 351

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
  	if (r)
  		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)

Can we put this check inside ttm_bo_unreserve?
James Zhu

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct amdgpu_device *adev, · line 355

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
+		amdgpu_bo_unreserve(*bo_ptr);
 
  	return 0;
  }

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

A message that is not in the archive (sent off-list or not yet received): 4304faa2-5777-9d0a-c8e8-b00e431238f0-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Am 17.09.2018 um 20:41 schrieb James Zhu:

Quoted 12 lines · Christian König
Quoted 9 lines

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct amdgpu_device · line 352

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device 
 *adev,
       if (r)
           return r;
   -    amdgpu_bo_unreserve(*bo_ptr);
+    if (*bo_ptr)

Can we put this check inside ttm_bo_unreserve?

No, calling amdgpu_bo_unreserve() with a NULL pointer is certainly a bug.

Christian.

Quoted 9 lines

James Zhu

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct amdgpu_device *adev, · line 355

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
+        amdgpu_bo_unreserve(*bo_ptr);
         return 0;
   }

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

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

Acked-by
#5 lore raw
In reply to a message not in the archive
Quoted 5 lines · Christian König

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs

If we set size as 0 while create bo, the bo_ptr will be NULL after that.

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
 	return 0;
 }
Signature · 6 lines
2.14.1

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

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

#6 lore raw
In reply to a message not in the archive
Quoted 33 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device
 *adev,
 	if (r)
 		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
 	return 0;
Quoted 1 line

}

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB27754BE2A5210C53B1054F53FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#8 lore raw

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 31 lines
Quoted 31 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device
 *adev,
  	if (r)
  		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
Quoted 5 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
  	return 0;
  }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you expected.

Is that only a rhetorical question or really a problem somewhere?

Regards,
Christian.

Quoted 11 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): 27a7e247-d895-17e8-5493-051dea82536d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#10 lore raw
Quoted 46 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, September 18, 2018 3:14 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct

amdgpu_device

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
 *adev,
 	if (r)
  		return r;
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct amdgpu_device *adev, · line 355

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
  	return 0;
  }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

Quoted 6 lines

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you expected.

Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick. It also make the code if (r)

	return r; 

redundant.

Regards
Rex

Quoted 14 lines

Regards,
Christian.

Quoted 11 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB27759724D41FECEEC1926845FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#12 lore raw

Am 18.09.2018 um 10:16 schrieb Zhu, Rex:

Quoted 43 lines
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, September 18, 2018 3:14 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 16 lines
Quoted 16 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct

amdgpu_device

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct · line 355

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
 *adev,
 	if (r)
   		return r;
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
   	return 0;
   }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

Quoted 7 lines
Quoted 6 lines

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you expected.

Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick.

Yeah, that is not a bad argument.

But it also makes the function more useful, e.g. we don't need size checks any more whenever an optional BO is allocated.

Quoted 4 lines

It also make the code
if (r)

	return r;

redundant.

Actually that is not correct.

When an error happens the *bo_ptr is not modified at all. So we could then try to unreserve a BO which was never reserved.

Christian.

Quoted 17 lines

Regards
Rex

Quoted 13 lines

Regards,
Christian.

Quoted 10 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): 248d2af0-e330-90e9-38c8-176a2bbd3649-5C7GfCeVMHo@public.gmane.org

#14 lore raw
Quoted 59 lines

-----Original Message-----
From: Koenig, Christian
Sent: Tuesday, September 18, 2018 4:41 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 10:16 schrieb Zhu, Rex:

Quoted 44 lines
Quoted 44 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, September 18, 2018 3:14 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel

BOs

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct

amdgpu_device

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct · line 355

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
 *adev,
 	if (r)
   		return r;
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
   	return 0;
   }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

Quoted 4 lines
Quoted 4 lines

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you

expected.

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick.

Yeah, that is not a bad argument.

But it also makes the function more useful, e.g. we don't need size checks any more whenever an optional BO is allocated.

Yes, the problem is user don't need size check. But user have no way to check whether the bo is allocated successfully.

Because in size 0 case, the create function also return true.
And as you said below, check bo_ptr is not safe either(the *bo_ptr may be not modified at all).

Regards
Rex

Quoted 9 lines
Quoted 4 lines

It also make the code
if (r)

	return r;

redundant.

Actually that is not correct.

When an error happens the *bo_ptr is not modified at all. So we could then try to unreserve a BO which was never reserved.

Yes, You ae right.

Quoted 19 lines

Christian.

Quoted 17 lines

Regards
Rex

Quoted 13 lines

Regards,
Christian.

Quoted 10 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): BYAPR12MB27755971A03F2E03A5BF58BCFB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#16 lore raw

Am 18.09.2018 um 11:27 schrieb Zhu, Rex:

Quoted 58 lines
Quoted 58 lines

-----Original Message-----
From: Koenig, Christian
Sent: Tuesday, September 18, 2018 4:41 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 10:16 schrieb Zhu, Rex:

Quoted 43 lines
Quoted 43 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, September 18, 2018 3:14 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel

BOs

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
    1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct

amdgpu_device

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct · line 355

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
 *adev,
 	if (r)
    		return r;
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
    	return 0;
    }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

Quoted 4 lines
Quoted 4 lines

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you

expected.

Quoted 2 lines
Quoted 1 line

Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick.

Quoted 8 lines
Quoted 4 lines

Yeah, that is not a bad argument.

But it also makes the function more useful, e.g. we don't need size checks any more whenever an optional BO is allocated.

Yes, the problem is user don't need size check. But user have no way to check whether the bo is allocated successfully.

Because in size 0 case, the create function also return true.
And as you said below, check bo_ptr is not safe either(the *bo_ptr may be not modified at all).

That is not correct. When size==0 we call amdgpu_bo_unref(bo_ptr), and that one sets bo_ptr to NULL.

When size==0 was possible before, the calling code would have needed to check bo_ptr later on anyway.

In other words what we had before:

calling_function()
{
    if (size) {
        r = amdgpu_bo_create_kernel(..., size, &bo); if (r)
            goto error_handling;
    }
    ....
    if (bo)
        ....
}

But now that looks like:
calling_function()
{
    r = amdgpu_bo_create_kernel(..., size, &bo);
    if (r)
        goto error_handling;
    ....
    if (bo) {
        ....
}

So we just removed the extra size check of the calling function. I think that is a valid usage.

Christian.

Quoted 11 lines

Regards
Rex

Quoted 4 lines
Quoted 4 lines

It also make the code
if (r)

	return r;

redundant.

Quoted 25 lines
Quoted 4 lines

Actually that is not correct.

When an error happens the *bo_ptr is not modified at all. So we could then try to unreserve a BO which was never reserved.

Yes, You ae right.

Quoted 18 lines

Christian.

Quoted 16 lines

Regards
Rex

Quoted 13 lines

Regards,
Christian.

Quoted 10 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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

A message that is not in the archive (sent off-list or not yet received): 279b1ebf-326e-34b9-2878-bda3ffee21b8-5C7GfCeVMHo@public.gmane.org

#18 lore raw

Thanks.
So we still need to check the bo valid before use for the case that if we don't know the size when allocate.

Best Regards
Rex

Quoted 109 lines

-----Original Message-----
From: Koenig, Christian
Sent: Tuesday, September 18, 2018 5:34 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 11:27 schrieb Zhu, Rex:

Quoted 56 lines
Quoted 56 lines

-----Original Message-----
From: Koenig, Christian
Sent: Tuesday, September 18, 2018 4:41 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 10:16 schrieb Zhu, Rex:

Quoted 48 lines
Quoted 48 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, September 18, 2018 3:14 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:

Quoted 17 lines
Quoted 17 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Tuesday, September 18, 2018 2:07 AM
To: [email protected]
Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer

Don't try to unreserve a BO we doesn't allocated.

Fixes 07012fdd497e drm/amdgpu: don't allocate zero sized kernel

BOs

---
    drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
    1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index 84d82d5382f9..c1387efc0c91 100644
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct

amdgpu_device

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -1
 *adev,
 	if (r)
    		return r;
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_kernel(struct · line 355

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
    	return 0;
    }

It is weird.
If we return true for allocate bo with size 0.
Does that mean we need to check all the bo_ptr before we use them.

No, allocating a BO with zero size doesn't make much sense and was essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you

Quoted 8 lines
Quoted 7 lines

expected.

Quoted 2 lines
Quoted 1 line

Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick.

Yeah, that is not a bad argument.

But it also makes the function more useful, e.g. we don't need size checks any more whenever an optional BO is allocated.

Yes, the problem is user don't need size check. But user have no way to

check whether the bo is allocated successfully.

Quoted 3 lines

Because in size 0 case, the create function also return true. And as you said below, check bo_ptr is not safe either(the *bo_ptr may be

not modified at all).

That is not correct. When size==0 we call amdgpu_bo_unref(bo_ptr), and that one sets bo_ptr to NULL.

When size==0 was possible before, the calling code would have needed to check bo_ptr later on anyway.

In other words what we had before:

calling_function()
{
    if (size) {
        r = amdgpu_bo_create_kernel(..., size, &bo); if (r)
            goto error_handling;
    }
    ....
    if (bo)
        ....
}

But now that looks like:
calling_function()
{
    r = amdgpu_bo_create_kernel(..., size, &bo);
    if (r)
        goto error_handling;
    ....
    if (bo) {
        ....
}

Quoted 42 lines

So we just removed the extra size check of the calling function. I think that is a valid usage.

Christian.

Quoted 36 lines

Regards
Rex

Quoted 8 lines
Quoted 4 lines

It also make the code
if (r)

	return r;

redundant.

Actually that is not correct.

When an error happens the *bo_ptr is not modified at all. So we could then try to unreserve a BO which was never reserved.

Yes, You ae right.

Quoted 18 lines

Christian.

Quoted 16 lines

Regards
Rex

Quoted 13 lines

Regards,
Christian.

Quoted 10 lines

Best Regards
Rex

Quoted 7 lines

--
2.14.1

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

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