Skip to contentSkip to conversation

drm/amdgpu: initialize VF2PF work before it can be cancelled

PATCH Superseded Chenglei Xie 2 participants 20 messages Oct 22 – Nov 5

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

PATCH 1/2 drm/amdgpu: initialize VF2PF work before it can be cancelled

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Initialize the work in the early init branch of amdgpu_virt_init_data_exchange(), before the interval is ever written. The cancel is then safe on every failure path.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +9 -0
index 4b1b42fee6b4..c1843c3d2692 100644
@@ -842,6 +842,15 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
 		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
 	} else if (adev->bios != NULL) {
 		/* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/
+
+		/*
+		 * Initialize the work before amdgpu_virt_read_pf2vf_data() sets
+		 * vf2pf_update_interval_ms below, so a teardown after a failed
+		 * init can cancel the work safely.
+		 */
+		INIT_DELAYED_WORK(&adev->virt.vf2pf_work,
+				  amdgpu_virt_update_vf2pf_work_item);
+
 		if (adev->virt.req_init_data_ver == GPU_CRIT_REGION_V2) {
 			pfvf_data =
 				kzalloc(adev->virt.crit_regn_tbl[AMD_SRIOV_MSG_DATAEXCHANGE_TABLE_ID].size_kb << 10,
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu: abort SPM VF init when the HBM aperture is missing

An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR. Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     | 11 ++++-
 2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +34 -13
index 5069042b5279..10002b78c69d 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = amdgpu_virt_init_critical_region(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 	}
 
 	switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		adev->family = AMDGPU_FAMILY_SI;
 		r = si_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = cik_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 	case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = vi_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 	default:
 		r = amdgpu_discovery_set_ip_blocks(adev);
 		if (r) {
 			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
 		}
 		break;
 	}
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
 	    !amdgpu_device_get_rev_id(adev)) {
 		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
 	}
 
 	if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
 			r = amdgpu_device_parse_gpu_info_fw(adev);
 			if (r)
-				return r;
+				goto err_release_full_gpu;
 
 			bios_flags = amdgpu_device_get_vbios_flags(adev);
 			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 			if (!skip_bios) {
 				bool optional =
 					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
 				if (optional && !adev->bios)
 					dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 							adev,
 							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
 							0, 0);
-						return r;
+						goto err_release_full_gpu;
 					}
 				}
 			}
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		}
 	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
 	/* Request full GPU access only for the remaining SR-IOV init work. */
 	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
 		r = amdgpu_virt_request_full_gpu(adev, true);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 	}
 
 	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	amdgpu_smu_early_init(adev);
 
 	return 0;
+
+err_release_full_gpu:
+	/*
+	 * Release the exclusive access acquired above so the host completes the
+	 * handshake instead of timing out and FLR'ing the VF.
+	 */
+	if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
+		amdgpu_virt_release_full_gpu(adev, true);
+
+	/* Don't send request since VF is inactive. */
+	if (amdgpu_sriov_vf(adev)) {
+		adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+		adev->virt.ops = NULL;
+	}
+
+	return r;
 }
 
 static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +9 -2
index cd276a138e10..5c6a20e42000 100644
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
 		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
 							&aper_size);
-		if (r)
-			return r;
+		if (r) {
+			/*
+			 * An SPM VF has no FB BAR0; without the HBM aperture
+			 * from the SRAT this GPU cannot init, so fail its probe.
+			 */
+			dev_err(adev->dev,
+				"SPM VF: no HBM aperture in SRAT (%d)\n", r);
+			return -ENODEV;
+		}
 
 		adev->gmc.aper_base = aper_base;
 		adev->gmc.aper_size = aper_size;
Signature · 1 line
2.34.1
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

AMD General

Hi @Lazar, Lijo<mailto:[email protected]>,

Ping on this one too. Could you please take a look when you have a moment?

Thanks,
Chenglei

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Thursday, October 22, 2026 11:32 AM
To: [email protected]
Cc: Xie, Chenglei <[email protected]>; Luo, Zhigang <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR.

Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 11 ++++-

2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0

index 5069042b5279..10002b78c69d 100644

--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                             r = amdgpu_virt_init_critical_region(adev);

                            if (r)

- return r;

+ goto err_release_full_gpu;

             }

              switch (adev->asic_type) {

@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                            adev->family = AMDGPU_FAMILY_SI;

                            r = si_set_ip_blocks(adev);

                            if (r)

- return r;

+ goto err_release_full_gpu;

                            break;

#endif

#ifdef CONFIG_DRM_AMDGPU_CIK

@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                             r = cik_set_ip_blocks(adev);

                            if (r)

- return r;

+ goto err_release_full_gpu;

                            break;

#endif

case CHIP_TOPAZ:

@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                             r = vi_set_ip_blocks(adev);

                            if (r)

- return r;

+ goto err_release_full_gpu;

                            break;

             default:

                            r = amdgpu_discovery_set_ip_blocks(adev);

                            if (r) {

                                          adev->num_ip_blocks = 0;

- return r;

+ goto err_release_full_gpu;

                            }

                            break;

             }

@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

             if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&

                 !amdgpu_device_get_rev_id(adev)) {

                            dev_err(adev->dev, "Unsupported A0 hardware\n");

- return -ENODEV; /* device unsupported - no device error */

+ r = -ENODEV; /* device unsupported - no device error */

+ goto err_release_full_gpu;

             }

              if (amdgpu_has_atpx() &&

@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                            if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {

                                          r = amdgpu_device_parse_gpu_info_fw(adev);

                                          if (r)

- return r;

+ goto err_release_full_gpu;

                                           bios_flags = amdgpu_device_get_vbios_flags(adev);

                                          skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP); @@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                                          if (!skip_bios) {

                                                         bool optional =

                                                                       !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);

- if (!amdgpu_get_bios(adev) && !optional)

- return -EINVAL;

+ if (!amdgpu_get_bios(adev) && !optional) {

+ r = -EINVAL;

+ goto err_release_full_gpu;

+ }

                                                          if (optional && !adev->bios)

                                                                       dev_info(

@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                                                                                                    adev,

                                                                                                   AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,

                                                                                                    0, 0);

- return r;

+ goto err_release_full_gpu;

                                                                       }

                                                         }

                                          }

@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

                             }

             }

- if (!total)

- return -ENODEV;

+ if (!total) {

+ r = -ENODEV;

+ goto err_release_full_gpu;

+ }

              /* Request full GPU access only for the remaining SR-IOV init work. */

             if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {

                            r = amdgpu_virt_request_full_gpu(adev, true);

                            if (r)

- return r;

+ goto err_release_full_gpu;

             }

              if (adev->gmc.xgmi.supported)

@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

             amdgpu_smu_early_init(adev);

              return 0;

+

+err_release_full_gpu:

+ /*

+ * Release the exclusive access acquired above so the host completes the

+ * handshake instead of timing out and FLR'ing the VF.

+ */

+ if (amdgpu_sriov_vf(adev) && early_full_gpu_access)

+ amdgpu_virt_release_full_gpu(adev, true);

+

+ /* Don't send request since VF is inactive. */

+ if (amdgpu_sriov_vf(adev)) {

+ adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;

+ adev->virt.ops = NULL;

+ }

+

+ return r;

}

static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev) diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

index cd276a138e10..5c6a20e42000 100644

--- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c

@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)

r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,

&aper_size);

- if (r)

- return r;

+ if (r) {

+ /*

+ * An SPM VF has no FB BAR0; without the HBM aperture

+ * from the SRAT this GPU cannot init, so fail its probe.

+ */

+ dev_err(adev->dev,

+ "SPM VF: no HBM aperture in SRAT (%d)\n", r);

+ return -ENODEV;

+ }

                             adev->gmc.aper_base = aper_base;

                            adev->gmc.aper_size = aper_size;

--

2.34.1

#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

In reply to Chenglei Xie
Quoted 145 lines · Chenglei Xie

An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR. Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     | 11 ++++-
  2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -13
index 5069042b5279..10002b78c69d 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = amdgpu_virt_init_critical_region(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  	}
 
  	switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		adev->family = AMDGPU_FAMILY_SI;
  		r = si_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = cik_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  	case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = vi_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  	default:
  		r = amdgpu_discovery_set_ip_blocks(adev);
  		if (r) {
  			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
  		}
  		break;
  	}
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
  	    !amdgpu_device_get_rev_id(adev)) {
  		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
  	}
 
  	if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
  			r = amdgpu_device_parse_gpu_info_fw(adev);
  			if (r)
-				return r;
+				goto err_release_full_gpu;
 
  			bios_flags = amdgpu_device_get_vbios_flags(adev);
  			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  			if (!skip_bios) {
  				bool optional =
  					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
  				if (optional && !adev->bios)
  					dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  							adev,
  							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
  							0, 0);
-						return r;
+						goto err_release_full_gpu;
  					}
  				}
  			}
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		}
  	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
  	/* Request full GPU access only for the remaining SR-IOV init work. */
  	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
  		r = amdgpu_virt_request_full_gpu(adev, true);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  	}
 
  	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	amdgpu_smu_early_init(adev);
 
  	return 0;
+
+err_release_full_gpu:
+	/*
+	 * Release the exclusive access acquired above so the host completes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2205

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+	 * handshake instead of timing out and FLR'ing the VF.
+	 */
+	if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
+		amdgpu_virt_release_full_gpu(adev, true);
+
+	/* Don't send request since VF is inactive. */
+	if (amdgpu_sriov_vf(adev)) {
+		adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+		adev->virt.ops = NULL;
+	}

