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

2021-09-29 Thread Andy Lutomirski
On Wed, Sep 29, 2021, at 10:07 AM, Luck, Tony wrote: > On Wed, Sep 29, 2021 at 09:58:22AM -0700, Andy Lutomirski wrote: >> On 9/28/21 16:10, Luck, Tony wrote: >> > Moving beyond pseudo-code and into compiles-but-probably-broken-code. >> > >> > >> > The intent of the functions below is that

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

2021-09-29 Thread Luck, Tony
On Wed, Sep 29, 2021 at 09:58:22AM -0700, Andy Lutomirski wrote: > On 9/28/21 16:10, Luck, Tony wrote: > > Moving beyond pseudo-code and into compiles-but-probably-broken-code. > > > > > > The intent of the functions below is that Fenghua should be able to > > do: > > > > void

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

2021-09-29 Thread Andy Lutomirski
On 9/28/21 16:10, Luck, Tony wrote: Moving beyond pseudo-code and into compiles-but-probably-broken-code. The intent of the functions below is that Fenghua should be able to do: void fpu__pasid_write(u32 pasid) { u64 msr_val = pasid | MSR_IA32_PASID_VALID; struct

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

2021-09-29 Thread Peter Zijlstra
On Fri, Sep 24, 2021 at 08:39:24AM -0700, Luck, Tony wrote: > If you have ctags installed then a ctrl-] on that > __fixup_pasid_exception() will take you to the function with > the comments. No electron microscope needed. I to use ctags, but when reading the #GP handler, this is a whole

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

2021-09-28 Thread Luck, Tony
>> 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. > >

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

2021-09-28 Thread Luck, Tony
> But the helpers seem to be generic. They take "task" as a parameter and > handle the task as non-current case. So the helpers are not for PASID only. > They may be used by others to modify a running task's FPU state. But > It's not safe to do so. > > At least need some comments/restriction for

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

