<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<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);" class="elementToProof">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">Hi Chris,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">you misunderstood background about this case.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">a</span><span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);">lthough
we expect this test case to fail, it should fail at the location where the Bo actual memory is actually allocated. now the code logic will cause the failure to allocate memory to store DMA address.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);"><span style="background-color:rgb(255, 255, 255);display:inline !important">e.g: </span>the case is failed in 2TB system
ram machine, it should be allocated successful, but it is failed.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0);">allocate 1TB BO, the ttm should allocate 1TB/4k * 8 buffer to store allocate result (page address), this should not be
failed usually.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-size: 12pt; background-color: rgba(0, 0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif;"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-size: 12pt; background-color: rgba(0, 0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif;">There is a similar fix in upstream kernel 5.18, b</span><span style="color: rgb(0, 0, 0); font-size: 12pt; background-color: rgba(0, 0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif;">efore
this fix entered the TTM code, this problem existed in TTM.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-size: 12pt; background-color: rgba(0, 0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif;"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="color: rgb(0, 0, 0); font-size: 12pt; background-color: rgba(0, 0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif;"><a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.18-rc3&id=a421ef303008b0ceee2cfc625c3246fa7654b0ca" id="LPlnk660272">kernel/git/torvalds/linux.git
- Linux kernel source tree</a><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span class="commit-subject" style="font-size: 12pt; margin: 1.5em 0em 0.5em; padding: 0em; color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">mm: allow !GFP_KERNEL allocations for kvmalloc</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<div><br>
</div>
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">Best Regards,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">Kevin</span><br>
<div><br>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Koenig, Christian <Christian.Koenig@amd.com><br>
<b>Sent:</b> Wednesday, April 20, 2022 6:53 PM<br>
<b>To:</b> Wang, Yang(Kevin) <KevinYang.Wang@amd.com>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH] drm/ttm: fix ttm tt init fail when size exceeds kmalloc limit</font>
<div> </div>
</div>
<div>Am 20.04.22 um 11:07 schrieb Wang, Yang(Kevin):<br>
<blockquote type="cite">
<p align="Left" style="margin-top: 0px; margin-bottom: 0px;font-family:Arial; font-size:10pt; color:#0000FF; margin:5pt">
[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="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Koenig, Christian
<a href="mailto:Christian.Koenig@amd.com" data-auth="NotApplicable" class="x_moz-txt-link-rfc2396E">
<Christian.Koenig@amd.com></a><br>
<b>Sent:</b> Wednesday, April 20, 2022 5:00 PM<br>
<b>To:</b> Wang, Yang(Kevin) <a href="mailto:KevinYang.Wang@amd.com" data-auth="NotApplicable" class="x_moz-txt-link-rfc2396E">
<KevinYang.Wang@amd.com></a>; <a href="mailto:dri-devel@lists.freedesktop.org" data-auth="NotApplicable" class="x_moz-txt-link-abbreviated">
dri-devel@lists.freedesktop.org</a> <a href="mailto:dri-devel@lists.freedesktop.org" data-auth="NotApplicable" class="x_moz-txt-link-rfc2396E">
<dri-devel@lists.freedesktop.org></a>; <a href="mailto:amd-gfx@lists.freedesktop.org" data-auth="NotApplicable" class="x_moz-txt-link-abbreviated">
amd-gfx@lists.freedesktop.org</a> <a href="mailto:amd-gfx@lists.freedesktop.org" data-auth="NotApplicable" class="x_moz-txt-link-rfc2396E">
<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="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText x_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="x_PlainText x_elementToProof"><br>
Regards,<br>
Christian.</div>
<div class="x_PlainText x_elementToProof"><br>
<div class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">[kevin]:</div>
</div>
<div class="x_PlainText x_elementToProof"><span class="x_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>
<b><br>
</b>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">
<div>
<div class="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText x_elementToProof"></div>
<div class="x_PlainText x_elementToProof"><span class="x_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="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)"><br>
</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_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="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">{</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">...</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)"> if ((flags & GFP_KERNEL) != GFP_KERNEL)<br>
</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)"> return kmalloc_node(size, flags, node);<br>
</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">...</span></div>
<div class="x_PlainText x_elementToProof"><span class="x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">}</span></div>
<div class="x_PlainText x_elementToProof"><br>
</div>
<div class="x_PlainText x_elementToProof">Best Regards,</div>
<div class="x_PlainText x_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 href="mailto:KevinYang.Wang@amd.com" data-auth="NotApplicable" class="x_moz-txt-link-rfc2396E">
<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>
</div>
</div>
</body>
</html>