* [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap
[not found] <20200511093554.211493-1-daniel.vetter@ffwll.ch>
@ 2020-05-11 9:35 ` Daniel Vetter
2020-05-11 15:24 ` Rob Clark
2020-05-14 20:11 ` [PATCH] " Daniel Vetter
0 siblings, 2 replies; 8+ messages in thread
From: Daniel Vetter @ 2020-05-11 9:35 UTC (permalink / raw)
To: DRI Development
Cc: Intel Graphics Development, Daniel Vetter, Daniel Vetter,
Rob Clark, Sean Paul, linux-arm-msm, freedreno
I honestly don't exactly understand what's going on here, but the
current code is wrong for sure: It calls dma_buf_vunmap without ever
calling dma_buf_vmap.
What I'm not sure about is whether the WARN_ON is correct:
- msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
a pretty neat layering violation of how you shouldn't peek behind
the curtain of the dma-buf exporter, but par for course. Note that
all the nice new helpers don't (and we should probably have a bit a
warning about this in the kerneldoc).
- but then in the get_vaddr() in msm_gem.c, and that seems to happily
wrap a vmap() around any object with ->pages set (so including
imported dma-buf)
- I'm not seeing any guarantees that userspace can't use an imported
dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
guarantees that an imported dma-buf won't end up with a ->vaddr set.
But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
calling dma_buf_vmap is the wrong thing to do.
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <sean@poorly.run>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
---
drivers/gpu/drm/msm/msm_gem.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 5a6a79fbc9d6..3305a457960e 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -907,8 +907,7 @@ static void free_object(struct msm_gem_object *msm_obj)
put_iova(obj);
if (obj->import_attach) {
- if (msm_obj->vaddr)
- dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
+ WARN_ON(msm_obj->vaddr);
/* Don't drop the pages for imported dmabuf, as they are not
* ours, just free the array we allocated:
--
2.26.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-11 9:35 ` [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap Daniel Vetter
@ 2020-05-11 15:24 ` Rob Clark
2020-05-11 15:28 ` Daniel Vetter
2020-05-14 20:11 ` [PATCH] " Daniel Vetter
1 sibling, 1 reply; 8+ messages in thread
From: Rob Clark @ 2020-05-11 15:24 UTC (permalink / raw)
To: Daniel Vetter
Cc: DRI Development, Intel Graphics Development, Daniel Vetter,
Sean Paul, linux-arm-msm, freedreno
On Mon, May 11, 2020 at 2:36 AM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> I honestly don't exactly understand what's going on here, but the
> current code is wrong for sure: It calls dma_buf_vunmap without ever
> calling dma_buf_vmap.
>
> What I'm not sure about is whether the WARN_ON is correct:
> - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> a pretty neat layering violation of how you shouldn't peek behind
> the curtain of the dma-buf exporter, but par for course. Note that
> all the nice new helpers don't (and we should probably have a bit a
> warning about this in the kerneldoc).
>
> - but then in the get_vaddr() in msm_gem.c, and that seems to happily
> wrap a vmap() around any object with ->pages set (so including
> imported dma-buf)
>
> - I'm not seeing any guarantees that userspace can't use an imported
> dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> guarantees that an imported dma-buf won't end up with a ->vaddr set.
fwiw, a5xx_submit_in_rb() isn't a "normal" path (build-time disabled
by default, and restricted to sudo).. it really only exists to
simplify poking at fw.
There could be vmap's in the msm_gem_submit path, however. If we
don't, we should probably just disallow using an imported dma-buf as
cmdstream.. I don't think there is any sane reason to permit that. We
should probably also disallow get_vaddr() on imported buffers.
BR,
-R
>
> But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> calling dma_buf_vmap is the wrong thing to do.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: freedreno@lists.freedesktop.org
> ---
> drivers/gpu/drm/msm/msm_gem.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 5a6a79fbc9d6..3305a457960e 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -907,8 +907,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> put_iova(obj);
>
> if (obj->import_attach) {
> - if (msm_obj->vaddr)
> - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> + WARN_ON(msm_obj->vaddr);
>
> /* Don't drop the pages for imported dmabuf, as they are not
> * ours, just free the array we allocated:
> --
> 2.26.2
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-11 15:24 ` Rob Clark
@ 2020-05-11 15:28 ` Daniel Vetter
2020-05-11 20:36 ` Rob Clark
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2020-05-11 15:28 UTC (permalink / raw)
To: Rob Clark
Cc: DRI Development, Intel Graphics Development, Daniel Vetter,
Sean Paul, linux-arm-msm, freedreno
On Mon, May 11, 2020 at 5:24 PM Rob Clark <robdclark@gmail.com> wrote:
>
> On Mon, May 11, 2020 at 2:36 AM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> >
> > I honestly don't exactly understand what's going on here, but the
> > current code is wrong for sure: It calls dma_buf_vunmap without ever
> > calling dma_buf_vmap.
> >
> > What I'm not sure about is whether the WARN_ON is correct:
> > - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> > a pretty neat layering violation of how you shouldn't peek behind
> > the curtain of the dma-buf exporter, but par for course. Note that
> > all the nice new helpers don't (and we should probably have a bit a
> > warning about this in the kerneldoc).
> >
> > - but then in the get_vaddr() in msm_gem.c, and that seems to happily
> > wrap a vmap() around any object with ->pages set (so including
> > imported dma-buf)
> >
> > - I'm not seeing any guarantees that userspace can't use an imported
> > dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> > guarantees that an imported dma-buf won't end up with a ->vaddr set.
>
> fwiw, a5xx_submit_in_rb() isn't a "normal" path (build-time disabled
> by default, and restricted to sudo).. it really only exists to
> simplify poking at fw.
>
> There could be vmap's in the msm_gem_submit path, however. If we
> don't, we should probably just disallow using an imported dma-buf as
> cmdstream.. I don't think there is any sane reason to permit that. We
> should probably also disallow get_vaddr() on imported buffers.
Yeah if that's possible and won't blow up (I can't test) I think it'd
be best. Something like
if (bo->import_attach) return NULL; should do the trick I think.
Should I type that up as v2 of this?
-Daniel
>
> BR,
> -R
>
> >
> > But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> > calling dma_buf_vmap is the wrong thing to do.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Rob Clark <robdclark@gmail.com>
> > Cc: Sean Paul <sean@poorly.run>
> > Cc: linux-arm-msm@vger.kernel.org
> > Cc: freedreno@lists.freedesktop.org
> > ---
> > drivers/gpu/drm/msm/msm_gem.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> > index 5a6a79fbc9d6..3305a457960e 100644
> > --- a/drivers/gpu/drm/msm/msm_gem.c
> > +++ b/drivers/gpu/drm/msm/msm_gem.c
> > @@ -907,8 +907,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> > put_iova(obj);
> >
> > if (obj->import_attach) {
> > - if (msm_obj->vaddr)
> > - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> > + WARN_ON(msm_obj->vaddr);
> >
> > /* Don't drop the pages for imported dmabuf, as they are not
> > * ours, just free the array we allocated:
> > --
> > 2.26.2
> >
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-11 15:28 ` Daniel Vetter
@ 2020-05-11 20:36 ` Rob Clark
0 siblings, 0 replies; 8+ messages in thread
From: Rob Clark @ 2020-05-11 20:36 UTC (permalink / raw)
To: Daniel Vetter
Cc: DRI Development, Intel Graphics Development, Daniel Vetter,
Sean Paul, linux-arm-msm, freedreno
On Mon, May 11, 2020 at 8:29 AM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> On Mon, May 11, 2020 at 5:24 PM Rob Clark <robdclark@gmail.com> wrote:
> >
> > On Mon, May 11, 2020 at 2:36 AM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > >
> > > I honestly don't exactly understand what's going on here, but the
> > > current code is wrong for sure: It calls dma_buf_vunmap without ever
> > > calling dma_buf_vmap.
> > >
> > > What I'm not sure about is whether the WARN_ON is correct:
> > > - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> > > a pretty neat layering violation of how you shouldn't peek behind
> > > the curtain of the dma-buf exporter, but par for course. Note that
> > > all the nice new helpers don't (and we should probably have a bit a
> > > warning about this in the kerneldoc).
> > >
> > > - but then in the get_vaddr() in msm_gem.c, and that seems to happily
> > > wrap a vmap() around any object with ->pages set (so including
> > > imported dma-buf)
> > >
> > > - I'm not seeing any guarantees that userspace can't use an imported
> > > dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> > > guarantees that an imported dma-buf won't end up with a ->vaddr set.
> >
> > fwiw, a5xx_submit_in_rb() isn't a "normal" path (build-time disabled
> > by default, and restricted to sudo).. it really only exists to
> > simplify poking at fw.
> >
> > There could be vmap's in the msm_gem_submit path, however. If we
> > don't, we should probably just disallow using an imported dma-buf as
> > cmdstream.. I don't think there is any sane reason to permit that. We
> > should probably also disallow get_vaddr() on imported buffers.
>
> Yeah if that's possible and won't blow up (I can't test) I think it'd
> be best. Something like
> if (bo->import_attach) return NULL; should do the trick I think.
> Should I type that up as v2 of this?
Sure. It should probably be something like
if (obj->import_attach)
return ERR_PTR(-ESOMETHING)
looks like the gem-submit path handles an IS_ERR() return
BR,
-R
> -Daniel
>
> >
> > BR,
> > -R
> >
> > >
> > > But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> > > calling dma_buf_vmap is the wrong thing to do.
> > >
> > > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > > Cc: Rob Clark <robdclark@gmail.com>
> > > Cc: Sean Paul <sean@poorly.run>
> > > Cc: linux-arm-msm@vger.kernel.org
> > > Cc: freedreno@lists.freedesktop.org
> > > ---
> > > drivers/gpu/drm/msm/msm_gem.c | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> > > index 5a6a79fbc9d6..3305a457960e 100644
> > > --- a/drivers/gpu/drm/msm/msm_gem.c
> > > +++ b/drivers/gpu/drm/msm/msm_gem.c
> > > @@ -907,8 +907,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> > > put_iova(obj);
> > >
> > > if (obj->import_attach) {
> > > - if (msm_obj->vaddr)
> > > - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> > > + WARN_ON(msm_obj->vaddr);
> > >
> > > /* Don't drop the pages for imported dmabuf, as they are not
> > > * ours, just free the array we allocated:
> > > --
> > > 2.26.2
> > >
>
>
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> +41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-11 9:35 ` [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap Daniel Vetter
2020-05-11 15:24 ` Rob Clark
@ 2020-05-14 20:11 ` Daniel Vetter
2020-05-28 8:29 ` Daniel Vetter
2020-05-31 16:02 ` Rob Clark
1 sibling, 2 replies; 8+ messages in thread
From: Daniel Vetter @ 2020-05-14 20:11 UTC (permalink / raw)
To: DRI Development
Cc: Daniel Vetter, Daniel Vetter, Rob Clark, Sean Paul, linux-arm-msm,
freedreno
I honestly don't exactly understand what's going on here, but the
current code is wrong for sure: It calls dma_buf_vunmap without ever
calling dma_buf_vmap.
What I'm not sure about is whether the WARN_ON is correct:
- msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
a pretty neat layering violation of how you shouldn't peek behind
the curtain of the dma-buf exporter, but par for course. Note that
all the nice new helpers don't (and we should probably have a bit a
warning about this in the kerneldoc).
- but then in the get_vaddr() in msm_gem.c, we seems to happily wrap a
vmap() around any object with ->pages set (so including imported
dma-buf).
- I'm not seeing any guarantees that userspace can't use an imported
dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
guarantees that an imported dma-buf won't end up with a ->vaddr set.
But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
calling dma_buf_vunmap is the wrong thing to do.
v2: Rob said in review that we do indeed have a gap in get_vaddr() that
needs to be plugged. But the users I've found aren't legit users on
imported dma-buf, so we can just reject that.
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <sean@poorly.run>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
---
drivers/gpu/drm/msm/msm_gem.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 5a6a79fbc9d6..e70abd1cde43 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -554,6 +554,9 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
struct msm_gem_object *msm_obj = to_msm_bo(obj);
int ret = 0;
+ if (obj->import_attach)
+ return ERR_PTR(-ENODEV);
+
mutex_lock(&msm_obj->lock);
if (WARN_ON(msm_obj->madv > madv)) {
@@ -907,8 +910,7 @@ static void free_object(struct msm_gem_object *msm_obj)
put_iova(obj);
if (obj->import_attach) {
- if (msm_obj->vaddr)
- dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
+ WARN_ON(msm_obj->vaddr);
/* Don't drop the pages for imported dmabuf, as they are not
* ours, just free the array we allocated:
--
2.26.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-14 20:11 ` [PATCH] " Daniel Vetter
@ 2020-05-28 8:29 ` Daniel Vetter
2020-05-31 16:02 ` Rob Clark
1 sibling, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2020-05-28 8:29 UTC (permalink / raw)
To: DRI Development
Cc: Daniel Vetter, Daniel Vetter, Rob Clark, Sean Paul, linux-arm-msm,
freedreno
On Thu, May 14, 2020 at 10:11:17PM +0200, Daniel Vetter wrote:
> I honestly don't exactly understand what's going on here, but the
> current code is wrong for sure: It calls dma_buf_vunmap without ever
> calling dma_buf_vmap.
>
> What I'm not sure about is whether the WARN_ON is correct:
> - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> a pretty neat layering violation of how you shouldn't peek behind
> the curtain of the dma-buf exporter, but par for course. Note that
> all the nice new helpers don't (and we should probably have a bit a
> warning about this in the kerneldoc).
>
> - but then in the get_vaddr() in msm_gem.c, we seems to happily wrap a
> vmap() around any object with ->pages set (so including imported
> dma-buf).
>
> - I'm not seeing any guarantees that userspace can't use an imported
> dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> guarantees that an imported dma-buf won't end up with a ->vaddr set.
>
> But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> calling dma_buf_vunmap is the wrong thing to do.
>
> v2: Rob said in review that we do indeed have a gap in get_vaddr() that
> needs to be plugged. But the users I've found aren't legit users on
> imported dma-buf, so we can just reject that.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: freedreno@lists.freedesktop.org
Ping for some review/ack so I can start landing thist stuff please?
Thanks, Daniel
> ---
> drivers/gpu/drm/msm/msm_gem.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 5a6a79fbc9d6..e70abd1cde43 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -554,6 +554,9 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
> struct msm_gem_object *msm_obj = to_msm_bo(obj);
> int ret = 0;
>
> + if (obj->import_attach)
> + return ERR_PTR(-ENODEV);
> +
> mutex_lock(&msm_obj->lock);
>
> if (WARN_ON(msm_obj->madv > madv)) {
> @@ -907,8 +910,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> put_iova(obj);
>
> if (obj->import_attach) {
> - if (msm_obj->vaddr)
> - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> + WARN_ON(msm_obj->vaddr);
>
> /* Don't drop the pages for imported dmabuf, as they are not
> * ours, just free the array we allocated:
> --
> 2.26.2
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-14 20:11 ` [PATCH] " Daniel Vetter
2020-05-28 8:29 ` Daniel Vetter
@ 2020-05-31 16:02 ` Rob Clark
2020-06-03 12:46 ` Daniel Vetter
1 sibling, 1 reply; 8+ messages in thread
From: Rob Clark @ 2020-05-31 16:02 UTC (permalink / raw)
To: Daniel Vetter
Cc: DRI Development, Daniel Vetter, Sean Paul, linux-arm-msm,
freedreno
On Thu, May 14, 2020 at 1:11 PM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>
> I honestly don't exactly understand what's going on here, but the
> current code is wrong for sure: It calls dma_buf_vunmap without ever
> calling dma_buf_vmap.
>
> What I'm not sure about is whether the WARN_ON is correct:
> - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> a pretty neat layering violation of how you shouldn't peek behind
> the curtain of the dma-buf exporter, but par for course. Note that
> all the nice new helpers don't (and we should probably have a bit a
> warning about this in the kerneldoc).
>
> - but then in the get_vaddr() in msm_gem.c, we seems to happily wrap a
> vmap() around any object with ->pages set (so including imported
> dma-buf).
>
> - I'm not seeing any guarantees that userspace can't use an imported
> dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> guarantees that an imported dma-buf won't end up with a ->vaddr set.
>
> But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> calling dma_buf_vunmap is the wrong thing to do.
>
> v2: Rob said in review that we do indeed have a gap in get_vaddr() that
> needs to be plugged. But the users I've found aren't legit users on
> imported dma-buf, so we can just reject that.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: freedreno@lists.freedesktop.org
Reviewed-by: Rob Clark <robdclark@gmail.com>
> ---
> drivers/gpu/drm/msm/msm_gem.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 5a6a79fbc9d6..e70abd1cde43 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -554,6 +554,9 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
> struct msm_gem_object *msm_obj = to_msm_bo(obj);
> int ret = 0;
>
> + if (obj->import_attach)
> + return ERR_PTR(-ENODEV);
> +
> mutex_lock(&msm_obj->lock);
>
> if (WARN_ON(msm_obj->madv > madv)) {
> @@ -907,8 +910,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> put_iova(obj);
>
> if (obj->import_attach) {
> - if (msm_obj->vaddr)
> - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> + WARN_ON(msm_obj->vaddr);
>
> /* Don't drop the pages for imported dmabuf, as they are not
> * ours, just free the array we allocated:
> --
> 2.26.2
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] drm/msm: Don't call dma_buf_vunmap without _vmap
2020-05-31 16:02 ` Rob Clark
@ 2020-06-03 12:46 ` Daniel Vetter
0 siblings, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2020-06-03 12:46 UTC (permalink / raw)
To: Rob Clark
Cc: Daniel Vetter, DRI Development, Daniel Vetter, Sean Paul,
linux-arm-msm, freedreno
On Sun, May 31, 2020 at 09:02:11AM -0700, Rob Clark wrote:
> On Thu, May 14, 2020 at 1:11 PM Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> >
> > I honestly don't exactly understand what's going on here, but the
> > current code is wrong for sure: It calls dma_buf_vunmap without ever
> > calling dma_buf_vmap.
> >
> > What I'm not sure about is whether the WARN_ON is correct:
> > - msm imports dma-buf using drm_prime_sg_to_page_addr_arrays. Which is
> > a pretty neat layering violation of how you shouldn't peek behind
> > the curtain of the dma-buf exporter, but par for course. Note that
> > all the nice new helpers don't (and we should probably have a bit a
> > warning about this in the kerneldoc).
> >
> > - but then in the get_vaddr() in msm_gem.c, we seems to happily wrap a
> > vmap() around any object with ->pages set (so including imported
> > dma-buf).
> >
> > - I'm not seeing any guarantees that userspace can't use an imported
> > dma-buf for e.g. MSM_SUBMIT_CMD_BUF in a5xx_submit_in_rb, so no
> > guarantees that an imported dma-buf won't end up with a ->vaddr set.
> >
> > But even if that WARN_ON is wrong, cleaning up a vmap() done by msm by
> > calling dma_buf_vunmap is the wrong thing to do.
> >
> > v2: Rob said in review that we do indeed have a gap in get_vaddr() that
> > needs to be plugged. But the users I've found aren't legit users on
> > imported dma-buf, so we can just reject that.
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Rob Clark <robdclark@gmail.com>
> > Cc: Sean Paul <sean@poorly.run>
> > Cc: linux-arm-msm@vger.kernel.org
> > Cc: freedreno@lists.freedesktop.org
>
> Reviewed-by: Rob Clark <robdclark@gmail.com>
Queued in drm-misc-next for 5.9, thanks for your review.
-Daniel
>
> > ---
> > drivers/gpu/drm/msm/msm_gem.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> > index 5a6a79fbc9d6..e70abd1cde43 100644
> > --- a/drivers/gpu/drm/msm/msm_gem.c
> > +++ b/drivers/gpu/drm/msm/msm_gem.c
> > @@ -554,6 +554,9 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
> > struct msm_gem_object *msm_obj = to_msm_bo(obj);
> > int ret = 0;
> >
> > + if (obj->import_attach)
> > + return ERR_PTR(-ENODEV);
> > +
> > mutex_lock(&msm_obj->lock);
> >
> > if (WARN_ON(msm_obj->madv > madv)) {
> > @@ -907,8 +910,7 @@ static void free_object(struct msm_gem_object *msm_obj)
> > put_iova(obj);
> >
> > if (obj->import_attach) {
> > - if (msm_obj->vaddr)
> > - dma_buf_vunmap(obj->import_attach->dmabuf, msm_obj->vaddr);
> > + WARN_ON(msm_obj->vaddr);
> >
> > /* Don't drop the pages for imported dmabuf, as they are not
> > * ours, just free the array we allocated:
> > --
> > 2.26.2
> >
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-06-03 12:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200511093554.211493-1-daniel.vetter@ffwll.ch>
2020-05-11 9:35 ` [PATCH 1/9] drm/msm: Don't call dma_buf_vunmap without _vmap Daniel Vetter
2020-05-11 15:24 ` Rob Clark
2020-05-11 15:28 ` Daniel Vetter
2020-05-11 20:36 ` Rob Clark
2020-05-14 20:11 ` [PATCH] " Daniel Vetter
2020-05-28 8:29 ` Daniel Vetter
2020-05-31 16:02 ` Rob Clark
2020-06-03 12:46 ` Daniel Vetter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox