Skip to contentSkip to conversation

drm/ttm: Don't init dma32_zone on 64-bit systems

RFC PATCH In review Kuehling, Felix 7 participants 22 messages Feb 15, 2019 – Feb 22, 2019 13 messages not in the archive

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

RFC PATCH 1/1 drm/ttm: Don't init dma32_zone on 64-bit systems

This is an RFC. I'm not sure this is the right solution, but it highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB. On a 64-bit system with hundreds of GB of system memory and GPU memory, this can become a bottle neck. We're seeing TTM memory allocation failures not because we're truly out of memory, but because we're out of space in the dma32_zone for the acc_size needed for our BO book-keeping.

---
 drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +2 -2
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int ttm_mem_init_highmem_zone(struct ttm_mem_global *glob,
 	glob->zones[glob->num_zones++] = zone;
 	return 0;
 }
-#else
+#elifndef CONFIG_64BIT
 static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
 				   const struct sysinfo *si)
 {
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
 	ret = ttm_mem_init_highmem_zone(glob, &si);
 	if (unlikely(ret != 0))
 		goto out_no_zone;
-#else
+#elifndef CONFIG_64BIT
 	ret = ttm_mem_init_dma32_zone(glob, &si);
 	if (unlikely(ret != 0))
 		goto out_no_zone;
Signature · 6 lines
2.7.4

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

Hmm,

This zone was intended to stop TTM page allocations from exhausting the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default, which means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system to make sure there are some pages left in the DMA32 zone, otherwise random non-IO page allocations would also potentially exhaust the DMA32 zone without anybody caring, which means removing this zone wouldn't be any worse than whatever other subsystems may be doing already...

/Thomas

Quoted 31 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB. On a 64-bit system with hundreds of GB of system memory and GPU memory, this can become a bottle neck. We're seeing TTM memory allocation failures not because we're truly out of memory, but because we're out of space in the dma32_zone for the acc_size needed for our BO book-keeping.

---
  drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int ttm_mem_init_highmem_zone(struct ttm_mem_global *glob,
  	glob->zones[glob->num_zones++] = zone;
  	return 0;
  }
-#else
+#elifndef CONFIG_64BIT
  static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
  				   const struct sysinfo *si)
  {

drivers/gpu/drm/ttm/ttm_memory.c int ttm_mem_global_init(struct ttm_mem_global *glob) · line 447

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
  	ret = ttm_mem_init_highmem_zone(glob, &si);
  	if (unlikely(ret != 0))
  		goto out_no_zone;
-#else
+#elifndef CONFIG_64BIT
  	ret = ttm_mem_init_dma32_zone(glob, &si);
  	if (unlikely(ret != 0))
  		goto out_no_zone;

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

#2 lore raw

Another good question is also why the heck the acc_size counts towards the DMA32 zone?

In other words why should the internal bookkeeping pages be allocated in the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 51 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default, which means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system to make sure there are some pages left in the DMA32 zone, otherwise random non-IO page allocations would also potentially exhaust the DMA32 zone without anybody caring, which means removing this zone wouldn't be any worse than whatever other subsystems may be doing already...

/Thomas

Quoted 33 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB. On a 64-bit system with hundreds of GB of system memory and GPU memory, this can become a bottle neck. We're seeing TTM memory allocation failures not because we're truly out of memory, but because we're out of space in the dma32_zone for the acc_size needed for our BO book-keeping.

---
  drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int ttm_mem_init_highmem_zone(struct 
 ttm_mem_global *glob,
       glob->zones[glob->num_zones++] = zone;
       return 0;
   }
-#else
+#elifndef CONFIG_64BIT
   static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
                      const struct sysinfo *si)

  {

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
Quoted 10 lines

drivers/gpu/drm/ttm/ttm_memory.c int ttm_mem_global_init(struct ttm_mem_global *glob) · line 447

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
       ret = ttm_mem_init_highmem_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;
-#else
+#elifndef CONFIG_64BIT
       ret = ttm_mem_init_dma32_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;

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

#3 lore raw
Quoted 3 lines · Christian

Another good question is also why the heck the acc_size counts towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are not.

For small persistent allocations using ttm_mem_global_alloc(), they are accounted also in the DMA32 zone, which may cause over-accounting of that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 66 lines

In other words why should the internal bookkeeping pages be allocated in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 57 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default, which
means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system to
make sure there are some pages left in the DMA32 zone, otherwise random non-IO page allocations would also potentially exhaust the DMA32 zone without anybody caring, which means removing this zone wouldn't be any worse than whatever other subsystems may be doing already...

/Thomas

Quoted 36 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB. On a
64-bit system with hundreds of GB of system memory and GPU memory,
this can become a bottle neck. We're seeing TTM memory allocation failures not because we're truly out of memory, but because we're out of space in the dma32_zone for the acc_size needed for our BO book-keeping.

---
  drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int ttm_mem_init_highmem_zone(struct 
 ttm_mem_global *glob,
      glob->zones[glob->num_zones++] = zone;
      return 0;
  }
-#else
+#elifndef CONFIG_64BIT
  static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
                     const struct sysinfo *si)
  {
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct ttm_mem_global
 *glob)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
      ret = ttm_mem_init_highmem_zone(glob, &si);
      if (unlikely(ret != 0))
          goto out_no_zone;
-#else
+#elifndef CONFIG_64BIT
      ret = ttm_mem_init_dma32_zone(glob, &si);
      if (unlikely(ret != 0))
          goto out_no_zone;

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

A message that is not in the archive (sent off-list or not yet received): d90f7ab569b636db0968c80dad9eb16ce7bf1eab.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#5 lore raw

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 5 lines · Christian
Quoted 3 lines

Another good question is also why the heck the acc_size counts towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

We have an accounting for the stuff needed additional to the pages backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for this accounting which of course is completely nonsense.

Christian.

Quoted 80 lines

For small persistent allocations using ttm_mem_global_alloc(), they are accounted also in the DMA32 zone, which may cause over-accounting of that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 69 lines

In other words why should the internal bookkeeping pages be allocated in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 61 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default, which
means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system to
make sure there are some pages left in the DMA32 zone, otherwise random non-IO page allocations would also potentially exhaust the DMA32 zone without anybody caring, which means removing this zone wouldn't be any worse than whatever other subsystems may be doing already...

/Thomas

Quoted 40 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB. On a
64-bit system with hundreds of GB of system memory and GPU memory,
this can become a bottle neck. We're seeing TTM memory allocation failures not because we're truly out of memory, but because we're out of space in the dma32_zone for the acc_size needed for our BO book-keeping.

---
   drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int ttm_mem_init_highmem_zone(struct
 ttm_mem_global *glob,
       glob->zones[glob->num_zones++] = zone;
       return 0;
   }
-#else
+#elifndef CONFIG_64BIT
   static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
                      const struct sysinfo *si)
   {
drivers/gpu/drm/ttm/ttm_memory.c +0 -1
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct ttm_mem_global
 *glob)
       ret = ttm_mem_init_highmem_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;
-#else
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/ttm/ttm_memory.c +1 -0
+#elifndef CONFIG_64BIT
       ret = ttm_mem_init_dma32_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;

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

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

A message that is not in the archive (sent off-list or not yet received): 89c4b66a-152a-d0f3-4ce0-d89f6ef822bb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

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

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 6 lines · Christian
Quoted 3 lines

Another good question is also why the heck the acc_size counts towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 6 lines

We have an accounting for the stuff needed additional to the pages backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted. In particular if it's vmalloced. It might be DMA32, it might not. Given the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better solutions?

/Thomas

Quoted 107 lines

Christian.

Quoted 104 lines

For small persistent allocations using ttm_mem_global_alloc(), they are
accounted also in the DMA32 zone, which may cause over-accounting of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 80 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 71 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust the
DMA32 zone without anybody caring, which means removing this zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 44 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB.
On a
64-bit system with hundreds of GB of system memory and GPU memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because we're
out of space in the dma32_zone for the acc_size needed for our BO
book-keeping.

---
   drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

       glob->zones[glob->num_zones++] = zone;
       return 0;

}

drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
   static int ttm_mem_init_dma32_zone(struct ttm_mem_global

*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_memory.c

Quoted 8 lines
       ret = ttm_mem_init_highmem_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
       ret = ttm_mem_init_dma32_zone(glob, &si);
       if (unlikely(ret != 0))
           goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1a84a2a700cd48b3980a08d695c38ade%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861064581303965&sdata=6FCAP6YbostgKfEEhRKKh9eQSrfXR%2BfCczYB8WwlPVY%3D&reserved=0

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

A message that is not in the archive (sent off-list or not yet received): eaad8f2dc24e98c68036801ccd6a871586033d31.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#9 lore raw
Quoted 17 lines · Thomas Hellstrom
Quoted 10 lines · Christian König

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 6 lines · Christian
Quoted 3 lines

Another good question is also why the heck the acc_size counts towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 6 lines

We have an accounting for the stuff needed additional to the pages backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 7 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted. In particular if it's vmalloced. It might be DMA32, it might not. Given the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to use it to account for a few things that are allocated with kmalloc.

So would a better solution be to change ttm_mem_global_alloc to use only the kernel zone?

Regards,
  Felix

Quoted 109 lines

/Thomas

Quoted 106 lines

Christian.

Quoted 104 lines

For small persistent allocations using ttm_mem_global_alloc(), they are
accounted also in the DMA32 zone, which may cause over-accounting of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 80 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 71 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust the
DMA32 zone without anybody caring, which means removing this zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 44 lines · Felix

This is an RFC. I'm not sure this is the right solution, but it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to 2GB.
On a
64-bit system with hundreds of GB of system memory and GPU memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because we're
out of space in the dma32_zone for the acc_size needed for our BO
book-keeping.

---
    drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

        glob->zones[glob->num_zones++] = zone;
        return 0;
    }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
    static int ttm_mem_init_dma32_zone(struct ttm_mem_global

*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_memory.c

Quoted 8 lines
        ret = ttm_mem_init_highmem_zone(glob, &si);
        if (unlikely(ret != 0))
            goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
        ret = ttm_mem_init_dma32_zone(glob, &si);
        if (unlikely(ret != 0))
            goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1a84a2a700cd48b3980a08d695c38ade%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861064581303965&sdata=6FCAP6YbostgKfEEhRKKh9eQSrfXR%2BfCczYB8WwlPVY%3D&reserved=0

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

A message that is not in the archive (sent off-list or not yet received): 2be5739a-fe9a-f436-48a2-fb420cb97a13-5C7GfCeVMHo@public.gmane.org

#11 lore raw
Quoted 38 lines · Felix
Quoted 20 lines · Thomas Hellstrom
Quoted 12 lines · Christian König

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 8 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 7 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 10 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not. Given
the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to
use it to account for a few things that are allocated with kmalloc.

Quoted 4 lines

So would a better solution be to change ttm_mem_global_alloc to use only
the kernel zone?

IMO we need to determine what functionality to keep and then the best solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential DOS attacks (DMA32 and kernel zones are not mutually exclusive. They overlap).

/Thomas

Quoted 123 lines

Regards,
Felix

Quoted 119 lines

/Thomas

Quoted 117 lines

Christian.

Quoted 115 lines

For small persistent allocations using ttm_mem_global_alloc(), they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 89 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 80 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 50 lines · Felix

This is an RFC. I'm not sure this is the right solution, but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to
2GB.
On a
64-bit system with hundreds of GB of system memory and GPU
memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed for
our BO
book-keeping.

---
    drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

        glob->zones[glob->num_zones++] = zone;
        return 0;
    }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
    static int ttm_mem_init_dma32_zone(struct

ttm_mem_global
*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_memory.c

Quoted 8 lines
        ret = ttm_mem_init_highmem_zone(glob, &si);
        if (unlikely(ret != 0))
            goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
        ret = ttm_mem_init_dma32_zone(glob, &si);
        if (unlikely(ret != 0))
            goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1357d06244fb499b31dd08d6968ca04b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861928079462725&sdata=1Bucho93KMzN0z7QbfiNn%2BNWaZs5yi86Ya6vm9Xhbqo%3D&reserved=0

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

A message that is not in the archive (sent off-list or not yet received): 19a0abdbd60c251a63975a7ddff31c35a5eb0a31.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#13 lore raw

Am 20.02.19 um 07:41 schrieb Thomas Hellstrom:

Quoted 42 lines · Felix
Quoted 37 lines · Thomas Hellstrom
Quoted 20 lines · Christian König
Quoted 12 lines

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 8 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 7 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 10 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not. Given
the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to
use it to account for a few things that are allocated with kmalloc.

Quoted 4 lines

So would a better solution be to change ttm_mem_global_alloc to use only
the kernel zone?

Quoted 5 lines

IMO we need to determine what functionality to keep and then the best solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential DOS attacks (DMA32 and kernel zones are not mutually exclusive. They overlap).

Yeah and exactly because of this it doesn't make to much sense to account the housekeeping stuff in both zones.

IIRC the kernel takes perfectly care by itself that kmalloced memory doesn't eat up everything in the DMA32 zone.

Christian.

Quoted 130 lines

/Thomas

Quoted 123 lines

Regards,
Felix

Quoted 119 lines

/Thomas

Quoted 117 lines

Christian.

Quoted 115 lines

For small persistent allocations using ttm_mem_global_alloc(), they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 89 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 80 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 50 lines · Felix

This is an RFC. I'm not sure this is the right solution, but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to
2GB.
On a
64-bit system with hundreds of GB of system memory and GPU
memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed for
our BO
book-keeping.

---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

         glob->zones[glob->num_zones++] = zone;
         return 0;
     }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
     static int ttm_mem_init_dma32_zone(struct

ttm_mem_global
*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_memory.c

Quoted 8 lines
         ret = ttm_mem_init_highmem_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
         ret = ttm_mem_init_dma32_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1357d06244fb499b31dd08d6968ca04b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861928079462725&sdata=1Bucho93KMzN0z7QbfiNn%2BNWaZs5yi86Ya6vm9Xhbqo%3D&reserved=0

Quoted 4 lines

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

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

#14 lore raw
Quoted 43 lines · Christian König

Am 20.02.19 um 07:41 schrieb Thomas Hellstrom:

Quoted 42 lines · Felix
Quoted 41 lines · Thomas Hellstrom
Quoted 20 lines · Christian König
Quoted 12 lines

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 8 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 7 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 10 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not. Given
the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to
use it to account for a few things that are allocated with kmalloc.

So would a better solution be to change ttm_mem_global_alloc to use only
the kernel zone?

Quoted 7 lines
Quoted 5 lines

IMO we need to determine what functionality to keep and then the best solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential DOS attacks (DMA32 and kernel zones are not mutually exclusive. They overlap).

Yeah and exactly because of this it doesn't make to much sense to account the housekeeping stuff in both zones.

IMO it makes sense because (given the assumption that kmalloc/vmalloc doesn't care) , accounting only in DMA32 in low memory configurations will not guarantee that kernel is not exhausted. Accounting only in kernel in huge memory configurations will not guarantee that DMA32 is not exhausted.

Quoted 2 lines

IIRC the kernel takes perfectly care by itself that kmalloced memory doesn't eat up everything in the DMA32 zone.

If we can somehow verify this, or at least illustrate that it's likely, I'm perfectly fine with either patch from the vmwgfx POW.

Thanks,
Thomas

Quoted 138 lines

Christian.

Quoted 135 lines

/Thomas

Quoted 124 lines

Regards,
    Felix

Quoted 120 lines

/Thomas

Quoted 118 lines

Christian.

Quoted 116 lines

For small persistent allocations using ttm_mem_global_alloc(), they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 89 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 80 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 50 lines · Felix

This is an RFC. I'm not sure this is the right solution, but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to
2GB.
On a
64-bit system with hundreds of GB of system memory and GPU
memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed for
our BO
book-keeping.

---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--

     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,
         glob->zones[glob->num_zones++] = zone;
         return 0;
     }

drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT

     static int ttm_mem_init_dma32_zone(struct
ttm_mem_global
*glob,
                        const struct sysinfo *si)
     {

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

         ret = ttm_mem_init_highmem_zone(glob, &si); if (unlikely(ret != 0))
             goto out_no_zone;

drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT

         ret = ttm_mem_init_dma32_zone(glob, &si); if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1357d06244fb499b31dd08d6968ca04b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861928079462725&sdata=1Bucho93KMzN0z7QbfiNn%2BNWaZs5yi86Ya6vm9Xhbqo%3D&reserved=0

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

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

A message that is not in the archive (sent off-list or not yet received): 307f2073-7c15-8dac-58fe-3c0170231530-4+hqylr40dJg9hUCZPvPmw@public.gmane.org

#16 lore raw

Am 20.02.19 um 09:14 schrieb Thomas Hellstrom:

Quoted 50 lines · Christian König
Quoted 49 lines

Am 20.02.19 um 07:41 schrieb Thomas Hellstrom:

Quoted 47 lines · Felix
Quoted 37 lines · Thomas Hellstrom
Quoted 20 lines · Christian König
Quoted 12 lines

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 8 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 7 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 10 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not. Given
the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to
use it to account for a few things that are allocated with kmalloc.

Quoted 4 lines

So would a better solution be to change ttm_mem_global_alloc to use only
the kernel zone?

IMO we need to determine what functionality to keep and then the best solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential DOS attacks (DMA32 and kernel zones are not mutually exclusive. They overlap).

Quoted 8 lines
Quoted 2 lines

Yeah and exactly because of this it doesn't make to much sense to account the housekeeping stuff in both zones.

IMO it makes sense because (given the assumption that kmalloc/vmalloc doesn't care) , accounting only in DMA32 in low memory configurations will not guarantee that kernel is not exhausted. Accounting only in kernel in huge memory configurations will not guarantee that DMA32 is not exhausted.

DMA32 is not exhausted by TTMs kmalloc/vmalloc because otherwise any other kmalloc/vmalloc could exhaust it as well.

I mean its probably 20+ years ago that I last looked at stuff in this part of the kernel, but I don't think we have ever changed the handling of DMA/DMA32 or otherwise we would be running into massive exhaustion problems already on modern systems.

Quoted 6 lines
Quoted 3 lines

IIRC the kernel takes perfectly care by itself that kmalloced memory doesn't eat up everything in the DMA32 zone.

If we can somehow verify this, or at least illustrate that it's likely, I'm perfectly fine with either patch from the vmwgfx POW.

Well I actually think that the whole accounting of housekeeping towards the memory zones is completely pointless in the first place. Even if we swap things out we still have the same BO and TTM structures around anyway.

What we should rather to is to make sure that all processes using a BO have their RSS increased because they do so. So when a process tries to exhaust a memory domain it is simply killed by the OOM killer.

Regards,
Christian.

Quoted 146 lines

Thanks,
Thomas

Quoted 138 lines

Christian.

Quoted 135 lines

/Thomas

Quoted 124 lines

Regards,
    Felix

Quoted 120 lines

/Thomas

Quoted 118 lines

Christian.

Quoted 116 lines

For small persistent allocations using ttm_mem_global_alloc(), they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 89 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 80 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 50 lines · Felix

This is an RFC. I'm not sure this is the right solution, but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to
2GB.
On a
64-bit system with hundreds of GB of system memory and GPU
memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed for
our BO
book-keeping.

---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--

     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,
         glob->zones[glob->num_zones++] = zone;
         return 0;
     }

drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT

     static int ttm_mem_init_dma32_zone(struct
ttm_mem_global
*glob,
                        const struct sysinfo *si)
     {

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

         ret = ttm_mem_init_highmem_zone(glob, &si); if (unlikely(ret != 0))
             goto out_no_zone;

drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT

         ret = ttm_mem_init_dma32_zone(glob, &si); if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cthellstrom%40vmware.com%7C1357d06244fb499b31dd08d6968ca04b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861928079462725&sdata=1Bucho93KMzN0z7QbfiNn%2BNWaZs5yi86Ya6vm9Xhbqo%3D&reserved=0

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

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

A message that is not in the archive (sent off-list or not yet received): 66b1fa8a-6449-6fe2-18a0-c7aa2200ac68-5C7GfCeVMHo@public.gmane.org

#18 lore raw
Quoted 102 lines · Christian

Am 20.02.19 um 09:14 schrieb Thomas Hellstrom:

Quoted 73 lines · Christian König
Quoted 68 lines

Am 20.02.19 um 07:41 schrieb Thomas Hellstrom:

Quoted 58 lines · Felix
Quoted 52 lines · Thomas Hellstrom
Quoted 26 lines · Christian König
Quoted 21 lines

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 11 lines
Quoted 5 lines · Christian

Another good question is also why the heck the
acc_size
counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages
are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting
size!

We have an accounting for the stuff needed additional to the
pages
backing the BO (e.g. the page and DMA addr array).

Quoted 4 lines

And from the bug description it sounds like we use the DMA32 zone
for
this accounting which of course is completely nonsense.

Quoted 16 lines

It's actually accounted in all available zones, since it would be
pretty hard to determine exactly where that memory should be
accounted.
In particular if it's vmalloced. It might be DMA32, it might not.
Given
the objective of stopping malicious user-space from exhausting the
DMA32 zone it was, at the time the code was written, a reasonable
approximation. With ever increasing memory sizes, there might be
better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for
the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems
to
use it to account for a few things that are allocated with kmalloc.

Quoted 5 lines

So would a better solution be to change ttm_mem_global_alloc to use
only
the kernel zone?

Quoted 8 lines

IMO we need to determine what functionality to keep and then the best
solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential
DOS attacks (DMA32 and kernel zones are not mutually exclusive. They
overlap).

Quoted 3 lines

Yeah and exactly because of this it doesn't make to much sense to
account the housekeeping stuff in both zones.

Quoted 9 lines

IMO it makes sense because (given the assumption that kmalloc/vmalloc
doesn't care) , accounting only in DMA32 in low memory configurations
will not guarantee that kernel is not exhausted. Accounting only in
kernel in huge memory configurations will not guarantee that DMA32 is
not exhausted.

DMA32 is not exhausted by TTMs kmalloc/vmalloc because otherwise any other kmalloc/vmalloc could exhaust it as well.

I mean its probably 20+ years ago that I last looked at stuff in this
part of the kernel, but I don't think we have ever changed the handling
of DMA/DMA32 or otherwise we would be running into massive exhaustion
problems already on modern systems.

Quoted 6 lines
Quoted 3 lines

IIRC the kernel takes perfectly care by itself that kmalloced memory
doesn't eat up everything in the DMA32 zone.

If we can somehow verify this, or at least illustrate that it's likely, I'm perfectly fine with either patch from the vmwgfx POW.

Quoted 6 lines

Well I actually think that the whole accounting of housekeeping towards
the memory zones is completely pointless in the first place. Even if we
swap things out we still have the same BO and TTM structures around anyway.

Well, the whole point of this is to stop malicious user-space apps from exhausting memory, causing a DOS vulnerability, similaraly for example to how processes are stopped from creating to many open file descriptors or other kernel structures. IIRC, for example, you used to be able to call gem open in an infinite loop with the same bo until you brought a random big process down using the OOM killer. With vmwgfx you can't do that. You'd end up swapping out all available BOs and then you'd get an error.

Quoted 6 lines

What we should rather to is to make sure that all processes using a BO
have their RSS increased because they do so. So when a process tries to
exhaust a memory domain it is simply killed by the OOM killer.

Yes, if there is a way to reliably do that and also take care of other kernel structures that are created by user-space, like in the example above that indeed sounds like a better solution.

/Thomas

Quoted 166 lines

Regards,
Christian.

Quoted 162 lines

Thanks,
Thomas

Quoted 157 lines

Christian.

Quoted 155 lines

/Thomas

Quoted 145 lines

Regards,
Felix

Quoted 141 lines

/Thomas

Quoted 139 lines

Christian.

Quoted 137 lines

For small persistent allocations using ttm_mem_global_alloc(),
they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 108 lines

In other words why should the internal bookkeeping pages be
allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 98 lines

Hmm,

This zone was intended to stop TTM page allocations from
exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by
default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page
allocation
system
to
make sure there are some pages left in the DMA32
zone,
otherwise
random non-IO page allocations would also
potentially
exhaust
the
DMA32 zone without anybody caring, which means
removing
this
zone
wouldn't be any worse than whatever other
subsystems may be
doing
already...

/Thomas

Quoted 61 lines · Felix

This is an RFC. I'm not sure this is the right
solution,
but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all
allocated BOs
to
2GB.
On a
64-bit system with hundreds of GB of system
memory and
GPU
memory,
this can become a bottle neck. We're seeing TTM
memory
allocation
failures not because we're truly out of memory,
but
because
we're
out of space in the dma32_zone for the acc_size
needed
for
our BO
book-keeping.

Signed-off-by: Felix Kuehling <
[email protected]>
CC: [email protected]
CC: [email protected]

---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
     1 file changed, 2 insertions(+), 2

deletions(-)

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

         glob->zones[glob->num_zones++] = zone;
         return 0;
     }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
     static int ttm_mem_init_dma32_zone(struct

ttm_mem_global
*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int

ttm_mem_global_init(struct
ttm_mem_global
*glob)
ret = ttm_mem_init_highmem_zone(glob,
&si);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
         if (unlikely(ret != 0))
             goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
         ret = ttm_mem_init_dma32_zone(glob,
&si);
         if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cthellstrom%40vmware.com%7C40edb735811c4c609d5f08d6970e52df%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636862485126215077&amp;sdata=Q4%2Fga%2B8HbwMLRhePkp62uiUMtkpWfp44nMuNumiOskM%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cthellstrom%40vmware.com%7C40edb735811c4c609d5f08d6970e52df%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636862485126215077&amp;sdata=Q4%2Fga%2B8HbwMLRhePkp62uiUMtkpWfp44nMuNumiOskM%3D&amp;reserved=0

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

#19 lore raw
In reply to a message not in the archive
Quoted 42 lines · Thomas Hellstrom
Quoted 37 lines · Felix
Quoted 20 lines · Thomas Hellstrom
Quoted 12 lines · Christian König

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 8 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting size!

Quoted 7 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone for
this accounting which of course is completely nonsense.

Quoted 10 lines

It's actually accounted in all available zones, since it would be pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not. Given
the objective of stopping malicious user-space from exhausting the DMA32 zone it was, at the time the code was written, a reasonable approximation. With ever increasing memory sizes, there might be better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems to
use it to account for a few things that are allocated with kmalloc.

Quoted 4 lines

So would a better solution be to change ttm_mem_global_alloc to use only
the kernel zone?

Quoted 5 lines

IMO we need to determine what functionality to keep and then the best solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential DOS attacks (DMA32 and kernel zones are not mutually exclusive. They overlap).

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
  Felix

Quoted 130 lines

/Thomas

Quoted 123 lines

Regards,
Felix

Quoted 119 lines

/Thomas

Quoted 117 lines

Christian.

Quoted 115 lines

For small persistent allocations using ttm_mem_global_alloc(), they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 89 lines

In other words why should the internal bookkeeping pages be allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 80 lines

Hmm,

This zone was intended to stop TTM page allocations from exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be doing
already...

/Thomas

Quoted 50 lines · Felix

This is an RFC. I'm not sure this is the right solution, but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs to
2GB.
On a
64-bit system with hundreds of GB of system memory and GPU
memory,
this can become a bottle neck. We're seeing TTM memory allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed for
our BO
book-keeping.

---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

         glob->zones[glob->num_zones++] = zone;
         return 0;
     }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
     static int ttm_mem_init_dma32_zone(struct

ttm_mem_global
*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ttm/ttm_memory.c

Quoted 8 lines
         ret = ttm_mem_init_highmem_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
         ret = ttm_mem_init_dma32_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cthellstrom%40vmware.com%7C1357d06244fb499b31dd08d6968ca04b%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636861928079462725&amp;sdata=1Bucho93KMzN0z7QbfiNn%2BNWaZs5yi86Ya6vm9Xhbqo%3D&amp;reserved=0

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

#20 lore raw
Quoted 63 lines · Felix
Quoted 54 lines · Thomas Hellstrom
Quoted 48 lines · Felix
Quoted 23 lines · Thomas Hellstrom
Quoted 14 lines · Christian König

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 9 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages
are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting
size!

Quoted 8 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone
for
this accounting which of course is completely nonsense.

Quoted 15 lines

It's actually accounted in all available zones, since it would be
pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not.
Given
the objective of stopping malicious user-space from exhausting the
DMA32 zone it was, at the time the code was written, a reasonable
approximation. With ever increasing memory sizes, there might be
better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for
the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems
to
use it to account for a few things that are allocated with kmalloc.

Quoted 5 lines

So would a better solution be to change ttm_mem_global_alloc to use
only
the kernel zone?

Quoted 8 lines

IMO we need to determine what functionality to keep and then the best
solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential
DOS attacks (DMA32 and kernel zones are not mutually exclusive. They
overlap).

Quoted 6 lines

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32 zone, so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds superflous but harmless.

/Thomas

Quoted 133 lines
Quoted 133 lines

/Thomas

Quoted 126 lines

Regards,
Felix

Quoted 122 lines

/Thomas

Quoted 120 lines

Christian.

Quoted 118 lines

For small persistent allocations using ttm_mem_global_alloc(),
they
are
accounted also in the DMA32 zone, which may cause over- accounting
of
that zone, but that's pretty unlikely to be a big problem..

/Thomas

Quoted 103 lines

In other words why should the internal bookkeeping pages be
allocated
in
the DMA32 zone?

That doesn't sounds valid to me in any way,
Christian.

Am 18.02.19 um 09:02 schrieb Thomas Hellstrom:

Quoted 93 lines

Hmm,

This zone was intended to stop TTM page allocations from
exhausting
the DMA32 zone. IIRC dma_alloc_coherent() uses DMA32 by default,
which
means if we drop this check, other devices may stop functioning
unexpectedly?

However, in the end I'd expect the kernel page allocation
system
to
make sure there are some pages left in the DMA32 zone, otherwise
random non-IO page allocations would also potentially exhaust
the
DMA32 zone without anybody caring, which means removing this
zone
wouldn't be any worse than whatever other subsystems may be
doing
already...

/Thomas

Quoted 60 lines · Felix

This is an RFC. I'm not sure this is the right
solution,
but
it
highlights the problem I'm trying to solve.

The dma32_zone limits the acc_size of all allocated BOs
to
2GB.
On a
64-bit system with hundreds of GB of system memory and
GPU
memory,
this can become a bottle neck. We're seeing TTM memory
allocation
failures not because we're truly out of memory, but because
we're
out of space in the dma32_zone for the acc_size needed
for
our BO
book-keeping.

Quoted 1 line
---
     drivers/gpu/drm/ttm/ttm_memory.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +0 -0
index f1567c3..bb05365 100644
@@ -363,7 +363,7 @@ static int

ttm_mem_init_highmem_zone(struct
ttm_mem_global *glob,

         glob->zones[glob->num_zones++] = zone;
         return 0;
     }
drivers/gpu/drm/ttm/ttm_memory.c +1 -1
-#else
+#elifndef CONFIG_64BIT
     static int ttm_mem_init_dma32_zone(struct

ttm_mem_global
*glob,
const struct sysinfo *si)
{

drivers/gpu/drm/ttm/ttm_memory.c +0 -0
@@ -441,7 +441,7 @@ int ttm_mem_global_init(struct

ttm_mem_global
*glob)

         ret = ttm_mem_init_highmem_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;

-#else

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+#elifndef CONFIG_64BIT

         ret = ttm_mem_init_dma32_zone(glob, &si);
         if (unlikely(ret != 0))
             goto out_no_zone;

_______________________________________________
amd-gfx mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cthellstrom%40vmware.com%7C5521905ed2f94144c64208d69768eda0%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636862874256927858&amp;sdata=2PqTuwA75OoJTDBZ%2BtXnuEfrI3Lham5uYTWq2rT%2BN24%3D&amp;reserved=0

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

#21 lore raw

Am 21.02.19 um 07:47 schrieb Thomas Hellstrom:

Quoted 67 lines · Felix
Quoted 66 lines · Thomas Hellstrom
Quoted 54 lines · Felix
Quoted 48 lines · Thomas Hellstrom
Quoted 23 lines · Christian König
Quoted 14 lines

Am 18.02.19 um 10:47 schrieb Thomas Hellstrom:

Quoted 9 lines · Christian
Quoted 4 lines

Another good question is also why the heck the acc_size counts
towards
the DMA32 zone?

DMA32 TTM pages are accounted in the DMA32 zone. Other pages
are
not.

Yeah, I'm perfectly aware of this. But this is for the accounting
size!

Quoted 8 lines

We have an accounting for the stuff needed additional to the pages
backing the BO (e.g. the page and DMA addr array).

And from the bug description it sounds like we use the DMA32 zone
for
this accounting which of course is completely nonsense.

Quoted 15 lines

It's actually accounted in all available zones, since it would be
pretty hard to determine exactly where that memory should be accounted.
In particular if it's vmalloced. It might be DMA32, it might not.
Given
the objective of stopping malicious user-space from exhausting the
DMA32 zone it was, at the time the code was written, a reasonable
approximation. With ever increasing memory sizes, there might be
better
solutions?

As far as I can see, in TTM, ttm_mem_global_alloc is only used for
the
acc_size in ttm_bo_init_reserved. Other than that vmwgfx also seems
to
use it to account for a few things that are allocated with kmalloc.

Quoted 5 lines

So would a better solution be to change ttm_mem_global_alloc to use
only
the kernel zone?

Quoted 8 lines

IMO we need to determine what functionality to keep and then the best
solution. The current code does its job, but is obviously too restrictive. Both of the solutions you suggest open up for potential
DOS attacks (DMA32 and kernel zones are not mutually exclusive. They
overlap).

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on x86_64? Can we make x86_64 more like HIGHMEM instead?

Quoted 8 lines
Quoted 3 lines

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32 zone, so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can only do 32bit addressing. And IIRC we can actually do DMA32 to highmem since something like 2.4.*.

Because of this it is actually irrelevant if you have highmem or not, what matters for DMA32 is if you have an IOMMU or not.

So even on x86_64 you actually do need the DMA32 zone if you don't have an IOMMU which remaps all memory for devices which can't directly address it.

Regards,
Christian.

Quoted 4 lines

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 4423e7aa-2153-5305-91c2-8d212ae1786b-5C7GfCeVMHo@public.gmane.org

#23 lore raw
Quoted 9 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on

Quoted 8 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32 zone, so we'd always exhaust the kernel zone before dma32 anyway.

Quoted 8 lines
Quoted 2 lines

Not sure why we have dma32 on x86 without highmem, though. sounds superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can only do 32bit addressing. And IIRC we can actually do DMA32 to highmem since something like 2.4.*.

Because of this it is actually irrelevant if you have highmem or not, what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 4 lines

So even on x86_64 you actually do need the DMA32 zone if you don't have an IOMMU which remaps all memory for devices which can't directly address it.

Why is DMA32 special in this way? For example AMD GFX8 GPUs support 40-bit DMA. But we don't have a special zone for that.

How common is it to have devices that need DMA32 on an x86_64 system?

Regards,
  Felix

Quoted 7 lines

Regards,
Christian.

Quoted 3 lines

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 2a76cb48-10f1-6df2-5b40-8d5b4c52acc4-5C7GfCeVMHo@public.gmane.org

#25 lore raw
Quoted 26 lines · Felix
Quoted 18 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on

Quoted 11 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32 zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can only do
32bit addressing. And IIRC we can actually do DMA32 to highmem since
something like 2.4.*.

Quoted 3 lines

Because of this it is actually irrelevant if you have highmem or not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 7 lines
Quoted 4 lines

So even on x86_64 you actually do need the DMA32 zone if you don't have
an IOMMU which remaps all memory for devices which can't directly address it.

Why is DMA32 special in this way? For example AMD GFX8 GPUs support 40-bit DMA. But we don't have a special zone for that.

If you're running on a non-IOMMU system with physical memory addresses

Quoted 1 line

40 bits, and tell the DMA subsystem that you need to restrict to 40

bits, it will probably start using bounce buffers for streaming DMA (which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32 zone.

Quoted 2 lines

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory unless they explicitly set the dma coherent mask to something larger. Like Christian says, if an IOMMU is present and enabled, the need for the DMA32 zone goes away. In theory at least.

/Thomas

Quoted 11 lines

Regards,
Felix

Quoted 6 lines

Regards,
Christian.

Quoted 3 lines

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 39a4a5534ea3d5fa9ba94714e80f919c5a43aea9.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#27 lore raw
Quoted 30 lines · Thomas Hellstrom
Quoted 29 lines · Felix
Quoted 18 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on

Quoted 11 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32 zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can only do
32bit addressing. And IIRC we can actually do DMA32 to highmem since
something like 2.4.*.

Quoted 3 lines

Because of this it is actually irrelevant if you have highmem or not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 4 lines

So even on x86_64 you actually do need the DMA32 zone if you don't have
an IOMMU which remaps all memory for devices which can't directly address it.

Quoted 7 lines
Quoted 2 lines

Why is DMA32 special in this way? For example AMD GFX8 GPUs support 40-bit DMA. But we don't have a special zone for that.

If you're running on a non-IOMMU system with physical memory addresses

Quoted 1 line

40 bits, and tell the DMA subsystem that you need to restrict to 40

bits, it will probably start using bounce buffers for streaming DMA (which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32 zone.

OK, then why is it not needed when CONFIG_HIGHMEM is defined?

I found that there is a CONFIG_ZONE_DMA32 parameter. Maybe we should use that to decide whether to account for the DMA32 zone in TTM. It is set on x86_64 and a number of other 64-bit architectures.

Quoted 5 lines
Quoted 1 line

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory unless they explicitly set the dma coherent mask to something larger. Like Christian says, if an IOMMU is present and enabled, the need for the DMA32 zone goes away. In theory at least.

Thanks. I read up a bit on DMA32 and memory zones in general. I found that there is a lowmem_reserve_ratio feature that protects against normal page allocations overflowing into lowmem zones. There is some documentation in Documentation/scsctl/vm.txt (search for lowmem_reserve_ratio). The protected amount of memory in each zone can be seen in /proc/zoneinfo.

With that, can we conclude that we don't need to count ttm_mem_global_alloc against the dma32 zone.

Thanks,
  Felix

Quoted 14 lines

/Thomas

Quoted 10 lines

Regards,
Felix

Quoted 6 lines

Regards,
Christian.

Quoted 3 lines

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 2b4ea7ed-08e6-6dd3-7b56-e7c1713fc357-5C7GfCeVMHo@public.gmane.org

#29 lore raw

Hi,

Quoted 78 lines · Felix
Quoted 41 lines · Thomas Hellstrom
Quoted 37 lines · Felix
Quoted 22 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on

Quoted 5 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

Quoted 8 lines

IIRC with x86, the kernel zone is always smaller than any dma32
zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds
superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can
only do
32bit addressing. And IIRC we can actually do DMA32 to highmem since
something like 2.4.*.

Quoted 4 lines

Because of this it is actually irrelevant if you have highmem or
not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 6 lines

So even on x86_64 you actually do need the DMA32 zone if you don't
have
an IOMMU which remaps all memory for devices which can't directly
address it.

Quoted 3 lines

Why is DMA32 special in this way? For example AMD GFX8 GPUs support
40-bit DMA. But we don't have a special zone for that.

Quoted 8 lines

If you're running on a non-IOMMU system with physical memory addresses

Quoted 2 lines

40 bits, and tell the DMA subsystem that you need to restrict to 40

bits, it will probably start using bounce buffers for streaming DMA (which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32 zone.

OK, then why is it not needed when CONFIG_HIGHMEM is defined?

I found that there is a CONFIG_ZONE_DMA32 parameter. Maybe we should use
that to decide whether to account for the DMA32 zone in TTM. It is set
on x86_64 and a number of other 64-bit architectures.

Quoted 8 lines
Quoted 2 lines

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory unless they explicitly set the dma coherent mask to something larger.
Like Christian says, if an IOMMU is present and enabled, the need for
the DMA32 zone goes away. In theory at least.

Thanks. I read up a bit on DMA32 and memory zones in general. I found
that there is a lowmem_reserve_ratio feature that protects against normal page allocations overflowing into lowmem zones. There is some documentation in Documentation/scsctl/vm.txt (search for lowmem_reserve_ratio). The protected amount of memory in each zone can
be seen in /proc/zoneinfo.

Quoted 2 lines

With that, can we conclude that we don't need to count ttm_mem_global_alloc against the dma32 zone.

Yes, it indeed looks like that.
But then I would suggest removing the DMA32 zone entirely.

/Thomas

Quoted 18 lines

Thanks,
Felix

Quoted 13 lines

/Thomas

Quoted 10 lines

Regards,
Felix

Quoted 6 lines

Regards,
Christian.

Quoted 3 lines

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 0f1a3b818a4f6b426dff5c641332a456b08136f8.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#31 lore raw

Am 21.02.19 um 22:02 schrieb Thomas Hellstrom:

Quoted 79 lines

Hi,

Quoted 76 lines · Felix
Quoted 41 lines · Thomas Hellstrom
Quoted 37 lines · Felix
Quoted 22 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one on

Quoted 5 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

Quoted 8 lines

IIRC with x86, the kernel zone is always smaller than any dma32
zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Not sure why we have dma32 on x86 without highmem, though. sounds
superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who can
only do
32bit addressing. And IIRC we can actually do DMA32 to highmem since
something like 2.4.*.

Quoted 4 lines

Because of this it is actually irrelevant if you have highmem or
not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 6 lines

So even on x86_64 you actually do need the DMA32 zone if you don't
have
an IOMMU which remaps all memory for devices which can't directly
address it.

Quoted 3 lines

Why is DMA32 special in this way? For example AMD GFX8 GPUs support
40-bit DMA. But we don't have a special zone for that.

Quoted 8 lines

If you're running on a non-IOMMU system with physical memory addresses

Quoted 2 lines

40 bits, and tell the DMA subsystem that you need to restrict to 40

bits, it will probably start using bounce buffers for streaming DMA (which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32 zone.

OK, then why is it not needed when CONFIG_HIGHMEM is defined?

I found that there is a CONFIG_ZONE_DMA32 parameter. Maybe we should use
that to decide whether to account for the DMA32 zone in TTM. It is set
on x86_64 and a number of other 64-bit architectures.

Quoted 8 lines
Quoted 2 lines

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory unless they explicitly set the dma coherent mask to something larger.
Like Christian says, if an IOMMU is present and enabled, the need for
the DMA32 zone goes away. In theory at least.

Thanks. I read up a bit on DMA32 and memory zones in general. I found
that there is a lowmem_reserve_ratio feature that protects against normal page allocations overflowing into lowmem zones. There is some documentation in Documentation/scsctl/vm.txt (search for lowmem_reserve_ratio). The protected amount of memory in each zone can
be seen in /proc/zoneinfo.

Quoted 4 lines
Quoted 2 lines

With that, can we conclude that we don't need to count ttm_mem_global_alloc against the dma32 zone.

Yes, it indeed looks like that.
But then I would suggest removing the DMA32 zone entirely.

We still need it for the pages we allocate, but we should just stop accounting all the housekeeping to it.

To answer Felix earlier question we really still need DMA32 without IOMMU even on a 64bit system. The problem is simply that you have tons of PCIe hardware which can do only 32bit addressing, for example the audio codecs even on our newest Vega chips.

Regards,
Christian.

Quoted 21 lines

/Thomas

Quoted 17 lines

Thanks,
Felix

Quoted 13 lines

/Thomas

Quoted 10 lines

Regards,
Felix

Quoted 6 lines

Regards,
Christian.

Quoted 3 lines

/Thomas

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

#32 lore raw
Quoted 97 lines · Christian

Am 21.02.19 um 22:02 schrieb Thomas Hellstrom:

Quoted 96 lines

Hi,

Quoted 93 lines · Felix
Quoted 53 lines · Thomas Hellstrom
Quoted 44 lines · Felix
Quoted 27 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one
on

Quoted 11 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32
zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Quoted 4 lines

Not sure why we have dma32 on x86 without highmem, though.
sounds
superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who
can
only do
32bit addressing. And IIRC we can actually do DMA32 to highmem
since
something like 2.4.*.

Quoted 5 lines

Because of this it is actually irrelevant if you have highmem
or
not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 7 lines

So even on x86_64 you actually do need the DMA32 zone if you
don't
have
an IOMMU which remaps all memory for devices which can't directly
address it.

Quoted 3 lines

Why is DMA32 special in this way? For example AMD GFX8 GPUs support
40-bit DMA. But we don't have a special zone for that.

If you're running on a non-IOMMU system with physical memory addresses

Quoted 3 lines

40 bits, and tell the DMA subsystem that you need to restrict to
40

Quoted 6 lines

bits, it will probably start using bounce buffers for streaming DMA
(which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32
zone.

OK, then why is it not needed when CONFIG_HIGHMEM is defined?

I found that there is a CONFIG_ZONE_DMA32 parameter. Maybe we should
use
that to decide whether to account for the DMA32 zone in TTM. It is
set
on x86_64 and a number of other 64-bit architectures.

Quoted 10 lines
Quoted 2 lines

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory
unless they explicitly set the dma coherent mask to something larger.
Like Christian says, if an IOMMU is present and enabled, the need
for
the DMA32 zone goes away. In theory at least.

Thanks. I read up a bit on DMA32 and memory zones in general. I found
that there is a lowmem_reserve_ratio feature that protects against
normal page allocations overflowing into lowmem zones. There is some
documentation in Documentation/scsctl/vm.txt (search for lowmem_reserve_ratio). The protected amount of memory in each zone
can
be seen in /proc/zoneinfo.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

With that, can we conclude that we don't need to count ttm_mem_global_alloc against the dma32 zone.

Yes, it indeed looks like that.
But then I would suggest removing the DMA32 zone entirely.

We still need it for the pages we allocate, but we should just stop accounting all the housekeeping to it.

Why is that? Can't we just account all pages in the kernel zone, and leave it up to the kernel to make sure there are still DMA32 pages left?

/Thomas

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

A message that is not in the archive (sent off-list or not yet received): 0c5e5ad70e2acbf2efd9fd0878768dcd5e008cd3.camel-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#34 lore raw
Quoted 100 lines · Thomas Hellstrom
Quoted 99 lines · Christian

Am 21.02.19 um 22:02 schrieb Thomas Hellstrom:

Quoted 98 lines

Hi,

Quoted 95 lines · Felix
Quoted 53 lines · Thomas Hellstrom
Quoted 44 lines · Felix
Quoted 27 lines · Christian

On x86 with HIGHMEM there is no dma32 zone. Why do we need one
on

Quoted 11 lines
Quoted 5 lines

x86_64? Can we make x86_64 more like HIGHMEM instead?

Regards,
Felix

IIRC with x86, the kernel zone is always smaller than any dma32
zone,
so we'd always exhaust the kernel zone before dma32 anyway.

Quoted 4 lines

Not sure why we have dma32 on x86 without highmem, though.
sounds
superflous but harmless.

Well DMA32 denotes memory which is accessible by devices who
can
only do
32bit addressing. And IIRC we can actually do DMA32 to highmem
since
something like 2.4.*.

Quoted 5 lines

Because of this it is actually irrelevant if you have highmem
or
not,
what matters for DMA32 is if you have an IOMMU or not.

Are you saying we should have a dma32_zone even on x86 with HIGHMEM?

Quoted 7 lines

So even on x86_64 you actually do need the DMA32 zone if you
don't
have
an IOMMU which remaps all memory for devices which can't directly
address it.

Quoted 3 lines

Why is DMA32 special in this way? For example AMD GFX8 GPUs support
40-bit DMA. But we don't have a special zone for that.

If you're running on a non-IOMMU system with physical memory addresses

Quoted 3 lines

40 bits, and tell the DMA subsystem that you need to restrict to
40

Quoted 6 lines

bits, it will probably start using bounce buffers for streaming DMA
(which won't work with most graphics drivers), or for dma_alloc_coherent(), it will probably use memory from the DMA32
zone.

OK, then why is it not needed when CONFIG_HIGHMEM is defined?

I found that there is a CONFIG_ZONE_DMA32 parameter. Maybe we should
use
that to decide whether to account for the DMA32 zone in TTM. It is
set
on x86_64 and a number of other 64-bit architectures.

Quoted 10 lines
Quoted 2 lines

How common is it to have devices that need DMA32 on an x86_64 system?

IIRC All devices using dma_alloc_coherent() allocate DMA32 memory
unless they explicitly set the dma coherent mask to something larger.
Like Christian says, if an IOMMU is present and enabled, the need
for
the DMA32 zone goes away. In theory at least.

Thanks. I read up a bit on DMA32 and memory zones in general. I found
that there is a lowmem_reserve_ratio feature that protects against
normal page allocations overflowing into lowmem zones. There is some
documentation in Documentation/scsctl/vm.txt (search for lowmem_reserve_ratio). The protected amount of memory in each zone
can
be seen in /proc/zoneinfo.

With that, can we conclude that we don't need to count ttm_mem_global_alloc against the dma32 zone.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Yes, it indeed looks like that.
But then I would suggest removing the DMA32 zone entirely.

We still need it for the pages we allocate, but we should just stop accounting all the housekeeping to it.

Why is that? Can't we just account all pages in the kernel zone, and leave it up to the kernel to make sure there are still DMA32 pages left?

ttm_page_alloc and ttm_page_alloc_dma support allocating from DMA32 explicitly (setting GFP_DMA32). Such allocations could exhaust DMA32 memory, which TTM should prevent by limiting its DMA32 usage. This would still be counted against the dma32 zone by ttm_mem_global_alloc_page.

I'll send out a new patch that counts general kernel allocations against the kernel zone only. I hope this would be acceptable.

Regards,
  Felix

Quoted 3 lines

/Thomas

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