# Re: \[PATCH v29 23/32\] x86/cet/shstk: Add user-mode shadow stack support

- From: Yu, Yu-cheng \<hidden\>
- Date: 2021-08-27 18:37:50 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2021/08/1490813
- Thread: https://ratatoskr.run/linux-doc/2021/08/1484313/t.md

```text
On 8/27/2021 11:21 AM, Borislav Petkov wrote:
> On Fri, Aug 27, 2021 at 11:10:31AM -0700, Yu, Yu-cheng wrote:
>> Because on context switches the whole xstates are switched together,
>> we need to make sure all are in registers.
>
> There's context switch code which does that already.
>
> Why would shstk_setup() be responsible for switching the whole extended
> states buffer instead of only the shadow stack stuff only?
>

Right now, the kernel does lazy restore, and it waits until right before a task goes back to ring-3 to restore xstates.  If a task needs to write to any xstate registers before that (e.g. for signals), it restores the whole xstates first and clears TIF_NEED_FPU_LOAD, which will prevent xstates being restored again later.
```