2021-09-28 Thread Yu, Fenghua
Hi, Tony, > void *begin_update_one_xsave_feature(struct task_struct *tsk, >enum xfeature xfeature, bool full) { > struct xregs_state *xsave = >thread.fpu.state.xsave; > struct xregs_state *xinit = _fpstate.xsave; > u64 fmask = 1ull <<

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

2021-09-28 Thread Fenghua Yu
Hi, Tony, On Tue, Sep 28, 2021 at 06:06:52PM -0700, Luck, Tony wrote: > >>fpregs_lock(); > > > > I'm afraid we may hit the same locking issue when we send IPI to notify > > another task to modify its > > PASID state. Here the API is called to modify another running task's PASID > > state as

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

2021-09-28 Thread Luck, Tony
>> fpregs_lock(); > > I'm afraid we may hit the same locking issue when we send IPI to notify > another task to modify its > PASID state. Here the API is called to modify another running task's PASID > state as well without a right lock. > fpregs_lock() is not enough to deal with this, I'm

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

2021-09-28 Thread Yu, Fenghua
Hi, Tony, > void *begin_update_one_xsave_feature(struct task_struct *tsk, >enum xfeature xfeature, bool full) { > struct xregs_state *xsave = >thread.fpu.state.xsave; > struct xregs_state *xinit = _fpstate.xsave; > u64 fmask = 1ull <<

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

2021-09-28 Thread Luck, Tony
On Tue, Sep 28, 2021 at 11:50:37PM +, Fenghua Yu wrote: > If xfeatures's feature bit is 0, xsaves will not write its init value to the > memory due to init optimization. So the xsaves will do nothing and the > state is not initialized and may have random data. > Setting TIF_NEED_FPU_LOAD

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

2021-09-28 Thread Fenghua Yu
Hi, Tony, On Tue, Sep 28, 2021 at 04:10:39PM -0700, Luck, Tony wrote: > Moving beyond pseudo-code and into compiles-but-probably-broken-code. > > > The intent of the functions below is that Fenghua should be able to > do: > > void fpu__pasid_write(u32 pasid) > { > u64 msr_val = pasid |

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

2021-09-28 Thread Luck, Tony
Moving beyond pseudo-code and into compiles-but-probably-broken-code. The intent of the functions below is that Fenghua should be able to do: void fpu__pasid_write(u32 pasid) { u64 msr_val = pasid | MSR_IA32_PASID_VALID; struct ia32_pasid_state *addr; addr =

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

2021-09-28 Thread Dave Hansen
On 9/28/21 1:28 PM, Luck, Tony wrote: > On Tue, Sep 28, 2021 at 12:19:22PM -0700, Dave Hansen wrote: >> On 9/28/21 11:50 AM, Luck, Tony wrote: >>> On Mon, Sep 27, 2021 at 04:51:25PM -0700, Dave Hansen wrote: >> ... 1. Hide whether we need to write to real registers 2. Hide whether we

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

2021-09-28 Thread Luck, Tony
On Tue, Sep 28, 2021 at 12:19:22PM -0700, Dave Hansen wrote: > On 9/28/21 11:50 AM, Luck, Tony wrote: > > On Mon, Sep 27, 2021 at 04:51:25PM -0700, Dave Hansen wrote: > ... > >> 1. Hide whether we need to write to real registers > >> 2. Hide whether we need to update the in-memory image > >> 3.

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

2021-09-28 Thread Dave Hansen
On 9/28/21 11:50 AM, Luck, Tony wrote: > On Mon, Sep 27, 2021 at 04:51:25PM -0700, Dave Hansen wrote: ... >> 1. Hide whether we need to write to real registers >> 2. Hide whether we need to update the in-memory image >> 3. Hide other FPU infrastructure like the TIF flag. >> 4. Make the users deal

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

2021-09-28 Thread Luck, Tony
On Mon, Sep 27, 2021 at 04:51:25PM -0700, Dave Hansen wrote: > That's close to what we want. > > The size should probably be implicit. If it isn't implicit, it needs to > at least be double-checked against the state sizes. > > Not to get too fancy, but I think we also want to have a "replace" >

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

2021-09-27 Thread Dave Hansen
On 9/27/21 2:02 PM, Luck, Tony wrote: > Or are you thinking of a helper that does both the check > and the update ... so the code here could be: > > update_one_xsave_feature(XFEATURE_PASID, _val, sizeof(msr_val)); > > With the helper being something like: > > void

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

2021-09-27 Thread Luck, Tony
On Thu, Sep 23, 2021 at 04:17:05PM -0700, Andy Lutomirski wrote: > > + fpregs_lock(); > > + > > + /* > > +* If the task's FPU doesn't need to be loaded or is valid, directly > > +* write the IA32_PASID MSR. Otherwise, write the PASID state and > > +* the MSR will be loaded from the

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

2021-09-24 Thread Luck, Tony
On Fri, Sep 24, 2021 at 03:37:22PM +0200, Peter Zijlstra wrote: > On Thu, Sep 23, 2021 at 10:14:42AM -0700, Luck, Tony wrote: > > On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > > > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > > > @@ -538,6 +547,9 @@

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

2021-09-24 Thread Peter Zijlstra
On Thu, Sep 23, 2021 at 10:14:42AM -0700, Luck, Tony wrote: > On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > > @@ -538,6 +547,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) > > > > > >

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

2021-09-23 Thread Andy Lutomirski
On Thu, Sep 23, 2021, at 7:56 PM, Fenghua Yu wrote: > Hi, Andy, > > On Thu, Sep 23, 2021 at 04:17:05PM -0700, Andy Lutomirski wrote: >> On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: >> > ENQCMD requires the IA32_PASID MSR has a valid PASID value which was >> > allocated to the process

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

2021-09-23 Thread Fenghua Yu
Hi, Andy, On Thu, Sep 23, 2021 at 04:17:05PM -0700, Andy Lutomirski wrote: > On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > > ENQCMD requires the IA32_PASID MSR has a valid PASID value which was > > allocated to the process during bind. The MSR could be populated eagerly > > by an IPI

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

2021-09-23 Thread Andy Lutomirski
On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > ENQCMD requires the IA32_PASID MSR has a valid PASID value which was > allocated to the process during bind. The MSR could be populated eagerly > by an IPI after the PASID is allocated in bind. But the method was > disabled in commit

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

2021-09-23 Thread Luck, Tony
On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > @@ -538,6 +547,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) > > > > cond_local_irq_enable(regs); > > > > + if (user_mode(regs) &&

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

2021-09-23 Thread Thomas Gleixner
On Mon, Sep 20 2021 at 19:23, Fenghua Yu wrote: > diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c > index c8def1b7f8fb..8a89b2cecd77 100644 > --- a/arch/x86/kernel/fpu/xstate.c > +++ b/arch/x86/kernel/fpu/xstate.c > @@ -1289,3 +1289,62 @@ int proc_pid_arch_status(struct

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

2021-09-23 Thread Peter Zijlstra
On Wed, Sep 22, 2021 at 02:33:09PM -0700, Dave Hansen wrote: > On 9/22/21 2:11 PM, Peter Zijlstra wrote: > >>> +static bool fixup_pasid_exception(void) > >>> +{ > >>> + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > >>> + return false; > >>> + > >>> + return __fixup_pasid_exception(); >

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

2021-09-23 Thread Peter Zijlstra
On Wed, Sep 22, 2021 at 09:26:10PM +, Luck, Tony wrote: > >> > +static bool fixup_pasid_exception(void) > >> > +{ > >> > +if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > >> > +return false; > >> > + > >> > +return __fixup_pasid_exception(); > >> > +} > > > >

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

2021-09-22 Thread Fenghua Yu
Hi, Peter, On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > > > + if (user_mode(regs) && fixup_pasid_exception()) > > + goto exit; > > + > > if (static_cpu_has(X86_FEATURE_UMIP)) { > >

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

2021-09-22 Thread Fenghua Yu
Hi, Peter, On Wed, Sep 22, 2021 at 11:11:45PM +0200, Peter Zijlstra wrote: > On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > > +static bool fixup_pasid_exception(void) > > > +{ > > > + if

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

2021-09-22 Thread Dave Hansen
On 9/22/21 2:11 PM, Peter Zijlstra wrote: >>> +static bool fixup_pasid_exception(void) >>> +{ >>> + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) >>> + return false; >>> + >>> + return __fixup_pasid_exception(); >>> +} > That is, shouldn't the above at the very least decode the

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

2021-09-22 Thread Luck, Tony
>> > +static bool fixup_pasid_exception(void) >> > +{ >> > + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) >> > + return false; >> > + >> > + return __fixup_pasid_exception(); >> > +} > > That is, shouldn't the above at the very least decode the instruction > causing the #GP and check

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

2021-09-22 Thread Peter Zijlstra
On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > > diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c > > index a58800973aed..a25d738ae839 100644 > > --- a/arch/x86/kernel/traps.c > > +++

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

2021-09-22 Thread Peter Zijlstra
On Mon, Sep 20, 2021 at 07:23:45PM +, Fenghua Yu wrote: > diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c > index a58800973aed..a25d738ae839 100644 > --- a/arch/x86/kernel/traps.c > +++ b/arch/x86/kernel/traps.c > @@ -61,6 +61,7 @@ > #include > #include > #include >