drm/amd/amdgpu: Fix NULL RAS context deref on VF unrecoverable error
Subsystems (2)
PATCH 1/1 drm/amd/amdgpu: Fix NULL RAS context deref on VF unrecoverable error
A VF has no RAS context when RAS isn't supported on it or before RAS is initialized during probe. Handling UNRECOV_ERR_NOTIFICATION in that state dereferences a NULL amdgpu_ras pointer and panics the guest.
The fix is to track the notification in adev->virt.unrecov_err instead of the RAS context, and amdgpu_Ras_is_rma() checks that flags for VFs. Once the flag is set, mailbox reqs fail immediately with -ENODEV and GPU recovery bails out. If the notification arrives during probe, probe now fails cleaning instead of panicking. If it arrives during unload, unload completes without accessing the HW.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 3 +++ drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 15 ++++++++++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 23 ++++++++++++----------- 4 files changed, 30 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
@@ -4925,6 +4925,9 @@ bool amdgpu_ras_is_rma(struct amdgpu_device *adev) {struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +if (amdgpu_sriov_vf (adev)) +return adev->virt.unrecov_err; +if (amdgpu_uniras_enabled (adev))return amdgpu_ras_mgr_is_rma (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +3 -0
@@ -358,6 +358,9 @@ struct amdgpu_virt {/* hibernate and resume with different VF feature for xgmi enabled system */ bool is_xgmi_node_migrate_enabled; + +/* PF reported the VF unrecoverable */ +bool unrecov_err; };struct amdgpu_video_codec_info ;
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +12 -3
@@ -98,6 +98,16 @@ static int xgpu_ai_poll_ack(struct amdgpu_device *adev)return -ETIME ; } +static void xgpu_ai_set_unrecov_err (struct amdgpu_device *adev) +{ +if (adev->virt.unrecov_err) +return ; + + adev->virt.unrecov_err = true; + +dev_err (adev->dev,"VF is in an unrecoverable state. Runtime Services are halted.\n" ); +} +static int xgpu_ai_poll_msg (struct amdgpu_device *adev,enum idh_event event) {int r, timeout =AI_MAILBOX_POLL_MSG_TIMEDOUT ;
@@ -345,7 +355,6 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev, struct amdgpu_iv_entry *entry) {enum idh_event event =xgpu_ai_mailbox_peek_msg (adev); -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev);switch (event) {case IDH_RAS_BAD_PAGES_READY :
@@ -360,8 +369,8 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,break ;case IDH_UNRECOV_ERR_NOTIFICATION :xgpu_ai_mailbox_send_ack (adev); - ras->is_rma = true; -dev_err (adev->dev,"VF is in an unrecoverable state. Runtime Services are halted.\n" ); +xgpu_ai_set_unrecov_err (adev); +if (amdgpu_sriov_runtime (adev)) WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain, &adev->virt.flr_work),
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +12 -11
@@ -103,11 +103,20 @@ static int xgpu_nv_poll_ack(struct amdgpu_device *adev)return -ETIME ; } +static void xgpu_nv_set_unrecov_err (struct amdgpu_device *adev) +{ +if (adev->virt.unrecov_err) +return ; + + adev->virt.unrecov_err = true; + +dev_err (adev->dev,"VF is in an unrecoverable state. Runtime Services are halted.\n" ); +} +static int xgpu_nv_poll_msg (struct amdgpu_device *adev,enum idh_event event) {int r;uint64_t timeout, now; -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev); now = (uint64_t )ktime_to_ms (ktime_get ()); timeout = now +NV_MAILBOX_POLL_MSG_TIMEDOUT ;
@@ -119,11 +128,7 @@ static int xgpu_nv_poll_msg(struct amdgpu_device *adev, enum idh_event event) event, NV_MAILBOX_POLL_MSG_TIMEDOUT - timeout + now);return 0 ; }else if (r == -ENODEV ) { -if (!amdgpu_ras_is_rma (adev)) { - ras->is_rma = true; -dev_err (adev->dev,"VF is in an unrecoverable state. " -"Runtime Services are halted.\n" ); - } +xgpu_nv_set_unrecov_err (adev);return r; }
@@ -453,7 +458,6 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev, struct amdgpu_iv_entry *entry) {enum idh_event event =xgpu_nv_mailbox_peek_msg (adev); -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev);switch (event) {case IDH_RAS_BAD_PAGES_READY :
@@ -468,10 +472,7 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev,break ;case IDH_UNRECOV_ERR_NOTIFICATION :xgpu_nv_mailbox_send_ack (adev); -if (!amdgpu_ras_is_rma (adev)) { - ras->is_rma = true; -dev_err (adev->dev,"VF is in an unrecoverable state. Runtime Services are halted.\n" ); - } +xgpu_nv_set_unrecov_err (adev);if (amdgpu_sriov_runtime (adev)) WARN_ONCE(!amdgpu_reset_domain_schedule(adev->reset_domain,
Signature · 1 line
2.43.0
AMD General
Quoted 48 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Ellen Pan
Sent: Thursday, October 22, 2026 4:48 AM
To: [email protected]
Cc: Lazar, Lijo <[email protected]>; Luo, Zhigang <[email protected]>; Wan, Gavin <[email protected]>; Chan, Hing Pong <[email protected]>; Pan, Ellen <[email protected]>
Subject: [PATCH] drm/amd/amdgpu: Fix NULL RAS context deref on VF unrecoverable errorA VF has no RAS context when RAS isn't supported on it or before RAS is initialized during probe. Handling
UNRECOV_ERR_NOTIFICATIONin that state dereferences a NULLamdgpu_raspointer and panics the guest.The fix is to track the notification in
adev->virt.unrecov_errinstead of the RAS context, andamdgpu_Ras_is_rma()checks that flags for VFs. Once the flag is set, mailbox reqs fail immediately with-ENODEVand GPU recovery bails out. If the notification arrives during probe, probe now fails cleaning instead of panicking. If it arrives during unload, unload completes without accessing the HW.Signed-off-by Ellen Pan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 3 +++ drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 15 ++++++++++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c | 23 ++++++++++++----------- 4 files changed, 30 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3
-0@@ -4925,6 +4925,9 @@ bool amdgpu_ras_is_rma(struct amdgpu_device *adev) {struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +if (amdgpu_sriov_vf (adev)) +return adev->virt.unrecov_err; +if (amdgpu_uniras_enabled (adev))return amdgpu_ras_mgr_is_rma (adev);drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h struct amdgpu_virt { · line 362
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +2
-0@@ -358,6 +358,9 @@ struct amdgpu_virt {/* hibernate and resume with different VF feature for xgmi enabled system */ bool is_xgmi_node_migrate_enabled; + +/* PF reported the VF unrecoverable */
[Tao] you can update comment to clarify that vf maintains rma status by itself, with this fixed, the patch is:
Quoted 112 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1
-0+bool unrecov_err; };struct amdgpu_video_codec_info ;drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +11
-3@@ -98,6 +98,16 @@ static int xgpu_ai_poll_ack(struct amdgpu_device *adev)return -ETIME ; } +static void xgpu_ai_set_unrecov_err (struct amdgpu_device *adev) { +if (adev->virt.unrecov_err) +return ; + + adev->virt.unrecov_err = true; + + dev_err(adev->dev, "VF is in an unrecoverable state. Runtime Services +are halted.\n"); } +static int xgpu_ai_poll_msg (struct amdgpu_device *adev,enum idh_event event) { int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT; @@ -345,7 +355,6 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,struct amdgpu_iv_entry *entry) {enum idh_event event =xgpu_ai_mailbox_peek_msg (adev); -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev);switch (event) {case IDH_RAS_BAD_PAGES_READY :@@ -360,8 +369,8 @@ static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev, break;case IDH_UNRECOV_ERR_NOTIFICATION :xgpu_ai_mailbox_send_ack (adev); - ras->is_rma = true; - dev_err(adev->dev, "VF is in an unrecoverable state. Runtime Services are halted.\n"); + xgpu_ai_set_unrecov_err(adev); +if (amdgpu_sriov_runtime (adev))WARN_ONCE(!amdgpu_reset_domain_schedule(adev-
Quoted 1 line
reset_domain,&adev->virt.flr_work),drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +10
-1@@ -103,11 +103,20 @@ static int xgpu_nv_poll_ack(struct amdgpu_device *adev)return -ETIME ; } +static void xgpu_nv_set_unrecov_err (struct amdgpu_device *adev) { +if (adev->virt.unrecov_err) +return ; + + adev->virt.unrecov_err = true; + + dev_err(adev->dev, "VF is in an unrecoverable state. Runtime Services +are halted.\n"); } +static int xgpu_nv_poll_msg (struct amdgpu_device *adev,enum idh_event event) {int r;uint64_t timeout, now; -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev); now = (uint64_t )ktime_to_ms (ktime_get ()); timeout = now + NV_MAILBOX_POLL_MSG_TIMEDOUT; @@ -119,11 +128,7 @@ static int xgpu_nv_poll_msg(struct amdgpu_device *adev, enumidh_event event)event,
NV_MAILBOX_POLL_MSG_TIMEDOUT - timeout + now); return 0; } else if (r == -ENODEV) {drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +1
-6-if (!amdgpu_ras_is_rma (adev)) { - ras->is_rma = true; -dev_err (adev->dev,"VF is in an unrecoverable state. " -"Runtime Services are halted.\n" ); - } +xgpu_nv_set_unrecov_err (adev);return r; }@@ -453,7 +458,6 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev, struct amdgpu_iv_entry *entry) {enum idh_event event =xgpu_nv_mailbox_peek_msg (adev); -struct amdgpu_ras *ras =amdgpu_ras_get_context (adev);switch (event) {case
IDH_RAS_BAD_PAGES_READY:drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c +1
-4@@ -468,10 +472,7 @@ static int xgpu_nv_mailbox_rcv_irq(struct amdgpu_device *adev, break;case IDH_UNRECOV_ERR_NOTIFICATION :xgpu_nv_mailbox_send_ack (adev); -if (!amdgpu_ras_is_rma (adev)) { - ras->is_rma = true; - dev_err(adev->dev, "VF is in an unrecoverable state. Runtime Services are halted.\n"); - } + xgpu_nv_set_unrecov_err(adev);if (
amdgpu_sriov_runtime(adev))
WARN_ONCE(!amdgpu_reset_domain_schedule(adev-Quoted 1 line
reset_domain,--
2.43.0