Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2862512pxv; Mon, 12 Jul 2021 03:52:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfFgrdyFOlCfp5UYglteEepfAN5glZQPKsGtHRkSTr9Oo5CwizfL2g4rGqNT3El5kKOOEn X-Received: by 2002:a92:c56c:: with SMTP id b12mr38086237ilj.13.1626087133072; Mon, 12 Jul 2021 03:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626087133; cv=none; d=google.com; s=arc-20160816; b=1AYJEOCLD4ekGsMDLq+kLS0t+GF1+qbaAchtL2FtJ5lpx5lKbo6cv5TC8J0Sys+G/Y J+GDIuabDHde8DqlEyuvdodn7xY/9Ry9kMU6T31/NM6Aba7IwHjhliqF8bEGJUkX7j50 D7oQ8nXCPHAI3cm/lEoqVHSnEWfiBeuSigbkF4RxcmMsO44vCA9YfqnhFCAuWv2ENuRk cHDOFOa36Zh27Hau7Y+uMtp6eMnFjiUbtqeBgNvVZCHs3J8KJBCvLImuwrUD8CLRDLRj TIPmA+futovaV6C/o3LI+y3PWRhXLeeZAzHprPhQbFtiAcvWTrFNOS/z76QB2id471w2 BS2g== 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=93U/ijQ3lMGC4mDdJscztM+2atBgVNVIswoEHmLPJVo=; b=vxv/kgtxa9bXXSIjHGuH0rXw4xxgYMXAj4RMxHCd0c1kKtCs3v3eX+0sijn0ajdIAD IFibM9xJJMbVhC6oEuYgOSydAVC/A5wyDzlFh7QUgtYDsmZ4EdUYG0fFwGuSk5HjryaJ U51rmyC4JncExE8kqblmhLKzK6O3g6qrsX1CtDVzrW47Y36y153imeS8D2dXNPI9sapO OisRnPI9l3GNmlrpB9xO+fWv5AgJR1L1RVFSNd8FIqWXXiwOWotjBH6npUyFWMseTazG rHIf+8Hr5W581Ju7ThU7R7kRfc6DDysMsUsCjpJKn08A0iQg+97CER4DY1SDmYLB7Vf2 r2kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IjVdIwAQ; 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 v9si20517640ilu.9.2021.07.12.03.52.01; Mon, 12 Jul 2021 03:52:13 -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=IjVdIwAQ; 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 S1357149AbhGLIRE (ORCPT + 99 others); Mon, 12 Jul 2021 04:17:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:52408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243107AbhGLHdI (ORCPT ); Mon, 12 Jul 2021 03:33:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BF14611BF; Mon, 12 Jul 2021 07:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626075013; bh=7mIAPfZFWlrtSMP2nEPWi0DYh6syXH1MzLV13mn0kAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IjVdIwAQK3dlpfPK47iBkVCMDQZ8QQkkRvqoH2lUEhDI+KCU86+1KLfSHzgRETarF 8SiStGT1EjowXVLhh6mby4la886F4bAqJ9I6WmJbjqHHCGdnOtTS16ypAxHHYr7xj/ aXpdWdbLx5eoDDDgnSZWiXVAuruIhPpje2UwebbQ= 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.13 073/800] perf/smmuv3: Dont trample existing events with global filter Date: Mon, 12 Jul 2021 08:01:36 +0200 Message-Id: <20210712060923.458570912@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060912.995381202@linuxfoundation.org> References: <20210712060912.995381202@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 @@ -277,7 +277,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) : @@ -285,17 +285,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; }