I think this is not the right place for this. These flags are not set inside this function.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+
+	return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
index cd276a138e10..5c6a20e42000 100644
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
  		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
  							&aper_size);
-		if (r)

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block) · line 678

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +9 -1
-			return r;
+		if (r) {
+			/*
+			 * An SPM VF has no FB BAR0; without the HBM aperture
+			 * from the SRAT this GPU cannot init, so fail its probe.
+			 */
+			dev_err(adev->dev,
+				"SPM VF: no HBM aperture in SRAT (%d)\n", r);
+			return -ENODEV;
+		}

amdgpu_acpi_find_gpu_memory_in_srat has error logging. The error code returned is -ENOENT when table is not found. So this change is not requred.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
  		adev->gmc.aper_base = aper_base;
  		adev->gmc.aper_size = aper_size;
#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

AMD General

Thanks Lijo, please review if my reply on the comments make sense.

Regards,
Chenglei

On 22-Oct-26 9:01 PM, Chenglei Xie wrote:
An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR. Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 11 ++++-

2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 5069042b5279..10002b78c69d 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev)

r = amdgpu_virt_init_critical_region(adev);
if (r)
- return r;
+ goto err_release_full_gpu;
}
switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) adev->family = AMDGPU_FAMILY_SI;
r = si_set_ip_blocks(adev);
if (r)
- return r;
+ goto err_release_full_gpu;
break;
#endif
#ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) r = cik_set_ip_blocks(adev);
if (r)
- return r;
+ goto err_release_full_gpu;
break;
#endif
case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) r = vi_set_ip_blocks(adev);
if (r)
- return r;
+ goto err_release_full_gpu;
break;
default:
r = amdgpu_discovery_set_ip_blocks(adev);
if (r) {
adev->num_ip_blocks = 0;
- return r;
+ goto err_release_full_gpu;
}
break;
}
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) && !amdgpu_device_get_rev_id(adev)) {
dev_err(adev->dev, "Unsupported A0 hardware
");
- return -ENODEV; /* device unsupported - no device error /
+ r = -ENODEV; /* device unsupported - no device error /
+ goto err_release_full_gpu;
}
if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
r = amdgpu_device_parse_gpu_info_fw(adev);
if (r)
- return r;
+ goto err_release_full_gpu;
bios_flags = amdgpu_device_get_vbios_flags(adev);
skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) if (!skip_bios) {
bool optional =
!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
- if (!amdgpu_get_bios(adev) && !optional)
- return -EINVAL;
+ if (!amdgpu_get_bios(adev) && !optional) {
+ r = -EINVAL;
+ goto err_release_full_gpu;
+ }
if (optional && !adev->bios)
dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) adev,
AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
0, 0);
- return r;
+ goto err_release_full_gpu;
}
}
}
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) }
}
- if (!total)
- return -ENODEV;
+ if (!total) {
+ r = -ENODEV;
+ goto err_release_full_gpu;
+ }
/* Request full GPU access only for the remaining SR-IOV init work. /
if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
r = amdgpu_virt_request_full_gpu(adev, true);
if (r)
- return r;
+ goto err_release_full_gpu;
}
if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device adev) amdgpu_smu_early_init(adev);
return 0;
+
+err_release_full_gpu:
+ /*
+ * Release the exclusive access acquired above so the host completes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /* Don't send request since VF is inactive. /
+ if (amdgpu_sriov_vf(adev)) {
+ adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+ adev->virt.ops = NULL;
+ }
I think this is not the right place for this. These flags are not set inside this function.

Chenglei:
Agree. I'll move the release + deactivate into a helper in amdgpu_virt.c and just call that helper instead. As this is needed to avoid REQ_GPU_FINI timeout post release.
+
+ return r;
}
static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device adev)

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index cd276a138e10..5c6a20e42000 100644
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block ip_block)

r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base, &aper_size);
- if (r)
- return r;
+ if (r) {
+ /*
+ * An SPM VF has no FB BAR0; without the HBM aperture
+ * from the SRAT this GPU cannot init, so fail its probe.
+ /
+ dev_err(adev->dev,
+ "SPM VF: no HBM aperture in SRAT (%d)
", r);
+ return -ENODEV;
+ }
amdgpu_acpi_find_gpu_memory_in_srat has error logging. The error code returned is -ENOENT when table is not found. So this change is not requred. Thanks,
Lijo

Chenglei:
I will drop the redundant error log. But I would like to keep the -ENOENT to -ENODEV change. The early_init loop treats -ENOENT as the IP block being absent and sets status.valid to false, so the -ENOENT makes the init continue without GMC and only fail later with -ENOMEM. -ENODEV sets total to false, so it aborts at the real failure point. Let me know if you would still prefer to drop this part.
adev->gmc.aper_base = aper_base;
adev->gmc.aper_size = aper_size;

________________________________
From: Lazar, Lijo <[email protected]>
Sent: Thursday, October 29, 2026 12:43 AM
To: Xie, Chenglei <[email protected]>; [email protected] <[email protected]>
Cc: Luo, Zhigang <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 145 lines · Chenglei Xie

An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR. Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     | 11 ++++-
  2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -13
index 5069042b5279..10002b78c69d 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = amdgpu_virt_init_critical_region(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               adev->family = AMDGPU_FAMILY_SI;
               r = si_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = cik_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
       case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = vi_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
       default:
               r = amdgpu_discovery_set_ip_blocks(adev);
               if (r) {
                       adev->num_ip_blocks = 0;
-                     return r;
+                     goto err_release_full_gpu;
               }
               break;
       }
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
           !amdgpu_device_get_rev_id(adev)) {
               dev_err(adev->dev, "Unsupported A0 hardware\n");
-             return -ENODEV; /* device unsupported - no device error */
+             r = -ENODEV;    /* device unsupported - no device error */
+             goto err_release_full_gpu;
       }
 
       if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                       r = amdgpu_device_parse_gpu_info_fw(adev);
                       if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                       bios_flags = amdgpu_device_get_vbios_flags(adev);
                       skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                       if (!skip_bios) {
                               bool optional =
                                       !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-                             if (!amdgpu_get_bios(adev) && !optional)
-                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) {
+                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }
 
                               if (optional && !adev->bios)
                                       dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                       adev,
                                                       AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                       0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                       }
                               }
                       }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               }
       }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
       /* Request full GPU access only for the remaining SR-IOV init work. */
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       amdgpu_smu_early_init(adev);
 
       return 0;
+
+err_release_full_gpu:
+     /*
+      * Release the exclusive access acquired above so the host completes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2205

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+      * handshake instead of timing out and FLR'ing the VF.
+      */
+     if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
+             amdgpu_virt_release_full_gpu(adev, true);
+
+     /* Don't send request since VF is inactive. */
+     if (amdgpu_sriov_vf(adev)) {
+             adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+             adev->virt.ops = NULL;
+     }

I think this is not the right place for this. These flags are not set inside this function.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+
+     return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
index cd276a138e10..5c6a20e42000 100644
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
               r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                       &aper_size);
-             if (r)

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block) · line 678

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +9 -1
-                     return r;
+             if (r) {
+                     /*
+                      * An SPM VF has no FB BAR0; without the HBM aperture
+                      * from the SRAT this GPU cannot init, so fail its probe.
+                      */
+                     dev_err(adev->dev,
+                             "SPM VF: no HBM aperture in SRAT (%d)\n", r);
+                     return -ENODEV;
+             }

amdgpu_acpi_find_gpu_memory_in_srat has error logging. The error code returned is -ENOENT when table is not found. So this change is not requred.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
               adev->gmc.aper_base = aper_base;
               adev->gmc.aper_size = aper_size;
#5 lore raw

Re: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 171 lines · Chenglei

AMD General

Thanks Lijo, please review if my reply on the comments make sense.

Regards,
Chenglei

