Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2833329pxv; Mon, 12 Jul 2021 03:04:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa+bLhw4Q5BG//xpYpze7Ji+Zl5cXNi3fQvGqCL/ydMX3YhRO92VCGPcGLMIN0GvvaLbCh X-Received: by 2002:a92:1944:: with SMTP id e4mr36613113ilm.186.1626084296862; Mon, 12 Jul 2021 03:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084296; cv=none; d=google.com; s=arc-20160816; b=MSHTxU57+wCRkOmtUHePmfoZz0N8wJPd7Iacns+19tMWtn3hd55jFKCpdCdC2tq2TY 3Sl2p35RQ/6J7KhFIqwzk+mHLkFeElksLPpfUQ8YGfv4DjIXsbuFaeayIDyIijbsR54O iwhQz1mOWwXensgTp7Tkv+rMUE/CQnX7SW2ckkXrEArAmCidGg0f5akQWN6VLzMM+ph9 mhWgbn8fITLbj+TqAQYCJtKuuAwM2DvopCKDVqeXkJsR+143xe6k4qxYBE4XVtixV0Q5 LJjO9N92O6iMkIhP7oaWZ0s/6JIpcql8zJMQ0FS0DMPXlHi0ZAxjiWL1aUaT7ymYl7AI MZqQ== 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=T8/tT9EffAWmeyBCHTNwf+pnFfYIYYfb9qlumgBhUWWRKwJOpk89AkIe3SSism2Ok6 S6k+vBvQGfBEZDD+Z0TYgN+Qw3bgAAP+sebf54LZkEpNL1VW/UvAiyHjqMlr/i3HKv8O Uh0pWoJFI+aZSk11x3Ji3loY2/Nenn9nrIZEY49+V38bnbIqgDD/AgSXhMV7mrouPEjm feUFrzeuvY858F43tZF3uTz2gNcQfZFfQdFb7KtdWm+GPc9/FF7tej9e4InZz7SdiESA DNreq699GPWnhTABsJpeE/CF5aXkVG6vwHwwn2m902FS4wCXRF5755igOPXxqeMrvauW 32/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oaQrTqaT; 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 v14si15868597ilj.0.2021.07.12.03.04.43; Mon, 12 Jul 2021 03:04:56 -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=oaQrTqaT; 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 S1345278AbhGLHZO (ORCPT + 99 others); Mon, 12 Jul 2021 03:25:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:32916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239452AbhGLG6Z (ORCPT ); Mon, 12 Jul 2021 02:58:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 803FD610CA; Mon, 12 Jul 2021 06:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072936; bh=7mIAPfZFWlrtSMP2nEPWi0DYh6syXH1MzLV13mn0kAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oaQrTqaTvsoWbjB1GpoJKgaYwZnlUhS1uMu+BWXaNw0xcuTR6dYs9rcv019+OHTAT VlW7bjHFRVJxyrL8Fzq1eiwBhnaPaemQovkar2CiQ9GHUJwd0NTkHD19qv5KGgPWHT UGqSk/FD2gwUZfW2FNmGswxOHheek/UFeC8SfnLw= 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.12 069/700] perf/smmuv3: Dont trample existing events with global filter Date: Mon, 12 Jul 2021 08:02:32 +0200 Message-Id: <20210712060934.463166294@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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; }