diff mbox series

dma-buf: keep the signaling time of merged fences

Message ID 20230621073204.28459-1-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series dma-buf: keep the signaling time of merged fences | expand

Commit Message

Christian König June 21, 2023, 7:32 a.m. UTC
Some Android CTS is testing for that.

Signed-off-by: Christian König <christian.koenig@amd.com>
CC: stable@vger.kernel.org
---
 drivers/dma-buf/dma-fence-unwrap.c | 11 +++++++++--
 drivers/dma-buf/dma-fence.c        |  5 +++--
 drivers/gpu/drm/drm_syncobj.c      |  2 +-
 include/linux/dma-fence.h          |  2 +-
 4 files changed, 14 insertions(+), 6 deletions(-)

Comments

Greg Kroah-Hartman June 21, 2023, 11:02 a.m. UTC | #1
On Wed, Jun 21, 2023 at 09:32:04AM +0200, Christian König wrote:
> Some Android CTS is testing for that.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> CC: stable@vger.kernel.org
> ---
>  drivers/dma-buf/dma-fence-unwrap.c | 11 +++++++++--
>  drivers/dma-buf/dma-fence.c        |  5 +++--
>  drivers/gpu/drm/drm_syncobj.c      |  2 +-
>  include/linux/dma-fence.h          |  2 +-
>  4 files changed, 14 insertions(+), 6 deletions(-)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- You did not specify a description of why the patch is needed, or
  possibly, any description at all, in the email body.  Please read the
  section entitled "The canonical patch format" in the kernel file,
  Documentation/process/submitting-patches.rst for what is needed in
  order to properly describe the change.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot
Greg Kroah-Hartman June 21, 2023, 11:02 a.m. UTC | #2
On Wed, Jun 21, 2023 at 09:32:04AM +0200, Christian König wrote:
> Some Android CTS is testing for that.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> CC: stable@vger.kernel.org

What commit id does this fix?

thanks,

greg k-h
Christian König June 21, 2023, 12:05 p.m. UTC | #3
Am 21.06.23 um 13:02 schrieb Greg KH:
> On Wed, Jun 21, 2023 at 09:32:04AM +0200, Christian König wrote:
>> Some Android CTS is testing for that.
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> CC: stable@vger.kernel.org
> What commit id does this fix?

Sorry Greg, totally unintentionally send this CC to the stable list 
because git wasn't correctly configured.

The patch is still under review.

Regards,
Christian.

>
> thanks,
>
> greg k-h
Greg Kroah-Hartman June 21, 2023, 12:35 p.m. UTC | #4
On Wed, Jun 21, 2023 at 02:05:07PM +0200, Christian König wrote:
> Am 21.06.23 um 13:02 schrieb Greg KH:
> > On Wed, Jun 21, 2023 at 09:32:04AM +0200, Christian König wrote:
> > > Some Android CTS is testing for that.
> > > 
> > > Signed-off-by: Christian König <christian.koenig@amd.com>
> > > CC: stable@vger.kernel.org
> > What commit id does this fix?
> 
> Sorry Greg, totally unintentionally send this CC to the stable list because
> git wasn't correctly configured.

It's fine to cc: the stable list, we WANT to see patches that are being
sent out like this before they hit the maintainers tree as you get more
review of them.

So no need to change your git configuration, this is fine.

> The patch is still under review.

Agreed, which is why it should be fixed :)

thanks,

greg k-h
Christian König June 22, 2023, 2:44 p.m. UTC | #5
Alex, Luben or somebody else at least a bit familiar with that, can I 
get a quick rb or acked-by?

This is an important bug fix for Android CTS.

Thanks,
Christian.

Am 21.06.23 um 09:32 schrieb Christian König:
> Some Android CTS is testing for that.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> CC: stable@vger.kernel.org
> ---
>   drivers/dma-buf/dma-fence-unwrap.c | 11 +++++++++--
>   drivers/dma-buf/dma-fence.c        |  5 +++--
>   drivers/gpu/drm/drm_syncobj.c      |  2 +-
>   include/linux/dma-fence.h          |  2 +-
>   4 files changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c
> index 7002bca792ff..06eb91306c01 100644
> --- a/drivers/dma-buf/dma-fence-unwrap.c
> +++ b/drivers/dma-buf/dma-fence-unwrap.c
> @@ -66,18 +66,25 @@ struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
>   {
>   	struct dma_fence_array *result;
>   	struct dma_fence *tmp, **array;
> +	ktime_t timestamp;
>   	unsigned int i;
>   	size_t count;
>   
>   	count = 0;
> +	timestamp = ns_to_ktime(0);
>   	for (i = 0; i < num_fences; ++i) {
> -		dma_fence_unwrap_for_each(tmp, &iter[i], fences[i])
> +		dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) {
>   			if (!dma_fence_is_signaled(tmp))
>   				++count;
> +			else if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
> +					  &tmp->flags) &&
> +				 ktime_after(tmp->timestamp, timestamp))
> +				timestamp = tmp->timestamp;
> +		}
>   	}
>   
>   	if (count == 0)
> -		return dma_fence_get_stub();
> +		return dma_fence_allocate_private_stub(timestamp);
>   
>   	array = kmalloc_array(count, sizeof(*array), GFP_KERNEL);
>   	if (!array)
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index f177c56269bb..ad076f208760 100644
> --- a/drivers/dma-buf/dma-fence.c
> +++ b/drivers/dma-buf/dma-fence.c
> @@ -150,10 +150,11 @@ EXPORT_SYMBOL(dma_fence_get_stub);
>   
>   /**
>    * dma_fence_allocate_private_stub - return a private, signaled fence
> + * @timestamp: timestamp when the fence was signaled
>    *
>    * Return a newly allocated and signaled stub fence.
>    */
> -struct dma_fence *dma_fence_allocate_private_stub(void)
> +struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp)
>   {
>   	struct dma_fence *fence;
>   
> @@ -169,7 +170,7 @@ struct dma_fence *dma_fence_allocate_private_stub(void)
>   	set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
>   		&fence->flags);
>   
> -	dma_fence_signal(fence);
> +	dma_fence_signal_timestamp(fence, timestamp);
>   
>   	return fence;
>   }
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 0c2be8360525..04589a35eb09 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -353,7 +353,7 @@ EXPORT_SYMBOL(drm_syncobj_replace_fence);
>    */
>   static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
>   {
> -	struct dma_fence *fence = dma_fence_allocate_private_stub();
> +	struct dma_fence *fence = dma_fence_allocate_private_stub(ktime_get());
>   
>   	if (IS_ERR(fence))
>   		return PTR_ERR(fence);
> diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
> index d54b595a0fe0..0d678e9a7b24 100644
> --- a/include/linux/dma-fence.h
> +++ b/include/linux/dma-fence.h
> @@ -606,7 +606,7 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr)
>   void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline);
>   
>   struct dma_fence *dma_fence_get_stub(void);
> -struct dma_fence *dma_fence_allocate_private_stub(void);
> +struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp);
>   u64 dma_fence_context_alloc(unsigned num);
>   
>   extern const struct dma_fence_ops dma_fence_array_ops;
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c
index 7002bca792ff..06eb91306c01 100644
--- a/drivers/dma-buf/dma-fence-unwrap.c
+++ b/drivers/dma-buf/dma-fence-unwrap.c
@@ -66,18 +66,25 @@  struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
 {
 	struct dma_fence_array *result;
 	struct dma_fence *tmp, **array;
+	ktime_t timestamp;
 	unsigned int i;
 	size_t count;
 
 	count = 0;
+	timestamp = ns_to_ktime(0);
 	for (i = 0; i < num_fences; ++i) {
-		dma_fence_unwrap_for_each(tmp, &iter[i], fences[i])
+		dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) {
 			if (!dma_fence_is_signaled(tmp))
 				++count;
+			else if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
+					  &tmp->flags) &&
+				 ktime_after(tmp->timestamp, timestamp))
+				timestamp = tmp->timestamp;
+		}
 	}
 
 	if (count == 0)
-		return dma_fence_get_stub();
+		return dma_fence_allocate_private_stub(timestamp);
 
 	array = kmalloc_array(count, sizeof(*array), GFP_KERNEL);
 	if (!array)
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index f177c56269bb..ad076f208760 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -150,10 +150,11 @@  EXPORT_SYMBOL(dma_fence_get_stub);
 
 /**
  * dma_fence_allocate_private_stub - return a private, signaled fence
+ * @timestamp: timestamp when the fence was signaled
  *
  * Return a newly allocated and signaled stub fence.
  */
-struct dma_fence *dma_fence_allocate_private_stub(void)
+struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp)
 {
 	struct dma_fence *fence;
 
@@ -169,7 +170,7 @@  struct dma_fence *dma_fence_allocate_private_stub(void)
 	set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
 		&fence->flags);
 
-	dma_fence_signal(fence);
+	dma_fence_signal_timestamp(fence, timestamp);
 
 	return fence;
 }
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 0c2be8360525..04589a35eb09 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -353,7 +353,7 @@  EXPORT_SYMBOL(drm_syncobj_replace_fence);
  */
 static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
 {
-	struct dma_fence *fence = dma_fence_allocate_private_stub();
+	struct dma_fence *fence = dma_fence_allocate_private_stub(ktime_get());
 
 	if (IS_ERR(fence))
 		return PTR_ERR(fence);
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index d54b595a0fe0..0d678e9a7b24 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -606,7 +606,7 @@  static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr)
 void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline);
 
 struct dma_fence *dma_fence_get_stub(void);
-struct dma_fence *dma_fence_allocate_private_stub(void);
+struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp);
 u64 dma_fence_context_alloc(unsigned num);
 
 extern const struct dma_fence_ops dma_fence_array_ops;