On 22-Oct-26 9:01 PM, Chenglei Xie wrote:

    An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init()
    resolves the VF HBM aperture from the SRAT. When that lookup fails the
    code returned -ENOENT, which the early init loop treats as the GMC block
    being absent. The probe then keeps going without a memory controller and
    only dies much later with -ENOMEM, far from the real cause.

    Return -ENODEV instead so the early init loop aborts this GPU probe
    at the
    point it actually failed. Other GPUs probe independently and are not
    affected.

    Aborting here also exposes a second problem. On a legacy host the VF
    takes
    exclusive GPU access at the start of early init, and every error path
    returned directly without giving it back. The host then waited for a
    release that never came, timed out, and recovered the VF with an FLR.
    Route the post-acquisition failures through a common
    err_release_full_gpu
    label that releases full GPU access before returning.

    early init also fails before the CP scheduler is programmed, so the host
    treats the VF as not active once it sees the release. Clear
    AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label
    so the
    later fini path does not send a REQ_GPU_FINI that the host will never
    answer.

    Signed-off-by: Chenglei Xie <[email protected]>
    ---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------
    drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 11 ++++-
    2 files changed, 43 insertions(+), 15 deletions(-)

    diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/
    gpu/drm/amd/amdgpu/amdgpu_device.c
    index 5069042b5279..10002b78c69d 100644
    --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
    +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
    @@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    r = amdgpu_virt_init_critical_region(adev);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    }
    switch (adev->asic_type) {
    @@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    adev->family = AMDGPU_FAMILY_SI;
    r = si_set_ip_blocks(adev);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    break;
    #endif
    #ifdef CONFIG_DRM_AMDGPU_CIK
    @@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    r = cik_set_ip_blocks(adev);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    break;
    #endif
    case CHIP_TOPAZ:
    @@ -2047,13 +2047,13 @@ static int
    amdgpu_device_ip_early_init(struct amdgpu_device adev)
    r = vi_set_ip_blocks(adev);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    break;
    default:
    r = amdgpu_discovery_set_ip_blocks(adev);
    if (r) {
    adev->num_ip_blocks = 0;
    - return r;
    + goto err_release_full_gpu;
    }
    break;
    }
    @@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
    !amdgpu_device_get_rev_id(adev)) {
    dev_err(adev->dev, "Unsupported A0 hardware
    ");
    - return -ENODEV; /* device unsupported - no device error /
    + r = -ENODEV; /* device unsupported - no device error /
    + goto err_release_full_gpu;
    }
    if (amdgpu_has_atpx() &&
    @@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
    r = amdgpu_device_parse_gpu_info_fw(adev);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    bios_flags = amdgpu_device_get_vbios_flags(adev);
    skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
    @@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    if (!skip_bios) {
    bool optional =
    !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
    - if (!amdgpu_get_bios(adev) && !optional)
    - return -EINVAL;
    + if (!amdgpu_get_bios(adev) && !optional) {
    + r = -EINVAL;
    + goto err_release_full_gpu;
    + }
    if (optional && !adev->bios)
    dev_info(
    @@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    adev,
    AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
    0, 0);
    - return r;
    + goto err_release_full_gpu;
    }
    }
    }
    @@ -2159,14 +2162,16 @@ static int
    amdgpu_device_ip_early_init(struct amdgpu_device adev)
    }
    }
    - if (!total)
    - return -ENODEV;
    + if (!total) {
    + r = -ENODEV;
    + goto err_release_full_gpu;
    + }
    /* Request full GPU access only for the remaining SR-IOV init work. /
    if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
    r = amdgpu_virt_request_full_gpu(adev, true);
    if (r)
    - return r;
    + goto err_release_full_gpu;
    }
    if (adev->gmc.xgmi.supported)
    @@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct
    amdgpu_device adev)
    amdgpu_smu_early_init(adev);
    return 0;
    +
    +err_release_full_gpu:
    + /*
    + * Release the exclusive access acquired above so the host
    completes the
    + * handshake instead of timing out and FLR'ing the VF.
    + /
    + if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
    + amdgpu_virt_release_full_gpu(adev, true);
    +
    + /* Don't send request since VF is inactive. /
    + if (amdgpu_sriov_vf(adev)) {
    + adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
    + adev->virt.ops = NULL;
    + }
Quoted 7 lines

I think this is not the right place for this. These flags are not set inside this function.

Chenglei:
Agree. I'll move the release + deactivate into a helper in amdgpu_virt.c and just call that helper instead. As this is needed to avoid REQ_GPU_FINI timeout post release.

Yes, that works.

Quoted 31 lines

+
+ return r;
}
static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device adev) diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c b/drivers/gpu/ drm/amd/amdgpu/gmc_v12_0.c
index cd276a138e10..5c6a20e42000 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block ip_block)
r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base, &aper_size);
- if (r)
- return r;
+ if (r) {
+ /*
+ * An SPM VF has no FB BAR0; without the HBM aperture
+ * from the SRAT this GPU cannot init, so fail its probe.
+ /
+ dev_err(adev->dev,
+ "SPM VF: no HBM aperture in SRAT (%d)
", r);
+ return -ENODEV;
+ }

amdgpu_acpi_find_gpu_memory_in_srat has error logging. The error code returned is -ENOENT when table is not found. So this change is not requred. Thanks,
Lijo

Quoted 4 lines

Chenglei:
I will drop the redundant error log. But I would like to keep the - ENOENT to -ENODEV change. The early_init loop treats -ENOENT as the IP block being absent and sets status.valid to false, so the -ENOENT makes the init continue without GMC and only fail later with -ENOMEM.

Thanks, I see that now.

gmc is one critical block. I think we should later decide not to proceed if any critical ip block fails.

Thanks,
Lijo

Quoted 211 lines

-ENODEV sets total to false, so it aborts at the real failure point. Let me know if you would still prefer
to drop this part.

    adev->gmc.aper_base = aper_base;
    adev->gmc.aper_size = aper_size;

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Thursday, October 29, 2026 12:43 AM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Luo, Zhigang <[email protected]>
*Subject:* Re: [PATCH 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 145 lines · Chenglei Xie

An SPM-backed SR-IOV VF has no usable FB BAR, so gmc_v12_0_early_init() resolves the VF HBM aperture from the SRAT. When that lookup fails the code returned -ENOENT, which the early init loop treats as the GMC block being absent. The probe then keeps going without a memory controller and only dies much later with -ENOMEM, far from the real cause.

Return -ENODEV instead so the early init loop aborts this GPU probe at the point it actually failed. Other GPUs probe independently and are not affected.

Aborting here also exposes a second problem. On a legacy host the VF takes exclusive GPU access at the start of early init, and every error path returned directly without giving it back. The host then waited for a release that never came, timed out, and recovered the VF with an FLR. Route the post-acquisition failures through a common err_release_full_gpu label that releases full GPU access before returning.

early init also fails before the CP scheduler is programmed, so the host treats the VF as not active once it sees the release. Clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops at the same label so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 47 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     | 11 ++++-

   2 files changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
index 5069042b5279..10002b78c69d 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = amdgpu_virt_init_critical_region(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 adev->family = AMDGPU_FAMILY_SI;
                 r = si_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif
    #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = cik_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif

        case CHIP_TOPAZ:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = vi_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;

        default:
                r = amdgpu_discovery_set_ip_blocks(adev); if (r) {
                        adev->num_ip_blocks = 0; -                     return r;
+                     goto err_release_full_gpu; }
                break;
        }

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

        if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) && !amdgpu_device_get_rev_id(adev)) { dev_err(adev->dev, "Unsupported A0 hardware\n"); -             return -ENODEV; /* device unsupported - no device error */ +             r = -ENODEV;    /* device unsupported - no device error */ +             goto err_release_full_gpu;
        }

        if (amdgpu_has_atpx() &&

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                         r = amdgpu_device_parse_gpu_info_fw(adev);
                         if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                         bios_flags = amdgpu_device_get_vbios_flags(adev);
                         skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                         if (!skip_bios) {

                                bool optional =
                                        !!(bios_flags & AMDGPU_VBIOS_OPTIONAL); -                             if (!amdgpu_get_bios(adev) && !optional) -                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) { +                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }

                                if (optional && !adev->bios) dev_info(

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -4
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                         adev,
                                                         AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                         0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                         }
                                 }
                         }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 }
         }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
         /* Request full GPU access only for the remaining SR-IOV init work. */
         if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
                 r = amdgpu_virt_request_full_gpu(adev, true);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,22 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
         amdgpu_smu_early_init(adev);
 
         return 0;
+
+err_release_full_gpu:
+     /*
+      * Release the exclusive access acquired above so the host completes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2205

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+      * handshake instead of timing out and FLR'ing the VF.
+      */
+     if (amdgpu_sriov_vf(adev) && early_full_gpu_access)
+             amdgpu_virt_release_full_gpu(adev, true);
+
+     /* Don't send request since VF is inactive. */
+     if (amdgpu_sriov_vf(adev)) {
+             adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+             adev->virt.ops = NULL;
+     }

I think this is not the right place for this. These flags are not set inside this function.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
+
+     return r;
    }
 
    static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -1
index cd276a138e10..5c6a20e42000 100644
@@ -667,8 +667,15 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
                 r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                         &aper_size);
-             if (r)

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block) · line 678

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +9 -1
-                     return r;
+             if (r) {
+                     /*
+                      * An SPM VF has no FB BAR0; without the HBM aperture
+                      * from the SRAT this GPU cannot init, so fail its probe.
+                      */
+                     dev_err(adev->dev,
+                             "SPM VF: no HBM aperture in SRAT (%d)\n", r);
+                     return -ENODEV;
+             }

amdgpu_acpi_find_gpu_memory_in_srat has error logging. The error code returned is -ENOENT when table is not found. So this change is not requred.

Thanks,
Lijo

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
                 adev->gmc.aper_base = aper_base;
                 adev->gmc.aper_size = aper_size;
#6 lore raw
In reply to Chenglei Xie

AMD General

Hi @Lazar, Lijo<mailto:[email protected]>,

Could you help review this 2 patch SRIOV VF changes when you get a chance? It's been on amd-gfx for a few days.

Thanks,
Chenglei.

-----Original Message-----
From: Xie, Chenglei <[email protected]>
Sent: Thursday, October 22, 2026 11:32 AM
To: [email protected]
Cc: Xie, Chenglei <[email protected]>; Luo, Zhigang <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: initialize VF2PF work before it can be cancelled

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But

amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Initialize the work in the early init branch of amdgpu_virt_init_data_exchange(), before the interval is ever written. The cancel is then safe on every failure path.

---

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 9 +++++++++

1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0

index 4b1b42fee6b4..c1843c3d2692 100644

--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

@@ -842,6 +842,15 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)

                            schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));

             } else if (adev->bios != NULL) {

                            /* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/

+

+ /*

+ * Initialize the work before amdgpu_virt_read_pf2vf_data() sets

+ * vf2pf_update_interval_ms below, so a teardown after a failed

+ * init can cancel the work safely.

+ */

+ INIT_DELAYED_WORK(&adev->virt.vf2pf_work,

+ amdgpu_virt_update_vf2pf_work_item);

+

                            if (adev->virt.req_init_data_ver == GPU_CRIT_REGION_V2) {

                                          pfvf_data =

                                          kzalloc(adev->virt.crit_regn_tbl[AMD_SRIOV_MSG_DATAEXCHANGE_TABLE_ID].size_kb << 10,

--

2.34.1

#7 lore raw
In reply to Chenglei Xie
Quoted 23 lines · Chenglei Xie

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Initialize the work in the early init branch of amdgpu_virt_init_data_exchange(), before the interval is ever written. The cancel is then safe on every failure path.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index 4b1b42fee6b4..c1843c3d2692 100644
@@ -842,6 +842,15 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
  		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) · line 852

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +8 -0
  	} else if (adev->bios != NULL) {
  		/* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/
+
+		/*
+		 * Initialize the work before amdgpu_virt_read_pf2vf_data() sets
+		 * vf2pf_update_interval_ms below, so a teardown after a failed
+		 * init can cancel the work safely.
+		 */
+		INIT_DELAYED_WORK(&adev->virt.vf2pf_work,
+				  amdgpu_virt_update_vf2pf_work_item);

+ Victor

You may move this to amdgpu_virt_init(). Victor refactored virt init sequence recently.

Victor, could you check?

Thanks,
Lijo

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -0
+
  		if (adev->virt.req_init_data_ver == GPU_CRIT_REGION_V2) {
  			pfvf_data =
  				kzalloc(adev->virt.crit_regn_tbl[AMD_SRIOV_MSG_DATAEXCHANGE_TABLE_ID].size_kb << 10,
#8 lore raw

PATCH v2 1/2 drm/amdgpu: initialize VF2PF work before it can be cancelled

In reply to Chenglei Xie

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Initialize the work once in amdgpu_virt_init(), which runs before early init fills in the interval, so the cancel is safe on every failure path.

---
v2: Initialize the work in amdgpu_virt_init() instead of
amdgpu_virt_init_data_exchange(), per review.

 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -2
index 4b1b42fee6b4..576a818db522 100644
@@ -838,7 +838,6 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
 		/* go through this logic in ip_init and reset to init workqueue*/
 		amdgpu_virt_exchange_data(adev);
 
-		INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item);
 		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
 	} else if (adev->bios != NULL) {
 		/* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/
@@ -1249,8 +1248,17 @@ void amdgpu_virt_init(struct amdgpu_device *adev)
 
 	is_sriov = amdgpu_virt_init_req_data(adev, reg);
 
-	if (is_sriov)
+	if (is_sriov) {
 		amdgpu_virt_init_ras(adev);
+
+		/*
+		 * Initialize the vf2pf work here, before early init writes
+		 * vf2pf_update_interval_ms, so a teardown after a failed init
+		 * can cancel the work safely.
+		 */
+		INIT_DELAYED_WORK(&adev->virt.vf2pf_work,
+				  amdgpu_virt_update_vf2pf_work_item);
+	}
 }
 
 static bool amdgpu_virt_access_debugfs_is_mmio(struct amdgpu_device *adev)
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 2/2 drm/amdgpu: abort SPM VF init when the HBM aperture is missing

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-
 4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +36 -13
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = amdgpu_virt_init_critical_region(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 	}
 
 	switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		adev->family = AMDGPU_FAMILY_SI;
 		r = si_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = cik_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 	case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = vi_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 	default:
 		r = amdgpu_discovery_set_ip_blocks(adev);
 		if (r) {
 			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
 		}
 		break;
 	}
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
 	    !amdgpu_device_get_rev_id(adev)) {
 		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
 	}
 
 	if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
 			r = amdgpu_device_parse_gpu_info_fw(adev);
 			if (r)
-				return r;
+				goto err_release_full_gpu;
 
 			bios_flags = amdgpu_device_get_vbios_flags(adev);
 			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 			if (!skip_bios) {
 				bool optional =
 					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
 				if (optional && !adev->bios)
 					dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 							adev,
 							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
 							0, 0);
-						return r;
+						goto err_release_full_gpu;
 					}
 				}
 			}
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		}
 	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
 	/* Request full GPU access only for the remaining SR-IOV init work. */
 	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
 		r = amdgpu_virt_request_full_gpu(adev, true);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 	}
 
 	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	amdgpu_smu_early_init(adev);
 
 	return 0;
+
+err_release_full_gpu:
+	if (amdgpu_sriov_vf(adev)) {
+		/*
+		 * Release the access the host is waiting on so it finishes the
+		 * handshake instead of timing out and FLR'ing the VF.
+		 */
+		if (early_full_gpu_access)
+			amdgpu_virt_release_full_gpu(adev, true);
+
+		/*
+		 * Mark the VF inactive so the later fini path does not send a
+		 * request the host will never answer.
+		 */
+		amdgpu_virt_deactivate(adev);
+	}
+
+	return r;
 }
 
 static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
 	return 0;
 }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+	adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+	adev->virt.ops = NULL;
+}
+
 /**
  * amdgpu_virt_reset_gpu() - reset gpu
  * @adev:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
 void amdgpu_virt_init_setting(struct amdgpu_device *adev);
 int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
 int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
 int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
 void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
 int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
 		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
 							&aper_size);
+		/*
+		 * An SPM VF has no FB BAR0 and cannot init without the HBM
+		 * aperture from the SRAT. Abort this GPU probe instead of
+		 * limping on as if the GMC block were absent.
+		 */
 		if (r)
-			return r;
+			return -ENODEV;
 
 		adev->gmc.aper_base = aper_base;
 		adev->gmc.aper_size = aper_size;
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-
  4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23 -13
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = amdgpu_virt_init_critical_region(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  	}
 
  	switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		adev->family = AMDGPU_FAMILY_SI;
  		r = si_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = cik_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  	case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = vi_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  	default:
  		r = amdgpu_discovery_set_ip_blocks(adev);
  		if (r) {
  			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
  		}
  		break;
  	}
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
  	    !amdgpu_device_get_rev_id(adev)) {
  		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
  	}
 
  	if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
  			r = amdgpu_device_parse_gpu_info_fw(adev);
  			if (r)
-				return r;
+				goto err_release_full_gpu;
 
  			bios_flags = amdgpu_device_get_vbios_flags(adev);
  			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  			if (!skip_bios) {
  				bool optional =
  					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
  				if (optional && !adev->bios)
  					dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  							adev,
  							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
  							0, 0);
-						return r;
+						goto err_release_full_gpu;
  					}
  				}
  			}
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		}
  	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
  	/* Request full GPU access only for the remaining SR-IOV init work. */
  	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
  		r = amdgpu_virt_request_full_gpu(adev, true);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  	}
 
  	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	amdgpu_smu_early_init(adev);
 
  	return 0;
+
+err_release_full_gpu:
+	if (amdgpu_sriov_vf(adev)) {
+		/*
+		 * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+		 * handshake instead of timing out and FLR'ing the VF.
+		 */
+		if (early_full_gpu_access)
+			amdgpu_virt_release_full_gpu(adev, true);
+
+		/*
+		 * Mark the VF inactive so the later fini path does not send a
+		 * request the host will never answer.
+		 */
+		amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+	}
+
+	return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
  	return 0;
  }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+	adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+	adev->virt.ops = NULL;
+}
+
  /**
   * amdgpu_virt_reset_gpu() - reset gpu
   * @adev:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
  void amdgpu_virt_init_setting(struct amdgpu_device *adev);
  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
  void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
  int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
  		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
  							&aper_size);
+		/*
+		 * An SPM VF has no FB BAR0 and cannot init without the HBM
+		 * aperture from the SRAT. Abort this GPU probe instead of
+		 * limping on as if the GMC block were absent.
+		 */
  		if (r)
-			return r;
+			return -ENODEV;
 
  		adev->gmc.aper_base = aper_base;
  		adev->gmc.aper_size = aper_size;
#11 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

No, it should not be called. If amdgpu_virt_request_full_gpu fails,
the VF holds no access as the acquire handshake never completed.
There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear.
Jumping to err_release_full_gpu would send a release for access that is never granted.

Thanks,
Chenglei

________________________________
From: Lazar, Lijo <[email protected]>
Sent: Sunday, November 1, 2026 11:32 PM
To: Xie, Chenglei <[email protected]>; [email protected] <[email protected]>
Cc: Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
Subject: Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-
  4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23 -13
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = amdgpu_virt_init_critical_region(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               adev->family = AMDGPU_FAMILY_SI;
               r = si_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = cik_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
       case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = vi_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
       default:
               r = amdgpu_discovery_set_ip_blocks(adev);
               if (r) {
                       adev->num_ip_blocks = 0;
-                     return r;
+                     goto err_release_full_gpu;
               }
               break;
       }
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
           !amdgpu_device_get_rev_id(adev)) {
               dev_err(adev->dev, "Unsupported A0 hardware\n");
-             return -ENODEV; /* device unsupported - no device error */
+             r = -ENODEV;    /* device unsupported - no device error */
+             goto err_release_full_gpu;
       }
 
       if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                       r = amdgpu_device_parse_gpu_info_fw(adev);
                       if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                       bios_flags = amdgpu_device_get_vbios_flags(adev);
                       skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                       if (!skip_bios) {
                               bool optional =
                                       !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-                             if (!amdgpu_get_bios(adev) && !optional)
-                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) {
+                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }
 
                               if (optional && !adev->bios)
                                       dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                       adev,
                                                       AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                       0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                       }
                               }
                       }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               }
       }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
       /* Request full GPU access only for the remaining SR-IOV init work. */
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       amdgpu_smu_early_init(adev);
 
       return 0;
