Re: [PATCH] drm/ttm: fix ttm tt init fail when size exceeds kmalloc limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 20.04.22 um 10:56 schrieb Yang Wang:
if the __GFP_ZERO is set, the kvmalloc() can't fallback to use vmalloc()

Hui what? Why should kvmalloc() not be able to fallback to vmalloc() when __GFP_ZERO is set?

And even that is really the case then that sounds like a bug in kvmalloc().

Regards,
Christian.

to allocate memory, when request size is exceeds kmalloc limit, it will
cause allocate memory fail.

e.g: when ttm want to create a BO with 1TB size, it maybe fail.

Signed-off-by: Yang Wang <KevinYang.Wang@xxxxxxx>
---
  drivers/gpu/drm/ttm/ttm_tt.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 79c870a3bef8..9f2f3e576b8d 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -97,9 +97,12 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc)
  static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
  {
  	ttm->pages = kvmalloc_array(ttm->num_pages, sizeof(void*),
-			GFP_KERNEL | __GFP_ZERO);
+				    GFP_KERNEL);
  	if (!ttm->pages)
  		return -ENOMEM;
+
+	memset(ttm->pages, 0, ttm->num_pages * sizeof(void *));
+
  	return 0;
  }
@@ -108,10 +111,12 @@ static int ttm_dma_tt_alloc_page_directory(struct ttm_tt *ttm)
  	ttm->pages = kvmalloc_array(ttm->num_pages,
  				    sizeof(*ttm->pages) +
  				    sizeof(*ttm->dma_address),
-				    GFP_KERNEL | __GFP_ZERO);
+				    GFP_KERNEL);
  	if (!ttm->pages)
  		return -ENOMEM;
+ memset(ttm->pages, 0, ttm->num_pages * (sizeof(*ttm->pages) + sizeof(*ttm->dma_address)));
+
  	ttm->dma_address = (void *)(ttm->pages + ttm->num_pages);
  	return 0;
  }
@@ -120,9 +125,12 @@ static int ttm_sg_tt_alloc_page_directory(struct ttm_tt *ttm)
  {
  	ttm->dma_address = kvmalloc_array(ttm->num_pages,
  					  sizeof(*ttm->dma_address),
-					  GFP_KERNEL | __GFP_ZERO);
+					  GFP_KERNEL);
  	if (!ttm->dma_address)
  		return -ENOMEM;
+
+	memset(ttm->dma_address, 0, ttm->num_pages * sizeof(*ttm->dma_address));
+
  	return 0;
  }




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux