Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68591e6f authored by Wei Wang's avatar Wei Wang Committed by Gerrit - the friendly Code Review server
Browse files

perf: Fix HW/SW event grouping failure

In commit b05ec5a7 ("perf: Skip permission checks on kernel owned
perf events"), the patch changes the first argument of
find_get_context() from pmu to event. This leads to
group_leader != ctx so that hardware events and software
events can not be grouped together.

Bug: 30675453
Test: LTP syscalls-perf_event_open02 and set hwmon governor

CRs-Fixed: 2270895
Change-Id: I0b0021aab873f0886a7028a0a14637702b62b3d4
Git-repo: https://source.codeaurora.org/quic/la/kernel/common/


Git-commit: 03aba81b63d0c6c36bfa5a66b61956a1e480bd43
Signed-off-by: default avatarWei Wang <wvw@google.com>
Signed-off-by: default avatarChetan C R <cravin@codeaurora.org>
parent 9f52526c
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -3331,18 +3331,16 @@ errout:
 * Returns a matching context with refcount and pincount.
 */
static struct perf_event_context *
find_get_context(struct perf_event *event, struct task_struct *task, int cpu)
find_get_context(struct pmu *pmu, struct task_struct *task, int cpu, bool check)
{
	struct perf_event_context *ctx, *clone_ctx = NULL;
	struct perf_cpu_context *cpuctx;
	struct pmu *pmu = event->pmu;
	unsigned long flags;
	int ctxn, err;

	if (!task) {
		/* Must be root to operate on a CPU event: */
		if (event->owner != EVENT_OWNER_KERNEL && perf_paranoid_cpu() &&
			!capable(CAP_SYS_ADMIN))
		if (check && perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
			return ERR_PTR(-EACCES);

		/*
@@ -7614,7 +7612,7 @@ SYSCALL_DEFINE5(perf_event_open,
	/*
	 * Get the target context (task or percpu):
	 */
	ctx = find_get_context(event, task, event->cpu);
	ctx = find_get_context(pmu, task, event->cpu, true);
	if (IS_ERR(ctx)) {
		err = PTR_ERR(ctx);
		goto err_alloc;
@@ -7811,8 +7809,12 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
	event->owner = EVENT_OWNER_KERNEL;

	account_event(event);
	/* Skip security check on kernel owned event */
	if (event->owner == EVENT_OWNER_KERNEL)
		ctx = find_get_context(event->pmu, task, cpu, false);
	else
		ctx = find_get_context(event->pmu, task, cpu, true);

	ctx = find_get_context(event, task, cpu);
	if (IS_ERR(ctx)) {
		err = PTR_ERR(ctx);
		goto err_free;