Skip to contentSkip to conversation

Core scheduling v3

RFC PATCH Superseded Vineeth Remanan Pillai 15 participants 161 messages May 29, 2019 – Nov 15, 2019 Scheduler Page 2 of 2

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#145 lore raw
In reply to Tim Chen
Quoted 19 lines · Tim Chen
kernel/sched/fair.c +19 -0
+static inline s64 core_sched_imbalance_delta(int src_cpu, int dst_cpu,
+                       int src_sibling, int dst_sibling,
+                       struct task_group *tg, u64 task_load)
+{
+       struct sched_entity *se, *se_sibling, *dst_se, *dst_se_sibling;
+       s64 excess, deficit, old_mismatch, new_mismatch;
+
+       if (src_cpu == dst_cpu)
+               return -1;
+
+       /* XXX SMT4 will require additional logic */
+
+       se = tg->se[src_cpu];
+       se_sibling = tg->se[src_sibling];
+
+       excess = se->avg.load_avg - se_sibling->avg.load_avg;
+       if (src_sibling == dst_cpu) {
+               old_mismatch = abs(excess);
+               new_mismatch = abs(excess - 2*task_load);

kernel/sched/fair.c static bool update_nohz_stats(struct rq *rq, bool force) · line 8366

Quoted 10 lines
kernel/sched/fair.c +10 -0
+               return old_mismatch - new_mismatch;
+       }
+
+       dst_se = tg->se[dst_cpu];
+       dst_se_sibling = tg->se[dst_sibling];
+       deficit = dst_se->avg.load_avg - dst_se_sibling->avg.load_avg;
+
+       old_mismatch = abs(excess) + abs(deficit);
+       new_mismatch = abs(excess - (s64) task_load) +
+                      abs(deficit + (s64) task_load);

If I understood correctly, these formulas made an assumption that the task being moved to the destination is matched the destination's core cookie. so if the task is not matched with dst's core cookie and still have to stay in the runqueue
then the formula becomes not correct.

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 8348

Quoted 8 lines

/**
* update_sg_lb_stats - Update sched_group's statistics for load balancing.
* @env: The load balancing environment.

kernel/sched/fair.c +0 -1
@@ -8345,7 +8492,8 @@ static inline void update_sg_lb_stats(struct lb_env *env,
                else
                        load = source_load(i, load_idx);
 
-               sgs->group_load += load;

Why is this load update line removed?

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 8499

Quoted 5 lines
kernel/sched/fair.c +2 -0
+               core_sched_imbalance_scan(sgs, i, env->dst_cpu);
+
                sgs->group_util += cpu_util(i);
                sgs->sum_nr_running += rq->cfs.h_nr_running;
 

Thanks,
-Aubrey

#146 lore raw
Quoted 25 lines · Aubrey Li
Quoted 24 lines · Tim Chen
kernel/sched/fair.c +24 -0
+static inline s64 core_sched_imbalance_delta(int src_cpu, int dst_cpu,
+                       int src_sibling, int dst_sibling,
+                       struct task_group *tg, u64 task_load)
+{
+       struct sched_entity *se, *se_sibling, *dst_se, *dst_se_sibling;
+       s64 excess, deficit, old_mismatch, new_mismatch;
+
+       if (src_cpu == dst_cpu)
+               return -1;
+
+       /* XXX SMT4 will require additional logic */
+
+       se = tg->se[src_cpu];
+       se_sibling = tg->se[src_sibling];
+
+       excess = se->avg.load_avg - se_sibling->avg.load_avg;
+       if (src_sibling == dst_cpu) {
+               old_mismatch = abs(excess);
+               new_mismatch = abs(excess - 2*task_load);
+               return old_mismatch - new_mismatch;
+       }
+
+       dst_se = tg->se[dst_cpu];
+       dst_se_sibling = tg->se[dst_sibling];
Quoted 8 lines

kernel/sched/fair.c static bool update_nohz_stats(struct rq *rq, bool force) · line 8366

Quoted 5 lines
kernel/sched/fair.c +5 -0
+       deficit = dst_se->avg.load_avg - dst_se_sibling->avg.load_avg;
+
+       old_mismatch = abs(excess) + abs(deficit);
+       new_mismatch = abs(excess - (s64) task_load) +
+                      abs(deficit + (s64) task_load);

If I understood correctly, these formulas made an assumption that the task being moved to the destination is matched the destination's core cookie.

That's not the case. We do not need to match the destination's core cookie, as that may change after context switches. It needs to reduce the load mismatch with the destination CPU's sibling for that cgroup.

Quoted 12 lines

so if
the task is not matched with dst's core cookie and still have to stay in the runqueue
then the formula becomes not correct.

Quoted 7 lines

/**
* update_sg_lb_stats - Update sched_group's statistics for load balancing.
* @env: The load balancing environment.

kernel/sched/fair.c +0 -0
@@ -8345,7 +8492,8 @@ static inline void update_sg_lb_stats(struct lb_env *env,
                else
                        load = source_load(i, load_idx);
 
Quoted 3 lines

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 8348

Quoted 1 line
kernel/sched/fair.c +0 -1
-               sgs->group_load += load;

Why is this load update line removed?

This was removed accidentally. Should be restored.

Quoted 7 lines

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 8499

Quoted 6 lines
kernel/sched/fair.c +2 -0
+               core_sched_imbalance_scan(sgs, i, env->dst_cpu);
+
                sgs->group_util += cpu_util(i);
                sgs->sum_nr_running += rq->cfs.h_nr_running;
 

Thanks.

Tim

#147 lore raw
Quoted 36 lines · Tim Chen
Quoted 25 lines · Aubrey Li
Quoted 24 lines · Tim Chen
kernel/sched/fair.c +24 -0
+static inline s64 core_sched_imbalance_delta(int src_cpu, int dst_cpu,
+                       int src_sibling, int dst_sibling,
+                       struct task_group *tg, u64 task_load)
+{
+       struct sched_entity *se, *se_sibling, *dst_se, *dst_se_sibling;
+       s64 excess, deficit, old_mismatch, new_mismatch;
+
+       if (src_cpu == dst_cpu)
+               return -1;
+
+       /* XXX SMT4 will require additional logic */
+
+       se = tg->se[src_cpu];
+       se_sibling = tg->se[src_sibling];
+
+       excess = se->avg.load_avg - se_sibling->avg.load_avg;
+       if (src_sibling == dst_cpu) {
+               old_mismatch = abs(excess);
+               new_mismatch = abs(excess - 2*task_load);
+               return old_mismatch - new_mismatch;
+       }
+
+       dst_se = tg->se[dst_cpu];
+       dst_se_sibling = tg->se[dst_sibling];
Quoted 8 lines

kernel/sched/fair.c static bool update_nohz_stats(struct rq *rq, bool force) · line 8366

Quoted 5 lines
kernel/sched/fair.c +5 -0
+       deficit = dst_se->avg.load_avg - dst_se_sibling->avg.load_avg;
+
+       old_mismatch = abs(excess) + abs(deficit);
+       new_mismatch = abs(excess - (s64) task_load) +
+                      abs(deficit + (s64) task_load);

If I understood correctly, these formulas made an assumption that the task being moved to the destination is matched the destination's core cookie.

Quoted 1 line

That's not the case. We do not need to match the destination's core cookie,

I actually meant destination core's core cookie.

Quoted 2 lines

as that may change after context switches. It needs to reduce the load mismatch with the destination CPU's sibling for that cgroup.

So the new_mismatch is not always true, especially when there are more cgroups and
more core cookies on the system.

Thanks,
-Aubrey

#148 lore raw
In reply to Tim Chen
Quoted 10 lines

I've made an attempt in the following two patches to address the load balancing of mismatched load between the siblings.

It is applied on top of Aaron's patches:
- sched: Fix incorrect rq tagged as forced idle
- wrapper for cfs_rq->min_vruntime
https://lore.kernel.org/lkml/20190725143127.GB992@aaronlu/
- core vruntime comparison
https://lore.kernel.org/lkml/20190725143248.GC992@aaronlu/

Quoted 2 lines

I will love Julien, Aaron and others to try it out. Suggestions to tune it is welcomed.

Just letting you know that I will be testing your load balancing patches this week along with the changes Vineeth is currently doing. I didn't test it before because I was focused on single threaded and pinned micro-benchmarks, but I am back on scaling tests so it will be interesting to see.

Thanks,

Julien

#149 lore raw
In reply to Vineeth Remanan Pillai

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable? Having spoken to the Chrome team, I believe that the semantics we want are:

1) A thread to be able to indicate that it should not run on the same core as anything not in posession of the same cookie
2) Descendents of that thread to (by default) have the same cookie
3) No other thread be able to obtain the same cookie
4) Threads not be able to rejoin the global group (ie, threads can segregate themselves from their parent and peers, but can never rejoin that group once segregated)

but don't know if that's what everyone else would want.

include/uapi/linux/prctl.h +1 -0
index 094bb03b9cc2..5d411246d4d5 100644
@@ -229,4 +229,5 @@ struct prctl_mm_map {
 # define PR_PAC_APDBKEY			(1UL << 3)
 # define PR_PAC_APGAKEY			(1UL << 4)
 
+#define PR_CORE_ISOLATE			55
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +7 -0
index 12df0e5434b8..a054cfcca511 100644
@@ -2486,6 +2486,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EINVAL;
 		error = PAC_RESET_KEYS(me, arg2);
 		break;
+	case PR_CORE_ISOLATE:
+#ifdef CONFIG_SCHED_CORE
+		current->core_cookie = (unsigned long)current;
+#else
+		result = -EINVAL;
+#endif
+		break;
 	default:
 		error = -EINVAL;
 		break;
Signature · 1 line
Matthew Garrett | [email protected]
maintainer
#150 lore raw
Quoted 6 lines · Matthew Garrett

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable?

Sure; like I wrote earlier; I only did the cgroup thing because I was lazy and it was the easiest interface to hack on in a hurry.

The rest of the ABI nonsense can 'trivially' be done later; if when we decide to actually do this.

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

Quoted 28 lines

Having spoken to the Chrome team, I believe that the semantics we want are:

1) A thread to be able to indicate that it should not run on the same core as anything not in posession of the same cookie
2) Descendents of that thread to (by default) have the same cookie
3) No other thread be able to obtain the same cookie
4) Threads not be able to rejoin the global group (ie, threads can segregate themselves from their parent and peers, but can never rejoin that group once segregated)

but don't know if that's what everyone else would want.

include/uapi/linux/prctl.h +1 -0
index 094bb03b9cc2..5d411246d4d5 100644
@@ -229,4 +229,5 @@ struct prctl_mm_map {
 # define PR_PAC_APDBKEY			(1UL << 3)
 # define PR_PAC_APGAKEY			(1UL << 4)
 
+#define PR_CORE_ISOLATE			55
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +0 -0
index 12df0e5434b8..a054cfcca511 100644

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2491

Quoted 6 lines
kernel/sys.c +3 -0
@@ -2486,6 +2486,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EINVAL;
 		error = PAC_RESET_KEYS(me, arg2);
 		break;
+	case PR_CORE_ISOLATE:
+#ifdef CONFIG_SCHED_CORE
+		current->core_cookie = (unsigned long)current;

This needs to then also force a reschedule of current. And there's the little issue of what happens if 'current' dies while its children live on, and current gets re-used for a new process and does this again.

Quoted 11 lines
kernel/sys.c +4 -0
+#else
+		result = -EINVAL;
+#endif
+		break;
 	default:
 		error = -EINVAL;
 		break;
Signature · 2 lines
-- 
Matthew Garrett | [email protected]
#151 lore raw
Quoted 8 lines · On Tue, Aug 27, 2019 at 11:50:35PM +0200 Peter Zijlstra wrote:
Quoted 6 lines · Matthew Garrett

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable?

Quoted 5 lines

Sure; like I wrote earlier; I only did the cgroup thing because I was lazy and it was the easiest interface to hack on in a hurry.

The rest of the ABI nonsense can 'trivially' be done later; if when we decide to actually do this.

I think something that allows the tag to be set may be needed. One of the use cases for this is virtualization stacks, where you really want to be able to keep the higher CPU count and to set up the isolation from management processes on the host.

The current cgroup interface doesn't work for that because it doesn't apply the tag to children. We've been unable to fully test it in a virt setup because our VMs are made of a child cgroup per vcpu.

Quoted 3 lines

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

I was thinking MDS is really the reason for this. L1TF has mitigations but the only current mitigation for MDS for smt is ... nosmt.

The current core scheduler implementation, I believe, still has (theoretical?) holes involving interrupts, once/if those are closed it may be even less attractive.

Quoted 31 lines
Quoted 31 lines

Having spoken to the Chrome team, I believe that the semantics we want are:

1) A thread to be able to indicate that it should not run on the same core as anything not in posession of the same cookie
2) Descendents of that thread to (by default) have the same cookie
3) No other thread be able to obtain the same cookie
4) Threads not be able to rejoin the global group (ie, threads can segregate themselves from their parent and peers, but can never rejoin that group once segregated)

