2024-02-06 19:00:51

by Marcelo Tosatti

[permalink] [raw]
Subject: [patch 06/12] perf_event_open: check for block interference CPUs

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-isolation/kernel/events/core.c
===================================================================
--- linux-isolation.orig/kernel/events/core.c
+++ linux-isolation/kernel/events/core.c
@@ -55,6 +55,7 @@
#include <linux/pgtable.h>
#include <linux/buildid.h>
#include <linux/task_work.h>
+#include <linux/sched/isolation.h>

#include "internal.h"

@@ -12435,6 +12436,7 @@ SYSCALL_DEFINE5(perf_event_open,
int err;
int f_flags = O_RDWR;
int cgroup_fd = -1;
+ int idx;

/* for future expandability... */
if (flags & ~PERF_FLAG_ALL)
@@ -12712,6 +12714,26 @@ SYSCALL_DEFINE5(perf_event_open,
goto err_context;
}

+ idx = block_interf_srcu_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.
@@ -12775,6 +12797,8 @@ SYSCALL_DEFINE5(perf_event_open,
put_task_struct(task);
}

+ block_interf_srcu_read_unlock(idx);
+
mutex_lock(&current->perf_event_mutex);
list_add_tail(&event->owner_entry, &current->perf_event_list);
mutex_unlock(&current->perf_event_mutex);
@@ -12789,6 +12813,8 @@ SYSCALL_DEFINE5(perf_event_open,
fd_install(event_fd, event_file);
return event_fd;

+err_block_interf:
+ block_interf_srcu_read_unlock(idx);
err_context:
put_pmu_ctx(event->pmu_ctx);
event->pmu_ctx = NULL; /* _free_event() */