When creating perf events, return an error rather
than interfering with CPUs tagged as block interference.
Note: this patch is incomplete, installation of perf context
on block interference CPUs via task context is not performed.
Signed-off-by: Marcelo Tosatti <[email protected]>
Index: linux-2.6/kernel/events/core.c
===================================================================
--- linux-2.6.orig/kernel/events/core.c
+++ linux-2.6/kernel/events/core.c
@@ -54,6 +54,7 @@
#include <linux/highmem.h>
#include <linux/pgtable.h>
#include <linux/buildid.h>
+#include <linux/sched/isolation.h>
#include "internal.h"
@@ -12391,6 +12392,26 @@ not_move_group:
WARN_ON_ONCE(ctx->parent_ctx);
+ block_interf_read_lock();
+ if (!task) {
+ if (move_group) {
+ for_each_sibling_event(sibling, group_leader) {
+ if (block_interf_cpu(sibling->cpu)) {
+ err = -EPERM;
+ goto err_block_interf;
+ }
+ }
+ if (block_interf_cpu(group_leader->cpu)) {
+ err = -EPERM;
+ goto err_block_interf;
+ }
+ }
+ if (block_interf_cpu(event->cpu)) {
+ err = -EPERM;
+ goto err_block_interf;
+ }
+ }
+
/*
* This is the point on no return; we cannot fail hereafter. This is
* where we start modifying current state.
@@ -12464,6 +12485,8 @@ not_move_group:
put_task_struct(task);
}
+ block_interf_read_unlock();
+
mutex_lock(¤t->perf_event_mutex);
list_add_tail(&event->owner_entry, ¤t->perf_event_list);
mutex_unlock(¤t->perf_event_mutex);
@@ -12478,6 +12501,8 @@ not_move_group:
fd_install(event_fd, event_file);
return event_fd;
+err_block_interf:
+ block_interf_read_unlock();
err_locked:
if (move_group)
perf_event_ctx_unlock(group_leader, gctx);