Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-28 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Tim Chen wrote: > On 11/27/2018 02:36 PM, Thomas Gleixner wrote: > >> We need this special handling only if the next task has TIF_SPEC_UPDATE > >> set, which is one-off event globally (when seccomp marks all its threads > >> so due to seccomp filter change), and once all the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-28 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Tim Chen wrote: > On 11/27/2018 02:36 PM, Thomas Gleixner wrote: > >> We need this special handling only if the next task has TIF_SPEC_UPDATE > >> set, which is one-off event globally (when seccomp marks all its threads > >> so due to seccomp filter change), and once all the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > Does it really have to? > > > > We need this special handling only if the next task has TIF_SPEC_UPDATE > > set, which is one-off event globally (when seccomp marks all its threads > > so due to seccomp filter change), and once all the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > Does it really have to? > > > > We need this special handling only if the next task has TIF_SPEC_UPDATE > > set, which is one-off event globally (when seccomp marks all its threads > > so due to seccomp filter change), and once all the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Tim Chen
On 11/27/2018 02:36 PM, Thomas Gleixner wrote: >> >> We need this special handling only if the next task has TIF_SPEC_UPDATE >> set, which is one-off event globally (when seccomp marks all its threads >> so due to seccomp filter change), and once all the TIF_SPEC_UPDATE tasks >> schedule at

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Tim Chen
On 11/27/2018 02:36 PM, Thomas Gleixner wrote: >> >> We need this special handling only if the next task has TIF_SPEC_UPDATE >> set, which is one-off event globally (when seccomp marks all its threads >> so due to seccomp filter change), and once all the TIF_SPEC_UPDATE tasks >> schedule at

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > > index 3f5e351bdd37..6c4fcef52b19 100644 > > > ---

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > > index 3f5e351bdd37..6c4fcef52b19 100644 > > > ---

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > > index 3f5e351bdd37..6c4fcef52b19 100644 > > > --- a/arch/x86/kernel/process.c > > > +++

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > > index 3f5e351bdd37..6c4fcef52b19 100644 > > > --- a/arch/x86/kernel/process.c > > > +++

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > index 3f5e351bdd37..6c4fcef52b19 100644 > > --- a/arch/x86/kernel/process.c > > +++

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > > static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > > index 3f5e351bdd37..6c4fcef52b19 100644 > > --- a/arch/x86/kernel/process.c > > +++

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > struct thread_info { > unsigned long flags; /* low level flags */ > + unsigned long spec_flags; /* spec flags to sync on ctxsw > */ The information is already available in task->atomic_flags, no need for new

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > struct thread_info { > unsigned long flags; /* low level flags */ > + unsigned long spec_flags; /* spec flags to sync on ctxsw > */ The information is already available in task->atomic_flags, no need for new

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -474,6 +474,21 @@ void __switch_to_xtra(struct task_struct *prev_p, struct > task_struct *next_p) > > tifn = READ_ONCE(task_thread_info(next_p)->flags); > tifp =

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -474,6 +474,21 @@ void __switch_to_xtra(struct task_struct *prev_p, struct > task_struct *next_p) > > tifn = READ_ONCE(task_thread_info(next_p)->flags); > tifp =

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > > That's racy and does not prevent the situation because the TIF flags are > > updated befor the UPDATE bit is set. > > > So __speculation_ctrl_update() might see the new bits, but not > > TIF_SPEC_UPDATE. > > Hm, right, scratch that. We'd need to do

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-27 Thread Jiri Kosina
On Tue, 27 Nov 2018, Jiri Kosina wrote: > > That's racy and does not prevent the situation because the TIF flags are > > updated befor the UPDATE bit is set. > > > So __speculation_ctrl_update() might see the new bits, but not > > TIF_SPEC_UPDATE. > > Hm, right, scratch that. We'd need to do

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > That's racy and does not prevent the situation because the TIF flags are > updated befor the UPDATE bit is set. > So __speculation_ctrl_update() might see the new bits, but not > TIF_SPEC_UPDATE. Hm, right, scratch that. We'd need to do that

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Jiri Kosina
On Tue, 27 Nov 2018, Thomas Gleixner wrote: > That's racy and does not prevent the situation because the TIF flags are > updated befor the UPDATE bit is set. > So __speculation_ctrl_update() might see the new bits, but not > TIF_SPEC_UPDATE. Hm, right, scratch that. We'd need to do that

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > On Mon, 26 Nov 2018, Thomas Gleixner wrote: > > How about the minimalistic aproach below? (only compile tested so far, > applies on top of your latest WIP.x86/pti branch). The downside of course > is wasting another TIF bit. We need to waste another

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Thomas Gleixner
On Tue, 27 Nov 2018, Jiri Kosina wrote: > On Mon, 26 Nov 2018, Thomas Gleixner wrote: > > How about the minimalistic aproach below? (only compile tested so far, > applies on top of your latest WIP.x86/pti branch). The downside of course > is wasting another TIF bit. We need to waste another

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Jiri Kosina
On Mon, 26 Nov 2018, Thomas Gleixner wrote: > > Looks like seccomp thread can be running on a remote CPU when its > > TIF_SPEC_IB flag gets updated. > > > > I wonder if this will cause STIBP to be always off in this scenario, when > > two tasks with SPEC_IB flags running on a remote CPU have

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Jiri Kosina
On Mon, 26 Nov 2018, Thomas Gleixner wrote: > > Looks like seccomp thread can be running on a remote CPU when its > > TIF_SPEC_IB flag gets updated. > > > > I wonder if this will cause STIBP to be always off in this scenario, when > > two tasks with SPEC_IB flags running on a remote CPU have

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Thomas Gleixner
On Mon, 26 Nov 2018, Tim Chen wrote: > On 11/22/2018 11:37 PM, Ingo Molnar wrote: > >> We also had that discussion with SSBD and decided that we won't chase > >> threads and send IPIs around. Yes, it's not perfect, but not the end of the > >> world either. For PRCTL it's a non issue. > > Looks

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Thomas Gleixner
On Mon, 26 Nov 2018, Tim Chen wrote: > On 11/22/2018 11:37 PM, Ingo Molnar wrote: > >> We also had that discussion with SSBD and decided that we won't chase > >> threads and send IPIs around. Yes, it's not perfect, but not the end of the > >> world either. For PRCTL it's a non issue. > > Looks

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Tim Chen
On 11/22/2018 11:37 PM, Ingo Molnar wrote: >>> I think all the call paths from prctl and seccomp coming here >>> has tsk == current. >> >> We had that discussion before with SSBD: >> >> seccomp_set_mode_filter() >>seccomp_attach_filter() >> seccomp_sync_threads() >>

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-26 Thread Tim Chen
On 11/22/2018 11:37 PM, Ingo Molnar wrote: >>> I think all the call paths from prctl and seccomp coming here >>> has tsk == current. >> >> We had that discussion before with SSBD: >> >> seccomp_set_mode_filter() >>seccomp_attach_filter() >> seccomp_sync_threads() >>

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Ingo Molnar
* Thomas Gleixner wrote: > On Thu, 22 Nov 2018, Ingo Molnar wrote: > > * Thomas Gleixner wrote: > > > > Had to read this twice, because the comment and the code are both correct > > but deal with the inverse case. This might have helped: > > > > /* > > * Immediately update the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Ingo Molnar
* Thomas Gleixner wrote: > On Thu, 22 Nov 2018, Ingo Molnar wrote: > > * Thomas Gleixner wrote: > > > > Had to read this twice, because the comment and the code are both correct > > but deal with the inverse case. This might have helped: > > > > /* > > * Immediately update the

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Ingo Molnar
* Thomas Gleixner wrote: > On Wed, 21 Nov 2018, Tim Chen wrote: > > > On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > > > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, > > > bool on) > > > { > > > bool update; > > > > > > + if (on) > > >

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Ingo Molnar
* Thomas Gleixner wrote: > On Wed, 21 Nov 2018, Tim Chen wrote: > > > On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > > > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, > > > bool on) > > > { > > > bool update; > > > > > > + if (on) > > >

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Thomas Gleixner
On Thu, 22 Nov 2018, Ingo Molnar wrote: > * Thomas Gleixner wrote: > > Had to read this twice, because the comment and the code are both correct > but deal with the inverse case. This might have helped: > > /* >* Immediately update the speculation MSRs on the current task, >

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Thomas Gleixner
On Thu, 22 Nov 2018, Ingo Molnar wrote: > * Thomas Gleixner wrote: > > Had to read this twice, because the comment and the code are both correct > but deal with the inverse case. This might have helped: > > /* >* Immediately update the speculation MSRs on the current task, >

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Thomas Gleixner
On Wed, 21 Nov 2018, Tim Chen wrote: > On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, bool > > on) > > { > > bool update; > > > > + if (on) > > + update =

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-22 Thread Thomas Gleixner
On Wed, 21 Nov 2018, Tim Chen wrote: > On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, bool > > on) > > { > > bool update; > > > > + if (on) > > + update =

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Ingo Molnar
* Thomas Gleixner wrote: > The update of the TIF_SSBD flag and the conditional speculation control MSR > update is done in the ssb_prctl_set() function directly. The upcoming prctl > support for controlling indirect branch speculation via STIBP needs the > same mechanism. > > Split the code

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Ingo Molnar
* Thomas Gleixner wrote: > The update of the TIF_SSBD flag and the conditional speculation control MSR > update is done in the ssb_prctl_set() function directly. The upcoming prctl > support for controlling indirect branch speculation via STIBP needs the > same mechanism. > > Split the code

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Tim Chen
On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, bool > on) > { > bool update; > > + if (on) > + update = !test_and_set_tsk_thread_flag(tsk, tifbit); > + else > + update

Re: [patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Tim Chen
On Wed, Nov 21, 2018 at 09:14:50PM +0100, Thomas Gleixner wrote: > +static void task_update_spec_tif(struct task_struct *tsk, int tifbit, bool > on) > { > bool update; > > + if (on) > + update = !test_and_set_tsk_thread_flag(tsk, tifbit); > + else > + update

[patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Thomas Gleixner
The update of the TIF_SSBD flag and the conditional speculation control MSR update is done in the ssb_prctl_set() function directly. The upcoming prctl support for controlling indirect branch speculation via STIBP needs the same mechanism. Split the code out and make it reusable. Signed-off-by:

[patch 20/24] x86/speculation: Split out TIF update

2018-11-21 Thread Thomas Gleixner
The update of the TIF_SSBD flag and the conditional speculation control MSR update is done in the ssb_prctl_set() function directly. The upcoming prctl support for controlling indirect branch speculation via STIBP needs the same mechanism. Split the code out and make it reusable. Signed-off-by: