All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-buf: cma_heap: Fix mutex locking section
@ 2022-01-04  7:35 ` Weizhao Ouyang
  0 siblings, 0 replies; 8+ messages in thread
From: Weizhao Ouyang @ 2022-01-04  7:35 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, christian.koenig
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel, Weizhao Ouyang

Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
and vaddr.

Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
---
 drivers/dma-buf/heaps/cma_heap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..83f02bd51dda 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
 	struct cma_heap_buffer *buffer = dmabuf->priv;
 	struct dma_heap_attachment *a;
 
+	mutex_lock(&buffer->lock);
+
 	if (buffer->vmap_cnt)
 		invalidate_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-	mutex_lock(&buffer->lock);
 	list_for_each_entry(a, &buffer->attachments, list) {
 		if (!a->mapped)
 			continue;
@@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
 	struct cma_heap_buffer *buffer = dmabuf->priv;
 	struct dma_heap_attachment *a;
 
+	mutex_lock(&buffer->lock);
+
 	if (buffer->vmap_cnt)
 		flush_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-	mutex_lock(&buffer->lock);
 	list_for_each_entry(a, &buffer->attachments, list) {
 		if (!a->mapped)
 			continue;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] dma-buf: cma_heap: Fix mutex locking section
@ 2022-01-04  7:35 ` Weizhao Ouyang
  0 siblings, 0 replies; 8+ messages in thread
From: Weizhao Ouyang @ 2022-01-04  7:35 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, christian.koenig
  Cc: linaro-mm-sig, Weizhao Ouyang, linux-kernel, dri-devel, linux-media

Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
and vaddr.

Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
---
 drivers/dma-buf/heaps/cma_heap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 0c05b79870f9..83f02bd51dda 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
 	struct cma_heap_buffer *buffer = dmabuf->priv;
 	struct dma_heap_attachment *a;
 
