Skip to contentSkip to conversation

gpu: drm: fix an improper check of amdgpu_bo_create_kernel

PATCH In review Kangjie Lu 3 participants 3 messages Dec 26, 2018 – Dec 27, 2018

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 gpu: drm: fix an improper check of amdgpu_bo_create_kernel

adev->firmware.fw_buf being not NULL may not indicate kernel buffer is created successful. A better way is to check the status (return value) of it. The fix does so.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +12 -6
index 7b33867036e7..ba3c1cfb2c35 100644
@@ -422,13 +422,19 @@ static int amdgpu_ucode_patch_jt(struct amdgpu_firmware_info *ucode,
 
 int amdgpu_ucode_create_bo(struct amdgpu_device *adev)
 {
+	int ret;
+
 	if (adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT) {
-		amdgpu_bo_create_kernel(adev, adev->firmware.fw_size, PAGE_SIZE,
-			amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
-			&adev->firmware.fw_buf,
-			&adev->firmware.fw_buf_mc,
-			&adev->firmware.fw_buf_ptr);
-		if (!adev->firmware.fw_buf) {
+		ret =
+			amdgpu_bo_create_kernel(adev,
+			  adev->firmware.fw_size,
+			  PAGE_SIZE,
+			  amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM :
+				AMDGPU_GEM_DOMAIN_GTT,
+			  &adev->firmware.fw_buf,
+			  &adev->firmware.fw_buf_mc,
+				&adev->firmware.fw_buf_ptr);
+		if (ret) {
 			dev_err(adev->dev, "failed to create kernel buffer for firmware.fw_buf\n");
 			return -ENOMEM;
 		} else if (amdgpu_sriov_vf(adev)) {
Signature · 1 line
2.17.2 (Apple Git-113)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines

-----Original Message-----
From: Kangjie Lu [mailto:[email protected]]
Sent: Wednesday, December 26, 2018 2:24 PM
To: [email protected]
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhou, David(ChunMing) <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Zhu, Rex <[email protected]>; Huang, Ray <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Gao, Likun <[email protected]>; Francis, David <[email protected]>; [email protected]; dri- [email protected]; [email protected]
Subject: [PATCH] gpu: drm: fix an improper check of amdgpu_bo_create_kernel

Quoted 3 lines

adev->firmware.fw_buf being not NULL may not indicate kernel buffer is created successful. A better way is to check the status (return value) of it. The fix does so.

Actually, it is the same. If bo is created successfully, the amdgpu_bo object will be created. But using "ret" to align with other function should be better as the return status. Thanks.

Quoted 43 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +7 -6
index 7b33867036e7..ba3c1cfb2c35 100644
@@ -422,13 +422,19 @@ static int amdgpu_ucode_patch_jt(struct
 amdgpu_firmware_info *ucode,
 
 int amdgpu_ucode_create_bo(struct amdgpu_device *adev)
 {
+	int ret;
+
 	if (adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT) {
-		amdgpu_bo_create_kernel(adev, adev->firmware.fw_size,
 PAGE_SIZE,
-			amdgpu_sriov_vf(adev) ?
 AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
-			&adev->firmware.fw_buf,
-			&adev->firmware.fw_buf_mc,
-			&adev->firmware.fw_buf_ptr);
-		if (!adev->firmware.fw_buf) {
+		ret =
+			amdgpu_bo_create_kernel(adev,
+			  adev->firmware.fw_size,
+			  PAGE_SIZE,
+			  amdgpu_sriov_vf(adev) ?

AMDGPU_GEM_DOMAIN_VRAM :

drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +5 -0
+				AMDGPU_GEM_DOMAIN_GTT,
+			  &adev->firmware.fw_buf,
+			  &adev->firmware.fw_buf_mc,
+				&adev->firmware.fw_buf_ptr);
+		if (ret) {
 			dev_err(adev->dev, "failed to create kernel buffer

for firmware.fw_buf\n");

drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +0 -1
 			return -ENOMEM;
 		} else if (amdgpu_sriov_vf(adev)) {
--
Quoted 1 line

2.17.2 (Apple Git-113)

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

#2 lore raw
In reply to Kangjie Lu

Comments in line.

Thanks
JimQu
________________________________________
发件人: amd-gfx <[email protected]> 代表 Kangjie Lu <[email protected]>
发送时间: 2018年12月26日 14:23
收件人: [email protected]
抄送: Zhou, David(ChunMing); David Airlie; Xu, Feifei; Francis, David; [email protected]; [email protected]; Huang, Ray; [email protected]; Daniel Vetter; [email protected]; Deucher, Alexander; Gao, Likun; Zhu, Rex; Koenig, Christian; Zhang, Hawking 主题: [PATCH] gpu: drm: fix an improper check of amdgpu_bo_create_kernel

adev->firmware.fw_buf being not NULL may not indicate kernel buffer is created successful. A better way is to check the status (return value) of it. The fix does so.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c +12 -6
index 7b33867036e7..ba3c1cfb2c35 100644
@@ -422,13 +422,19 @@ static int amdgpu_ucode_patch_jt(struct amdgpu_firmware_info *ucode,
 
 int amdgpu_ucode_create_bo(struct amdgpu_device *adev)
 {
+       int ret;
+
        if (adev->firmware.load_type != AMDGPU_FW_LOAD_DIRECT) {
-               amdgpu_bo_create_kernel(adev, adev->firmware.fw_size, PAGE_SIZE,
-                       amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
-                       &adev->firmware.fw_buf,
-                       &adev->firmware.fw_buf_mc,
-                       &adev->firmware.fw_buf_ptr);
-               if (!adev->firmware.fw_buf) {
+               ret =
+                       amdgpu_bo_create_kernel(adev,
+                         adev->firmware.fw_size,
+                         PAGE_SIZE,
+                         amdgpu_sriov_vf(adev) ? AMDGPU_GEM_DOMAIN_VRAM :
+                               AMDGPU_GEM_DOMAIN_GTT,
+                         &adev->firmware.fw_buf,
+                         &adev->firmware.fw_buf_mc,
+                               &adev->firmware.fw_buf_ptr);
+               if (ret) {
 

JimQu: Look into amdgpu_bo_create_kernel(), new bo will be created only if *bo_ptr = NULL, So if you encounter the issue the adev->firmware.fw_buf != NULL but new bo is not created, the only problem I can see are:

1. there is bug in amdgpu_bo_create_kernel()
2. adev->firmware.fw_buf != NULL before it is transferred into amdgpu_bo_create_kernel().

Could you commit what is environment you encounter the issue?

Thanks
JimQu

                        dev_err(adev->dev, "failed to create kernel buffer for firmware.fw_buf\n");
                        return -ENOMEM;
                } else if (amdgpu_sriov_vf(adev)) {

--
2.17.2 (Apple Git-113)

_______________________________________________
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