From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA6B2C61DB9 for ; Thu, 27 Aug 2026 20:33:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 60B8D10F1A8; Thu, 27 Aug 2026 20:33:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="ghoQbs1r"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2041510F19E for ; Thu, 27 Aug 2026 20:33:27 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 0926D44022; Thu, 27 Aug 2026 20:33:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B54D31F00A3E; Thu, 27 Aug 2026 20:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787862806; bh=S09KMKeejzD64bM7Mo69fZD6EyqOgGCSj8/rAtNwTt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ghoQbs1rBX4gZHHxLvGMeDqxgTlWT2vHzff0iBVNoRcycqoL75Np82wQYoH+JRLAU OGjsyzodrEjIv4HgUNhPHcii8Vota2epXwmRD7ZCneKzcMO5YBNAtI1ZeFOanMqhfo HD/3rhRTiCnD22wYn5LxpzCt2HeZUrDE2LsW4nXUXfnA4joERkfGxs3X/aIpKuRDxw G0BrhMLvpKq3MunURfO7uYc7WhNDLcucVrkeQ+WsxAvlCWFUZdEKkI8o33Yidv/Zs2 BKIaTMSkDybaOfVfushMnM9iV0sQ58hdVwYY+H6OUg720dphSLQfY8qxdqG7MWbKBu sxSCEBqGF7VeQ== From: "Rob Herring (Arm)" Date: Thu, 27 Aug 2026 15:33:10 -0500 Subject: [PATCH 11/11] accel: ethosu: Validate OFM transpose MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260827-ethosu-fixes-v1-11-346f9ea8791c@kernel.org> References: <20260827-ethosu-fixes-v1-0-346f9ea8791c@kernel.org> In-Reply-To: <20260827-ethosu-fixes-v1-0-346f9ea8791c@kernel.org> To: Tomeu Vizoso , Oded Gabbay , Frank Li , Thomas Zimmermann Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.16-dev X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" U85 OFM dimensions are specified before transposition, while tile bases and strides address the transposed feature map. Permute the output endpoint before validating its tile and stride accesses. Allow the defined U85 transpose encodings and reject the two reserved encodings. Assisted-by: LLM Signed-off-by: Rob Herring (Arm) --- drivers/accel/ethosu/ethosu_device.h | 1 + drivers/accel/ethosu/ethosu_gem.c | 58 ++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/accel/ethosu/ethosu_device.h b/drivers/accel/ethosu/ethosu_device.h index c330048dbcca..1731c43aa045 100644 --- a/drivers/accel/ethosu/ethosu_device.h +++ b/drivers/accel/ethosu/ethosu_device.h @@ -87,6 +87,7 @@ struct gen_pool; #define PMU_EV_TYPE_IDLE 0x20 #define NPU_DMA_REGION_INDEX_MODE BIT(11) +#define NPU_OFM_TRANSPOSE_MASK GENMASK(13, 11) enum ethosu_cmds { NPU_OP_STOP = 0x0, diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c index a042e650f626..ad36fb8b3b30 100644 --- a/drivers/accel/ethosu/ethosu_gem.c +++ b/drivers/accel/ethosu/ethosu_gem.c @@ -199,6 +199,52 @@ static bool feat_matrix_chained(struct ethosu_device *edev, struct feat_matrix * return !ethosu_is_u65(edev) && storage == 2; } +static int feat_matrix_permute(struct ethosu_device *edev, + struct feat_matrix *fm, u32 *x, u32 *y, + u32 *c, bool ofm) +{ + u32 width = *x; + u32 height = *y; + u32 depth = *c; + u32 transpose; + + if (ethosu_is_u65(edev) || !ofm) + return 0; + + transpose = FIELD_GET(NPU_OFM_TRANSPOSE_MASK, fm->precision); + + switch (transpose) { + case 0: /* HWC */ + break; + case 1: /* WHC */ + *x = height; + *y = width; + break; + case 2: /* HCW */ + *x = depth; + *c = width; + break; + case 3: /* WCH */ + *x = depth; + *y = width; + *c = height; + break; + case 6: /* CHW */ + *x = height; + *y = depth; + *c = width; + break; + case 7: /* CWH */ + *y = depth; + *c = height; + break; + default: + return -EINVAL; + } + + return 0; +} + static u64 feat_matrix_length(struct ethosu_device *edev, struct ethosu_validated_cmdstream_info *info, struct feat_matrix *fm, @@ -283,6 +329,9 @@ static int feat_matrix_size(struct ethosu_device *edev, int ret; *max_len = 0; + ret = feat_matrix_permute(edev, fm, &x, &y, &c, ofm); + if (ret) + return ret; if (ethosu_is_u65(edev) || storage == 0) { for (int xi = 0; xi < 2; xi++) { @@ -641,8 +690,13 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev, case NPU_SET_OFM_PRECISION: if (((param >> 6) & 0x3) > 1) return -EINVAL; - if (!ethosu_is_u65(edev) && (param & GENMASK(13, 11))) - return -EINVAL; + if (!ethosu_is_u65(edev)) { + switch (FIELD_GET(NPU_OFM_TRANSPOSE_MASK, param)) { + case 4: + case 5: + return -EINVAL; + } + } st.ofm.precision = param; break; case NPU_SET_OFM_REGION: -- 2.53.0