Skip to contentSkip to conversation

drm/ttm: don't set page->mapping

PATCH NAK Daniel Vetter 3 participants 13 messages Nov 4, 2020 – Nov 6, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

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]>
Cc Christian Koenig <[email protected]>
Cc Huang Rui <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_tt.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -12
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
 {
@@ -320,7 +309,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);
Signature · 6 lines
2.28.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 17 lines

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.

Quoted 6 lines

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.

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Christian.

Quoted 33 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
  {

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 7 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
@@ -320,7 +309,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);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 23 lines · Christian König

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 21 lines

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.

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.

Quoted 7 lines
Quoted 2 lines

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

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all. -Daniel

Quoted 44 lines

Christian.

Quoted 40 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -12
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
  {
@@ -320,7 +309,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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 23 lines · Christian König
Quoted 22 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 21 lines

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.

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.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

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

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Quoted 2 lines

                if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
   {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
       if (ret)
               return ret;
 
Quoted 5 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 26 lines · Christian König

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 25 lines · Christian König
Quoted 24 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 23 lines

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.

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.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 51 lines
Quoted 3 lines

                if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM;

Christian.

Quoted 44 lines

-Daniel

Quoted 41 lines

Christian.

Quoted 39 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -12
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
   {
@@ -320,7 +309,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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 27 lines · Christian König
Quoted 26 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 25 lines · Christian König
Quoted 24 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 23 lines

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.

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.

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

Regards,
Christian.

Quoted 61 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 43 lines
Quoted 2 lines

                if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
    {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
        if (ret)
                return ret;
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
Quoted 31 lines · Christian König

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 29 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 28 lines · Christian König
Quoted 27 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 17 lines

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.

Quoted 6 lines

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.

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

Quoted 3 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 70 lines

Regards,
Christian.

Quoted 65 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 47 lines
Quoted 2 lines

                if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM;

Christian.

Quoted 43 lines

-Daniel

Quoted 41 lines

Christian.

Quoted 39 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -12
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
    {
@@ -320,7 +309,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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Am 05.11.20 um 14:20 schrieb Daniel Vetter:

Quoted 36 lines · Christian König
Quoted 35 lines

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 34 lines · Christian König
Quoted 24 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 23 lines · Christian König
Quoted 22 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 21 lines

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.

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.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

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

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

Quoted 8 lines
Quoted 3 lines

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

And exactly that would get a NAK from us.

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Regards,
Christian.

Quoted 77 lines
Quoted 4 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 63 lines

Regards,
Christian.

Quoted 60 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 43 lines
Quoted 2 lines

                if (p->mapping != adev->mman.bdev.dev_mapping) return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
     {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
         if (ret)
                 return ret;
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
Quoted 47 lines · Christian König

Am 05.11.20 um 14:20 schrieb Daniel Vetter:

Quoted 36 lines · Christian König
Quoted 35 lines

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 34 lines · Christian König
Quoted 24 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 23 lines · Christian König
Quoted 22 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 21 lines

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.

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.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

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

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

Quoted 8 lines
Quoted 3 lines

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

Quoted 4 lines

And exactly that would get a NAK from us.

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Uh that doesn't work if you work around core restrictions with your own debugfs paths. Maybe you can do fun like this in your dkms, but not in upstream. Like if this was specifically created to work around CONFIG_STRICT_DEVMEM (and it sounds like that) then I think this should never have landed in upstream to begin with. -Daniel

Quoted 86 lines

Regards,
Christian.

Quoted 81 lines
Quoted 4 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 67 lines

Regards,
Christian.

Quoted 64 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 47 lines
Quoted 2 lines
                  if (p->mapping != adev->mman.bdev.dev_mapping)
                          return -EPERM;

Christian.

Quoted 43 lines

-Daniel

Quoted 41 lines

Christian.

Quoted 39 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -12
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
     {
@@ -320,7 +309,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);
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw
Quoted 51 lines · Daniel Vetter
Quoted 49 lines · Christian König

Am 05.11.20 um 14:20 schrieb Daniel Vetter:

Quoted 36 lines · Christian König
Quoted 35 lines

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 34 lines · Christian König
Quoted 24 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 23 lines · Christian König
Quoted 22 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 21 lines

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.

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.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

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

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

Quoted 8 lines
Quoted 3 lines

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

And exactly that would get a NAK from us.

Quoted 8 lines
Quoted 2 lines

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Uh that doesn't work if you work around core restrictions with your own debugfs paths. Maybe you can do fun like this in your dkms, but not in upstream. Like if this was specifically created to work around CONFIG_STRICT_DEVMEM (and it sounds like that) then I think this should never have landed in upstream to begin with.

I'm also kinda confused that there's distros with CONFIG_STRICT_DEVMEM which allow debugfs. debugfs is a pretty bad root hole all around, or at least that's been the assumption all the time.
-Daniel

Quoted 87 lines
Quoted 76 lines
Quoted 76 lines
Quoted 3 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 63 lines

Regards,
Christian.

Quoted 60 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 43 lines
Quoted 2 lines
                  if (p->mapping != adev->mman.bdev.dev_mapping)
                          return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
     {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
         if (ret)
                 return ret;
 
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

Am 05.11.20 um 15:38 schrieb Daniel Vetter:

Quoted 47 lines · Daniel Vetter
Quoted 46 lines · Christian König
Quoted 45 lines

Am 05.11.20 um 14:20 schrieb Daniel Vetter:

Quoted 44 lines · Christian König
Quoted 31 lines

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 29 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 28 lines · Christian König
Quoted 27 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 17 lines

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.

Quoted 6 lines

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.

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

And exactly that would get a NAK from us.

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Uh that doesn't work if you work around core restrictions with your own debugfs paths.

That's why we have the restriction to check the mapping of the pages.

This way we only expose the memory which was allocated by our driver and don't allow any uncontrolled access to the whole system memory.

We have something similar for radeon as well, but there we have a global GART table which we can use for validating stuff.

Quoted 7 lines
Quoted 4 lines

Maybe you can do fun like this in your dkms, but
not in upstream. Like if this was specifically created to work around CONFIG_STRICT_DEVMEM (and it sounds like that) then I think this should never have landed in upstream to begin with.

I'm also kinda confused that there's distros with CONFIG_STRICT_DEVMEM which allow debugfs. debugfs is a pretty bad root hole all around, or at least that's been the assumption all the time.

Yeah, completely agree :) But that's not my problem.

Christian.

Quoted 89 lines

-Daniel

Quoted 85 lines
Quoted 76 lines
Quoted 76 lines
Quoted 3 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 63 lines

Regards,
Christian.

Quoted 60 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 43 lines
Quoted 2 lines
                   if (p->mapping != adev->mman.bdev.dev_mapping)
                           return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
      {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
          if (ret)
                  return ret;
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C619e6a6113674691eb9708d8819874f4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637401839082694450%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=Uo7UXS7y%2BU%2FHfnBenx2vQXuyyB%2FCuOULLOp1uL0eg4I%3D&amp;reserved=0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
Quoted 56 lines · Christian König

Am 05.11.20 um 15:38 schrieb Daniel Vetter:

Quoted 47 lines · Daniel Vetter
Quoted 46 lines · Christian König
Quoted 45 lines

Am 05.11.20 um 14:20 schrieb Daniel Vetter:

Quoted 44 lines · Christian König
Quoted 31 lines

Am 05.11.20 um 13:50 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 29 lines

Am 05.11.20 um 10:11 schrieb Daniel Vetter:

Quoted 28 lines · Christian König
Quoted 27 lines

Am 04.11.20 um 17:50 schrieb Daniel Vetter:

Quoted 17 lines

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.

Quoted 6 lines

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.

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

And exactly that would get a NAK from us.

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Uh that doesn't work if you work around core restrictions with your own debugfs paths.

Quoted 7 lines

That's why we have the restriction to check the mapping of the pages.

This way we only expose the memory which was allocated by our driver and don't allow any uncontrolled access to the whole system memory.

We have something similar for radeon as well, but there we have a global GART table which we can use for validating stuff.

The check doesn't take any locks over the check and copy*user, I don't think it's protecting anything really against somewhat adverse userspace.

I mean fundamentally locking down stuff like STRICT_DEVMEM or all the others makes debugging harder, that's kinda the expected tradeoff.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

Maybe you can do fun like this in your dkms, but
not in upstream. Like if this was specifically created to work around CONFIG_STRICT_DEVMEM (and it sounds like that) then I think this should never have landed in upstream to begin with.

I'm also kinda confused that there's distros with CONFIG_STRICT_DEVMEM which allow debugfs. debugfs is a pretty bad root hole all around, or at least that's been the assumption all the time.

Yeah, completely agree :) But that's not my problem.

I guess I'll do another rfc series and poke a pile of people ... seems to be a habit I'm developing :-)
-Daniel

Quoted 93 lines

Christian.

Quoted 89 lines

-Daniel

Quoted 85 lines
Quoted 76 lines
Quoted 76 lines
Quoted 3 lines

When I tried a few years ago to not set the page->mapping I immediately ran into issues with our eviction test. So I think that this is used elsewhere as well.

That's the kind of interaction I'm worried about here tbh. If this does some kind of shrinking of some sorts, I think a real shrinker should take over.

An improved grep shows nothing else, so the only the above is the only thing I can think of. What kind of eviction test goes boom if you clear ->mapping here? I'd be happy to type up the clever trick for the debugfs files.
-Daniel

Quoted 63 lines

Regards,
Christian.

Quoted 60 lines

If this is to avoid issues with userptr, then I think there's a simple trick:
- grab page reference
- recheck that the iova still points at the same address
- do read/write, safe in the knowledge that this page cannot be reused for anything else
- drop page reference

Of course this can still race against iova updates, but that seems to be a fundamental part of your debug interface here.

Or am I missing something?

Just pondering this more since setting the page->mapping pointer for just this seems somewhat wild abuse of ->mapping semantics :-) -Daniel

Quoted 43 lines
Quoted 2 lines
                   if (p->mapping != adev->mman.bdev.dev_mapping)
                           return -EPERM;

Christian.

Quoted 39 lines

-Daniel

Quoted 37 lines

Christian.

Quoted 35 lines
Cc Thomas Hellstrom <[email protected]>
Cc Brian Paul <[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(-)
drivers/gpu/drm/ttm/ttm_tt.c +0 -11
index 8861a74ac335..438ea43fd8c1 100644
@@ -291,17 +291,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)
      {
@@ -320,7 +309,6 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
          if (ret)
                  return ret;
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/ttm/ttm_tt.c int ttm_tt_populate(struct ttm_bo_device *bdev, · line 314

Quoted 4 lines
drivers/gpu/drm/ttm/ttm_tt.c +0 -1
-     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
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fblog.ffwll.ch%2F&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C619e6a6113674691eb9708d8819874f4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637401839082694450%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=Uo7UXS7y%2BU%2FHfnBenx2vQXuyyB%2FCuOULLOp1uL0eg4I%3D&amp;reserved=0

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

Am 05.11.20 um 17:37 schrieb Daniel Vetter:

Quoted 24 lines

[SNIP]

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 10 lines
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

NAK, we use this to determine if a pages belongs to the driver or not in amdgpu for example.

Mostly used for debugging, but I would really like to keep that.

Can you pls point me at that code? A quick grep hasn't really found much at all.

See amdgpu_iomem_read() for an example:

Why do you reject this?

When IOMMU is disabled or uses an 1 to 1 mapping we would otherwise give the same access as /dev/mem to system memory and that is forbidden. But as I noted this is just for the debugfs file.

Ah, there's a config option for that. Plus it's debugfs, anything goes in debugfs, but if you're worried about that hole we should just disable the entire debugfs file for CONFIG_STRICT_DEVMEM. I can perhaps throw that on top, that follow_pfn patch series I'm baking is all about this kind of fun.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

And exactly that would get a NAK from us.

We have specially created that debugfs file as an alternative when CONFIG_STRICT_DEVMEM is set.

Uh that doesn't work if you work around core restrictions with your own debugfs paths.

That's why we have the restriction to check the mapping of the pages.

Quoted 8 lines
Quoted 5 lines

This way we only expose the memory which was allocated by our driver and don't allow any uncontrolled access to the whole system memory.

We have something similar for radeon as well, but there we have a global GART table which we can use for validating stuff.

The check doesn't take any locks over the check and copy*user, I don't think it's protecting anything really against somewhat adverse userspace.

You mean that it's racing with freeing the pages? Yes that is an obvious problem, but we already had the same issue for radeon as well.

On the other hand we could easily prevent that with a lock.

Quoted 2 lines

I mean fundamentally locking down stuff like STRICT_DEVMEM or all the others makes debugging harder, that's kinda the expected tradeoff.

Well we just wanted to have the same debugging functionality we had for radeon.

As you said debugfs is a rabbit hole regarding attack vectors anyway.

If you are root you can just go to /sys and start reprogramming the hardware to do what you want to do.

Regards,
Christian.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Maybe you can do fun like this in your dkms, but
not in upstream. Like if this was specifically created to work around CONFIG_STRICT_DEVMEM (and it sounds like that) then I think this should never have landed in upstream to begin with.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

I'm also kinda confused that there's distros with CONFIG_STRICT_DEVMEM which allow debugfs. debugfs is a pretty bad root hole all around, or at least that's been the assumption all the time.

Yeah, completely agree :) But that's not my problem.

I guess I'll do another rfc series and poke a pile of people ... seems to be a habit I'm developing :-)
-Daniel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel