dma-buf: heaps: Set allocation limit for system heap
PATCH 1/1 dma-buf: heaps: Set allocation limit for system heap
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for an extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is the same as what was set by the deprecated ION system heap.
--- drivers/dma-buf/heaps/system_heap.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/dma-buf/heaps/system_heap.c +6 -0
@@ -371,6 +371,12 @@ static struct dma_buf *system_heap_do_allocate(struct dma_heap *heap,struct page *page, *tmp_page;int i, ret = -ENOMEM ; +if (len /PAGE_SIZE >totalram_pages () /2 ) { +pr_err ("pid %d requested too large an allocation(size %lu) from system heap\n" , + current->pid, len); +return ERR_PTR (ret); + } + buffer =kzalloc (sizeof (*buffer),GFP_KERNEL );if (!buffer)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.32.0.432.gabb21c7263-goog
Quoted 9 lines · Hridya Valsaraju
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for an extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is the same as what was set by the deprecated ION system heap.
Signed-off-by Hridya Valsaraju <[email protected]>
Seems sane to me, unless folks have better suggestions for allocation limits.
thanks
-john
Quoted 7 lines · John Stultz
Quoted 5 lines · Hridya Valsaraju
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for an extremely large allocation which might destabilize the system.
Quoted 8 lines
Quoted 4 lines
The limit is set to half the size of the device's total RAM which is the same as what was set by the deprecated ION system heap.
Signed-off-by Hridya Valsaraju <[email protected]>Seems sane to me, unless folks have better suggestions for allocation limits.
Reviewed-by John Stultz <[email protected]>
Thank you for taking a look John!
Regards,
Hridya
Quoted 3 lines
thanks
-john
Sumit Semwal
maintainerHi Hridya,
Apologies for the delay in responding.
Quoted 14 lines · Hridya Valsaraju
Quoted 2 lines · John Stultz
On Thu, Jul 22, 2021 at 12:07 PM Hridya Valsaraju <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for
an
Quoted 3 lines
Quoted 3 lines
extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is
the
Quoted 2 lines
Quoted 2 lines
same as what was set by the deprecated ION system heap.
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Hridya Valsaraju <[email protected]>Seems sane to me, unless folks have better suggestions for allocation
limits.
Quoted 2 lines
Reviewed-by John Stultz <[email protected]>Thank you for taking a look John!
Looks good to me; I will apply it to drm-misc today.
Quoted 8 lines
Regards,
HridyaQuoted 3 lines
thanks
-john
Best,
Sumit.
Signature · 5 lines
Thanks and regards, Sumit Semwal (he / him) Tech Lead - LCG, Vertical Technologies Linaro.org │ Open source software for ARM SoCs
Quoted 22 lines · Sumit Semwal
Hi Hridya,
Apologies for the delay in responding.
Quoted 16 lines · Hridya Valsaraju
Quoted 2 lines · John Stultz
On Thu, Jul 22, 2021 at 12:07 PM Hridya Valsaraju <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for
an
Quoted 3 lines
Quoted 3 lines
extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is
the
Quoted 4 lines
Quoted 3 lines
same as what was set by the deprecated ION system heap.
Signed-off-by Hridya Valsaraju <[email protected]>
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Seems sane to me, unless folks have better suggestions for allocation
limits.
Quoted 2 lines
Reviewed-by John Stultz <[email protected]>Thank you for taking a look John!
Looks good to me; I will apply it to drm-misc today.
Please don't, this doesn't really solve anything:
- it's easy to bypass, just allocate more buffers to get over the limit
- resource limit plan is cgroups, not hand-rolled limits in every allocator
- the ttm "max half of system memory" is for pinned memory, to work around locking inversion issues between dma_resv_lock and core mm shrinkers. It does not actually impose an overall allocation limit, you can allocate ttm bo until your entire memory (and swap) are full. Christian König has merged a patch set to lift this by reworking the shrinker interaction, but it had to be reverted again because of some fallout I can't remember offhand. dma_resv_lock vs shrinkers is very tricky.
So if you want resource limits then you really want cgroups here.
Cheers, Daniel
Quoted 19 lines
Quoted 10 lines
Regards,
HridyaQuoted 3 lines
thanks
-johnBest,
Sumit.Signature · 5 lines
Thanks and regards, Sumit Semwal (he / him) Tech Lead - LCG, Vertical Technologies Linaro.org │ Open source software for ARM SoCs
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 45 lines · Daniel Vetter
Quoted 22 lines · Sumit Semwal
Hi Hridya,
Apologies for the delay in responding.
Quoted 16 lines · Hridya Valsaraju
Quoted 2 lines · John Stultz
On Thu, Jul 22, 2021 at 12:07 PM Hridya Valsaraju <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for
an
Quoted 3 lines
Quoted 3 lines
extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is
the
Quoted 4 lines
Quoted 3 lines
same as what was set by the deprecated ION system heap.
Signed-off-by Hridya Valsaraju <[email protected]>Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Seems sane to me, unless folks have better suggestions for allocation
limits.
Quoted 2 lines
Reviewed-by John Stultz <[email protected]>Thank you for taking a look John!
Looks good to me; I will apply it to drm-misc today.
Please don't, this doesn't really solve anything:
- it's easy to bypass, just allocate more buffers to get over the limit
- resource limit plan is cgroups, not hand-rolled limits in every allocator
- the ttm "max half of system memory" is for pinned memory, to work around locking inversion issues betweendma_resv_lockand core mm shrinkers. It does not actually impose an overall allocation limit, you can allocate ttm bo until your entire memory (and swap) are full. Christian König has merged a patch set to lift this by reworking the shrinker interaction, but it had to be reverted again because of some fallout I can't remember offhand.dma_resv_lockvs shrinkers is very tricky.
Quoted 1 line
So if you want resource limits then you really want cgroups here.
Thanks Daniel and Sumit, that makes sense. Once the GPU memory accounting cgroups are ready, we should be able to set the limit using the same.
Regards,
Hridya
Quoted 27 lines
Cheers, Daniel
Quoted 13 lines
Quoted 10 lines
Regards,
HridyaQuoted 3 lines
thanks
-johnBest,
Sumit.Quoted 6 lines
--
Thanks and regards,Sumit Semwal (he / him)
Tech Lead - LCG, Vertical Technologies
Linaro.org │ Open source software for ARM SoCs--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Sumit Semwal
maintainerHi Hridya,
Apologies for the delay in responding;
Quoted 12 lines · Hridya Valsaraju
Quoted 10 lines · John Stultz
Quoted 8 lines · Hridya Valsaraju
This patch limits the size of total memory that can be requested in a single allocation from the system heap. This would prevent a buggy/malicious client from depleting system memory by requesting for an extremely large allocation which might destabilize the system.
The limit is set to half the size of the device's total RAM which is the same as what was set by the deprecated ION system heap.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Hridya Valsaraju <[email protected]>Seems sane to me, unless folks have better suggestions for allocation limits.
Reviewed-by John Stultz <[email protected]>Thank you for taking a look John!
Looks good to me; I will apply it to drm-misc today.
Quoted 7 lines
Regards,
HridyaQuoted 3 lines
thanks
-john
Best,
Sumit.
Signature · 5 lines
Thanks and regards, Sumit Semwal (he / him) Tech Lead - LCG, Vertical Technologies Linaro.org │ Open source software for ARM SoCs