RE: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP

From: Yu, Fenghua
Date: Tue Sep 28 2021 - 21:56:27 EST


Hi, Tony,

> void *begin_update_one_xsave_feature(struct task_struct *tsk,
> enum xfeature xfeature, bool full) {
> struct xregs_state *xsave = &tsk->thread.fpu.state.xsave;
> struct xregs_state *xinit = &init_fpstate.xsave;
> u64 fmask = 1ull << xfeature;
> void *addr;
>
> BUG_ON(!(xsave->header.xcomp_bv & fmask));
>
> fpregs_lock();
>
> addr = __raw_xsave_addr(xsave, xfeature);
>
> if (full || tsk != current) {
> memcpy(addr, __raw_xsave_addr(xinit, xfeature),
> xstate_sizes[xfeature]);
> goto out;
> }
>
> if (!(xsave->header.xfeatures & fmask)) {
> xsave->header.xfeatures |= fmask; //<<<<<
> xsaves(xsave, fmask);
> }

I'm not sure why the FPU state is initialized here.

For updating the PASID state, it's unnecessary to init the PASID state.

Maybe it is necessary in other cases?

>
> out:
> xsave->header.xfeatures |= fmask;

Setting the xfeatures bit plus updating the PASID state is enough
to restore the PASID state to the IA32_PASID MSR.

> return addr;
> }
>
> void finish_update_one_xsave_feature(struct task_struct *tsk) {
> set_ti_thread_flag(task_thread_info(tsk), TIF_NEED_FPU_LOAD);
> if (tsk == current) //<<<<<
> __cpu_invalidate_fpregs_state(); //<<<<<
> fpregs_unlock();
> }

Thanks.

-Fenghua