but don't know if that's what everyone else would want.

include/uapi/linux/prctl.h +1 -0
index 094bb03b9cc2..5d411246d4d5 100644
@@ -229,4 +229,5 @@ struct prctl_mm_map {
 # define PR_PAC_APDBKEY			(1UL << 3)
 # define PR_PAC_APGAKEY			(1UL << 4)
 
+#define PR_CORE_ISOLATE			55
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +0 -0
index 12df0e5434b8..a054cfcca511 100644
@@ -2486,6 +2486,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			return -EINVAL;
 		error = PAC_RESET_KEYS(me, arg2);
Quoted 8 lines

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2491

Quoted 4 lines
kernel/sys.c +3 -0
 		break;
+	case PR_CORE_ISOLATE:
+#ifdef CONFIG_SCHED_CORE
+		current->core_cookie = (unsigned long)current;

This needs to then also force a reschedule of current. And there's the little issue of what happens if 'current' dies while its children live on, and current gets re-used for a new process and does this again.

sched_core_get() too?

Cheers,
Phil

Quoted 12 lines
Quoted 12 lines
kernel/sys.c +4 -0
+#else
+		result = -EINVAL;
+#endif
+		break;
 	default:
 		error = -EINVAL;
 		break;
Signature · 2 lines
-- 
Matthew Garrett | [email protected]
maintainer
#152 lore raw
Quoted 7 lines · Phil Auld
Quoted 2 lines · On Tue, Aug 27, 2019 at 11:50:35PM +0200 Peter Zijlstra wrote:

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

I was thinking MDS is really the reason for this. L1TF has mitigations but the only current mitigation for MDS for smt is ... nosmt.

L1TF has no known mitigation that is SMT safe. The moment you have something in your L1, the other sibling can read it using L1TF.

The nice thing about L1TF is that only (malicious) guests can exploit it, and therefore the synchronizatin context is VMM. And it so happens that VMEXITs are 'rare' (and already expensive and thus lots of effort has already gone into avoiding them).

If you don't use VMs, you're good and SMT is not a problem.

If you do use VMs (and do/can not trust them), _then_ you need core-scheduling; and in that case, the implementation under discussion misses things like synchronization on VMEXITs due to interrupts and things like that.

But under the assumption that VMs don't generate high scheduling rates, it can work.

Quoted 3 lines

The current core scheduler implementation, I believe, still has (theoretical?) holes involving interrupts, once/if those are closed it may be even less attractive.

No; so MDS leaks anything the other sibling (currently) does, this makes _any_ privilidge boundary a synchronization context.

Worse still, the exploit doesn't require a VM at all, any other task can get to it.

That means you get to sync the siblings on lovely things like system call entry and exit, along with VMM and anything else that one would consider a privilidge boundary. Now, system calls are not rare, they are really quite common in fact. Trying to sync up siblings at the rate of system calls is utter madness.

So under MDS, SMT is completely hosed. If you use VMs exclusively, then it _might_ work because a 'pure' host doesn't schedule that often (maybe, same assumption as for L1TF).

Now, there have been proposals of moving the privilidge boundary further into the kernel. Just like PTI exposes the entry stack and code to Meltdown, the thinking is, lets expose more. By moving the priv boundary the hope is that we can do lots of common system calls without having to sync up -- lots of details are 'pending'.

#153 lore raw
Quoted 23 lines · Peter Zijlstra
Quoted 5 lines · Phil Auld

On Tue, Aug 27, 2019 at 11:50:35PM +0200 Peter Zijlstra wrote:

The current core scheduler implementation, I believe, still has (theoretical?) holes involving interrupts, once/if those are closed it may be even less attractive.

No; so MDS leaks anything the other sibling (currently) does, this makes _any_ privilidge boundary a synchronization context.

Worse still, the exploit doesn't require a VM at all, any other task can get to it.

That means you get to sync the siblings on lovely things like system call entry and exit, along with VMM and anything else that one would consider a privilidge boundary. Now, system calls are not rare, they are really quite common in fact. Trying to sync up siblings at the rate of system calls is utter madness.

So under MDS, SMT is completely hosed. If you use VMs exclusively, then it _might_ work because a 'pure' host doesn't schedule that often (maybe, same assumption as for L1TF).

Quoted 6 lines

Now, there have been proposals of moving the privilidge boundary further into the kernel. Just like PTI exposes the entry stack and code to Meltdown, the thinking is, lets expose more. By moving the priv boundary the hope is that we can do lots of common system calls without having to sync up -- lots of details are 'pending'.

If are willing to consider the idea that we will sync with the sibling only if we touch potential user data, then a significant portion of syscalls may not need to sync. Yeah, it still sucks because of the complexity added to audit all the places in kernel that may touch privileged data and require synchronization.

I did a prototype (without core sched), kernel build slow 2.5%. So this use case still seem reasonable.

A worst case scenario is concurrent SMT FIO write to encrypted file, which have a lot of synchronizations due to extended access to privilege data by crypto, we slow by 9%.

Tim

#154 lore raw
In reply to Peter Zijlstra
Quoted 47 lines · On Wed, Aug 28, 2019 at 06:01:14PM +0200 Peter Zijlstra wrote:
Quoted 7 lines · Phil Auld
Quoted 2 lines · On Tue, Aug 27, 2019 at 11:50:35PM +0200 Peter Zijlstra wrote:

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

I was thinking MDS is really the reason for this. L1TF has mitigations but the only current mitigation for MDS for smt is ... nosmt.

L1TF has no known mitigation that is SMT safe. The moment you have something in your L1, the other sibling can read it using L1TF.

The nice thing about L1TF is that only (malicious) guests can exploit it, and therefore the synchronizatin context is VMM. And it so happens that VMEXITs are 'rare' (and already expensive and thus lots of effort has already gone into avoiding them).

If you don't use VMs, you're good and SMT is not a problem.

If you do use VMs (and do/can not trust them), _then_ you need core-scheduling; and in that case, the implementation under discussion misses things like synchronization on VMEXITs due to interrupts and things like that.

But under the assumption that VMs don't generate high scheduling rates, it can work.

Quoted 3 lines

The current core scheduler implementation, I believe, still has (theoretical?) holes involving interrupts, once/if those are closed it may be even less attractive.

No; so MDS leaks anything the other sibling (currently) does, this makes _any_ privilidge boundary a synchronization context.

Worse still, the exploit doesn't require a VM at all, any other task can get to it.

That means you get to sync the siblings on lovely things like system call entry and exit, along with VMM and anything else that one would consider a privilidge boundary. Now, system calls are not rare, they are really quite common in fact. Trying to sync up siblings at the rate of system calls is utter madness.

So under MDS, SMT is completely hosed. If you use VMs exclusively, then it _might_ work because a 'pure' host doesn't schedule that often (maybe, same assumption as for L1TF).

Quoted 5 lines

Now, there have been proposals of moving the privilidge boundary further into the kernel. Just like PTI exposes the entry stack and code to Meltdown, the thinking is, lets expose more. By moving the priv boundary the hope is that we can do lots of common system calls without having to sync up -- lots of details are 'pending'.

Thanks for clarifying. My understanding is (somewhat) less fuzzy now. :)

