Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/xe/tests: Fix g2g_test_array indexing

The G2G KUnit test allocates a compact N×N
matrix sized by gt_count and verifies entries
using dense indices: idx = (j * gt_count) + i

The producer path currently computes idx using
gt->info.id. However, gt->info.id values
are not guaranteed to be contiguous.
For example, with gt_count=2 and IDs {0,3},
this formula produces indices beyond the
allocated range, causing mismatches and
potential out-of-bounds access.

Update the producer to map each GT to a dense
index in [0..gt_count-1] and compute:
idx = (tx_dense * gt_count) + rx_dense

Additionally, introduce an event-based delay
in g2g_test_in_order() to ensure ordering
between sends.

v2: Add single helper function (Daniele)

v3: Modify comment (Daniele)

Signed-off-by: Pallavi Mishra <pallavi.mishra@intel.com>
Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
Link: https://patch.msgid.link/20260129054722.2150674-1-pallavi.mishra@intel.com

authored by

Pallavi Mishra and committed by
Vinay Belgaumkar
10634077 9b5e995e

+59 -2
+59 -2
drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c
··· 48 48 u32 seqno; 49 49 }; 50 50 51 + static int slot_index_from_gts(struct xe_gt *tx_gt, struct xe_gt *rx_gt) 52 + { 53 + struct xe_device *xe = gt_to_xe(tx_gt); 54 + int idx = 0, found = 0, id, tx_idx, rx_idx; 55 + struct xe_gt *gt; 56 + struct kunit *test = kunit_get_current_test(); 57 + 58 + for (id = 0; id < xe->info.tile_count * xe->info.max_gt_per_tile; id++) { 59 + gt = xe_device_get_gt(xe, id); 60 + if (!gt) 61 + continue; 62 + if (gt == tx_gt) { 63 + tx_idx = idx; 64 + found++; 65 + } 66 + if (gt == rx_gt) { 67 + rx_idx = idx; 68 + found++; 69 + } 70 + 71 + if (found == 2) 72 + break; 73 + 74 + idx++; 75 + } 76 + 77 + if (found != 2) 78 + KUNIT_FAIL(test, "GT index not found"); 79 + 80 + return (tx_idx * xe->info.gt_count) + rx_idx; 81 + } 82 + 51 83 static void g2g_test_send(struct kunit *test, struct xe_guc *guc, 52 84 u32 far_tile, u32 far_dev, 53 85 struct g2g_test_payload *payload) ··· 195 163 goto done; 196 164 } 197 165 198 - idx = (tx_gt->info.id * xe->info.gt_count) + rx_gt->info.id; 166 + idx = slot_index_from_gts(tx_gt, rx_gt); 199 167 200 168 if (xe->g2g_test_array[idx] != payload->seqno - 1) { 201 169 xe_gt_err(rx_gt, "G2G: Seqno mismatch %d vs %d for %d:%d -> %d:%d!\n", ··· 212 180 return ret; 213 181 } 214 182 183 + #define G2G_WAIT_TIMEOUT_MS 100 184 + #define G2G_WAIT_POLL_MS 1 185 + 215 186 /* 216 187 * Send the given seqno from all GuCs to all other GuCs in tile/GT order 217 188 */ 218 189 static void g2g_test_in_order(struct kunit *test, struct xe_device *xe, u32 seqno) 219 190 { 220 191 struct xe_gt *near_gt, *far_gt; 221 - int i, j; 192 + int i, j, waited; 193 + u32 idx; 222 194 223 195 for_each_gt(near_gt, xe, i) { 224 196 u32 near_tile = gt_to_tile(near_gt)->id; ··· 241 205 payload.rx_dev = far_dev; 242 206 payload.rx_tile = far_tile; 243 207 payload.seqno = seqno; 208 + 209 + /* Calculate idx for event-based wait */ 210 + idx = slot_index_from_gts(near_gt, far_gt); 211 + waited = 0; 212 + 213 + /* 214 + * Wait for previous seqno to be acknowledged before sending, 215 + * to avoid queuing too many back-to-back messages and 216 + * causing a test timeout. Actual correctness of message 217 + * will be checked later in xe_guc_g2g_test_notification() 218 + */ 219 + while (xe->g2g_test_array[idx] != (seqno - 1)) { 220 + msleep(G2G_WAIT_POLL_MS); 221 + waited += G2G_WAIT_POLL_MS; 222 + if (waited >= G2G_WAIT_TIMEOUT_MS) { 223 + kunit_info(test, "Timeout waiting! tx gt: %d, rx gt: %d\n", 224 + near_gt->info.id, far_gt->info.id); 225 + break; 226 + } 227 + } 228 + 244 229 g2g_test_send(test, &near_gt->uc.guc, far_tile, far_dev, &payload); 245 230 } 246 231 }