<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
Am 20.04.22 um 11:07 schrieb Wang, Yang(Kevin):<br>
<blockquote type="cite" cite="mid:CO6PR12MB54733101E19842B59668482B82F59@CO6PR12MB5473.namprd12.prod.outlook.com">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif;
font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b>
Koenig, Christian <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a><br>
<b>Sent:</b> Wednesday, April 20, 2022 5:00 PM<br>
<b>To:</b> Wang, Yang(Kevin) <a class="moz-txt-link-rfc2396E" href="mailto:KevinYang.Wang@amd.com"><KevinYang.Wang@amd.com></a>;
<a class="moz-txt-link-abbreviated" href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a>
<a class="moz-txt-link-rfc2396E" href="mailto:dri-devel@lists.freedesktop.org"><dri-devel@lists.freedesktop.org></a>;
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a><br>
<b>Subject:</b> Re: [PATCH] drm/ttm: fix ttm tt init fail
when size exceeds kmalloc limit</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">Am 20.04.22 um 10:56
schrieb Yang Wang:<br>
> if the __GFP_ZERO is set, the kvmalloc() can't
fallback to use vmalloc()<br>
<br>
Hui what? Why should kvmalloc() not be able to fallback
to vmalloc() <br>
when __GFP_ZERO is set?<br>
<br>
And even that is really the case then that sounds like a
bug in kvmalloc().</div>
<div class="PlainText elementToProof"><br>
Regards,<br>
Christian.</div>
<div class="PlainText elementToProof"><br>
<div class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">[kevin]:</div>
</div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">it
is really test case from libdrm amdgpu test, which try
to allocate a big BO which will cause ttm tt init
fail.</span><br>
</div>
</span></font></div>
</div>
</blockquote>
<br>
<br>
LOL! Guys, this test case is intended to fail!<br>
<br>
The test consists of allocating a buffer so ridiculous large that it
should never succeed and be rejected by the kernel driver.<br>
<br>
This patch here is a really clear NAK.<br>
<br>
Regards,<br>
Christian.<br>
<br>
<blockquote type="cite" cite="mid:CO6PR12MB54733101E19842B59668482B82F59@CO6PR12MB5473.namprd12.prod.outlook.com">
<div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">
</div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">it
may be a kvmalloc() bug, and this patch can as a
workaround in<span style="background-color:rgb(255,
255, 255);display:inline !important"> ttm</span> before
this issue fix.</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)"><br>
</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">void
*kvmalloc_node(size_t size, gfp_t flags, int node) <br>
</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">{</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">...</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">
if ((flags & GFP_KERNEL) != GFP_KERNEL)<br>
</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">
return kmalloc_node(size, flags, node);<br>
</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">...</span></div>
<div class="PlainText elementToProof"><span class="PlainText" style="margin:0px;background-color:rgb(255, 255, 255)">}</span></div>
<div class="PlainText elementToProof"><br>
</div>
<div class="PlainText elementToProof">Best Regards,</div>
<div class="PlainText elementToProof">Kevin<br>
<br>
> to allocate memory, when request size is exceeds
kmalloc limit, it will<br>
> cause allocate memory fail.<br>
><br>
> e.g: when ttm want to create a BO with 1TB size, it
maybe fail.<br>
><br>
> Signed-off-by: Yang Wang
<a class="moz-txt-link-rfc2396E" href="mailto:KevinYang.Wang@amd.com"><KevinYang.Wang@amd.com></a><br>
> ---<br>
> drivers/gpu/drm/ttm/ttm_tt.c | 14 +++++++++++---<br>
> 1 file changed, 11 insertions(+), 3 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c
b/drivers/gpu/drm/ttm/ttm_tt.c<br>
> index 79c870a3bef8..9f2f3e576b8d 100644<br>
> --- a/drivers/gpu/drm/ttm/ttm_tt.c<br>
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c<br>
> @@ -97,9 +97,12 @@ int ttm_tt_create(struct
ttm_buffer_object *bo, bool zero_alloc)<br>
> static int ttm_tt_alloc_page_directory(struct
ttm_tt *ttm)<br>
> {<br>
> ttm->pages =
kvmalloc_array(ttm->num_pages, sizeof(void*),<br>
> - GFP_KERNEL | __GFP_ZERO);<br>
> + GFP_KERNEL);<br>
> if (!ttm->pages)<br>
> return -ENOMEM;<br>
> +<br>
> + memset(ttm->pages, 0, ttm->num_pages *
sizeof(void *));<br>
> +<br>
> return 0;<br>
> }<br>
> <br>
> @@ -108,10 +111,12 @@ static int
ttm_dma_tt_alloc_page_directory(struct ttm_tt *ttm)<br>
> ttm->pages =
kvmalloc_array(ttm->num_pages,<br>
>
sizeof(*ttm->pages) +<br>
>
sizeof(*ttm->dma_address),<br>
> - GFP_KERNEL |
__GFP_ZERO);<br>
> + GFP_KERNEL);<br>
> if (!ttm->pages)<br>
> return -ENOMEM;<br>
> <br>
> + memset(ttm->pages, 0, ttm->num_pages *
(sizeof(*ttm->pages) +
sizeof(*ttm->dma_address)));<br>
> +<br>
> ttm->dma_address = (void *)(ttm->pages
+ ttm->num_pages);<br>
> return 0;<br>
> }<br>
> @@ -120,9 +125,12 @@ static int
ttm_sg_tt_alloc_page_directory(struct ttm_tt *ttm)<br>
> {<br>
> ttm->dma_address =
kvmalloc_array(ttm->num_pages,<br>
>
sizeof(*ttm->dma_address),<br>
> - GFP_KERNEL
| __GFP_ZERO);<br>
> +
GFP_KERNEL);<br>
> if (!ttm->dma_address)<br>
> return -ENOMEM;<br>
> +<br>
> + memset(ttm->dma_address, 0,
ttm->num_pages * sizeof(*ttm->dma_address));<br>
> +<br>
> return 0;<br>
> }<br>
> <br>
<br>
</div>
</span></font></div>
</div>
</blockquote>
<br>
</body>
</html>