<div dir="ltr">Hi,<div><br></div><div>DirectFB is a good example of "doing it all in userspace". It works but at the cost of ending up with pretty custom interfaces and non-standard ways of handling things such as buffer addresses (physical) w.r.t to h/w acceleration, IPC/RPC, buffer sharing for multi-process support, etc. Memory management (and dma) has to be the kernel's duty.</div>
<div><br></div><div>Ilyes</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Oct 3, 2013 at 6:00 PM, Rob Clark <span dir="ltr"><<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Oct 3, 2013 at 7:48 AM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
> Hello<br>
><br>
> In my opinion, graphics stack will benefit from moving memory management to userspace because there are tons of features not available in kernel, like simd or c++.<br>
<br>
both of which bring no benefit to memory management code<br>
<br>
> Also, bugs in buffer management code will bite only one process, not the whole system.<br>
<br>
As soon as you need to pin pages (which you need to do, except for the<br>
hw that Jerome is targetting with his proposal where the GPU can<br>
really support virtual memory), memory management becomes a whole<br>
system issue.. pinning pages can only be done from the kernel and it<br>
is pretty frowned upon to have a driver that lets userspace pin<br>
arbitrary pages without being able to keep track of those pages and<br>
clean up.<br>
<br>
Anyways, it is much better to trust the kernel than userspace. In<br>
system design, you must assume userspace is untrusted. If you have<br>
enough tracking for random pages that userspace asks the kernel to pin<br>
for the gpu in order to cleanup when userspace process dies, then you<br>
have *more* complexity than what you have in GEM. Trust me, it is far<br>
easier for the kernel to deal with buffer handles than having go<br>
figure out the pages backing a random vma (get_user_pages()) and<br>
keeping track of things on a per-page basis.<br>
<br>
><br>
> However, tile-based page flipping can be implemented without major changes in graphics stack and it may improve double-buffered 2D rendering performance by reducing amount of blitted pixels by reusing unchanged pages. If GPU's ROP units can take pixels from one location(front buffer) and put results to another one(back buffer), blitting may be completely avoided if a small area of double buffered window is updated.<br>
><br>
<br>
Taking pixels from one location to another sounds like blitting to me.<br>
But anyways, client GL app blitting (or otherwise) directly into<br>
front buffer is basically defeating the purpose of dri2<br>
<br>
And tile base page flipping is an orthogonal topic to userspace vs<br>
kernel memory management.<br>
<br>
> As for security, there are thousands of ways to peeform a DoS attack. In windows, one can eat so much ram, so user will be unable to kill an app because the task manager will not start. To avoid this, some memory must be reserved for emergency situation, enough to perform 2D rendering by single client. Multiple clients will be able to render their gui without caching of window contents even under stress conditions. Also, kernel dri module must be able to warn a client if it must return memory to system and reset it's context on task manager request<br>
><br>
<br>
With the current GEM design, buffers can be swapped out under memory<br>
pressure, or the appropriate cleanup done if OOM killer kills a<br>
userspace process.<br>
<br>
Doing the memory management in userspace, there are just so many ways<br>
that things can go wrong. And once you've fixed those, you end up<br>
with something more complex. Sorry, it is just a really bad idea.<br>
<br>
BR,<br>
-R<br>
<br>
> Regards, Dmitry.<br>
><br>
><br>
><br>
> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
><br>
>>right, but the time you do that, you've implemented enough memory<br>
>>tracking/management in the kernel, so you don't really win on<br>
>>complexity. Otherwise those pinned pages will remain pinned, and you<br>
>>are still out of memory.<br>
>><br>
>>BR,<br>
>>-R<br>
>><br>
>><br>
>>On Fri, Sep 27, 2013 at 7:53 PM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
>>> DoS from client app is a certainly a problem if we can't interrupt a program. But we can.<br>
>>><br>
>>> The program ate all gpu ram, ok. Let wm to cast oom killer on gpu ram eater.j<br>
>>><br>
>>> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
>>><br>
>>>>sure, but userspace memory management is not a good idea for gpu's<br>
>>>>which cannot support page fault & resume, as it requires pinning<br>
>>>>pages. In the best case (ignoring other issues), it allows any<br>
>>>>userspace that can use GPU easily construct a DoS attach by pinning<br>
>>>>all available memory.<br>
>>>><br>
>>>>BR,<br>
>>>>-R<br>
>>>><br>
>>>>On Fri, Sep 27, 2013 at 6:54 PM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
>>>>> My idea targets not only new gpus. it targets any GPU with MMU.<br>
>>>>><br>
>>>>><br>
>>>>> I just want the idea to be not patentable.<br>
>>>>><br>
>>>>> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
>>>>><br>
>>>>>>new gpu's can support coherency.. this is the HSA stuff (latest<br>
>>>>>>generation of radeon can support, and I think latest nv stuff as<br>
>>>>>>well.. probably not any current intel hw, though). What Jerome was<br>
>>>>>>talking about is a bit different from what you are trying to do.<br>
>>>>>><br>
>>>>>>On Fri, Sep 27, 2013 at 6:41 PM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
>>>>>>> Passing structures... well, maybe sometimes in future.<br>
>>>>>>><br>
>>>>>>> But NOW we are not living in infuture. Right now gpus doesn't support cache snooping, memory coherence protocols like MESI or MOESI. Radeon cache is read-only. And memory is NUMA. Just forget about coherence.<br>
>>>>>>><br>
>>>>>>> I see no point in fighting selfmade problems. Really.<br>
>>>>>>><br>
>>>>>>> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
>>>>>>><br>
>>>>>>>>Jerome's talk was about something above and beyond opencl, where you<br>
>>>>>>>>can just pass data structures (which can include cpu userspace ptrs)<br>
>>>>>>>>to the gpu for more transparent cpu/gpu interoperability.. (ie.<br>
>>>>>>>>without explicit map step)<br>
>>>>>>>><br>
>>>>>>>>BR,<br>
>>>>>>>>-R<br>
>>>>>>>><br>
>>>>>>>>On Fri, Sep 27, 2013 at 5:54 PM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
>>>>>>>>> In my opinion, GART support can be dropped because non pci-e hardware is just not usable with modern linux distros. It is too old and does not have enough ram.<br>
>>>>>>>>><br>
>>>>>>>>> About page faults: I don't really understand what is the problem with page faults. All pages referenced by memory map must be locked before execution of a gpu operation. Memory map must be locked(by rwsem) while it is in use.<br>
>>>>>>>>><br>
>>>>>>>>> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
>>>>>>>>><br>
>>>>>>>>>>For GL yes (ignoring some important details like GART size<br>
>>>>>>>>>>limitations, alignment, etc)<br>
>>>>>>>>>><br>
>>>>>>>>>>Jerome's talk was about doing things where an explicit map-to-gpu is<br>
>>>>>>>>>>not required... think of things like passing a pointer to a linked<br>
>>>>>>>>>>list to a shader. For that you need to let the CPU intervene on page<br>
>>>>>>>>>>fault from GPU.<br>
>>>>>>>>>><br>
>>>>>>>>>>BR,<br>
>>>>>>>>>>-R<br>
>>>>>>>>>><br>
>>>>>>>>>>On Fri, Sep 27, 2013 at 4:48 PM, dm.leontiev7 <<a href="mailto:dm.leontiev7@gmail.com">dm.leontiev7@gmail.com</a>> wrote:<br>
>>>>>>>>>>> Hello<br>
>>>>>>>>>>><br>
>>>>>>>>>>> Page fault support is not required: virtual address space can be separated into 3 areas: read-only, write-only and read-write. So, no read-write protection on mmu level is required.<br>
>>>>>>>>>>><br>
>>>>>>>>>>> Non-existent pages are not the problem because an application has to allocate page before mapping it. Pages must always exist.<br>
>>>>>>>>>>><br>
>>>>>>>>>>> On page deallocation driver must invalidate all affected memory maps.<br>
>>>>>>>>>>><br>
>>>>>>>>>>> Regards,<br>
>>>>>>>>>>> Dmitry<br>
>>>>>>>>>>><br>
>>>>>>>>>>><br>
>>>>>>>>>>><br>
>>>>>>>>>>><br>
>>>>>>>>>>> Пользователь Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> писал:<br>
>>>>>>>>>>><br>
>>>>>>>>>>>>On Fri, Sep 27, 2013 at 3:08 PM, Christian König<br>
>>>>>>>>>>>><<a href="mailto:deathsimple@vodafone.de">deathsimple@vodafone.de</a>> wrote:<br>
>>>>>>>>>>>>><br>
>>>>>>>>>>>>> A different story is backing buffers with anonymous system memory. I was<br>
>>>>>>>>>>>>> told that Jerome just recently did a very interesting talk at XDC about it<br>
>>>>>>>>>>>>> (didn't have time to look at it myself).<br>
>>>>>>>>>>>><br>
>>>>>>>>>>>><br>
>>>>>>>>>>>>note that this requires a gpu which can page fault (and more<br>
>>>>>>>>>>>>importantly, resume after cpu intervenes on page fault).. which I<br>
>>>>>>>>>>>>think means modern(ish) radeon or nv..<br>
>>>>>>>>>>>><br>
>>>>>>>>>>>>BR,<br>
>>>>>>>>>>>>-R<br>
_______________________________________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/dri-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</blockquote></div><br></div>