2020-11-20 09:59:18

by Daniel Vetter

[permalink] [raw]
Subject: [PATCH] drm/ttm: don't set page->mapping

Random observation while trying to review Christian's patch series to
stop looking at struct page for dma-buf imports.

This was originally added in

commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
Author: Thomas Hellstrom <[email protected]>
Date: Fri Jan 3 11:47:23 2014 +0100

drm/ttm: Correctly set page mapping and -index members

Needed for some vm operations; most notably unmap_mapping_range() with
even_cows = 0.

Signed-off-by: Thomas Hellstrom <[email protected]>
Reviewed-by: Brian Paul <[email protected]>

but we do not have a single caller of unmap_mapping_range with
even_cows == 0. And all the gem drivers don't do this, so another
small thing we could standardize between drm and ttm drivers.

Plus I don't really see a need for unamp_mapping_range where we don't
want to indiscriminately shoot down all ptes.

Cc: Thomas Hellstrom <[email protected]>
Cc: Brian Paul <[email protected]>
Signed-off-by: Daniel Vetter <[email protected]>
Cc: Christian Koenig <[email protected]>
Cc: Huang Rui <[email protected]>
---
drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
1 file changed, 12 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index da9eeffe0c6d..5b2eb6d58bb7 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -284,17 +284,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
return ret;
}

