From nobody Mon Feb 9 16:51:53 2026 Received: from mx07-00376f01.pphosted.com (mx07-00376f01.pphosted.com [185.132.180.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C2DD38A9B7 for ; Tue, 13 Jan 2026 10:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.180.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768299445; cv=none; b=E5A//X8AMnAJ4dH+QsVsRMIipsSVd8tYLFtscCyzocv8PLUfSx0fmf9T7+H824k40urU+jsHLsh6WXfXcoXUd9BahRoWLYFrNP/463SmBukdwirkpj514EdQpvo01C2Pu5Zg4il9Dij2lykzyI+qZQkZL45WG0EaZspDXhJ9Sy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768299445; c=relaxed/simple; bh=e48rK276oHs7zkZU1GPlTK5G1OMsY6vbZe40B8Ci+g4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=KJSKBhov5O4zEUzpqKH5mxh7Su3ynW4r24BeA6uPfYoVEQPGZrGYExjuUAKqUUqYDtikmwTd8AqUqOF5nIpxLga2W1+6GtuafK6a8hMJ1RaSZlf7z6lqLLkq0fdTCc9Oq3j1V3MY5gsNqep8quWRomopUYebBlUe/Vr4X9tWr/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=imgtec.com; spf=pass smtp.mailfrom=imgtec.com; dkim=pass (2048-bit key) header.d=imgtec.com header.i=@imgtec.com header.b=v9La1J1b; arc=none smtp.client-ip=185.132.180.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=imgtec.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=imgtec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=imgtec.com header.i=@imgtec.com header.b="v9La1J1b" Received: from pps.filterd (m0168889.ppops.net [127.0.0.1]) by mx07-00376f01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60D6XiIS3196794; Tue, 13 Jan 2026 10:16:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imgtec.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=dk201812; bh=Z w788SzHZ6X+qopWNgn6e9jJ+VJXNluv2HjpPwnE7i0=; b=v9La1J1b8nnODhY9+ dwR6IVSBGg4MT41GT6rHgig6g+1tf7r8P6SujMQa2VWNsMFOPqbWZMmus+zl3bPs /pBVkB0nR8PINDPivMsNOjssIsiAJphcC7Ka5YZ7hrymPcntdC3PhvIT8X+M6EY/ B332oJ/v6GRz8dyeTOi3eQzT5NPhU2Gik/V+VQRE/5xfvohynwoMf1LOTImkiuz4 6aiAeBHMNf0cjxp3jN7D5uws2Y45VHyisKS50nqt/nEICR9h+w4Ve1XwQ5yEEhh4 HtWBkJ0zwMgSc3tjlvI2lubeHm+/zxyq0aVzhZ+OoGNAiOCbL74VPqT0CCE4PaiD idL3w== Received: from hhmail01.hh.imgtec.org (83-244-153-141.cust-83.exponential-e.net [83.244.153.141]) by mx07-00376f01.pphosted.com (PPS) with ESMTPS id 4bkfqua1rs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jan 2026 10:16:57 +0000 (GMT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa (172.25.4.58) by HHMAIL01.hh.imgtec.org (10.100.10.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Tue, 13 Jan 2026 10:16:56 +0000 From: Matt Coster Date: Tue, 13 Jan 2026 10:16:40 +0000 Subject: [PATCH 2/6] drm/imagination: Validate fw trace group_mask Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260113-device-support-info-v1-2-91e5db7f7294@imgtec.com> References: <20260113-device-support-info-v1-0-91e5db7f7294@imgtec.com> In-Reply-To: <20260113-device-support-info-v1-0-91e5db7f7294@imgtec.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter CC: Frank Binns , Brajesh Gupta , Alessio Belle , Alexandru Dadu , Matt Coster , , X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4987; i=matt.coster@imgtec.com; h=from:subject:message-id; bh=e48rK276oHs7zkZU1GPlTK5G1OMsY6vbZe40B8Ci+g4=; b=owGbwMvMwCFWuUfy8817WRsYT6slMWSmSU8LPBzet+LYsm1t/uXZbllzLSaubf3SXeNgxF1ss 2Z9NHNNRykLgxgHg6yYIsuOFZYr1P6oaUnc+FUMM4eVCWQIAxenAEykV4uRYeEk32+WMqGHfab4 WLWc9z2mzhLttedzHI/M5NDIBDGhCEaGW6HyU+WuNek8di/f+WX/UYOb396ureBfGtcQteDNzmw 2fgA= X-Developer-Key: i=matt.coster@imgtec.com; a=openpgp; fpr=05A40CFCE7269D61D97100A1747F0A9036F90DFA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTEzMDA4NiBTYWx0ZWRfX2LgACICv+lMY MK6nPAkr/vlKM5TId0Yn/1Zp0NmFCcSrQsgLff0qOnsBFKx5QS5cAdxhxRGgAun8o4r1FUlW9IM FaGan9sP7l21yIH+BSyfTiTJGVX0Be9RndwRrrvXk6HJIXBsCuXaAPzfM7wy2vUNbiJe/Ij6AVo kgu7OOz8r+E/Fi4atjSiEqn5wk+W4UTFW0fL2gZYePxarn3O1xfX6NikQI4D9sfSDlhCNo0r62t TOO6uByXqgF6SR24bRfwNUYOJR4gPHKCYJHrfm7Ua43TzhNGhbArBdaGkoxb7xBP/n9gyIRTsgC iKlhbFsosEDP6g3Y3aVV0/wrhGFgEFyZo8O1sKkrL8oMm05U+sGqXdsUweS3vyC9OtQFgMM848l 28IfGHGFNov3N59we9wzV286FXBpLTM+10H1iOaoNbwm8/pbhKMo53ErqjwbusqrtUlupIM/mSH LiCrGl2rad24+Dav0JA== X-Proofpoint-GUID: ppISc8BZrdA-8qX2HTFw-0qEPa7ugPoP X-Proofpoint-ORIG-GUID: ppISc8BZrdA-8qX2HTFw-0qEPa7ugPoP X-Authority-Analysis: v=2.4 cv=aexsXBot c=1 sm=1 tr=0 ts=69661b99 cx=c_pps a=AKOq//PuzOIrVTIF9yBwbA==:117 a=AKOq//PuzOIrVTIF9yBwbA==:17 a=jNdnsKvOq7QA:10 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=r_1tXGB3AAAA:8 a=Nbp4WR2GB4CHkkDwQf0A:9 a=QEXdDO2ut3YA:10 a=t8nPyN_e6usw4ciXM-Pk:22 This value can come from two places: a module parameter or a debugfs file. In both cases, validate it early to provide feedback to userspace at the time the value is set instead of deferring until the value is used. Signed-off-by: Matt Coster --- drivers/gpu/drm/imagination/pvr_fw_trace.c | 76 ++++++++++++++++++++++++--= ---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_fw_trace.c b/drivers/gpu/drm/i= magination/pvr_fw_trace.c index a607e5b108915..a2aa588cbe5fa 100644 --- a/drivers/gpu/drm/imagination/pvr_fw_trace.c +++ b/drivers/gpu/drm/imagination/pvr_fw_trace.c @@ -12,12 +12,35 @@ #include =20 #include +#include #include #include #include #include #include =20 +static int +validate_group_mask(struct pvr_device *pvr_dev, const u32 group_mask) +{ + if (group_mask & ~ROGUE_FWIF_LOG_TYPE_GROUP_MASK) { + drm_warn(from_pvr_device(pvr_dev), + "Invalid fw_trace group mask 0x%08x (must be a subset of 0x%08x)", + group_mask, ROGUE_FWIF_LOG_TYPE_GROUP_MASK); + return -EINVAL; + } + + return 0; +} + +static inline u32 +build_log_type(const u32 group_mask) +{ + if (!group_mask) + return ROGUE_FWIF_LOG_TYPE_NONE; + + return group_mask | ROGUE_FWIF_LOG_TYPE_TRACE; +} + /* * Don't gate this behind CONFIG_DEBUG_FS so that it can be used as an ini= tial * value without further conditional code... @@ -29,7 +52,33 @@ static u32 pvr_fw_trace_init_mask; * there's no reason to turn on fw_trace without it. */ #if IS_ENABLED(CONFIG_DEBUG_FS) -module_param_named(init_fw_trace_mask, pvr_fw_trace_init_mask, hexint, 060= 0); +static int +pvr_fw_trace_init_mask_set(const char *val, const struct kernel_param *kp) +{ + u32 mask =3D 0; + int err; + + err =3D kstrtouint(val, 0, &mask); + if (err) + return err; + + err =3D validate_group_mask(NULL, mask); + if (err) + return err; + + *(unsigned int *)kp->arg =3D mask; + + return 0; +} + +const struct kernel_param_ops pvr_fw_trace_init_mask_ops =3D { + .set =3D pvr_fw_trace_init_mask_set, + .get =3D param_get_hexint, +}; + +param_check_hexint(init_fw_trace_mask, &pvr_fw_trace_init_mask); +module_param_cb(init_fw_trace_mask, &pvr_fw_trace_init_mask_ops, &pvr_fw_t= race_init_mask, 0600); +__MODULE_PARM_TYPE(init_fw_trace_mask, "hexint"); MODULE_PARM_DESC(init_fw_trace_mask, "Enable FW trace for the specified groups at device init time"); #endif @@ -42,11 +91,7 @@ tracebuf_ctrl_init(void *cpu_ptr, void *priv) =20 tracebuf_ctrl->tracebuf_size_in_dwords =3D ROGUE_FW_TRACE_BUF_DEFAULT_SIZ= E_IN_DWORDS; tracebuf_ctrl->tracebuf_flags =3D 0; - - if (fw_trace->group_mask) - tracebuf_ctrl->log_type =3D fw_trace->group_mask | ROGUE_FWIF_LOG_TYPE_T= RACE; - else - tracebuf_ctrl->log_type =3D ROGUE_FWIF_LOG_TYPE_NONE; + tracebuf_ctrl->log_type =3D build_log_type(fw_trace->group_mask); =20 for (u32 thread_nr =3D 0; thread_nr < ARRAY_SIZE(fw_trace->buffers); thre= ad_nr++) { struct rogue_fwif_tracebuf_space *tracebuf_space =3D @@ -140,7 +185,7 @@ void pvr_fw_trace_fini(struct pvr_device *pvr_dev) /** * update_logtype() - Send KCCB command to trigger FW to update logtype * @pvr_dev: Target PowerVR device - * @group_mask: New log group mask. + * @group_mask: New log group mask; must pass validate_group_mask(). * * Returns: * * 0 if the provided @group_mask is the same as the current value (this= is a @@ -153,6 +198,7 @@ static int update_logtype(struct pvr_device *pvr_dev, u32 group_mask) { struct pvr_fw_trace *fw_trace =3D &pvr_dev->fw_dev.fw_trace; + struct drm_device *drm_dev =3D from_pvr_device(pvr_dev); struct rogue_fwif_kccb_cmd cmd; int idx; int err; @@ -161,15 +207,11 @@ update_logtype(struct pvr_device *pvr_dev, u32 group_= mask) if (fw_trace->group_mask =3D=3D group_mask) return 0; =20 - if (group_mask) - fw_trace->tracebuf_ctrl->log_type =3D ROGUE_FWIF_LOG_TYPE_TRACE | group_= mask; - else - fw_trace->tracebuf_ctrl->log_type =3D ROGUE_FWIF_LOG_TYPE_NONE; - fw_trace->group_mask =3D group_mask; + fw_trace->tracebuf_ctrl->log_type =3D build_log_type(group_mask); =20 down_read(&pvr_dev->reset_sem); - if (!drm_dev_enter(from_pvr_device(pvr_dev), &idx)) { + if (!drm_dev_enter(drm_dev, &idx)) { err =3D -EIO; goto err_up_read; } @@ -472,8 +514,14 @@ static int pvr_fw_trace_mask_get(void *data, u64 *valu= e) static int pvr_fw_trace_mask_set(void *data, u64 value) { struct pvr_device *pvr_dev =3D data; + const u32 group_mask =3D (u32)value; + int err; + + err =3D validate_group_mask(pvr_dev, group_mask); + if (err) + return err; =20 - return update_logtype(pvr_dev, (u32)value); + return update_logtype(pvr_dev, group_mask); } =20 DEFINE_DEBUGFS_ATTRIBUTE(pvr_fw_trace_mask_fops, pvr_fw_trace_mask_get, --=20 2.52.0