<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I think these are pretty fundamental errors. You should never hit them in practice and if you do, I think a BUG is fine.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> ZhiJie.Zhang <zhangzhijie@loongson.cn><br>
<b>Sent:</b> Thursday, December 16, 2021 9:38 PM<br>
<b>To:</b> Koenig, Christian <Christian.Koenig@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> zhangzhijie@loongson.cn <zhangzhijie@loongson.cn>; botton_zhang@163.com <botton_zhang@163.com>; airlied@linux.ie <airlied@linux.ie>; daniel@ffwll.ch <daniel@ffwll.ch>; Jack.Zhang1@amd.com <Jack.Zhang1@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: Try To using WARN() instead BUG() avoid kernel panic</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Signed-off-by: ZhiJie.Zhang <zhangzhijie@loongson.cn><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 4 +--<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 +++++++++++++++-------<br>
drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 5 +++-<br>
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 18 +++++++++----<br>
4 files changed, 41 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
index f1a050379190..edf2de4cec8c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
@@ -76,7 +76,7 @@ static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device,<br>
DRM_ERROR("audio endpt register access not implemented.\n");<br>
return 0;<br>
default:<br>
- BUG();<br>
+ adev->accel_working = false;<br>
}<br>
WARN(1, "Invalid indirect register space");<br>
return 0;<br>
@@ -104,9 +104,9 @@ static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device,<br>
DRM_ERROR("audio endpt register access not implemented.\n");<br>
return;<br>
default:<br>
- BUG();<br>
}<br>
WARN(1, "Invalid indirect register space");<br>
+ adev->accel_working = false;<br>
}<br>
<br>
static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index 188accb71249..b9ecf7f70409 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -488,7 +488,11 @@ uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset)<br>
<br>
if (offset < adev->rmmio_size)<br>
return (readb(adev->rmmio + offset));<br>
- BUG();<br>
+<br>
+ WARN(1, "Invalid indirect register space");<br>
+ adev->accel_working = false;<br>
+<br>
+ return 0;<br>
}<br>
<br>
/*<br>
@@ -513,8 +517,10 @@ void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value)<br>
<br>
if (offset < adev->rmmio_size)<br>
writeb(value, adev->rmmio + offset);<br>
- else<br>
- BUG();<br>
+ else {<br>
+ WARN(1, "Invalid indirect register space");<br>
+ adev->accel_working = false;<br>
+ }<br>
}<br>
<br>
/**<br>
@@ -803,7 +809,8 @@ void amdgpu_device_indirect_wreg64(struct amdgpu_device *adev,<br>
static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)<br>
{<br>
DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
return 0;<br>
}<br>
<br>
@@ -821,7 +828,8 @@ static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32<br>
{<br>
DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",<br>
reg, v);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
}<br>
<br>
/**<br>
@@ -837,7 +845,8 @@ static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32<br>
static uint64_t amdgpu_invalid_rreg64(struct amdgpu_device *adev, uint32_t reg)<br>
{<br>
DRM_ERROR("Invalid callback to read 64 bit register 0x%04X\n", reg);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
return 0;<br>
}<br>
<br>
@@ -855,7 +864,8 @@ static void amdgpu_invalid_wreg64(struct amdgpu_device *adev, uint32_t reg, uint<br>
{<br>
DRM_ERROR("Invalid callback to write 64 bit register 0x%04X with 0x%08llX\n",<br>
reg, v);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
}<br>
<br>
/**<br>
@@ -874,7 +884,9 @@ static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,<br>
{<br>
DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",<br>
reg, block);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
+<br>
return 0;<br>
}<br>
<br>
@@ -895,7 +907,8 @@ static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,<br>
{<br>
DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",<br>
reg, block, v);<br>
- BUG();<br>
+<br>
+ adev->accel_working = false;<br>
}<br>
<br>
/**<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c<br>
index c8ebd108548d..957169142e57 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c<br>
@@ -129,7 +129,10 @@ static int cik_sdma_init_microcode(struct amdgpu_device *adev)<br>
case CHIP_MULLINS:<br>
chip_name = "mullins";<br>
break;<br>
- default: BUG();<br>
+ default:<br>
+ DRM_ERROR("Invalid CHIPS");<br>
+ err = -EINVAL;<br>
+ goto out;<br>
}<br>
<br>
for (i = 0; i < adev->sdma.num_instances; i++) {<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c<br>
index 6a8dadea40f9..e312a2146f6f 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c<br>
@@ -334,7 +334,10 @@ static int gfx_v6_0_init_microcode(struct amdgpu_device *adev)<br>
case CHIP_HAINAN:<br>
chip_name = "hainan";<br>
break;<br>
- default: BUG();<br>
+ default:<br>
+ DRM_ERROR("Invalid CHIPS");<br>
+ err = -EINVAL;<br>
+ goto out;<br>
}<br>
<br>
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp.bin", chip_name);<br>
@@ -1668,8 +1671,8 @@ static void gfx_v6_0_constants_init(struct amdgpu_device *adev)<br>
gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;<br>
break;<br>
default:<br>
- BUG();<br>
- break;<br>
+ DRM_ERROR("Invalid CHIPS");<br>
+ return;<br>
}<br>
<br>
WREG32(mmGRBM_CNTL, (0xff << GRBM_CNTL__READ_TIMEOUT__SHIFT));<br>
@@ -2153,7 +2156,10 @@ static u64 gfx_v6_0_ring_get_wptr(struct amdgpu_ring *ring)<br>
else if (ring == &adev->gfx.compute_ring[1])<br>
return RREG32(mmCP_RB2_WPTR);<br>
else<br>
- BUG();<br>
+ WARN(1, "Invalid Ring Buffer");<br>
+<br>
+ adev->accel_working = false;<br>
+ return -EINVAL;<br>
}<br>
<br>
static void gfx_v6_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)<br>
@@ -2175,7 +2181,9 @@ static void gfx_v6_0_ring_set_wptr_compute(struct amdgpu_ring *ring)<br>
WREG32(mmCP_RB2_WPTR, lower_32_bits(ring->wptr));<br>
(void)RREG32(mmCP_RB2_WPTR);<br>
} else {<br>
- BUG();<br>
+ WARN(1, "Invalid Ring Buffer");<br>
+<br>
+ adev->accel_working = false;<br>
}<br>
<br>
}<br>
-- <br>
2.34.0<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>