On Wed, May 20, 2020 at 12:47 AM Keno Fischer <keno@xxxxxxxxxxxxxxxxxx> wrote: > > > > +Thus, to obtain an xsave area that may be set back to the tracee, all unused > > > > +state components must first be re-set to the correct initial state for the > > > > +corresponding state component, and the XSTATE_BV bitfield must subsequently > > > > +be adjusted to match the kernel xstate component bitmask (obtained as > > > > +described above). > > > > The above paragraph needs a better wording. Are you saying the following? - > > > > "If a state component is not saved (its XSTATE_BV bit is zero) but you > > want to modify corresponding registers in the tracee, you need to set > > this bit to 1 and initialize the component to the desired state." > > Kind of, what I want to get across is a warning that the following pattern: > > struct iov = { ... }; > ptrace(PTRACE_GETREGSET, pid1, NT_X86_XSTATE, &iov); > ptrace(PTRACE_SETREGSET, pid2, NT_X86_XSTATE, &iov); > > will not necessarily result in pid1 and pid2 having identical register states. > If a state component was in its initial state in pid1, the XSTATE_BV > bit will be cleared, resulting in the registers in pid2 not being modified. Wanting to set the registers to initial state is a subset of the case where you want to set them to some state (initial or not), so my proposed explanation covers it too. But your example with two separate pids makes it clearer when you would need to be aware of it even if the state you are setting is the initial one: you need explicitly set it, can't assume just "copying" will do. I propose: If a state component is not saved (its XSTATE_BV bit is zero) but you want to modify corresponding registers in the tracee, you need to set this bit to 1 and initialize the component to the desired state. In particular, it means that on PTRACE_SETREGSET, not saved component does not cause corresponding registers to be re-initialized: a naive "copy registers from pid1 to pid2": ptrace(PTRACE_GETREGSET, pid1, NT_X86_XSTATE, &iov); ptrace(PTRACE_SETREGSET, pid2, NT_X86_XSTATE, &iov); will not copy register sets which are in initial state in pid1, they will remain unmodified in pid2.