-static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
-{
- pgoff_t i;
-
- if (ttm->page_flags & TTM_PAGE_FLAG_SG)
- return;
-
- for (i = 0; i < ttm->num_pages; ++i)
- ttm->pages[i]->mapping = bdev->dev_mapping;
-}
-
int ttm_tt_populate(struct ttm_bo_device *bdev,
struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
@@ -313,7 +302,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
if (ret)
return ret;

- ttm_tt_add_mapping(bdev, ttm);
ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
ret = ttm_tt_swapin(ttm);
--
2.29.2


2020-11-20 10:07:11

by Christian König

[permalink] [raw]
Subject: Re: [PATCH] drm/ttm: don't set page->mapping

Am 20.11.20 um 10:54 schrieb Daniel Vetter:
> Random observation while trying to review Christian's patch series to
> stop looking at struct page for dma-buf imports.
>
> This was originally added in
>
> commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
> Author: Thomas Hellstrom <[email protected]>
> Date: Fri Jan 3 11:47:23 2014 +0100
>
> drm/ttm: Correctly set page mapping and -index members
>
> Needed for some vm operations; most notably unmap_mapping_range() with
> even_cows = 0.
>
> Signed-off-by: Thomas Hellstrom <[email protected]>
> Reviewed-by: Brian Paul <[email protected]>
>
> but we do not have a single caller of unmap_mapping_range with
> even_cows == 0. And all the gem drivers don't do this, so another
> small thing we could standardize between drm and ttm drivers.
>
> Plus I don't really see a need for unamp_mapping_range where we don't
> want to indiscriminately shoot down all ptes.
>
> Cc: Thomas Hellstrom <[email protected]>
> Cc: Brian Paul <[email protected]>
> Signed-off-by: Daniel Vetter <[email protected]>
> Cc: Christian Koenig <[email protected]>
> Cc: Huang Rui <[email protected]>

This is still a NAK as long as we can't come up with a better way to
track TTMs page allocations.

Additional to that page_mapping() is used quite extensively in the mm
code and I'm not sure if that isn't needed for other stuff as well.

Regards,
Christian.

> ---
> drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
> 1 file changed, 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index da9eeffe0c6d..5b2eb6d58bb7 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -284,17 +284,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> return ret;
> }
>
> -static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> -{
> - pgoff_t i;
> -
> - if (ttm->page_flags & TTM_PAGE_FLAG_SG)
> - return;
> -
> - for (i = 0; i < ttm->num_pages; ++i)
> - ttm->pages[i]->mapping = bdev->dev_mapping;
> -}
> -
> int ttm_tt_populate(struct ttm_bo_device *bdev,
> struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> {
> @@ -313,7 +302,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
> if (ret)
> return ret;
>
> - ttm_tt_add_mapping(bdev, ttm);
> ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
> if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
> ret = ttm_tt_swapin(ttm);

2020-11-20 10:09:39

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH] drm/ttm: don't set page->mapping

On Fri, Nov 20, 2020 at 11:04 AM Christian König
<[email protected]> wrote:
>
> Am 20.11.20 um 10:54 schrieb Daniel Vetter:
> > Random observation while trying to review Christian's patch series to
> > stop looking at struct page for dma-buf imports.
> >
> > This was originally added in
> >
> > commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
> > Author: Thomas Hellstrom <[email protected]>
> > Date: Fri Jan 3 11:47:23 2014 +0100
> >
> > drm/ttm: Correctly set page mapping and -index members
> >
> > Needed for some vm operations; most notably unmap_mapping_range() with
> > even_cows = 0.
> >
> > Signed-off-by: Thomas Hellstrom <[email protected]>
> > Reviewed-by: Brian Paul <[email protected]>
> >
> > but we do not have a single caller of unmap_mapping_range with
> > even_cows == 0. And all the gem drivers don't do this, so another
> > small thing we could standardize between drm and ttm drivers.
> >
> > Plus I don't really see a need for unamp_mapping_range where we don't
> > want to indiscriminately shoot down all ptes.
> >
> > Cc: Thomas Hellstrom <[email protected]>
> > Cc: Brian Paul <[email protected]>
> > Signed-off-by: Daniel Vetter <[email protected]>
> > Cc: Christian Koenig <[email protected]>
> > Cc: Huang Rui <[email protected]>
>
> This is still a NAK as long as we can't come up with a better way to
> track TTMs page allocations.
>
> Additional to that page_mapping() is used quite extensively in the mm
> code and I'm not sure if that isn't needed for other stuff as well.

Apologies, I'm honestly not quite sure how this lone patch here ended
up in this submission. I didn't want to send it out.
-Daniel

>
> Regards,
> Christian.
>
> > ---
> > drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
> > 1 file changed, 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> > index da9eeffe0c6d..5b2eb6d58bb7 100644
> > --- a/drivers/gpu/drm/ttm/ttm_tt.c
> > +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> > @@ -284,17 +284,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> > return ret;
> > }
> >
> > -static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> > -{
> > - pgoff_t i;
> > -
> > - if (ttm->page_flags & TTM_PAGE_FLAG_SG)
> > - return;
> > -
> > - for (i = 0; i < ttm->num_pages; ++i)
> > - ttm->pages[i]->mapping = bdev->dev_mapping;
> > -}
> > -
> > int ttm_tt_populate(struct ttm_bo_device *bdev,
> > struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> > {
> > @@ -313,7 +302,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
> > if (ret)
> > return ret;
> >
> > - ttm_tt_add_mapping(bdev, ttm);
> > ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
> > if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
> > ret = ttm_tt_swapin(ttm);
>


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

2020-11-20 10:10:35

by Christian König

[permalink] [raw]
Subject: Re: [PATCH] drm/ttm: don't set page->mapping

Am 20.11.20 um 11:05 schrieb Daniel Vetter:
> On Fri, Nov 20, 2020 at 11:04 AM Christian König
> <[email protected]> wrote:
>> Am 20.11.20 um 10:54 schrieb Daniel Vetter:
>>> Random observation while trying to review Christian's patch series to
>>> stop looking at struct page for dma-buf imports.
>>>
>>> This was originally added in
>>>
>>> commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
>>> Author: Thomas Hellstrom <[email protected]>
>>> Date: Fri Jan 3 11:47:23 2014 +0100
>>>
>>> drm/ttm: Correctly set page mapping and -index members
>>>
>>> Needed for some vm operations; most notably unmap_mapping_range() with
>>> even_cows = 0.
>>>
>>> Signed-off-by: Thomas Hellstrom <[email protected]>
>>> Reviewed-by: Brian Paul <[email protected]>
>>>
>>> but we do not have a single caller of unmap_mapping_range with
>>> even_cows == 0. And all the gem drivers don't do this, so another
>>> small thing we could standardize between drm and ttm drivers.
>>>
>>> Plus I don't really see a need for unamp_mapping_range where we don't
>>> want to indiscriminately shoot down all ptes.
>>>
>>> Cc: Thomas Hellstrom <[email protected]>
>>> Cc: Brian Paul <[email protected]>
>>> Signed-off-by: Daniel Vetter <[email protected]>
>>> Cc: Christian Koenig <[email protected]>
>>> Cc: Huang Rui <[email protected]>
>> This is still a NAK as long as we can't come up with a better way to
>> track TTMs page allocations.
>>
>> Additional to that page_mapping() is used quite extensively in the mm
>> code and I'm not sure if that isn't needed for other stuff as well.
> Apologies, I'm honestly not quite sure how this lone patch here ended
> up in this submission. I didn't want to send it out.

No problem.

But looking a bit deeper into the mm code that other drm drivers don't
set this correctly and still use unmap_mapping_range() sounds like quite
a bug to me.

Going to track down what exactly that is used for.

Christian.

> -Daniel
>
>> Regards,
>> Christian.
>>
>>> ---
>>> drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
>>> 1 file changed, 12 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
>>> index da9eeffe0c6d..5b2eb6d58bb7 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_tt.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
>>> @@ -284,17 +284,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>>> return ret;
>>> }
>>>
>>> -static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>>> -{
>>> - pgoff_t i;
>>> -
>>> - if (ttm->page_flags & TTM_PAGE_FLAG_SG)
>>> - return;
>>> -
>>> - for (i = 0; i < ttm->num_pages; ++i)
>>> - ttm->pages[i]->mapping = bdev->dev_mapping;
>>> -}
>>> -
>>> int ttm_tt_populate(struct ttm_bo_device *bdev,
>>> struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>>> {
>>> @@ -313,7 +302,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
>>> if (ret)
>>> return ret;
>>>
>>> - ttm_tt_add_mapping(bdev, ttm);
>>> ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
>>> if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
>>> ret = ttm_tt_swapin(ttm);
>

2020-11-20 15:06:18

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH] drm/ttm: don't set page->mapping

On Fri, Nov 20, 2020 at 11:08:31AM +0100, Christian K?nig wrote:
> Am 20.11.20 um 11:05 schrieb Daniel Vetter:
> > On Fri, Nov 20, 2020 at 11:04 AM Christian K?nig
> > <[email protected]> wrote:
> > > Am 20.11.20 um 10:54 schrieb Daniel Vetter:
> > > > Random observation while trying to review Christian's patch series to
> > > > stop looking at struct page for dma-buf imports.
> > > >
> > > > This was originally added in
> > > >
> > > > commit 58aa6622d32af7d2c08d45085f44c54554a16ed7
> > > > Author: Thomas Hellstrom <[email protected]>
> > > > Date: Fri Jan 3 11:47:23 2014 +0100
> > > >
> > > > drm/ttm: Correctly set page mapping and -index members
> > > >
> > > > Needed for some vm operations; most notably unmap_mapping_range() with
> > > > even_cows = 0.
> > > >
> > > > Signed-off-by: Thomas Hellstrom <[email protected]>
> > > > Reviewed-by: Brian Paul <[email protected]>
> > > >
> > > > but we do not have a single caller of unmap_mapping_range with
> > > > even_cows == 0. And all the gem drivers don't do this, so another
> > > > small thing we could standardize between drm and ttm drivers.
> > > >
> > > > Plus I don't really see a need for unamp_mapping_range where we don't
> > > > want to indiscriminately shoot down all ptes.
> > > >
> > > > Cc: Thomas Hellstrom <[email protected]>
> > > > Cc: Brian Paul <[email protected]>
> > > > Signed-off-by: Daniel Vetter <[email protected]>
> > > > Cc: Christian Koenig <[email protected]>
> > > > Cc: Huang Rui <[email protected]>
> > > This is still a NAK as long as we can't come up with a better way to
> > > track TTMs page allocations.
> > >
> > > Additional to that page_mapping() is used quite extensively in the mm
> > > code and I'm not sure if that isn't needed for other stuff as well.
> > Apologies, I'm honestly not quite sure how this lone patch here ended
> > up in this submission. I didn't want to send it out.
>
> No problem.
>
> But looking a bit deeper into the mm code that other drm drivers don't set
> this correctly and still use unmap_mapping_range() sounds like quite a bug
> to me.
>
> Going to track down what exactly that is used for.

Pagecache shootdown. unmap_mapping_range only shoots down from the virtual
side. Since that's all we care about, we don't need to set up the
address_space in the page.
-Daniel

>
> Christian.
>
> > -Daniel
> >
> > > Regards,
> > > Christian.
> > >
> > > > ---
> > > > drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
> > > > 1 file changed, 12 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> > > > index da9eeffe0c6d..5b2eb6d58bb7 100644
> > > > --- a/drivers/gpu/drm/ttm/ttm_tt.c
> > > > +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> > > > @@ -284,17 +284,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> > > > return ret;
> > > > }
> > > >
> > > > -static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
> > > > -{
> > > > - pgoff_t i;
> > > > -
> > > > - if (ttm->page_flags & TTM_PAGE_FLAG_SG)
> > > > - return;
> > > > -
> > > > - for (i = 0; i < ttm->num_pages; ++i)
> > > > - ttm->pages[i]->mapping = bdev->dev_mapping;
> > > > -}
> > > > -
> > > > int ttm_tt_populate(struct ttm_bo_device *bdev,
> > > > struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> > > > {
> > > > @@ -313,7 +302,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
> > > > if (ret)
> > > > return ret;
> > > >
> > > > - ttm_tt_add_mapping(bdev, ttm);
> > > > ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
> > > > if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
> > > > ret = ttm_tt_swapin(ttm);
> >
>

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