+
+err_release_full_gpu:
+     if (amdgpu_sriov_vf(adev)) {
+             /*
+              * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+              * handshake instead of timing out and FLR'ing the VF.
+              */
+             if (early_full_gpu_access)
+                     amdgpu_virt_release_full_gpu(adev, true);
+
+             /*
+              * Mark the VF inactive so the later fini path does not send a
+              * request the host will never answer.
+              */
+             amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+     }
+
+     return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
       return 0;
  }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+     adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+     adev->virt.ops = NULL;
+}
+
  /**
   * amdgpu_virt_reset_gpu() - reset gpu
   * @adev:   amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
  void amdgpu_virt_init_setting(struct amdgpu_device *adev);
  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
  void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
  int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
               r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                       &aper_size);
+             /*
+              * An SPM VF has no FB BAR0 and cannot init without the HBM
+              * aperture from the SRAT. Abort this GPU probe instead of
+              * limping on as if the GMC block were absent.
+              */
               if (r)
-                     return r;
+                     return -ENODEV;
 
               adev->gmc.aper_base = aper_base;
               adev->gmc.aper_size = aper_size;
#12 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 22 lines · Chenglei

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

Quoted 6 lines

No, it should not be called. If amdgpu_virt_request_full_gpu fails,
the VF holds no access as the acquire handshake never completed.
There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear.
Jumping to err_release_full_gpu would send a release for access that is never granted.

In that case, this code needs to be changed to just return immediately.

Review

Quoted 5 lines
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
(quoted diff) +1 -1
-                     return r;
+                     goto err_release_full_gpu;

Thanks,
Lijo

Quoted 238 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Sunday, November 1, 2026 11:32 PM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]> *Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 + drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-

   4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = amdgpu_virt_init_critical_region(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 adev->family = AMDGPU_FAMILY_SI;
                 r = si_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif
    #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = cik_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif

        case CHIP_TOPAZ:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = vi_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;

        default:
                r = amdgpu_discovery_set_ip_blocks(adev); if (r) {
                        adev->num_ip_blocks = 0; -                     return r;
+                     goto err_release_full_gpu; }
                break;
        }

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

        if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) && !amdgpu_device_get_rev_id(adev)) { dev_err(adev->dev, "Unsupported A0 hardware\n"); -             return -ENODEV; /* device unsupported - no device error */ +             r = -ENODEV;    /* device unsupported - no device error */ +             goto err_release_full_gpu;
        }

        if (amdgpu_has_atpx() &&

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                         r = amdgpu_device_parse_gpu_info_fw(adev);
                         if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                         bios_flags = amdgpu_device_get_vbios_flags(adev);
                         skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                         if (!skip_bios) {

                                bool optional =
                                        !!(bios_flags & AMDGPU_VBIOS_OPTIONAL); -                             if (!amdgpu_get_bios(adev) && !optional) -                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) { +                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }

                                if (optional && !adev->bios) dev_info(

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -4
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                         adev,
                                                         AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                         0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                         }
                                 }
                         }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 }
         }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
         /* Request full GPU access only for the remaining SR-IOV init work. */
         if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
                 r = amdgpu_virt_request_full_gpu(adev, true);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
         amdgpu_smu_early_init(adev);
 
         return 0;
+
+err_release_full_gpu:
+     if (amdgpu_sriov_vf(adev)) {
+             /*
+              * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+              * handshake instead of timing out and FLR'ing the VF.
+              */
+             if (early_full_gpu_access)
+                     amdgpu_virt_release_full_gpu(adev, true);
+
+             /*
+              * Mark the VF inactive so the later fini path does not send a
+              * request the host will never answer.
+              */
+             amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+     }
+
+     return r;
    }
 
    static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
         return 0;
    }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+     adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+     adev->virt.ops = NULL;
+}
+
    /**
     * amdgpu_virt_reset_gpu() - reset gpu
     * @adev:   amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
    void amdgpu_virt_init_setting(struct amdgpu_device *adev);
    int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
    int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
    int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
    void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
    int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
                 r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                         &aper_size);
+             /*
+              * An SPM VF has no FB BAR0 and cannot init without the HBM
+              * aperture from the SRAT. Abort this GPU probe instead of
+              * limping on as if the GMC block were absent.
+              */
                 if (r)
-                     return r;
+                     return -ENODEV;
 
                 adev->gmc.aper_base = aper_base;
                 adev->gmc.aper_size = aper_size;
#13 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

AMD General

On 02-Nov-26 11:11 PM, Xie, Chenglei wrote:
AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

No, it should not be called. If amdgpu_virt_request_full_gpu fails, the VF holds no access as the acquire handshake never completed. There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear. Jumping to err_release_full_gpu would send a release for access that is never granted.

Quoted 9 lines

In that case, this code needs to be changed to just return immediately. if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
r = amdgpu_virt_request_full_gpu(adev, true);
if (r)
- return r;
+ goto err_release_full_gpu;

Thanks,
Lijo

No, the goto is needed here because we need the amdgpu_virt_deactivate()
to prevent REQ_GPU_FINI to be sent inside amdgpu_device_fini_hw(). In amdgpu_driver_unload_kms(), void amdgpu_driver_unload_kms(struct drm_device dev)
{
struct amdgpu_device adev = drm_to_adev(dev);
if (adev == NULL || !adev->num_ip_blocks)
return;
amdgpu_unregister_gpu_instance(adev);
i f (adev->rmmio == NULL)
return;
if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_UNLOAD))
drm_warn(dev, "smart shift update failed
");
amdgpu_acpi_fini(adev);
amdgpu_device_fini_hw(adev);
}
it checks if adev->num_ip_blocks is non-zero to proceed with the device_fini.
In the early full access case, it runs before IP discovery while num_ip_blocks is still 0. So the amdgpu_driver_unload_kms() returns before the fini. But here it already passed the ip discovery set, so the num_ip_blocks>0 and fini will be executed.
Also, release_full_gpu is correctly skipped since early_full_gpu_access is false in this case.

Thanks,
Chenglei

________________________________
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, November 3, 2026 1:35 AM
To: Xie, Chenglei <[email protected]>; [email protected] <[email protected]>
Cc: Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
Subject: Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 22 lines · Chenglei

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

Quoted 7 lines

No, it should not be called. If amdgpu_virt_request_full_gpu fails, the VF holds no access as the acquire handshake never completed. There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear. Jumping to err_release_full_gpu would send a release for access that is never granted.

In that case, this code needs to be changed to just return immediately.

Review

Quoted 5 lines
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
(quoted diff) +1 -1
-                     return r;
+                     goto err_release_full_gpu;

Thanks,
Lijo

Quoted 241 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Sunday, November 1, 2026 11:32 PM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
*Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-
  4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23 -13
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = amdgpu_virt_init_critical_region(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               adev->family = AMDGPU_FAMILY_SI;
               r = si_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = cik_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
       case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = vi_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
       default:
               r = amdgpu_discovery_set_ip_blocks(adev);
               if (r) {
                       adev->num_ip_blocks = 0;
-                     return r;
+                     goto err_release_full_gpu;
               }
               break;
       }
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
           !amdgpu_device_get_rev_id(adev)) {
               dev_err(adev->dev, "Unsupported A0 hardware\n");
-             return -ENODEV; /* device unsupported - no device error */
+             r = -ENODEV;    /* device unsupported - no device error */
+             goto err_release_full_gpu;
       }
 
       if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                       r = amdgpu_device_parse_gpu_info_fw(adev);
                       if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                       bios_flags = amdgpu_device_get_vbios_flags(adev);
                       skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                       if (!skip_bios) {
                               bool optional =
                                       !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-                             if (!amdgpu_get_bios(adev) && !optional)
-                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) {
+                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }
 
                               if (optional && !adev->bios)
                                       dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                       adev,
                                                       AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                       0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                       }
                               }
                       }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               }
       }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
       /* Request full GPU access only for the remaining SR-IOV init work. */
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       amdgpu_smu_early_init(adev);
 
       return 0;
+
+err_release_full_gpu:
+     if (amdgpu_sriov_vf(adev)) {
+             /*
+              * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+              * handshake instead of timing out and FLR'ing the VF.
+              */
+             if (early_full_gpu_access)
+                     amdgpu_virt_release_full_gpu(adev, true);
+
+             /*
+              * Mark the VF inactive so the later fini path does not send a
+              * request the host will never answer.
+              */
+             amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+     }
+
+     return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
       return 0;
  }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+     adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+     adev->virt.ops = NULL;
+}
+
  /**
   * amdgpu_virt_reset_gpu() - reset gpu
   * @adev:   amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
  void amdgpu_virt_init_setting(struct amdgpu_device *adev);
  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
  void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
  int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
               r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                       &aper_size);
+             /*
+              * An SPM VF has no FB BAR0 and cannot init without the HBM
+              * aperture from the SRAT. Abort this GPU probe instead of
+              * limping on as if the GMC block were absent.
+              */
               if (r)
-                     return r;
+                     return -ENODEV;
 
               adev->gmc.aper_base = aper_base;
               adev->gmc.aper_size = aper_size;
#14 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 61 lines · Chenglei

AMD General

On 02-Nov-26 11:11 PM, Xie, Chenglei wrote:

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

>Shouldn't this be called when amdgpu_virt_request_full_gpu fails for >early_full_gpu_access case also?
>Thanks,
>Lijo

No, it should not be called. If amdgpu_virt_request_full_gpu fails, the VF holds no access as the acquire handshake never completed. There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear. Jumping to err_release_full_gpu would send a release for access that is never granted.

Quoted 9 lines

In that case, this code needs to be changed to just return immediately. if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
r = amdgpu_virt_request_full_gpu(adev, true);
if (r)
- return r;
+ goto err_release_full_gpu;

Thanks,
Lijo

No, the goto is needed here because we need the amdgpu_virt_deactivate()
to prevent REQ_GPU_FINI to be sent inside amdgpu_device_fini_hw(). In amdgpu_driver_unload_kms(),

    void amdgpu_driver_unload_kms(struct drm_device dev)
    {
    struct amdgpu_device adev = drm_to_adev(dev);
    if (adev == NULL || *!adev->num_ip_blocks*)
    return;
    amdgpu_unregister_gpu_instance(adev);
    i f (adev->rmmio == NULL)
    return;
    if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_UNLOAD))
    drm_warn(dev, "smart shift update failed
    ");
    amdgpu_acpi_fini(adev);
    amdgpu_device_fini_hw(adev);
    }
Quoted 6 lines

it checks if adev->num_ip_blocks is non-zero to proceed with the device_fini. In the early full access case, it runs before IP discovery while num_ip_blocks is still 0. So the amdgpu_driver_unload_kms() returns before the fini. But here it already passed the ip discovery set, so the num_ip_blocks>0 and fini will be executed.
Also, release_full_gpu is correctly skipped since early_full_gpu_access is false in this case. ]

If deactivating is harmless in early access also (looks so to me), suggest to make the behavior the same in both cases for the sake of consistency.

Thanks,
Lijo

Quoted 295 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Tuesday, November 3, 2026 1:35 AM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]> *Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 22 lines · Chenglei

AMD General

     +err_release_full_gpu:
     + if (amdgpu_sriov_vf(adev)) {
     + /*
     + * Release the access the host is waiting on so it finishes the
     + * handshake instead of timing out and FLR'ing the VF.
     + /
     + if (early_full_gpu_access)
     + amdgpu_virt_release_full_gpu(adev, true);
     +
     + /*
     + * Mark the VF inactive so the later fini path does not send a
     + * request the host will never answer.
     + /
     + amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

Quoted 6 lines

No, it should not be called. If amdgpu_virt_request_full_gpu fails,
the VF holds no access as the acquire handshake never completed.
There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear.
Jumping to err_release_full_gpu would send a release for access that is never granted.

In that case, this code needs to be changed to just return immediately.

 >        if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) { >                r = amdgpu_virt_request_full_gpu(adev, true); >                if (r)
 > -                     return r;
 > +                     goto err_release_full_gpu;

Thanks,
Lijo

Quoted 238 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Sunday, November 1, 2026 11:32 PM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]> *Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 + drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-

   4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = amdgpu_virt_init_critical_region(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 adev->family = AMDGPU_FAMILY_SI;
                 r = si_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif
    #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = cik_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;
    #endif

        case CHIP_TOPAZ:

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 r = vi_set_ip_blocks(adev);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
                 break;

        default:
                r = amdgpu_discovery_set_ip_blocks(adev); if (r) {
                        adev->num_ip_blocks = 0; -                     return r;
+                     goto err_release_full_gpu; }
                break;
        }

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)

        if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) && !amdgpu_device_get_rev_id(adev)) { dev_err(adev->dev, "Unsupported A0 hardware\n"); -             return -ENODEV; /* device unsupported - no device error */ +             r = -ENODEV;    /* device unsupported - no device error */ +             goto err_release_full_gpu;
        }

        if (amdgpu_has_atpx() &&

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                 if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                         r = amdgpu_device_parse_gpu_info_fw(adev);
                         if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                         bios_flags = amdgpu_device_get_vbios_flags(adev);
                         skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                         if (!skip_bios) {

                                bool optional =
                                        !!(bios_flags & AMDGPU_VBIOS_OPTIONAL); -                             if (!amdgpu_get_bios(adev) && !optional) -                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) { +                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }

                                if (optional && !adev->bios) dev_info(

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -4
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                         adev,
                                                         AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                         0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                         }
                                 }
                         }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
                 }
         }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
         /* Request full GPU access only for the remaining SR-IOV init work. */
         if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
                 r = amdgpu_virt_request_full_gpu(adev, true);
                 if (r)
-                     return r;
+                     goto err_release_full_gpu;
         }
 
         if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
         amdgpu_smu_early_init(adev);
 
         return 0;
+
+err_release_full_gpu:
+     if (amdgpu_sriov_vf(adev)) {
+             /*
+              * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+              * handshake instead of timing out and FLR'ing the VF.
+              */
+             if (early_full_gpu_access)
+                     amdgpu_virt_release_full_gpu(adev, true);
+
+             /*
+              * Mark the VF inactive so the later fini path does not send a
+              * request the host will never answer.
+              */
+             amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+     }
+
+     return r;
    }
 
    static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
         return 0;
    }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+     adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+     adev->virt.ops = NULL;
+}
+
    /**
     * amdgpu_virt_reset_gpu() - reset gpu
     * @adev:   amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
    void amdgpu_virt_init_setting(struct amdgpu_device *adev);
    int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
    int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
    int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
    void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
    int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
                 r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                         &aper_size);
+             /*
+              * An SPM VF has no FB BAR0 and cannot init without the HBM
+              * aperture from the SRAT. Abort this GPU probe instead of
+              * limping on as if the GMC block were absent.
+              */
                 if (r)
-                     return r;
+                     return -ENODEV;
 
                 adev->gmc.aper_base = aper_base;
                 adev->gmc.aper_size = aper_size;
#15 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

AMD General

Quoted 6 lines

If deactivating is harmless in early access also (looks so to me), suggest to make the behavior the same in both cases for the sake of consistency.

Thanks,
Lijo

Deactivate is harmless on the early access path too. The only catch is the err_release_full_gpu label also releases full GPU access, gated on early_full_gpu_access, which is true there, so a plain goto would release access the failed request never acquired. To ensure the consistancy, I made a v3 patch to gate the release on full_access_held flag
set after each successful acquire, and route both
request failures through the label. So the two cases behave the same now.

Thanks,
Chenglei
________________________________
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, November 4, 2026 10:50 AM
To: Xie, Chenglei <[email protected]>; [email protected] <[email protected]>
Cc: Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
Subject: Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 62 lines · Chenglei

AMD General

On 02-Nov-26 11:11 PM, Xie, Chenglei wrote:

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

>Shouldn't this be called when amdgpu_virt_request_full_gpu fails for >early_full_gpu_access case also?
>Thanks,
>Lijo

No, it should not be called. If amdgpu_virt_request_full_gpu fails, the VF holds no access as the acquire handshake never completed. There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear. Jumping to err_release_full_gpu would send a release for access that is never granted.

Quoted 9 lines

In that case, this code needs to be changed to just return immediately. if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
r = amdgpu_virt_request_full_gpu(adev, true);
if (r)
- return r;
+ goto err_release_full_gpu;

Thanks,
Lijo

No, the goto is needed here because we need the amdgpu_virt_deactivate() to prevent REQ_GPU_FINI to be sent inside amdgpu_device_fini_hw(). In amdgpu_driver_unload_kms(),

    void amdgpu_driver_unload_kms(struct drm_device dev)
    {
    struct amdgpu_device adev = drm_to_adev(dev);
    if (adev == NULL || *!adev->num_ip_blocks*)
    return;
    amdgpu_unregister_gpu_instance(adev);
    i f (adev->rmmio == NULL)
    return;
    if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_UNLOAD))
    drm_warn(dev, "smart shift update failed
    ");
    amdgpu_acpi_fini(adev);
    amdgpu_device_fini_hw(adev);
    }
Quoted 10 lines

it checks if adev->num_ip_blocks is non-zero to proceed with the device_fini.
In the early full access case, it runs before IP discovery while num_ip_blocks is still 0.
So the amdgpu_driver_unload_kms() returns before the fini. But here it already passed
the ip discovery set, so the num_ip_blocks>0 and fini will be executed. Also, release_full_gpu is correctly skipped since early_full_gpu_access is false in this case.
]

If deactivating is harmless in early access also (looks so to me), suggest to make the behavior the same in both cases for the sake of consistency.

Thanks,
Lijo

Quoted 302 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Tuesday, November 3, 2026 1:35 AM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
*Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 22 lines · Chenglei

AMD General

+err_release_full_gpu:
+ if (amdgpu_sriov_vf(adev)) {
+ /*
+ * Release the access the host is waiting on so it finishes the
+ * handshake instead of timing out and FLR'ing the VF.
+ /
+ if (early_full_gpu_access)
+ amdgpu_virt_release_full_gpu(adev, true);
+
+ /*
+ * Mark the VF inactive so the later fini path does not send a
+ * request the host will never answer.
+ /
+ amdgpu_virt_deactivate(adev);

Quoted 4 lines

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?
Thanks,
Lijo

Quoted 7 lines

No, it should not be called. If amdgpu_virt_request_full_gpu fails, the VF holds no access as the acquire handshake never completed. There is nothing to release and RUNTIME was never set,
so the amdgpu_virt_deactivate() has nothing to clear. Jumping to err_release_full_gpu would send a release for access that is never granted.

In that case, this code needs to be changed to just return immediately.

Review

Quoted 5 lines
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
(quoted diff) +1 -1
-                     return r;
+                     goto err_release_full_gpu;

Thanks,
Lijo

Quoted 241 lines

Thanks,
Chenglei

------------------------------------------------------------------------
*From:* Lazar, Lijo <[email protected]>
*Sent:* Sunday, November 1, 2026 11:32 PM
*To:* Xie, Chenglei <[email protected]>; amd- [email protected] <[email protected]> *Cc:* Skvortsov, Victor <[email protected]>; Luo, Zhigang <[email protected]>
*Subject:* Re: [PATCH v2 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 148 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 49 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 ++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 +++-
  4 files changed, 55 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +23 -13
index 3ced5c18daaa..3b6a3d86348c 100644
@@ -1999,7 +1999,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = amdgpu_virt_init_critical_region(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       switch (adev->asic_type) {
@@ -2012,7 +2012,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               adev->family = AMDGPU_FAMILY_SI;
               r = si_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2028,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = cik_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
  #endif
       case CHIP_TOPAZ:
@@ -2047,13 +2047,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               r = vi_set_ip_blocks(adev);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
               break;
       default:
               r = amdgpu_discovery_set_ip_blocks(adev);
               if (r) {
                       adev->num_ip_blocks = 0;
-                     return r;
+                     goto err_release_full_gpu;
               }
               break;
       }
@@ -2062,7 +2062,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
           !amdgpu_device_get_rev_id(adev)) {
               dev_err(adev->dev, "Unsupported A0 hardware\n");
-             return -ENODEV; /* device unsupported - no device error */
+             r = -ENODEV;    /* device unsupported - no device error */
+             goto err_release_full_gpu;
       }
 
       if (amdgpu_has_atpx() &&
@@ -2123,7 +2124,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
               if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
                       r = amdgpu_device_parse_gpu_info_fw(adev);
                       if (r)
-                             return r;
+                             goto err_release_full_gpu;
 
                       bios_flags = amdgpu_device_get_vbios_flags(adev);
                       skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2132,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                       if (!skip_bios) {
                               bool optional =
                                       !!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-                             if (!amdgpu_get_bios(adev) && !optional)
-                                     return -EINVAL;
+                             if (!amdgpu_get_bios(adev) && !optional) {
+                                     r = -EINVAL;
+                                     goto err_release_full_gpu;
+                             }
 
                               if (optional && !adev->bios)
                                       dev_info(
@@ -2148,7 +2151,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
                                                       adev,
                                                       AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
                                                       0, 0);
-                                             return r;
+                                             goto err_release_full_gpu;
                                       }
                               }
                       }
@@ -2159,14 +2162,16 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
               }
       }
-     if (!total)
-             return -ENODEV;
+     if (!total) {
+             r = -ENODEV;
+             goto err_release_full_gpu;
+     }
 
       /* Request full GPU access only for the remaining SR-IOV init work. */
       if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
               r = amdgpu_virt_request_full_gpu(adev, true);
               if (r)
-                     return r;
+                     goto err_release_full_gpu;
       }
 
       if (adev->gmc.xgmi.supported)
@@ -2184,6 +2189,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
       amdgpu_smu_early_init(adev);
 
       return 0;
+
+err_release_full_gpu:
+     if (amdgpu_sriov_vf(adev)) {
+             /*
+              * Release the access the host is waiting on so it finishes the

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) · line 2206

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+              * handshake instead of timing out and FLR'ing the VF.
+              */
+             if (early_full_gpu_access)
+                     amdgpu_virt_release_full_gpu(adev, true);
+
+             /*
+              * Mark the VF inactive so the later fini path does not send a
+              * request the host will never answer.
+              */
+             amdgpu_virt_deactivate(adev);

Shouldn't this be called when amdgpu_virt_request_full_gpu fails for early_full_gpu_access case also?

Thanks,
Lijo

Quoted 60 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
+     }
+
+     return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
       return 0;
  }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+     adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+     adev->virt.ops = NULL;
+}
+
  /**
   * amdgpu_virt_reset_gpu() - reset gpu
   * @adev:   amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
  void amdgpu_virt_init_setting(struct amdgpu_device *adev);
  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
  void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
  int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
               r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
                                                       &aper_size);
+             /*
+              * An SPM VF has no FB BAR0 and cannot init without the HBM
+              * aperture from the SRAT. Abort this GPU probe instead of
+              * limping on as if the GMC block were absent.
+              */
               if (r)
-                     return r;
+                     return -ENODEV;
 
               adev->gmc.aper_base = aper_base;
               adev->gmc.aper_size = aper_size;
Reviewed-by on v2 1/2
#16 lore raw
In reply to Chenglei Xie
Quoted 8 lines · Chenglei Xie

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Quoted 4 lines

Initialize the work once in amdgpu_virt_init(), which runs before early init fills in the interval, so the cancel is safe on every failure path.

Thanks,
Lijo

Quoted 38 lines

---
v2: Initialize the work in amdgpu_virt_init() instead of
amdgpu_virt_init_data_exchange(), per review.

  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -2
index 4b1b42fee6b4..576a818db522 100644
@@ -838,7 +838,6 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
  		/* go through this logic in ip_init and reset to init workqueue*/
  		amdgpu_virt_exchange_data(adev);
 
-		INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item);
  		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
  	} else if (adev->bios != NULL) {
  		/* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/
@@ -1249,8 +1248,17 @@ void amdgpu_virt_init(struct amdgpu_device *adev)
 
  	is_sriov = amdgpu_virt_init_req_data(adev, reg);
 
-	if (is_sriov)
+	if (is_sriov) {
  		amdgpu_virt_init_ras(adev);
+
+		/*
+		 * Initialize the vf2pf work here, before early init writes
+		 * vf2pf_update_interval_ms, so a teardown after a failed init
+		 * can cancel the work safely.
+		 */
+		INIT_DELAYED_WORK(&adev->virt.vf2pf_work,
+				  amdgpu_virt_update_vf2pf_work_item);
+	}
  }
 
  static bool amdgpu_virt_access_debugfs_is_mmio(struct amdgpu_device *adev)
#17 lore raw

PATCH v3 1/2 drm/amdgpu: initialize VF2PF work before it can be cancelled

In reply to Chenglei Xie

The vf2pf delayed work is only set up on the ip_init path of amdgpu_virt_init_data_exchange(), which also schedules it. But amdgpu_virt_fini_data_exchange() decides whether to cancel the work from vf2pf_update_interval_ms, and the early init path fills that in much earlier through amdgpu_virt_read_pf2vf_data(). When init fails in that window, teardown calls cancel_delayed_work_sync() on a work that was never initialized and trips the WARN in __flush_work().

Initialize the work once in amdgpu_virt_init(), which runs before early init fills in the interval, so the cancel is safe on every failure path.

---
v3: No change.
v2: Initialize the work in amdgpu_virt_init() instead of
amdgpu_virt_init_data_exchange(), per review.

 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +10 -2
index 4b1b42fee6b4..576a818db522 100644
@@ -838,7 +838,6 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
 		/* go through this logic in ip_init and reset to init workqueue*/
 		amdgpu_virt_exchange_data(adev);
 
-		INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item);
 		schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
 	} else if (adev->bios != NULL) {
 		/* got through this logic in early init stage to get necessary flags, e.g. rlcg_acc related*/
@@ -1249,8 +1248,17 @@ void amdgpu_virt_init(struct amdgpu_device *adev)
 
 	is_sriov = amdgpu_virt_init_req_data(adev, reg);
 
-	if (is_sriov)
+	if (is_sriov) {
 		amdgpu_virt_init_ras(adev);
+
+		/*
+		 * Initialize the vf2pf work here, before early init writes
+		 * vf2pf_update_interval_ms, so a teardown after a failed init
+		 * can cancel the work safely.
+		 */
+		INIT_DELAYED_WORK(&adev->virt.vf2pf_work,
+				  amdgpu_virt_update_vf2pf_work_item);
+	}
 }
 
 static bool amdgpu_virt_access_debugfs_is_mmio(struct amdgpu_device *adev)
Signature · 1 line
2.34.1
#18 lore raw

PATCH v3 2/2 drm/amdgpu: abort SPM VF init when the HBM aperture is missing

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v3: Route the initial full GPU access request failure through the
err_release_full_gpu label too, and gate the release on a new full_access_held flag so both acquire failures are handled the same way, per review.
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 55 ++++++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 ++-
 4 files changed, 59 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +40 -15
index 3ced5c18daaa..a0b9cff01bbd 100644
@@ -1977,7 +1977,7 @@ static void amdgpu_device_init_pcie_links(struct amdgpu_device *adev)
 static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 {
 	struct amdgpu_ip_block *ip_block;
-	bool total, skip_bios, early_full_gpu_access = false;
+	bool total, skip_bios, early_full_gpu_access = false, full_access_held = false;
 	uint32_t bios_flags;
 	int i, r;
 
@@ -1994,12 +1994,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		if (early_full_gpu_access) {
 			r = amdgpu_virt_request_full_gpu(adev, true);
 			if (r)
-				return r;
+				goto err_release_full_gpu;
+			full_access_held = true;
 		}
 
 		r = amdgpu_virt_init_critical_region(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 	}
 
 	switch (adev->asic_type) {
@@ -2012,7 +2013,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		adev->family = AMDGPU_FAMILY_SI;
 		r = si_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2029,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = cik_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 #endif
 	case CHIP_TOPAZ:
@@ -2047,13 +2048,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		r = vi_set_ip_blocks(adev);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
 		break;
 	default:
 		r = amdgpu_discovery_set_ip_blocks(adev);
 		if (r) {
 			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
 		}
 		break;
 	}
@@ -2062,7 +2063,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
 	    !amdgpu_device_get_rev_id(adev)) {
 		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
 	}
 
 	if (amdgpu_has_atpx() &&
@@ -2123,7 +2125,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
 			r = amdgpu_device_parse_gpu_info_fw(adev);
 			if (r)
-				return r;
+				goto err_release_full_gpu;
 
 			bios_flags = amdgpu_device_get_vbios_flags(adev);
 			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2133,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 			if (!skip_bios) {
 				bool optional =
 					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
 				if (optional && !adev->bios)
 					dev_info(
@@ -2148,7 +2152,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 							adev,
 							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
 							0, 0);
-						return r;
+						goto err_release_full_gpu;
 					}
 				}
 			}
