Re: [PATCH v9 12/26] x86/fpu/xstate: Use feature disable (XFD) to protect dynamic user state
From: Dave Hansen
Date: Tue Aug 31 2021 - 18:12:09 EST
On 8/31/21 3:07 PM, Len Brown wrote:
> On Mon, Aug 30, 2021 at 1:52 PM Borislav Petkov <bp@xxxxxxxxx> wrote:
>
>> Well, if you preallocate everything...
> Nothing prevents, say, a pthread_create() or anything
> else where the kernel consumes memory on behalf of a process
> from failing at run-time... AMX does not add a unique OOM risk here.
>
>>> The advantage of the #NM over the syscall is that the programmer
>>> doesn't actually have to do anything. Also, transparently allocated
>>> buffers offer a theoretical benefit that a program may have many
>>> threads, but only a few may actually touch AMX, and so there is
>>> savings to be had by allocating buffers only for the threads that
>>> actually use the buffers.
>> The program already asked the kernel whether it can use AMX - it can
>> allocate the buffers for the threads too.
> The result is that if one thread in a 1,000 task process requests
> and touches AMX, the kernel would allocate 8MB, instead of 8KB
> of context switch buffers for that process, no?
Yes, but that's a pretty natural consequence of the process-level ABI
which was chosen. A per-thread permission scheme would not have had
this particular trade-off.
If you have a big process (lots of threads) and you use a process-level
ABI, there are going to big implications. I don't think we can get away
from this.