lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <68c08c9f6b1c5aab8ef4971724243b176a7d44d4.1761804232.git.kuhanh.murugasen.krishnan@altera.com>
Date: Tue,  4 Nov 2025 10:10:13 +0800
From: Kuhanh Murugasen Krishnan <kuhanh.murugasen.krishnan@...era.com>
To: Moritz Fischer <mdf@...nel.org>,
	Xu Yilun <yilun.xu@...el.com>,
	Tom Rix <trix@...hat.com>,
	linux-fpga@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Kuhanh Murugasen Krishnan <kuhanh.murugasen.krishnan@...era.com>
Subject: [PATCH 1/1] fpga: altera-cvp: Add support for truncated bitstream error handling

From: "Murugasen Krishnan, Kuhanh" <kuhanh.murugasen.krishnan@...era.com>

The Advanced Interface Bus (AIB) CvP firmware cannot handle bitstreams
smaller than 4096 bytes. When a truncated bitstream is sent, the
firmware’s DMA engine waits indefinitely for the remaining data,
causing the CvP transfer to hang and the configuration to fail.

To address this limitation, the driver now ensures that all transfers
are aligned to the 4096-byte block size by padding smaller bitstreams.
A dedicated 4096-byte transmit buffer (send_buf) is used to copy and
pad host data for each transaction. This guarantees that the firmware
always receives a full block.

Additionally, the driver now checks for CVP_CONFIG_ERROR in the CvP
status register at the end of configuration to detect truncated or
mismatched bitstream errors and aborts cleanly with -EPROTO.

These changes ensure proper error handling for truncated bitstreams and
prevent system hangs due to incomplete DMA transfers.

Signed-off-by: Ang Tien Sung <tien.sung.ang@...era.com>
Signed-off-by: Murugasen Krishnan, Kuhanh <kuhanh.murugasen.krishnan@...era.com>

---
 drivers/fpga/altera-cvp.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c
index 5af0bd33890c..390ecb8359ac 100644
--- a/drivers/fpga/altera-cvp.c
+++ b/drivers/fpga/altera-cvp.c
@@ -80,6 +80,7 @@ struct altera_cvp_conf {
 	u8			numclks;
 	u32			sent_packets;
 	u32			vsec_offset;
+	u8			*send_buf;
 	const struct cvp_priv	*priv;
 };
 
@@ -452,7 +453,10 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf,
 		}
 
 		len = min(conf->priv->block_size, remaining);
-		altera_cvp_send_block(conf, data, len);
+		/* Copy the requested host data into the transmit buffer */
+		memcpy(conf->send_buf, data, len);
+		altera_cvp_send_block(conf, (const u32 *)conf->send_buf,
+				      conf->priv->block_size);
 		data += len / sizeof(u32);
 		done += len;
 		remaining -= len;
@@ -491,10 +495,13 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr,
 	if (ret)
 		return ret;
 
-	/* STEP 16 - check CVP_CONFIG_ERROR_LATCHED bit */
-	altera_read_config_dword(conf, VSE_UNCOR_ERR_STATUS, &val);
-	if (val & VSE_UNCOR_ERR_CVP_CFG_ERR) {
-		dev_err(&mgr->dev, "detected CVP_CONFIG_ERROR_LATCHED!\n");
+	/*
+	 * STEP 16 - If bitstream error (truncated/miss-matched),
+	 * we shall exit here.
+	 */
+	ret = altera_read_config_dword(conf, VSE_CVP_STATUS, &val);
+	if (ret || (val & VSE_CVP_STATUS_CFG_ERR)) {
+		dev_err(&mgr->dev, "CVP_CONFIG_ERROR!\n");
 		return -EPROTO;
 	}
 
@@ -660,6 +667,13 @@ static int altera_cvp_probe(struct pci_dev *pdev,
 
 	pci_set_drvdata(pdev, mgr);
 
+	/* Allocate the 4096 block size transmit buffer */
+	conf->send_buf = devm_kzalloc(&pdev->dev, conf->priv->block_size, GFP_KERNEL);
+	if (!conf->send_buf) {
+		ret = -ENOMEM;
+		fpga_mgr_unregister(mgr);
+		goto err_unmap;
+	}
 	return 0;
 
 err_unmap:
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