@@ -2159,14 +2163,17 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
 		}
 	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
 	/* Request full GPU access only for the remaining SR-IOV init work. */
 	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
 		r = amdgpu_virt_request_full_gpu(adev, true);
 		if (r)
-			return r;
+			goto err_release_full_gpu;
+		full_access_held = true;
 	}
 
 	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2191,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 	amdgpu_smu_early_init(adev);
 
 	return 0;
+
+err_release_full_gpu:
+	if (amdgpu_sriov_vf(adev)) {
+		/*
+		 * Release the access the host is waiting on so it finishes the
+		 * handshake instead of timing out and FLR'ing the VF.
+		 */
+		if (full_access_held)
+			amdgpu_virt_release_full_gpu(adev, true);
+
+		/*
+		 * Mark the VF inactive so the later fini path does not send a
+		 * request the host will never answer.
+		 */
+		amdgpu_virt_deactivate(adev);
+	}
+
+	return r;
 }
 
 static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
 	return 0;
 }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+	adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+	adev->virt.ops = NULL;
+}
+
 /**
  * amdgpu_virt_reset_gpu() - reset gpu
  * @adev:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
 void amdgpu_virt_init_setting(struct amdgpu_device *adev);
 int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
 int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
 int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
 void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
 int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
 		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
 							&aper_size);
+		/*
+		 * An SPM VF has no FB BAR0 and cannot init without the HBM
+		 * aperture from the SRAT. Abort this GPU probe instead of
+		 * limping on as if the GMC block were absent.
+		 */
 		if (r)
-			return r;
+			return -ENODEV;
 
 		adev->gmc.aper_base = aper_base;
 		adev->gmc.aper_size = aper_size;
Signature · 1 line
2.34.1
Reviewed-by on v3 2/2
#19 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: abort SPM VF init when the HBM aperture is missing

Quoted 40 lines · Chenglei Xie

An SPM backed VF has no FB BAR0 and gets its HBM aperture from the ACPI SRAT. When that entry is missing, amdgpu_acpi_find_gpu_memory_in_srat() returns -ENOENT, which the early init IP loop treats as the GMC block being absent. Init keeps going and dies later with a confusing -ENOMEM instead of the real cause.

Return -ENODEV from gmc_v12_0_early_init() so the probe aborts at the point where the aperture is actually missing.

On a legacy host the VF already holds exclusive GPU access at this point, and the early init error paths returned directly without releasing it, so the host timed out and FLR'd the VF. Route these failures through a new err_release_full_gpu label that releases the access the host is waiting on.

Add amdgpu_virt_deactivate() to clear AMDGPU_SRIOV_CAPS_RUNTIME and drop adev->virt.ops, and call it from the same label, so the later fini path does not send a REQ_GPU_FINI that the host will never answer.

---
v3: Route the initial full GPU access request failure through the
err_release_full_gpu label too, and gate the release on a new full_access_held flag so both acquire failures are handled the same way, per review.
v2: Move the runtime cap and virt ops clearing into a new
amdgpu_virt_deactivate() helper and call it from the label. Drop the redundant SRAT error log already emitted by amdgpu_acpi_find_gpu_memory_in_srat().

  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 55 ++++++++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 12 +++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     |  7 ++-
  4 files changed, 59 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 3ced5c18daaa..a0b9cff01bbd 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_init_pcie_links(struct amdgpu_device *adev) · line 1980

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -1977,7 +1977,7 @@ static void amdgpu_device_init_pcie_links(struct amdgpu_device *adev)
  static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  {
  	struct amdgpu_ip_block *ip_block;
-	bool total, skip_bios, early_full_gpu_access = false;
+	bool total, skip_bios, early_full_gpu_access = false, full_access_held = false;

<nit/style> reverse xmas tree order.

Thanks,
Lijo

Quoted 194 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +39 -14
  	uint32_t bios_flags;
  	int i, r;
 
@@ -1994,12 +1994,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		if (early_full_gpu_access) {
  			r = amdgpu_virt_request_full_gpu(adev, true);
  			if (r)
-				return r;
+				goto err_release_full_gpu;
+			full_access_held = true;
  		}
 
  		r = amdgpu_virt_init_critical_region(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  	}
 
  	switch (adev->asic_type) {
@@ -2012,7 +2013,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		adev->family = AMDGPU_FAMILY_SI;
  		r = si_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  #ifdef CONFIG_DRM_AMDGPU_CIK
@@ -2028,7 +2029,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = cik_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  #endif
  	case CHIP_TOPAZ:
@@ -2047,13 +2048,13 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		r = vi_set_ip_blocks(adev);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
  		break;
  	default:
  		r = amdgpu_discovery_set_ip_blocks(adev);
  		if (r) {
  			adev->num_ip_blocks = 0;
-			return r;
+			goto err_release_full_gpu;
  		}
  		break;
  	}
@@ -2062,7 +2063,8 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3) &&
  	    !amdgpu_device_get_rev_id(adev)) {
  		dev_err(adev->dev, "Unsupported A0 hardware\n");
-		return -ENODEV;	/* device unsupported - no device error */
+		r = -ENODEV;	/* device unsupported - no device error */
+		goto err_release_full_gpu;
  	}
 
  	if (amdgpu_has_atpx() &&
@@ -2123,7 +2125,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  		if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON) {
  			r = amdgpu_device_parse_gpu_info_fw(adev);
  			if (r)
-				return r;
+				goto err_release_full_gpu;
 
  			bios_flags = amdgpu_device_get_vbios_flags(adev);
  			skip_bios = !!(bios_flags & AMDGPU_VBIOS_SKIP);
@@ -2131,8 +2133,10 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  			if (!skip_bios) {
  				bool optional =
  					!!(bios_flags & AMDGPU_VBIOS_OPTIONAL);
-				if (!amdgpu_get_bios(adev) && !optional)
-					return -EINVAL;
+				if (!amdgpu_get_bios(adev) && !optional) {
+					r = -EINVAL;
+					goto err_release_full_gpu;
+				}
 
  				if (optional && !adev->bios)
  					dev_info(
@@ -2148,7 +2152,7 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  							adev,
  							AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL,
  							0, 0);
-						return r;
+						goto err_release_full_gpu;
  					}
  				}
  			}
@@ -2159,14 +2163,17 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
 
  		}
  	}
-	if (!total)
-		return -ENODEV;
+	if (!total) {
+		r = -ENODEV;
+		goto err_release_full_gpu;
+	}
 
  	/* Request full GPU access only for the remaining SR-IOV init work. */
  	if (amdgpu_sriov_vf(adev) && !early_full_gpu_access) {
  		r = amdgpu_virt_request_full_gpu(adev, true);
  		if (r)
-			return r;
+			goto err_release_full_gpu;
+		full_access_held = true;
  	}
 
  	if (adev->gmc.xgmi.supported)
@@ -2184,6 +2191,24 @@ static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  	amdgpu_smu_early_init(adev);
 
  	return 0;
+
+err_release_full_gpu:
+	if (amdgpu_sriov_vf(adev)) {
+		/*
+		 * Release the access the host is waiting on so it finishes the
+		 * handshake instead of timing out and FLR'ing the VF.
+		 */
+		if (full_access_held)
+			amdgpu_virt_release_full_gpu(adev, true);
+
+		/*
+		 * Mark the VF inactive so the later fini path does not send a
+		 * request the host will never answer.
+		 */
+		amdgpu_virt_deactivate(adev);
+	}
+
+	return r;
  }
 
  static int amdgpu_device_ip_hw_init_phase1(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +12 -0
index 576a818db522..a4dd0299fe11 100644
@@ -135,6 +135,18 @@ int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init)
  	return 0;
  }
 
+/*
+ * amdgpu_virt_deactivate - stop driving an SR-IOV VF after a failed init
+ *
+ * Clear the runtime capability and drop the virt ops so the teardown path
+ * does not issue host handshakes the host will never answer.
+ */
+void amdgpu_virt_deactivate(struct amdgpu_device *adev)
+{
+	adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
+	adev->virt.ops = NULL;
+}
+
  /**
   * amdgpu_virt_reset_gpu() - reset gpu
   * @adev:	amdgpu device.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +1 -0
index 3971bcc1ed11..3520af170278 100644
@@ -471,6 +471,7 @@ bool amdgpu_virt_mmio_blocked(struct amdgpu_device *adev);
  void amdgpu_virt_init_setting(struct amdgpu_device *adev);
  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
+void amdgpu_virt_deactivate(struct amdgpu_device *adev);
  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
  void amdgpu_virt_request_init_data(struct amdgpu_device *adev);
  int amdgpu_virt_ptl_request(struct amdgpu_device *adev, u32 req_code,
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +6 -1
index cd276a138e10..3bb13cfed92f 100644
@@ -667,8 +667,13 @@ static int gmc_v12_0_early_init(struct amdgpu_ip_block *ip_block)
 
  		r = amdgpu_acpi_find_gpu_memory_in_srat(adev, &aper_base,
  							&aper_size);
+		/*
+		 * An SPM VF has no FB BAR0 and cannot init without the HBM
+		 * aperture from the SRAT. Abort this GPU probe instead of
+		 * limping on as if the GMC block were absent.
+		 */
  		if (r)
-			return r;
+			return -ENODEV;
 
  		adev->gmc.aper_base = aper_base;
  		adev->gmc.aper_size = aper_size;