+	mutex_lock(&buffer->lock);
+
 	if (buffer->vmap_cnt)
 		invalidate_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-	mutex_lock(&buffer->lock);
 	list_for_each_entry(a, &buffer->attachments, list) {
 		if (!a->mapped)
 			continue;
@@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
 	struct cma_heap_buffer *buffer = dmabuf->priv;
 	struct dma_heap_attachment *a;
 
+	mutex_lock(&buffer->lock);
+
 	if (buffer->vmap_cnt)
 		flush_kernel_vmap_range(buffer->vaddr, buffer->len);
 
-	mutex_lock(&buffer->lock);
 	list_for_each_entry(a, &buffer->attachments, list) {
 		if (!a->mapped)
 			continue;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
  2022-01-04  7:35 ` Weizhao Ouyang
@ 2022-01-04  7:42   ` John Stultz
  -1 siblings, 0 replies; 8+ messages in thread
From: John Stultz @ 2022-01-04  7:42 UTC (permalink / raw)
  To: Weizhao Ouyang
  Cc: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, christian.koenig, linux-media, dri-devel,
	linaro-mm-sig, linux-kernel

On Mon, Jan 3, 2022 at 11:36 PM Weizhao Ouyang <o451686892@gmail.com> wrote:
>
> Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> and vaddr.
>
> Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>

Looks good to me!  Thanks so much for sending this in!

Acked-by: John Stultz <john.stultz@linaro.org>

thanks again
-john

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
@ 2022-01-04  7:42   ` John Stultz
  0 siblings, 0 replies; 8+ messages in thread
From: John Stultz @ 2022-01-04  7:42 UTC (permalink / raw)
  To: Weizhao Ouyang
  Cc: Benjamin Gaignard, dri-devel, linux-kernel, Liam Mark,
	linaro-mm-sig, Laura Abbott, christian.koenig, linux-media

On Mon, Jan 3, 2022 at 11:36 PM Weizhao Ouyang <o451686892@gmail.com> wrote:
>
> Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> and vaddr.
>
> Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>

Looks good to me!  Thanks so much for sending this in!

Acked-by: John Stultz <john.stultz@linaro.org>

thanks again
-john

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
  2022-01-04  7:42   ` John Stultz
@ 2022-01-13 11:07     ` Sumit Semwal
  -1 siblings, 0 replies; 8+ messages in thread
From: Sumit Semwal @ 2022-01-13 11:07 UTC (permalink / raw)
  To: John Stultz
  Cc: Weizhao Ouyang, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, christian.koenig, linux-media, dri-devel,
	linaro-mm-sig, linux-kernel

Hello Weizhao,

On Tue, 4 Jan 2022 at 13:13, John Stultz <john.stultz@linaro.org> wrote:
>
> On Mon, Jan 3, 2022 at 11:36 PM Weizhao Ouyang <o451686892@gmail.com> wrote:
> >
> > Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> > and vaddr.
> >
> > Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> > Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
>
> Looks good to me!  Thanks so much for sending this in!
Thanks for the patch; it's merged to drm-misc-fixes.
>
> Acked-by: John Stultz <john.stultz@linaro.org>
>
> thanks again
> -john


Best,
Sumit.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
@ 2022-01-13 11:07     ` Sumit Semwal
  0 siblings, 0 replies; 8+ messages in thread
From: Sumit Semwal @ 2022-01-13 11:07 UTC (permalink / raw)
  To: John Stultz
  Cc: Benjamin Gaignard, Weizhao Ouyang, dri-devel, linux-kernel,
	Liam Mark, linaro-mm-sig, Laura Abbott, christian.koenig,
	linux-media

Hello Weizhao,

On Tue, 4 Jan 2022 at 13:13, John Stultz <john.stultz@linaro.org> wrote:
>
> On Mon, Jan 3, 2022 at 11:36 PM Weizhao Ouyang <o451686892@gmail.com> wrote:
> >
> > Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> > and vaddr.
> >
> > Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> > Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
>
> Looks good to me!  Thanks so much for sending this in!
Thanks for the patch; it's merged to drm-misc-fixes.
>
> Acked-by: John Stultz <john.stultz@linaro.org>
>
> thanks again
> -john


Best,
Sumit.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
  2022-01-04  7:35 ` Weizhao Ouyang
@ 2022-01-19 15:05   ` Daniel Vetter
  -1 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2022-01-19 15:05 UTC (permalink / raw)
  To: Weizhao Ouyang
  Cc: Sumit Semwal, Benjamin Gaignard, Liam Mark, Laura Abbott,
	Brian Starkey, John Stultz, christian.koenig, linaro-mm-sig,
	linux-kernel, dri-devel, linux-media

On Tue, Jan 04, 2022 at 03:35:45PM +0800, Weizhao Ouyang wrote:
> Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> and vaddr.
> 
> Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
> ---
>  drivers/dma-buf/heaps/cma_heap.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
> index 0c05b79870f9..83f02bd51dda 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
>  	struct cma_heap_buffer *buffer = dmabuf->priv;
>  	struct dma_heap_attachment *a;
>  
> +	mutex_lock(&buffer->lock);
> +
>  	if (buffer->vmap_cnt)
>  		invalidate_kernel_vmap_range(buffer->vaddr, buffer->len);

Since this creates nesting with mm/, but optionally I think it'd be good
to prime lockdep so it knows about this. See e.g. dma_resv_lockdep() in
dma-resv.c, except I don't know offhand what the right lock for
invalidate_kernel_vmap_range is.
-Daniel


>  
> -	mutex_lock(&buffer->lock);
>  	list_for_each_entry(a, &buffer->attachments, list) {
>  		if (!a->mapped)
>  			continue;
> @@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
>  	struct cma_heap_buffer *buffer = dmabuf->priv;
>  	struct dma_heap_attachment *a;
>  
> +	mutex_lock(&buffer->lock);
> +
>  	if (buffer->vmap_cnt)
>  		flush_kernel_vmap_range(buffer->vaddr, buffer->len);
>  
> -	mutex_lock(&buffer->lock);
>  	list_for_each_entry(a, &buffer->attachments, list) {
>  		if (!a->mapped)
>  			continue;
> -- 
> 2.32.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section
@ 2022-01-19 15:05   ` Daniel Vetter
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2022-01-19 15:05 UTC (permalink / raw)
  To: Weizhao Ouyang
  Cc: Benjamin Gaignard, christian.koenig, dri-devel, linux-kernel,
	Liam Mark, linaro-mm-sig, Laura Abbott, linux-media

On Tue, Jan 04, 2022 at 03:35:45PM +0800, Weizhao Ouyang wrote:
> Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt
> and vaddr.
> 
> Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
> Signed-off-by: Weizhao Ouyang <o451686892@gmail.com>
> ---
>  drivers/dma-buf/heaps/cma_heap.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
> index 0c05b79870f9..83f02bd51dda 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
>  	struct cma_heap_buffer *buffer = dmabuf->priv;
>  	struct dma_heap_attachment *a;
>  
> +	mutex_lock(&buffer->lock);
> +
>  	if (buffer->vmap_cnt)
>  		invalidate_kernel_vmap_range(buffer->vaddr, buffer->len);

Since this creates nesting with mm/, but optionally I think it'd be good
to prime lockdep so it knows about this. See e.g. dma_resv_lockdep() in
dma-resv.c, except I don't know offhand what the right lock for
invalidate_kernel_vmap_range is.
-Daniel


>  
> -	mutex_lock(&buffer->lock);
>  	list_for_each_entry(a, &buffer->attachments, list) {
>  		if (!a->mapped)
>  			continue;
> @@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
>  	struct cma_heap_buffer *buffer = dmabuf->priv;
>  	struct dma_heap_attachment *a;
>  
> +	mutex_lock(&buffer->lock);
> +
>  	if (buffer->vmap_cnt)
>  		flush_kernel_vmap_range(buffer->vaddr, buffer->len);
>  
> -	mutex_lock(&buffer->lock);
>  	list_for_each_entry(a, &buffer->attachments, list) {
>  		if (!a->mapped)
>  			continue;
> -- 
> 2.32.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-01-19 15:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04  7:35 [PATCH] dma-buf: cma_heap: Fix mutex locking section Weizhao Ouyang
2022-01-04  7:35 ` Weizhao Ouyang
2022-01-04  7:42 ` John Stultz
2022-01-04  7:42   ` John Stultz
2022-01-13 11:07   ` Sumit Semwal
2022-01-13 11:07     ` Sumit Semwal
2022-01-19 15:05 ` Daniel Vetter
2022-01-19 15:05   ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.