Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2717514pxv; Sun, 11 Jul 2021 23:40:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4PSPuZ2firf64I5eZJPzGjdt+qu1bzBTU0tYhj5wtyR11EEHTO4IqPej2neH5OfZ7UQfv X-Received: by 2002:a05:6402:2789:: with SMTP id b9mr28083392ede.201.1626072054407; Sun, 11 Jul 2021 23:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072054; cv=none; d=google.com; s=arc-20160816; b=eYte8t0i1mbVa/X2IyKg6RgVOO2fmfRehTE3Jywo/OPF49If9E7aKukYLC5Bq7P5Hl Wsj/3QOZNLrukc8a7tcn0oibLnpY2UbVRTnv+J349RDsN54yxfIPMj+0s2sOXafjBr30 dJG4ITELQiaDyaj95ug4s0rKZdJbze9sBmr323AnmNb9FtjSxyqp6fMW6PZXCekSnqiP 6d5GdF1B71UOAyBs/D54Dc8pGSpVKzzcwBTtnN5+IfHQM0XC4v1YSfC+jzjQuUa8qzuC s4SR7N/yeYgeE2ClkR/rskAolnVTw5g2S6zcLOpoRAB23VEZdvVKSNCD8zJ9WP8EzOcu MpFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LYaE6r5ahxWSKlZ9eDUts0olj5RewM+UVJOhuk6h36M=; b=JXdL499tAditPeaD4HWMlKjyhJmilCTCzXgky0U4XQb479ujJks7gB+r5j2eXacVf/ Zn4ERgCweW5mevd1j8DgR+fZTSgRmvctkBlAQGPuJZDfcJx1EQS6JrNQWWO2TWTBh+Gu Hvhnm7AC47GJblz0KQds4GiyTVFd2AeTeeulRtTJbSUM/YCAtI1irHGwh1RrtHMCwAxT XoqZ+2QLKaimu/RqTyPOH9I9hiKBFeP/IOSptNaz9xahy62mBhq9puQV28jtOKindFGk BnZ6ARgpx1sewkQOGUAHvGLFZFy3UPeIHiAEnQwGrX5uo7d8OZvVl/n6SsUDxG+s/5Ql AMvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="kABtg5/M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si17997243ejg.480.2021.07.11.23.40.32; Sun, 11 Jul 2021 23:40:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="kABtg5/M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236322AbhGLGlh (ORCPT + 99 others); Mon, 12 Jul 2021 02:41:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:55424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237105AbhGLGeJ (ORCPT ); Mon, 12 Jul 2021 02:34:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B1BEA61152; Mon, 12 Jul 2021 06:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071420; bh=Mc2o0mKA+e5b0/Jg87QMiGwTum9UxfWN2g2j+WJ9h+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kABtg5/MnFXf2Nlp72NJpXYBh/KvmyRQpHY4C5onLC4C7MOqvzpNESNCjZdSVLW+J G3Yjdgf6VX5H0/8KQl8/XKYmJYc1Xuav2fDgE3Xl9sEDTxwb4Q7ICAw4t2sAx03s4s s1kizCisMZLzagn4/1mQfkLlFeb0aJoCb7BEV5Ro= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Will Deacon Subject: [PATCH 5.10 060/593] perf/smmuv3: Dont trample existing events with global filter Date: Mon, 12 Jul 2021 08:03:40 +0200 Message-Id: <20210712060849.751800106@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy commit 4c1daba15c209b99d192f147fea3dade30f72ed2 upstream. With global filtering, we only allow an event to be scheduled if its filter settings exactly match those of any existing events, therefore it is pointless to reapply the filter in that case. Much worse, though, is that in doing that we trample the event type of counter 0 if it's already active, and never touch the appropriate PMEVTYPERn so the new event is likely not counting the right thing either. Don't do that. CC: stable@vger.kernel.org Signed-off-by: Robin Murphy Link: https://lore.kernel.org/r/32c80c0e46237f49ad8da0c9f8864e13c4a803aa.1623153312.git.robin.murphy@arm.com Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- drivers/perf/arm_smmuv3_pmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/drivers/perf/arm_smmuv3_pmu.c +++ b/drivers/perf/arm_smmuv3_pmu.c @@ -275,7 +275,7 @@ static int smmu_pmu_apply_event_filter(s struct perf_event *event, int idx) { u32 span, sid; - unsigned int num_ctrs = smmu_pmu->num_counters; + unsigned int cur_idx, num_ctrs = smmu_pmu->num_counters; bool filter_en = !!get_filter_enable(event); span = filter_en ? get_filter_span(event) : @@ -283,17 +283,19 @@ static int smmu_pmu_apply_event_filter(s sid = filter_en ? get_filter_stream_id(event) : SMMU_PMCG_DEFAULT_FILTER_SID; - /* Support individual filter settings */ - if (!smmu_pmu->global_filter) { + cur_idx = find_first_bit(smmu_pmu->used_counters, num_ctrs); + /* + * Per-counter filtering, or scheduling the first globally-filtered + * event into an empty PMU so idx == 0 and it works out equivalent. + */ + if (!smmu_pmu->global_filter || cur_idx == num_ctrs) { smmu_pmu_set_event_filter(event, idx, span, sid); return 0; } - /* Requested settings same as current global settings*/ - idx = find_first_bit(smmu_pmu->used_counters, num_ctrs); - if (idx == num_ctrs || - smmu_pmu_check_global_filter(smmu_pmu->events[idx], event)) { - smmu_pmu_set_event_filter(event, 0, span, sid); + /* Otherwise, must match whatever's currently scheduled */ + if (smmu_pmu_check_global_filter(smmu_pmu->events[cur_idx], event)) { + smmu_pmu_set_evtyper(smmu_pmu, idx, get_event(event)); return 0; }