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

drm/amdkfd: Fix for-loop when allocating HQD (non-HWS)

This patch fixes a minor bug in allocate_hqd(), where the loop run from the
next-to-allocate pipe until the number of pipes.

This is wrong because we need to consider the possibility where
next-to-allocate pipe is not 0, and thus, the for-loop only checks part of the
pipes and doesn't wrap-around, as it supposed to do.

Therefore, we add another counting variable to make sure we go over all the
pipes, regardless of where we start to look at the first iteration of the loop.

This bug only affected non-HWS mode. In HWS mode, the CP fw is responsible for
allocating the HQD.

Signed-off-by: Ben Goz <ben.goz@amd.com>
Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Ben Goz and committed by
Oded Gabbay
f0ec5b99 6898f0a5

+3 -3
+3 -3
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
··· 191 191 static int allocate_hqd(struct device_queue_manager *dqm, struct queue *q) 192 192 { 193 193 bool set; 194 - int pipe, bit; 194 + int pipe, bit, i; 195 195 196 196 set = false; 197 197 198 - for (pipe = dqm->next_pipe_to_allocate; pipe < get_pipes_num(dqm); 199 - pipe = (pipe + 1) % get_pipes_num(dqm)) { 198 + for (pipe = dqm->next_pipe_to_allocate, i = 0; i < get_pipes_num(dqm); 199 + pipe = ((pipe + 1) % get_pipes_num(dqm)), ++i) { 200 200 if (dqm->allocated_queues[pipe] != 0) { 201 201 bit = find_first_bit( 202 202 (unsigned long *)&dqm->allocated_queues[pipe],