Skip to contentSkip to conversation

drm/amdgpu: clamp the isolation index for rings outside a partition

PATCH In review Xiang Liu 3 participants 3 messages Aug 21

Subsystems (2)
lore
Share & tools
lore

Xiang Liu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: clamp the isolation index for rings outside a partition

adev->isolation[] has one slot per partition, but a ring that is not assigned to one keeps AMDGPU_XCP_NO_PARTITION, which is ~0, so indexing the array with it is out of bounds. SDMA submissions hit this on both the isolation enforcement and the VM flush path and trip UBSAN.

Fall back to the first slot the way the cleaner shader path already does, and stop taking the address before the ring type check that makes it relevant.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -1
index baadb676f76b..d8d182599fc6 100644
@@ -6756,8 +6756,8 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
 						  struct amdgpu_ring *ring,
 						  struct amdgpu_job *job)
 {
-	struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
 	struct drm_sched_fence *f = job->base.s_fence;
+	struct amdgpu_isolation *isolation;
 	struct dma_fence *dep;
 	void *owner;
 	int r;
@@ -6770,6 +6770,9 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
 	    ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
 		return NULL;
 
+	isolation = &adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+				     0 : ring->xcp_id];
+
 	/*
 	 * All submissions where enforce isolation is false are handled as if
 	 * they come from a single client. Use ~0l as the owner to distinct it
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -1
index 5a6f5151c3ca..743d307c71fd 100644
@@ -774,7 +774,9 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
 		     bool *emit_gds_needed)
 {
 	struct amdgpu_device *adev = ring->adev;
-	struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
+	struct amdgpu_isolation *isolation =
+		&adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+				 0 : ring->xcp_id];
 	unsigned vmhub = ring->vm_hub;
 	struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
 	struct amdgpu_vmid *id = &id_mgr->ids[job->vmid];
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Xiang Liu
Sent: Friday, August 21, 2026 6:09 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>; Liu, Xiang(Dean) <[email protected]>
Subject: [PATCH] drm/amdgpu: clamp the isolation index for rings outside a partition

adev->isolation[] has one slot per partition, but a ring that is not
assigned to one keeps AMDGPU_XCP_NO_PARTITION, which is ~0, so indexing the array with it is out of bounds. SDMA submissions hit this on both the isolation enforcement and the VM flush path and trip UBSAN.

Fall back to the first slot the way the cleaner shader path already does, and stop taking the address before the ring type check that makes it relevant.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -1
index baadb676f76b..d8d182599fc6 100644
@@ -6756,8 +6756,8 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
                                                  struct amdgpu_ring *ring,
                                                  struct amdgpu_job *job)
 {
-       struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
        struct drm_sched_fence *f = job->base.s_fence;
+       struct amdgpu_isolation *isolation;
        struct dma_fence *dep;
        void *owner;
        int r;
@@ -6770,6 +6770,9 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
            ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
                return NULL;
 
+       isolation = &adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+                                    0 : ring->xcp_id];
+
        /*
         * All submissions where enforce isolation is false are handled as if
         * they come from a single client. Use ~0l as the owner to distinct it diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 5a6f5151c3ca..743d307c71fd 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -1
@@ -774,7 +774,9 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
                     bool *emit_gds_needed)
 {
        struct amdgpu_device *adev = ring->adev;
-       struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
+       struct amdgpu_isolation *isolation =
+               &adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+                                0 : ring->xcp_id];
        unsigned vmhub = ring->vm_hub;
        struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
        struct amdgpu_vmid *id = &id_mgr->ids[job->vmid];

--
2.34.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Xiang Liu
Quoted 11 lines · Xiang Liu

adev->isolation[] has one slot per partition, but a ring that is not assigned to one keeps AMDGPU_XCP_NO_PARTITION, which is ~0, so indexing the array with it is out of bounds. SDMA submissions hit this on both the isolation enforcement and the VM flush path and trip UBSAN.

Fall back to the first slot the way the cleaner shader path already does, and stop taking the address before the ring type check that makes it relevant.

Quoted 47 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -1
index baadb676f76b..d8d182599fc6 100644
@@ -6756,8 +6756,8 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
                                                  struct amdgpu_ring *ring,
                                                  struct amdgpu_job *job)
 {
-       struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
        struct drm_sched_fence *f = job->base.s_fence;
+       struct amdgpu_isolation *isolation;
        struct dma_fence *dep;
        void *owner;
        int r;
@@ -6770,6 +6770,9 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,
            ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
                return NULL;
 
+       isolation = &adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+                                    0 : ring->xcp_id];
+
        /*
         * All submissions where enforce isolation is false are handled as if
         * they come from a single client. Use ~0l as the owner to distinct it
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -2
index 5a6f5151c3ca..743d307c71fd 100644
@@ -774,7 +774,9 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,
                     bool *emit_gds_needed)
 {
        struct amdgpu_device *adev = ring->adev;
-       struct amdgpu_isolation *isolation = &adev->isolation[ring->xcp_id];
+       struct amdgpu_isolation *isolation =
+               &adev->isolation[ring->xcp_id == AMDGPU_XCP_NO_PARTITION ?
+                                0 : ring->xcp_id];
        unsigned vmhub = ring->vm_hub;
        struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
        struct amdgpu_vmid *id = &id_mgr->ids[job->vmid];
--

2.34.1