<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 Chirs,</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);">yes, right, the amdgpu drive rwill use </span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0); color: rgb(0, 0, 0); display: inline !important;">amdgpu_bo_validate_size()
 function to verify bo size,</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; background-color: rgba(0, 0, 0, 0); display: inline !important; color: rgb(0, 0, 0);">but when driver try to allocate VRAM domain bo fail, the amdgpu driver will fall back to
 allocate domain = (GTT | VRAM)  bo.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgba(0, 0, 0, 0); display: inline !important; color: rgb(0, 0, 0);">please check following code, it will cause the 2</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgba(0, 0, 0, 0); color: rgb(0, 0, 0); display: inline !important;"><span style="font-size: 13.3333px;">nd
 time</span><span style="font-size: 12pt;"> to allocate bo fail during allocate 256Mb buffer to store dma address (via kvmalloc()).</span></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:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14px;background-color:rgb(255, 255, 255);display:inline !important"><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; background-color: rgba(0, 0, 0, 0); display: inline !important; color: rgb(0, 0, 0);">        initial_domain = (u32)(0xffffffff & args->in.domains);</span><span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14px;background-color:rgb(255, 255, 255);display:inline !important">
<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);">retry:</span></div>
<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);">        r = amdgpu_gem_object_create(adev, size, args->in.alignment,</span></div>
<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);">                                     initial_domain,</span></div>
<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);">                                     flags, ttm_bo_type_device, resv, &gobj);</span></div>
<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);">        if (r && r != -ERESTARTSYS) {</span></div>
<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);">                if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {</span></div>
<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);">                        flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;</span></div>
<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);">                        goto retry;</span></div>
<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);">                }</span></div>
<div><br>
</div>
<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);">                if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {</span></div>
<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);">                        initial_domain |= AMDGPU_GEM_DOMAIN_GTT;</span></div>
<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);">                        goto retry;</span></div>
<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);">                }</span></div>
<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);">                DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n",</span></div>
<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);">                                size, initial_domain, args->in.alignment, r);</span></div>
</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background-color: rgba(0, 0, 0, 0); display: inline !important; color: rgb(0, 0, 0);">        }</span><span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14px;background-color:rgb(255, 255, 255);display:inline !important"><br>
</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);">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></div>
<div id="appendonsend"></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 face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Wednesday, April 20, 2022 7:55 PM<br>
<b>To:</b> Wang, Yang(Kevin) <KevinYang.Wang@amd.com>; Koenig, Christian <Christian.Koenig@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 class="elementToProof">Hi Kevin,<br>
<br>
no, the test case should already fail in amdgpu_bo_validate_size().<br>
<br>
If we have a system with 2TiB of memory where the test case could succeed then we should increase the requested size to something larger.<br>
<br>
And if the underlying core Linux kernel functions don't allow allocations as large as the requested one we should *NEVER* ever add workarounds like this.<br>
<br>
It is perfectly expected that this test case is not able to fulfill the desired allocation. That it fails during kvmalloc is unfortunate, but not a show stopper.<br>
<br>
Regards,<br>
Christian.<br>
<br>
<br>
<div class="x_moz-cite-prefix">Am 20.04.22 um 13:32 schrieb Wang, Yang(Kevin):<br>
</div>
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt"><br>
</span></div>
<div class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fcommit%2F%3Fh%3Dv5.18-rc3%26id%3Da421ef303008b0ceee2cfc625c3246fa7654b0ca&data=05%7C01%7CKevinYang.Wang%40amd.com%7C2e9fd86a27d64a39432508da22c4b1f1%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637860525454702938%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=CiP9x3grwQ2aXFZPjpsAtwLCpBVeJufbGngy%2BtXLFbM%3D&reserved=0" data-auth="Verified" originalsrc="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.18-rc3&id=a421ef303008b0ceee2cfc625c3246fa7654b0ca" shash="KMFRekIa5um9dneRj4pqsGBn2wIcYBwLUel6we5AalD06U/g9WcKPxBwS4F9Mgfpnqpq0GbN+8AA16pzy6v+Ay23e5shnO53IP8e7UcwQUE0fw1Wd4T+gBBF8PJiMugXDZiWlVYrV3tySgoFbmz+CuFzrYJbobUVj6E5khawPfo=" id="LPlnk660272">kernel/git/torvalds/linux.git
 - Linux kernel source tree</a><br>
</span></div>
<div class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span class="x_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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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 class="x_elementToProof" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<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="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 6:53 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>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;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_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_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_x_moz-txt-link-rfc2396E">
<KevinYang.Wang@amd.com></a>; <a href="mailto:dri-devel@lists.freedesktop.org" data-auth="NotApplicable" class="x_x_moz-txt-link-abbreviated x_moz-txt-link-freetext">
dri-devel@lists.freedesktop.org</a> <a href="mailto:dri-devel@lists.freedesktop.org" data-auth="NotApplicable" class="x_x_moz-txt-link-rfc2396E">
<dri-devel@lists.freedesktop.org></a>; <a href="mailto:amd-gfx@lists.freedesktop.org" data-auth="NotApplicable" class="x_x_moz-txt-link-abbreviated x_moz-txt-link-freetext">
amd-gfx@lists.freedesktop.org</a> <a href="mailto:amd-gfx@lists.freedesktop.org" data-auth="NotApplicable" class="x_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_x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_x_PlainText x_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_x_PlainText x_x_elementToProof"><br>
Regards,<br>
Christian.</div>
<div class="x_x_PlainText x_x_elementToProof"><br>
<div class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">
[kevin]:</div>
</div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_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_x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_x_PlainText x_x_elementToProof"><span class="x_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_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)"><br>
</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_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_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">{</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">...</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">        if ((flags & GFP_KERNEL) != GFP_KERNEL)<br>
</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">                return kmalloc_node(size, flags, node);<br>
</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">...</span></div>
<div class="x_x_PlainText x_x_elementToProof"><span class="x_x_PlainText" style="margin:0px; background-color:rgb(255,255,255)">}</span></div>
<div class="x_x_PlainText x_x_elementToProof"><br>
</div>
<div class="x_x_PlainText x_x_elementToProof">Best Regards,</div>
<div class="x_x_PlainText x_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_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>
</blockquote>
<br>
</div>
</div>
</body>
</html>