<div dir="auto">The env var workaround is fine.<div dir="auto"><br></div><div dir="auto">Thread affinity is used for cache topology related optimizations. I think it's a mistake to treat it only as a resource allocation tool.</div><div dir="auto"><br></div><div dir="auto">Marek</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2019, 1:59 AM Marc-André Lureau <<a href="mailto:marcandre.lureau@gmail.com">marcandre.lureau@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
On Fri, Mar 1, 2019 at 12:13 PM Mathias Fröhlich<br>
<<a href="mailto:Mathias.Froehlich@gmx.net" target="_blank" rel="noreferrer">Mathias.Froehlich@gmx.net</a>> wrote:<br>
><br>
> On Friday, 1 March 2019 12:15:08 CET Eero Tamminen wrote:<br>
> > Hi,<br>
> ><br>
> > On 1.3.2019 11.12, Michel Dänzer wrote:<br>
> > > On 2019-02-28 8:41 p.m., Marek Olšák wrote:<br>
> > >>> On Thu, Feb 28, 2019 at 1:37 PM Eero Tamminen <<a href="mailto:eero.t.tamminen@intel.com" target="_blank" rel="noreferrer">eero.t.tamminen@intel.com</a>><br>
> > >>>> Why distro versions of Qemu filter sched_setaffinity() syscall?<br>
> > >>><br>
> > >>> (<a href="https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1815889" rel="noreferrer noreferrer" target="_blank">https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1815889</a>)<br>
> > >>><br>
> > >>> Daniel Berrange (berrange) wrote on 2019-02-27: #19<br>
> > >>><br>
> > >>> "IMHO that mesa change is not valid. It is settings its affinity to<br>
> > >>> run on all threads which is definitely *NOT* something we want to be<br>
> > >>> allowed. Management applications want to control which CPUs QEMU runs<br>
> > >>> on, and as such Mesa should honour the CPU placement that the QEMU<br>
> > >>> process has.<br>
> > >>><br>
> > >>> This is a great example of why QEMU wants to use seccomp to block<br>
> > >>> affinity changes to prevent something silently trying to use more CPUs<br>
> > >>> than are assigned to this QEMU."<br>
> > >>><br>
> > >><br>
> > >> Mesa uses thread affinity to optimize memory access performance on some<br>
> > >> CPUs (see util_pin_thread_to_L3). Other places in Mesa need to restore the<br>
> > >> original thread affinity for some child threads. Additionally, if games<br>
> > >> limit the thread affinity, Mesa needs to restore the full thread affinity<br>
> > >> for some of its child threads.<br>
> > ><br>
> > > The last part sounds like Mesa clearly overstepping its authority.<br>
> > ><br>
> > ><br>
> > >> In essence, the thread affinity should only be considered a hint for the<br>
> > >> kernel for optimal performance. There is no reason to kill the process if<br>
> > >> it's disallowed. Just ignore the call or modify the thread mask to make it<br>
> > >> legal.<br>
> > ><br>
> > > The fundamental issue here is that Mesa is using the thread affinity API<br>
> > > for something else than it's intended for. If there was an API for what<br>
> > > Mesa wants (encouraging certain sets of threads to run on topologically<br>
> > > close cores), there should be no need to block that.<br>
> ><br>
> > Why such process needs to be killed instead the request being masked<br>
> > suitably, is there some program that breaks subtly if affinity request<br>
> > is masked (and that being worse than the program being killed)?<br>
><br>
> But that is still a situation that could be nicely handled with a<br>
> EPERM error return. Way better than just kill a process.<br>
> That 'badly affected' program still can call abort then.<br>
> But nicely working programs don't get just killed then!!<br>
<br>
<br>
Returning an error seems less secure that prohibiting it completely.<br>
And it may lead to subtle bugs in rarely tested code paths.<br>
<br>
It's legitimate that QEMU and management layers want to prevent<br>
arbitrary code from changing resource allocation etc.<br>
<br>
There are no easy way I can think of for mesa (and other libraries) to<br>
probe the seccomp filters and associated action.<br>
<br>
So we need a way to tell mesa not to call setaffinity() (and other<br>
syscalls). MESA_NO_THREAD_AFFINITY or MESA_NO_SYSCALLS=setaffinity,...<br>
seem like a relatively easy way to go.<br>
<br>
thanks<br>
<br>
<br>
-- <br>
Marc-André Lureau<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div>