AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] drm/amdgpu: reject UALink peers outside the vPod active set
@ 2026-12-04 14:41 Mukul Joshi
  2026-12-04 15:00 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Mukul Joshi @ 2026-12-04 14:41 UTC (permalink / raw)
  To: amd-gfx; +Cc: Felix.Kuehling, Harish.Kasiviswanathan, philip.yang, Mukul Joshi

remote->peer[] is only set up for active vPod members other than this
GPU, but the import ioctl and HELLO processing only range-check the
accelerator id. An unused id makes connection setup run on a zeroed
peer: an uninitialized mutex and scheduler entity, and GPU address 0.

Reject such ids in the import ioctl, connection setup and HELLO
processing.

Fixes: 8c583a03f24c ("drm/amdgpu: Implement UALink handle import ioctl")
Fixes: aa574f2570d6 ("drm/amdgpu: Resync UALink ring wptr after reboot")
Signed-off-by: Mukul Joshi <mukul.joshi@amd.com>
---
v1->v2:
- Add the Fixes tag.

 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 0ce5faccfda7..6dcaf297a496 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -58,6 +58,8 @@ static void amdgpu_ualink_reset_peer_rings(struct amdgpu_device *adev,
 					   u32 remote_accel_id);
 static int amdgpu_ualink_ring_resync_ptrs(struct amdgpu_device *adev,
 					  u32 remote_accel_id);
+static bool amdgpu_ualink_peer_is_set_up(struct amdgpu_device *adev,
+					 u32 accel_id);
 
 #define STRIP_NPA(addr)						\
 	(((u64)(addr) & ~AMDGPU_UALINK_NPA_ADDR_GPUID_MASK))
@@ -2280,6 +2282,13 @@ static void amdgpu_ualink_process_hello_msg(struct amdgpu_device *adev,
 		return;
 	}
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, sender_acc_id)) {
+		dev_err_ratelimited(adev->dev,
+			"HELLO: sender AccId:%u is not in the vPod\n",
+			sender_acc_id);
+		return;
+	}
+
 	conn_state = &adev->ualink.conn_state[sender_acc_id];
 
 	/* Check if connection is already established. If yes, then receiving HELLO msg
@@ -2353,6 +2362,9 @@ static int amdgpu_ualink_setup_connection(struct amdgpu_device *adev,
 	struct amdgpu_ualink_connection *conn_state;
 	int r;
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, remote_acc_id))
+		return -EINVAL;
+
 	conn_state = &adev->ualink.conn_state[remote_acc_id];
 
 	/* Connection state management goes through different states.
@@ -3899,6 +3911,13 @@ int amdgpu_ualink_import_handle(struct drm_device *dev,
 		return amdgpu_ualink_local_import(adev, remote_acc_id,
 						  &handle, fd_out);
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, remote_acc_id)) {
+		dev_dbg(adev->dev,
+			"IMPORT: remote AccId:%u is not in the vPod\n",
+			remote_acc_id);
+		return -EINVAL;
+	}
+
 	xa_lock(&adev->ualink.imp_xa);
 	imp_xa_node = xa_load(&adev->ualink.imp_xa, handle.handle_lo);
 
@@ -4506,6 +4525,20 @@ static inline enum amdgpu_ualink_addr_mode ualink_addr_mode(struct amdgpu_device
 	return adev->ualink.info->vpod.addr_mode;
 }
 
+/*
+ * remote->peer[] (lock, scheduler entity, ring addresses and sizes) is only
+ * set up for members of the activation-time snapshot, excluding this GPU.
+ */
+static bool amdgpu_ualink_peer_is_set_up(struct amdgpu_device *adev,
+					 u32 accel_id)
+{
+	struct amdgpu_ualink_remote *remote = to_remote(adev);
+
+	return remote && accel_id < AMDGPU_UALINK_ACCEL_MAX &&
+	       accel_id != ualink_accel_id(adev) &&
+	       test_bit(accel_id, remote->active_accel_bits);
+}
+
 /*
  * address mode and NPA address for ring wptr, rptr, wb status, wb data
  *
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 14:41 [PATCHv2] drm/amdgpu: reject UALink peers outside the vPod active set Mukul Joshi
2026-12-04 15:00 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox