Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2705165pxv; Sun, 11 Jul 2021 23:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPiIiIeLyEVuQbLue7ADXGodzcvNqeJPq5qO+JMtdfZAsqV6z5rQB2+qIxSzXREcBMd2FR X-Received: by 2002:a02:cce6:: with SMTP id l6mr7503436jaq.114.1626070640091; Sun, 11 Jul 2021 23:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070640; cv=none; d=google.com; s=arc-20160816; b=bsSWWZIsmWg3vNRv/gHLq8dUs6DepVkU+79kAALEck2mamOETsF9lfzASzArpgMXKK nMjw1v+2LvzamMw3keGOCCyjWa9TujpXRttGyHTHJ7UOJECZkWfkk7a0AaaNCtiZTrUK uE5+JXb1OWwjO5MJv0uT7zHUGNeQFQeSs0+asF7R7eU0Eewg5xRpWUfnNHJgCyfwBP2G P0JsV7/6aWlHWvJNvKdQ8FWPn0rYpB/LaE1+YbvKBnG2F+CtsA+FxmqhyCVnhkSY7Ipg dX+XntDseel3r8XmZbe7ukso3OeRL3e2QzNa6VjGqwuGj+vPuHaoQDE9A+OV0u8fZo4q ooCg== 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=dilrSkz3k05W1VCWseuRL/mE6JBvdC3xRxyZO2NhnEF12+yPHSbV+fIUC6o1FnHhYy 9HkgHKlYSxqAQ7RnKtAAB2BiHiuxNS+jRIPxVOW0M6+zS0Jmg5NKUmwTMuncVeKSVb+N RVBnOhzxCD7gXs2wOpf33PFl+j3UW+RoIntA0Au4+5KostAcKOcfBLE61ZBTHu0a74j0 WvLeV7v9K5MLyFLg8CTM+TVoq0fWdjIyzyUXhTzbFCqlhqRolAds8DpKWbcK27aG5DRL 3E3i84e/tWvbFIBJE8lsvccy72dT5RuE1Kom3UWRVAYUsqk/4bCFhVyow3TSj9YZvGVg ZNeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wZZ0tKJy; 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 p31si18761496jac.95.2021.07.11.23.17.09; Sun, 11 Jul 2021 23:17:20 -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=wZZ0tKJy; 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 S233795AbhGLGS7 (ORCPT + 99 others); Mon, 12 Jul 2021 02:18:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:37164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbhGLGSi (ORCPT ); Mon, 12 Jul 2021 02:18:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 959AE610A7; Mon, 12 Jul 2021 06:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070551; bh=Mc2o0mKA+e5b0/Jg87QMiGwTum9UxfWN2g2j+WJ9h+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wZZ0tKJy/bRvrpV4uy6XVALnskAyP2Wln4oOiOqcaihvYE3+6dmXTGnUfhj7SZFKb KetTF/UfFU89LMiKFPsk9cA9omdYynj2dLUt/GOIwc0Bdve5QnNEee2/cy5EQZGPe+ dR+iYOSmcfLnqZLbrhcEPJ/F6veULl9OSQlOy2ao= 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.4 039/348] perf/smmuv3: Dont trample existing events with global filter Date: Mon, 12 Jul 2021 08:07:03 +0200 Message-Id: <20210712060706.146385978@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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; }