* [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status
@ 2023-07-25 7:46 Mikko Perttunen
2023-09-01 9:37 ` Mikko Perttunen
0 siblings, 1 reply; 5+ messages in thread
From: Mikko Perttunen @ 2023-07-25 7:46 UTC (permalink / raw)
To: Sumit Semwal, Gustavo Padovan
Cc: Mikko Perttunen, linux-media, dri-devel, linux-kernel
From: Mikko Perttunen <mperttunen@nvidia.com>
dma_fence_get_status is not guaranteed to return valid information
on if the fence has been signaled or not if SW signaling has not
been enabled for the fence. To ensure valid information is reported,
enable SW signaling for fences before getting their status.
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
drivers/dma-buf/sync_file.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index af57799c86ce..57f194b8477f 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -267,6 +267,7 @@ static int sync_fill_fence_info(struct dma_fence *fence,
strscpy(info->driver_name, fence->ops->get_driver_name(fence),
sizeof(info->driver_name));
+ dma_fence_enable_sw_signaling(fence);
info->status = dma_fence_get_status(fence);
while (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) &&
!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags))
@@ -307,6 +308,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
* info->num_fences.
*/
if (!info.num_fences) {
+ dma_fence_enable_sw_signaling(sync_file->fence);
info.status = dma_fence_get_status(sync_file->fence);
goto no_fences;
} else {
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status
2023-07-25 7:46 Mikko Perttunen
@ 2023-09-01 9:37 ` Mikko Perttunen
0 siblings, 0 replies; 5+ messages in thread
From: Mikko Perttunen @ 2023-09-01 9:37 UTC (permalink / raw)
To: Sumit Semwal, Gustavo Padovan
Cc: linux-media, linux-kernel, dri-devel, Mikko Perttunen
On 7/25/23 10:46, Mikko Perttunen wrote:
> From: Mikko Perttunen <mperttunen@nvidia.com>
>
> dma_fence_get_status is not guaranteed to return valid information
> on if the fence has been signaled or not if SW signaling has not
> been enabled for the fence. To ensure valid information is reported,
> enable SW signaling for fences before getting their status.
>
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
> drivers/dma-buf/sync_file.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> index af57799c86ce..57f194b8477f 100644
> --- a/drivers/dma-buf/sync_file.c
> +++ b/drivers/dma-buf/sync_file.c
> @@ -267,6 +267,7 @@ static int sync_fill_fence_info(struct dma_fence *fence,
> strscpy(info->driver_name, fence->ops->get_driver_name(fence),
> sizeof(info->driver_name));
>
> + dma_fence_enable_sw_signaling(fence);
> info->status = dma_fence_get_status(fence);
> while (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) &&
> !test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags))
> @@ -307,6 +308,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
> * info->num_fences.
> */
> if (!info.num_fences) {
> + dma_fence_enable_sw_signaling(sync_file->fence);
> info.status = dma_fence_get_status(sync_file->fence);
> goto no_fences;
> } else {
Any thoughts?
Mikko
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status
@ 2025-07-08 12:03 Mikko Perttunen
2025-07-08 14:20 ` Christian König
0 siblings, 1 reply; 5+ messages in thread
From: Mikko Perttunen @ 2025-07-08 12:03 UTC (permalink / raw)
To: Sumit Semwal, Gustavo Padovan, Christian König
Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel,
Mikko Perttunen
From: Mikko Perttunen <mperttunen@nvidia.com>
dma_fence_get_status is not guaranteed to return valid information
on if the fence has been signaled or not if SW signaling has not
been enabled for the fence. To ensure valid information is reported,
enable SW signaling for fences before getting their status.
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
---
drivers/dma-buf/sync_file.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 747e377fb95417ddd506b528618a4288bea9d459..a6fd1d14dde155561b9fd2c07e6aa20dc9863a8d 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -271,6 +271,8 @@ static int sync_fill_fence_info(struct dma_fence *fence,
const char __rcu *timeline;
const char __rcu *driver;
+ dma_fence_enable_sw_signaling(fence);
+
rcu_read_lock();
driver = dma_fence_driver_name(fence);
@@ -320,6 +322,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
* info->num_fences.
*/
if (!info.num_fences) {
+ dma_fence_enable_sw_signaling(sync_file->fence);
info.status = dma_fence_get_status(sync_file->fence);
goto no_fences;
} else {
---
base-commit: 58ba80c4740212c29a1cf9b48f588e60a7612209
change-id: 20250708-syncfile-enable-signaling-a993acff1860
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status
2025-07-08 12:03 [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status Mikko Perttunen
@ 2025-07-08 14:20 ` Christian König
2025-07-09 1:28 ` Mikko Perttunen
0 siblings, 1 reply; 5+ messages in thread
From: Christian König @ 2025-07-08 14:20 UTC (permalink / raw)
To: Mikko Perttunen, Sumit Semwal, Gustavo Padovan
Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel,
Mikko Perttunen
On 08.07.25 14:03, Mikko Perttunen wrote:
> From: Mikko Perttunen <mperttunen@nvidia.com>
>
> dma_fence_get_status is not guaranteed to return valid information
> on if the fence has been signaled or not if SW signaling has not
> been enabled for the fence. To ensure valid information is reported,
> enable SW signaling for fences before getting their status.
I don't know how often I had to rejected that patch now, we really need to improve the documentation :(
The fence info query exists to query the status *without* enabling signaling, that is the whole purpose of the function!
If you want to enable signaling *and* query the status then just poll on the sync file file descriptor with a zero timeout.
If the signaling timestamp or error code is needed then that can be retrieved after signaling through the info IOCTL.
Regards,
Christian.
>
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
> drivers/dma-buf/sync_file.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
> index 747e377fb95417ddd506b528618a4288bea9d459..a6fd1d14dde155561b9fd2c07e6aa20dc9863a8d 100644
> --- a/drivers/dma-buf/sync_file.c
> +++ b/drivers/dma-buf/sync_file.c
> @@ -271,6 +271,8 @@ static int sync_fill_fence_info(struct dma_fence *fence,
> const char __rcu *timeline;
> const char __rcu *driver;
>
> + dma_fence_enable_sw_signaling(fence);
> +
> rcu_read_lock();
>
> driver = dma_fence_driver_name(fence);
> @@ -320,6 +322,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
> * info->num_fences.
> */
> if (!info.num_fences) {
> + dma_fence_enable_sw_signaling(sync_file->fence);
> info.status = dma_fence_get_status(sync_file->fence);
> goto no_fences;
> } else {
>
> ---
> base-commit: 58ba80c4740212c29a1cf9b48f588e60a7612209
> change-id: 20250708-syncfile-enable-signaling-a993acff1860
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status
2025-07-08 14:20 ` Christian König
@ 2025-07-09 1:28 ` Mikko Perttunen
0 siblings, 0 replies; 5+ messages in thread
From: Mikko Perttunen @ 2025-07-09 1:28 UTC (permalink / raw)
To: Christian König, Sumit Semwal, Gustavo Padovan
Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel,
Mikko Perttunen
On 7/8/25 11:20 PM, Christian König wrote:
> On 08.07.25 14:03, Mikko Perttunen wrote:
>> From: Mikko Perttunen <mperttunen@nvidia.com>
>>
>> dma_fence_get_status is not guaranteed to return valid information
>> on if the fence has been signaled or not if SW signaling has not
>> been enabled for the fence. To ensure valid information is reported,
>> enable SW signaling for fences before getting their status.
>
> I don't know how often I had to rejected that patch now, we really need to improve the documentation :(
Sorry :(
Improved documentation certainly would be good. I've thought of SW
signaling as a kernel-side 'optimization' and not something that would
be visible to the user space. Perhaps documentation could also mention
situations where calling this without enabling signaling is useful.
Anyway, I'll fix our issue in userspace by adding the zero-timeout poll
instead.
Thanks!
Mikko
>
> The fence info query exists to query the status *without* enabling signaling, that is the whole purpose of the function!
>
> If you want to enable signaling *and* query the status then just poll on the sync file file descriptor with a zero timeout.
>
> If the signaling timestamp or error code is needed then that can be retrieved after signaling through the info IOCTL.
>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
>> ---
>> drivers/dma-buf/sync_file.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
>> index 747e377fb95417ddd506b528618a4288bea9d459..a6fd1d14dde155561b9fd2c07e6aa20dc9863a8d 100644
>> --- a/drivers/dma-buf/sync_file.c
>> +++ b/drivers/dma-buf/sync_file.c
>> @@ -271,6 +271,8 @@ static int sync_fill_fence_info(struct dma_fence *fence,
>> const char __rcu *timeline;
>> const char __rcu *driver;
>>
>> + dma_fence_enable_sw_signaling(fence);
>> +
>> rcu_read_lock();
>>
>> driver = dma_fence_driver_name(fence);
>> @@ -320,6 +322,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
>> * info->num_fences.
>> */
>> if (!info.num_fences) {
>> + dma_fence_enable_sw_signaling(sync_file->fence);
>> info.status = dma_fence_get_status(sync_file->fence);
>> goto no_fences;
>> } else {
>>
>> ---
>> base-commit: 58ba80c4740212c29a1cf9b48f588e60a7612209
>> change-id: 20250708-syncfile-enable-signaling-a993acff1860
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-09 1:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08 12:03 [PATCH] dma_buf/sync_file: Enable signaling for fences when querying status Mikko Perttunen
2025-07-08 14:20 ` Christian König
2025-07-09 1:28 ` Mikko Perttunen
-- strict thread matches above, loose matches on Subject: below --
2023-07-25 7:46 Mikko Perttunen
2023-09-01 9:37 ` Mikko Perttunen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox