Storing xstate in a middle of C code like that is not really reliable. Performing full store only for selected syscalls should be achievable with some assembly wrappers or a conditional mechanism in syscall dispatcher, but it would probably not be pretty. Do we need it in context of avx512?
If we're fine messing xstate, maybe it would be fine to simply ignore avx512 when storing the context in the syscall dispatcher. When asked about the context, we could interpret it as an initial state. To support setting the context, we only need to reserve the space in the syscall frame to be able to store it when needed.