From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796050282; b=PnW4W1PQKZhUV6Xf1Dd66y4ebzK1QAVz2H6dJyJr9RH5Zp/I+zOlFsy62McOUAA7K4nG aDClCMDUeeUafuhUY62pb4VMMOoe+MGa4nApAKx1KU/MgfANZRApISu7PhMbhcfoVuOed DOESvWePusBmq4MhgqbhDxmeK9UwijBCD2H7DTez8quP2E2qrs/AnnTfned74SuuhWIPD sD1ejq5u1PFxV7eA53mvjlE2qo5BECcgMZM9ktKV1iEgcPX+rSoGstm/OURetoDr4kuRv sr2zuAKj6LBdgnDN+c68N5yAhIRfHy5jcOloA8V9QZSdFnobXkAEeQVKn1dl/REy+yw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796050282; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=0q+2zGF3ZaDNNdS/5R2ywECjPvw4WCLjHyOA39Rbq88=; b=P7A3Ww3zJZgVgvYKqAflWbYeiBI3eDdmd7vuuuZcgdmE6Ew2J99YwRm2Z/sC8QP67Cqv IJTmga2TVXWEE+vFBgj/47xHyT2Va0iTe0l6Y2Nej1CdLjiM8aXokLzOsqm9S+T9aBf7A 03u1Cb8x9OHnnnc8bvXVXJzGq6NnapIuWmr5PfGnQmXvf7U12/KIM05UmvgmJScl/qSgo nQ8LH20xTTO1T046m135rke6rWXmdGSKFjAG2hNJ92W0KW3/8eBXtwyibFu1njKaZawC2 dyN9M9Tz1LGIaTcN2OCAXaa267mxI3xlFEFcqV+s5gM6Kt8UP+TwsqKCFVrHqKk+xGQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b="Z5/Up0Lu"; arc=none smtp.remote-ip=209.85.221.52 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DBAB606A32A for ; Mon, 30 Nov 2026 14:51:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2DBAB606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Z5/Up0Lu Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-490d59c3f0aso4886853f8f.1 for ; Mon, 30 Nov 2026 06:51:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796050279; x=1796655079; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0q+2zGF3ZaDNNdS/5R2ywECjPvw4WCLjHyOA39Rbq88=; b=Z5/Up0LuKjNweVArxkYkAjzJPqBLZXwu3n5SB3yrp0kwcg+jF9CL6Kfw+MF6NY60jl DO7oZxFHJKyEUMy4TLz/hrHOJAE6ydOveJXklfhzxTLTiBDWePDYbAgygV1PlJ7+5n/B AtvX3wQfAu14DwdPIAxffY9vfm4W1L5jeSXSuNVsA17iP0ujv54ygCZEGVJdYCeRyYY/ HqYyFioHKvwCOg3YiIJNy8KiXkPguVduKvuqeGWl+kfOQErAu24jJOS7nu7GILRPSqp8 DI5E57UHCv/73HMozmDovZwirp5DHGW7LlIras0MT79WyAOt7Fb1Q7mL1zkBevcZYAC8 SRSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796050279; x=1796655079; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0q+2zGF3ZaDNNdS/5R2ywECjPvw4WCLjHyOA39Rbq88=; b=YZDkz/ukRwtPTepkB9D96+RssV/gtxPiwUofc1FR6Wa4guBzOegJVm0UTYWDtUqMNI 0uUiJAGWYv7uWxgMdpImz82v3po2pron3K/jseogy2cxB2zpBUrHFv8vlp8VIB/LBW1A c+FYW2wyJeZ0DQ7gkeJ12IiY05AetDkig2xxR8Ljlgu4ThO/wzBwgEYc2mj7KnpG8RYP BFXrgT29D7BUF4Ki9fJ/K1rJErHOzw6hqecAn31xzmXsGL+uwL2JPGyQDk+N6GaRN6tY iNUi2D9Ng13UKcP0DsYcfZdV4p7mhgLHPxz51iHqXmH0Puogqw3OCWDxut5iSFsIGnAF lwLw== X-Forwarded-Encrypted: i=1; AL+hErGh+kzsILNuKmyefBBSf3I4qBp5n5wsl+jEWDTnktDWzIT35+XYvkpCPqXSVQCT5w9EjvPI8Za6LUC0gUc=@vger.kernel.org X-Gm-Message-State: APuU4Z9coz7OFgI45jaw1IB4SRoBhMoKwvTrBV5tnEPwMSmwi2LacX3o UqMLF1AIRKcXOUB1m9RC+fiFPBkdDH26cH9rC7NLsrRJsdBjqvDKqSu0NpVSoaKel5c= X-Gm-Gg: AZFdTZfjXC+CtclKAyYDUa9JkHELT1cQfwYRr2AtXGTotkdMrpNtb+GFcHsgL6jeGtP SMQ9m/+yHe/QKd9EQgJiDaFG+EGH0tfQVdjfTlb2y3SGP7YX5TPg9VlQAflgVFrk00bVJZnippY yJy+KQ6ybdtlWr+jUsGJwEVXHfCYr2pTE5drijyvJYAAb9FjR+J9Cm3wGlz8jdNhZCE1EkGK3IU KRFY7KGakl0gzrlNOZ85eNikrB1G2cB0F/cNrWRRd+7hpC5woNfo98M9WBDXe/dB3Z+juBhi+lr faZRUssgsOA+dJRL+mn/GNyUEnXH3Anl7Cm2NzcbL0XI6t5blQvBygEHyzuTGUzj9GA/WoN+v4y w5OHH4kQYSOBxy1aimULviy6vlHOqf8wO2I+QQMXatEDjVka0BCn3Oq2YVY+xsCNUnzXYkDWV/V Pqm9SF3LNMYyyaA0PxRPC6ZtrkSFLXqRCx2uvKIcsRX6x+0m0R3RbOfizk08JCnpNBijCS32C0m bDMKotyeu/dl2L/AUhquncE3grR3Kk1MYD3me9dblobvslyozPYjAV7EnBfm7t175deCjaZZAoP KeAIdkCV0hrxnnjFoBFHoyL6QrJ+S4dRPA== X-Received: by 2002:a05:6000:1848:b0:4c8:802e:4300 with SMTP id ffacd0b85a97d-4c8802e4669mr2248847f8f.33.1796050279505; Mon, 30 Nov 2026 06:51:19 -0800 (PST) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67f281sm62144669f8f.22.2026.11.30.06.51.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 06:51:18 -0800 (PST) Message-ID: <3dffa952-9430-4947-b2b9-9a826f1cc938@linaro.org> Date: Mon, 30 Nov 2026 14:51:17 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] perf: arm_spe: Validate the data source filter per-bit To: Ping Li , Leo Yan Cc: robh@kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, mark.rutland@arm.com References: <20261130061331.90095-1-leeonion.muyu@gmail.com> <20261130061331.90095-3-leeonion.muyu@gmail.com> Content-Language: en-US From: James Clark In-Reply-To: <20261130061331.90095-3-leeonion.muyu@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 30/11/2026 06:13, Ping Li wrote: > The data source filter (config4) is only checked for the presence of > the FDS feature and never validated per-bit, so a config asking to > filter on data sources the hardware does not support is accepted. > > PMSDSFR_EL1 is an inclusion mask which the driver exposes inverted: > a set config4 bit requests that a data source is excluded, a cleared > bit requests that it is included. Unsupported filter bits are RAZ/WI > (Arm ARM DDI 0487 M.b, D24.7.10), so they are stuck at 0: exclusion > requests are always honoured, but requests to include an unsupported > data source are silently dropped while the filter is active. I'm not sure changing this this really fixes anything though? Now you're going to start rejecting events based on peoples existing filters, and if a filter bit isn't implemented, surely that must be because that data source value is never used on that CPU, so nobody would see any unexpected behavior anyway? If a CPU emitted a data source whose filter bit was RAZ/WI, enabling data source filtering would always discard that source, with no way to include it. There can't be real hardware with that limitation can there? I'm certain that the RAZ/WI part of the ARM exists because of data source that the CPU never emits, not because filtering them is unsupported. Say a user was doing something simple like excluding data source 3, they'd do filter == (1 << 3), which now gets rejected after inverting it because all the other bits are set, some of which are "unsupported". Publishing the supported data filter mask as a cap _might_ be useful, although nobody has ever asked for it. But this change looks like it's just "technically more correct" but not actually useful. > > Probe the supported filter bits of PMSDSFR_EL1 when FDS is > implemented and reject configs which ask to include an unsupported > data source. Group the check with the FDS presence check so that > config4 is only validated when the filter is in use. Keep a full > mask when the feature is not implemented so that the field cannot > be misread as 'all bits supported'. > > Fixes: e6a27290d800 ("perf: arm_spe: Add support for filtering on data source") > Signed-off-by: Ping Li > --- > drivers/perf/arm_spe_pmu.c | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) > > diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c > index 0b1a088bb7c7..a0d0caf75145 100644 > --- a/drivers/perf/arm_spe_pmu.c > +++ b/drivers/perf/arm_spe_pmu.c > @@ -93,6 +93,7 @@ struct arm_spe_pmu { > > u64 pmsevfr_res0; > u64 pmsnevfr_res0; > + u64 pmsdsfr_res0; > u16 max_record_sz; > u16 align; > struct perf_output_handle __percpu *handle; > @@ -822,9 +823,19 @@ static int arm_spe_pmu_event_init(struct perf_event *event) > if (arm_spe_event_to_pmsnevfr(event) & spe_pmu->pmsnevfr_res0) > return -EOPNOTSUPP; > > - if (arm_spe_event_to_pmsdsfr(event) != U64_MAX && > - !(spe_pmu->features & SPE_PMU_FEAT_FDS)) > - return -EOPNOTSUPP; > + /* > + * The data source filter is exposed inverted, so validate the > + * value written to PMSDSFR_EL1 (~config4) rather than config4 > + * itself. > + */ > + reg = arm_spe_event_to_pmsdsfr(event); > + if (reg != U64_MAX) { > + if (!(spe_pmu->features & SPE_PMU_FEAT_FDS)) > + return -EOPNOTSUPP; > + > + if (reg & spe_pmu->pmsdsfr_res0) > + return -EOPNOTSUPP; > + } > > if (attr->exclude_idle) > return -EOPNOTSUPP; > @@ -1236,6 +1247,13 @@ static void __arm_spe_pmu_dev_probe(void *info) > spe_pmu->pmsnevfr_res0 = U64_MAX; > } > > + if (spe_pmu->features & SPE_PMU_FEAT_FDS) { > + write_sysreg_s(U64_MAX, SYS_PMSDSFR_EL1); > + spe_pmu->pmsdsfr_res0 = ~read_sysreg_s(SYS_PMSDSFR_EL1); > + } else { > + spe_pmu->pmsdsfr_res0 = U64_MAX; > + } > + > dev_info(dev, > "probed SPEv1.%d for CPUs %*pbl [max_record_sz %u, align %u, features 0x%llx]\n", > spe_pmu->pmsver - 1, cpumask_pr_args(&spe_pmu->supported_cpus),