I think, though, that you were basically agreeing with me that the current core scheduler does not close the holes, or am I reading that wrong.

Cheers,
Phil

maintainer
#155 lore raw
Quoted 55 lines · Phil Auld
Quoted 47 lines · On Wed, Aug 28, 2019 at 06:01:14PM +0200 Peter Zijlstra wrote:
Quoted 7 lines · Phil Auld
Quoted 2 lines · On Tue, Aug 27, 2019 at 11:50:35PM +0200 Peter Zijlstra wrote:

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

I was thinking MDS is really the reason for this. L1TF has mitigations but the only current mitigation for MDS for smt is ... nosmt.

L1TF has no known mitigation that is SMT safe. The moment you have something in your L1, the other sibling can read it using L1TF.

The nice thing about L1TF is that only (malicious) guests can exploit it, and therefore the synchronizatin context is VMM. And it so happens that VMEXITs are 'rare' (and already expensive and thus lots of effort has already gone into avoiding them).

If you don't use VMs, you're good and SMT is not a problem.

If you do use VMs (and do/can not trust them), _then_ you need core-scheduling; and in that case, the implementation under discussion misses things like synchronization on VMEXITs due to interrupts and things like that.

But under the assumption that VMs don't generate high scheduling rates, it can work.

Quoted 3 lines

The current core scheduler implementation, I believe, still has (theoretical?) holes involving interrupts, once/if those are closed it may be even less attractive.

No; so MDS leaks anything the other sibling (currently) does, this makes _any_ privilidge boundary a synchronization context.

Worse still, the exploit doesn't require a VM at all, any other task can get to it.

That means you get to sync the siblings on lovely things like system call entry and exit, along with VMM and anything else that one would consider a privilidge boundary. Now, system calls are not rare, they are really quite common in fact. Trying to sync up siblings at the rate of system calls is utter madness.

So under MDS, SMT is completely hosed. If you use VMs exclusively, then it _might_ work because a 'pure' host doesn't schedule that often (maybe, same assumption as for L1TF).

Quoted 5 lines

Now, there have been proposals of moving the privilidge boundary further into the kernel. Just like PTI exposes the entry stack and code to Meltdown, the thinking is, lets expose more. By moving the priv boundary the hope is that we can do lots of common system calls without having to sync up -- lots of details are 'pending'.

Quoted 4 lines

Thanks for clarifying. My understanding is (somewhat) less fuzzy now. :)

I think, though, that you were basically agreeing with me that the current core scheduler does not close the holes, or am I reading that wrong.

Agreed; the missing bits for L1TF are ugly but doable (I've actually done them before, Tim has that _somewhere_), but I've not seen a 'workable' solution for MDS yet.

#156 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Phil Auld

I think, though, that you were basically agreeing with me that the current core scheduler does not close the holes, or am I reading that wrong.

Agreed; the missing bits for L1TF are ugly but doable (I've actually done them before, Tim has that _somewhere_), but I've not seen a 'workable' solution for MDS yet.

Following the discussion we had yesterday at LPC, after we have agreed on a solution for fixing the current fairness issue, we will post the v4. We will then work on prototyping the other synchronisation points (syscalls, interrupts and VMEXIT) to evaluate the overhead in various use-cases.

Depending on the use-case, we know the performance overhead maybe heavier than just disabling SMT, but the benchmarks we have seen so far indicate that there are valid cases for core scheduling. Core scheduling will continue to be unused by default, but with it, we will have the option to tune the system to be both secure and faster than disabling SMT for those cases.

Thanks,

Julien

P.S: I think the branch that contains the VMEXIT handling is here
https://github.com/pdxChen/gang/commits/sched_1.23-base

#157 lore raw
Quoted 9 lines · Julien Desfossez
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Phil Auld

I think, though, that you were basically agreeing with me that the current core scheduler does not close the holes, or am I reading that wrong.

Agreed; the missing bits for L1TF are ugly but doable (I've actually done them before, Tim has that _somewhere_), but I've not seen a 'workable' solution for MDS yet.

The L1TF problem is a much bigger one for HT than MDS. It is relatively easy for a Rogue VM to sniff L1 cached memory locations. While for MDS, it is quite difficult for the attacker to associate data in the cpu buffers with specific memory to make the sniffed data useful.

Even if we don't have a complete solution yet for MDS HT vulnerability, it is worthwhile to plug the L1TF hole for HT first with core scheduler, as L1TF is much more exploitable.

Tim

Quoted 20 lines

Following the discussion we had yesterday at LPC, after we have agreed on a solution for fixing the current fairness issue, we will post the v4. We will then work on prototyping the other synchronisation points (syscalls, interrupts and VMEXIT) to evaluate the overhead in various use-cases.

Depending on the use-case, we know the performance overhead maybe heavier than just disabling SMT, but the benchmarks we have seen so far indicate that there are valid cases for core scheduling. Core scheduling will continue to be unused by default, but with it, we will have the option to tune the system to be both secure and faster than disabling SMT for those cases.

Thanks,

Julien

P.S: I think the branch that contains the VMEXIT handling is here
https://github.com/pdxChen/gang/commits/sched_1.23-base

#158 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Matthew Garrett

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable?

Quoted 9 lines

Sure; like I wrote earlier; I only did the cgroup thing because I was lazy and it was the easiest interface to hack on in a hurry.

The rest of the ABI nonsense can 'trivially' be done later; if when we decide to actually do this.

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

For MDS, core-scheduler does prevent thread to thread attack between user space threads running on sibling CPU threads. Yes, it doesn't prevent the user to kernel attack from sibling which will require additional mitigation measure. However, it does block a major attack vector for MDS if HT is enabled.

Tim

maintainer
#159 lore raw
Quoted 19 lines · Tim Chen
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Matthew Garrett

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable?

Quoted 9 lines

Sure; like I wrote earlier; I only did the cgroup thing because I was lazy and it was the easiest interface to hack on in a hurry.

The rest of the ABI nonsense can 'trivially' be done later; if when we decide to actually do this.

And given MDS, I'm still not entirely convinced it all makes sense. If it were just L1TF, then yes, but now...

Quoted 5 lines

For MDS, core-scheduler does prevent thread to thread attack between user space threads running on sibling CPU threads. Yes, it doesn't prevent the user to kernel attack from sibling which will require additional mitigation measure. However, it does block a major attack vector for MDS if HT is enabled.

I'm not sure what your argument is; the dike has two holes; you plug one, you still drown.

#160 lore raw
In reply to Matthew Garrett
Quoted 34 lines · Matthew Garrett

Apple have provided a sysctl that allows applications to indicate that specific threads should make use of core isolation while allowing the rest of the system to make use of SMT, and browsers (Safari, Firefox and Chrome, at least) are now making use of this. Trying to do something similar using cgroups seems a bit awkward. Would something like this be reasonable? Having spoken to the Chrome team, I believe that the semantics we want are:

1) A thread to be able to indicate that it should not run on the same core as anything not in posession of the same cookie
2) Descendents of that thread to (by default) have the same cookie
3) No other thread be able to obtain the same cookie
4) Threads not be able to rejoin the global group (ie, threads can segregate themselves from their parent and peers, but can never rejoin that group once segregated)

but don't know if that's what everyone else would want.

include/uapi/linux/prctl.h +1 -0
index 094bb03b9cc2..5d411246d4d5 100644
@@ -229,4 +229,5 @@ struct prctl_mm_map {
 # define PR_PAC_APDBKEY                        (1UL << 3)
 # define PR_PAC_APGAKEY                        (1UL << 4)
 
+#define PR_CORE_ISOLATE                        55
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +0 -0
index 12df0e5434b8..a054cfcca511 100644

kernel/sys.c SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, · line 2491

Quoted 6 lines
kernel/sys.c +3 -0
@@ -2486,6 +2486,13 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
                        return -EINVAL;
                error = PAC_RESET_KEYS(me, arg2);
                break;
+       case PR_CORE_ISOLATE:
+#ifdef CONFIG_SCHED_CORE
+               current->core_cookie = (unsigned long)current;

Because AVX512 instructions could pull down the core frequency, we also want to give a magic cookie number to all AVX512-using tasks on the system, so they won't affect the performance/latency of any other tasks.

This could be done by putting all AVX512 tasks into a cgroup, or by AVX512 detection the following patch introduced.

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=2f7726f955572e587d5f50fbe9b2deed5334bd90

Thanks,
-Aubrey