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

dma-buf: fix dma-fence-chain out of order test

There was probably a misunderstand on how the dma-fence-chain is
supposed to work or what dma_fence_chain_find_seqno() is supposed to
return.

dma_fence_chain_find_seqno() is here to give us the fence to wait upon
for a particular point in the timeline. The timeline progresses only
when all the points prior to a given number have completed.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: dc2f7e67a28a5c ("dma-buf: Exercise dma-fence-chain under selftests")
Link: https://patchwork.freedesktop.org/patch/372960/
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Lionel Landwerlin and committed by
Christian König
4cca2e64 91fac86d

+21 -22
+21 -22
drivers/dma-buf/st-dma-fence-chain.c
··· 318 318 goto err; 319 319 } 320 320 321 - if (fence && fence != fc.chains[1]) { 321 + /* 322 + * We signaled the middle fence (2) of the 1-2-3 chain. The behavior 323 + * of the dma-fence-chain is to make us wait for all the fences up to 324 + * the point we want. Since fence 1 is still not signaled, this what 325 + * we should get as fence to wait upon (fence 2 being garbage 326 + * collected during the traversal of the chain). 327 + */ 328 + if (fence != fc.chains[0]) { 322 329 pr_err("Incorrect chain-fence.seqno:%lld reported for completed seqno:2\n", 323 - fence->seqno); 324 - 325 - dma_fence_get(fence); 326 - err = dma_fence_chain_find_seqno(&fence, 2); 327 - dma_fence_put(fence); 328 - if (err) 329 - pr_err("Reported %d for finding self!\n", err); 330 + fence ? fence->seqno : 0); 330 331 331 332 err = -EINVAL; 332 333 } ··· 416 415 if (!fence) 417 416 goto signal; 418 417 419 - err = dma_fence_chain_find_seqno(&fence, seqno); 420 - if (err) { 421 - pr_err("Reported an invalid fence for find-self:%d\n", 422 - seqno); 423 - dma_fence_put(fence); 424 - break; 425 - } 426 - 427 - if (fence->seqno < seqno) { 428 - pr_err("Reported an earlier fence.seqno:%lld for seqno:%d\n", 429 - fence->seqno, seqno); 430 - err = -EINVAL; 431 - dma_fence_put(fence); 432 - break; 418 + /* 419 + * We can only find ourselves if we are on fence we were 420 + * looking for. 421 + */ 422 + if (fence->seqno == seqno) { 423 + err = dma_fence_chain_find_seqno(&fence, seqno); 424 + if (err) { 425 + pr_err("Reported an invalid fence for find-self:%d\n", 426 + seqno); 427 + dma_fence_put(fence); 428 + break; 429 + } 433 430 } 434 431 435 432 dma_fence_put(fence);