[PATCH 01/11] misc: fastrpc: Assert held reservation lock for dma-buf mmapping

Srinivas Kandagatla posted 11 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 01/11] misc: fastrpc: Assert held reservation lock for dma-buf mmapping
Posted by Srinivas Kandagatla 2 months, 1 week ago
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>

When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
held. Add locking sanity check to the dma-buf mmaping callback to ensure
that the locking assumption won't regress in the future.

Suggested-by: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 80811e852d8f..c6b9ddaa698b 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -6,6 +6,7 @@
 #include <linux/device.h>
 #include <linux/dma-buf.h>
 #include <linux/dma-mapping.h>
+#include <linux/dma-resv.h>
 #include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/miscdevice.h>
@@ -692,6 +693,8 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,
 	struct fastrpc_buf *buf = dmabuf->priv;
 	size_t size = vma->vm_end - vma->vm_start;
 
+	dma_resv_assert_held(dmabuf->resv);
+
 	return dma_mmap_coherent(buf->dev, vma, buf->virt,
 				 FASTRPC_PHYS(buf->phys), size);
 }
-- 
2.25.1
Re: [PATCH 01/11] misc: fastrpc: Assert held reservation lock for dma-buf mmapping
Posted by Dmitry Osipenko 2 months, 1 week ago
On 11/24/22 20:51, Srinivas Kandagatla wrote:
> From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> 
> When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
> held. Add locking sanity check to the dma-buf mmaping callback to ensure
> that the locking assumption won't regress in the future.
> 
> Suggested-by: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
>  drivers/misc/fastrpc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 80811e852d8f..c6b9ddaa698b 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -6,6 +6,7 @@
>  #include <linux/device.h>
>  #include <linux/dma-buf.h>
>  #include <linux/dma-mapping.h>
> +#include <linux/dma-resv.h>
>  #include <linux/idr.h>
>  #include <linux/list.h>
>  #include <linux/miscdevice.h>
> @@ -692,6 +693,8 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,
>  	struct fastrpc_buf *buf = dmabuf->priv;
>  	size_t size = vma->vm_end - vma->vm_start;
>  
> +	dma_resv_assert_held(dmabuf->resv);
> +
>  	return dma_mmap_coherent(buf->dev, vma, buf->virt,
>  				 FASTRPC_PHYS(buf->phys), size);
>  }

This patch was already applied to DRM tree together with the rest of
prerequisite dma-buf patches. IOW, it shouldn't be applied separately
via the misc tree.

-- 
Best regards,
Dmitry
Re: [PATCH 01/11] misc: fastrpc: Assert held reservation lock for dma-buf mmapping
Posted by Srinivas Kandagatla 2 months, 1 week ago

On 24/11/2022 18:03, Dmitry Osipenko wrote:
> On 11/24/22 20:51, Srinivas Kandagatla wrote:
>> From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>>
>> When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
>> held. Add locking sanity check to the dma-buf mmaping callback to ensure
>> that the locking assumption won't regress in the future.
>>
>> Suggested-by: Daniel Vetter <daniel@ffwll.ch>
>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
>> ---
>>   drivers/misc/fastrpc.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
>> index 80811e852d8f..c6b9ddaa698b 100644
>> --- a/drivers/misc/fastrpc.c
>> +++ b/drivers/misc/fastrpc.c
>> @@ -6,6 +6,7 @@
>>   #include <linux/device.h>
>>   #include <linux/dma-buf.h>
>>   #include <linux/dma-mapping.h>
>> +#include <linux/dma-resv.h>
>>   #include <linux/idr.h>
>>   #include <linux/list.h>
>>   #include <linux/miscdevice.h>
>> @@ -692,6 +693,8 @@ static int fastrpc_mmap(struct dma_buf *dmabuf,
>>   	struct fastrpc_buf *buf = dmabuf->priv;
>>   	size_t size = vma->vm_end - vma->vm_start;
>>   
>> +	dma_resv_assert_held(dmabuf->resv);
>> +
>>   	return dma_mmap_coherent(buf->dev, vma, buf->virt,
>>   				 FASTRPC_PHYS(buf->phys), size);
>>   }
> 
> This patch was already applied to DRM tree together with the rest of
> prerequisite dma-buf patches. IOW, it shouldn't be applied separately
> via the misc tree.
thanks, that is true.



---srini

>