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.

dma-buf/dma-fence: Add dma_fence_check_and_signal()

The overwhelming majority of users of dma_fence signaling functions
don't care about whether the fence had already been signaled by someone
else. Therefore, the return code shall be removed from those functions.

For the few users who rely on the check, a new, specialized function
shall be provided.

Add dma_fence_check_and_signal(), which signals a fence if it had not
yet been signaled, and informs the user about that.

Add a counter part, dma_fence_check_and_signal_locked(), which doesn't
take the spinlock.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Link: https://patch.msgid.link/20251201105011.19386-4-phasta@kernel.org

+46
+44
drivers/dma-buf/dma-fence.c
··· 444 444 EXPORT_SYMBOL(dma_fence_signal_locked); 445 445 446 446 /** 447 + * dma_fence_check_and_signal_locked - signal the fence if it's not yet signaled 448 + * @fence: the fence to check and signal 449 + * 450 + * Checks whether a fence was signaled and signals it if it was not yet signaled. 451 + * 452 + * Unlike dma_fence_check_and_signal(), this function must be called with 453 + * &struct dma_fence.lock being held. 454 + * 455 + * Return: true if fence has been signaled already, false otherwise. 456 + */ 457 + bool dma_fence_check_and_signal_locked(struct dma_fence *fence) 458 + { 459 + bool ret; 460 + 461 + ret = dma_fence_test_signaled_flag(fence); 462 + dma_fence_signal_locked(fence); 463 + 464 + return ret; 465 + } 466 + EXPORT_SYMBOL(dma_fence_check_and_signal_locked); 467 + 468 + /** 469 + * dma_fence_check_and_signal - signal the fence if it's not yet signaled 470 + * @fence: the fence to check and signal 471 + * 472 + * Checks whether a fence was signaled and signals it if it was not yet signaled. 473 + * All this is done in a race-free manner. 474 + * 475 + * Return: true if fence has been signaled already, false otherwise. 476 + */ 477 + bool dma_fence_check_and_signal(struct dma_fence *fence) 478 + { 479 + unsigned long flags; 480 + bool ret; 481 + 482 + spin_lock_irqsave(fence->lock, flags); 483 + ret = dma_fence_check_and_signal_locked(fence); 484 + spin_unlock_irqrestore(fence->lock, flags); 485 + 486 + return ret; 487 + } 488 + EXPORT_SYMBOL(dma_fence_check_and_signal); 489 + 490 + /** 447 491 * dma_fence_signal - signal completion of a fence 448 492 * @fence: the fence to signal 449 493 *
+2
include/linux/dma-fence.h
··· 365 365 #endif 366 366 367 367 int dma_fence_signal(struct dma_fence *fence); 368 + bool dma_fence_check_and_signal(struct dma_fence *fence); 369 + bool dma_fence_check_and_signal_locked(struct dma_fence *fence); 368 370 int dma_fence_signal_locked(struct dma_fence *fence); 369 371 int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp); 370 372 int dma_fence_signal_timestamp_locked(struct dma_fence *fence,